package com.chinaweal.aiccs.aiccs.business.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chinaweal.aiccs.aiccs.business.entity.XrTaskList;
import com.chinaweal.aiccs.aiccs.business.entity.dto.XrTaskListDto;
import com.chinaweal.aiccs.aiccs.business.service.IXrTaskListService;
import com.chinaweal.aiccs.common.base.controller.BaseController;
import com.chinaweal.aicorg.model.AICUser;
import com.chinaweal.youfool.framework.springboot.base.query.BaseQuery;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import com.chinaweal.youfool.framework.springboot.rest.ResultCode;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 待办列表 控制器
 * </p>
 *
 * @author quebh
 * @since 2023-05-04
 */
@Api(tags = "7.待办列表")
@ApiSort(7)
@RestController
@RequestMapping("/xrTaskList")
public class XrTaskListController extends BaseController {

    @Resource
    private IXrTaskListService iXrTaskListService;
//    @Resource
//    private IXrTaskForwardService iXrTaskForwardService;
//    @Resource
//    private IXrBizSpeListService iXrBizSpeListService;
//    @Resource
//    private IXrTsBizRemListService iXrTsBizRemListService;
//    @Resource
//    private IXrTSBizDissentService iXrTSBizDissentService;
//    @Resource
//    private IXrSeriousIllegalRemListService iXrSeriousIllegalRemListService;
//    @Resource
//    private IXrSeriousIllegalSpeListService iXrSeriousIllegalSpeListService;

//    @ApiOperation(value = "1.业务签收", position = 1)
//    @PostMapping("/signForByBizSeqNo")
//    public RestResult<String> signForByBizSeqNo(String bizSeqNo, String type, HttpServletRequest request) {
//        AICUser user = getLoginUser(request);
//        if (user == null) {
//            return RestResult.error(ResultCode.USER_NOT_LOGGED_IN);
//        }
//        LambdaUpdateWrapper<XrTaskList> updateWrapper = new LambdaUpdateWrapper<>();
//        updateWrapper.set(XrTaskList::getSenderUserId, user.getPrimaryKey()).eq(XrTaskList::getBizSeqNo, bizSeqNo);
//        iXrTaskListService.update(updateWrapper);
//        LambdaUpdateWrapper<XrTaskForward> updateForwardWrapper = new LambdaUpdateWrapper<>();
//        updateForwardWrapper.set(XrTaskForward::getIsReceive, "1").eq(XrTaskForward::getBizSeqNo, bizSeqNo);
//        iXrTaskForwardService.update(updateForwardWrapper);
//
//        if (StringUtils.equals("abnormal", type)) {
//            LambdaUpdateWrapper<XrBizSpeList> updateBizSWrapper = new LambdaUpdateWrapper<>();
//            updateBizSWrapper.set(XrBizSpeList::getStatus, "0").eq(XrBizSpeList::getBizSeqNo, bizSeqNo);
//            iXrBizSpeListService.update(updateBizSWrapper);
//        } else if (StringUtils.equals("dissent", type)) {
//            LambdaUpdateWrapper<XrBizDissent> updateBizSWrapper = new LambdaUpdateWrapper<>();
//            updateBizSWrapper.set(XrBizDissent::getStatus, "0").eq(XrBizDissent::getBizSeqNo, bizSeqNo);
//            iXrTSBizDissentService.update(updateBizSWrapper);
//        } else if (StringUtils.equals("remove", type)) {
//            LambdaUpdateWrapper<XrBizRemList> updateBizSWrapper = new LambdaUpdateWrapper<>();
//            updateBizSWrapper.set(XrBizRemList::getStatus, "0").eq(XrBizRemList::getBizSeqNo, bizSeqNo);
//            iXrTsBizRemListService.update(updateBizSWrapper);
//        } else if (StringUtils.equals("remove", type)) {
//            LambdaUpdateWrapper<XrSeriousIllegalRemList> updateRemSWrapper = new LambdaUpdateWrapper<>();
//            updateRemSWrapper.set(XrSeriousIllegalRemList::getStatus, "0").eq(XrSeriousIllegalRemList::getBizSeqNo, bizSeqNo);
//            iXrSeriousIllegalRemListService.update(updateRemSWrapper);
//        } else if (StringUtils.equals("lawfullyRevoked", type)) {
//            LambdaUpdateWrapper<XrSeriousIllegalRemList> updateRemSWrapper = new LambdaUpdateWrapper<>();
//            updateRemSWrapper.set(XrSeriousIllegalRemList::getStatus, "0").eq(XrSeriousIllegalRemList::getBizSeqNo, bizSeqNo);
//            iXrSeriousIllegalRemListService.update(updateRemSWrapper);
//        } else {
//            LambdaUpdateWrapper<XrSeriousIllegalSpeList> updateRemSWrapper = new LambdaUpdateWrapper<>();
//            updateRemSWrapper.set(XrSeriousIllegalSpeList::getStatus, "0").eq(XrSeriousIllegalSpeList::getBizSeqNo, bizSeqNo);
//            iXrSeriousIllegalSpeListService.update(updateRemSWrapper);
//        }
//        return RestResult.ok();
//    }
//
    @ApiOperation(value = "2.查找当前节点的下一步路线", position = 2)
    @GetMapping("/taskInfo")
    public RestResult<XrTaskList> taskInfo(@RequestParam @ApiParam("bizSeqNo") String bizSeqNo) {
        return RestResult.ok(iXrTaskListService.lambdaQuery().eq(XrTaskList::getBizSeqNo, bizSeqNo).one());
    }
//
//    @ApiOperation(value = "3.待办列表", position = 6)
//    @PostMapping("/taskList")
//    public RestResult<IPage<XrTaskList>> taskList(@RequestBody BaseQuery<XrTaskListDto> query) {
//        return RestResult.ok(iXrTaskListService.taskList(query));
//    }
//
//    @ApiOperation(value = "4.待办列表功能", position = 6)
//    @PostMapping("/toDoList")
//    public RestResult<IPage<XrTaskList>> toDoList(@RequestBody BaseQuery<XrTaskListDto> query) {
//        return RestResult.ok(iXrTaskListService.toDoList(query));
//    }

    @ApiOperation(value = "5.判断当前用户是否该业务的发起人", position = 2)
    @GetMapping("/isTaskCreater")
    public RestResult<Boolean> isTaskCreater(@RequestParam @ApiParam("bizSeqNo") String bizSeqNo,HttpServletRequest request) {
        AICUser user = getLoginUser(request);
        XrTaskList xrTaskList = iXrTaskListService.lambdaQuery().eq(XrTaskList::getBizSeqNo, bizSeqNo).one();
        return RestResult.ok(StringUtils.equals(xrTaskList.getCreateBy(), user.getEname()));
    }
}
