package com.njcn.csharmonic.controller;


import com.njcn.common.pojo.annotation.OperateInfo;
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.csharmonic.pojo.param.PqGovernPlanParam;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import com.njcn.csharmonic.pojo.vo.PqGovernPlanVo;
import com.njcn.csharmonic.service.IPqGovernPlanService;
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 org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xy
 * @since 2026-06-16
 */
@RestController
@RequestMapping("/pqGovernPlan")
@Api(tags = "治理方案管理")
@AllArgsConstructor
public class PqGovernPlanController extends BaseController {

    private final IPqGovernPlanService pqGovernPlanService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/save")
    @ApiOperation("新增治理方案")
    public HttpResult<Boolean> save(@RequestBody @Validated PqGovernPlanParam param) {
        String methodDescribe = getMethodDescribe("save");
        boolean result = pqGovernPlanService.save(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/update")
    @ApiOperation("修改治理方案")
    public HttpResult<Boolean> update(@RequestBody @Validated PqGovernPlanParam.UpdatePqGovernPlanParam param) {
        String methodDescribe = getMethodDescribe("update");
        boolean result = pqGovernPlanService.update(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/delete")
    @ApiOperation("删除治理方案")
    @ApiImplicitParam(name = "ids", value = "ID集合")
    public HttpResult<Boolean> delete(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("delete");
        boolean result = pqGovernPlanService.delete(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getById")
    @ApiOperation("根据ID查询治理方案")
    @ApiImplicitParam(name = "id", value = "ID", required = true)
    public HttpResult<PqGovernPlan> getById(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getById");
        PqGovernPlan plan = pqGovernPlanService.getById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, plan, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getListByPid")
    @ApiOperation("根据pid查询所有治理方案")
    @ApiImplicitParam(name = "pid", value = "用户id（关联pq_sensitive_user的id）", required = true)
    public HttpResult<List<PqGovernPlanVo>> getListByPid(@RequestParam("pid") String pid) {
        String methodDescribe = getMethodDescribe("getListByPid");
        List<PqGovernPlanVo> list = pqGovernPlanService.getListByPid(pid);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getListExcludeNull")
    @ApiOperation("查询所有治理方案(剔除治理前后监测点为空的数据)")
    public HttpResult<List<PqGovernPlan>> getListExcludeNull() {
        String methodDescribe = getMethodDescribe("getListExcludeNull");
        List<PqGovernPlan> list = pqGovernPlanService.getListExcludeNull();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/clearGovernPoints")
    @ApiOperation("清空治理前后监测点数据")
    @ApiImplicitParam(name = "id", value = "治理方案ID", required = true)
    public HttpResult<Boolean> clearGovernPoints(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("clearGovernPoints");
        boolean result = pqGovernPlanService.clearGovernPoints(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getListByMonitorPoint")
    @ApiOperation("根据监测点查询方案数据")
    @ApiImplicitParam(name = "ids", value = "监测点id集合", required = true)
    public HttpResult<List<PqGovernPlan>> getListByMonitorPoint(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("clearGovernPoints");
        List<PqGovernPlan> result = pqGovernPlanService.getListByMonitorPoint(ids,null);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

}

