zss
2024-08-06 e60938e6bf6edf5da6dd7f9f6cc831fdcf27a69f
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java
@@ -2,6 +2,10 @@
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
@@ -25,9 +29,11 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@@ -73,12 +79,25 @@
    //获取检验下单数据
    @Override
    public Map<String, Object> selectInsOrderParameter(IPage<InsOrder> page, SampleOrderDto sampleOrderDto) {
        Map<String, Object> map = new HashMap<>();
        map.put("head", PrintChina.printChina(SampleOrderDto.class));
        //判断全部,个人,组织的权限
        Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectInsOrderParameter");
        User user = userMapper.selectById(map1.get("userId"));
        User user = userMapper.selectById(map1.get("userId"));//当前登录的人
        Integer roleId = user.getRoleId();
        //获取当前人所属实验室id
        String departLimsId = user.getDepartLimsId();
        String laboratory = null;
        if (ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) {
            String[] split = departLimsId.split(",");
            //查询对应架构名称(通信实验室,电力实验室,检测办)
            String departLims = baseMapper.seldepLimsId(Integer.parseInt(split[split.length - 1]));
            if (departLims.contains("实验室")) {
                laboratory = departLims;
            }
        }
        //判断是否是全部权限
        Power power = powerMapper.selectOne(Wrappers.<Power>lambdaQuery().eq(Power::getRoleId, roleId).eq(Power::getMenuMethod, "selectAllInsOrder"));
        Power power = powerMapper.selectOne(Wrappers.<Power>lambdaQuery().eq(Power::getRoleId, roleId).eq(Power::getMenuMethod, "selectInsOrderParameter"));
        if (ObjectUtils.isEmpty(power)) {
            if (map1.get("look") == 1) {
                //个人
@@ -92,23 +111,23 @@
                }
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("head", PrintChina.printChina(SampleOrderDto.class));
        map.put("body", insOrderMapper.selectInsOrderPage(page, QueryWrappers.queryWrappers(sampleOrderDto)));
        map.put("body", insOrderMapper.selectInsOrderPage(page, QueryWrappers.queryWrappers(sampleOrderDto), laboratory));
        return map;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int upInsOrder(Integer orderId, Integer sampleId, String appointed, Integer userId) {
    public int upInsOrder(Integer orderId, Integer sampleId, String appointed, Integer userId, String sonLaboratory) {
        InsOrder insOrder = new InsOrder();
        insOrder.setId(orderId);
        insOrder.setAppointed(LocalDate.parse(appointed));
        insOrder.setSendTime(LocalDateTime.now());
        insOrderMapper.updateById(insOrder);
        List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId).select(InsSample::getId));
        List<InsSample> insSamples =
                insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId).select(InsSample::getId));
        List<Integer> ids = insSamples.stream().map(a -> a.getId()).collect(Collectors.toList());
        List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery().in(InsProduct::getInsSampleId, ids).eq(InsProduct::getState, 1).isNull(InsProduct::getInsFibersId).isNull(InsProduct::getInsFiberId).select(InsProduct::getSonLaboratory).groupBy(InsProduct::getSonLaboratory));
        List<InsProduct> insProducts =
                insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery().in(InsProduct::getInsSampleId, ids).eq(InsProduct::getState, 1).isNull(InsProduct::getInsFibersId).isNull(InsProduct::getInsFiberId).select(InsProduct::getSonLaboratory).groupBy(InsProduct::getSonLaboratory));
        for (InsProduct insProduct : insProducts) {
            InsOrderState insOrderState = new InsOrderState();
            insOrderState.setInsOrderId(orderId);
@@ -125,6 +144,7 @@
            insSampleUser.setState(0);
            insSampleUser.setUserId(userId);
            insSampleUser.setInsSampleId(orderId);
            insSampleUser.setSonLaboratory(sonLaboratory);
            insSampleUserMapper.insert(insSampleUser);
        }
        return 1;
