liding
3 小时以前 51786b723d0a91d11476776d9ce50af7994dc4bd
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java
@@ -57,6 +57,7 @@
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
@@ -107,6 +108,8 @@
    private StandardTemplateService standardTemplateService;
    private InsOrderStandardTemplateMapper insOrderStandardTemplateMapper;
    private InsOrderTemplateDeviceMapper insOrderTemplateDeviceMapper;
    private InsSampleReceiptMapper insSampleReceiptMapper;
    private ApplicationEventPublisher applicationEventPublisher;
@@ -120,7 +123,10 @@
            isOrderAll = "1";
            sampleOrderDto.setState(null);
        }
        return insOrderMapper.selectInsOrderPage(page, QueryWrappers.queryWrappers(sampleOrderDto), laboratory, isOrderAll);
        // 检验中:新聚下单免审核即受理,需样品接收提交后(ins_sample_receipt.status=1)才展示
        String receiptSubmitted = sampleOrderDto.getState() != null && sampleOrderDto.getState() == 1 ? "1" : null;
        return insOrderMapper.selectInsOrderPage(page, QueryWrappers.queryWrappers(sampleOrderDto), laboratory,
                isOrderAll, receiptSubmitted);
    }
@@ -175,13 +181,17 @@
        }
        if (userId != null) {
            InsSampleUser insSampleUser = new InsSampleUser();
            insSampleUser.setState(0);
            insSampleUser.setUserId(userId);
            insSampleUser.setInsSampleId(orderId);
            insSampleUser.setSonLaboratory(directTemplateOrder
                    ? DIRECT_TEMPLATE_LABORATORY : sonLaboratory);
            insSampleUserMapper.insert(insSampleUser);
            Set<String> assignedLaboratories = StringUtils.isBlank(sonLaboratory)
                    ? taskLaboratories
                    : Collections.singleton(sonLaboratory);
            for (String laboratory : assignedLaboratories) {
                InsSampleUser insSampleUser = new InsSampleUser();
                insSampleUser.setState(0);
                insSampleUser.setUserId(userId);
                insSampleUser.setInsSampleId(orderId);
                insSampleUser.setSonLaboratory(laboratory);
                insSampleUserMapper.insert(insSampleUser);
            }
        }
        // 判断订单有没有绑定抽样计划
@@ -412,9 +422,7 @@
            // 审核检验单
            upInsOrderOfState(insOrder);
            // 分配检验人
            String sonLaboratory = insOrder.getTypeSource().equals(1)?"原材料":"成品实验室";
            upInsOrder(insOrder.getId(), null, appointed != null ? appointed.toString() : null, SecurityUtils.getUserId().intValue(), sonLaboratory);
            // 审核通过后仅进入样品接收;由样品接收页面选择主检验人后再创建检验任务。
            //是否为原材料下单
            if(insOrder.getTypeSource().equals(1)){
@@ -477,6 +485,24 @@
        if (StringUtils.isBlank(sampleCode) || sampleCode.length() < 2) {
            throw new ErrorException("样品编号不能为空且不能少于2位");
        }
        // 委托要求字段校验:四组单选必选,分包/快递联动必填
        InsOrder reqOrder = dto.getInsOrder();
        if (reqOrder.getSubcontractType() == null || reqOrder.getSampleDisposal() == null
                || reqOrder.getResultEvaluation() == null || reqOrder.getReportDelivery() == null) {
            throw new ErrorException("请选择分包内容、样品处置、对结果评价和报告交付方式");
        }
        if (Integer.valueOf(1).equals(reqOrder.getSubcontractType())
                && StringUtils.isBlank(reqOrder.getSubcontractCompany())) {
            throw new ErrorException("分包内容为有时,分包单位信息不能为空");
        }
        if (Integer.valueOf(2).equals(reqOrder.getReportDelivery())) {
            if (StringUtils.isBlank(reqOrder.getReportAddress())) {
                throw new ErrorException("报告交付方式为快递时,报告寄送地址不能为空");
            }
            if (StringUtils.isBlank(reqOrder.getReportReceiver())) {
                throw new ErrorException("报告交付方式为快递时,收件人及电话不能为空");
            }
        }
        StandardTree standard = standardTreeService.getById(dto.getStandardTreeId());
        if (standard == null || StringUtils.isBlank(standard.getSample())
                || standard.getSampleType() != null || standard.getModel() != null) {
@@ -537,7 +563,9 @@
        InsOrder order = dto.getInsOrder();
        order.setId(null);
        order.setState(0);
        // 新聚下单免审核:直接受理,下单即流转到样品接收
        order.setState(1);
        order.setExamineTime(LocalDateTime.now());
        order.setIsExemption(0);
        order.setFactory(null);
        order.setLaboratory(standard.getLaboratory());
@@ -549,6 +577,14 @@
        // 新聚订单的环境条件由检验任务填写,避免下单模板或浏览器缓存带入旧值。
        order.setTemperature(null);
        order.setHumidity(null);
        // 未命中联动条件时清空对应文本字段,避免模板快照或浏览器缓存带入旧值。
        if (!Integer.valueOf(1).equals(order.getSubcontractType())) {
            order.setSubcontractCompany(null);
        }
        if (!Integer.valueOf(2).equals(order.getReportDelivery())) {
            order.setReportAddress(null);
            order.setReportReceiver(null);
        }
        insOrderMapper.insert(order);
        InsSample sample = new InsSample();
@@ -590,6 +626,10 @@
        insOrderMapper.update(null, Wrappers.<InsOrder>lambdaUpdate()
                .eq(InsOrder::getId, order.getId())
                .set(InsOrder::getEntrustCode, entrustCode));
        // 免审核后由下单生成待接收的样品接收记录,主检验人仍在样品接收页面选择后才创建检验任务
        insSampleReceiptMapper.insertIgnore(order.getId(), sample.getId());
        // 同事务内发布下单事件,由 cnas-process 自动生成检验委托单;监听器异常会连带下单回滚
        applicationEventPublisher.publishEvent(new com.ruoyi.inspect.event.NewJuOrderPlacedEvent(order.getId()));
        return order.getId();
    }
@@ -701,6 +741,7 @@
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int upInsOrderOfState(InsOrder insOrder) {
        insOrder.setExamineTime(LocalDateTime.now());
        if (insOrder.getState() == 1) {
@@ -746,7 +787,17 @@
            insOrder.setEntrustCode(no);
        }
        return insOrderMapper.updateById(insOrder);
        int updated = insOrderMapper.updateById(insOrder);
        if (updated > 0 && Integer.valueOf(1).equals(insOrder.getState())) {
            List<InsSample> samples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery()
                    .eq(InsSample::getInsOrderId, insOrder.getId())
                    .orderByAsc(InsSample::getId));
            if (samples.size() != 1) {
                throw new ErrorException("委托单必须且只能包含一个样品,不能进入样品接收流程");
            }
            insSampleReceiptMapper.insertIgnore(insOrder.getId(), samples.get(0).getId());
        }
        return updated;
    }
    /**
@@ -1104,7 +1155,7 @@
        insOrder.setState(1);
        upInsOrderOfState(insOrder);
        upInsOrder(insOrder.getId(), null, appointed != null ? appointed.toString() : null, SecurityUtils.getUserId().intValue(), "原材料");
        // 审核通过后仅进入样品接收;由样品接收页面选择主检验人后再创建检验任务。
        return insOrder.getId();
    }