package com.njcn.process.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.process.pojo.param.SupvPlanParam;
import com.njcn.process.pojo.param.SupvProblemParam;
import com.njcn.process.pojo.po.SupvProblem;
import com.njcn.process.pojo.vo.SupvProblemVO;
import com.njcn.process.service.ISupvProblemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.njcn.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hongawen
 * @since 2023-06-21
 */
@RestController
@RequestMapping("/supv/problem")
@Api(tags = "技术监督实施问题控制器")
@RequiredArgsConstructor
public class SupvProblemController extends BaseController {

    private final ISupvProblemService iSupvProblemService;


    @PostMapping("addProblem")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @ApiOperation("新增技术监督问题")
    @ApiImplicitParam(name = "supvProblemParam",value = "请求体",required = true)
    public HttpResult<Object> addProblem(@RequestBody @Validated SupvProblemParam supvProblemParam){
        String methodDescribe = getMethodDescribe("addProblem");
        iSupvProblemService.addProblem(supvProblemParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @PostMapping("updateProblem")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @ApiOperation("修改技术监督问题")
    @ApiImplicitParam(name = "supvProblemParam",value = "请求体",required = true)
    public HttpResult<Object> updateProblem(@RequestBody @Validated SupvProblemParam.UpdateSupvProblemParam supvProblemParam){
        String methodDescribe = getMethodDescribe("updateProblem");
        iSupvProblemService.updateProblem(supvProblemParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @PostMapping("delProblem")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @ApiOperation("删除监督问题")
    @ApiImplicitParam(name = "problemIds",value = "监督问题计划索引集合",required = true)
    public HttpResult<Object> delProblem(@RequestBody List<String> problemIds){
        String methodDescribe = getMethodDescribe("delProblem");
        iSupvProblemService.delProblem(problemIds);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @PostMapping("pageProblem")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("分页查询监督问题")
    @ApiImplicitParam(name = "supvProblemParam",value = "请求体",required = true)
    public HttpResult<Page<SupvProblem>> pageProblem(@RequestBody SupvProblemParam supvProblemParam){
        String methodDescribe = getMethodDescribe("pageProblem");
        if(StrUtil.isBlank(supvProblemParam.getPlanId())){
            throw new BusinessException("监督计划索引不可为空");
        }
        Page<SupvProblem> page = iSupvProblemService.pageProblem(supvProblemParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    @PostMapping("problemList")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("所有监督问题")
    @ApiImplicitParam(name = "supvProblemParam",value = "请求体",required = true)
    public void problemList(@RequestBody SupvPlanParam supvPlanParam){
         iSupvProblemService.problemList(supvPlanParam);
    }
}

