liding
2 天以前 bd46f203b0d30a3d33b7c51ae9a528e4807477e1
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java
@@ -84,6 +84,8 @@
public class InsOrderServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder>
        implements InsOrderService {
    private static final String DIRECT_TEMPLATE_LABORATORY = "新聚";
    private InsOrderMapper insOrderMapper;
    private InsSampleService insSampleService;
    private InsSampleMapper insSampleMapper;
@@ -137,36 +139,52 @@
        insOrderMapper.updateById(insOrder);
        List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId));
        List<Integer> ids = insSamples.stream().map(InsSample::getId).collect(Collectors.toList());
        List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
                .in(InsProduct::getInsSampleId, ids)
                .eq(InsProduct::getState, 1)
                .select(InsProduct::getSonLaboratory).groupBy(InsProduct::getSonLaboratory));
        List<InsProduct> insProducts = ids.isEmpty()
                ? Collections.emptyList()
                : insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
                        .in(InsProduct::getInsSampleId, ids)
                        .eq(InsProduct::getState, 1)
                        .select(InsProduct::getSonLaboratory).groupBy(InsProduct::getSonLaboratory));
        InsOrder order = insOrderMapper.selectById(orderId);
        boolean directTemplateOrder = isDirectTemplateOrder(order, insSamples);
        Set<String> taskLaboratories = directTemplateOrder
                ? Collections.singleton(DIRECT_TEMPLATE_LABORATORY)
                : insProducts.stream()
                        .map(InsProduct::getSonLaboratory)
                        .filter(StringUtils::isNotBlank)
                        .collect(Collectors.toCollection(LinkedHashSet::new));
        if (!directTemplateOrder && taskLaboratories.size() != insProducts.size()) {
            throw new ErrorException("该检验单有未维护实验室的检验项目");
        }
        // 批量添加检验任务状态表
        List<InsOrderState> insOrderStateList = insProducts.stream().map(insProduct -> {
        List<InsOrderState> insOrderStateList = taskLaboratories.stream()
                .filter(laboratory -> insOrderStateService.count(Wrappers.<InsOrderState>lambdaQuery()
                        .eq(InsOrderState::getInsOrderId, orderId)
                        .eq(InsOrderState::getLaboratory, laboratory)) == 0)
                .map(laboratory -> {
            InsOrderState insOrderState = new InsOrderState();
            insOrderState.setInsOrderId(orderId);
            try {
                insOrderState.setLaboratory(insProduct.getSonLaboratory());
            } catch (NullPointerException e) {
                throw new ErrorException("该检验单有未维护实验室的检验项目");
            }
            insOrderState.setLaboratory(laboratory);
            insOrderState.setInsState(0);
            return insOrderState;
        }).collect(Collectors.toList());
        insOrderStateService.saveBatch(insOrderStateList);
        if (!insOrderStateList.isEmpty()) {
            insOrderStateService.saveBatch(insOrderStateList);
        }
        if (userId != null) {
            InsSampleUser insSampleUser = new InsSampleUser();
            insSampleUser.setState(0);
            insSampleUser.setUserId(userId);
            insSampleUser.setInsSampleId(orderId);
            insSampleUser.setSonLaboratory(sonLaboratory);
            insSampleUser.setSonLaboratory(directTemplateOrder
                    ? DIRECT_TEMPLATE_LABORATORY : sonLaboratory);
            insSampleUserMapper.insert(insSampleUser);
        }
        // 判断订单有没有绑定抽样计划
        InsOrder order = insOrderMapper.selectById(orderId);
        if (order.getQuarterItemId() != null) {
           // 需要添加下发时间到抽样时间, 取样人员就是检测人
            SpotCheckQuarterItem spotCheckQuarterItem = spotCheckQuarterItemMapper.selectById(order.getQuarterItemId());
@@ -177,6 +195,22 @@
        }
        return 1;
    }
    private boolean isDirectTemplateOrder(InsOrder order, List<InsSample> samples) {
        if (order == null || CollectionUtils.isEmpty(samples)) {
            return false;
        }
        Long snapshotCount = insOrderStandardTemplateMapper.selectCount(
                Wrappers.<InsOrderStandardTemplate>lambdaQuery()
                        .eq(InsOrderStandardTemplate::getInsOrderId, order.getId()));
        return snapshotCount > 0 && samples.stream().anyMatch(sample ->
                sample.getStandardMethodListId() == null
                        && StringUtils.isBlank(sample.getFactory())
                        && StringUtils.isBlank(sample.getSampleType())
                        && StringUtils.isBlank(sample.getModel())
                        && StringUtils.isBlank(order.getFactory())
                        && StringUtils.isBlank(order.getSampleType()));
    }
@@ -530,7 +564,7 @@
            product.setModel(null);
            product.setTemplateId(item.getTemplateId());
            product.setTemplateRowIndex(item.getTemplateRowIndex());
            product.setSonLaboratory("新聚");
            product.setSonLaboratory(DIRECT_TEMPLATE_LABORATORY);
            product.setState(1);
            product.setSort(productSort++);
            insProductMapper.insert(product);