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
package cn.iocoder.yudao.module.mes.dal.mysql.safety;
 
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.safety.vo.material.SafetyMaterialPageReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.safety.SafetyMaterialDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
 
import java.time.LocalDate;
import java.util.List;
 
/**
 * 安全生产 - 物资台账 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface SafetyMaterialMapper extends BaseMapperX<SafetyMaterialDO> {
 
    default PageResult<SafetyMaterialDO> selectPage(SafetyMaterialPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SafetyMaterialDO>()
                .likeIfPresent(SafetyMaterialDO::getCode, reqVO.getCode())
                .likeIfPresent(SafetyMaterialDO::getName, reqVO.getName())
                .eqIfPresent(SafetyMaterialDO::getCategory, reqVO.getCategory())
                .eqIfPresent(SafetyMaterialDO::getStatus, reqVO.getStatus())
                .likeIfPresent(SafetyMaterialDO::getStorageLocation, reqVO.getStorageLocation())
                .orderByAsc(SafetyMaterialDO::getCategory)
                .orderByAsc(SafetyMaterialDO::getCode));
    }
 
    default SafetyMaterialDO selectByCode(String code) {
        return selectOne(SafetyMaterialDO::getCode, code);
    }
 
    /** 锁定库存行,避免并发出入库导致库存错乱 */
    @Select("SELECT * FROM safety_material WHERE id = #{id} AND deleted = b'0' FOR UPDATE")
    SafetyMaterialDO selectByIdForUpdate(@Param("id") Long id);
 
    /** 低于安全库存的物资 */
    default List<SafetyMaterialDO> selectBelowSafeStock() {
        return selectList(new LambdaQueryWrapperX<SafetyMaterialDO>()
                .apply("stock_qty < safe_stock")
                .orderByAsc(SafetyMaterialDO::getCode));
    }
 
    /** 有效期临近的物资 */
    default List<SafetyMaterialDO> selectExpiringBefore(LocalDate deadline) {
        return selectList(new LambdaQueryWrapperX<SafetyMaterialDO>()
                .isNotNull(SafetyMaterialDO::getExpireDate)
                .le(SafetyMaterialDO::getExpireDate, deadline)
                .orderByAsc(SafetyMaterialDO::getExpireDate));
    }
 
}