package com.njcn.device.pq.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.device.pq.pojo.param.TerminalMainQueryParam;
import com.njcn.device.pq.pojo.po.PqsLineWeight;
import com.njcn.device.pq.pojo.vo.PqsLineWeightVo;
import com.njcn.device.pq.service.IPqsLineWeightService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.core.io.InputStreamResource;
import org.springframework.web.bind.annotation.*;

import com.njcn.web.controller.BaseController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 *  监测点评分权重
 * </p>
 *
 * @author wr
 * @since 2023-08-24
 */
@RestController
@RequestMapping("/LineWeight")
@Api(tags = "监测点评分权重")
@RequiredArgsConstructor
public class PqsLineWeightController extends BaseController {

    private final IPqsLineWeightService iPqsLineWeightService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/LineWeightList")
    @ApiOperation("查询监测点权重")
    public HttpResult<Page<PqsLineWeightVo>> LineWeightList(@RequestBody TerminalMainQueryParam terminalMainQueryParam) {
        String methodDescribe = getMethodDescribe("LineWeightList");
        Page<PqsLineWeightVo> pqsLineWeightVoPage = iPqsLineWeightService.LineWeightList(terminalMainQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqsLineWeightVoPage, methodDescribe);

    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addLineWeight")
    @ApiOperation("监测点评分权重修改")
    public HttpResult<Boolean> addLineWeight(@RequestBody PqsLineWeight lineWeight) {
        String methodDescribe = getMethodDescribe("addLineWeight");
        Boolean aBoolean = iPqsLineWeightService.addLineWeight(lineWeight);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, aBoolean, methodDescribe);

    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/export")
    @ApiOperation("监测点评分权重模板导出")
    public InputStreamResource export() throws IOException {
        return iPqsLineWeightService.exportTemplate();
    }

    @PostMapping(value = "/batchWeight")
    @ApiOperation("批量导入监测点评分权重")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    public HttpResult<String> batchWeight(@ApiParam(value = "文件", required = true) @RequestPart("file") MultipartFile file, HttpServletResponse response) {
        String methodDescribe = getMethodDescribe("batchWeight");
        iPqsLineWeightService.batchWeight(file, response);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/exportList")
    @ApiOperation("监测点评分权重信息导出")
    public void export(@RequestBody TerminalMainQueryParam terminalMainQueryParam) throws IOException {
         iPqsLineWeightService.exportWeight(terminalMainQueryParam);
    }
}

