yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
package com.qianwen.smartman.modules.andon.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.google.common.collect.Lists;
import java.lang.invoke.SerializedLambda;
import java.util.List;
import java.util.stream.Collectors;
import com.qianwen.smartman.common.cache.RegionCache;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.service.impl.BladeServiceImpl;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.andon.convert.AndonTypeConvert;
import com.qianwen.smartman.modules.andon.entity.AndonRecord;
import com.qianwen.smartman.modules.andon.entity.AndonType;
import com.qianwen.smartman.modules.andon.entity.DeviceAndonType;
import com.qianwen.smartman.modules.andon.enums.AndonStatusEnum;
import com.qianwen.smartman.modules.andon.mapper.AndonTypeMapper;
import com.qianwen.smartman.modules.andon.service.IAndonRecordService;
import com.qianwen.smartman.modules.andon.service.IAndonTypeService;
import com.qianwen.smartman.modules.andon.service.IDeviceAndonTypeService;
import com.qianwen.smartman.modules.andon.vo.AndonTypeDetailVO;
import com.qianwen.smartman.modules.andon.vo.AndonTypeSaveVO;
import com.qianwen.smartman.modules.andon.vo.AndonTypeUpdateVO;
import com.qianwen.smartman.modules.andon.vo.AndonTypeVO;
import com.qianwen.smartman.modules.andon.vo.BindingDeviceTypeVO;
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/andon/service/impl/AndonTypeServiceImpl.class */
public class AndonTypeServiceImpl extends BladeServiceImpl<AndonTypeMapper, AndonType> implements IAndonTypeService {
    private final ICodeGeneratorService codeGeneratorService;
    private final IDeviceAndonTypeService deviceAndonTypeService;
    private final IAndonRecordService recordService;
 
    public AndonTypeServiceImpl(final ICodeGeneratorService codeGeneratorService, final IDeviceAndonTypeService deviceAndonTypeService, final IAndonRecordService recordService) {
        this.codeGeneratorService = codeGeneratorService;
        this.deviceAndonTypeService = deviceAndonTypeService;
        this.recordService = recordService;
    }
 
    @Override // org.springblade.modules.andon.service.IAndonTypeService
    @Transactional(rollbackFor = {Exception.class})
    public AndonTypeVO saveAndonType(AndonTypeSaveVO vo) {
        andonTypeCodeGenerator(vo);
        checkDuplicateCode(vo.getCode());
        AndonType type = new AndonType().setCode(vo.getCode()).setName(vo.getName()).setRemark(vo.getRemark());
        save(type);
        saveDeviceTypeBinding(type.getId(), vo.getDeviceTypeIds());
        return AndonTypeConvert.INSTANCE.convert(type);
    }
 
    @Override // org.springblade.modules.andon.service.IAndonTypeService
    @Transactional(rollbackFor = {Exception.class})
    public Boolean updateAndonType(AndonTypeUpdateVO vo) {
        Long typeId = vo.getId();
        notUpdate(typeId);
        boolean update = Lambda.updateWrapper(this.baseMapper).set(AndonType::getName, vo.getName()).set(AndonType::getRemark, vo.getRemark()).eq(AndonType::getId, typeId).update();
        List<AndonRecord> list = this.recordService.list(Lambda.eq(AndonRecord::getTypeId, typeId)
            .in(AndonRecord::getCurStatus, Lists.newArrayList(new Integer[] { AndonStatusEnum.ALREADY_RECEIVED.getStatus(), AndonStatusEnum.HAVA_INITIATED.getStatus() })));
        List<Long> deviceTypeIds = vo.getDeviceTypeIds();
        if (Func.isNotEmpty(list)) {
          List<DeviceAndonType> typeList = this.deviceAndonTypeService.list(Lambda.eq(DeviceAndonType::getAndonTypeId, typeId));
          List<Long> collect = (List<Long>)typeList.stream().map(DeviceAndonType::getDeviceTypeId).collect(Collectors.toList());
          boolean sameList = sameList(collect, deviceTypeIds);
          if (sameList)
            throw new ServiceException(MessageUtils.message("andon.type.device.type.update", new Object[0])); 
        } 
        update = (this.deviceAndonTypeService.remove(Lambda.eq(DeviceAndonType::getAndonTypeId, typeId)) && update);
        saveDeviceTypeBinding(typeId, deviceTypeIds);
        return Boolean.valueOf(update);
        
        /*
        Long typeId = vo.getId();
        notUpdate(typeId);
        boolean update = ((LambdaUpdateChainWrapper) ((LambdaUpdateChainWrapper) ((LambdaUpdateChainWrapper) Lambda.updateWrapper(this.baseMapper).set((v0) -> {
            return v0.getName();
        }, vo.getName())).set((v0) -> {
            return v0.getRemark();
        }, vo.getRemark())).eq((v0) -> {
            return v0.getId();
        }, typeId)).update();
        List<AndonRecord> list = this.recordService.list((Wrapper) Lambda.eq((v0) -> {
            return v0.getTypeId();
        }, typeId).in((v0) -> {
            return v0.getCurStatus();
        }, Lists.newArrayList(new Integer[]{AndonStatusEnum.ALREADY_RECEIVED.getStatus(), AndonStatusEnum.HAVA_INITIATED.getStatus()})));
        List<Long> deviceTypeIds = vo.getDeviceTypeIds();
        if (Func.isNotEmpty(list)) {
            List<DeviceAndonType> typeList = this.deviceAndonTypeService.list(Lambda.eq((v0) -> {
                return v0.getAndonTypeId();
            }, typeId));
            List<Long> collect = (List) typeList.stream().map((v0) -> {
                return v0.getDeviceTypeId();
            }).collect(Collectors.toList());
            boolean sameList = sameList(collect, deviceTypeIds);
            if (sameList) {
                throw new ServiceException(MessageUtils.message("andon.type.device.type.update", new Object[0]));
            }
        }
        boolean update2 = this.deviceAndonTypeService.remove(Lambda.eq((v0) -> {
            return v0.getAndonTypeId();
        }, typeId)) && update;
        saveDeviceTypeBinding(typeId, deviceTypeIds);
        return Boolean.valueOf(update2);
        */
    }
 
