2 天以前 f7273277023f3497ac071bf98f556a569cb4dd25
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/bagcode/MesProBagCodeMapper.java
@@ -27,6 +27,39 @@
        return selectOne(MesProBagCodeDO::getCode, code);
    }
    default MesProBagCodeDO selectByCodeForUpdate(String code) {
        return selectOne(new LambdaQueryWrapperX<MesProBagCodeDO>()
                .eq(MesProBagCodeDO::getCode, code).last("FOR UPDATE"));
    }
    @org.apache.ibatis.annotations.Update("UPDATE mes_pro_bag_code SET inbound_time = NOW(), inbound_event_id = #{eventId}, inbound_device_code = #{deviceCode}, inbound_line_code = #{lineCode}, update_time = NOW() WHERE id = #{id} AND deleted = 0 AND inbound_event_id IS NULL")
    int markInbound(@org.apache.ibatis.annotations.Param("id") Long id, @org.apache.ibatis.annotations.Param("eventId") Long eventId,
                    @org.apache.ibatis.annotations.Param("deviceCode") String deviceCode, @org.apache.ibatis.annotations.Param("lineCode") String lineCode);
    /** 批次整批入库时批量标记其下未入库袋码(幂等),保持袋码与库存状态一致 */
    @Update("UPDATE mes_pro_bag_code SET inbound_time = NOW(), inbound_event_id = #{eventId}, inbound_line_code = #{lineCode}, update_time = NOW() "
            + "WHERE deleted = 0 AND inbound_event_id IS NULL AND batch_id = #{batchId}")
    int markInboundByBatchId(@Param("batchId") Long batchId, @Param("eventId") Long eventId,
                             @Param("lineCode") String lineCode);
    /** 整托入库时批量标记托盘下未入库袋码(幂等) */
    @Update("UPDATE mes_pro_bag_code SET inbound_time = NOW(), inbound_event_id = #{eventId}, inbound_line_code = #{lineCode}, update_time = NOW() "
            + "WHERE deleted = 0 AND inbound_event_id IS NULL AND pallet_id = #{palletId}")
    int markInboundByPalletId(@Param("palletId") Long palletId, @Param("eventId") Long eventId,
                              @Param("lineCode") String lineCode);
    /**
     * 更新袋码质检状态(种子质检合格/不合格时记录该袋结果)
     *
     * @param id       袋码编号
     * @param qcStatus 质检状态(见 MesProBagCodeQcStatusEnum)
     */
    default void updateQcStatus(Long id, Integer qcStatus) {
        update(null, new LambdaUpdateWrapper<MesProBagCodeDO>()
                .eq(MesProBagCodeDO::getId, id)
                .set(MesProBagCodeDO::getQcStatus, qcStatus));
    }
    default List<MesProBagCodeDO> selectListByUuid(String uuid) {
        return selectList(MesProBagCodeDO::getUuid, uuid);
    }
@@ -58,9 +91,11 @@
                .likeIfPresent(MesProBagCodeDO::getBatchCode, reqVO.getBatchCode())
                .eqIfPresent(MesProBagCodeDO::getUuid, reqVO.getUuid())
                .eqIfPresent(MesProBagCodeDO::getPalletId, reqVO.getPalletId())
                .eqIfPresent(MesProBagCodeDO::getItemId, reqVO.getItemId())
                .eqIfPresent(MesProBagCodeDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MesProBagCodeDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(MesProBagCodeDO::getBagNo));
                .orderByDesc(MesProBagCodeDO::getCreateTime)
                .orderByDesc(MesProBagCodeDO::getId));
    }
    /**
@@ -75,6 +110,18 @@
                .set(MesProBagCodeDO::getPalletId, palletId)
                .set(MesProBagCodeDO::getPalletCode, palletCode)
                .in(MesProBagCodeDO::getId, ids));
    }
    /**
     * 托盘正式码生成后,回写其下所有袋码的冗余托盘码
     *
     * @param palletId   托盘编号
     * @param palletCode 正式托盘码
     */
    default void updatePalletCodeByPalletId(Long palletId, String palletCode) {
        update(null, new LambdaUpdateWrapper<MesProBagCodeDO>()
                .set(MesProBagCodeDO::getPalletCode, palletCode)
                .eq(MesProBagCodeDO::getPalletId, palletId));
    }
    /**
@@ -95,8 +142,28 @@
     * @param batchId 批次编号
     * @return 最大袋序号,无记录返回 0
     */
    @Select("SELECT IFNULL(MAX(bag_no), 0) FROM mes_pro_bag_code WHERE batch_id = #{batchId}")
    Integer selectMaxBagNo(@Param("batchId") Long batchId);
    @Select("SELECT IFNULL(MAX(bag_no), 0) FROM mes_pro_bag_code")
    Integer selectMaxBagNo();
    @Update("<script>UPDATE mes_pro_bag_code SET batch_id = #{batchId}, batch_code = #{batchCode}, update_time = NOW() " +
            "WHERE deleted = 0 AND batch_id IS NULL AND status IN " +
            "<foreach collection='statuses' item='st' open='(' separator=',' close=')'>#{st}</foreach> AND id IN " +
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>#{id}</foreach></script>")
    int bindBatchByIds(@Param("ids") Collection<Long> ids, @Param("batchId") Long batchId,
                       @Param("batchCode") String batchCode, @Param("statuses") Collection<Integer> statuses);
    /** 查询托盘下尚未绑定批次的袋码(托盘绑定批次时级联录入用) */
    default List<MesProBagCodeDO> selectUnboundListByPalletIds(Collection<Long> palletIds) {
        return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>()
                .in(MesProBagCodeDO::getPalletId, palletIds)
                .isNull(MesProBagCodeDO::getBatchId)
                .orderByAsc(MesProBagCodeDO::getId));
    }
    /** 批次内有效袋码的品种编号集合(忽略历史空品种袋码),用于录入批次时的品种一致性校验 */
    @Select("SELECT DISTINCT item_id FROM mes_pro_bag_code " +
            "WHERE deleted = 0 AND status <> 30 AND batch_id = #{batchId} AND item_id IS NOT NULL")
    List<Long> selectDistinctItemIdsByBatchId(@Param("batchId") Long batchId);
    default List<MesProBagCodeDO> selectListByIdsForUpdate(Collection<Long> ids) {
        return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>()
@@ -112,6 +179,15 @@
                   @Param("toStatus") Integer toStatus, @Param("cancelTime") LocalDateTime cancelTime,
                   @Param("cancelReason") String cancelReason);
    @Update("UPDATE mes_pro_bag_code SET sales_id = #{salesId}, outbound_time = #{outboundTime}, update_time = NOW() "
            + "WHERE id = #{id} AND deleted = 0")
    void markOutbound(@Param("id") Long id, @Param("salesId") Long salesId,
                      @Param("outboundTime") LocalDateTime outboundTime);
    @Update("UPDATE mes_pro_bag_code SET sales_id = NULL, outbound_time = NULL, update_time = NOW() "
            + "WHERE id = #{id} AND deleted = 0")
    void clearOutbound(@Param("id") Long id);
    @Select("SELECT COUNT(*) FROM mes_pro_bag_code WHERE batch_id = #{batchId} " +
            "AND deleted = 0 AND status <> 30")
    int selectEffectiveCountByBatchId(@Param("batchId") Long batchId);