yangys
2024-03-27 e48aa2ac8dea1be5db11c63edf0b912c4ad5ce65
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
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.qianwen.smartman.modules.cps.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.lang.invoke.SerializedLambda;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.base.BaseServiceImpl;
import com.qianwen.core.tool.node.ForestNodeMerger;
import com.qianwen.core.tool.utils.CollectionUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.convert.BomMaterialConvert;
import com.qianwen.smartman.modules.cps.entity.BomMaterial;
import com.qianwen.smartman.modules.cps.entity.BomVersion;
import com.qianwen.smartman.modules.cps.enums.BomVersionStatusEnum;
import com.qianwen.smartman.modules.cps.mapper.BomMaterialMapper;
import com.qianwen.smartman.modules.cps.service.IBomMaterialService;
import com.qianwen.smartman.modules.cps.service.IBomProcessService;
import com.qianwen.smartman.modules.cps.service.IBomVersionService;
import com.qianwen.smartman.modules.cps.vo.BomMaterialDetailVO;
import com.qianwen.smartman.modules.cps.vo.BomMaterialVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/cps/service/impl/BomMaterialServiceImpl.class */
public class BomMaterialServiceImpl extends BaseServiceImpl<BomMaterialMapper, BomMaterial> implements IBomMaterialService {
    @Autowired
    private IBomProcessService bomProcessService;
    @Autowired
    @Lazy
    private IBomVersionService bomVersionService;
 
    @Override // org.springblade.modules.cps.service.IBomMaterialService
    @Transactional(rollbackFor = {Exception.class})
    public Boolean saveBomMaterial(Long bomId, String allPath, Long parentId, List<BomMaterialVO> bomMaterialVOList) {
        bomMaterialVOList.forEach(i -> {
            BomMaterial bomMaterial = new BomMaterial();
            bomMaterial.setId(Long.valueOf(IdWorker.getId()));
            bomMaterial.setVersionId(bomId);
            bomMaterial.setParentId(parentId == null ? Long.valueOf("0") : parentId);
            bomMaterial.setMaterialId(i.getMaterialId());
            bomMaterial.setAllPath(Func.isBlank(allPath) ? "/" + bomMaterial.getId() : allPath + "/" + bomMaterial.getId());
            save(bomMaterial);
        });
        return true;
    }
 
    @Override // org.springblade.modules.cps.service.IBomMaterialService
    @Transactional(rollbackFor = {Exception.class})
    public Boolean deleteBomMaterial(Long bomId) {
        List<BomMaterial> list = list(Wrappers.<BomMaterial>query().lambda()
                    .in(BomMaterial::getVersionId, new Object[] { bomId }));
        if (CollectionUtil.isEmpty(list))
          return true; 
        
        remove(Wrappers.<BomMaterial>update().lambda()
            .eq(BomMaterial::getVersionId, bomId));
        List<Long> bomMaterialIdList = (List<Long>)list.stream().map(BomMaterial::getId).distinct().collect(Collectors.toList());
        this.bomProcessService.deleteBomProcess(bomMaterialIdList);
        return true;
    }
 
    @Override // org.springblade.modules.cps.service.IBomMaterialService
    public List<BomMaterialVO> getBomMaterialVOListByBomId(Long bomId) {
        return BomMaterialConvert.INSTANCE.convert(list(Wrappers.<BomMaterial>query().lambda()
                  .in(BomMaterial::getVersionId, new Object[] { bomId })));
    }
 
    @Override // org.springblade.modules.cps.service.IBomMaterialService
    public BomMaterialDetailVO detail(Long id) {
        return ((BomMaterialMapper) this.baseMapper).detail(id);
    }
 
    @Override // org.springblade.modules.cps.service.IBomMaterialService
    public List<BomMaterialDetailVO> list(Map<String, Object> params) {
        return ((BomMaterialMapper) this.baseMapper).list(params);
    }
 
    @Override // org.springblade.modules.cps.service.IBomMaterialService
    public IPage<BomMaterialDetailVO> page(IPage<BomMaterialDetailVO> page, Map<String, Object> params) {
        return page.setRecords(((BomMaterialMapper) this.baseMapper).page(page, params));
    }
 
    @Override // org.springblade.modules.cps.service.IBomMaterialService
    public Boolean insert(BomMaterialVO bomMaterialVO) {
        if (Func.isEmpty(bomMaterialVO.getVersionId())) {
            throw new ServiceException(MessageUtils.message("cps.production.bom.version.id.is.empty", new Object[0]));
        }
        BomVersion bomVersion = (BomVersion) this.bomVersionService.getById(bomMaterialVO.getVersionId());
        if (BomVersionStatusEnum.FINALIZED.getStatus().equals(bomVersion.getVersionStatus())) {
            throw new ServiceException(MessageUtils.message("cps.production.bom.version.has.been.finalized.can.not.add.bom.material", new Object[0]));
        }
        List<BomMaterial> list = list(Wrappers.<BomMaterial>query().lambda()
                .eq(BomMaterial::getVersionId, bomMaterialVO.getVersionId())
                .eq(BomMaterial::getMaterialId, bomMaterialVO.getMaterialId()));
        /*
        List<BomMaterial> list = list((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
            return v0.getVersionId();
        }, bomMaterialVO.getVersionId())).eq((v0) -> {
            return v0.getMaterialId();
        }, bomMaterialVO.getMaterialId()));
        */
        if (CollectionUtil.isNotEmpty(list)) {
            throw new ServiceException(MessageUtils.message("cps.production.bom.version.has.same.bom.material", new Object[0]));
        }
        String allPath = "";
        if (Func.isNotEmpty(bomMaterialVO.getParentId()) && bomMaterialVO.getParentId().compareTo((Long) 0L) > 0) {
            allPath = (String) Optional.ofNullable(((BomMaterial) getById(bomMaterialVO.getParentId())).getAllPath()).orElse(null);
        }
        saveBomMaterial(bomMaterialVO.getVersionId(), allPath, bomMaterialVO.getParentId(), Arrays.asList(bomMaterialVO));
        return true;
    }
 
    @Override // org.springblade.modules.cps.service.IBomMaterialService
    @Transactional(rollbackFor = {Exception.class})
    public Boolean removeBomMaterial(Long id) {
        BomMaterial bomMaterial = (BomMaterial) getById(id);
        BomVersion bomVersion = (BomVersion) this.bomVersionService.getById(bomMaterial.getVersionId());
        if (BomVersionStatusEnum.FINALIZED.getStatus().equals(bomVersion.getVersionStatus())) {
            throw new ServiceException(MessageUtils.message("cps.production.bom.version.has.been.finalized.can.not.delete.bom.material", new Object[0]));
        }
        List<BomMaterial> list = list(Wrappers.<BomMaterial>query().lambda()
                .eq(BomMaterial::getParentId, bomMaterial.getId()));
        if (CollectionUtil.isNotEmpty(list)) {
            throw new ServiceException(MessageUtils.message("cps.production.bom.material.has.children.can.not.delete", new Object[0]));
        }
        removeById(id);
        this.bomProcessService.deleteBomProcess(Arrays.asList(id));
        return true;
    }
 
    @Override // org.springblade.modules.cps.service.IBomMaterialService
    public List<BomMaterialDetailVO> tree(Map<String, Object> params) {
        return ForestNodeMerger.merge(((BomMaterialMapper) this.baseMapper).list(params));
    }
}