    @Override // org.springblade.modules.andon.service.IAndonTypeService
    public Boolean removeAndonType(Long typeId) {
        notRemove(typeId);
        return Boolean.valueOf(removeById(typeId));
    }
 
    @Override // org.springblade.modules.andon.service.IAndonTypeService
    public List<AndonTypeVO> andonTypeList(String keyword) {
        return this.baseMapper.andonTypeList(keyword);
    }
 
    @Override // org.springblade.modules.andon.service.IAndonTypeService
    public AndonTypeDetailVO detail(Long typeId) {
        return this.baseMapper.detail(typeId);
    }
 
    @Override // org.springblade.modules.andon.service.IAndonTypeService
    public List<BindingDeviceTypeVO> allDeviceTypes(String typeId) {
        return this.baseMapper.allDeviceTypes(typeId);
    }
 
    @Override // org.springblade.modules.andon.service.IAndonTypeService
    public List<AndonTypeVO> workBanding(Long workstationId) {
        return this.baseMapper.workBanding(workstationId);
    }
 
    private boolean sameList(List<Long> l1, List<Long> l2) {
        if (l1.size() != l2.size()) {
            return true;
        }
        String c1 = (String) l1.stream().sorted((v0, v1) -> {
            return v0.compareTo(v1);
        }).map((v0) -> {
            return String.valueOf(v0);
        }).collect(Collectors.joining(","));
        String c2 = (String) l2.stream().sorted((v0, v1) -> {
            return v0.compareTo(v1);
        }).map((v0) -> {
            return String.valueOf(v0);
        }).collect(Collectors.joining(","));
        return !c1.equals(c2);
    }
 
    private void notRemove(Long typeId) {
        List<AndonRecord> list = this.recordService.list(Lambda.eq((v0) -> {
            return v0.getTypeId();
        }, typeId));
        if (Func.isNotEmpty(list)) {
            throw new ServiceException(MessageUtils.message("andon.type.has.record", new Object[0]));
        }
    }
 
    private void notUpdate(Long typeId) {
        List<AndonRecord> list = this.recordService.list(Lambda.eq(AndonRecord::getTypeId, typeId).in(AndonRecord::getCurStatus, 
                  Lists.newArrayList(AndonStatusEnum.ALREADY_RECEIVED.getStatus(), AndonStatusEnum.HAVA_INITIATED.getStatus())));
            if (Func.isNotEmpty(list))
              throw new ServiceException(MessageUtils.message("andon.type.not.update", new Object[0])); 
        /*
        List<AndonRecord> list = this.recordService.list((Wrapper) Lambda.eq((v0) -> {
            return v0.getTypeId();
        }, typeId).in((v0) -> {
            return v0.getCurStatus();
        }, Lists.newArrayList(new Integer[]{AndonStatusEnum.ALREADY_RECEIVED.getStatus(), AndonStatusEnum.HAVA_INITIATED.getStatus()})));
        if (Func.isNotEmpty(list)) {
            throw new ServiceException(MessageUtils.message("andon.type.not.update", new Object[0]));
        }
        */
    }
 
    private void saveDeviceTypeBinding(Long andonTypeId, List<Long> deviceTypeIds) {
        List<DeviceAndonType> types = deviceTypeIds.stream().map(dt -> {
            return new DeviceAndonType().setAndonTypeId(andonTypeId).setDeviceTypeId(dt);
        }).collect(Collectors.toList());
        this.deviceAndonTypeService.saveBatch(types);
    }
 
    private void andonTypeCodeGenerator(AndonTypeSaveVO vo) {
        if (Func.isBlank(vo.getCode())) {
            String code = this.codeGeneratorService.getGeneratorCode(vo, MetaTypeEnum.ANDON_TYPE.getCode());
            if (Func.isBlank(code)) {
                throw new ServiceException(MessageUtils.message("cps.tpm.maintain.coding.rules", new Object[0]));
            }
            vo.setCode(code);
        }
    }
 
    private void checkDuplicateCode(String code) {
        List<AndonType> list = list(Lambda.eq(AndonType::getCode, code));
        
        if (Func.isNotEmpty(list)) {
            throw new ServiceException(MessageUtils.message("andon.type.code.dub", new Object[0]));
        }
    }
}