chenrui
2025-04-10 c296b7d0c412429d29ad24bd34aa9def65045085
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
@@ -2,8 +2,6 @@
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
@@ -32,6 +30,7 @@
import com.ruoyi.basic.service.StandardTemplateService;
import com.ruoyi.common.constant.DictDataConstants;
import com.ruoyi.common.constant.InsOrderTypeConstants;
import com.ruoyi.common.constant.MenuJumpPathConstants;
import com.ruoyi.common.core.domain.entity.Custom;
import com.ruoyi.common.core.domain.entity.InformationNotification;
import com.ruoyi.common.core.domain.entity.User;
@@ -44,7 +43,6 @@
import com.ruoyi.inspect.util.HackLoopTableRenderPolicy;
import com.ruoyi.inspect.vo.InsOrderPlanTaskSwitchVo;
import com.ruoyi.inspect.vo.InsOrderPlanVO;
import com.ruoyi.performance.mapper.AuxiliaryOutputWorkingHoursMapper;
import com.ruoyi.performance.mapper.PerformanceShiftMapper;
import com.ruoyi.performance.mapper.ShiftTimeMapper;
import com.ruoyi.performance.pojo.AuxiliaryOutputWorkingHours;
@@ -57,8 +55,9 @@
import com.ruoyi.system.service.InformationNotificationService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xwpf.usermodel.*;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
@@ -71,13 +70,10 @@
import java.math.RoundingMode;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@@ -104,22 +100,15 @@
    private InsOrderStateMapper insOrderStateMapper;
    @Resource
    private InsProductMapper insProductMapper;
    @Resource
    private ShiftTimeMapper shiftTimeMapper;
    @Resource
    private PerformanceShiftMapper performanceShiftMapper;
    @Value("${wordUrl}")
    private String wordUrl;
    @Value("${twoCode}")
    private String twoCode;
    @Resource
    private InsReportMapper insReportMapper;
    @Resource
    private InsProductResultMapper insProductResultMapper;
    @Resource
    private InsProductUserMapper insProductUserMapper;
    @Resource
    private InsUnPassService insUnPassService;
    @Resource
    private AuxiliaryOutputWorkingHoursService auxiliaryOutputWorkingHoursService;
    @Resource
@@ -132,7 +121,6 @@
    private CustomMapper customMapper;
    @Value("${file.path}")
    private String imgUrl;
    @Resource
    private InsOrderFileMapper insOrderFileMapper;
    @Resource
@@ -151,8 +139,7 @@
    private InsOrderFactoryVerifyMapper insOrderFactoryVerifyMapper;
    @Resource
    private InsOrderFactoryVerifyItemService insOrderFactoryVerifyItemService;
    @Value("${file.licenseUrl}")
    private String licenseUrl;
    @Resource
    private SpotCheckQuarterItemMapper spotCheckQuarterItemMapper;
    @Resource
@@ -163,32 +150,25 @@
    private InsOrderDeviceRecordService insOrderDeviceRecordService;
    @Resource
    private ISysDictTypeService iSysDictTypeService;
    @Resource
    private InsOrderRatesService insOrderRatesService;
    @Override
    public IPage<InsOrderPlanVO> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) {
        // todo: 仅看自己或者实验室
        //获取当前人所属实验室id
        String laboratory = null;
        String userName = null;
        Integer userId = null;
        if (ObjectUtil.isNotEmpty(insOrderPlanDTO.getUserId())) {
            userId = SecurityUtils.getUserId().intValue();
            userName = userMapper.selectById(userId).getName();
        // 检测管理人员全查,非检测管理人员只查看自己的
        InsOrderPlanQueryDto insOrderPlanQueryDto = new InsOrderPlanQueryDto();
        insOrderPlanQueryDto.setCheckUserFlag(SecurityUtils.hasRole("inspector"));
        insOrderPlanQueryDto.setTestAdminFlag(SecurityUtils.hasRole("testadmin"));
        // 判断是否触发只查看自己
        if(null != insOrderPlanDTO.getUserId()){
            insOrderPlanQueryDto.setViewMySelfFlag(true);
            insOrderPlanDTO.setUserId(null);
        }
        Integer isCheck = insOrderPlanDTO.getIsCheck();
        insOrderPlanQueryDto.setIsCheck(insOrderPlanDTO.getIsCheck());
        insOrderPlanDTO.setIsCheck(null);
        String sonLaboratory = insOrderPlanDTO.getSonLaboratory();//试验室
        insOrderPlanQueryDto.setUserId(SecurityUtils.getUserId().intValue());
        IPage<InsOrderPlanVO> insOrderPage = insSampleMapper.findInsSampleAndOrder(page,
                QueryWrappers.queryWrappers(insOrderPlanDTO),
                userName,
                userId,
                sonLaboratory,
                laboratory,
                isCheck);
                QueryWrappers.queryWrappers(insOrderPlanDTO),insOrderPlanQueryDto);
        return insOrderPage;
    }
