liyong
6 天以前 274dd8b724dd4485658e1d2a3f825a007f625bd7
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
package cn.iocoder.yudao.module.mes.service.mdm;
 
import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.mdm.MesMdmItemDO;
import cn.iocoder.yudao.module.mes.dal.mysql.mdm.MesMdmItemMapper;
import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
 
import java.util.Collection;
import java.util.Collections;
import java.util.List;
 
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.MD_ITEM_NOT_EXISTS;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.MD_ITEM_IS_DISABLE;
 
/**
 * MDM 物料 Service 实现类
 *
 * 专门用于查询 mdm_item 表
 */
@Service
@Validated
public class MesMdmItemServiceImpl implements MesMdmItemService {
 
    @Resource
    private MesMdmItemMapper mesMdmItemMapper;
    @Autowired
    private MesMdItemService mesMdItemService;
 
    @Override
    public MesMdmItemDO getItem(Long id) {
        return mesMdmItemMapper.selectById(id);
    }
 
    @Override
    public MesMdmItemDO validateItemExists(Long id) {
        MesMdmItemDO item = mesMdmItemMapper.selectById(id);
        if (item == null) {
            throw exception(MD_ITEM_NOT_EXISTS);
        }
        return item;
    }
 
    @Override
    public MesMdmItemDO mesValidateItemExists(Long itemId) {
        MesMdItemDO mesItem = mesMdItemService.getItem(itemId);
        if (mesItem == null) {
            throw exception(MD_ITEM_NOT_EXISTS);
        }
        MesMdmItemDO item = mesMdmItemMapper.selectById(mesItem.getMdmItemId());
        if (item == null) {
            throw exception(MD_ITEM_NOT_EXISTS);
        }
        return item;
    }
 
    @Override
    public MesMdmItemDO validateItemExistsAndEnable(Long id) {
        MesMdmItemDO item = validateItemExists(id);
        if (item.getStatus() != null && item.getStatus() == 1) {
            throw exception(MD_ITEM_IS_DISABLE);
        }
        return item;
    }
 
    @Override
    public List<MesMdmItemDO> getItemList(Collection<Long> ids) {
        if (ids == null || ids.isEmpty()) {
            return Collections.emptyList();
        }
        return mesMdmItemMapper.selectListByIds(ids);
    }
 
}