package com.njcn.supervision.controller.plan;

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.supervision.pojo.param.plan.SupervisopnProblemParam;
import com.njcn.supervision.pojo.po.plan.SupervisionProblemPO;
import com.njcn.supervision.service.plan.SupervisionProblemPOService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 干扰源用户管理
 *
 * @author qijian
 * @version 1.0.0
 * @createTime 2022/11/11 - 9:20
 */
@Slf4j
@RestController
@RequestMapping("/superProblem")
@Api(tags = "技术监督计划问题")
@AllArgsConstructor
public class SupervisionProblemController extends BaseController {


    private final SupervisionProblemPOService supervisionProblemPOService;

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

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


}
