2 天以前 ac2545f3cd01f3061a107e4980fc6fa59eaeaa6b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package cn.iocoder.yudao.module.mes.dal.mysql.pro.bagcode;
 
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.mes.controller.admin.pro.bagcode.vo.MesProBagCodePageReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.bagcode.MesProBagCodeDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
 
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
 
/**
 * MES 袋码赋码(一袋一码)Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface MesProBagCodeMapper extends BaseMapperX<MesProBagCodeDO> {
 
    default MesProBagCodeDO selectByCode(String code) {
        return selectOne(MesProBagCodeDO::getCode, code);
    }
 
    default List<MesProBagCodeDO> selectListByUuid(String uuid) {
        return selectList(MesProBagCodeDO::getUuid, uuid);
    }
 
    default List<MesProBagCodeDO> selectListByIds(Collection<Long> ids) {
        return selectBatchIds(ids);
    }
 
    default List<MesProBagCodeDO> selectListByBatchId(Long batchId) {
        return selectList(MesProBagCodeDO::getBatchId, batchId);
    }
 
    default Long selectCountByBatchId(Long batchId) {
        return selectCount(MesProBagCodeDO::getBatchId, batchId);
    }
 
    default Long selectCountByPalletId(Long palletId) {
        return selectCount(MesProBagCodeDO::getPalletId, palletId);
    }
 
    default List<MesProBagCodeDO> selectListByPalletId(Long palletId) {
        return selectList(MesProBagCodeDO::getPalletId, palletId);
    }
 
    default PageResult<MesProBagCodeDO> selectPage(MesProBagCodePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MesProBagCodeDO>()
                .likeIfPresent(MesProBagCodeDO::getCode, reqVO.getCode())
                .eqIfPresent(MesProBagCodeDO::getBatchId, reqVO.getBatchId())
                .likeIfPresent(MesProBagCodeDO::getBatchCode, reqVO.getBatchCode())
                .eqIfPresent(MesProBagCodeDO::getUuid, reqVO.getUuid())
                .eqIfPresent(MesProBagCodeDO::getPalletId, reqVO.getPalletId())
                .eqIfPresent(MesProBagCodeDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MesProBagCodeDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(MesProBagCodeDO::getBagNo));
    }
 
    /**
     * 批量绑定托盘
     *
     * @param ids        袋码编号列表
     * @param palletId   托盘编号
     * @param palletCode 托盘码
     */
    default void bindPalletByIds(Collection<Long> ids, Long palletId, String palletCode) {
        update(null, new LambdaUpdateWrapper<MesProBagCodeDO>()
                .set(MesProBagCodeDO::getPalletId, palletId)
                .set(MesProBagCodeDO::getPalletCode, palletCode)
                .in(MesProBagCodeDO::getId, ids));
    }
 
    /**
     * 批量解绑托盘(置空托盘编号与托盘码)
     *
     * @param ids 袋码编号列表
     */
    default void unbindPalletByIds(Collection<Long> ids) {
        update(null, new LambdaUpdateWrapper<MesProBagCodeDO>()
                .set(MesProBagCodeDO::getPalletId, null)
                .set(MesProBagCodeDO::getPalletCode, null)
                .in(MesProBagCodeDO::getId, ids));
    }
 
    /**
     * 查询批次内袋码最大序号(包含已逻辑删除记录,保证序号不回退、码值唯一)
     *
     * @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);
 
    default List<MesProBagCodeDO> selectListByIdsForUpdate(Collection<Long> ids) {
        return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>()
                .in(MesProBagCodeDO::getId, ids)
                .orderByAsc(MesProBagCodeDO::getId)
                .last("FOR UPDATE"));
    }
 
    @Update("<script>UPDATE mes_pro_bag_code SET status = #{toStatus}, cancel_time = #{cancelTime}, " +
            "cancel_reason = #{cancelReason}, pallet_id = NULL, pallet_code = NULL, update_time = NOW() " +
            "WHERE deleted = 0 AND id = #{id} AND status = #{fromStatus}</script>")
    int cancelById(@Param("id") Long id, @Param("fromStatus") Integer fromStatus,
                   @Param("toStatus") Integer toStatus, @Param("cancelTime") LocalDateTime cancelTime,
                   @Param("cancelReason") String cancelReason);
 
    @Select("SELECT COUNT(*) FROM mes_pro_bag_code WHERE batch_id = #{batchId} " +
            "AND deleted = 0 AND status <> 30")
    int selectEffectiveCountByBatchId(@Param("batchId") Long batchId);
 
    /**
     * 批量标记为已导出印刷(仅更新处于目标原状态的记录)
     *
     * @param ids        袋码编号列表
     * @param fromStatus 原状态
     * @param toStatus   目标状态
     * @param printTime  导出时间
     * @return 更新行数
     */
    @Update("<script>UPDATE mes_pro_bag_code SET status = #{toStatus}, print_time = #{printTime}, update_time = NOW() " +
            "WHERE deleted = 0 AND status = #{fromStatus} AND id IN " +
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>#{id}</foreach></script>")
    int updateStatusByIds(@Param("ids") Collection<Long> ids, @Param("fromStatus") Integer fromStatus,
                          @Param("toStatus") Integer toStatus, @Param("printTime") LocalDateTime printTime);
 
}