package com.njcn.process.controller;


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.prepare.harmonic.pojo.dto.SuperviseDto;
import com.njcn.process.pojo.param.SuperviseParam;
import com.njcn.process.pojo.vo.SuperviceRunLogVo;
import com.njcn.process.pojo.vo.SuperviseVo;
import com.njcn.process.pojo.vo.ThsSuperviseVo;
import com.njcn.process.pojo.param.FileParam;
import com.njcn.process.pojo.param.ThsSuperviseParam;
import com.njcn.process.pojo.po.ThsSupervise;
import com.njcn.process.service.ThsOverRunLogService;
import com.njcn.process.service.ThsSuperviseService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lxp
 * @since 2023-03-16
 */
@Api(tags = "预警-告警技术监督")
@RestController
@RequestMapping("/thsSupervise")
public class ThsSuperviseController extends BaseController {
    @Autowired
    private ThsSuperviseService thsSuperviseService;
    @Autowired
    private ThsOverRunLogService thsOverRunLogService;




   /* @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("预警/告警事务生成手动")
    @ApiImplicitParam(name = "superviseParam", value = "创建技术监督参数", required = true)
    @PostMapping("/initSuperviseHand")
    public HttpResult<SuperviceRunLogVo> initSuperviseHand(@RequestBody @Validated SuperviseParam superviseParam) {
        String methodDescribe = getMethodDescribe("initSuperviseHand");
        SuperviceRunLogVo result = thsSuperviseService.initSuperviseHand(superviseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
*/

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("预警/告警事务生成自动")
    @ApiImplicitParam(name = "superviseParam", value = "创建技术监督参数", required = true)
    @PostMapping("/initSupervise")
    public HttpResult<SuperviceRunLogVo> initSupervise(@RequestBody @Validated SuperviseParam superviseParam) {
        String methodDescribe = getMethodDescribe("initSupervise");
        SuperviceRunLogVo result = thsSuperviseService.initSupervise(superviseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("技术监督单详细列表")
    @ApiImplicitParam(name = "thsSuperviseParam", value = "创建技术监督参数", required = true)
    @PostMapping("/queryPage")
    public HttpResult<Page<ThsSupervise>> queryPage(@RequestBody @Validated ThsSuperviseParam thsSuperviseParam) {
        String methodDescribe = getMethodDescribe("queryPage");
        Page<ThsSupervise> page = thsSuperviseService.queryPage(thsSuperviseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }




    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @ApiOperation("保存技术监督监测点")
    @ApiImplicitParam(name = "superviceRunLogVo", value = "技术监督监测点参数", required = true)
    @PostMapping("/saveOverRunLog")
    public HttpResult saveOverRunLog(@RequestBody SuperviceRunLogVo superviceRunLogVo) {
        thsSuperviseService.saveOverRunLog(superviceRunLogVo);
        String methodDescribe = getMethodDescribe("saveOverRunLog");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @ApiOperation("更新技术监督")
    @ApiImplicitParam(name = "superviceRunLogVo", value = "更新技术监督参数", required = true)
    @PostMapping("/updateSupervice")
    public HttpResult updateSupervice(@RequestBody SuperviceRunLogVo superviceRunLogVo) {
        return thsOverRunLogService.updateSupervise(superviceRunLogVo);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("技术监督详情")
    @ApiImplicitParam(name = "supIndex", value = "技术监督id", required = true)
    @PostMapping("/superviseDetail")
    public HttpResult<SuperviceRunLogVo> superviseDetail(@RequestParam String supIndex) {
        SuperviceRunLogVo result = thsOverRunLogService.superviseDetail(supIndex);
        String methodDescribe = getMethodDescribe("superviseDetail");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
    @ApiOperation("删除技术监督")
    @ApiImplicitParam(name = "superviseDto", value = "删除技术监督请求体", required = true)
    @PostMapping("/deleteSupervise")
    public HttpResult deleteSupervise(@RequestBody SuperviseDto superviseDto) {
        return thsSuperviseService.deleteSupervise(superviseDto);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("查询技术监督列表")
    @ApiImplicitParam(name = "superviseDto", value = "查询技术监督列表参数", required = true)
    @PostMapping("/querySuperviseList")
    public HttpResult<Page<SuperviseVo>> querySuperviseList(@RequestBody SuperviseDto superviseDto) {
        Page<SuperviseVo> pageResult = thsSuperviseService.querySuperviseList(superviseDto);
        String methodDescribe = getMethodDescribe("querySuperviseList");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pageResult, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("上传技术监督单据")
    @PostMapping("/uploadSuperviseTicket")
    public HttpResult uploadSuperviseTicket(@ApiParam(value = "文件", required = true)
                                            @RequestPart(value = "files") MultipartFile[] files,
                                            @ApiParam(name = "id", value = "越限监测点记录id") @RequestParam(value = "id", required = false) String id,
                                            @ApiParam(name = "supIndex", value = "技术监督id", required = true) @RequestParam("supIndex") String supIndex,
                                            @ApiParam(name = "ticketType", value = "上传单据类型:1 反馈单,2 测试报告,4 整改通知反馈单", required = true) @RequestParam("ticketType") Integer ticketType,
                                            HttpServletResponse response) {
        thsSuperviseService.uploadSuperviseTicket(id, supIndex, ticketType, files, response);
        String methodDescribe = getMethodDescribe("uploadSuperviseTicket");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);

    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("查询流程状态列表")
    @PostMapping("/queryProgressValues")
    public HttpResult queryProgressValues() {
        List<Map<Integer, String>> values = thsSuperviseService.queryProgressValues();
        String methodDescribe = getMethodDescribe("queryProgressValues");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, values, methodDescribe);

    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
    @ApiOperation("上传单据模板")
    @PostMapping("/uploadAlarmFormwork")
    public HttpResult uploadAlarmFormwork(@ApiParam(value = "文件", required = true)
                                          @RequestPart(value = "file") MultipartFile file,
                                          @ApiParam(name = "type", value = "类型（0：预警；1：告警）", required = true) @RequestParam("type") Integer type,
                                          @ApiParam(name = "formworkType", value = "0：预/告警单模板；1：整改通知反馈单模板", required = true) @RequestParam("formworkType") Integer formworkType,
                                          HttpServletResponse response) {
        thsSuperviseService.uploadAlarmFormwork(type, formworkType, file, response);
        String methodDescribe = getMethodDescribe("uploadAlarmFormwork");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
    @ApiOperation("下载单据模板")
    @PostMapping("/dowloadAlarmFormwork")
    public HttpResult dowloadAlarmFormwork(@ApiParam(name = "type", value = "类型（0：预警；1：告警）", required = true) @RequestParam("type") Integer type,
                                           @ApiParam(name = "supIndex", value = "技术监督id", required = true) @RequestParam("supIndex") String supIndex,
                                           @ApiParam(name = "formworkType", value = "0：预/告警单模板；1：整改通知反馈单模板", required = true) @RequestParam("formworkType") Integer formworkType,
                                           HttpServletResponse response) {
        String httpPath = thsSuperviseService.dowloadAlarmFormwork(type, formworkType, supIndex, response);
        String methodDescribe = getMethodDescribe("uploadAlarmFormwork");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, httpPath, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("技术监督首页")
    @ApiImplicitParam(name = "superviseDto", value = "查询技术监督列表参数", required = true)
    @PostMapping("/superviseIndex")
    public HttpResult<ThsSuperviseVo> superviseIndex(@RequestBody SuperviseDto superviseDto) {
        ThsSuperviseVo resultList = thsSuperviseService.superviseIndex(superviseDto);
        String methodDescribe = getMethodDescribe("superviseIndex");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, resultList, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
    @PostMapping(value = "/downloadFeedBackFile", produces = {MediaType.APPLICATION_OCTET_STREAM_VALUE, MediaType.APPLICATION_JSON_VALUE})
    @ApiOperation("技术监督反馈文件下载")
    @ApiImplicitParam(name = "fileParam", value = "反馈文件下载参数", required = true)
    public HttpResult downloadFeedBackFile(@RequestBody @Validated FileParam fileParam, HttpServletRequest request, HttpServletResponse response) {
        String methodDescribe = getMethodDescribe("downloadFeedBackFile");
        HttpServletResponse resp = thsSuperviseService.downloadFeedBackFile(fileParam, request, response);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, resp, methodDescribe);
    }



}

