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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package com.qianwen.smartman.modules.cps.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.lang.invoke.SerializedLambda;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.secure.utils.AuthUtil;
import com.qianwen.core.tool.utils.CollectionUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.convert.BomVersionConvert;
import com.qianwen.smartman.modules.cps.entity.BomVersion;
import com.qianwen.smartman.modules.cps.enums.BomVersionStatusEnum;
import com.qianwen.smartman.modules.cps.mapper.BomVersionMapper;
import com.qianwen.smartman.modules.cps.service.IBomMaterialService;
import com.qianwen.smartman.modules.cps.service.IBomVersionService;
import com.qianwen.smartman.modules.cps.vo.BomMaterialVO;
import com.qianwen.smartman.modules.cps.vo.BomVersionDetailVO;
import com.qianwen.smartman.modules.cps.vo.BomVersionUpdateVO;
import com.qianwen.smartman.modules.cps.vo.BomVersionVO;
import com.qianwen.smartman.modules.system.service.IBasCoderuleService;
import com.qianwen.smartman.modules.system.service.ICodeGeneratorService;
import com.qianwen.smartman.modules.tpm.enums.MetaTypeEnum;
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/BomVersionServiceImpl.class */
public class BomVersionServiceImpl extends BaseServiceImpl<BomVersionMapper, BomVersion> implements IBomVersionService {
    private static final Logger log = LoggerFactory.getLogger(BomVersionServiceImpl.class);
    private final IBasCoderuleService basCoderuleService;
    private final ICodeGeneratorService codeGeneratorService;
    private final IBomMaterialService bomMaterialService;
 
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case -1061435468:
                if (implMethodName.equals("getProductId")) {
                    z = true;
                    break;
                }
                break;
            case -343633100:
                if (implMethodName.equals("getVersionStatus")) {
                    z = false;
                    break;
                }
                break;
            case 98245393:
                if (implMethodName.equals("getId")) {
                    z = true;
                    break;
                }
                break;
            case 771206363:
                if (implMethodName.equals("getTenantId")) {
                    z = true;
                    break;
                }
                break;
            case 1388468386:
                if (implMethodName.equals("getVersion")) {
                    z = true;
                    break;
                }
                break;
        }
        switch (z) {
            case false:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/BomVersion") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getVersionStatus();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/BomVersion") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getVersionStatus();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/BomVersion") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getVersion();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getId();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getId();
                    };
                }
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getId();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/BomVersion") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getTenantId();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/cps/entity/BomVersion") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getProductId();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
 
    public BomVersionServiceImpl(final IBasCoderuleService basCoderuleService, final ICodeGeneratorService codeGeneratorService, final IBomMaterialService bomMaterialService) {
        this.basCoderuleService = basCoderuleService;
        this.codeGeneratorService = codeGeneratorService;
        this.bomMaterialService = bomMaterialService;
    }
 
    @Override // org.springblade.modules.cps.service.IBomVersionService
    @Transactional(rollbackFor = {Exception.class})
    public BomVersion insert(BomVersionVO bomVersionVO) {
        BomVersion bomVersion = BomVersionConvert.INSTANCE.convert(bomVersionVO);
        if (Func.isBlank(bomVersionVO.getVersion())) {
            String version = this.codeGeneratorService.getGeneratorCode(bomVersion, MetaTypeEnum.BOM_VERSION.getCode());
            log.info("Bom版本编码规则生成的version:{}", version + " ," + version.length());
            bomVersion.setVersion(version);
        }
        if (checkNameIsExist(bomVersion.getVersion(), null, bomVersion.getProductId())) {
            throw new ServiceException(MessageUtils.message("cps.production.bom.version.is.exist", new Object[0]));
        }
        save(bomVersion);
        return bomVersion;
    }
 
    @Override // org.springblade.modules.cps.service.IBomVersionService
    public BomVersionVO update(BomVersionUpdateVO bomVersionUpdateVO) {
        BomVersion bomVersion = (BomVersion) getById(bomVersionUpdateVO.getId());
        if (BomVersionStatusEnum.FINALIZED.getStatus().equals(bomVersion.getVersionStatus())) {
            throw new ServiceException(MessageUtils.message("cps.production.bom.version.has.been.finalized.can.not.edit", new Object[0]));
        }
        if (!bomVersion.getVersion().equals(bomVersionUpdateVO.getVersion())) {
            boolean existCodeRule = this.basCoderuleService.isExistCodeRule(MetaTypeEnum.BOM_VERSION.getCode());
            if (existCodeRule) {
                throw new ServiceException(MessageUtils.message("cps.production.bom.version.coding.rule.exists.can.not.edit", new Object[0]));
            }
        }
        if (checkNameIsExist(bomVersionUpdateVO.getVersion(), bomVersionUpdateVO.getId(), bomVersion.getProductId())) {
            throw new ServiceException(MessageUtils.message("cps.production.bom.version.name.is.exist", new Object[0]));
        }
        bomVersion.setVersion(bomVersionUpdateVO.getVersion());
        bomVersion.setDescription(bomVersionUpdateVO.getDescription());
        updateById(bomVersion);
        return BomVersionConvert.INSTANCE.convert(bomVersion);
    }
 
    @Override // org.springblade.modules.cps.service.IBomVersionService
    public BomVersionDetailVO getVersionById(Long id) {
        return ((BomVersionMapper) this.baseMapper).getVersionById(id);
    }
 
    @Override // org.springblade.modules.cps.service.IBomVersionService
    @Transactional(rollbackFor = {Exception.class})
    public Boolean remove(Long id) {
        BomVersion bomVersion = (BomVersion) getById(id);
        if (BomVersionStatusEnum.FINALIZED.getStatus().equals(bomVersion.getVersionStatus())) {
            throw new ServiceException(MessageUtils.message("cps.production.bom.version.has.been.finalized.can.not.delete", new Object[0]));
        }
        removeById(id);
        this.bomMaterialService.deleteBomMaterial(id);
        return true;
    }
 
    @Override // org.springblade.modules.cps.service.IBomVersionService
    public Boolean fixVersion(Long id) {
        List<BomMaterialVO> bomMaterialVOList = this.bomMaterialService.getBomMaterialVOListByBomId(id);
        if (CollectionUtil.isEmpty(bomMaterialVOList)) {
            throw new ServiceException(MessageUtils.message("cps.production.bom.version.have.no.bom.material.can.not.fixed", new Object[0]));
        }
        return Boolean.valueOf(update((Wrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().set((v0) -> {
            return v0.getVersionStatus();
        }, BomVersionStatusEnum.FINALIZED.getStatus())).eq((v0) -> {
            return v0.getId();
        }, id)));
    }
 
    @Override // org.springblade.modules.cps.service.IBomVersionService
    public Boolean cancelFixVersion(Long id) {
        return Boolean.valueOf(update((Wrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().set((v0) -> {
            return v0.getVersionStatus();
        }, BomVersionStatusEnum.DEFAULT.getStatus())).eq((v0) -> {
            return v0.getId();
        }, id)));
    }
 
    private boolean checkNameIsExist(String version, Long id, Long productId) {
        List<BomVersion> bomVersionList = ((BomVersionMapper) this.baseMapper).selectList(Wrappers.query().lambda().eq(Func.isNotEmpty(AuthUtil.getTenantId()), (v0) -> {
            return v0.getTenantId();
        }, AuthUtil.getTenantId()).eq(Func.isNotBlank(version), (v0) -> {
            return v0.getVersion();
        }, version).eq(Func.isNotEmpty(productId), (v0) -> {
            return v0.getProductId();
        }, productId).notIn(Func.isNotEmpty(id), (v0) -> {
            return v0.getId();
        }, new Object[]{id}));
        return bomVersionList != null && bomVersionList.size() > 0;
    }
}