liu
8 小时以前 66517edf1de22c8203daa256abffddae43bae704
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/pallet/MesProPalletMapper.java
@@ -24,14 +24,21 @@
        return selectOne(MesProPalletDO::getCode, code);
    }
    default MesProPalletDO selectByScanCode(String code) {
        return selectOne(new LambdaQueryWrapperX<MesProPalletDO>().and(q ->
                q.eq(MesProPalletDO::getBusinessCode, code).or().eq(MesProPalletDO::getCode, code)
                        .or().eq(MesProPalletDO::getTempCode, code)));
    }
    default MesProPalletDO selectByScanCodeForUpdate(String code) {
        return selectOne(new LambdaQueryWrapperX<MesProPalletDO>().and(q ->
                q.eq(MesProPalletDO::getBusinessCode, code).or().eq(MesProPalletDO::getCode, code)
                        .or().eq(MesProPalletDO::getTempCode, code)).last("FOR UPDATE"));
    }
    default MesProPalletDO selectByTempCode(String tempCode) {
        return selectOne(MesProPalletDO::getTempCode, tempCode);
    }
    /** 生成临时托盘码用的全局序号:解析 temp_code 的数字后缀,不存在则返回 0。
     *  不能过滤 deleted,唯一索引 uk_temp_code 对逻辑删除行仍生效,忽略软删会导致序号回退、码值重复 */
    @Select("SELECT IFNULL(MAX(CAST(SUBSTRING(temp_code, 4) AS UNSIGNED)), 0) FROM mes_pro_pallet")
    Integer selectMaxTempCodeSeq();
    @Select("SELECT * FROM mes_pro_pallet WHERE id = #{id} AND deleted = 0 FOR UPDATE")
    MesProPalletDO selectByIdForUpdate(@Param("id") Long id);
@@ -49,15 +56,35 @@
                .orderByAsc(MesProPalletDO::getId));
    }
    /**
     * 查询袋码绑定托盘时可选的目标托盘:未作废的临时托盘与正式托盘。
     * <p>
     * 传入品种时仅返回该品种的托盘,以及尚未确定品种的预生成临时托盘(item_id 为空,绑定袋码时回填品种)。
     *
     * @param itemId 袋码品种编号,可为空
     * @return 托盘列表
     */
    default List<MesProPalletDO> selectBindableList(Long itemId) {
        return selectList(new LambdaQueryWrapperX<MesProPalletDO>()
                .ne(MesProPalletDO::getStatus, MesProPalletStatusEnum.CANCELED.getStatus())
                .and(itemId != null, q -> q.eq(MesProPalletDO::getItemId, itemId)
                        .or().isNull(MesProPalletDO::getItemId))
                .orderByDesc(MesProPalletDO::getId));
    }
    default PageResult<MesProPalletDO> selectPage(MesProPalletPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MesProPalletDO>()
                .likeIfPresent(MesProPalletDO::getCode, reqVO.getCode())
                .likeIfPresent(MesProPalletDO::getBusinessCode, reqVO.getBusinessCode())
                .likeIfPresent(MesProPalletDO::getTempCode, reqVO.getTempCode())
                .eqIfPresent(MesProPalletDO::getBatchId, reqVO.getBatchId())
                .likeIfPresent(MesProPalletDO::getBatchCode, reqVO.getBatchCode())
                .eqIfPresent(MesProPalletDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MesProPalletDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MesProPalletDO::getId));
                .orderByDesc(MesProPalletDO::getId)
                .and(cn.hutool.core.util.StrUtil.isNotBlank(reqVO.getCode()), q ->
                        q.like(MesProPalletDO::getCode, reqVO.getCode()).or()
                                .like(MesProPalletDO::getBusinessCode, reqVO.getCode()).or()
                                .like(MesProPalletDO::getTempCode, reqVO.getCode())));
    }
    /**
@@ -79,6 +106,13 @@
            + "WHERE id = #{id} AND deleted = 0 AND inbound_event_id IS NULL")
    int markInbound(@Param("id") Long id, @Param("eventId") Long eventId);
    /** 单袋、整托、整批入库后,只有有效袋码全部入库的托盘才同步标记已入库。 */
    @org.apache.ibatis.annotations.Update("UPDATE mes_pro_pallet p SET inbound_event_id = #{eventId}, inbound_time = NOW(), update_time = NOW() "
            + "WHERE p.batch_id = #{batchId} AND p.deleted = 0 AND p.status <> 20 AND p.inbound_event_id IS NULL "
            + "AND EXISTS (SELECT 1 FROM mes_pro_bag_code b WHERE b.pallet_id = p.id AND b.deleted = 0 AND b.status <> 30) "
            + "AND NOT EXISTS (SELECT 1 FROM mes_pro_bag_code b WHERE b.pallet_id = p.id AND b.deleted = 0 AND b.status <> 30 AND b.inbound_event_id IS NULL)")
    int markCompletedInboundByBatchId(@Param("batchId") Long batchId, @Param("eventId") Long eventId);
    @org.apache.ibatis.annotations.Update("UPDATE mes_pro_pallet SET sales_id = NULL, outbound_time = NULL, update_time = NOW() "
            + "WHERE id = #{id} AND deleted = 0")
    void clearOutbound(@Param("id") Long id);