zss
2024-08-01 30a143f368dd2ff6e9c27b9d5dd17923ffed03ae
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java
@@ -29,15 +29,12 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.ServletException;
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.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.function.Predicate;
@@ -130,9 +127,11 @@
        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);
@@ -159,8 +158,21 @@
    @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"));
        //客户代号
        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();
@@ -631,13 +643,18 @@
        // 这里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 = EasyExcel.write(response.getOutputStream()).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build();
            WriteSheet mainSheet = EasyExcel.writerSheet("样品费用统计导出").head(CostStatisticsDto.class).build();
            excelWriter.write(costStatisticsDtos, mainSheet);
            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).build();
                excelWriter.write(dataList, mainSheet);
            }
            // 关闭流
            excelWriter.finish();
        } catch (IOException e) {