liding
2 天以前 3fdea1ab6ab545de0a25573318ecd838de3be576
feat: 1.检验任务查询优化 2.模板时间和地点保存
已修改3个文件
190 ■■■■ 文件已修改
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java 62 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/resources/mapper/InsSampleMapper.xml 83 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
@@ -92,6 +92,7 @@
    private static final int DETECTION_REPORT = 0;
    private static final int INSPECTION_REPORT = 1;
    private static final String DIRECT_TEMPLATE_LABORATORY = "新聚";
    @Resource
    private InsSampleMapper insSampleMapper;
@@ -225,6 +226,7 @@
    @Override
    public Map<String, Object> doInsOrder(Integer id, String laboratory) {
        ensureDirectTemplateOrderState(id);
        InsOrder order = insOrderMapper.selectById(id);
        Map<String, Object> map = insOrderService.getInsOrderAndSample(id, laboratory);
        List<SampleProductDto> list = JSON.parseArray(JSON.toJSONString(map.get("sampleProduct")), SampleProductDto.class);
@@ -345,7 +347,22 @@
        Map<String, Object> map = new HashMap<>();
        List<String> collect = new ArrayList<>();
        if (isDirectTemplateOrder(orderId)) {
            map.put("errorMsg", Collections.emptyList());
            List<InsOrderStandardTemplate> snapshots = insOrderStandardTemplateService.list(
                    Wrappers.<InsOrderStandardTemplate>lambdaQuery()
                            .eq(InsOrderStandardTemplate::getInsOrderId, orderId)
                            .orderByAsc(InsOrderStandardTemplate::getSort,
                                    InsOrderStandardTemplate::getId));
            for (InsOrderStandardTemplate snapshot : snapshots) {
                String templateName = StringUtils.defaultIfBlank(snapshot.getName(),
                        "模板ID " + snapshot.getTemplateId());
                if (snapshot.getDetectionTime() == null) {
                    collect.add("请选择“" + templateName + "”的检测时间");
                }
                if (StringUtils.isBlank(snapshot.getDetectionPlace())) {
                    collect.add("请填写“" + templateName + "”的检测地点");
                }
            }
            map.put("errorMsg", collect);
            map.put("missingExportItems", getMissingTemplateExportValues(orderId));
            map.put("unInsOrderCount", 0L);
            return map;
@@ -608,6 +625,7 @@
        if (snapshot == null) {
            throw new ErrorException("未找到当前订单的原始记录模板快照");
        }
        ensureDirectTemplateOrderState(dto.getOrderId());
        List<InsProduct> products = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
                .eq(InsProduct::getInsSampleId, dto.getSampleId())
                .eq(InsProduct::getTemplateId, dto.getTemplateId())
@@ -670,6 +688,9 @@
                .map(InsProduct::getSonLaboratory)
                .filter(StringUtils::isNotBlank)
                .collect(Collectors.toSet());
        if (laboratories.isEmpty() && isDirectTemplateOrder(orderId)) {
            laboratories.add(DIRECT_TEMPLATE_LABORATORY);
        }
        if (!laboratories.isEmpty()) {
            insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate()
                    .eq(InsOrderState::getInsOrderId, orderId)
@@ -1071,6 +1092,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int submitPlan(Integer orderId, String laboratory, Integer verifyUser, String entrustCode, Boolean registerInsResults) {
        ensureDirectTemplateOrderState(orderId);
        int reportType = DETECTION_REPORT;
        InsOrder order = insOrderMapper.selectOne(Wrappers.<InsOrder>lambdaQuery()
                .eq(InsOrder::getId, orderId)
@@ -1531,6 +1553,7 @@
        if (orderId == null || laboratory == null || type == null) {
            throw new ErrorException("复核参数不完整");
        }
        ensureDirectTemplateOrderState(orderId);
        InsOrderState currentState = insOrderStateMapper.selectOne(Wrappers.<InsOrderState>lambdaQuery()
                .eq(InsOrderState::getInsOrderId, orderId)
                .eq(InsOrderState::getLaboratory, laboratory)
@@ -1719,6 +1742,26 @@
                .isNotNull(InsProduct::getTemplateRowIndex)) > 0;
    }
    /**
     * 兼容修复上线前已经下发、但因没有 ins_product 而缺少任务状态的直绑模板订单。
     */
    private void ensureDirectTemplateOrderState(Integer orderId) {
        if (!isDirectTemplateOrder(orderId)) {
            return;
        }
        Long stateCount = insOrderStateMapper.selectCount(Wrappers.<InsOrderState>lambdaQuery()
                .eq(InsOrderState::getInsOrderId, orderId)
                .eq(InsOrderState::getLaboratory, DIRECT_TEMPLATE_LABORATORY));
        if (stateCount > 0) {
            return;
        }
        InsOrderState state = new InsOrderState();
        state.setInsOrderId(orderId);
        state.setLaboratory(DIRECT_TEMPLATE_LABORATORY);
        state.setInsState(0);
        insOrderStateMapper.insert(state);
    }
    private Integer resolveInspectionUserId(Integer orderId, String laboratory) {
        InsSampleUser inspector = insSampleUserMapper.selectOne(Wrappers.<InsSampleUser>lambdaQuery()
                .eq(InsSampleUser::getInsSampleId, orderId)
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);
inspect-server/src/main/resources/mapper/InsSampleMapper.xml
@@ -166,11 +166,36 @@
               ip.structure_item_parameter_id
    </sql>
    <!--
        直绑模板订单不依赖 ins_product。通过订单模板快照和单样品标准结构识别,
        列表、任务切换及详情统一使用固定任务实验室“新聚”。
    -->
    <sql id="directTemplateOrderJoin">
        LEFT JOIN (
            SELECT DISTINCT iost.ins_order_id
            FROM ins_order_standard_template iost
            INNER JOIN ins_order dto ON dto.id = iost.ins_order_id
            INNER JOIN ins_sample dts ON dts.ins_order_id = dto.id
            WHERE dts.standard_method_list_id IS NULL
              AND (dts.factory IS NULL OR TRIM(dts.factory) = '')
              AND (dts.sample_type IS NULL OR TRIM(dts.sample_type) = '')
              AND (dts.model IS NULL OR TRIM(dts.model) = '')
              AND (dto.factory IS NULL OR TRIM(dto.factory) = '')
              AND (dto.sample_type IS NULL OR TRIM(dto.sample_type) = '')
        ) direct_template ON direct_template.ins_order_id = io.id
    </sql>
    <select id="findInsSampleAndOrder" resultType="com.ruoyi.inspect.vo.InsOrderPlanVO">
        select * from(select * from(
        SELECT
        a.*,ios.ins_state,ios.verify_tell,verify_user
        a.*,
        CASE
            WHEN ios.ins_state IS NULL AND a.direct_template = 1 THEN 0
            ELSE ios.ins_state
        END AS ins_state,
        ios.verify_tell,
        verify_user
        FROM
        (
        SELECT
@@ -187,7 +212,11 @@
        GROUP_CONCAT(DISTINCT isa.model SEPARATOR ' ') AS sample_model,
        userName,
        checkName,
        ip.son_laboratory,
        CASE
            WHEN direct_template.ins_order_id IS NOT NULL THEN '新聚'
            ELSE ip.son_laboratory
        END AS son_laboratory,
        CASE WHEN direct_template.ins_order_id IS NOT NULL THEN 1 ELSE 0 END AS direct_template,
        io.ins_time,
        io.laboratory,
        io.type_source,
@@ -204,6 +233,7 @@
        LEFT JOIN ins_sample isa ON isa.ins_order_id = io.id
        LEFT JOIN ins_report ira ON ira.ins_order_id = io.id
        LEFT JOIN ifs_inventory_quantity iiq ON iiq.id = io.ifs_inventory_id
        <include refid="directTemplateOrderJoin"/>
        LEFT JOIN (
        SELECT ins_sample_id,GROUP_CONCAT( DISTINCT uu.name SEPARATOR ',') AS userName
        FROM ins_sample_user u LEFT JOIN  user uu ON u.user_id = uu.id
@@ -237,10 +267,16 @@
            </if>
        </if>
        <if test="sonLaboratory!= null and sonLaboratory != ''">
            and ip.son_laboratory = #{sonLaboratory}
            and CASE
                    WHEN direct_template.ins_order_id IS NOT NULL THEN '新聚'
                    ELSE ip.son_laboratory
                END = #{sonLaboratory}
        </if>
        GROUP BY
        ip.son_laboratory,
        CASE
            WHEN direct_template.ins_order_id IS NOT NULL THEN '新聚'
            ELSE ip.son_laboratory
        END,
        io.id
        ) a
        LEFT JOIN ins_order_state ios ON ios.ins_order_id = a.id AND ios.laboratory = a.son_laboratory
@@ -248,7 +284,7 @@
        a.type DESC,
        a.id
        ) b
        where ins_state is not null
        where (ins_state is not null or direct_template = 1)
        <if test="laboratory!=null and laboratory!=''">
            and laboratory=#{laboratory}
        </if>
@@ -263,7 +299,12 @@
    <select id="inspectionOrderDetailsTaskSwitching" resultType="com.ruoyi.inspect.vo.InsOrderPlanTaskSwitchVo">
        select * from(
        SELECT
        a.*,ios.ins_state,ios.verify_tell,isu2.order_user_id,<!--(ios.verify_user = #{userId})--> verify_user
        a.*,
        CASE
            WHEN ios.ins_state IS NULL AND a.direct_template = 1 THEN 0
            ELSE ios.ins_state
        END AS ins_state,
        ios.verify_tell,isu2.order_user_id,<!--(ios.verify_user = #{userId})--> verify_user
        FROM
        (
        SELECT
@@ -275,12 +316,17 @@
        group_concat(distinct isa.sample,' ') sampleType,
        isu.user_id,
        user.name userName,
        ip.son_laboratory,
        CASE
            WHEN direct_template.ins_order_id IS NOT NULL THEN '新聚'
            ELSE ip.son_laboratory
        END AS son_laboratory,
        CASE WHEN direct_template.ins_order_id IS NOT NULL THEN 1 ELSE 0 END AS direct_template,
        io.ins_time,
        io.laboratory
        FROM
        ins_order io
        LEFT JOIN ins_sample isa ON isa.ins_order_id = io.id
        <include refid="directTemplateOrderJoin"/>
        LEFT JOIN ( <!--SELECT * FROM ins_sample_user GROUP BY ins_sample_id, user_id -->
        SELECT *
        FROM ins_sample_user u
@@ -303,7 +349,10 @@
        </if>
        OR isu.user_id is NULL
        GROUP BY
        ip.son_laboratory,
        CASE
            WHEN direct_template.ins_order_id IS NOT NULL THEN '新聚'
            ELSE ip.son_laboratory
        END,
        io.id
        ) a
        LEFT JOIN ins_order_state ios ON ios.ins_order_id = a.id AND ios.laboratory = a.son_laboratory
@@ -315,7 +364,7 @@
        OR user_id is NULL
        ) isu2 on
        isu2.ins_sample_id = a.id
        where ins_state is not null
        where (ins_state is not null or direct_template = 1)
        <if test="laboratory != null and laboratory != ''">
            and a.laboratory=#{laboratory}
        </if>
@@ -404,7 +453,7 @@
               ip.sample_type ip_sample_type,
               ip.sample      ip_sample,
               ip.model       ip_model,
               son_laboratory,
               ip.son_laboratory,
               ip.unit        ip_unit,
               price,
               man_hour,
@@ -442,8 +491,18 @@
                 left join ins_product ip on isa.id = ip.ins_sample_id
                 left join ins_product_result ipr on ip.id = ipr.ins_product_id
        where ins_order_id = #{id}
          and state = 1
          and ip.son_laboratory = #{laboratory}
          and (
              (ip.state = 1 and ip.son_laboratory = #{laboratory})
              or (
                  ip.id is null
                  and #{laboratory} = '新聚'
                  and exists (
                      select 1
                      from ins_order_standard_template iost
                      where iost.ins_order_id = isa.ins_order_id
                  )
              )
          )
    </select>
    <select id="getSampleEn" resultType="java.lang.String">
        select name_en