admin
2024-07-12 971788bf15d4bd58fe5bb6dbb76f16317a25ef7b
提交 | 用户 | 时间
0ca254 1 package com.jcdm.main.da.paramCollection.service.impl;
A 2
3 import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.date.DateUtil;
5 import cn.hutool.core.util.ObjectUtil;
6 import cn.hutool.core.util.StrUtil;
7 import cn.hutool.db.Db;
8 import cn.hutool.http.HttpRequest;
9 import cn.hutool.http.HttpResponse;
10 import cn.hutool.json.JSONObject;
11 import cn.hutool.json.JSONUtil;
12 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
13 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
14 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
15 import com.jcdm.common.core.domain.AjaxResult;
16 import com.jcdm.common.utils.DateUtils;
17 import com.jcdm.common.utils.SecurityUtils;
18 import com.jcdm.common.utils.StringUtils;
19 import com.jcdm.main.bs.formula.service.IBsFormulaInfoService;
20 import com.jcdm.main.bs.formula.service.impl.BsFormulaInfoServiceImpl;
21 import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo;
22 import com.jcdm.main.bs.formulaChild.mapper.BsFormulaChildInfoMapper;
23 import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService;
24 import com.jcdm.main.constant.Constants;
25 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
26 import com.jcdm.main.da.collectionParamConf.mapper.DaCollectionParamConfMapper;
27 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
28 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
29 import com.jcdm.main.da.paramCollection.mapper.DaParamCollectionMapper;
30 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
31 import com.jcdm.main.da.paramCollectionTemp.domain.DaParamCollectionTemp;
32 import com.jcdm.main.da.paramCollectionTemp.service.IDaParamCollectionTempService;
33 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
34 import com.jcdm.main.da.passingStationCollection.mapper.DaPassingStationCollectionMapper;
35 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
36 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
37 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
38 import com.jcdm.main.plcserver.sub.OPCUaSubscription;
39 import com.jcdm.main.restful.factoryMes.service.RestfulService;
40 import com.jcdm.main.restful.qingYan.doman.ChildVO;
41 import com.jcdm.main.restful.qingYan.doman.ParentVO;
42 import com.kangaroohy.milo.model.ReadWriteEntity;
43 import com.kangaroohy.milo.service.MiloService;
44 import lombok.extern.slf4j.Slf4j;
45 import org.apache.ibatis.session.ExecutorType;
46 import org.apache.ibatis.session.SqlSession;
47 import org.apache.ibatis.session.SqlSessionFactory;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50 import org.springframework.beans.factory.annotation.Autowired;
51 import org.springframework.security.core.parameters.P;
52 import org.springframework.stereotype.Service;
53
54 import javax.annotation.Resource;
55 import java.text.SimpleDateFormat;
56 import java.time.Instant;
57 import java.util.*;
58 import java.util.concurrent.CompletableFuture;
59 import java.util.stream.Collectors;
60
61 /**
62  * 设备产品过程参数采集Service业务层处理
63  * 
64  * @author yyt
65  * @date 2023-12-13
66  */
67 @Slf4j
68 @Service
69 public class DaParamCollectionServiceImpl extends ServiceImpl<DaParamCollectionMapper,DaParamCollection> implements IDaParamCollectionService
70 {
71     private static final Logger logger = LoggerFactory.getLogger("sys-user");
72
73     @Autowired
74     private DaParamCollectionMapper daParamCollectionMapper;
75
76     @Autowired
77     private DaCollectionParamConfMapper daCollectionParamConfMapper;
78
79     @Autowired
80     private BsFormulaChildInfoMapper bsFormulaChildInfoMapper;
81
82     @Autowired
83     private IBsFormulaChildInfoService bsFormulaChildInfoService;
84
85     @Autowired
86     private MiloService miloService;
87
88     @Autowired
89     private DaPassingStationCollectionMapper daPassingStationCollectionMapper;
90
91     @Resource
92     private SqlSessionFactory sqlSessionFactory;
93
94     @Autowired
95     private IDaParamCollectionService daParamCollectionService;
96
97     @Autowired
98     private IDaCollectionParamConfService daCollectionParamConfService;
99
100     @Autowired
101     private IDaParamCollectionTempService daParamCollectionTempService;
102
103     @Autowired
104     private IOmProductionOrdeInfoService omProductionOrdeInfoService;
105
106     @Autowired
107     private IDaPassingStationCollectionService daPassingStationCollectionService;
108
109     public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
110
111     /**
112      * 查询设备产品过程参数采集
113      * 
114      * @param id 设备产品过程参数采集主键
115      * @return 设备产品过程参数采集
116      */
117     @Override
118     public DaParamCollection selectDaParamCollectionById(Long id)
119     {
120         return daParamCollectionMapper.selectDaParamCollectionById(id);
121     }
122
123     /**
124      * 查询设备产品过程参数采集列表
125      * 
126      * @param daParamCollection 设备产品过程参数采集
127      * @return 设备产品过程参数采集
128      */
129     @Override
130     public List<DaParamCollection> selectDaParamCollectionList(DaParamCollection daParamCollection)
131     {
132         return daParamCollectionMapper.selectDaParamCollectionList(daParamCollection);
133     }
134
135     @Override
136     public void saveBeachDaParamCollection(List<DaParamCollection> list) {
137         // ExecutorType.SIMPLE: 这个执行器类型不做特殊的事情。它为每个语句的执行创建一个新的预处理语句。
138         // ExecutorType.REUSE: 这个执行器类型会复用预处理语句。
139         // ExecutorType.BATCH: 这个执行器会批量执行所有更新语句,如果 SELECT 在它们中间执行还会标定它们是 必须的,来保证一个简单并易于理解的行为。
140         logger.info("进入乐工批量方法saveBeachDaParamCollection");
141
142         // 关闭session的自动提交
143         SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
144         try {
145             DaParamCollectionMapper userMapper = sqlSession.getMapper(DaParamCollectionMapper.class);
146             list.stream().forEach(DaParamCollection -> userMapper.insertDaParamCollection(DaParamCollection));
147             // 提交数据
148             sqlSession.commit();
149             sqlSession.rollback();
150             logger.info("结束乐工批量方法saveBeachDaParamCollection");
151
152         } catch (Exception e) {
153             sqlSession.rollback();
154         } finally {
155             sqlSession.close();
156         }
157     }
158
159     /**
160      * 新增设备产品过程参数采集
161      * 
162      * @param daParamCollection 设备产品过程参数采集
163      * @return 结果
164      */
165     @Override
166     public int insertDaParamCollection(DaParamCollection daParamCollection)
167     {
168         daParamCollection.setCreateTime(DateUtils.getNowDate());
169         return daParamCollectionMapper.insertDaParamCollection(daParamCollection);
170     }
171
172     /**
173      * 修改设备产品过程参数采集
174      * 
175      * @param daParamCollection 设备产品过程参数采集
176      * @return 结果
177      */
178     @Override
179     public int updateDaParamCollection(DaParamCollection daParamCollection)
180     {
181         daParamCollection.setUpdateTime(DateUtils.getNowDate());
182         return daParamCollectionMapper.updateDaParamCollection(daParamCollection);
183     }
184
185     /**
186      * 批量删除设备产品过程参数采集
187      * 
188      * @param ids 需要删除的设备产品过程参数采集主键
189      * @return 结果
190      */
191     @Override
192     public int deleteDaParamCollectionByIds(Long[] ids)
193     {
194         return daParamCollectionMapper.deleteDaParamCollectionByIds(ids);
195     }
196
197     /**
198      * 删除设备产品过程参数采集信息
199      * 
200      * @param id 设备产品过程参数采集主键
201      * @return 结果
202      */
203     @Override
204     public int deleteDaParamCollectionById(Long id)
205     {
206         return daParamCollectionMapper.deleteDaParamCollectionById(id);
207     }
208
209     @Override
210     public void addBasicParameters(DaParamCollection daParamCollection) {
211         // 假设这是从数据库或其他地方获取的参数数据
212         Map<String, String> map = new HashMap<>();
213         map.put("GC", "南浔工厂");
214         map.put("CXBH", "Pack线");
215         map.put("SBBH", "设备001");
216         map.put("YGBH", "员工001");
217         map.put("GDBH", daParamCollection.getWorkOrderNo());
218         map.put("CPXH", daParamCollection.getModel());
219         map.put("INT", DateUtil.formatDateTime(new Date()));
220
221         map.forEach((key, value) -> {
222             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
223             daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
224             daCollectionParamConf.setCollectParameterId(key);
225             List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
226             DaParamCollection saveData = new DaParamCollection();
227             saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
228             saveData.setProductCode(daParamCollection.getProductCode());
229             saveData.setLocationCode(daParamCollection.getLocationCode());
230             saveData.setSfcCode(daParamCollection.getProductBarcode());
231             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
232             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
233             saveData.setCollectionTime(new Date());
234             saveData.setParamValue(value);
235             daParamCollectionMapper.insertDaParamCollection(saveData);
236         });
237     }
238
239     @Override
240     public void addTighteningParameters(DaParamCollection daParamCollection) {
241         String paramCode = daParamCollection.getParamCode();
242         String tightenData = daParamCollection.getTightenTheArray();
243         if(StringUtils.isNotBlank(paramCode)&&StringUtils.isNotBlank(tightenData)){
244             tightenData = tightenData.replace("[", "").replace("]", "").replace(" ", "");
245             String[] tightenDataParts = tightenData.split(",");
246             String[] paramCodeParts = paramCode.split(",");
247             for (int i = 0; i < paramCodeParts.length; i++) {
248                 daParamCollection.setParamValue(tightenDataParts[i]);
249                 daParamCollection.setParamCode(paramCodeParts[i]);
250                 daParamCollection.setCollectionTime(new Date());
251                 daParamCollection.setSfcCode(daParamCollection.getProductBarcode());
252                 daParamCollectionMapper.insertDaParamCollection(daParamCollection);
253
254                 DaParamCollectionTemp daParamCollectionTemp = new DaParamCollectionTemp();
255                 daParamCollectionTemp.setParamValue(tightenDataParts[i]);
256                 daParamCollectionTemp.setParamCode(paramCodeParts[i]);
257                 daParamCollectionTemp.setCollectionTime(new Date());
258                 daParamCollectionTemp.setSfcCode(daParamCollection.getProductBarcode());
259                 daParamCollectionTemp.setLocationCode(daParamCollection.getLocationCode());
260                 daParamCollectionTemp.setProductCode(daParamCollection.getProductCode());
261                 daParamCollectionTempService.save(daParamCollectionTemp);
262             }
263         }
264     }
265
266     @Override
267     public void saveCampaignTimeParameters(DaParamCollection daParamCollection) {
2de856 268
0ca254 269         BsFormulaChildInfo childInfo = daParamCollection.getFormulaChildEntity();
A 270         if(StringUtils.isNotBlank(childInfo.getResults())){
271             if(!childInfo.getResults().equals("OK")){
272                 try {
2de856 273                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("MOZU1."+daParamCollection.getLocationCode()+".RecordDataDone").value(22).build());
0ca254 274                 } catch (Exception e) {
A 275                     throw new RuntimeException(e);
276                 }
277                 return;
278             }
279         }else {
280             try {
2de856 281                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("MOZU1."+daParamCollection.getLocationCode()+".RecordDataDone").value(22).build());
0ca254 282             } catch (Exception e) {
A 283                 throw new RuntimeException(e);
284             }
285             return;
286         }
2de856 287
0ca254 288         String result = childInfo.getResults();
A 289         if(result != null && !result.isEmpty()){
290             try {
291
292                 //增加过站记录
293                 DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
294                 daPassingStationCollection.setWorkOrderNo(daParamCollection.getWorkOrderNo());
295                 daPassingStationCollection.setSfcCode(daParamCollection.getProductBarcode());
296                 daPassingStationCollection.setProductCode(daParamCollection.getProductCode());
297                 daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
298                 daPassingStationCollection.setInboundTime(daParamCollection.getInboundTime());
299                 daPassingStationCollection.setOutboundTime(new Date());
300                 daPassingStationCollection.setCreateTime(new Date());
301                 daPassingStationCollection.setOutRsSign("1");
302                 boolean save = daPassingStationCollectionService.save(daPassingStationCollection);
303
304                 //添加基础参数
50c585 305 //                this.manualWorkstationsAddBasicParameters(daParamCollection);
0ca254 306
2de856 307                 //半自动工位,先将自动数据保存到数据库
C 308                 this.saveParameters(daParamCollection);
0ca254 309
A 310                 //给opc发21
2de856 311                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("MOZU1."+daParamCollection.getLocationCode()+".RecordDataDone").value(21).build());
ef58b9 312                 if(daParamCollection.getLocationCode().equals("M1OP100-1") || daParamCollection.getLocationCode().equals("M1OP100-2") ){
0ca254 313                     try{
A 314                         CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
ef58b9 315                             logger.info("OP100报工开始-工厂MES异步方法");
C 316                             String reportResult = RestfulService.getWorkReportResultFeedback(daParamCollection.getProductBarcode(), daParamCollection.getLocationCode(), format.format(new Date()));
0ca254 317                             JSONObject jsonObject = new JSONObject(reportResult);
A 318                             String code = jsonObject.getStr("code");
319                             if("success".equals(code)){
320                                 //如果成功,执行报工成功方法,修改是否报工为1,添加报工时间
ef58b9 321                                 omProductionOrdeInfoService.updateOrderByProductNum("1",daParamCollection.getProductBarcode(),daParamCollection.getLocationCode());
0ca254 322                             }else{
A 323                                 //解析工厂mes返回结果,如果失败,执行报工失败方法,修改是否报工为2,添加报工时间
ef58b9 324                                 omProductionOrdeInfoService.updateOrderByProductNum("2",daParamCollection.getProductBarcode(),daParamCollection.getLocationCode());
0ca254 325                             }
ef58b9 326                             logger.info("OP100报工结束-工厂MES异步方法{}"+reportResult);
0ca254 327                         });
A 328                     }catch (Exception e){
329                         System.out.println(e.getMessage());
330                     }
2de856 331
0ca254 332                 }
A 333
334
335             } catch (Exception e) {
336                 throw new RuntimeException(e);
337             }
338         }
339     }
340
2de856 341
C 342     //半自动工位,先将自动数据保存到数据库
343     public void saveParameters(DaParamCollection daParamCollection) {
344         //添加自动工位参数数据
345         //查询参数配置表
346         List<DaCollectionParamConf> list = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
347                 .eq(DaCollectionParamConf::getProcessesCode, daParamCollection.getLocationCode())//工位
348                 .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
349         );//类型
350
351         List<String> collectAddressList = list.stream()
352                 .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
353         List<ReadWriteEntity> paramCollectionList = null;//模组 参数值
354         try {
355             paramCollectionList = miloService.readFromOpcUa(collectAddressList);
356         } catch (Exception e) {
357             throw new RuntimeException(e);
358         }
359
360         if (CollUtil.isNotEmpty(paramCollectionList)) {
361             List<DaParamCollection> saveParamList = new ArrayList<>();//封装参数采集list
362             List<DaParamCollectionTemp> saveParamListTemp = new ArrayList<>();//封装参数采集list
363             for (int i = 0; i < paramCollectionList.size(); i++) {
364                 DaParamCollection collection = new DaParamCollection();
365                 collection.setSfcCode(daParamCollection.getProductBarcode());//模组码
366                 collection.setParamCode(list.get(i).getCollectParameterId());//参数编码
367                 collection.setParamName(list.get(i).getCollectParameterName());//参数名称
368                 String paramValue = "";
369                 if (ObjectUtil.isNotNull(paramCollectionList.get(i).getValue())) {
370                     paramValue = paramCollectionList.get(i).getValue().toString();//参数值
371                 }
372                 collection.setParamValue(paramValue);//参数值
373                 collection.setLocationCode(daParamCollection.getLocationCode());//工位
374                 collection.setCollectionTime(new Date());//采集时间
375                 saveParamList.add(collection);//封装参数采集list
376
377                 DaParamCollectionTemp collectionTemp = new DaParamCollectionTemp();
378                 collectionTemp.setSfcCode(daParamCollection.getProductBarcode());//模组码
379                 collectionTemp.setParamCode(list.get(i).getCollectParameterId());//参数编码
380                 collectionTemp.setParamName(list.get(i).getCollectParameterName());//参数名称
381
382                 if (ObjectUtil.isNotNull(paramCollectionList.get(i).getValue())) {
383                     paramValue = paramCollectionList.get(i).getValue().toString();//参数值
384                 }
385                 collectionTemp.setParamValue(paramValue);//参数值
386                 collectionTemp.setLocationCode(daParamCollection.getLocationCode());//工位
387                 collectionTemp.setCollectionTime(new Date());//采集时间
388                 saveParamListTemp.add(collectionTemp);//封装参数采集list
389
390             }
391             //插入参数采集表
392             daParamCollectionService.insertBatch(saveParamList);
393             //插入参数采集表
394             daParamCollectionTempService.insertBatch(saveParamListTemp);
395         }
396     }
0ca254 397     @Override
A 398     public void insertBatch(List<DaParamCollection> confList){
399         try{
400             this.saveBatch(confList);
401         }catch (Exception e){
402             return;
403         }
404
405     }
406
407     @Override
408     public void replaceAssemblyCode(DaParamCollection daParamCollection) {
409         List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>()
410                 .eq(DaParamCollection::getSfcCode, daParamCollection.getYzSfcCode())
411         );
412         if(list.size() > 0){
413             for (DaParamCollection paramCollection : list) {
414                 paramCollection.setSfcCode(daParamCollection.getSfcCode());
415                 daParamCollectionService.saveOrUpdate(paramCollection);
416             }
417         }
418
419     }
420
421     @Override
422     public void yzAddBasicParameters(DaParamCollection daParamCollection) {
423         // 假设这是从数据库或其他地方获取的参数数据
424         Map<String, String> map = new HashMap<>();
425 //        map.put("GC", "南浔工厂");
426 //        map.put("CXBH", "Pack线");
427 //        map.put("SBBH", "设备001");
428 //        map.put("YGBH", "员工001");
429 //        map.put("GDBH", daParamCollection.getWorkOrderNo());
430 //        map.put("CPXH", daParamCollection.getModel());
431         map.put("INT", DateUtil.formatDateTime(new Date()));
432
433         map.forEach((key, value) -> {
434             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
435             daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
436             daCollectionParamConf.setCollectParameterId(key);
437             List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
438             DaParamCollection saveData = new DaParamCollection();
439             saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
440             saveData.setProductCode(daParamCollection.getProductCode());
441             saveData.setLocationCode(daParamCollection.getLocationCode());
442             saveData.setSfcCode(daParamCollection.getProductBarcode());
443             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
444             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
445             saveData.setCollectionTime(new Date());
446             saveData.setParamValue(value);
447             daParamCollectionMapper.insertDaParamCollection(saveData);
448         });
449     }
450
451     @Override
452     public void jrmSaveCampaignTimeParameters(DaParamCollection daParamCollection) {
453         DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
454         daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
455         daCollectionParamConf.setCollectParameterId("OUTT");
456         List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
457         DaParamCollection saveData = new DaParamCollection();
458         saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
459         saveData.setProductCode(daParamCollection.getProductCode());
460         saveData.setLocationCode(daParamCollection.getLocationCode());
461         saveData.setSfcCode(daParamCollection.getProductBarcode());
462         saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
463         saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
464         saveData.setCollectionTime(new Date());
465         saveData.setParamValue(DateUtil.formatDateTime(new Date()));
466         daParamCollectionMapper.insertDaParamCollection(saveData);
467
468         //更新过站记录表出站时间
469         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
470         daPassingStationCollection.setWorkOrderNo(daParamCollection.getWorkOrderNo());
471         daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
472         List<DaPassingStationCollection> daPassingStationCollections = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection);
473         daPassingStationCollections.get(0).setOutboundTime(new Date());
474         int i = daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
475
476         try {
477             String strA = daParamCollection.getLocationCode();
478             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+strA+".RecordDataDone").value(21).build());
479         } catch (Exception e) {
480             throw new RuntimeException(e);
481         }
482     }
483
484
485     public void sendToFactoryMes(String stationCode,String productNum ){
486 //        String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
487         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
488         ParentVO vo =new ParentVO();
489         List<ChildVO> checkList = new ArrayList<>();
490         List<DaParamCollection> list = this.list(new LambdaQueryWrapper<DaParamCollection>()
491                 .eq(DaParamCollection::getSfcCode, productNum)
492                 .eq(DaParamCollection::getLocationCode, stationCode));
493         vo.setTotalResult("1");
494         String string = new Random(10).toString();
495         vo.setRecordId(string);
496         vo.setProductNum(productNum);
497         vo.setSiteCode("3983");
498         vo.setStationCode(stationCode);
499         if (CollUtil.isNotEmpty(list)){
500             List<DaParamCollection> collect = list.stream().filter(x -> Constants.NG.equals(x.getParamValue())).collect(Collectors.toList());
501             if (CollUtil.isNotEmpty(collect)){
502                 vo.setTotalResult("0");
503             }
504             List<BsFormulaChildInfo> bsFormulaChildInfoList = bsFormulaChildInfoService.list();
505             for (DaParamCollection daParamCollection : list) {
506                 ChildVO childVO = new ChildVO();
507                 childVO.setItemCode(daParamCollection.getParamCode());
508                 String time = daParamCollection.getCollectionTime() != null ? daParamCollection.getCollectionTime().toString() : "";
509                 childVO.setCheckResult("1");
510                 if (StrUtil.isNotBlank(daParamCollection.getParamValue())){
511                     if (Constants.NG.equals(daParamCollection.getParamValue())){
512                         childVO.setCheckResult("0");
513                     }
514                 }
515                 childVO.setCheckTime(time);
516                 childVO.setItemValue(daParamCollection.getParamValue());
517                 childVO.setItemType("3");
518                 childVO.setItemText(daParamCollection.getParamName());
519                 if (StrUtil.isNotBlank(daParamCollection.getParamCode())){
520                     List<BsFormulaChildInfo> collect1 = bsFormulaChildInfoList.stream().filter(x -> daParamCollection.getParamCode().equals(x.getParamCode())).collect(Collectors.toList());
521                     if (CollUtil.isNotEmpty(collect1)){
522                         BsFormulaChildInfo bsFormulaChildInfo = collect1.get(0);
523                         childVO.setItemType(bsFormulaChildInfo.getOperationType());
524                     }
525                 }
526
527                 checkList.add(childVO);
528             }
529         }
530         vo.setCheckList(checkList);
531         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(vo)).execute();
532
533     }
534
535     @Override
536     public void pushGeelycvMesFeedback(String packID, String stationCode) {
537         logger.info("进入人工工位推送工厂MES数据方法-pushGeelycvMesFeedback-工位{}-pack码{}",stationCode,packID);
538         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
539         String totalResult = "0";
540         List<DaParamCollectionTemp> paramList = daParamCollectionTempService.list(new LambdaQueryWrapper<DaParamCollectionTemp>().eq(DaParamCollectionTemp::getSfcCode, packID).eq(DaParamCollectionTemp::getLocationCode, stationCode));
541         if(paramList.size() > 0){
542             ParentVO parentVO = new ParentVO();
543             parentVO.setSiteCode("3983");
544             parentVO.setRecordId(String.valueOf(Instant.now().toEpochMilli()));
545             parentVO.setStationCode(stationCode);
546             parentVO.setProductNum(packID);
547             parentVO.setTotalResult("1");
548             List<ChildVO> listChildVo = new ArrayList<>();
549
550             for (DaParamCollectionTemp daParamCollection : paramList) {
551                 ChildVO childVO = new ChildVO();
552                 childVO.setItemCode(daParamCollection.getParamCode());
553 //                BsFormulaChildInfo childOne = bsFormulaChildInfoService.getOne(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getParamCode, daParamCollection.getParamCode()));
554 //                DaCollectionParamConf paramConfOne = daCollectionParamConfService.getOne(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
555                 List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
556                 DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
557 //                if(childOne!=null){
558 //                    String operationType = childOne.getOperationType();
559 //                    if(operationType.equals("1")){
560 //                        childVO.setItemType("2");
561 //                    }else if(operationType.equals("2")){
562 //                        childVO.setItemType("1");
563 //                    }
564 //                }else {
565 //                    childVO.setItemType("3");
566 //                }
567                 if(paramConfOne!=null){
568                     childVO.setItemType(paramConfOne.getSpareField1());
569                     childVO.setItemText(paramConfOne.getCollectParameterName());
570                 }else {
571                     childVO.setItemType("3");
572                     childVO.setItemText("");
573                 }
574                 childVO.setItemValue(daParamCollection.getParamValue());
575
576                 if(daParamCollection.getParamValue().equals("1")){
577                     childVO.setCheckResult("1");
578                 }else if(daParamCollection.getParamValue().equals("2")){
579                     childVO.setCheckResult("0");
580                     parentVO.setTotalResult("0");
581                     totalResult = "1";
582                 }else {
583                     childVO.setCheckResult("1");
584                 }
585                 childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
586                 listChildVo.add(childVO);
587
588             }
589             parentVO.setCheckList(listChildVo);
590             try{
591                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
592                     logger.info("开始执行异步方法");
971788 593                     HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
0ca254 594                     logger.info("异步方法执行结束");
A 595                     logger.info("手动工位传工厂MES异步方法{}"+execute.body());
596
597                     DaParamCollectionTemp daParamCollectionTemp = new DaParamCollectionTemp();
598                     daParamCollectionTemp.setSfcCode(packID);
599                     daParamCollectionTemp.setLocationCode(stationCode);
600                     int i = daParamCollectionTempService.deleteDaParamCollectionTempBySfcCodeAndLocationCode(daParamCollectionTemp);
601                     logger.info("删除临时表数据条数{}-工位{}-pack码{}",i,stationCode,packID);
602 //                    List<Long> idsList = paramList.stream().map(DaParamCollectionTemp::getId).collect(Collectors.toList());
603 //                    Long[] array = idsList.toArray(new Long[0]);
604 //                    int i = daParamCollectionTempService.deleteDaParamCollectionTempByIds(array);
605 //                    logger.info("删除临时表数据条数{}-工位{}-pack码{}",i,stationCode,packID);
606                 });
607             }catch (Exception e){
608                 System.out.println(e.getMessage());
609             }
610 //            HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
611
612 //            System.out.println(execute.body());
613             System.out.println("-----------------------"+totalResult);
614             logger.info("结束人工工位推送工厂MES数据方法-pushGeelycvMesFeedback-工位{}-pack码{}",stationCode,packID);
615         }
616
617     }
618
619     @Override
620     public void automaticWorkstationPushGeelycvMesFeedback(String packID, String stationCode,List<DaParamCollection> paramList) {
621         logger.info("进入工位{}-工厂MES推送数据方法automaticWorkstationPushGeelycvMesFeedback",stationCode);
622         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
623         String totalResult = "0";
624         if(paramList.size() > 0){
625             logger.info("进入工位{}-拼数据",stationCode);
626             ParentVO parentVO = new ParentVO();
627             parentVO.setSiteCode("3983");
628             parentVO.setRecordId(String.valueOf(Instant.now().toEpochMilli()));
629             parentVO.setStationCode(stationCode);
630             parentVO.setProductNum(packID);
631             parentVO.setTotalResult("1");
632             List<ChildVO> listChildVo = new ArrayList<>();
633
634             for (DaParamCollection daParamCollection : paramList) {
635                 ChildVO childVO = new ChildVO();
636                 childVO.setItemCode(daParamCollection.getParamCode());
637 //                BsFormulaChildInfo childOne = bsFormulaChildInfoService.getOne(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getParamCode, daParamCollection.getParamCode()));
638 //                DaCollectionParamConf paramConfOne = daCollectionParamConfService.getOne(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
639                 List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
640                 DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
641 //                if(childOne!=null){
642 //                    String operationType = childOne.getOperationType();
643 //                    if(operationType.equals("1")){
644 //                        childVO.setItemType("2");
645 //                    }else if(operationType.equals("2")){
646 //                        childVO.setItemType("1");
647 //                    }
648 //                }else {
649 //                    childVO.setItemType("3");
650 //                }
651                 if(paramConfOne!=null){
652                     childVO.setItemType(paramConfOne.getSpareField1());
653                     childVO.setItemText(paramConfOne.getCollectParameterName());
654                 }else {
655                     childVO.setItemType("3");
656                     childVO.setItemText("");
657                 }
658                 childVO.setItemValue(daParamCollection.getParamValue());
659
660                 if(daParamCollection.getParamValue().equals("1")){
661                     childVO.setCheckResult("1");
662                 }else if(daParamCollection.getParamValue().equals("2")){
663                     childVO.setCheckResult("0");
664                     parentVO.setTotalResult("0");
665                     totalResult = "1";
666                 }else {
667                     childVO.setCheckResult("1");
668                 }
669                 childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
670                 listChildVo.add(childVO);
671             }
672             parentVO.setCheckList(listChildVo);
673             logger.info("结束工位{}-拼数据",stationCode);
674             logger.info("进入工位{}-工厂MES推送数据方法HttpResponseSend",stationCode);
675             try{
676                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
677                     logger.info("开始执行异步方法");
971788 678                     HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
0ca254 679                     System.out.println(execute.body());
A 680                     logger.info("异步方法执行结束");
681                     logger.info("自动工位传工厂MES异步方法{}"+execute.body());
682                 });
683             }catch (Exception e){
684                 System.out.println(e.getMessage());
685             }
686 //            HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
687             logger.info("结束工位{}-工厂MES推送数据方法HttpResponseSend",stationCode);
688             System.out.println("-----------------------"+totalResult);
689         }
690         logger.info("结束工位{}-工厂MES推送数据方法automaticWorkstationPushGeelycvMesFeedback",stationCode);
691     }
692
693     @Override
694     public AjaxResult checkRecordDataDone(DaParamCollection daParamCollection) {
695         String result = "";
696
697
698         try {
699             List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getSpareField4, "1").eq(BsFormulaChildInfo::getProcessesCode, daParamCollection.getLocationCode()));
700             if(list.size()>0){
701                 String results = list.get(0).getResults();
702                 if(results!= null && !results.equals("") && results.equals("OK")){
703                     result = "21";
704                 }
705             }
706             /*Object recordDataDone = miloService.readFromOpcUa("PACK" + "." + daParamCollection.getLocationCode() + ".RecordDataDone").getValue();
707             if(ObjectUtil.isNotNull(recordDataDone)){
708                 result = recordDataDone.toString();
709             }*/
710         } catch (Exception e) {
711             throw new RuntimeException(e);
712         }
713         return AjaxResult.success(result);
714     }
715
716     @Override
717     public void enterWeighing(DaParamCollection daParamCollection) {
718         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
719         long timestampMillis = Instant.now().toEpochMilli();
720         ParentVO parentVO = new ParentVO();
721         ChildVO childVO = new ChildVO();
722         List<ChildVO> childVOList = new ArrayList<>();
723         childVO.setItemCode("PWD_PW");
724         childVO.setItemType("3");
725         childVO.setItemText("Pack重量值");
726         childVO.setItemValue(daParamCollection.getWeightValue());
727         childVO.setCheckTime(format.format(new Date()));
728         childVO.setCheckResult("1");
729         childVOList.add(childVO);
730         parentVO.setSiteCode("3983");
731         parentVO.setRecordId(""+timestampMillis);
732         parentVO.setStationCode("OP500");
733         parentVO.setProductNum(daParamCollection.getSfcCode());
734         parentVO.setTotalResult("1");
735         parentVO.setCheckList(childVOList);
736         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
737 //        try{
738 //            CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
739 //                logger.info("开始执行异步方法");
740 //                HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
741 //                System.out.println(execute.body());
742 //                logger.info("异步方法执行结束");
743 //                logger.info("称重异步方法{}",execute.body());
744 //            });
745 //        }catch (Exception e){
746 //            System.out.println(e.getMessage());
747 //        }
748         RestfulService.getWorkReportResultFeedback(daParamCollection.getSfcCode(),"OP500",format.format(new Date()));
749     }
750
751     @Override
752     public void manualWorkstationsAddBasicParameters(DaParamCollection daParamCollection) {
753         // 假设这是从数据库或其他地方获取的参数数据
754         Map<String, String> map = new HashMap<>();
755         map.put("GC", "南浔工厂");
756         map.put("CXBH", "Pack线");
757         map.put("SBBH", "设备001");
758         map.put("YGBH", SecurityUtils.getUsername());
759         map.put("GDBH", daParamCollection.getWorkOrderNo());
760         map.put("CPXH", daParamCollection.getProductCode());
761         map.put("INT", format.format(daParamCollection.getInboundTime()));
762         map.put("OUTT",format.format(new Date()));
763
764         map.forEach((key, value) -> {
765             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
766             daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
767             daCollectionParamConf.setCollectParameterId(key);
768             List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
769             DaParamCollection saveData = new DaParamCollection();
770             saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
771             saveData.setProductCode(daParamCollection.getProductCode());
772             saveData.setLocationCode(daParamCollection.getLocationCode());
773             saveData.setSfcCode(daParamCollection.getProductBarcode());
774             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
775             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
776             saveData.setCollectionTime(new Date());
777             saveData.setParamValue(value);
778             daParamCollectionMapper.insertDaParamCollection(saveData);
779         });
780     }
781
782     @Override
783     public void preInstallOut(DaParamCollection daParamCollection) {
784         //增加过站记录
785         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
786         daPassingStationCollection.setSfcCode(daParamCollection.getProductBarcode());
787         daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
788         daPassingStationCollection.setInboundTime(daParamCollection.getInboundTime());
789         daPassingStationCollection.setOutboundTime(new Date());
790         daPassingStationCollection.setCreateTime(new Date());
791         daPassingStationCollection.setOutRsSign("1");
792         boolean save = daPassingStationCollectionService.save(daPassingStationCollection);
793         //添加基础参数
794         this.manualWorkstationsAddBasicParameters(daParamCollection);
795     }
796
797 }