package com.njcn.process.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.prepare.harmonic.pojo.dto.OverLimitFlagDTO;
import com.njcn.process.pojo.param.RStatProblemAndWorkOrderParam;
import com.njcn.process.pojo.vo.IssueesAndOrderVO;
import com.njcn.process.pojo.vo.OrderCountVO;
import com.njcn.process.pojo.vo.RStatDistributionProblemVO;
import com.njcn.process.pojo.vo.RStatWorkOrderDetailVO;
import com.njcn.process.service.RStatDistributionProblemService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description:
 * 接口文档访问地址：http://serverIP:port/swagger-ui.html
 * Date: 2023/2/1  16:33【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/rStatWorkOrder")
@Api(tags = "工单管理")
@AllArgsConstructor
public class RStatWorkOrderController extends BaseController {

    private final RStatDistributionProblemService rStatDistributionProblemService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
    @PostMapping("/queryIssuesAndOrder")
    @ApiOperation("查询问题及工单（当前部门下）")
    @ApiImplicitParam(name = "orgNo", value = "部门id", required = true)
    public HttpResult<IssueesAndOrderVO> queryIssuesAndOrder(@RequestParam("orgNo") String orgNo){
        String methodDescribe = getMethodDescribe("queryIssuesAndOrder");
        IssueesAndOrderVO issueesAndOrderVO =rStatDistributionProblemService.queryIssuesAndOrder(orgNo);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, issueesAndOrderVO, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
    @PostMapping("/queryOrderDetail")
    @ApiOperation("查询工单及工单总数及完成工单数量（当前部门下）")
    @ApiImplicitParam(name = "orgNo", value = "部门id", required = true)
    public HttpResult<OrderCountVO> queryOrderDetail(@RequestParam("orgNo") String orgNo){
        String methodDescribe = getMethodDescribe("queryOrderDetail");
        OrderCountVO orderCountVO =rStatDistributionProblemService.queryOrderCount(orgNo);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, orderCountVO, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
    @PostMapping("/createProblem")
    @ApiOperation("创建问题接口")
    @ApiImplicitParam(name = "overLimitFlagDTOList", value = "部门id", required = true)
    public HttpResult<Boolean> createProblem(@RequestBody List<OverLimitFlagDTO> overLimitFlagDTOList){
        String methodDescribe = getMethodDescribe("createProblem");
        Boolean problem = rStatDistributionProblemService.createProblem (overLimitFlagDTOList);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, problem, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryProblem")
    @ApiOperation("查询工单问题")
    @ApiImplicitParam(name = "rStatProblemAndWorkOrderParam", value = "查询工单问题参数", required = true)
    public HttpResult<IPage<RStatDistributionProblemVO>> queryProblem(@Validated @RequestBody RStatProblemAndWorkOrderParam rStatProblemAndWorkOrderParam){
        String methodDescribe = getMethodDescribe("queryProblem");

        IPage<RStatDistributionProblemVO> rStatDistributionProblemVOIPage  = rStatDistributionProblemService.queryProblem (rStatProblemAndWorkOrderParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, rStatDistributionProblemVOIPage, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/checkProblem")
    @ApiOperation("审核处理")
    @ApiImplicitParam(name = "rStatDistributionProblemVO", value = "审核工单问题参数", required = true)
    public HttpResult<Boolean> checkProblem(@Validated @RequestBody RStatDistributionProblemVO rStatDistributionProblemVO){
        String methodDescribe = getMethodDescribe("checkProblem");

       Boolean flag  = rStatDistributionProblemService.checkProblem (rStatDistributionProblemVO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryWorkOrder")
    @ApiOperation("查询工单")
    @ApiImplicitParam(name = "rStatProblemAndWorkOrderParam", value = "查询工单问题参数", required = true)
    public HttpResult<IPage<RStatWorkOrderDetailVO>> queryWorkOrder(@Validated @RequestBody RStatProblemAndWorkOrderParam rStatProblemAndWorkOrderParam){
        String methodDescribe = getMethodDescribe("queryWorkOrder");

        IPage<RStatWorkOrderDetailVO> rStatWorkOrderDetailVOIPage  = rStatDistributionProblemService.queryWorkOrder (rStatProblemAndWorkOrderParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, rStatWorkOrderDetailVOIPage, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/updateWorkOrderStatus")
    @ApiOperation("更新工单进度")
    @ApiImplicitParam(name = "rStatWorkOrderDetailVO", value = "查询工单问题参数", required = true)
    public HttpResult<Boolean> updateWorkOrderStatus(@Validated @RequestBody RStatWorkOrderDetailVO rStatWorkOrderDetailVO){
        String methodDescribe = getMethodDescribe("updateWorkOrderStatus");

        Boolean flag  = rStatDistributionProblemService.updateWorkOrderStatus (rStatWorkOrderDetailVO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }


}
