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