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
package cn.iocoder.yudao.module.mdm.service.item;
 
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.mdm.dal.dataobject.item.MdmItemBatchConfigDO;
import cn.iocoder.yudao.module.mdm.dal.mysql.item.MdmItemBatchConfigMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
 
import java.util.List;
 
/**
 * MDM 物料批次配置 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class MdmItemBatchConfigServiceImpl implements MdmItemBatchConfigService {
 
    @Resource
    private MdmItemBatchConfigMapper itemBatchConfigMapper;
 
    @Override
    public MdmItemBatchConfigDO getItemBatchConfigByItemId(Long itemId) {
        List<MdmItemBatchConfigDO> list = itemBatchConfigMapper.selectList(MdmItemBatchConfigDO::getItemId, itemId);
        return CollUtil.getFirst(list);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long saveItemBatchConfig(MdmItemBatchConfigDO config) {
        // 清空不需要的字段(只保留必要的7个字段)
        config.setClientFlag(false);
        config.setSalesOrderCodeFlag(false);
        config.setWorkOrderFlag(false);
        config.setTaskFlag(false);
        config.setWorkstationFlag(false);
        config.setToolFlag(false);
        config.setMoldFlag(false);
 
        // 查询已有配置
        MdmItemBatchConfigDO existing = getItemBatchConfigByItemId(config.getItemId());
        if (existing != null) {
            // 更新
            config.setId(existing.getId());
            itemBatchConfigMapper.updateById(config);
            return existing.getId();
        }
        // 新增
        itemBatchConfigMapper.insert(config);
        return config.getId();
    }
 
    @Override
    public void deleteItemBatchConfigByItemId(Long itemId) {
        itemBatchConfigMapper.delete(MdmItemBatchConfigDO::getItemId, itemId);
    }
 
}