package com.njcn.csharmonic.controller;

import com.njcn.common.pojo.annotation.OperateInfo;
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.csharmonic.pojo.param.MakeUpParam;
import com.njcn.csharmonic.pojo.vo.MakeUpVo;
import com.njcn.csharmonic.service.OfflineDataUploadService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 类的介绍：离线数据上传解析控制类
 *
 * @author gfh
 * @version 1.0.0
 * @createTime 2024/7/22 13:56
 */
@Slf4j
@RestController
@RequestMapping("/offlineDataUpload")
@Api(tags = "离线数据上传")
@AllArgsConstructor
public class OfflineDataUploadController extends BaseController {

    private final OfflineDataUploadService offlineDataUploadService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping(value = "/uploadAnalysis",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @ApiOperation("解析上传的文件")
    public HttpResult<byte[]> uploadAnalysis(@RequestPart("files") List<MultipartFile> files,@RequestParam("type") String type) throws Exception{
        String methodDescribe = getMethodDescribe("uploadAnalysis");
        byte[] result = offlineDataUploadService.uploadAnalysis(files,type);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping(value = "/makeUpData")
    @ApiOperation("补招数据-界面")
    @ApiImplicitParam(name = "lineId", value = "监测点id", required = true)
    public HttpResult<List<MakeUpVo>> makeUpData(@RequestParam("lineId") String lineId){
        String methodDescribe = getMethodDescribe("makeUpData");
        List<MakeUpVo> list = offlineDataUploadService.getMakeUpData(lineId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping(value = "/askDirOrFile")
    @ApiOperation("询问装置目录/文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "nDid", value = "装置nDid", required = true, paramType = "query"),
            @ApiImplicitParam(name = "prjName", value = "项目名称", required = true, paramType = "query"),
            @ApiImplicitParam(name = "path", value = "文件路径/文件名", required = true, paramType = "query"),
            @ApiImplicitParam(name = "fileType", value = "文件类型", required = true, paramType = "query")
    })
    public HttpResult<List<MakeUpVo>> askDirOrFile(@RequestParam("nDid") String nDid, @RequestParam("prjName") String prjName, @RequestParam("path") String path, @RequestParam("fileType") String fileType) {
        String methodDescribe = getMethodDescribe("askDirOrFile");
        List<MakeUpVo> list = offlineDataUploadService.askDirOrFile(nDid,prjName,path,fileType);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping(value = "/makeUp")
    @ApiOperation("设备补召")
    @ApiImplicitParam(name = "param", value = "补招参数", required = true)
    public HttpResult<String> makeUp(@RequestBody MakeUpParam param) {
        String methodDescribe = getMethodDescribe("makeUp");
        boolean result = offlineDataUploadService.startMakeUpData(param);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "文件补召中,请稍后", methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "文件补召失败", methodDescribe);
        }
    }

}
