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