2 天以前 f7273277023f3497ac071bf98f556a569cb4dd25
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/pallet/MesProPalletMapper.java
@@ -5,6 +5,7 @@
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.mes.controller.admin.pro.pallet.vo.MesProPalletPageReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.pallet.MesProPalletDO;
import cn.iocoder.yudao.module.mes.enums.pro.MesProPalletStatusEnum;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@@ -23,13 +24,35 @@
        return selectOne(MesProPalletDO::getCode, code);
    }
    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);
    default List<MesProPalletDO> selectListByBatchId(Long batchId) {
        return selectList(MesProPalletDO::getBatchId, batchId);
    }
    /** 查询未绑定生产批次的临时托盘(无正式托盘码且未作废),供批次新增/补录绑定托盘下拉使用 */
    default List<MesProPalletDO> selectUnboundList() {
        return selectList(new LambdaQueryWrapperX<MesProPalletDO>()
                .isNull(MesProPalletDO::getBatchId)
                .isNull(MesProPalletDO::getCode)
                .eq(MesProPalletDO::getStatus, MesProPalletStatusEnum.IN_USE.getStatus())
                .orderByAsc(MesProPalletDO::getId));
    }
    default PageResult<MesProPalletDO> selectPage(MesProPalletPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MesProPalletDO>()
                .likeIfPresent(MesProPalletDO::getCode, reqVO.getCode())
                .likeIfPresent(MesProPalletDO::getTempCode, reqVO.getTempCode())
                .eqIfPresent(MesProPalletDO::getBatchId, reqVO.getBatchId())
                .likeIfPresent(MesProPalletDO::getBatchCode, reqVO.getBatchCode())
                .eqIfPresent(MesProPalletDO::getStatus, reqVO.getStatus())
@@ -46,4 +69,18 @@
    @Select("SELECT IFNULL(MAX(pallet_no), 0) FROM mes_pro_pallet WHERE batch_id = #{batchId}")
    Integer selectMaxPalletNo(@Param("batchId") Long batchId);
    @org.apache.ibatis.annotations.Update("UPDATE mes_pro_pallet 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") java.time.LocalDateTime outboundTime);
    /** 整托扫码入库回写:幂等(已有入库标记的不再更新),用于防重复入库 */
    @org.apache.ibatis.annotations.Update("UPDATE mes_pro_pallet SET inbound_event_id = #{eventId}, inbound_time = NOW(), update_time = NOW() "
            + "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 SET sales_id = NULL, outbound_time = NULL, update_time = NOW() "
            + "WHERE id = #{id} AND deleted = 0")
    void clearOutbound(@Param("id") Long id);
}