云
20 小时以前 704265308b1227dbada5a36b2027b588c062ded2
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
package cn.iocoder.yudao.module.mes.dal.mysql.pro.batch;
 
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.batch.vo.MesProBatchPageReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.batch.MesProBatchDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
 
/**
 * MES 生产批次 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface MesProBatchMapper extends BaseMapperX<MesProBatchDO> {
 
    default MesProBatchDO selectByCode(String code) {
        return selectOne(MesProBatchDO::getCode, code);
    }
 
    default MesProBatchDO selectByScanCode(String code) {
        return selectOne(new LambdaQueryWrapperX<MesProBatchDO>().and(q ->
                q.eq(MesProBatchDO::getBusinessCode, code).or().eq(MesProBatchDO::getCode, code)
                        .or().eq(MesProBatchDO::getTempCode, code)));
    }
 
    default MesProBatchDO selectByScanCodeForUpdate(String code) {
        return selectOne(new LambdaQueryWrapperX<MesProBatchDO>().and(q ->
                q.eq(MesProBatchDO::getBusinessCode, code).or().eq(MesProBatchDO::getCode, code)
                        .or().eq(MesProBatchDO::getTempCode, code)).last("FOR UPDATE"));
    }
 
    default MesProBatchDO selectByTempCode(String tempCode) {
        return selectOne(MesProBatchDO::getTempCode, tempCode);
    }
 
    default Long selectCountByLineId(Long lineId) {
        return selectCount(MesProBatchDO::getLineId, lineId);
    }
 
    @Select("SELECT * FROM mes_pro_batch WHERE id = #{id} AND deleted = 0 FOR UPDATE")
    MesProBatchDO selectByIdForUpdate(@org.apache.ibatis.annotations.Param("id") Long id);
 
    @org.apache.ibatis.annotations.Update("UPDATE mes_pro_batch SET inbound_time = NOW(), inbound_event_id = #{eventId}, inbound_device_code = #{deviceCode}, inbound_line_code = #{lineCode}, inbound_bag_quantity = COALESCE(inbound_bag_quantity, 0) + 1, update_time = NOW() WHERE id = #{id} AND deleted = 0")
    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);
 
    /** 批次整批扫码入库回写:入库袋数直接置为批次袋数,幂等(已有入库标记的不再更新) */
    @org.apache.ibatis.annotations.Update("UPDATE mes_pro_batch SET inbound_time = NOW(), inbound_event_id = #{eventId}, inbound_line_code = #{lineCode}, inbound_bag_quantity = #{bagQuantity}, update_time = NOW() "
            + "WHERE id = #{id} AND deleted = 0 AND inbound_event_id IS NULL")
    int markBatchInbound(@org.apache.ibatis.annotations.Param("id") Long id, @org.apache.ibatis.annotations.Param("eventId") Long eventId,
                         @org.apache.ibatis.annotations.Param("lineCode") String lineCode, @org.apache.ibatis.annotations.Param("bagQuantity") Integer bagQuantity);
 
    /** 以有效袋码的入库标记为准;混扫、重试和作废袋不影响完成判断。调用方已锁定批次。 */
    @org.apache.ibatis.annotations.Update("UPDATE mes_pro_batch SET inbound_time = NOW(), inbound_event_id = #{eventId}, "
            + "inbound_device_code = #{deviceCode}, inbound_line_code = #{lineCode}, "
            + "inbound_bag_quantity = (SELECT COUNT(*) FROM mes_pro_bag_code b WHERE b.batch_id = #{id} "
            + "AND b.deleted = 0 AND b.status <> 30 AND b.inbound_event_id IS NOT NULL), "
            + "status = CASE WHEN EXISTS (SELECT 1 FROM mes_pro_bag_code b WHERE b.batch_id = #{id} AND b.deleted = 0 AND b.status <> 30) "
            + "AND NOT EXISTS (SELECT 1 FROM mes_pro_bag_code b WHERE b.batch_id = #{id} AND b.deleted = 0 AND b.status <> 30 AND b.inbound_event_id IS NULL) "
            + "THEN 30 ELSE status END, update_time = NOW() WHERE id = #{id} AND deleted = 0 AND status <> 40")
    int refreshInboundProgress(@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);
 
    default PageResult<MesProBatchDO> selectPage(MesProBatchPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MesProBatchDO>()
                .likeIfPresent(MesProBatchDO::getBusinessCode, reqVO.getBusinessCode())
                .likeIfPresent(MesProBatchDO::getTempCode, reqVO.getTempCode())
                .eqIfPresent(MesProBatchDO::getLineId, reqVO.getLineId())
                .likeIfPresent(MesProBatchDO::getLineCode, reqVO.getLineCode())
                .likeIfPresent(MesProBatchDO::getLineName, reqVO.getLineName())
                .likeIfPresent(MesProBatchDO::getProcessingTeam, reqVO.getProcessingTeam())
                .eqIfPresent(MesProBatchDO::getOwnerUserId, reqVO.getOwnerUserId())
                .eqIfPresent(MesProBatchDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MesProBatchDO::getProduceDate, reqVO.getProduceDate())
                .betweenIfPresent(MesProBatchDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MesProBatchDO::getId)
                .and(cn.hutool.core.util.StrUtil.isNotBlank(reqVO.getCode()), q ->
                        q.like(MesProBatchDO::getCode, reqVO.getCode()).or()
                                .like(MesProBatchDO::getBusinessCode, reqVO.getCode()).or()
                                .like(MesProBatchDO::getTempCode, reqVO.getCode())));
    }
 
}