package com.njcn.supervision.controller.survey;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.bpm.pojo.param.instance.BpmProcessInstanceCancelParam;
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.supervision.pojo.param.survey.SurveyPlanParam;
import com.njcn.supervision.pojo.vo.survey.SurveyPlanVO;
import com.njcn.supervision.service.survey.ISurveyPlanService;
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 com.njcn.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 普测计划流程表 前端控制器
 * </p>
 *
 * @author hongawen
 * @since 2024-05-30
 */
@RestController
@RequestMapping("/surveyPlan")
@Slf4j
@Api(tags = "普测计划流程管理")
@AllArgsConstructor
public class SurveyPlanController extends BaseController {

    private final ISurveyPlanService surveyPlanService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/surveyPlanPage")
    @ApiOperation("分页查询当前用户能看到的普测计划")
    @ApiImplicitParam(name = "surveyPlanQueryParam", value = "参数", required = true)
    public HttpResult<Page<SurveyPlanVO>> surveyPlanPage(@RequestBody @Validated SurveyPlanParam.SurveyPlanQueryParam surveyPlanQueryParam) {
        String methodDescribe = getMethodDescribe("surveyPlanPage");
        Page<SurveyPlanVO> out = surveyPlanService.surveyPlanPage(surveyPlanQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("新增普测计划")
    @ApiImplicitParam(name = "surveyPlanParam", value = "实体参数", required = true)
    public HttpResult<String> addSurveyPlan(@RequestBody @Validated SurveyPlanParam surveyPlanParam) {
        String methodDescribe = getMethodDescribe("addSurveyPlan");
        String planId = surveyPlanService.addSurveyPlan(surveyPlanParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, planId, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/update")
    @ApiOperation("重新发起普测计划")
    @ApiImplicitParam(name = "surveyPlanUpdateParam", value = "实体参数", required = true)
    public HttpResult<String> updateSurveyPlan(@RequestBody @Validated SurveyPlanParam.SurveyPlanUpdateParam surveyPlanUpdateParam) {
        String methodDescribe = getMethodDescribe("updateSurveyPlan");
        String runningDeviceId = surveyPlanService.updateSurveyPlan(surveyPlanUpdateParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, runningDeviceId, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/cancel")
    @ApiOperation("取消普测计划")
    @ApiImplicitParam(name = "cancelReqVO", value = "取消原因", required = true)
    public HttpResult<String> cancelSurveyPlan(@Validated @RequestBody BpmProcessInstanceCancelParam cancelReqVO) {
        String methodDescribe = getMethodDescribe("cancelSurveyPlan");
        String runningDeviceId = surveyPlanService.cancelSurveyPlan(cancelReqVO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, runningDeviceId, methodDescribe);
    }

    @GetMapping("/updateSurveyPlanStatus")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("更新普测计划流程状态")
    public HttpResult<Object> updateSurveyPlanStatus(String businessKey, Integer status) {
        String methodDescribe = getMethodDescribe("updateSurveyPlanStatus");
        surveyPlanService.updateProcessStatus(businessKey, status);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @GetMapping("/getById")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据id获取普测计划的详细数据")
    public HttpResult<SurveyPlanVO> getById(String id) {
        String methodDescribe = getMethodDescribe("getById");
        SurveyPlanVO surveyPlanVO = surveyPlanService.getVOById(id);
        System.out.println(surveyPlanVO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, surveyPlanVO, methodDescribe);
    }

    @PostMapping(value = "/deleteSurveyPlan")
    @ApiOperation("技术监督计划管理删除流程")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM, operateType = OperateType.DELETE)
    public HttpResult<Boolean> deleteSurveyPlan(@RequestBody List<String> supervisionId) {
        String methodDescribe = getMethodDescribe("deleteSurveyPlan");
        Boolean b = surveyPlanService.deleteSurveyPlan(supervisionId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
    }




}

