package com.sunda.spmsweb.overseacontroller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmsorder.entity.OrderKeyValueConfig;
import com.sunda.spmsorder.service.IFileOperationService;
import com.sunda.spmsorder.service.IOrderKeyValueConfigService;
import com.sunda.spmsoversea.dto.*;
import com.sunda.spmsoversea.excel.ConsumptionRecordExcel;
import com.sunda.spmsoversea.excel.InventoryAgeExcel;
import com.sunda.spmsoversea.excel.SapBoxNoteDtlExcel;
import com.sunda.spmsoversea.service.IOverseaReportService;
import com.sunda.spmsoversea.service.IOverseaRequisitionService;
import com.sunda.spmsoversea.service.IWhsOperateLogService;
import com.sunda.spmsoversea.service.IZSpmsGetKulingService;
import com.sunda.spmsweb.util.ExcelUtil;
import com.sunda.spmsweb.util.JWTUtil;
import com.sunda.spmswms.service.ISapBoxNoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @program: spms
 * @description:
 * @author: Wayne Wu
 * @create: 2022-01-11 09:59
 **/
@RestController
@RequestMapping("/overseaReport")
@Api(tags = "海外仓报表", description = "海外仓报表")
@Slf4j
public class OverseaReportController {

    @Autowired
    IOverseaReportService iOverseaReportService;
    
    @Autowired
    IFileOperationService iFileOperationService;


    @Autowired
    ISapBoxNoteService iSapBoxNoteService;

    @Autowired
    IOverseaRequisitionService iOverseaRequisitionService;

    @Autowired
    IWhsOperateLogService iWhsOperateLogService;
    @Autowired
    IOrderKeyValueConfigService iOrderKeyValueConfigService;

    @Autowired
    IZSpmsGetKulingService spmsGetKulingService;

