package com.njcn.process.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
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.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.poi.util.PoiUtil;
import com.njcn.process.pojo.param.*;
import com.njcn.process.pojo.vo.LoadTypeRelationExcel;
import com.njcn.process.pojo.vo.LoadTypeUserExcel;
import com.njcn.process.pojo.vo.RLoadTypeUserManageVO;
import com.njcn.process.service.LoadTypeUserManageService;
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.apache.poi.ss.usermodel.Workbook;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 干扰源用户管理
 *
 * @author qijian
 * @version 1.0.0
 * @createTime 2022/11/11 - 9:20
 */
@Slf4j
@RestController
@RequestMapping("/loadTypeUserManage")
@Api(tags = "干扰源用户管理")
@AllArgsConstructor
public class LoadTypeUserManageController extends BaseController {

    private final LoadTypeUserManageService loadTypeUserManageService;

    /**
     * 查询所有干扰源用户
     * @author qijian
     * @date 2022/11/11
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLoadTypeUserList")
    @ApiOperation("查询所有干扰源用户（未建档干扰源用户管理）")
    @ApiImplicitParam(name = "loadTypeUserSearchParam", value = "干扰源用户入参", required = true)
    public HttpResult<Page<RLoadTypeUserManageVO>> getLoadTypeUserList(@RequestBody @Validated LoadTypeUserSearchParam loadTypeUserSearchParam){
        String methodDescribe = getMethodDescribe("getLoadTypeUserList");
        Page<RLoadTypeUserManageVO> list = loadTypeUserManageService.getLoadTypeUserList(loadTypeUserSearchParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    /**
     * 根据id查询干扰源用户
     * @author qijian
     * @date 2022/11/14
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getLoadTypeUserById")
    @ApiOperation("根据id查询干扰源用户（通用）")
    @ApiImplicitParam(name = "id", value = "id", required = true)
    public HttpResult<RLoadTypeUserManageVO> getLoadTypeUserById(@RequestParam("id") String id){
        String methodDescribe = getMethodDescribe("getLoadTypeUserById");
        RLoadTypeUserManageVO rLoadTypeUserManageVO = loadTypeUserManageService.getLoadTypeUserById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, rLoadTypeUserManageVO, methodDescribe);
    }

    /**
     * 新增干扰源用户
     * @author qijian
     * @date 2022/11/14
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType= OperateType.ADD)
    @PostMapping("/addLoadTypeUser")
    @ApiOperation("新增干扰源用户（未建档干扰源用户管理）")
    @ApiImplicitParam(name = "loadTypeUserParam", value = "实体参数", required = true)
    public HttpResult<Boolean> addLoadTypeUser(@RequestBody @Validated LoadTypeUserParam loadTypeUserParam){
        String methodDescribe = getMethodDescribe("addLoadTypeUser");
        boolean res = loadTypeUserManageService.addLoadTypeUser(loadTypeUserParam);
        if(res){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/checkLoadTypeUserI")
    @ApiOperation("入网评估报告审核")
    @ApiImplicitParam(name = "loadTypeUserCheckParam", value = "入网评估报告审核参数", required = true)
    public HttpResult<Boolean> checkLoadTypeUserI(@Validated @RequestBody LoadTypeUserCheckParam loadTypeUserCheckParam){
        String methodDescribe = getMethodDescribe("checkLoadTypeUserI");
        Boolean flag  = loadTypeUserManageService.checkLoadTypeUserI (loadTypeUserCheckParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/checkLoadTypeUserA")
    @ApiOperation("实测报告审核")
    @ApiImplicitParam(name = "loadTypeUserCheckParam", value = "实测报告参数", required = true)
    public HttpResult<Boolean> checkLoadTypeUserA(@Validated @RequestBody LoadTypeUserCheckParam loadTypeUserCheckParam){
        String methodDescribe = getMethodDescribe("checkLoadTypeUserA");

        Boolean flag  = loadTypeUserManageService.checkLoadTypeUserA (loadTypeUserCheckParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }
    /**
     * 上传干扰源用户入网报告
     * @author qijian
     * @date 2022/11/14
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/uploadLoadTypeUserI")
    @ApiOperation("上传干扰源用户入网报告（未建档干扰源用户管理）")
    public HttpResult<Boolean> uploadLoadTypeUserI(@Validated LoadTypeUserIUploadParam loadTypeUserIUploadParam){
        String methodDescribe = getMethodDescribe("uploadLoadTypeUserI");
        boolean res = loadTypeUserManageService.uploadLoadTypeUserI(loadTypeUserIUploadParam);
        if(res){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }

    /**
     * 关联营销用户
     * @author qijian
     * @date 2022/11/16
     *
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType= OperateType.UPDATE)
    @PostMapping("/linkUser")
    @ApiOperation("关联营销用户（未建档干扰源用户管理）")
    @ApiImplicitParam(name = "loadTypeUserAssociateParam", value = "实体参数", required = true)
    public HttpResult<Boolean> linkUser(@RequestBody @Validated LoadTypeUserAssociateParam loadTypeUserAssociateParam){
        String methodDescribe = getMethodDescribe("linkUser");
        boolean res = loadTypeUserManageService.linkUser(loadTypeUserAssociateParam);
        if(res){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }

    /**
     * 导出未建档干扰源用户管理信息
     * @author qijian
     * @date 2022/12/06
     */
    @ResponseBody
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType= OperateType.DOWNLOAD)
    @ApiOperation("导出未建档干扰源用户管理信息")
    @PostMapping(value = "exportLoadTypeUserList")
    @ApiImplicitParam(name = "list", value = "导出勾选主键参数", required = true)
    public HttpResult<String> exportLoadTypeUserList(HttpServletResponse response, @RequestBody List<String> list) {
        String methodDescribe = getMethodDescribe("exportLoadTypeUserList");
        String fileName = "未建档干扰源用户管理信息.xls";
        List<LoadTypeUserExcel> excelList = null;
        try {
            excelList = loadTypeUserManageService.exportLoadTypeUserList(list);
        } catch (Exception e) {
            e.printStackTrace();
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
        ExportParams exportExcel = new ExportParams("未建档干扰源用户管理信息", "未建档干扰源用户");
        Workbook workbook = ExcelExportUtil.exportExcel(exportExcel, LoadTypeUserExcel.class, excelList);
        PoiUtil.exportFileByWorkbook(workbook, fileName, response);
        return null;
    }

    /**
     * 查询所有干扰源用户（与营销系统关联）
     * @author qijian
     * @date 2022/11/17
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLoadTypeRelationList")
    @ApiOperation("查询所有干扰源用户（干扰源用户常态化管理）")
    @ApiImplicitParam(name = "loadTypeUserSearchParam", value = "干扰源用户入参", required = true)
    public HttpResult<Page<RLoadTypeUserManageVO>> getLoadTypeRelationList(@RequestBody @Validated LoadTypeUserSearchParam loadTypeUserSearchParam){
        String methodDescribe = getMethodDescribe("getLoadTypeRelationList");
        Page<RLoadTypeUserManageVO> list = loadTypeUserManageService.getLoadTypeRelationList(loadTypeUserSearchParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    /**
     * 上传干扰源用户实测报告
     * @author qijian
     * @date 2022/11/14
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType= OperateType.UPDATE)
    @PostMapping("/uploadLoadTypeUserA")
    @ApiOperation("上传干扰源用户实测报告（干扰源用户常态化管理）")
    public HttpResult<Boolean> uploadLoadTypeUserA(@Validated LoadTypeUserAUploadParam loadTypeUserAUploadParam){
        String methodDescribe = getMethodDescribe("uploadLoadTypeUserA");
        boolean res = loadTypeUserManageService.uploadLoadTypeUserA(loadTypeUserAUploadParam);
        if(res){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        }else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }

    /**
     * 导出干扰源用户常态化管理信息
     * @author qijian
     * @date 2022/12/07
     */
    @ResponseBody
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType= OperateType.DOWNLOAD)
    @ApiOperation("导出干扰源用户常态化管理信息")
    @PostMapping(value = "exportLoadTypeRelationList")
    @ApiImplicitParam(name = "list", value = "导出勾选主键参数", required = true)
    public HttpResult<String> exportLoadTypeRelationList(HttpServletResponse response, @RequestBody List<String> list) {
        String methodDescribe = getMethodDescribe("exportLoadTypeRelationList");
        String fileName = "导出干扰源用户常态化管理信息.xls";
        List<LoadTypeRelationExcel> excelList = null;
        try {
            excelList = loadTypeUserManageService.exportLoadTypeRelationList(list);
        } catch (Exception e) {
            e.printStackTrace();
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
        ExportParams exportExcel = new ExportParams("干扰源用户常态化管理信息", "干扰源用户常态化管理");
        Workbook workbook = ExcelExportUtil.exportExcel(exportExcel, LoadTypeRelationExcel.class, excelList);
        PoiUtil.exportFileByWorkbook(workbook, fileName, response);
        return null;
    }

    /**
     * 删除新增干扰源用户计划
     * @author cdf
     * @date 2024/4/9
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("删除新增干扰源用户计划")
    @PostMapping(value = "delLoadTypeUserPlan")
    @ApiImplicitParam(name = "list", value = "主键参数集合", required = true)
    public HttpResult<String>delLoadTypeUserPlan(@RequestBody List<String> list) {
        String methodDescribe = getMethodDescribe("delLoadTypeUserPlan");
        loadTypeUserManageService.delLoadTypeUserPlan(list);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    /**
     * 提交审核
     * @author cdf
     * @date 2024/3/29
     */

    @ApiOperation("提交审核")
    @PostMapping(value = "submitAuditUser")
    @ApiImplicitParam(name = "loadTypeUserCheckParam", value = "实体参数", required = true)
    public HttpResult<Boolean> submitAuditUser(@RequestBody LoadTypeUserCheckParam loadTypeUserCheckParam) {
        String methodDescribe = getMethodDescribe("submitAuditUser");
        loadTypeUserManageService.submitAuditUser(loadTypeUserCheckParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }
}
