-
admin
2024-05-09 06713afdb80bc876ffc6a09442049a08eb8a2364
提交 | 用户 | 时间
e57a89 1 package com.jcdm.main.bs.formulaChild.service.impl;
2
5316c5 3 import java.util.ArrayList;
b64ed2 4 import java.util.Date;
e57a89 5 import java.util.List;
3c2299 6 import java.util.Map;
7bee80 7 import java.util.stream.Collectors;
e57a89 8
7bee80 9 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
10 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
0ce25f 11 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
e57a89 12 import com.jcdm.common.core.domain.AjaxResult;
13 import com.jcdm.common.utils.DateUtils;
3c2299 14 import com.jcdm.framework.websocket.WebSocketUsers;
b64ed2 15 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
16 import com.jcdm.main.da.paramCollection.mapper.DaParamCollectionMapper;
32483a 17 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
18 import com.jcdm.main.da.passingStationCollection.mapper.DaPassingStationCollectionMapper;
3c2299 19 import com.kangaroohy.milo.model.ReadWriteEntity;
20 import com.kangaroohy.milo.service.MiloService;
b77303 21 import org.aspectj.weaver.loadtime.Aj;
e57a89 22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.stereotype.Service;
24 import com.jcdm.main.bs.formulaChild.mapper.BsFormulaChildInfoMapper;
25 import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo;
26 import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService;
3c2299 27
28 import javax.websocket.Session;
e57a89 29
30 /**
31  * 配方配置子信息Service业务层处理
32  * 
33  * @author ruimin
34  * @date 2023-12-26
35  */
36 @Service
0ce25f 37 public class BsFormulaChildInfoServiceImpl extends ServiceImpl<BsFormulaChildInfoMapper,BsFormulaChildInfo> implements IBsFormulaChildInfoService
e57a89 38 {
39     @Autowired
40     private BsFormulaChildInfoMapper bsFormulaChildInfoMapper;
b64ed2 41
42     @Autowired
63b254 43     private IBsFormulaChildInfoService bsFormulaChildInfoService;
44
45     @Autowired
b64ed2 46     private DaParamCollectionMapper daParamCollectionMapper;
3c2299 47
48     @Autowired
49     private MiloService miloService;
32483a 50
51     @Autowired
52     private DaPassingStationCollectionMapper daPassingStationCollectionMapper;
3c2299 53
54     Map<String, Session> map = WebSocketUsers.getUsers();
e57a89 55
56     /**
57      * 查询配方配置子信息
58      * 
59      * @param id 配方配置子信息主键
60      * @return 配方配置子信息
61      */
62     @Override
63     public BsFormulaChildInfo selectBsFormulaChildInfoById(Long id)
64     {
65         return bsFormulaChildInfoMapper.selectBsFormulaChildInfoById(id);
66     }
67
68     /**
69      * 查询配方配置子信息列表
70      * 
71      * @param bsFormulaChildInfo 配方配置子信息
72      * @return 配方配置子信息
73      */
74     @Override
75     public List<BsFormulaChildInfo> selectBsFormulaChildInfoList(BsFormulaChildInfo bsFormulaChildInfo)
76     {
77         return bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(bsFormulaChildInfo);
78     }
79
80     /**
81      * 新增配方配置子信息
82      * 
83      * @param bsFormulaChildInfo 配方配置子信息
84      * @return 结果
85      */
86     @Override
87     public int insertBsFormulaChildInfo(BsFormulaChildInfo bsFormulaChildInfo)
88     {
89         bsFormulaChildInfo.setCreateTime(DateUtils.getNowDate());
90         return bsFormulaChildInfoMapper.insertBsFormulaChildInfo(bsFormulaChildInfo);
91     }
92
93     /**
94      * 修改配方配置子信息
95      * 
96      * @param bsFormulaChildInfo 配方配置子信息
97      * @return 结果
98      */
99     @Override
100     public int updateBsFormulaChildInfo(BsFormulaChildInfo bsFormulaChildInfo)
101     {
102         bsFormulaChildInfo.setUpdateTime(DateUtils.getNowDate());
103         return bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfo);
104     }
105
106     /**
107      * 批量删除配方配置子信息
108      * 
109      * @param ids 需要删除的配方配置子信息主键
110      * @return 结果
111      */
112     @Override
113     public int deleteBsFormulaChildInfoByIds(Long[] ids)
114     {
115         return bsFormulaChildInfoMapper.deleteBsFormulaChildInfoByIds(ids);
116     }
117
118     /**
119      * 删除配方配置子信息信息
120      * 
121      * @param id 配方配置子信息主键
122      * @return 结果
123      */
124     @Override
125     public int deleteBsFormulaChildInfoById(Long id)
126     {
127         return bsFormulaChildInfoMapper.deleteBsFormulaChildInfoById(id);
128     }
129
130     @Override
131     public BsFormulaChildInfo selectBsFormulaChildInfoByTypeTopOne(String type,String productCode,String processesCode) {
132         BsFormulaChildInfo info = new BsFormulaChildInfo();
133         info.setOperationType(type);
134         info.setProcessesCode(processesCode);
135         info.setProductCode(productCode);
136         return bsFormulaChildInfoMapper.selectBsFormulaChildInfoByTypeTopOne(info);
137     }
138
139     @Override
b77303 140     public BsFormulaChildInfo getCount(String productCode, String processesCode) {
141         BsFormulaChildInfo info = new BsFormulaChildInfo();
142         info.setProcessesCode(processesCode);
143         info.setProductCode(productCode);
144         return bsFormulaChildInfoMapper.getCount(info);
145     }
146
147     @Override
2c7661 148     public AjaxResult yzUpdateResults(BsFormulaChildInfo bsFormulaChildInfo) {
A 149         String result = "";
150         List<BsFormulaChildInfo> bsFormulaChildInfos = new ArrayList<>();
151         List<BsFormulaChildInfo> infos = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
152                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
153                 .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode())
154                 .eq(BsFormulaChildInfo::getOperationType, "2")
155         );
156         for (BsFormulaChildInfo formulaChildInfo : infos) {
157             if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())){
158                 bsFormulaChildInfos.add(formulaChildInfo);
159                 break;
160             }
161         }
162         if(bsFormulaChildInfos.size()>0){
163             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
164             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getScanBarcode());
165             bsFormulaChildInfos.get(0).setResults("OK");
166             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
167             bsFormulaChildInfo.setParamValue(bsFormulaChildInfo.getScanBarcode());
168             bsFormulaChildInfo.setParamCode(bsFormulaChildInfos.get(0).getParamCode());
169             bsFormulaChildInfo.setSfcBarcode(bsFormulaChildInfo.getSfcBarcode());
170             addParameterCollection(bsFormulaChildInfo);
171             if (spareField4 != null && !spareField4.isEmpty()) {
172                 // 执行操作
173                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
174                     try {
175                         result = "3";
176                     } catch (Exception e) {
177                         throw new RuntimeException(e);
178                     }
179                 }
180             }
181         }else {
182             result = "1";
183         }
184         return AjaxResult.success(result);
185     }
186
187     @Override
188     public AjaxResult yzUpdateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo) {
189         String result = "1";
190         BsFormulaChildInfo getMaterTwo = new BsFormulaChildInfo();
191         getMaterTwo.setProcessesCode(bsFormulaChildInfo.getLocationCode());
192         getMaterTwo.setOperationType("2");
193         List<BsFormulaChildInfo> operationType = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(getMaterTwo);
194         List<String> collect = operationType.stream().map(BsFormulaChildInfo::getResults).collect(Collectors.toList());
195         for (String s : collect) {
196             if(s.equals("")){
197                 return AjaxResult.error("扫描未完成,禁止拧紧操作!");
198             }
199         }
200         BsFormulaChildInfo listQuery = new BsFormulaChildInfo();
201         listQuery.setParamCode(bsFormulaChildInfo.getParamCode());
202         String paramCode = bsFormulaChildInfo.getTightenTheArray();
203         if(paramCode.contains("N")){
204             List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
205             bsFormulaChildInfos.get(0).setResults("NG");
206             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
207             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
208             return AjaxResult.error("扫描结果NG,请重新扫描!");
209         }else {
210             List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
211             bsFormulaChildInfos.get(0).setResults("OK");
212             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
213             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
4a5f2a 214
A 215             Integer stepNumber = Integer.valueOf(bsFormulaChildInfos.get(0).getStepSort());
216             try {
217                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".StepNumber").value(stepNumber).build());
218             } catch (Exception e) {
219                 throw new RuntimeException(e);
220             }
221
2c7661 222             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
A 223             if (spareField4 != null && !spareField4.isEmpty()) {
224                 // 执行操作
225                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
226                     try {
227 //                        WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), "OUT");
228                         result = "2";
229                     } catch (Exception e) {
230                         throw new RuntimeException(e);
231                     }
232                 }
233             }
234
235         }
236         return AjaxResult.success(result);
237     }
238
239     @Override
06713a 240     public AjaxResult jrmUpdateResults(BsFormulaChildInfo bsFormulaChildInfo) {
A 241         String result = "";
242         List<BsFormulaChildInfo> bsFormulaChildInfos = new ArrayList<>();
243         List<BsFormulaChildInfo> infos = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
244                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
245                 .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode())
246                 .eq(BsFormulaChildInfo::getOperationType, "2")
247         );
248         for (BsFormulaChildInfo formulaChildInfo : infos) {
249             if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())){
250                 bsFormulaChildInfos.add(formulaChildInfo);
251                 break;
252             }
253         }
254         if(bsFormulaChildInfos.size()>0){
255             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
256             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getScanBarcode());
257             bsFormulaChildInfos.get(0).setResults("OK");
258             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
259             bsFormulaChildInfo.setParamValue(bsFormulaChildInfo.getScanBarcode());
260             bsFormulaChildInfo.setParamCode(bsFormulaChildInfos.get(0).getParamCode());
261             bsFormulaChildInfo.setSfcBarcode(bsFormulaChildInfo.getSfcBarcode());
262             jrmAddParameterCollection(bsFormulaChildInfo);
263
264             if (spareField4 != null && !spareField4.isEmpty()) {
265                 // 执行操作
266                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
267                     try {
268                         result = "3";
269                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".RecordDataDone").value(21).build());
270                     } catch (Exception e) {
271                         throw new RuntimeException(e);
272                     }
273                 }
274             }
275         }else {
276             result = "1";
277         }
278         return AjaxResult.success(result);
279     }
280
281     @Override
b77303 282     public BsFormulaChildInfo releaseCheck(BsFormulaChildInfo bsFormulaChildInfo) {
e57a89 283         return bsFormulaChildInfoMapper.releaseCheck(bsFormulaChildInfo);
284     }
285
c5e9c5 286     //1-非本工位物料 2-正常扫描可继续下次 3-扫描结束已经是最后一位工步
e57a89 287     @Override
288     public AjaxResult updateResults(BsFormulaChildInfo bsFormulaChildInfo) {
c5e9c5 289         String result = "";
5316c5 290         List<BsFormulaChildInfo> bsFormulaChildInfos = new ArrayList<>();
A 291         List<BsFormulaChildInfo> infos = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
e70fb4 292                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
A 293                 .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode())
5316c5 294                 .eq(BsFormulaChildInfo::getOperationType, "2")
e70fb4 295         );
5316c5 296         for (BsFormulaChildInfo formulaChildInfo : infos) {
A 297             if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())){
298                 bsFormulaChildInfos.add(formulaChildInfo);
299                 break;
300             }
301         }
e57a89 302         if(bsFormulaChildInfos.size()>0){
c5e9c5 303             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
3c2299 304             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getScanBarcode());
e57a89 305             bsFormulaChildInfos.get(0).setResults("OK");
306             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
49c784 307             bsFormulaChildInfo.setParamValue(bsFormulaChildInfo.getScanBarcode());
b64ed2 308             bsFormulaChildInfo.setParamCode(bsFormulaChildInfos.get(0).getParamCode());
49c784 309             bsFormulaChildInfo.setSfcBarcode(bsFormulaChildInfo.getSfcBarcode());
b64ed2 310             addParameterCollection(bsFormulaChildInfo);
4a5f2a 311
A 312 //            Integer stepNumber = Integer.valueOf(bsFormulaChildInfos.get(0).getStepSort());
313 //            try {
314 //                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".StepNumber").value(stepNumber).build());
315 //            } catch (Exception e) {
316 //                throw new RuntimeException(e);
317 //            }
318
c5e9c5 319             if (spareField4 != null && !spareField4.isEmpty()) {
320                 // 执行操作
321                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
322                     try {
323                         result = "3";
324                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".RecordDataDone").value(21).build());
325                     } catch (Exception e) {
326                         throw new RuntimeException(e);
327                     }
328                 }
329             }
e57a89 330         }else {
c5e9c5 331             result = "1";
e57a89 332         }
c5e9c5 333         return AjaxResult.success(result);
e57a89 334     }
335
b64ed2 336     public void addParameterCollection(BsFormulaChildInfo bsFormulaChildInfo){
337         DaParamCollection daParamCollection = new DaParamCollection();
338         daParamCollection.setParamCode(bsFormulaChildInfo.getParamCode());
339         daParamCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo());
340         daParamCollection.setLocationCode(bsFormulaChildInfo.getLocationCode());
341         daParamCollection.setParamValue(bsFormulaChildInfo.getParamValue());
342         daParamCollection.setProductCode(bsFormulaChildInfo.getProductCode());
343         daParamCollection.setCollectionTime(new Date());
49c784 344         daParamCollection.setSfcCode(bsFormulaChildInfo.getSfcBarcode());
b64ed2 345         daParamCollectionMapper.insertDaParamCollection(daParamCollection);
346     }
347
06713a 348     public void jrmAddParameterCollection(BsFormulaChildInfo bsFormulaChildInfo){
A 349         String scanBarCode = bsFormulaChildInfo.getSfcBarcode();
350         String[] modeleSplit = scanBarCode.split(",");
351         for (String modele : modeleSplit) {
352             DaParamCollection daParamCollection = new DaParamCollection();
353             daParamCollection.setParamCode(bsFormulaChildInfo.getParamCode());
354             daParamCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo());
355             daParamCollection.setLocationCode(bsFormulaChildInfo.getLocationCode());
356             daParamCollection.setParamValue(bsFormulaChildInfo.getParamValue());
357             daParamCollection.setProductCode(bsFormulaChildInfo.getProductCode());
358             daParamCollection.setCollectionTime(new Date());
359             daParamCollection.setSfcCode(modele);
360             daParamCollectionMapper.insertDaParamCollection(daParamCollection);
361         }
362
363     }
364
e57a89 365     @Override
366     public AjaxResult workpieceRelease(BsFormulaChildInfo bsFormulaChildInfo) {
63b254 367         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
368                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
369                 .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
370         for (BsFormulaChildInfo info : list) {
e70fb4 371             info.setCollectData("");
63b254 372             info.setResults("");
373             bsFormulaChildInfoService.saveOrUpdate(info);
374         }
e57a89 375         return AjaxResult.success();
376     }
b77303 377
378     @Override
379     public AjaxResult updateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo) {
7bee80 380         BsFormulaChildInfo getMaterTwo = new BsFormulaChildInfo();
381         getMaterTwo.setProcessesCode(bsFormulaChildInfo.getLocationCode());
382         getMaterTwo.setOperationType("2");
383         List<BsFormulaChildInfo> operationType = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(getMaterTwo);
384         List<String> collect = operationType.stream().map(BsFormulaChildInfo::getResults).collect(Collectors.toList());
385         for (String s : collect) {
386             if(s.equals("")){
387                 return AjaxResult.error("扫描未完成,禁止拧紧操作!");
388             }
389         }
b77303 390         BsFormulaChildInfo listQuery = new BsFormulaChildInfo();
391         listQuery.setParamCode(bsFormulaChildInfo.getParamCode());
392         String paramCode = bsFormulaChildInfo.getTightenTheArray();
393         if(paramCode.contains("N")){
394             List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
395             bsFormulaChildInfos.get(0).setResults("NG");
396             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
397             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
398             return AjaxResult.error("扫描结果NG,请重新扫描!");
399         }else {
400             List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
401             bsFormulaChildInfos.get(0).setResults("OK");
402             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
403             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
4a5f2a 404
A 405             Integer stepNumber = Integer.valueOf(bsFormulaChildInfos.get(0).getStepSort());
406             try {
407                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".StepNumber").value(stepNumber).build());
408             } catch (Exception e) {
409                 throw new RuntimeException(e);
410             }
411
3c2299 412             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
413             if (spareField4 != null && !spareField4.isEmpty()) {
414                 // 执行操作
415                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
416                     try {
32483a 417 //                        //更新过站记录表出站时间
418 //                        DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
419 //                        daPassingStationCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo());
420 //                        List<DaPassingStationCollection> daPassingStationCollections = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection);
421 //                        daPassingStationCollections.get(0).setOutboundTime(new Date());
422 //                        daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
b5fcd8 423                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".RecordDataDone").value(21).build());
3c2299 424                         WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), "OUT");
425                     } catch (Exception e) {
426                         throw new RuntimeException(e);
427                     }
428                 }
429             }
430
b77303 431         }
432         return AjaxResult.success("扫描成功!");
433     }
434
435
436
437
e57a89 438 }