    @RequestMapping("/getInventoryAge")
    @ApiOperation(value = "获取库龄报表(按物料)", notes = "获取库龄报表\n" +
            "工厂代码必输，仓库代码、物料编号可选输入。示例参数：\n" +
            "werks = CN01，whsLocationCode = 1061，materialNo = 120000427\n" +
            "days 为库龄筛选天数，默认传 0 查所有；", httpMethod = "POST")
    @RequiresPermissions("overseaReport-getInventoryAge")
    public ResponseResult getInventoryAge(@RequestParam String werks,
                                          String whsLocationCode,
                                          String materialNo,
                                          Integer days){
        try {
            if (StringUtils.isEmpty(werks)){
                return ResponseResult.error("工厂不允许为空");
            }
            return ResponseResult.success().add("inventoryAgeList",
                    iOverseaReportService.getInventoryAge(werks, whsLocationCode, materialNo, days));
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    /**
     * 导出车库龄报表
     */
    @RequestMapping("/exportInventoryAge")
    @ApiOperation(value = "导出库龄报表(按物料)", notes = "获取库龄报表\n" +
            "工厂代码必输，仓库代码、物料编号可选输入。示例参数：\n" +
            "werks = CN01，whsLocationCode = 1061，materialNo = 120000427\n" +
            "days 为库龄筛选天数，默认传 0 查所有；", httpMethod = "POST")
    public void exportInventoryAge(@RequestParam String werks,
                             String whsLocationCode,
                             String materialNo,
                             Integer days, HttpServletResponse response) {
        try {
            if (StringUtils.isEmpty(werks)){
                throw new Exception("工厂不允许为空");
            }
            List<Map<String,Object>> result = iOverseaReportService.getInventoryAge(werks, whsLocationCode, materialNo, days);
            List<InventoryAgeExcel> itemList = new ArrayList<InventoryAgeExcel>();
            if(result!=null && result.size()>0) {
                for (int i = 0; i < result.size(); i++) {
                    Map<String,Object> map = (Map<String,Object>) result.get(i);
                    InventoryAgeExcel report = JSONObject.parseObject(JSONObject.toJSONString(map), InventoryAgeExcel.class);
                    itemList.add(report);
                }
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            String dateTime = sdf.format(new Date() );
            ExcelUtil.export(response, "InventoryAge" + dateTime, "bodyData", itemList, InventoryAgeExcel.class);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 导出箱码物料详情信息
     */
    @RequestMapping("/exportDnMaterialDtl")
    @ApiOperation(value = "根据箱码获取物料详情信息", notes = "根据箱码获取物料详情信息 \n" +
            "boxNote, 包装单号示例：ZX-10215800001-0404 \n")
    public void exportDnMaterialDtl(@RequestParam String boxNote, HttpServletResponse response) {
        try {
            List<Map<String, Object>> result = iSapBoxNoteService.getDnMaterialDtl(boxNote);
            List<SapBoxNoteDtlExcel> itemList = new ArrayList<SapBoxNoteDtlExcel>();
            if(result!=null && result.size()>0) {
                for (int i = 0; i < result.size(); i++) {
                    Map<String,Object> map = (Map<String,Object>) result.get(i);
                    SapBoxNoteDtlExcel report = JSONObject.parseObject(JSONObject.toJSONString(map), SapBoxNoteDtlExcel.class);
                    itemList.add(report);
                }
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            String dateTime = sdf.format(new Date() );
            ExcelUtil.export(response, "SapBoxNoteDtl" + dateTime, "bodyData", itemList, SapBoxNoteDtlExcel.class);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @RequestMapping("/getInventoryAgeBox")
    @ApiOperation(value = "获取库龄报表(按箱码)", notes = "获取库龄报表\n" +
            "工厂代码默认CN01，仓库代码、箱码可选输入。示例参数：\n" +
            "werks = CN01，whsLocationCode = 1061，boxNote = BJ-1180114586-0101\n" +
            "days 为库龄筛选天数，默认传 0 查所有；", httpMethod = "POST")
    @RequiresPermissions("overseaReport-getInventoryAgeBox")
    public ResponseResult getInventoryAgeBox(String whsLocationCode,
                                          String boxNote,
                                             Integer days){
        try {
            return ResponseResult.success().add("inventoryAgeList",
                    iOverseaReportService.getBoxInventoryAge("CN01", whsLocationCode, boxNote, days));
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getConsumptionRecord")
    @ApiOperation(value = "获取耗用记录报表", notes = "获取耗用记录报表\n" +
            "所有参数可选输入。示例参数：\n" +
            "werks = TF02，whsLocationCode = 1006，\n" +
            "materialNo = 170003956，beginDate = 2021-12-01，endDate = 2022-01-12", httpMethod = "POST")
    @RequiresPermissions("overseaReport-getConsumptionRecord")
    public ResponseResult getConsumptionRecord(@RequestBody OverseaConsumptionDTO overseaConsumptionDTO){
        try {
            return ResponseResult.success().add("consumptionRecordList",
                    iOverseaReportService.getConsumptionRecord(overseaConsumptionDTO));
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    /**
     * 导出耗用记录报表
     */
    @RequestMapping("/exportConsumptionRecord")
    @ApiOperation(value = "导出耗用记录报表", notes = "获取耗用记录报表\n" +
            "所有参数可选输入。示例参数：\n" +
            "werks = TF02，whsLocationCode = 1006，\n" +
            "materialNo = 170003956，beginDate = 2021-12-01，endDate = 2022-01-12", httpMethod = "POST")
    //public void exportConsumptionRecord(HttpServletResponse response) {
    public void exportConsumptionRecord(@RequestBody OverseaConsumptionDTO overseaConsumptionDTO, HttpServletResponse response) {
        try {
            //OverseaConsumptionDTO overseaConsumptionDTO = new OverseaConsumptionDTO();
            //overseaConsumptionDTO.setWerks("GF03");
            //overseaConsumptionDTO.setWhsLocationCode("1006");
            List<ConsumptionRecordExcel> itemList = new ArrayList<ConsumptionRecordExcel>();
            List<Map<String, Object>> result = iOverseaReportService.getConsumptionRecord(overseaConsumptionDTO);
            if(result!=null && result.size()>0) {
                for (int i = 0; i < result.size(); i++) {
                    Map<String,Object> map = (Map<String,Object>) result.get(i);
                    ConsumptionRecordExcel report = JSONObject.parseObject(JSONObject.toJSONString(map), ConsumptionRecordExcel.class);
                    itemList.add(report);
                }
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            String dateTime = sdf.format(new Date() );
            ExcelUtil.export(response, "ConsumptionRecord" + dateTime, "bodyData", itemList, ConsumptionRecordExcel.class);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @RequestMapping("/getToDoTasks")
    @ApiOperation(value = "获取首页待办", notes = "获取机电主任首页待办\n" +
            "机电主任登录首页信息统计，首页待办项信息展示：\n" +
            "     1.(机电主任)需求提报单审批：获取当前人关联工厂下待审批的车间请购单数量；跨工厂合并，全周期；orderWorkshopToDoItems；\n" +
            "     2.(机电主任)工厂请购单：获取本人创建的 待提交/待重提SRM/OA审批不通过 的工厂请购单数量；跨工厂合并，全周期；orderWerksToDoItems；\n" +
            "                 各状态单据量；跨工厂合并、近30天；orderWerksQuantityEachStatus；\n" +
            "     3.非目录物料申请单：待提交——获取本人创建的非目录物料申请 待提交OA 的数量；跨工厂合并，全周期；materialApplicationToDoItems；\n" +
            "                      编码未发放——获取本人创建的非目录物料申请，编码为空的明细行数；跨工厂合并，全周期；materialApplicationWithoutMaterialNo；\n" +
            "     4.车间领用单：待审批——获取当前人关联工厂待审批的领用单；跨工厂合并，全周期；overseaRequisitionToDoItems；\n" +
            "                 待领用——获取本人创建的审批通过但未生成出库任务的领用任务；跨工厂合并，全周期；overseaRequisitionWithoutOut；\n" +
            "     5.(车间主任)需求提报单审批：获取本人创建的需求申请单，待提交 和 审批不通过、已提交三个状态下数量，本人关联工厂内数据；跨工厂合并，全周期；orderWorkshopQuantityEachStatus；" +
            "示例参数：userId = 999947；\n", httpMethod = "POST")
    public ResponseResult getToDoTasks(String userId){
        try {
            if (StringUtils.isEmpty(userId)){
                userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            }
            return ResponseResult.success().add("getToDoTasks",
                    iOverseaReportService.getToDoTasks(userId));
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getOrderWorkshopTrace")
    @ApiOperation(value = "车间请购单整单追溯查询", notes = "海外仓首页，车间请购单整单追溯查询\n" +
            "海外仓首页，车间请购单整单追溯查询；\n" +
            "按车间请购单头表检查，有工厂请购单的，会向SRM请求该工厂请购单整单采购状态；" +
            "示例参数：\n" +
            "{\n" +
            "\t\"beginDate\": \"2021-11-01\",\n" +
            "\t\"endDate\": \"2022-01-01\",\n" +
            "\t\"current\": 1,\n" +
            "\t\"size\": 10,\n" +
            "\t\"werks\": \"GF03\",\n" +
            "\t\"workshopCode\": \"\",\n" +
            "\t\"spmsWsId\": \"\",\n" +
            "\t\"userId\": \"\",\n" +
            "\t\"urgency\": \"\",\n" +
            "\t\"status\": \"\"\n" +
            "}", httpMethod = "POST")
    public ResponseResult getOrderWorkshopTrace(@RequestBody WelcomePageSearchDTO welcomePageSearchDTO){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iOverseaReportService.getOrderWorkshopTrace(welcomePageSearchDTO, userId);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getOrderWerksTrace")
    @ApiOperation(value = "工厂请购单整单追溯查询", notes = "海外仓首页，工厂请购单整单追溯查询\n" +
            "海外仓首页，工厂请购单整单追溯查询；\n" +
            "工厂请购单逐行都会向SRM请求该工厂请购单整单采购状态；" +
            "示例参数：\n" +
            "{\n" +
            "\t\"beginDate\": \"2021-11-01\",\n" +
            "\t\"endDate\": \"2022-01-01\",\n" +
            "\t\"current\": 1,\n" +
            "\t\"size\": 10,\n" +
            "\t\"werks\": \"GF03\",\n" +
            "\t\"spmsId\": \"\",\n" +
            "\t\"urgency\": \"\",\n" +
            "\t\"status\": \"\"\n" +
            "}", httpMethod = "POST")
    @RequiresPermissions("overseaReport-getOrderWerksTrace")
    public ResponseResult getOrderWerksTrace(@RequestBody WelcomePageWerksOrderDTO welcomePageWerksOrderDTO){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iOverseaReportService.getOrderWerksTrace(welcomePageWerksOrderDTO, userId);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getOrderWerksBoxTrace")
    @ApiOperation(value = "根据工厂请购单uuid查询全流程追溯", notes = "根据工厂请购单uuid查询全流程追溯\n" +
            "示例参数：uuid = 44140f8ef76c499d94cdae59a88a3800; 79c5236f317f4f3fbcecb535d16649e5; cfc8ddf6389e45dda376a7f517341b1f;\n " +
            "TF02-2021-020，箱码包含状态：1——箱码待生成，2——自管仓待到货，3——自管仓，4——盘亏，5——自管仓已发出，6——海外仓已到货；\n" +
            "\n", httpMethod = "POST")
    public ResponseResult getOrderTrace(@RequestParam String uuid){
        try {
            //String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iOverseaReportService.getOrderWerksBoxTrace(uuid);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getOrderStatusFromSrm")
    @ApiOperation(value = "工厂请购单号向SRM请求整单状态", notes = "根据工厂请购单单号，向SRM请求SRM系统整单状态\n" +
            "示例参数：spmsId = TF02-2021-020;\n " +
            "\n", httpMethod = "POST")
    public ResponseResult getOrderStatusFromSrm(@RequestParam String spmsId){
        try {
            //String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iOverseaReportService.getOrderStatusFromSrm(spmsId);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getOrderKeyDates")
    @ApiOperation(value = "获取单据全生命周期关键节点", notes = "获取单据全生命周期关键节点\n" +
            "根据工厂、工厂请购单号、日期区间，查询符合条件下所有请购单全生命周期关键节点日期数据；\n" +
            "示例参数：\n " +
            "{\n" +
            "\t\"werks\": \"TF01\",\n" +
            "\t\"spmsId\": \"TF01-2021-009\",\n" +
            "\t\"beginDate\": \"2021-05-01\",\n" +
            "\t\"endDate\": \"2021-07-15\"\n" +
            "}\n" +
            "返回关键字段参数说明：\n" +
            "orderWerksId-工厂请购单号； orderWerksRowId-工厂请购单行号； orderWerksApplicationDate-工厂请购单创建日期； orderWerksFieldForOa-内部订单号； \n" +
            "orderWorkshopId-车间请购单号； orderWorkshopRowId-车间请购单行号； orderWorkshopApplicationDate-车间请购单创建日期；orderWorkshopSubject-车间请购单标题；\n" +
            "safetyQtyBasicUnit-工厂下物料安全库存； werksInventory-工厂下物料总库存； wayQuantity-在途数量； boxNoteItem-箱码明细行号；\n" +
            "deliveryNote-国内交货单号； packageList-装箱单号； \n" +
            "domesticArrivalDate-国内到货日期； domesticDeliveryDate-国内出库日期； overseaArrivalDate-海外到货日期； \n" +
            "daysSpent-耗费时间（海外收货日期 - 车间请购单创建日期）；\n" +
            "\n", httpMethod = "POST")
    @RequiresPermissions("overseaReport-getOrderKeyDates")
    public ResponseResult getOrderKeyDates(@RequestBody OverseaReport overseaReport){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iOverseaReportService.getOrderKeyDates(overseaReport, userId);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @SuppressWarnings("unchecked")
    @RequestMapping("/exportOrderKeyDates")
    @ApiOperation(value = "导出单据全生命周期关键节点", notes = "导出单据全生命周期关键节点\n" +
            "根据工厂、工厂请购单号、日期区间，查询符合条件下所有请购单全生命周期关键节点日期数据；\n" +
            "示例参数：\n " +
            "{\n" +
            "\t\"werks\": \"TF01\",\n" +
            "\t\"spmsId\": \"TF01-2021-009\",\n" +
            "\t\"beginDate\": \"2021-05-01\",\n" +
            "\t\"endDate\": \"2021-07-15\"\n" +
            "}\n" +
            "返回关键字段参数说明：\n" +
            "orderWerksId-工厂请购单号； orderWerksRowId-工厂请购单行号； orderWerksApplicationDate-工厂请购单创建日期； orderWerksFieldForOa-内部订单号； \n" +
            "orderWorkshopId-车间请购单号； orderWorkshopRowId-车间请购单行号； orderWorkshopApplicationDate-车间请购单创建日期；orderWorkshopSubject-车间请购单标题；\n" +
            "safetyQtyBasicUnit-工厂下物料安全库存； werksInventory-工厂下物料总库存； wayQuantity-在途数量； boxNoteItem-箱码明细行号；\n" +
            "deliveryNote-国内交货单号； packageList-装箱单号； \n" +
            "domesticArrivalDate-国内到货日期； domesticDeliveryDate-国内出库日期； overseaArrivalDate-海外到货日期； \n" +
            "daysSpent-耗费时间（海外收货日期 - 车间请购单创建日期）；\n" +
            "\n", httpMethod = "POST")
    public ResponseResult exportOrderKeyDates(@RequestBody OverseaReport overseaReport){
        try {
//            if (overseaReport == null || StringUtils.isEmpty(overseaReport.getWerks())){
//                return ResponseResult.error("请求工厂不能为空");
//            }

            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            List<Map<String, Object>> orderKeyDates = iOverseaReportService.getOrderKeyDatesList(overseaReport, userId);

            String filename = "orderKeyDatesList_" + System.currentTimeMillis()+".xlsx";
            // 1.附件缓存路径
            String excelPath = iFileOperationService.saveOrderKeyDatesExcel(orderKeyDates, filename);
            if (StringUtils.isEmpty(excelPath)){
                return ResponseResult.error("附件创建失败");
            }
            // 2.上传附件至minIO文件服务器
            String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
            if (fileUrl.isEmpty()){
                return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
            }
            // 3.返回附件地址，上传OA
            return ResponseResult.success()
                    .add("fileUrl",fileUrl);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
    @RequestMapping("/getSendSapFailedList")
    @ApiOperation(value = "获取提交SAP失败的单据", notes = "获取提交SAP失败的单据\n" +
            "所有参数可选输入。示例参数：\n" +
            "{\n" +
            "werks = TF02，spmsId = TF01-2021-018，\n" +
            "beginDate = 2021-12-01，endDate = 2022-01-12" +
            "}\n" , httpMethod = "POST")
    @RequiresPermissions("overseaReport-getSendSapFailedList")
    public ResponseResult getSendSapFailedList(@RequestBody OverseaReport overseaReport){
        try {
            return ResponseResult.success().add("sendSapFailedList", iOverseaReportService.getSendSapFailedListByRecord(overseaReport));
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
    @SuppressWarnings("unchecked")
	@RequestMapping("/exportSendSapFailedExcel")
    @ApiOperation(value = "提交SAP失败单据导出EXCEL", notes = "提交SAP失败单据导出EXCEL\n" +
    		"所有参数可选输入。示例参数：\n" +
            "{\n" +
            "werks = TF02，spmsId = TF01-2021-018，\n" +
            "beginDate = 2021-12-01，endDate = 2022-01-12" +
            "}\n", httpMethod = "POST")
    @RequiresPermissions("overseaReport-exportSendSapFailedExcel")
    public ResponseResult exportSendSapFailedExcel(@RequestBody OverseaReport overseaReport){
        try {
        	overseaReport.setCurrent(1);
        	overseaReport.setSize(Integer.MAX_VALUE);
            String filename = "sendSapFailedList_" + System.currentTimeMillis()+".xlsx";
            // 1.附件缓存路径
            String excelPath = iFileOperationService.saveSendSapFailedExcel(iOverseaReportService.getSendSapFailedListByRecord(overseaReport).getRecords(), filename);
            if (StringUtils.isEmpty(excelPath)){
                return ResponseResult.error("附件创建失败");
            }
            // 2.上传附件至minIO文件服务器
            String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
            if (fileUrl.isEmpty()){
                return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
            }
            // 3.返回附件地址，上传OA
            return ResponseResult.success()
                    .add("fileUrl",fileUrl);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
    @RequestMapping("/getMaterialPhotos")
    @ApiOperation(value = "获取物料图片覆盖报表", notes = "获取物料图片覆盖报表\n" +
    		"所有参数可选输入。示例参数：\n" +
            "{\n" +
            "werks = TF02,\n" +
            "materialNo = 210017651" +
            "}\n", httpMethod = "POST")
    @RequiresPermissions("overseaReport-getMaterialPhotos")
    public ResponseResult getMaterialPhotos(@RequestBody OverseaConsumptionDTO dto){
        try {
            return iOverseaReportService.getMaterialPhotosList(dto);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
	@RequestMapping("/exportMaterialPhotosExcel")
    @ApiOperation(value = "物料图片覆盖报表导出EXCEL", notes = "物料图片覆盖报表导出EXCEL\n" +
    		"所有参数可选输入。示例参数：\n" +
            "{\n" +
            "materialNo = 210017651" +
            "}\n", httpMethod = "POST")
	@RequiresPermissions("overseaReport-exportMaterialPhotosExcel")
    public ResponseResult exportMaterialPhotosExcel(@RequestBody OverseaConsumptionDTO dto){
        try {
        	dto.setCurrent(1);
        	dto.setSize(Integer.MAX_VALUE);
            String filename = "materialPhotosList_" + System.currentTimeMillis()+".xlsx";
            // 1.附件缓存路径
            String excelPath = iFileOperationService.saveMaterialPhotosExcel(iOverseaReportService.getMaterialPhotosList(dto), filename);
            if (StringUtils.isEmpty(excelPath)){
                return ResponseResult.error("附件创建失败");
            }
            // 2.上传附件至minIO文件服务器
            String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
            if (fileUrl.isEmpty()){
                return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
            }
            // 3.返回附件地址，上传OA
            return ResponseResult.success()
                    .add("fileUrl",fileUrl);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
	
	@RequestMapping("/getMaterialStockQtyDiffer")
    @ApiOperation(value = "获取SPMS与SAP库存差异报表", notes = "获取SPMS与SAP库存差异报表\n" +
    		"所有参数可选输入。示例参数：\n" +
            "{\n" +
            "werks = TF02,\n" +
            "whsLocationCode = 1006,\n" +
            "differNum = 0,\n" +
            "materialNo = 210017651" +
            "}\n", httpMethod = "POST")
	@RequiresPermissions("overseaReport-getMaterialStockQtyDiffer")
    public ResponseResult getMaterialStockQtyDiffer(@RequestBody OverseaConsumptionDTO dto){
        try {
            return iOverseaReportService.getMaterialStockQtyDifferList(dto);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
	
	@RequestMapping("/exportMaterialStockQtyDifferExcel")
    @ApiOperation(value = "SPMS与SAP库存差异报表导出EXCEL", notes = "SPMS与SAP库存差异报表导出EXCEL\n" +
    		"所有参数可选输入。示例参数：\n" +
            "{\n" +
            "werks = TF02,\n" +
            "whsLocationCode = 1006,\n" +
            "differNum = 0,\n" +
            "materialNo = 210017651" +
            "}\n", httpMethod = "POST")
	@RequiresPermissions("overseaReport-exportMaterialStockQtyDifferExcel")
    public ResponseResult exportMaterialStockQtyDifferExcel(@RequestBody OverseaConsumptionDTO dto){
        try {
        	if (StringUtils.isEmpty(dto.getWerks())) {
    			return ResponseResult.error("请求工厂不能为空");
    		}
    		if (StringUtils.isEmpty(dto.getWhsLocationCode())) {
    			return ResponseResult.error("仓库编号不能为空");
    		}
        	dto.setCurrent(1);
        	dto.setSize(Integer.MAX_VALUE);
            String filename = "MaterialStockQtyDiffer_" + System.currentTimeMillis()+".xlsx";
            // 1.附件缓存路径
            String excelPath = iFileOperationService.saveMaterialStockQtyDifferExcel(iOverseaReportService.getMaterialStockQtyDifferList(dto), filename);
            if (StringUtils.isEmpty(excelPath)){
                return ResponseResult.error("附件创建失败");
            }
            // 2.上传附件至minIO文件服务器
            String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
            if (fileUrl.isEmpty()){
                return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
            }
            // 3.返回附件地址，上传OA
            return ResponseResult.success()
                    .add("fileUrl",fileUrl);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }


    @RequestMapping("/getIntransitData")
    @ApiOperation(value = "获取SAP在途数据报表", notes = "获取SAP在途数据报表\n" +
            "所有参数可选输入。示例参数：\n" +
            "{\n" +
            "werks = TF02,\n" +
            "receiveWerks = TF02,\n" +
            "purchaseNo = 202211210001,\n" +
            "sapDeliveryNote = 202211210001,\n" +
            "beginDate = 0,\n" +
            "endDate = 0,\n" +
            "boxNote = PL0017651,\n" +
            "materialNo = 210017651" +
            "}\n", httpMethod = "POST")
    @RequiresPermissions("overseaReport-getIntransitData")
    public ResponseResult getIntransitData(@RequestBody OverseaConsumptionDTO dto){
        try {
            return iOverseaReportService.getIntransitData(dto);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }


    @RequestMapping("/exportIntransitDataExcel")
    @ApiOperation(value = "导出SAP在途数据报表", notes = "导出SAP在途数据报表\n" +
            "所有参数可选输入。示例参数：\n" +
            "{\n" +
            "werks = TF02,\n" +
            "receiveWerks = TF02,\n" +
            "purchaseNo = 202211210001,\n" +
            "sapDeliveryNote = 202211210001,\n" +
            "beginDate = 0,\n" +
            "endDate = 0,\n" +
            "boxNote = PL0017651,\n" +
            "materialNo = 210017651" +
            "}\n", httpMethod = "POST")
    public ResponseResult exportIntransitDataExcel(@RequestBody OverseaReceiptAndDeliverySearchDTO dto){
        try {
//            String receiveWerks = dto.getReceiveWerks();
//            if (StringUtils.isEmpty(receiveWerks)) {
//                ResponseResult.error("收货工厂不能为空");
//            }
//            dto.setCurrent(1);
//            dto.setSize(Integer.MAX_VALUE);
            String filename = "IntransitData_" + System.currentTimeMillis()+".xlsx";
            // 1.附件缓存路径
            String excelPath = iFileOperationService.saveIntransitDataExcel(iOverseaRequisitionService.getReceiptAndDeliveryReports(dto), filename);
            if (StringUtils.isEmpty(excelPath)){
                return ResponseResult.error("附件创建失败");
            }
            // 2.上传附件至minIO文件服务器
            String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
            if (fileUrl.isEmpty()){
                return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
            }
            // 3.返回附件地址，上传OA
            return ResponseResult.success()
                    .add("fileUrl",fileUrl);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }



    @RequestMapping("/exportWhsOperateLogExcel")
    @ApiOperation(value = "导出出入库明细", notes = "导出出入库明细\n" +
            "海外仓日志查询，查询条件固定后端控制 documentType = 4，返回结构带关联单据号；\n" +
            "返回参数说明：relateDocumentNumber 日志记录关联单据号主键(uuid或DN)；\n" +
            "            overseaWhsInNo 入库任务单号；\n" +
            "            sapDeliveryNote 其他收货交货单号；\n" +
            "            overseaWhsOutNo 出库任务单号；\n" +
            "            overseaOtherTaskNo 其他出入库任务单号；\n" +
            "            overseaWhsMoveNo 调拨任务单号；\n" +
            "示例参数说明：createUser 创建人工号/创建人姓名；\n" +
            "            searchInfo 物料编号/物料英文描述/物料中文描述；\n" +
            "            movementType 移动类型；\n" +
            "示例参数：\n" +
            "{\n" +
            "\t\"werks\": \"TF02\",\n" +
            "\t\"whsLocationCode\": \"1006\",\n" +
            "\t\"storageArea\": \"\",\n" +
            "\t\"storageNo\": \"\",\n" +
            "\t\"createUser\": \"\",\n" +
            "\t\"searchInfo\": \"\",\n" +
            "\t\"movementType\": \"\",\n" +
            "\t\"beginDate\": \"2022-01-22 12:00:00\",\n" +
            "\t\"endDate\": \"2022-01-24 10:00:00\",\n" +
            "\t\"current\": 1,\n" +
            "\t\"size\": 20\n" +
            "}", httpMethod = "POST")
    @RequiresPermissions("overseaReport-exportWhsOperateLogExcel")
    public ResponseResult exportWhsOperateLogExcel(@RequestBody WhsOperateLogSearchDTO dto){
        try {
            String filename = "WhsOperateLog_" + System.currentTimeMillis()+".xlsx";

            List<OrderKeyValueConfig> orderKeyValueConfigs = iOrderKeyValueConfigService.getByFieldKey("mobileType");
            Map<String, String> map = new HashMap<>();
            for (OrderKeyValueConfig item : orderKeyValueConfigs){
                map.put(item.getKeyCode(), item.getKeyCodeDesc());
            }

            // 1.附件缓存路径
            String excelPath = iFileOperationService.saveWhsOperateLogExcel(iWhsOperateLogService.getWhsOperateLogList(dto,map), filename);
            if (StringUtils.isEmpty(excelPath)){
                return ResponseResult.error("附件创建失败");
            }
            // 2.上传附件至minIO文件服务器
            String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
            if (fileUrl.isEmpty()){
                return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
            }
            // 3.返回附件地址，上传OA
            return ResponseResult.success()
                    .add("fileUrl",fileUrl);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getKulingListByRecord")
    @ApiOperation(value = "获取物料库龄的单据", notes = "获取物料库龄的单据\n" +
            "示例参数：工厂:werks=ZM01,仓库地点:lgort=1000,工厂:物料=311000259,\" +\n" +
            "库龄天数：30 days：labst=30，60 days：labst=60，90 days：labst=90，120 days：labst=120，\" +\n" +
            "180 days：labst=180，365 days：labst=365，365 days以上：labst=366\n"  , httpMethod = "POST")
    //@RequiresPermissions("overseaReport-getKulingListByRecord")
    public ResponseResult getKulingListByRecord(@RequestBody KulingReport kulingPage){
        try {
            String werks = kulingPage.getWerks();
            if (StringUtils.isEmpty(werks)) {
                ResponseResult.error("请求工厂不能为空");
            }
            return ResponseResult.success().add("list", spmsGetKulingService.getKulingListByRecord(kulingPage));
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }



    @RequestMapping("/exportKulingListExcel")
    @ApiOperation(value = "EXCEL导出库龄报表", notes = "传入:工厂:werks=ZM01,仓库地点:lgort=1000,工厂:物料=311000259," +
            "库龄天数：30 days：labst=30，60 days：labst=60，90 days：labst=90，120 days：labst=120，" +
            "180 days：labst=180，365 days：labst=365，365 days以上：labst=366" , httpMethod = "POST")
    public void exportKulingListExcel(@RequestBody KulingReport kulingPage, HttpServletResponse response) {
        List<SpmsKulingReportExcel> list = spmsGetKulingService.getKulingListByRecordExcel(kulingPage);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String dateTime = sdf.format(new Date() );
        ExcelUtil.export(response, "物料库龄报表" + dateTime, "WerksAllStockAge", list, SpmsKulingReportExcel.class);
    }

    @RequestMapping("/selectDeliveryReportList")
    @ApiOperation(value = "查询发货效率报表接口", notes = "查询发货效率报表接口\n" +
	    "示例参数：\n" +
	    "{\n" +
		    "\t\"工厂werks = TF02,\n" +
		    "\t\"仓库whsLocationCode = TF02,\n" +
		    "\t\"单据类型:documentType = 1-领用出库,\n" +
		    "\t\"统计维度statisticalType = 1-发货效率,\n" +
		    "\t\"开始时间beginDate = 2024-01-01,\n" +
		    "\t\"结束时间endDate = 2024-04-01\n" +
	    "}\n", httpMethod = "POST")
    public ResponseResult selectDeliveryReportList(@RequestBody JSONObject jsonObject){
        try {
        	String statisticalType = jsonObject.getString("statisticalType");
            if (StringUtils.isEmpty(statisticalType)) {
                return ResponseResult.error("请选择统计维度");
            }
            String werks = jsonObject.getString("werks");
            if (StringUtils.isEmpty(werks)) {
            	return ResponseResult.error("请选择工厂");
            }
            String whsLocationCode = jsonObject.getString("whsLocationCode");
            if (StringUtils.isEmpty(whsLocationCode)) {
            	return ResponseResult.error("请选择仓库");
            }
            String documentType = jsonObject.getString("documentType");
            if (StringUtils.isEmpty(documentType)) {
            	return ResponseResult.error("请选择单据类型");
            }
            return iOverseaReportService.getDeliveryReportList(jsonObject);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
    @RequestMapping("/exportDeliveryReportListExcel")
    @ApiOperation(value = "导出发货效率统计报表接口", notes = "导出发货效率统计报表接口\n" +
    	    "示例参数：\n" +
    	    "{\n" +
    		    "\t\"工厂werks = TF02,\n" +
    		    "\t\"仓库whsLocationCode = TF02,\n" +
    		    "\t\"单据类型:documentType = 1-领用出库,\n" +
    		    "\t\"统计维度statisticalType = 1-发货效率,\n" +
    		    "\t\"开始时间beginDate = 2024-01-01,\n" +
    		    "\t\"结束时间endDate = 2024-04-01\n" +
    	    "}\n", httpMethod = "POST")
    public ResponseResult exportDeliveryReportListExcel(@RequestBody JSONObject jsonObject){
        try {
        	String statisticalType = jsonObject.getString("statisticalType");
            if (StringUtils.isEmpty(statisticalType)) {
                return ResponseResult.error("请选择统计维度");
            }
            String werks = jsonObject.getString("werks");
            if (StringUtils.isEmpty(werks)) {
            	return ResponseResult.error("请选择工厂");
            }
            String whsLocationCode = jsonObject.getString("whsLocationCode");
            if (StringUtils.isEmpty(whsLocationCode)) {
            	return ResponseResult.error("请选择仓库");
            }
            String documentType = jsonObject.getString("documentType");
            if (StringUtils.isEmpty(documentType)) {
            	return ResponseResult.error("请选择单据类型");
            }
            String filename = "DeliveryRepor_" + System.currentTimeMillis()+".xlsx";
            // 1.附件缓存路径
            String excelPath = iFileOperationService.saveDeliveryReportExcel(iOverseaReportService.getDeliveryReportList(jsonObject), filename);
            if (StringUtils.isEmpty(excelPath)){
                return ResponseResult.error("附件创建失败");
            }
            // 2.上传附件至minIO文件服务器
            String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
            if (fileUrl.isEmpty()){
                return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
            }
            // 3.返回附件地址，上传OA
            return ResponseResult.success()
                    .add("fileUrl",fileUrl);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
    @RequestMapping("/exportDeliveryTargetReportExcel")
    @ApiOperation(value = "导出发货效率统计指标数据接口", notes = "导出发货效率统计指标数据接口\n" +
    	    "示例参数：\n" +
    	    "{\n" +
    		    "\t\"工厂werks = TF02,\n" +
    		    "\t\"仓库whsLocationCode = TF02,\n" +
    		    "\t\"单据类型:documentType = 1-领用出库,\n" +
    		    "\t\"统计维度statisticalType = 1-发货效率,\n" +
    		    "\t\"开始时间beginDate = 2024-01-01,\n" +
    		    "\t\"结束时间endDate = 2024-04-01\n" +
    	    "}\n", httpMethod = "POST")
    public ResponseResult exportDeliveryTargetReportExcel(@RequestBody JSONObject jsonObject){
        try {
        	String statisticalType = jsonObject.getString("statisticalType");
            if (StringUtils.isEmpty(statisticalType)) {
                return ResponseResult.error("请选择统计维度");
            }
            String werks = jsonObject.getString("werks");
            if (StringUtils.isEmpty(werks)) {
            	return ResponseResult.error("请选择工厂");
            }
            String whsLocationCode = jsonObject.getString("whsLocationCode");
            if (StringUtils.isEmpty(whsLocationCode)) {
            	return ResponseResult.error("请选择仓库");
            }
            String documentType = jsonObject.getString("documentType");
            if (StringUtils.isEmpty(documentType)) {
            	return ResponseResult.error("请选择单据类型");
            }
            String filename = "DeliveryTarget_" + System.currentTimeMillis()+".xlsx";
            // 1.附件缓存路径
            String excelPath = iFileOperationService.saveDeliveryTargetReportExcel(iOverseaReportService.getDeliveryReportList(jsonObject), filename);
            if (StringUtils.isEmpty(excelPath)){
                return ResponseResult.error("附件创建失败");
            }
            // 2.上传附件至minIO文件服务器
            String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
            if (fileUrl.isEmpty()){
                return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
            }
            // 3.返回附件地址，上传OA
            return ResponseResult.success()
                    .add("fileUrl",fileUrl);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
    @RequestMapping("/selectReceivingGoodsReportList")
    @ApiOperation(value = "查询收货效率报表接口", notes = "查询收货效率报表接口\n" +
	    "示例参数：\n" +
	    "{\n" +
		    "\t\"工厂werks = TF02,\n" +
		    "\t\"仓库whsLocationCode = TF02,\n" +
		    "\t\"单据类型:documentType =0-所有类型、1-海运收货、2-本地采购、3-空运人带、4-海外转储,\n" +
		    "\t\"统计维度statisticalType = 2-收货效率,\n" +
		    "\t\"开始时间beginDate = 2024-01-01,\n" +
		    "\t\"结束时间endDate = 2024-04-01\n" +
	    "}\n", httpMethod = "POST")
    public ResponseResult selectReceivingGoodsReportList(@RequestBody JSONObject jsonObject){
        try {
        	String statisticalType = jsonObject.getString("statisticalType");
            if (StringUtils.isEmpty(statisticalType)) {
                return ResponseResult.error("请选择统计维度");
            }
            String werks = jsonObject.getString("werks");
            if (StringUtils.isEmpty(werks)) {
            	return ResponseResult.error("请选择工厂");
            }
            String whsLocationCode = jsonObject.getString("whsLocationCode");
            if (StringUtils.isEmpty(whsLocationCode)) {
            	return ResponseResult.error("请选择仓库");
            }
            String documentType = jsonObject.getString("documentType");
            if (StringUtils.isEmpty(documentType)) {
            	return ResponseResult.error("请选择单据类型");
            }
            return iOverseaReportService.getDeliveryReportList(jsonObject);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
    @RequestMapping("/exportReceivingGoodsReportExcel")
    @ApiOperation(value = "导出收货效率统计报表接口", notes = "导出收货效率统计报表接口\n" +
    	    "示例参数：\n" +
    	    "{\n" +
			    "\t\"工厂werks = TF02,\n" +
			    "\t\"仓库whsLocationCode = TF02,\n" +
			    "\t\"单据类型:documentType =0-所有类型、1-海运收货、2-本地采购、3-空运人带、4-海外转储,\n" +
			    "\t\"统计维度statisticalType = 2-收货效率,\n" +
			    "\t\"开始时间beginDate = 2024-01-01,\n" +
			    "\t\"结束时间endDate = 2024-04-01\n" +
		    "}\n", httpMethod = "POST")
    public ResponseResult exportReceivingGoodsReportExcel(@RequestBody JSONObject jsonObject){
        try {
        	String statisticalType = jsonObject.getString("statisticalType");
            if (StringUtils.isEmpty(statisticalType)) {
                return ResponseResult.error("请选择统计维度");
            }
            String werks = jsonObject.getString("werks");
            if (StringUtils.isEmpty(werks)) {
            	return ResponseResult.error("请选择工厂");
            }
            String whsLocationCode = jsonObject.getString("whsLocationCode");
            if (StringUtils.isEmpty(whsLocationCode)) {
            	return ResponseResult.error("请选择仓库");
            }
            String documentType = jsonObject.getString("documentType");
            if (StringUtils.isEmpty(documentType)) {
            	return ResponseResult.error("请选择单据类型");
            }
            String filename = "receivingGoodsReportReport_" + System.currentTimeMillis()+".xlsx";
            // 1.附件缓存路径
            String excelPath = iFileOperationService.saveReceivingGoodsReportExcel(iOverseaReportService.getDeliveryReportList(jsonObject), filename);
            if (StringUtils.isEmpty(excelPath)){
                return ResponseResult.error("附件创建失败");
            }
            // 2.上传附件至minIO文件服务器
            String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
            if (fileUrl.isEmpty()){
                return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
            }
            return ResponseResult.success().add("fileUrl",fileUrl);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
    @RequestMapping("/exportReceivingGoodsTargetReportExcel")
    @ApiOperation(value = "导出收货效率统计指标报表接口", notes = "导出收货效率统计指标报表接口\n" +
    		"示例参数：\n" +
    		"{\n" +
    		"\t\"工厂werks = TF02,\n" +
    		"\t\"仓库whsLocationCode = TF02,\n" +
    		"\t\"单据类型:documentType =0-所有类型、1-海运收货、2-本地采购、3-空运人带、4-海外转储,\n" +
    		"\t\"统计维度statisticalType = 2-收货效率,\n" +
    		"\t\"开始时间beginDate = 2024-01-01,\n" +
    		"\t\"结束时间endDate = 2024-04-01\n" +
    		"}\n", httpMethod = "POST")
    public ResponseResult exportReceivingGoodsTargetReportExcel(@RequestBody JSONObject jsonObject){
    	try {
    		String statisticalType = jsonObject.getString("statisticalType");
    		if (StringUtils.isEmpty(statisticalType)) {
    			return ResponseResult.error("请选择统计维度");
    		}
    		String werks = jsonObject.getString("werks");
    		if (StringUtils.isEmpty(werks)) {
    			return ResponseResult.error("请选择工厂");
    		}
    		String whsLocationCode = jsonObject.getString("whsLocationCode");
    		if (StringUtils.isEmpty(whsLocationCode)) {
    			return ResponseResult.error("请选择仓库");
    		}
    		String documentType = jsonObject.getString("documentType");
    		if (StringUtils.isEmpty(documentType)) {
    			return ResponseResult.error("请选择单据类型");
    		}
    		String filename = "receivingGoodsTargetReportReport_" + System.currentTimeMillis()+".xlsx";
    		// 1.附件缓存路径
    		String excelPath = iFileOperationService.saveReceivingGoodsTargetReportExcel(iOverseaReportService.getDeliveryReportList(jsonObject), filename);
    		if (StringUtils.isEmpty(excelPath)){
    			return ResponseResult.error("附件创建失败");
    		}
    		// 2.上传附件至minIO文件服务器
    		String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
    		if (fileUrl.isEmpty()){
    			return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
    		}
    		return ResponseResult.success().add("fileUrl",fileUrl);
    	}catch (Exception e){
    		e.printStackTrace();
    		return ResponseResult.error("请求数据失败").add("error", e.getMessage());
    	}
    }
    
    @RequestMapping("/selectPdaCoverageRateReportList")
    @ApiOperation(value = "查询PDA覆盖率报表接口", notes = "查询PDA覆盖率报表接口\n" +
	    "示例参数：\n" +
	    "{\n" +
		    "\t\"工厂werks = TF02,\n" +
		    "\t\"仓库whsLocationCode = TF02,\n" +
		    "\t\"单据类型:documentType =0-所有类型,\n" +
		    "\t\"统计维度statisticalType = 3-PDA覆盖率,\n" +
		    "\t\"开始时间beginDate = 2024-01-01,\n" +
		    "\t\"结束时间endDate = 2024-04-01,\n" +
		    "\t\"current\": 1,\n" +
            "\t\"size\": 20\n" +
	    "}\n", httpMethod = "POST")
    public ResponseResult selectPdaCoverageRateReportList(@RequestBody JSONObject jsonObject){
        try {
        	String statisticalType = jsonObject.getString("statisticalType");
            if (StringUtils.isEmpty(statisticalType)) {
                return ResponseResult.error("请选择统计维度");
            }
            String werks = jsonObject.getString("werks");
            if (StringUtils.isEmpty(werks)) {
            	return ResponseResult.error("请选择工厂");
            }
            String whsLocationCode = jsonObject.getString("whsLocationCode");
            if (StringUtils.isEmpty(whsLocationCode)) {
            	return ResponseResult.error("请选择仓库");
            }
            String documentType = jsonObject.getString("documentType");
            if (StringUtils.isEmpty(documentType)) {
            	return ResponseResult.error("请选择单据类型");
            }
            return iOverseaReportService.getDeliveryReportList(jsonObject);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
    @RequestMapping("/exportPdaCoverageRateReportExcel")
    @ApiOperation(value = "导出PDA覆盖率统计报表接口", notes = "导出PDA覆盖率统计报表接口\n" +
    	    "示例参数：\n" +
    	    "{\n" +
			    "\t\"工厂werks = TF02,\n" +
			    "\t\"仓库whsLocationCode = TF02,\n" +
			    "\t\"单据类型:documentType =0-所有类型,\n" +
			    "\t\"统计维度statisticalType = 3-PDA覆盖率,\n" +
			    "\t\"开始时间beginDate = 2024-01-01,\n" +
			    "\t\"结束时间endDate = 2024-04-01\n" +
	          "}\n", httpMethod = "POST")
    public ResponseResult exportPdaCoverageRateReportExcel(@RequestBody JSONObject jsonObject){
        try {
        	String statisticalType = jsonObject.getString("statisticalType");
            if (StringUtils.isEmpty(statisticalType)) {
                return ResponseResult.error("请选择统计维度");
            }
            String werks = jsonObject.getString("werks");
            if (StringUtils.isEmpty(werks)) {
            	return ResponseResult.error("请选择工厂");
            }
            String whsLocationCode = jsonObject.getString("whsLocationCode");
            if (StringUtils.isEmpty(whsLocationCode)) {
            	return ResponseResult.error("请选择仓库");
            }
            String documentType = jsonObject.getString("documentType");
            if (StringUtils.isEmpty(documentType)) {
            	return ResponseResult.error("请选择单据类型");
            }
            int pageSize = Integer.MAX_VALUE;
            jsonObject.put("size", pageSize);
            String filename = "PdaCoverageRateReport_" + System.currentTimeMillis()+".xlsx";
            // 1.附件缓存路径
            String excelPath = iFileOperationService.savePdaCoverageRateExcel(iOverseaReportService.getDeliveryReportList(jsonObject), filename);
            if (StringUtils.isEmpty(excelPath)){
                return ResponseResult.error("附件创建失败");
            }
            // 2.上传附件至minIO文件服务器
            String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
            if (fileUrl.isEmpty()){
                return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
            }
            // 3.返回附件地址，上传OA
            return ResponseResult.success()
                    .add("fileUrl",fileUrl);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
    @RequestMapping("/exportPdaCoverageRateTargetReportExcel")
    @ApiOperation(value = "导出PDA覆盖率统计指标接口", notes = "导出PDA覆盖率统计指标接口\n" +
    		"示例参数：\n" +
    		"{\n" +
    		"\t\"工厂werks = TF02,\n" +
    		"\t\"仓库whsLocationCode = TF02,\n" +
    		"\t\"单据类型:documentType =0-所有类型,\n" +
    		"\t\"统计维度statisticalType = 3-PDA覆盖率,\n" +
    		"\t\"开始时间beginDate = 2024-01-01,\n" +
    		"\t\"结束时间endDate = 2024-04-01\n" +
    		"}\n", httpMethod = "POST")
    public ResponseResult exportPdaCoverageRateTargetReportExcel(@RequestBody JSONObject jsonObject){
    	try {
    		String statisticalType = jsonObject.getString("statisticalType");
    		if (StringUtils.isEmpty(statisticalType)) {
    			return ResponseResult.error("请选择统计维度");
    		}
    		String werks = jsonObject.getString("werks");
    		if (StringUtils.isEmpty(werks)) {
    			return ResponseResult.error("请选择工厂");
    		}
    		String whsLocationCode = jsonObject.getString("whsLocationCode");
    		if (StringUtils.isEmpty(whsLocationCode)) {
    			return ResponseResult.error("请选择仓库");
    		}
    		String documentType = jsonObject.getString("documentType");
    		if (StringUtils.isEmpty(documentType)) {
    			return ResponseResult.error("请选择单据类型");
    		}
    		String filename = "PdaCoverageRateTargetReport_" + System.currentTimeMillis()+".xlsx";
    		// 1.附件缓存路径
    		String excelPath = iFileOperationService.savePdaCoverageRateTargetExcel(iOverseaReportService.getDeliveryReportList(jsonObject), filename);
    		if (StringUtils.isEmpty(excelPath)){
    			return ResponseResult.error("附件创建失败");
    		}
    		// 2.上传附件至minIO文件服务器
    		String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
    		if (fileUrl.isEmpty()){
    			return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
    		}
    		// 3.返回附件地址，上传OA
    		return ResponseResult.success()
    				.add("fileUrl",fileUrl);
    	}catch (Exception e){
    		e.printStackTrace();
    		return ResponseResult.error("请求数据失败").add("error", e.getMessage());
    	}
    }
    
    @RequestMapping("/selectAnomaliesReportList")
    @ApiOperation(value = "查询过账异常报表接口", notes = "查询过账异常报表接口\n" +
	    "示例参数：\n" +
	    "{\n" +
		    "\t\"工厂werks = TF02,\n" +
		    "\t\"仓库whsLocationCode = TF02,\n" +
		    "\t\"单据类型:documentType =0-所有类型、1-海运入库、2-本地采购、3-空运人带、4-海外转储、5-盘亏盘盈、6-仓库出库、7-移仓管理、8-转储申请、9-其他出入库、10-调拨管理,\n" +
		    "\t\"统计维度statisticalType = 4-过账异常率,\n" +
		    "\t\"开始时间beginDate = 2024-01-01,\n" +
		    "\t\"结束时间endDate = 2024-04-01\n" +
	    "}\n", httpMethod = "POST")
    public ResponseResult selectAnomaliesReportList(@RequestBody JSONObject jsonObject){
        try {
        	String statisticalType = jsonObject.getString("statisticalType");
            if (StringUtils.isEmpty(statisticalType)) {
                return ResponseResult.error("请选择统计维度");
            }
            String werks = jsonObject.getString("werks");
            if (StringUtils.isEmpty(werks)) {
            	return ResponseResult.error("请选择工厂");
            }
            String whsLocationCode = jsonObject.getString("whsLocationCode");
            if (StringUtils.isEmpty(whsLocationCode)) {
            	return ResponseResult.error("请选择仓库");
            }
            String documentType = jsonObject.getString("documentType");
            if (StringUtils.isEmpty(documentType)) {
            	return ResponseResult.error("请选择单据类型");
            }
            return iOverseaReportService.getDeliveryReportList(jsonObject);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
    @RequestMapping("/exportAnomaliesReportExcel")
    @ApiOperation(value = "导出过账异常率统计报表接口", notes = "导出过账异常率统计报表接口\n" +
    		"示例参数：\n" +
    	    "{\n" +
    		    "\t\"工厂werks = TF02,\n" +
    		    "\t\"仓库whsLocationCode = TF02,\n" +
    		    "\t\"单据类型:documentType =0-所有类型、1-海运入库、2-本地采购、3-空运人带、4-海外转储、5-盘亏盘盈、6-仓库出库、7-移仓管理、8-转储申请、9-其他出入库、10-调拨管理,\n" +
    		    "\t\"统计维度statisticalType = 4-过账异常率,\n" +
    		    "\t\"开始时间beginDate = 2024-01-01,\n" +
    		    "\t\"结束时间endDate = 2024-04-01\n" +
    	    "}\n", httpMethod = "POST")
    public ResponseResult exportAnomaliesReportExcel(@RequestBody JSONObject jsonObject){
        try {
        	String statisticalType = jsonObject.getString("statisticalType");
            if (StringUtils.isEmpty(statisticalType)) {
                return ResponseResult.error("请选择统计维度");
            }
            String werks = jsonObject.getString("werks");
            if (StringUtils.isEmpty(werks)) {
            	return ResponseResult.error("请选择工厂");
            }
            String whsLocationCode = jsonObject.getString("whsLocationCode");
            if (StringUtils.isEmpty(whsLocationCode)) {
            	return ResponseResult.error("请选择仓库");
            }
            String documentType = jsonObject.getString("documentType");
            if (StringUtils.isEmpty(documentType)) {
            	return ResponseResult.error("请选择单据类型");
            }
            String filename = "AnomaliesReport_" + System.currentTimeMillis()+".xlsx";
            // 1.附件缓存路径
            String excelPath = iFileOperationService.saveAnomaliesRateExcel(iOverseaReportService.getAnomaliesReportList(jsonObject), filename);
            if (StringUtils.isEmpty(excelPath)){
                return ResponseResult.error("附件创建失败");
            }
            // 2.上传附件至minIO文件服务器
            String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
            if (fileUrl.isEmpty()){
                return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
            }
            // 3.返回附件地址，上传OA
            return ResponseResult.success().add("fileUrl",fileUrl);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
    @RequestMapping("/exportAnomaliesTargetReportExcel")
    @ApiOperation(value = "导出过账异常率统计指标接口", notes = "导出过账异常率统计指标接口\n" +
    		"示例参数：\n" +
    	    "{\n" +
    		    "\t\"工厂werks = TF02,\n" +
    		    "\t\"仓库whsLocationCode = TF02,\n" +
    		    "\t\"单据类型:documentType =0-所有类型、1-海运入库、2-本地采购、3-空运人带、4-海外转储、5-盘亏盘盈、6-仓库出库、7-移仓管理、8-转储申请、9-其他出入库、10-调拨管理,\n" +
    		    "\t\"统计维度statisticalType = 4-过账异常率,\n" +
    		    "\t\"开始时间beginDate = 2024-01-01,\n" +
    		    "\t\"结束时间endDate = 2024-04-01\n" +
    	    "}\n", httpMethod = "POST")
    public ResponseResult exportAnomaliesTargetReportExcel(@RequestBody JSONObject jsonObject){
    	try {
    		String statisticalType = jsonObject.getString("statisticalType");
            if (StringUtils.isEmpty(statisticalType)) {
                return ResponseResult.error("请选择统计维度");
            }
            String werks = jsonObject.getString("werks");
            if (StringUtils.isEmpty(werks)) {
            	return ResponseResult.error("请选择工厂");
            }
            String whsLocationCode = jsonObject.getString("whsLocationCode");
            if (StringUtils.isEmpty(whsLocationCode)) {
            	return ResponseResult.error("请选择仓库");
            }
            String documentType = jsonObject.getString("documentType");
            if (StringUtils.isEmpty(documentType)) {
            	return ResponseResult.error("请选择单据类型");
            }
    		String filename = "AnomaliesTargetReport_" + System.currentTimeMillis()+".xlsx";
    		// 1.附件缓存路径
    		String excelPath = iFileOperationService.saveAnomaliesTargetExcel(iOverseaReportService.getAnomaliesTargetReportList(jsonObject), filename);
    		if (StringUtils.isEmpty(excelPath)){
    			return ResponseResult.error("附件创建失败");
    		}
    		// 2.上传附件至minIO文件服务器
    		String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
    		if (fileUrl.isEmpty()){
    			return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
    		}
    		// 3.返回附件地址，上传OA
    		return ResponseResult.success().add("fileUrl",fileUrl);
    	}catch (Exception e){
    		e.printStackTrace();
    		return ResponseResult.error("请求数据失败").add("error", e.getMessage());
    	}
    }
    
    @RequestMapping("/selectOnwayReportList")
    @ApiOperation(value = "查询在途超期报表接口", notes = "查询在途超期报表接口\n" +
	    "示例参数：\n" +
	    "{\n" +
		    "\t\"工厂werks = TF02,\n" +
		    "\t\"仓库whsLocationCode = TF02,\n" +
		    "\t\"单据类型:documentType =0-所有类型,\n" +
		    "\t\"统计维度statisticalType = 5-在途超期未收率,\n" +
		    "\t\"开始时间beginDate = 2024-01-01,\n" +
		    "\t\"结束时间endDate = 2024-04-01\n" +
	    "}\n", httpMethod = "POST")
    public ResponseResult selectOnwayReportList(@RequestBody JSONObject jsonObject){
        try {
        	String statisticalType = jsonObject.getString("statisticalType");
            if (StringUtils.isEmpty(statisticalType)) {
                return ResponseResult.error("请选择统计维度");
            }
            String werks = jsonObject.getString("werks");
            if (StringUtils.isEmpty(werks)) {
            	return ResponseResult.error("请选择工厂");
            }
//            String whsLocationCode = jsonObject.getString("whsLocationCode");
//            if (StringUtils.isEmpty(whsLocationCode)) {
//            	return ResponseResult.error("请选择仓库");
//            }
            String documentType = jsonObject.getString("documentType");
            if (StringUtils.isEmpty(documentType)) {
            	return ResponseResult.error("请选择单据类型");
            }
            return iOverseaReportService.getDeliveryReportList(jsonObject);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/exportOnwayReportExcel")
    @ApiOperation(value = "导出在途超期统计报表接口", notes = "导出在途超期统计报表接口\n" +
    		"示例参数：\n" +
    	    "{\n" +
    		    "\t\"工厂werks = TF02,\n" +
    		    "\t\"仓库whsLocationCode = TF02,\n" +
    		    "\t\"单据类型:documentType =0-所有类型,\n" +
    		    "\t\"统计维度statisticalType = 5-在途超期未收率,\n" +
    		    "\t\"开始时间beginDate = 2024-01-01,\n" +
    		    "\t\"结束时间endDate = 2024-04-01\n" +
    	    "}\n", httpMethod = "POST")
    public ResponseResult exportOnwayReportExcel(@RequestBody JSONObject jsonObject){
        try {
        	String statisticalType = jsonObject.getString("statisticalType");
            if (StringUtils.isEmpty(statisticalType)) {
                return ResponseResult.error("请选择统计维度");
            }
            String werks = jsonObject.getString("werks");
            if (StringUtils.isEmpty(werks)) {
            	return ResponseResult.error("请选择工厂");
            }
//            String whsLocationCode = jsonObject.getString("whsLocationCode");
//            if (StringUtils.isEmpty(whsLocationCode)) {
//            	return ResponseResult.error("请选择仓库");
//            }
            String documentType = jsonObject.getString("documentType");
            if (StringUtils.isEmpty(documentType)) {
            	return ResponseResult.error("请选择单据类型");
            }
            String filename = "OnwayReport_" + System.currentTimeMillis()+".xlsx";
            // 1.附件缓存路径
            String excelPath = iFileOperationService.saveOnwayRateExcel(iOverseaReportService.getOnwayReportList(jsonObject), filename);
            if (StringUtils.isEmpty(excelPath)){
                return ResponseResult.error("附件创建失败");
            }
            // 2.上传附件至minIO文件服务器
            String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
            if (fileUrl.isEmpty()){
                return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
            }
            // 3.返回附件地址，上传OA
            return ResponseResult.success().add("fileUrl",fileUrl);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }
    
    @RequestMapping("/exportOnwayReportTargetExcel")
    @ApiOperation(value = "导出在途超期统计指标报表接口", notes = "导出在途超期统计指标报表接口\n" +
    		"示例参数：\n" +
    	    "{\n" +
    		    "\t\"工厂werks = TF02,\n" +
    		    "\t\"仓库whsLocationCode = TF02,\n" +
    		    "\t\"单据类型:documentType =0-所有类型,\n" +
    		    "\t\"统计维度statisticalType = 5-在途超期未收率,\n" +
    		    "\t\"开始时间beginDate = 2024-01-01,\n" +
    		    "\t\"结束时间endDate = 2024-04-01\n" +
    	    "}\n", httpMethod = "POST")
    public ResponseResult exportOnwayReportTargetExcel(@RequestBody JSONObject jsonObject){
        try {
        	String statisticalType = jsonObject.getString("statisticalType");
            if (StringUtils.isEmpty(statisticalType)) {
                return ResponseResult.error("请选择统计维度");
            }
            String werks = jsonObject.getString("werks");
            if (StringUtils.isEmpty(werks)) {
            	return ResponseResult.error("请选择工厂");
            }
//            String whsLocationCode = jsonObject.getString("whsLocationCode");
//            if (StringUtils.isEmpty(whsLocationCode)) {
//            	return ResponseResult.error("请选择仓库");
//            }
            String documentType = jsonObject.getString("documentType");
            if (StringUtils.isEmpty(documentType)) {
            	return ResponseResult.error("请选择单据类型");
            }
            String filename = "OnwayReportTarget_" + System.currentTimeMillis()+".xlsx";
            // 1.附件缓存路径
            String excelPath = iFileOperationService.saveOnwayRateTargetExcel(iOverseaReportService.getOnwayTargetReportList(jsonObject), filename);
            if (StringUtils.isEmpty(excelPath)){
                return ResponseResult.error("附件创建失败");
            }
            // 2.上传附件至minIO文件服务器
            String fileUrl = iFileOperationService.fileUploader(filename, excelPath);
            if (fileUrl.isEmpty()){
                return ResponseResult.error("附件上传失败:" + excelPath + "--" + fileUrl);
            }
            // 3.返回附件地址，上传OA
            return ResponseResult.success().add("fileUrl",fileUrl);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

}