@@ -237,17 +217,19 @@
        // 查询厂家密度
        String supplierDensity = "";
        SampleProductDto sampleProductDto = list.get(0);
        if (CollectionUtils.isNotEmpty(list)) {
            SampleProductDto sampleProductDto = list.get(0);
        // 判断有没有绑定型号
        String modelValue = insSampleMapper.selectSupplierDensityModel(sampleProductDto.getSample(),
                order.getProduction(),
                sampleProductDto.getModel());
        if (StringUtils.isNotBlank(modelValue)) {
            supplierDensity = modelValue;
        } else {
            supplierDensity = insSampleMapper.selectSupplierDensity(sampleProductDto.getSample(),
                    order.getProduction());
            // 判断有没有绑定型号
            String modelValue = insSampleMapper.selectSupplierDensityModel(sampleProductDto.getSample(),
                    order.getProduction(),
                    sampleProductDto.getModel());
            if (StringUtils.isNotBlank(modelValue)) {
                supplierDensity = modelValue;
            } else {
                supplierDensity = insSampleMapper.selectSupplierDensity(sampleProductDto.getSample(),
                        order.getProduction());
            }
        }
        map.put("supplierDensity", supplierDensity);
        return map;
@@ -370,7 +352,7 @@
        insContext.forEach((k, v) -> {
            JSONObject jo = JSON.parseObject(JSON.toJSONString(v));
            InsProduct insProduct = new InsProduct();
            insProduct.setId(Integer.parseInt(k));
            insProduct.setId(Long.valueOf(Integer.parseInt(k)));
            InsProduct product = insProductMapper.selectById(insProduct.getId());
            if (currentTable.equals(product.getTemplateId()) && currentSampleId.equals(product.getInsSampleId())) {
                List<InsProductResult> oldResults = insProductResultMapper.selectList(Wrappers.<InsProductResult>lambdaQuery()
@@ -457,6 +439,30 @@
                    }
                    newResult.setEquipName(JSON.toJSONString(ev));
                }
                //测试开始时间
                if (jo.get("testStartTime") != null) {
                    JSONArray jsonArray2 = JSON.parseArray(JSON.toJSONString(jo.get("testStartTime")));
                    List<Map<String, Object>> ev = new ArrayList<>();
                    for (Object o : jsonArray2) {
                        JSONObject testStartTimeValue = JSON.parseObject(JSON.toJSONString(o));
                        Map<String, Object> map = new HashMap<>();
                        map.put("v", JSON.parseObject(JSON.toJSONString(testStartTimeValue.get("v"))).get("v"));
                        ev.add(map);
                    }
                    newResult.setTestStartTime(JSON.toJSONString(ev));
                }
                //测试结束时间
                if (jo.get("testEndTime") != null) {
                    JSONArray jsonArray2 = JSON.parseArray(JSON.toJSONString(jo.get("testEndTime")));
                    List<Map<String, Object>> ev = new ArrayList<>();
                    for (Object o : jsonArray2) {
                        JSONObject testEndTimeValue = JSON.parseObject(JSON.toJSONString(o));
                        Map<String, Object> map = new HashMap<>();
                        map.put("v", JSON.parseObject(JSON.toJSONString(testEndTimeValue.get("v"))).get("v"));
                        ev.add(map);
                    }
                    newResult.setTestEndTime(JSON.toJSONString(ev));
                }
                //结论
                try {
                    JSONObject insResult = JSON.parseObject(JSON.toJSONString(jo.get("insResult")));
@@ -477,7 +483,7 @@
                insProduct.setUpdateUser(userId);
                insProductMapper.updateById(insProduct);
                insProductUserMapper.insert(new InsProductUser(null, userId, LocalDateTime.now(), insProduct.getId()));
                insProductUserMapper.insert(new InsProductUser(null, userId, LocalDateTime.now(), Math.toIntExact(insProduct.getId())));
                insSample.setInsState(1);
                Long l = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery()
@@ -752,7 +758,7 @@
    @Transactional(rollbackFor = Exception.class)
    public int submitPlan(Integer orderId, String laboratory, Integer verifyUser, String entrustCode) {
        InsOrder order = insOrderMapper.selectById(orderId);
        // 判断是否有重复编号, 有重复编号做提醒
        // 1. 判断是否有重复编号, 有重复编号做提醒
        Long codeCount = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery()
                .ne(InsOrder::getState, -1)
                .ne(InsOrder::getIfsInventoryId, order.getIfsInventoryId())
@@ -761,7 +767,7 @@
            throw new ErrorException("当前编号有重复, 请先去修改重复编号");
        }
        // 判断该订单是否是第一次生产
        // 2. 判断该订单是否是第一次生产(后续报告生成只取第一次提交时间)
        if (!(order.getIsFirstSubmit() != null && order.getIsFirstSubmit().equals(1))) {
            insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate()
                    .eq(InsOrder::getId, orderId)
@@ -769,11 +775,12 @@
                    .set(InsOrder::getFirstSubmitDate, LocalDateTime.now()));
        }
        // 3. 判断是否有未检项
        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<Integer> InsSampleIds = insSamples.stream().map(InsSample::getId).collect(Collectors.toList());
        List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
                .in(InsProduct::getInsSampleId, ids)
                .in(InsProduct::getInsSampleId, InsSampleIds)
                .eq(InsProduct::getSonLaboratory, laboratory)
                .eq(InsProduct::getState, 1)
                .and(wrapper -> wrapper
@@ -781,37 +788,37 @@
                        .or()
                        .eq(InsProduct::getInsResult, 2)
                )
                .isNull(InsProduct::getInsFiberId)
                .isNull(InsProduct::getInsFibersId)
                .ne(InsProduct::getIsBinding, 1));
        insProducts.addAll(insProductMapper.selectFiberInsProduct(ids, laboratory));
        insProducts.addAll(insProductMapper.selectFiberInsProduct(InsSampleIds, laboratory));
        if (insProducts.size() > 0) {
            String str = "";
            int count = 0;
            for (InsProduct product : insProducts) {
                count++;
                str += "<br/>" + count + ":" + product.getInspectionItem() + " " + product.getInspectionItemSubclass() + "<br/>";
                str +=  (count != 0 ? "\n" : "") + count + ":" +
                        product.getInspectionItemClass() + " " +
                        product.getInspectionItem() + " " +
                        product.getInspectionItemSubclass();
            }
            if (ObjectUtils.isNotEmpty(str)) {
                throw new ErrorException("<strong>存在待检验的项目:</strong><br/>" + str);
                throw new ErrorException("存在待检验的项目:" + str);
            }
        }
        // 4.修改检测结果
        insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate().eq(InsOrderState::getInsOrderId, orderId)
                .eq(InsOrderState::getLaboratory, laboratory)
                .set(InsOrderState::getInsTime, LocalDateTime.now())
                .set(InsOrderState::getInsState, 3)
                .set(InsOrderState::getVerifyUser, verifyUser));
        // 发送消息
        // 5.发送消息通知给复核人
        // 查询当前人信息
        Integer userId = SecurityUtils.getUserId().intValue();
        String userName = insProductMapper.selectUserById(userId).get("name");
        // 查询发送人信息
        String sendUserAccount = insProductMapper.selectUserById(verifyUser).get("account");
        InformationNotification info = new InformationNotification();
        info.setCreateUser(userName);
        info.setMessageType("2");
@@ -820,20 +827,21 @@
        info.setSenderId(userId);
        info.setConsigneeId(verifyUser);
        info.setViewStatus(false);
        info.setJumpPath("b1-inspect-orderPlan-review");
        info.setJumpPath(MenuJumpPathConstants.INSPECTION_REVIEW);
        informationNotificationService.addInformationNotification(info);
        //复核人--检验单相关负责人
        // 6.复核人--新增检验单相关负责人
        InsSampleUser insSampleUser = new InsSampleUser();
        insSampleUser.setUserId(verifyUser);
        insSampleUser.setInsSampleId(orderId);
        insSampleUser.setState(1);
        insSampleUser.setSonLaboratory(laboratory);
        insSampleUserMapper.insert(insSampleUser);
        /*校验一下result表*/
        CompletableFuture.supplyAsync(() -> {
            List<Integer> ips = insProducts.stream().map(InsProduct::getId).distinct().collect(Collectors.toList());
            for (Integer ip : ips) {
        // 7.校验一下result表(避免出现多个检验项结果)
        threadPoolTaskExecutor.execute(() -> {
            List<Long> ips = insProducts.stream().map(InsProduct::getId).distinct().collect(Collectors.toList());
            for (Long ip : ips) {
                List<InsProductResult> insProductResults = insProductResultMapper.selectList(Wrappers.<InsProductResult>lambdaQuery()
                        .eq(InsProductResult::getInsProductId, ip));
                if (insProductResults.size() > 1) {
@@ -842,26 +850,116 @@
                    }
                }
            }
            return null;
        });
        // 提交生成报告
        // 8.提交生成报告
        this.generateReport(orderId);
        // 添加临时pdf生成地址
        // 9.添加临时pdf生成地址
        InsReport report = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
                .eq(InsReport::getInsOrderId, orderId));
        String tempUrlPdf = this.wordToPdfTemp(report.getUrl().replace("/word", wordUrl));
        report.setTempUrlPdf("/word/" + tempUrlPdf);
        insReportMapper.updateById(report);
        // 查询订单
        // 10.原始记录模板复制(添加备份, 避免修改原始模板影响到已经完成的单子)
        this.templateCopy(orderId, InsSampleIds);
        // 11.成品抽样添加合格状态
        // 判断是否有抽样信息
        if (order.getQuarterItemId() != null) {
            // 判断是否有不合格
            this.addProductSpotCheck(insSamples, order);
        }
        // 12.添加工时
        // 删除原本订单工时
        auxiliaryOutputWorkingHoursService.remove(Wrappers.<AuxiliaryOutputWorkingHours>lambdaQuery()
                .eq(AuxiliaryOutputWorkingHours::getOrderId, orderId));
        // 查询工时暂存
        List<AuxiliaryOutputWorkingHoursTemporary> hoursTemporaries = auxiliaryOutputWorkingHoursTemporaryService.list(Wrappers.<AuxiliaryOutputWorkingHoursTemporary>lambdaQuery()
                .eq(AuxiliaryOutputWorkingHoursTemporary::getOrderId, orderId));
        List<AuxiliaryOutputWorkingHours> outputWorkingHours = hoursTemporaries.stream().map(hoursTemporary -> {
            AuxiliaryOutputWorkingHours workingHours = new AuxiliaryOutputWorkingHours();
            BeanUtil.copyProperties(hoursTemporary, workingHours);
            workingHours.setId(null);
            return workingHours;
        }).collect(Collectors.toList());
        auxiliaryOutputWorkingHoursService.saveBatch(outputWorkingHours);
        // 13.添加订单费用统计信息
        List<InsProduct> productList = insProductMapper.selectProductByOrderId(orderId);
        // 删除原本费用信息
        insOrderRatesService.remove(Wrappers.<InsOrderRates>lambdaQuery()
                .eq(InsOrderRates::getInsOrderId, orderId));
        List<InsOrderRates> orderRatesList = productList.stream().map(insProduct -> {
            InsOrderRates insOrderRates = new InsOrderRates();
            insOrderRates.setInsOrderId(orderId);
            insOrderRates.setInsSampleId(insProduct.getInsSampleId());
            insOrderRates.setInsProductId(Math.toIntExact(insProduct.getId()));
            insOrderRates.setSampleCode(insProduct.getSampleCode());
            insOrderRates.setEntrustCode(order.getEntrustCode());
            insOrderRates.setInspectionItemClass(insProduct.getInspectionItemClass());
            insOrderRates.setInspectionItem(insProduct.getInspectionItem());
            insOrderRates.setInspectionItemSubclass(insProduct.getInspectionItemSubclass());
            insOrderRates.setCableTag(insProduct.getCableTag());
            insOrderRates.setRates(insProduct.getRates());
            insOrderRates.setManHourGroup(insProduct.getManHourGroup());
            return insOrderRates;
        }).collect(Collectors.toList());
        insOrderRatesService.saveBatch(orderRatesList);
        // 14.发送企业微信通知
        // 查询原材料
        IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId());
        // 查询样品信息
        InsSample insSample = insSampleMapper.selectOne(Wrappers.<InsSample>lambdaQuery()
                .eq(InsSample::getInsOrderId, orderId)
                .last("limit 1"));
        // 查询原材料
        IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId());
        threadPoolTaskExecutor.execute(() -> {
            String message = "";
            message += "检验任务复核通知";
            message += "\n提交人: " + userName;
            message += "\n委托编号: " + order.getEntrustCode();
            message += "\n样品名称: " + insSample.getModel();
            message += "\n规格型号: " + order.getPartDetail();
            if (ifsInventoryQuantity != null) {
                message += "\n批次号: " + ifsInventoryQuantity.getUpdateBatchNo();
            }
            //发送企业微信消息通知  提交复核
            try {
                WxCpUtils.inform(sendUserAccount, message, null);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
        // 15.ifs移库(原材料需要进行移库操作) --> 最后执行,因为失败无法回滚
        if (ifsInventoryQuantity != null) {
            // 登记检验结果
            // 判断是否有不合格, 有不合格不能移库
            // todo: ifs移库
            insReportService.isRawMaterial(order);
        } else {
            // 修改成品状态
            // 判断是否有不合格
            Long unqualifiedCount = insReportService.getUnqualifiedCount(order);
            if (unqualifiedCount.equals(0L)) {
                insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate()
                        .eq(InsOrder::getId, order.getId())
                        .set(InsOrder::getInsResult, 1));
            } else {
                insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate()
                        .eq(InsOrder::getId, order.getId())
                        .set(InsOrder::getInsResult, 0));
            }
        }
        return 1;
    }
    private void templateCopy(Integer orderId, List<Integer> ids) {
        // 删除原本模板
        insOrderStandardTemplateService.remove(Wrappers.<InsOrderStandardTemplate>lambdaQuery()
                .eq(InsOrderStandardTemplate::getInsOrderId, orderId));
@@ -886,99 +984,6 @@
                }
            }
        }
        // 添加工时
        // 删除原本订单工时
        auxiliaryOutputWorkingHoursService.remove(Wrappers.<AuxiliaryOutputWorkingHours>lambdaQuery()
                .eq(AuxiliaryOutputWorkingHours::getOrderId, orderId));
        // 查询工时暂存
        List<AuxiliaryOutputWorkingHoursTemporary> hoursTemporaries = auxiliaryOutputWorkingHoursTemporaryService.list(Wrappers.<AuxiliaryOutputWorkingHoursTemporary>lambdaQuery()
                .eq(AuxiliaryOutputWorkingHoursTemporary::getOrderId, orderId));
        List<AuxiliaryOutputWorkingHours> outputWorkingHours = hoursTemporaries.stream().map(hoursTemporary -> {
            AuxiliaryOutputWorkingHours workingHours = new AuxiliaryOutputWorkingHours();
            BeanUtil.copyProperties(hoursTemporary, workingHours);
            workingHours.setId(null);
            return workingHours;
        }).collect(Collectors.toList());
        auxiliaryOutputWorkingHoursService.saveBatch(outputWorkingHours);
        // 成品抽样添加合格状态
        // 判断是否有抽样信息
        if (order.getQuarterItemId() != null) {
            // 判断是否有不合格
            Long unqualifiedCount = 0L;
            if (CollectionUtils.isNotEmpty(insSamples)) {
                unqualifiedCount = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery()
                        .in(InsProduct::getInsSampleId, insSamples.stream().map(InsSample::getId).collect(Collectors.toList()))
                        .eq(InsProduct::getInsResult, 0));
                // 判断如果有不合格的检验项, 判断有没有检验项复测, 复核合格也算合格通过
                if (!unqualifiedCount.equals(0L)) {
                    List<InsProduct> productList = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
                            .in(InsProduct::getInsSampleId, insSamples.stream().map(InsSample::getId).collect(Collectors.toList()))
                            .eq(InsProduct::getInsResult, 0));
                    boolean flag = true;
                    for (InsProduct insProduct : productList) {
                        Long unqualifiedProductCount = insUnqualifiedRetestProductMapper.selectCount(Wrappers.<InsUnqualifiedRetestProduct>lambdaQuery()
                                .eq(InsUnqualifiedRetestProduct::getInsProductId, insProduct.getId())
                                .ne(InsUnqualifiedRetestProduct::getInsResult, 0));
                        if (unqualifiedProductCount != 2) {
                            flag = false;
                        }
                    }
                    if (flag) {
                        unqualifiedCount = 0L;
                    }
                }
            }
            spotCheckQuarterItemMapper.update(null, Wrappers.<SpotCheckQuarterItem>lambdaUpdate()
                    .eq(SpotCheckQuarterItem::getQuarterItemId, order.getQuarterItemId())
                    .set(SpotCheckQuarterItem::getResult, unqualifiedCount.equals(0L) ? "合格" : "不合格"));
        }
        // 发送企业微信通知
        threadPoolTaskExecutor.execute(() -> {
            String message = "";
            message += "检验任务复核通知";
            message += "\n提交人: " + userName;
            message += "\n委托编号: " + order.getEntrustCode();
            message += "\n样品名称: " + insSample.getModel();
            message += "\n规格型号: " + order.getPartDetail();
            if (ifsInventoryQuantity != null) {
                message += "\n批次号: " + ifsInventoryQuantity.getUpdateBatchNo();
            }
            //发送企业微信消息通知  提交复核
            try {
                WxCpUtils.inform(sendUserAccount, message, null);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
        // ifs移库
        if (ifsInventoryQuantity != null) {
            // 登记检验结果
            // 判断是否有不合格, 有不合格不能移库
            // todo: ifs移库
            insReportService.isRawMaterial(order);
        } else {
            // 修改成品状态
            // 判断是否有不合格
            Long unqualifiedCount = insReportService.getUnqualifiedCount(order);
            if (unqualifiedCount.equals(0L)) {
                insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate()
                        .eq(InsOrder::getId, order.getId())
                        .set(InsOrder::getInsResult, 1));
            } else {
                insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate()
                        .eq(InsOrder::getId, order.getId())
                        .set(InsOrder::getInsResult, 0));
            }
        }
        return 1;
    }
