admin
2024-08-04 517d1ae8b37b25228a771556cdf46b422b8b5bf5
提交 | 用户 | 时间
0ca254 1 package com.jcdm.main.bs.formulaChild.service.impl;
A 2
3 import java.util.ArrayList;
4 import java.util.Date;
5 import java.util.List;
6 import java.util.Map;
7 import java.util.regex.Matcher;
8 import java.util.regex.Pattern;
9 import java.util.stream.Collectors;
10
11 import cn.hutool.core.util.StrUtil;
12 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
13 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
14 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
15 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
16 import com.jcdm.common.core.domain.AjaxResult;
17 import com.jcdm.common.utils.DateUtils;
18 import com.jcdm.common.utils.StringUtils;
19 import com.jcdm.framework.websocket.WebSocketUsers;
20 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
21 import com.jcdm.main.da.paramCollection.mapper.DaParamCollectionMapper;
22 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
23 import com.jcdm.main.da.paramCollectionTemp.domain.DaParamCollectionTemp;
24 import com.jcdm.main.da.paramCollectionTemp.service.IDaParamCollectionTempService;
25 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
26 import com.jcdm.main.da.passingStationCollection.mapper.DaPassingStationCollectionMapper;
27 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
28 import com.jcdm.main.da.testDeviceInterface.service.IDaTestDeviceInterfaceService;
29 import com.jcdm.main.plcserver.util.TimeUtil;
30 import com.kangaroohy.milo.model.ReadWriteEntity;
31 import com.kangaroohy.milo.service.MiloService;
32 import lombok.extern.slf4j.Slf4j;
33 import org.aspectj.weaver.loadtime.Aj;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Service;
38 import com.jcdm.main.bs.formulaChild.mapper.BsFormulaChildInfoMapper;
39 import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo;
40 import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService;
41
42 import javax.websocket.Session;
43
44 /**
45  * 配方配置子信息Service业务层处理
46  * 
47  * @author ruimin
48  * @date 2023-12-26
49  */
50 @Service
51 @Slf4j
52 public class BsFormulaChildInfoServiceImpl extends ServiceImpl<BsFormulaChildInfoMapper,BsFormulaChildInfo> implements IBsFormulaChildInfoService
53 {
54     private static final Logger logger = LoggerFactory.getLogger("sys-user");
55     @Autowired
56     private BsFormulaChildInfoMapper bsFormulaChildInfoMapper;
57
58     @Autowired
59     private IBsFormulaChildInfoService bsFormulaChildInfoService;
60
61     @Autowired
62     private DaParamCollectionMapper daParamCollectionMapper;
63
64     @Autowired
65     private MiloService miloService;
66
67     @Autowired
68     private DaPassingStationCollectionMapper daPassingStationCollectionMapper;
69
70     @Autowired
71     private IDaTestDeviceInterfaceService daTestDeviceInterfaceService;
72
73     @Autowired
74     private IDaParamCollectionService daParamCollectionService;
75
76     @Autowired
77     private IDaPassingStationCollectionService daPassingStationCollectionService;
78
79     @Autowired
80     private IDaParamCollectionTempService daParamCollectionTempService;
81
82     Map<String, Session> map = WebSocketUsers.getUsers();
83
84     /**
85      * 查询配方配置子信息
86      * 
87      * @param id 配方配置子信息主键
88      * @return 配方配置子信息
89      */
90     @Override
91     public BsFormulaChildInfo selectBsFormulaChildInfoById(Long id)
92     {
93         return bsFormulaChildInfoMapper.selectBsFormulaChildInfoById(id);
94     }
95
96     /**
97      * 查询配方配置子信息列表
98      * 
99      * @param bsFormulaChildInfo 配方配置子信息
100      * @return 配方配置子信息
101      */
102     @Override
103     public List<BsFormulaChildInfo> selectBsFormulaChildInfoList(BsFormulaChildInfo bsFormulaChildInfo)
104     {
105         return bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(bsFormulaChildInfo);
106     }
107
108     /**
109      * 新增配方配置子信息
110      * 
111      * @param bsFormulaChildInfo 配方配置子信息
112      * @return 结果
113      */
114     @Override
115     public int insertBsFormulaChildInfo(BsFormulaChildInfo bsFormulaChildInfo)
116     {
117         bsFormulaChildInfo.setCreateTime(DateUtils.getNowDate());
118         return bsFormulaChildInfoMapper.insertBsFormulaChildInfo(bsFormulaChildInfo);
119     }
120
121     /**
122      * 修改配方配置子信息
123      * 
124      * @param bsFormulaChildInfo 配方配置子信息
125      * @return 结果
126      */
127     @Override
128     public int updateBsFormulaChildInfo(BsFormulaChildInfo bsFormulaChildInfo)
129     {
130         bsFormulaChildInfo.setUpdateTime(DateUtils.getNowDate());
131         return bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfo);
132     }
133
134     /**
135      * 批量删除配方配置子信息
136      * 
137      * @param ids 需要删除的配方配置子信息主键
138      * @return 结果
139      */
140     @Override
141     public int deleteBsFormulaChildInfoByIds(Long[] ids)
142     {
143         return bsFormulaChildInfoMapper.deleteBsFormulaChildInfoByIds(ids);
144     }
145
146     /**
147      * 删除配方配置子信息信息
148      * 
149      * @param id 配方配置子信息主键
150      * @return 结果
151      */
152     @Override
153     public int deleteBsFormulaChildInfoById(Long id)
154     {
155         return bsFormulaChildInfoMapper.deleteBsFormulaChildInfoById(id);
156     }
157
158     @Override
159     public BsFormulaChildInfo selectBsFormulaChildInfoByTypeTopOne(String type,String productCode,String processesCode) {
160         BsFormulaChildInfo info = new BsFormulaChildInfo();
161         info.setOperationType(type);
162         info.setProcessesCode(processesCode);
163         info.setProductCode(productCode);
164         return bsFormulaChildInfoMapper.selectBsFormulaChildInfoByTypeTopOne(info);
165     }
166
167     @Override
168     public BsFormulaChildInfo getCount(String productCode, String processesCode) {
169         BsFormulaChildInfo info = new BsFormulaChildInfo();
170         info.setProcessesCode(processesCode);
171         info.setProductCode(productCode);
172         return bsFormulaChildInfoMapper.getCount(info);
173     }
174
175     @Override
176     public AjaxResult yzUpdateResults(BsFormulaChildInfo bsFormulaChildInfo) {
177         String result = "";
178         List<BsFormulaChildInfo> bsFormulaChildInfos = new ArrayList<>();
179         List<BsFormulaChildInfo> infos = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
180                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
181                 .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode())
182                 .eq(BsFormulaChildInfo::getOperationType, "2")
183         );
184         List<String> newResultsList = infos.stream().map(s -> s.getCollectData()).collect(Collectors.toList());
185         if(newResultsList.stream().noneMatch(results -> results.equals(bsFormulaChildInfo.getScanBarcode()))){
186             for (BsFormulaChildInfo formulaChildInfo : infos) {
187                 if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())) {
188                     bsFormulaChildInfos.add(formulaChildInfo);
189                     break;
190                 }
191             }
192         }
193         if(bsFormulaChildInfos.size()>0){
194             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
195             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getScanBarcode());
196             bsFormulaChildInfos.get(0).setResults("OK");
197             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
198             bsFormulaChildInfo.setParamValue(bsFormulaChildInfo.getScanBarcode());
199             bsFormulaChildInfo.setParamCode(bsFormulaChildInfos.get(0).getParamCode());
200             bsFormulaChildInfo.setSfcBarcode(bsFormulaChildInfo.getSfcBarcode());
201             addParameterCollection(bsFormulaChildInfo);
202             if (spareField4 != null && !spareField4.isEmpty()) {
203                 // 执行操作
204                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
205                     try {
206                         result = "3";
207                     } catch (Exception e) {
208                         throw new RuntimeException(e);
209                     }
210                 }
211             }
212         }else {
213             result = "1";
214         }
215         return AjaxResult.success(result);
216     }
217
218     @Override
219     public AjaxResult yzUpdateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo) {
220         Boolean b = true;
221         String result = "1";
222 //        BsFormulaChildInfo getMaterTwo = new BsFormulaChildInfo();
223 //        getMaterTwo.setProcessesCode(bsFormulaChildInfo.getLocationCode());
224 //        getMaterTwo.setOperationType("2");
225 //        List<BsFormulaChildInfo> operationType = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(getMaterTwo);
226 //        List<String> collect = operationType.stream().map(BsFormulaChildInfo::getResults).collect(Collectors.toList());
227 //        for (String s : collect) {
228 //            if(s.equals("")){
229 ////                return AjaxResult.success("扫描未完成,禁止拧紧操作!");
230 //            }
231 //        }
232 //        BsFormulaChildInfo listQuery = new BsFormulaChildInfo();
233 //        listQuery.setParamCode(bsFormulaChildInfo.getParamCode());
234 //        listQuery.setProcessesCode(bsFormulaChildInfo.getLocationCode());
235         String paramData = bsFormulaChildInfo.getTightenTheArray();
236         if(paramData.contains("N")){
237             result = "3";
238 //            List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
239 //            bsFormulaChildInfos.get(0).setResults("NG");
240 //            bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
241 //            bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
242             this.updateTighteningData(bsFormulaChildInfo,"NG",paramData);
243 //            return AjaxResult.success("扫描结果NG,请重新扫描!");
244         }else {
245 //            List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
246             if(bsFormulaChildInfo.getSpareField2()!=null&&bsFormulaChildInfo.getSpareField3()!=null){
247                 String tightenArray = bsFormulaChildInfo.getTightenTheArray().replace("[", "").replace("]", "").replace(" ", "");
248                 String[] tightenDataParts = tightenArray.split(",");
249                 b = TimeUtil.isNumberInRange(Double.parseDouble(tightenDataParts[0]),Double.parseDouble(bsFormulaChildInfo.getSpareField2()),Double.parseDouble(bsFormulaChildInfo.getSpareField3()));
250             }
251             if(b){
252                 result = "3";
253 //                bsFormulaChildInfos.get(0).setResults("OK");
254 //                bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
255 //                bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
256                 this.updateTighteningData(bsFormulaChildInfo,"OK",paramData);
257 //                logger.info("yzUpdateTighteningFormula--查询条件参数:"+listQuery);
258 //                logger.info("yzUpdateTighteningFormula--查询结果:"+bsFormulaChildInfos.get(0));
259                 Integer stepNumber = Integer.valueOf(bsFormulaChildInfo.getStepSort());
260                 try {
261                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".MStepNumber").value(stepNumber+1).build());
262                 } catch (Exception e) {
263                     throw new RuntimeException(e);
264                 }
265
266                 String spareField4 = bsFormulaChildInfo.getSpareField4();
267                 if (spareField4 != null && !spareField4.isEmpty()) {
268                     // 执行操作
269                     if(bsFormulaChildInfo.getSpareField4().equals("1")){
270                         try {
271 //                        WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), "OUT");
272                             result = "2";
273                         } catch (Exception e) {
274                             throw new RuntimeException(e);
275                         }
276                     }
277                 }
278             }else {
279                 result = "3";
280 //                List<BsFormulaChildInfo> bsFormulaChildInfos1 = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
281 //                bsFormulaChildInfos1.get(0).setResults("NG");
282 //                String originalString = bsFormulaChildInfo.getTightenTheArray();
283                 String modifiedString = paramData.replaceFirst("OK", "NG");
284 //                bsFormulaChildInfos1.get(0).setCollectData(modifiedString);
285 //                bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos1.get(0));
286                 this.updateTighteningData(bsFormulaChildInfo,"NG",modifiedString);
287 //                return AjaxResult.success("扫描结果NG,请重新扫描!");
288             }
289         }
290         return AjaxResult.success(result);
291     }
292
293     @Override
294     public AjaxResult updateTighteningData(BsFormulaChildInfo bsFormulaChildInfo,String result,String data) {
295         LambdaUpdateWrapper<BsFormulaChildInfo> updateWrapper = new LambdaUpdateWrapper();
296         updateWrapper.set(BsFormulaChildInfo::getCollectData, data);
297         updateWrapper.set(BsFormulaChildInfo::getResults, result);
298         updateWrapper.eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode());
299         updateWrapper.eq(BsFormulaChildInfo::getParamCode, bsFormulaChildInfo.getParamCode());
300         boolean update = bsFormulaChildInfoService.update(new BsFormulaChildInfo(), updateWrapper);
301         return AjaxResult.success(update);
302     }
303
304     @Override
305     public AjaxResult jrmUpdateResults(BsFormulaChildInfo bsFormulaChildInfo) {
306         String result = "";
307         List<BsFormulaChildInfo> bsFormulaChildInfos = new ArrayList<>();
308         List<BsFormulaChildInfo> infos = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
309                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
310                 .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode())
311                 .eq(BsFormulaChildInfo::getOperationType, "2")
312         ).stream().filter(x -> StrUtil.isBlank(x.getCollectData())).collect(Collectors.toList());
313
314
315         for (BsFormulaChildInfo formulaChildInfo : infos) {
316             if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())){
317                 bsFormulaChildInfos.add(formulaChildInfo);
318                 break;
319             }
320         }
321         if(bsFormulaChildInfos.size()>0){
322             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
323             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getScanBarcode());
324             bsFormulaChildInfos.get(0).setResults("OK");
325             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
326             bsFormulaChildInfo.setParamValue(bsFormulaChildInfo.getScanBarcode());
327             bsFormulaChildInfo.setParamCode(bsFormulaChildInfos.get(0).getParamCode());
328             bsFormulaChildInfo.setSfcBarcode(bsFormulaChildInfo.getSfcBarcode());
329             jrmAddParameterCollection(bsFormulaChildInfo);
330
331             if (spareField4 != null && !spareField4.isEmpty()) {
332                 // 执行操作
333                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
334                     try {
335                         result = "3";
336 //                        String strA = bsFormulaChildInfo.getLocationCode() + "A";
337 //                        String strB = bsFormulaChildInfo.getLocationCode() + "B";
338 //                        miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+strA+".RecordDataDone").value(21).build());
339 //                        miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+strB+".RecordDataDone").value(21).build());
340                         String locationCode = bsFormulaChildInfo.getLocationCode();
341 //                        miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+locationCode+".RecordDataDone").value(21).build());
342                     } catch (Exception e) {
343                         throw new RuntimeException(e);
344                     }
345                 }
346             }
347         }else {
348             result = "1";
349         }
350         return AjaxResult.success(result);
351     }
352
353     @Override
354     public AjaxResult jrmWorkpieceRelease(BsFormulaChildInfo bsFormulaChildInfo) {
355         this.clearCollectDataAndResultsByProcessesCode(bsFormulaChildInfo);
356 //        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
357 //                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
358 //                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
359 //        for (BsFormulaChildInfo info : list) {
360 //            info.setCollectData("");
361 //            info.setResults("");
362 //            bsFormulaChildInfoService.saveOrUpdate(info);
363 //        }
364         String[] split = bsFormulaChildInfo.getProductBarcode().split(",");
365         try {
366             for (int i = 0; i < split.length; i++) {
367                 daParamCollectionService.pushGeelycvMesFeedback(split[i], bsFormulaChildInfo.getLocationCode());
368
369                 String barCode = split[i];
370                 String locationCode = bsFormulaChildInfo.getLocationCode();
371
372                 if(StringUtils.isNotBlank(locationCode)&&StringUtils.isNotBlank(barCode)){
373                     DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
374                     daPassingStationCollection.setOutRsSign("1");
375                     daPassingStationCollection.setOutboundTime(new Date());
376                     daPassingStationCollection.setSfcCode(barCode);
377                     daPassingStationCollection.setLocationCode(locationCode);
378                     int updateDaPassingStation = daPassingStationCollectionService.updateDaPassingStationCollectionBySfcCodeAndLocationCode(daPassingStationCollection);
379                     logger.info("加热膜人工工位更新过站记录updateDaPassingStationCollectionBySfcCodeAndLocationCode:更新了{}条数据-更新条件pack码{}-工位{}",updateDaPassingStation,barCode,locationCode);
380                 }
381
382 //                DaPassingStationCollection passingStationCollectionOne = daPassingStationCollectionService.getOne(new LambdaQueryWrapper<DaPassingStationCollection>().eq(DaPassingStationCollection::getSfcCode, barCode).eq(DaPassingStationCollection::getLocationCode, locationCode));
383 //                if (passingStationCollectionOne != null) {
384 //                    passingStationCollectionOne.setOutRsSign("1");
385 //                    passingStationCollectionOne.setOutboundTime(new Date());
386 //                    daPassingStationCollectionService.saveOrUpdate(passingStationCollectionOne);
387 //                }
388             }
389         }catch (Exception e){
390         }
391         return AjaxResult.success();
392     }
393
394     @Override
395     public AjaxResult clearWorkpieceRelease(BsFormulaChildInfo bsFormulaChildInfo) {
396 //        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
397 //                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
398 //                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
399 //        for (BsFormulaChildInfo info : list) {
400 //            info.setCollectData("");
401 //            info.setResults("");
402 //            bsFormulaChildInfoService.saveOrUpdate(info);
403 //        }
404         this.clearCollectDataAndResultsByProcessesCode(bsFormulaChildInfo);
405         return AjaxResult.success();
406     }
407
408     @Override
409     public AjaxResult checkMaterialCode(BsFormulaChildInfo bsFormulaChildInfo) {
410         String result = "1";
411         BsFormulaChildInfo getMaterTwo = new BsFormulaChildInfo();
412         getMaterTwo.setProcessesCode(bsFormulaChildInfo.getLocationCode());
413         getMaterTwo.setOperationType("2");
414         List<BsFormulaChildInfo> operationType = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(getMaterTwo);
415         List<String> collect = operationType.stream().map(BsFormulaChildInfo::getResults).collect(Collectors.toList());
416         for (String s : collect) {
417             if(s.equals("")){
418                 result = "2";
419             }
420         }
421         return AjaxResult.success(result);
422     }
423
424     @Override
425     public AjaxResult clearCollectDataAndResultsByProcessesCode(BsFormulaChildInfo bsFormulaChildInfo) {
426         LambdaUpdateWrapper<BsFormulaChildInfo> updateWrapper = new LambdaUpdateWrapper();
427         updateWrapper.set(BsFormulaChildInfo::getCollectData, "");
428         updateWrapper.set(BsFormulaChildInfo::getResults,"");
429         updateWrapper.eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode());
430         BsFormulaChildInfo info = new BsFormulaChildInfo();
431         boolean update = this.update(info,updateWrapper);
432         return AjaxResult.success(update);
433     }
434
435     @Override
436     public BsFormulaChildInfo releaseCheck(BsFormulaChildInfo bsFormulaChildInfo) {
437         return bsFormulaChildInfoMapper.releaseCheck(bsFormulaChildInfo);
438     }
439
440     //1-非本工位物料 2-正常扫描可继续下次 3-扫描结束已经是最后一位工步
441     @Override
442     public AjaxResult updateResults(BsFormulaChildInfo bsFormulaChildInfo) {
443         String result = "";
444         List<BsFormulaChildInfo> bsFormulaChildInfos = new ArrayList<>();
445         List<BsFormulaChildInfo> infos = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
446                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
447                 .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode())
448                 .eq(BsFormulaChildInfo::getOperationType, "2")
449         );
450         for (BsFormulaChildInfo formulaChildInfo : infos) {
451             if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())){
452                 if(null != formulaChildInfo.getCollectData()){
453                     if(!formulaChildInfo.getCollectData().equals(bsFormulaChildInfo.getScanBarcode())){
454                         bsFormulaChildInfos.add(formulaChildInfo);
455                     }else{
456                         result = "2";
457                         return AjaxResult.success(result);
458                     }
459                 }else{
460                     bsFormulaChildInfos.add(formulaChildInfo);
461                 }
462                 break;
463             }
464         }
465         if(bsFormulaChildInfos.size()>0){
466             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
467             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getScanBarcode());
468             bsFormulaChildInfos.get(0).setResults("OK");
469             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
470             bsFormulaChildInfo.setParamValue(bsFormulaChildInfo.getScanBarcode());
471             bsFormulaChildInfo.setParamCode(bsFormulaChildInfos.get(0).getParamCode());
472             bsFormulaChildInfo.setSfcBarcode(bsFormulaChildInfo.getSfcBarcode());
473             addParameterCollection(bsFormulaChildInfo);
474
475 //            Integer stepNumber = Integer.valueOf(bsFormulaChildInfos.get(0).getStepSort());
476 //            try {
477 //                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".StepNumber").value(stepNumber).build());
478 //            } catch (Exception e) {
479 //                throw new RuntimeException(e);
480 //            }
481
482             if (spareField4 != null && !spareField4.isEmpty()) {
483                 // 执行操作
484                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
485                     try {
486                         result = "3";
487 //                        miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".RecordDataDone").value(21).build());
488                     } catch (Exception e) {
489                         throw new RuntimeException(e);
490                     }
491                 }
492             }
493         }
494         return AjaxResult.success(result);
495     }
496
497     public void addParameterCollection(BsFormulaChildInfo bsFormulaChildInfo){
498         DaParamCollection daParamCollection = new DaParamCollection();
499         daParamCollection.setParamCode(bsFormulaChildInfo.getParamCode());
500         daParamCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo());
501         daParamCollection.setLocationCode(bsFormulaChildInfo.getLocationCode());
502         daParamCollection.setParamValue(bsFormulaChildInfo.getParamValue());
503         daParamCollection.setProductCode(bsFormulaChildInfo.getProductCode());
504         daParamCollection.setCollectionTime(new Date());
505         daParamCollection.setSfcCode(bsFormulaChildInfo.getSfcBarcode());
506         daParamCollectionMapper.insertDaParamCollection(daParamCollection);
507
508         DaParamCollectionTemp daParamCollectionTemp = new DaParamCollectionTemp();
509         daParamCollectionTemp.setParamCode(bsFormulaChildInfo.getParamCode());
510         daParamCollectionTemp.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo());
511         daParamCollectionTemp.setLocationCode(bsFormulaChildInfo.getLocationCode());
512         daParamCollectionTemp.setParamValue(bsFormulaChildInfo.getParamValue());
513         daParamCollectionTemp.setProductCode(bsFormulaChildInfo.getProductCode());
514         daParamCollectionTemp.setCollectionTime(new Date());
515         daParamCollectionTemp.setSfcCode(bsFormulaChildInfo.getSfcBarcode());
516         daParamCollectionTempService.save(daParamCollectionTemp);
517     }
518
519     public void jrmAddParameterCollection(BsFormulaChildInfo bsFormulaChildInfo){
520         String scanBarCode = bsFormulaChildInfo.getSfcBarcode();
521         String[] modeleSplit = scanBarCode.split(",");
522 //        for (String modele : modeleSplit) {
523             DaParamCollection daParamCollection = new DaParamCollection();
524             daParamCollection.setParamCode(bsFormulaChildInfo.getParamCode());
525             daParamCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo());
526             daParamCollection.setLocationCode(bsFormulaChildInfo.getLocationCode());
527             daParamCollection.setParamValue(bsFormulaChildInfo.getParamValue());
528             daParamCollection.setProductCode(bsFormulaChildInfo.getProductCode());
529             daParamCollection.setCollectionTime(new Date());
530             if(bsFormulaChildInfo.getParamCode().contains("B")){
531                 daParamCollection.setSfcCode(modeleSplit[1]);
532             }else {
533                 daParamCollection.setSfcCode(modeleSplit[0]);
534             }
535 //            daParamCollection.setSfcCode(modele);
536             daParamCollectionMapper.insertDaParamCollection(daParamCollection);
537 //        }
538
539             DaParamCollectionTemp daParamCollectionTemp = new DaParamCollectionTemp();
540             daParamCollectionTemp.setParamCode(bsFormulaChildInfo.getParamCode());
541             daParamCollectionTemp.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo());
542             daParamCollectionTemp.setLocationCode(bsFormulaChildInfo.getLocationCode());
543             daParamCollectionTemp.setParamValue(bsFormulaChildInfo.getParamValue());
544             daParamCollectionTemp.setProductCode(bsFormulaChildInfo.getProductCode());
545             daParamCollectionTemp.setCollectionTime(new Date());
546             if(bsFormulaChildInfo.getParamCode().contains("B")){
547                 daParamCollectionTemp.setSfcCode(modeleSplit[1]);
548             }else {
549                 daParamCollectionTemp.setSfcCode(modeleSplit[0]);
550             }
551             daParamCollectionTempService.save(daParamCollectionTemp);
552     }
553
554     @Override
555     public AjaxResult workpieceRelease(BsFormulaChildInfo bsFormulaChildInfo) {
556         this.clearCollectDataAndResultsByProcessesCode(bsFormulaChildInfo);
557 //        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
558 //                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
559 //                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
560 //        for (BsFormulaChildInfo info : list) {
561 //            info.setCollectData("");
562 //            info.setResults("");
563 //            bsFormulaChildInfoService.saveOrUpdate(info);
564 //        }
565         try {
566             daParamCollectionService.pushGeelycvMesFeedback(bsFormulaChildInfo.getProductBarcode(), bsFormulaChildInfo.getLocationCode());
567 //            String barCode = bsFormulaChildInfo.getProductBarcode();
568 //            String locationCode = bsFormulaChildInfo.getLocationCode();
569 //
570 //            if(StringUtils.isNotBlank(locationCode)&&StringUtils.isNotBlank(barCode)){
571 //                DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
572 //                daPassingStationCollection.setOutRsSign("1");
573 //                daPassingStationCollection.setOutboundTime(new Date());
574 //                daPassingStationCollection.setSfcCode(barCode);
575 //                daPassingStationCollection.setLocationCode(locationCode);
576 //                int updateDaPassingStation = daPassingStationCollectionService.updateDaPassingStationCollectionBySfcCodeAndLocationCode(daPassingStationCollection);
577 //                logger.info("普通人工工位更新过站记录updateDaPassingStationCollectionBySfcCodeAndLocationCode:更新了{}条数据-更新条件pack码{}-工位{}",updateDaPassingStation,barCode,locationCode);
578 //            }
579
580 //            DaPassingStationCollection passingStationCollectionOne = daPassingStationCollectionService.getOne(new LambdaQueryWrapper<DaPassingStationCollection>().eq(DaPassingStationCollection::getSfcCode, barCode).eq(DaPassingStationCollection::getLocationCode, locationCode));
581 //            if (passingStationCollectionOne != null) {
582 //                passingStationCollectionOne.setOutRsSign("1");
583 //                passingStationCollectionOne.setOutboundTime(new Date());
584 //                daPassingStationCollectionService.saveOrUpdate(passingStationCollectionOne);
585 //            }
586         }catch (Exception e){
587         }
588         return AjaxResult.success();
589     }
590
591     @Override
592     public AjaxResult updateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo) {
593         Boolean b = true;
594         BsFormulaChildInfo getMaterTwo = new BsFormulaChildInfo();
595         getMaterTwo.setProcessesCode(bsFormulaChildInfo.getLocationCode());
596         getMaterTwo.setOperationType("2");
597         List<BsFormulaChildInfo> operationType = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(getMaterTwo);
598         List<String> collect = operationType.stream().map(BsFormulaChildInfo::getResults).collect(Collectors.toList());
599         for (String s : collect) {
600             if(s.equals("")){
601                 return AjaxResult.error("扫码未完成,禁止拧紧操作!");
602             }
603         }
604
605         //添加拧紧参数-参数采集表
606         DaParamCollection daParamCollection = new DaParamCollection();
607         daParamCollection.setParamCode(bsFormulaChildInfo.getParamCode());
608         daParamCollection.setTightenTheArray(bsFormulaChildInfo.getTightenTheArray());
609         daParamCollection.setProductBarcode(bsFormulaChildInfo.getProductBarcode());
610         daParamCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo());
611         daParamCollection.setLocationCode(bsFormulaChildInfo.getLocationCode());
612         daParamCollection.setProductCode(bsFormulaChildInfo.getProductCode());
613         daParamCollectionService.addTighteningParameters(daParamCollection);
614
615         String paramCode = bsFormulaChildInfo.getTightenTheArray();
616         if(paramCode.contains("NG")){
617        /*     List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
618             bsFormulaChildInfos.get(0).setResults("NG");
619             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
620 */
621             bsFormulaChildInfo.setResults("NG");
622             bsFormulaChildInfo.setCollectData(bsFormulaChildInfo.getTightenTheArray());
623             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfo);
624             return AjaxResult.error("拧紧结果NG,请重新拧紧!");
625         }else {
626             //List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
627             if(bsFormulaChildInfo.getSpareField2()!=null&&bsFormulaChildInfo.getSpareField3()!=null){
628                 String tightenArray = bsFormulaChildInfo.getTightenTheArray().replace("[", "").replace("]", "").replace(" ", "");
629                 String[] tightenDataParts = tightenArray.split(",");
630                 b = TimeUtil.isNumberInRange(Double.parseDouble(tightenDataParts[0]),Double.parseDouble(bsFormulaChildInfo.getSpareField2()),Double.parseDouble(bsFormulaChildInfo.getSpareField3()));
631             }
632             if(b){
633                 bsFormulaChildInfo.setResults("OK");
634                 bsFormulaChildInfo.setCollectData(bsFormulaChildInfo.getTightenTheArray());
635                 bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfo);
636
637                 Integer stepNumber = Integer.valueOf(bsFormulaChildInfo.getStepSort());
638                 try {
639                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".MStepNumber").value(stepNumber+1).build());
640                 } catch (Exception e) {
641                     throw new RuntimeException(e);
642                 }
643
644                 String spareField4 = bsFormulaChildInfo.getSpareField4();
645                 if (spareField4 != null && !spareField4.isEmpty()) {
646                     // 执行操作
647                     if(spareField4.equals("1")){
648                         try {
649     //                        //更新过站记录表出站时间
650     //                        DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
651     //                        daPassingStationCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo());
652     //                        List<DaPassingStationCollection> daPassingStationCollections = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection);
653     //                        daPassingStationCollections.get(0).setOutboundTime(new Date());
654     //                        daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
655 //                            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".RecordDataDone").value(21).build());
656                             WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), "OUT");
657                         } catch (Exception e) {
658                             throw new RuntimeException(e);
659                         }
660                     }
661                 }
662             }else {
663                 //List<BsFormulaChildInfo> bsFormulaChildInfos1 = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
664                 bsFormulaChildInfo.setResults("NG");
665                 String originalString = bsFormulaChildInfo.getTightenTheArray();
666                 String modifiedString = originalString.replaceFirst("OK", "NG");
667                 bsFormulaChildInfo.setCollectData(modifiedString);
668                 bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfo);
669                 return AjaxResult.error("拧紧结果NG,请重新拧紧!");
670             }
671
672         }
673
674
675         return AjaxResult.success("拧紧成功!");
676     }
677
678
679
680
681 }