@@ -134,9 +154,34 @@
    @Transactional(rollbackFor = Exception.class)
    public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder, List<List<Integer>> pairing) {
        insOrder.setState(0);
        String code = customMapper.selectById(insOrder.getCompanyId()).getCode2();
        //insOrder.setEntrustCode(giveCode.giveCode("JCZX-" + code + "-", "ins_order", "", "yyMMdd"));
        String giveCode = this.giveCode.giveCode("JCZX-" + code + "-", "ins_order", "", "yyMMdd");
        //判断选择的委托单位与制单人的委托单位是否一致
        Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId");
        String company = userMapper.selectById(userId).getCompany();
        if (!company.equals(insOrder.getCompanyId()+"")) {
            //如果不一致那么委托人字段必填
            if (ObjectUtils.isEmpty(insOrder.getPrepareUser())){
                throw new ErrorException("委托人不能为空");
            }
        }else {
            //如果一致,那么制单人就是委托人
            insOrder.setPrepareUser(insOrder.getCustom());
        }
        //客户代号
        Custom custom = customMapper.selectById(insOrder.getCompanyId());
        String code = custom.getCode2();
        if (!custom.getCompany().equals(insOrder.getCompany())){
            Custom one = customMapper.selectOne(Wrappers.<Custom>lambdaQuery().eq(Custom::getCompany, insOrder.getCompany()));
            insOrder.setCompanyId(one.getId());
            code=one.getCode2();
        }
        //实验室编号
        String code2 = baseMapper.selLaboratoryCode(insOrder.getLaboratory());
        if (StringUtils.isEmpty(code2)) {
            code2 = "";
        }
        //外部委托编号
        insOrder.setOutEntrustCode(giveCode.giveCode3("ZT/" + code2 + "-" + code + "-", insOrder.getCompanyId(), insOrder.getLaboratory(), "ins_order", "", "yyMM"));
        String giveCode = this.giveCode.giveCode("JCZX-" + code + "-", "ins_sample", "", "yyMMdd");
        insOrderMapper.insert(insOrder);
        AtomicInteger count = new AtomicInteger();
        list.forEach(a -> {
@@ -153,6 +198,7 @@
                    for (BushingDto bushingDto : a.getBushing()) {
                        bushingDto.setInsSampleId(a.getId());
                        insBushingMapper.insert(bushingDto);
                        //光纤不为空
                        if (bushingDto.getFiber().size() != 0) {
                            for (FiberDto fiberDto : bushingDto.getFiber()) {
                                fiberDto.setInsBushingId(bushingDto.getId());
@@ -160,7 +206,9 @@
                                addInsProductMethod(a.getId(), a.getInsProduct(), fiberDto.getId(), 2, true);
                                addInsProductMethod(a.getId(), fiberDto.getProductList(), fiberDto.getId(), 2, false);
                            }
                        } else {
                        }
                        //光纤带不为空
                        else if ( bushingDto.getFibers().size()!=0){
                            for (FibersDto fibersDto : bushingDto.getFibers()) {
                                fibersDto.setInsBushingId(bushingDto.getId());
                                fibersDto.setCode(this.giveCode.giveCode("", "ins_fibers", "", "yyMMdd"));
@@ -175,6 +223,17 @@
                                addInsProductMethod(a.getId(), fibersDto.getProductList(), fibersDto.getId(), 1, false);
                            }
                        }
                        //都为空 只配置了套管 这种情况只限于项目是含有松套管的
//                        else {
//                            String collect = a.getInsProduct().stream().map(InsProduct::getInspectionItem).distinct().collect(Collectors.joining(","));
//                            if (collect.contains("松套管")){
//                                //获取检验项目中包含松套管的检验项目
//                                List<InsProduct> products = a.getInsProduct().stream().filter(insProduct -> insProduct.getInspectionItem().contains("松套管")).collect(Collectors.toList());
//
//                            }else {
//                                throw new ErrorException("样品的光纤配置信息里面没有配置光纤带信息也没有光纤信息,请重新配置保存再提交下单!!!");
//                            }
//                        }
                    }
                }
            }
@@ -256,69 +315,122 @@
    private void addInsProductMethod(Integer sampleId, List<InsProduct> productList, Integer id, Integer type, Boolean is) {
        InsOrder insOrder = insOrderMapper.selectById(insSampleMapper.selectById(sampleId).getInsOrderId());
        String name = insSampleMapper.selMethodById(sampleId);
        for (InsProduct product : productList) {
            if (product.getState() == 1 && !product.getInspectionItem().equals("光纤接头损耗")) {
                //判断光缆的温度循环项目添加
                if (insOrder.getSampleType().equals("光缆") && product.getInspectionItem().equals("温度循环") && type != 0) {
                    //判断选择的标准方法是委托要求还是其他标准方法
                    if (!name.equals("委托要求")) {
                        //判断标准方法的温度循环的要求描述是否有填写
                        if (ObjectUtils.isEmpty(product.getTell()) || product.getTell().equals("")) {
                            throw new ErrorException("光缆的温度循环的要求描述为空,需要在标准库配置要求描述!!!");
                        } else {
                            //解析(温度范围:20℃,-40℃,65℃;保温时间:12h; 循环次数:2次; 光纤(1310nm,1550nm)附加衰减不大于0.03dB/km)
                            String tell = product.getTell().replace(")", ")")
                                    .replace("(", "(")
                                    .replace(")", ")")
                                    .replace(",", ",")
                                    .replace(":", ":")
                                    .replace(";", ";")
                                    .replace("不大于", "≤")
                                    .replace("不小于", "≥")
                                    .replace("大于", ">")
                                    .replace("小于", "<")
                                    .replace("等于", "=");
                            String[] message=null;
                            String[] nm=null;
                            String ask=null;
                            String count=null;
                            try {
                                String[] strings = tell.split(";");
                                //温度
                                String temperature = strings[0];
                                String[] split = temperature.split(":");
                                 message = split[1].split(",");
                                //循环次数
                                 count = strings[2].split(":")[1].split("次")[0];
                                //光纤项目和要求值
                                String string = strings[3];
                                 nm = string.split("(")[1].split(")")[0].split(",");
                                 ask = string.split("衰减")[1].split("dB")[0];
                            }catch (Exception e){
                                throw new ErrorException("温度循环的要求描述格式异常,请参照温度范围:20℃,-40℃,65℃;保温时间:12h; 循环次数:2次; 光纤(1310nm,1550nm)附加衰减不大于0.03dB/km");
                            }
                            //拼接
                            String s="";
                            for (int i = 0; i < nm.length; i++) {
                                 s+= "20℃(常温)," + nm[i] + ",null;";
                                for (int j = 0; j < message.length; j++) {
                                    s+= message[j] + "," + nm[i] + "," + ask + ";" ;
                                }
                            }
                            s+=count;
                            product.setAsk(s);
                            insProductMapper.updateById(product);
                            dealWithTemperatureLoop(type,id,sampleId,product);
                        }
                    }
                    else {
                        //20℃(常温),1310nm,null;-40℃,1310nm,≤0.2;75℃,1310nm,<0.3;20℃,1310nm,≤0.1;20℃(常温),1550nm,null;-40℃,1550nm,≤0.2;75℃,1550nm,<0.3;20℃,1550nm,≤0.1;3
                        dealWithTemperatureLoop(type,id,sampleId,product);
                    }
                }
                //判断热循环项目的添加和温升试验项目的添加
                else if (product.getInspectionItem().equals("热循环") || product.getInspectionItem().equals("温升试验")) {
                    List<InsProduct> insProductess = new ArrayList<>();
                    product.setId(null);
                    product.setInsSampleId(sampleId);
                    insProductess.add(product);
                    List<InsProduct> insProductes = new ArrayList<>();
                    List<InsProduct> insProducts = new ArrayList<>();
                    String[] strings = product.getAsk().split(";");
                    for (int i = 0; i < strings.length; i++) {
                        int count = Integer.parseInt(strings[strings.length - 1]);
                        if (i != strings.length - 1) {
                            InsProduct insProduct = new InsProduct();
                            switch (type) {
                                case 1:
                                    insProduct.setInsFibersId(id);
                                    break;
                                case 2:
                                    insProduct.setInsFiberId(id);
                                    break;
                            }
                            String[] split = strings[i].split(",");
                            if (split[0].equals("20℃")) {
                                insProduct.setInspectionItem(count + "");//检验项--循环次数
                            } else {
                                insProduct.setInspectionItem("1");//检验项--循环次数
                            }
                            insProduct.setInspectionItemSubclass(split[0]);//检验项--温度
                            insProduct.setInspectionItemClass(split[1]);//检验项--光纤项目
                            insProduct.setAsk(split[2]);//检验要求
                            insProduct.setTell(strings[i]);//检验描述
                            insProduct.setInsSampleId(sampleId);
                            insProduct.setState(1);
                            insProduct.setFactory(product.getFactory());
                            insProduct.setLaboratory(product.getLaboratory());
                            insProduct.setSampleType(product.getSampleType());
                            insProduct.setSample(product.getSample());
                            insProduct.setModel(product.getModel());
                            insProduct.setSonLaboratory(product.getSonLaboratory());
                            insProduct.setUnit(product.getUnit());
                            insProduct.setManHourGroup(product.getManHourGroup());
                            insProduct.setInspectionItemType("0");
                            insProduct.setInspectionValueType("1");
                            insProducts.add(insProduct);
                            insProductes.add(insProduct);
                        } else {
                            //最后一个数据是说明会循环多少次
                            if (count > 1) {
                                //循环超过1次
                                for (int j = 2; j <= count; j++) {
                                    for (InsProduct insProduct : insProducts) {
                                        if (!insProduct.getInspectionItemSubclass().equals("20℃") && !insProduct.getInspectionItemSubclass().equals("20℃(常温)")) {
                                            InsProduct insProduct1 = new InsProduct();
                                            BeanUtils.copyProperties(insProduct, insProduct1);
                                            insProduct1.setInspectionItem(j + "");
                                            insProductes.add(insProduct1);
                                        }
                                    }
                                }
                    //循环次数
                    int count = Integer.parseInt(strings[strings.length - 1]);
                    for (int i = 0; i < strings.length - 1; i++) {
                        String[] split = strings[i].split(",");
                        InsProduct insProduct = new InsProduct();
                        insProduct.setInspectionItem("1");//检验父项--循环次数
                        insProduct.setInspectionItemSubclass(split[0]);//检验子项--环境温度/导线温度/耐张温度/接续温度
                        insProduct.setInspectionItemSubclassEn(split[1]);//检验子项英文--环境温度/导线温度/耐张温度/接续温度
                        insProduct.setAsk(null);//检验要求
                        insProduct.setTell(null);//检验描述
                        insProduct.setInsSampleId(sampleId);
                        insProduct.setState(1);
                        insProduct.setFactory(product.getFactory());
                        insProduct.setLaboratory(product.getLaboratory());
                        insProduct.setSampleType(product.getSampleType());
                        insProduct.setSample(product.getSample());
                        insProduct.setModel(product.getModel());
                        insProduct.setSonLaboratory(product.getSonLaboratory());
                        insProduct.setUnit("℃");//单位
                        insProduct.setManHourGroup(product.getManHourGroup());
                        insProduct.setInspectionItemType("0");
                        insProduct.setInspectionValueType("1");
                        if (product.getInspectionItem().equals("热循环")) {
                            insProduct.setInspectionItemClass("直流电阻");//检验子子项--直流电阻
                            insProduct.setInspectionItemClassEn("DC resistance");//检验子子项英文--直流电阻
                            insProduct.setUnit("Ω/km");//单位
                        }
                        insProducts.add(insProduct);
                        insProductes.add(insProduct);
                        insProductess.add(insProduct);
                    }
                    //热循环才有多次循环次数
                    if (count > 1) {
                        //循环超过1次
                        for (int j = 2; j <= count; j++) {
                            for (InsProduct insProduct : insProductes) {
                                InsProduct insProduct1 = new InsProduct();
                                BeanUtils.copyProperties(insProduct, insProduct1);
                                insProduct1.setInspectionItem(j + "");//循环次数
                                insProductess.add(insProduct1);
                            }
                        }
                    }
                    insProductService.saveBatch(insProductes);
                } else {
                    insProductService.saveBatch(insProductess);
                }
                else {
                    if (!is) {
                        switch (type) {
                            case 1:
@@ -344,6 +456,67 @@
        }
    }
    //温度循环的处理
    private void dealWithTemperatureLoop(Integer type, Integer id,Integer sampleId,InsProduct product) {
        List<InsProduct> insProductes = new ArrayList<>();
        List<InsProduct> insProducts = new ArrayList<>();
        String[] strings = product.getAsk().split(";");
        for (int i = 0; i < strings.length; i++) {
            int count = Integer.parseInt(strings[strings.length - 1]);
            if (i != strings.length - 1) {
                InsProduct insProduct = new InsProduct();
                switch (type) {
                    case 1:
                        insProduct.setInsFibersId(id);
                        break;
                    case 2:
                        insProduct.setInsFiberId(id);
                        break;
                }
                String[] split = strings[i].split(",");
                if (split[0].equals("20℃")) {
                    insProduct.setInspectionItem(count + "");//检验项--循环次数
                } else {
                    insProduct.setInspectionItem("1");//检验项--循环次数
                }
                insProduct.setInspectionItemSubclass(split[0]);//检验项--温度
                insProduct.setInspectionItemClass(split[1]);//检验项--光纤项目
                insProduct.setAsk(split[2]);//检验要求
                insProduct.setTell(strings[i]);//检验描述
                insProduct.setInsSampleId(sampleId);
                insProduct.setState(1);
                insProduct.setFactory(product.getFactory());
                insProduct.setLaboratory(product.getLaboratory());
                insProduct.setSampleType(product.getSampleType());
                insProduct.setSample(product.getSample());
                insProduct.setModel(product.getModel());
                insProduct.setSonLaboratory(product.getSonLaboratory());
                insProduct.setUnit(product.getUnit());
                insProduct.setManHourGroup(product.getManHourGroup());
                insProduct.setInspectionItemType("0");
                insProduct.setInspectionValueType("1");
                insProducts.add(insProduct);
                insProductes.add(insProduct);
            } else {
                //最后一个数据是说明会循环多少次
                if (count > 1) {
                    //循环超过1次
                    for (int j = 2; j <= count; j++) {
                        for (InsProduct insProduct : insProducts) {
                            if (!insProduct.getInspectionItemSubclass().equals("20℃") && !insProduct.getInspectionItemSubclass().equals("20℃(常温)")) {
                                InsProduct insProduct1 = new InsProduct();
                                BeanUtils.copyProperties(insProduct, insProduct1);
                                insProduct1.setInspectionItem(j + "");
                                insProductes.add(insProduct1);
                            }
                        }
                    }
                }
            }
        }
        insProductService.saveBatch(insProductes);
    }
    @Override
    public Map<String, Object> getInsOrder(Integer id) {
        Map<String, Object> map = new HashMap<>();
@@ -363,7 +536,14 @@
            if (StringUtils.isEmpty(code)) {
                code = "";
            }
            String code2 = customMapper.selectById(insOrder.getCompanyId()).getCode2();
            Custom custom = customMapper.selectById(insOrder.getCompanyId());
            String code2 = custom.getCode2();
            if (!custom.getCompany().equals(insOrder.getCompany())){
                Custom one = customMapper.selectOne(Wrappers.<Custom>lambdaQuery().eq(Custom::getCompany, insOrder.getCompany()));
                insOrder.setCompanyId(one.getId());
                code2=one.getCode2();
            }
            //String code2 = customMapper.selectById(insOrder.getCompanyId()).getCode2();
            insOrder.setEntrustCode(giveCode.giveCode2("JCZX/" + code + "-" + code2 + "-", insOrder.getCompanyId(), insOrder.getLaboratory(), "ins_order", "", "yyMM"));
        }
        return insOrderMapper.updateById(insOrder);
@@ -399,7 +579,36 @@
        map.put("head", PrintChina.printChina(CostStatisticsDto.class));
        Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("costStatistics");
        if (map1.get("look") == 1) costStatisticsDto.setCreateUser(map1.get("userId"));
        map.put("body", insOrderMapper.selectCostStatistics(page, QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59")));
        IPage<CostStatisticsDto> dtoIPage = insOrderMapper.selectCostStatistics(page, QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59"));
        List<CostStatisticsDto> collect = dtoIPage.getRecords().stream().map(dto -> {
            Set<String> uniqueTags = new HashSet<>();
            if (dto.getInspectionItem().contains(",")) {
                for (String s : dto.getInspectionItem().split(",")) {
                    uniqueTags.add(s.split("@")[0]);
                }
            } else {
                uniqueTags.add(dto.getInspectionItem().split("@")[0]);
            }
            dto.setInspectionItem(uniqueTags.toString());
            return dto;
        }).collect(Collectors.toList());
        dtoIPage.setRecords(collect);
        map.put("body", dtoIPage);
        return map;
    }
    @Override
    public Map<String, Object> costStatistics2(CostStatisticsDto costStatisticsDto) {
        Map<String, Object> map = new HashMap<>();
        String dates = costStatisticsDto.getDates();
        String[] split = dates.replaceAll("\\[", "").replaceAll("]", "").replaceAll("\"", "").split(",");
        costStatisticsDto.setDates(null);
        List<CostStatisticsDto> costStatisticsDtos = insOrderMapper.selectCostStatistics2(QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59"));
        double totalPrice = costStatisticsDtos.stream()
                .filter(dto -> dto.getPrice() != null) // 过滤掉价格为 null 的对象
                .mapToDouble(value -> value.getPrice().doubleValue() * value.getNum())
                .sum();
        map.put("total", totalPrice);
        return map;
    }
@@ -438,6 +647,57 @@
        }).collect(Collectors.toList());
        return sampleProductDto3s;
    }
    @Override
    public void export(CostStatisticsDto costStatisticsDto, HttpServletResponse response) throws IOException {
        //查询导出的费用统计数据
        String dates = costStatisticsDto.getDates();
        String[] split = dates.replaceAll("\\[", "").replaceAll("]", "").replaceAll("\"", "").split(",");
        costStatisticsDto.setDates(null);
        List<CostStatisticsDto> costStatisticsDtos = insOrderMapper.selectCostStatistics2(QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59"));
        costStatisticsDtos = costStatisticsDtos.stream().map(dto -> {
            Set<String> uniqueTags = new HashSet<>();
            if (dto.getInspectionItem().contains(",")) {
                for (String s : dto.getInspectionItem().split(",")) {
                    uniqueTags.add(s.split("@")[0]);
                }
            } else {
                uniqueTags.add(dto.getInspectionItem().split("@")[0]);
            }
            dto.setInspectionItem(uniqueTags.toString());
            return dto;
        }).collect(Collectors.toList());
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("UTF-8");
        // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
        String fileName = URLEncoder.encode("样品费用统计导出", "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        Map<String, List<CostStatisticsDto>> groupByCompany =
                costStatisticsDtos.stream().filter(e -> StrUtil.isNotEmpty(e.getCompany()))
                        .collect(Collectors.groupingBy(CostStatisticsDto::getCompany));
        try {
            // 新建ExcelWriter
            // 新建ExcelWriter
            ExcelWriter excelWriter =
                    EasyExcel.write(response.getOutputStream())
                            .registerWriteHandler(new SimpleColumnWidthStyleStrategy(25))
                            .build();
            for (Map.Entry<String, List<CostStatisticsDto>> companyDataEntry : groupByCompany.entrySet()) {
                String sheetName = companyDataEntry.getKey();
                List<CostStatisticsDto> dataList = companyDataEntry.getValue();
                WriteSheet mainSheet = EasyExcel.writerSheet(sheetName)
                        .head(CostStatisticsDto.class)
                        .registerWriteHandler(new SimpleColumnWidthStyleStrategy(25))
                        .build();
                excelWriter.write(dataList, mainSheet);
            }
            // 关闭流
            excelWriter.finish();
        } catch (IOException e) {
            throw new RuntimeException("导出失败");
        }
    }
}