@@ -1116,7 +1121,6 @@
     * @param orderId
     */
    private void generateReport(Integer orderId) {
        List<InsUnPass> insUnPasses = new ArrayList<>();
        /*样品下的项目只要有一个项目不合格则检验结果为0,否则为1*/
        //这里的insSamples是订单下的所有样品包括("/")
        List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId));
@@ -1132,25 +1136,7 @@
                insSample.setInsResult(1);
            }
            insSampleMapper.updateById(insSample);
            /*复核通过后,将不合格的项目信息添加到ins_un_pass表中*/
            for (InsProduct insProduct : insProducts) {
                if (insProduct.getInsResult() == 0) {
                    InsUnPass insUnPass = new InsUnPass();
                    insUnPass.setId(null);
                    insUnPass.setModel(insSample.getModel());
                    insUnPass.setSample(insSample.getSample());
                    insUnPass.setInspectionItem(insProduct.getInspectionItem());
                    insUnPass.setInspectionItemSubclass(insProduct.getInspectionItemSubclass());
                    insUnPass.setLastValue(insProduct.getLastValue());
                    insUnPass.setEntrustCode(insOrderMapper.selectById(orderId).getEntrustCode());
                    List<Integer> userIds = insProductUserMapper.selectList(Wrappers.<InsProductUser>lambdaQuery().eq(InsProductUser::getInsProductId, insProduct.getId())).stream().map(InsProductUser::getCreateUser).distinct().collect(Collectors.toList());
                    String name = userMapper.selectBatchIds(userIds).stream().map(User::getName).collect(Collectors.joining(","));
                    insUnPass.setName(name);
                    insUnPasses.add(insUnPass);
                }
            }
        }
        insUnPassService.saveBatch(insUnPasses);
        InsOrder insOrder = insOrderMapper.selectById(orderId);
        // 抽检变成委托检验
        if (insOrder.getOrderType().equals(InsOrderTypeConstants.SPOT_CHECK)) {
@@ -1572,7 +1558,8 @@
        // 检测依据
        Set<String> standardMethod = new HashSet<>();
        StringBuilder standardMethod2 = new StringBuilder();
        standardMethod.add(baseMapper.getStandardMethodCode(insSample.getStandardMethodListId()));
        // TODO 检验的对象的检验标准由一个多个 数据类型由int变字符串 需要重写写这块逻辑
//        standardMethod.add(baseMapper.getStandardMethodCode(insSample.getStandardMethodListId()));
        for (String s : standardMethod) {
            standardMethod2.append("、").append(s);
        }
@@ -2116,7 +2103,9 @@
        samples.forEach(a -> {
            Map<Integer, String> map2 = new HashMap<>();
            models.add(a.getModel());
            String standardMethodCode = baseMapper.getStandardMethodCode(a.getStandardMethodListId());
            // TODO 检验的对象的检验标准由一个多个 数据类型由int变字符串 需要重写写这块逻辑
//            String standardMethodCode = baseMapper.getStandardMethodCode(a.getStandardMethodListId());
            String standardMethodCode = "";
            if (StrUtil.isNotBlank(a.getSpecialStandardMethod())) {
                standardMethodCode = standardMethodCode + "+" + a.getSpecialStandardMethod();
            }
@@ -4062,7 +4051,7 @@
    }
    /**
     * 保存元此阿里进货验证原始记录
     * *****保存元此阿里进货验证原始记录*****
     * @param insOrderId 订单Id
     * @param examineUserId  复核人Id
     * @param writeUserId  检验员Id
@@ -4212,7 +4201,7 @@
    /**
     * 格式化进厂验证内容
     * ***格式化进厂验证内容****
     * @param basicType
     * @return
     */
@@ -4241,7 +4230,7 @@
    }
    /**
     * word转换pdf
     * ***word转换pdf***
     * @param path
     * @return
     */
@@ -4258,11 +4247,10 @@
        FileOutputStream os = null;
        try {
            //凭证 不然切换后有水印
            InputStream is = Files.newInputStream(new File(licenseUrl).toPath());
            InputStream is = new ClassPathResource("/lib/license.xml").getInputStream();
            License license = new License();
            license.setLicense(is);
            if (!license.getIsLicensed()) {
                System.out.println("License验证不通过...");
                return null;
            }
            //生成一个空的PDF文件
@@ -4289,4 +4277,41 @@
        return null;
    }
    /**
     * *****修改成品抽样状态******
     * @param insSamples
     * @param order
     */
    private void addProductSpotCheck(List<InsSample> insSamples, InsOrder order) {
        Long unqualifiedCount = 0L;
        if (CollectionUtils.isNotEmpty(insSamples)) {
            unqualifiedCount = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery()
                    .in(InsProduct::getInsSampleId, insSamples.stream().map(InsSample::getId).collect(Collectors.toList()))
                    .eq(InsProduct::getInsResult, 0));
            // 判断如果有不合格的检验项, 判断有没有检验项复测, 复核合格也算合格通过
            if (!unqualifiedCount.equals(0L)) {
                List<InsProduct> productList = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
                        .in(InsProduct::getInsSampleId, insSamples.stream().map(InsSample::getId).collect(Collectors.toList()))
                        .eq(InsProduct::getInsResult, 0));
                boolean flag = true;
                for (InsProduct insProduct : productList) {
                    Long unqualifiedProductCount = insUnqualifiedRetestProductMapper.selectCount(Wrappers.<InsUnqualifiedRetestProduct>lambdaQuery()
                            .eq(InsUnqualifiedRetestProduct::getInsProductId, insProduct.getId())
                            .ne(InsUnqualifiedRetestProduct::getInsResult, 0));
                    if (unqualifiedProductCount != 2) {
                        flag = false;
                    }
                }
                if (flag) {
                    unqualifiedCount = 0L;
                }
            }
        }
        spotCheckQuarterItemMapper.update(null, Wrappers.<SpotCheckQuarterItem>lambdaUpdate()
                .eq(SpotCheckQuarterItem::getQuarterItemId, order.getQuarterItemId())
                .set(SpotCheckQuarterItem::getResult, unqualifiedCount.equals(0L) ? "合格" : "不合格"));
    }
}