package com.njcn.csharmonic.controller;


import cn.hutool.core.bean.BeanUtil;
import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.pojo.vo.LineDetailDataVO;
import com.njcn.device.biz.pojo.po.Overlimit;
import com.njcn.device.biz.pojo.po.PqsDeviceUnit;
import com.njcn.harmonic.common.pojo.dto.DeviceUnitCommDTO;
import com.njcn.harmonic.common.pojo.dto.HarmLineDetailDataCommDTO;
import com.njcn.harmonic.common.pojo.dto.OverLimitInfoCommDTO;
import com.njcn.harmonic.common.service.MonitorHarmonicReportService;

import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;


/**
 * @author wr
 */
@Slf4j
@RestController
@RequestMapping("/exportmodel")
@Api(tags = "word报告")
@AllArgsConstructor
public class WordExportModelController extends BaseController {

    private final CsLineFeignClient csLineFeignClient;



    private final MonitorHarmonicReportService monitorHarmonicReportService;

    /**
     * @param response
     * @param startTime    开始时间
     * @param endTime      结束时间
     * @param type         区分pq:0 pms:1
     * @param lineIndex    监测点id
     * @param name         监测点名称
     * @param reportNumber 客户编号
     * @param crmName      客户名称
     * @param file         接线图
     * @param isUrl        是否地址栏返回
     * @return
     * @throws IOException
     */
    @PostMapping("/exportModel")
    @ApiOperation("word报告")
    public void exportWorld(HttpServletResponse response,
                                          @RequestParam(value ="startTime",required = false) String startTime,
                                          @RequestParam(value ="endTime",required = false)  String endTime,
                                          @RequestParam(value ="type",required = false) Integer type,
                                          @RequestParam(value ="lineIndex",required = false)  String lineIndex,
                                          @RequestParam(value ="name",required = false)  String name,
                                          @RequestParam(value ="reportNumber",required = false) String reportNumber,
                                          @RequestParam(value ="crmName",required = false) String crmName,
                                          @RequestParam(value = "isUrl",required = false)  Boolean isUrl,
                                          @RequestPart(value ="file",required = false)   MultipartFile file) throws IOException {
        String methodDescribe = getMethodDescribe("exportWorld");

        HarmLineDetailDataCommDTO harmLineDetailDataCommDTO;
        OverLimitInfoCommDTO overLimitInfoCommDTO;
        DeviceUnitCommDTO deviceUnitCommDTO;

        Overlimit overLimit = new Overlimit();
        LineDetailDataVO lineDto = csLineFeignClient.getLineDetailData(lineIndex).getData();
        harmLineDetailDataCommDTO = BeanUtil.copyProperties(lineDto, HarmLineDetailDataCommDTO.class);

        List<Overlimit> overLimitList = csLineFeignClient.getOverLimitData(Stream.of(lineIndex).collect(Collectors.toList())).getData();
        overLimit = overLimitList.get(0);
        overLimitInfoCommDTO = BeanUtil.copyProperties(overLimit, OverLimitInfoCommDTO.class);


        PqsDeviceUnit pqsDeviceUnit = new PqsDeviceUnit();
        deviceUnitCommDTO = BeanUtil.copyProperties(pqsDeviceUnit, DeviceUnitCommDTO.class);


        monitorHarmonicReportService.exportWorld(response, startTime, endTime, type, lineIndex, name, reportNumber, crmName, isUrl, file, harmLineDetailDataCommDTO, overLimitInfoCommDTO,deviceUnitCommDTO,lineDto.getDataLevel());

    }


}
