package com.njcn.harmonic.controller;

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.DeviceInfoParam;
import com.njcn.harmonic.pojo.vo.IntegrityIconVO;
import com.njcn.harmonic.pojo.vo.IntegrityVO;
import com.njcn.harmonic.service.IntegrityService;
import com.njcn.poi.util.PoiUtil;
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.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2021/12/27 13:47
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/integrity")
@Api(tags = "数据完整性")
@AllArgsConstructor
public class IntegrityController extends BaseController {

    private final IntegrityService integrityService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getIntegrityData")
    @ApiOperation("数据完整性列表")
    @ApiImplicitParam(name = "integrityParam", value = "数据完整性参数", required = true)
    public HttpResult<List<IntegrityVO>> getIntegrityData(@RequestBody @Validated DeviceInfoParam.BusinessParam integrityParam) {
        String methodDescribe = getMethodDescribe("getIntegrityData");
        List<IntegrityVO> list = integrityService.getIntegrityData(integrityParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getIntegrityIcon")
    @ApiOperation("数据完整性图表")
    @ApiImplicitParam(name = "integrityIconParam", value = "数据完整性参数", required = true)
    public HttpResult<List<IntegrityIconVO>> getIntegrityIcon(@RequestBody @Validated DeviceInfoParam.CompareBusinessParam integrityIconParam) {
        String methodDescribe = getMethodDescribe("getIntegrityIcon");
        List<IntegrityIconVO> integrityIconVO = integrityService.getIntegrityIcon(integrityIconParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, integrityIconVO, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/exportIntegrityData")
    @ApiOperation("数据完整性")
    @ApiImplicitParam(name = "integrityParam", value = "数据完整性参数", required = true)
    public HttpResult<String> exportIntegrityData(@RequestBody @Validated DeviceInfoParam.BusinessParam integrityParam) {
        String methodDescribe = getMethodDescribe("exportIntegrityData");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, integrityService.exportIntegrityData(integrityParam, methodDescribe), methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DOWNLOAD)
    @GetMapping("/exportIntegrityDataExcel")
    @ApiOperation("导出数据完整性报表")
    @ApiImplicitParam(name = "filePath", value = "报表路径", required = true)
    public void exportIntegrityDataExcel(String filePath, HttpServletResponse response) {
        PoiUtil.exportFileByAbsolutePath(filePath,response);
    }

}
