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