cl
2024-07-20 db97fb6ecff5d184cf3c7da2fcee65dec106f0af
提交 | 用户 | 时间
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异步方法");
9a5ab9 316                             String stationCode = "M1P100";//因为上层系统只支持6为,所有报工工位为M1P100
997e69 317                             String reportResult = RestfulService.getWorkReportResultFeedback(daParamCollection.getProductBarcode(), stationCode, format.format(new Date()));
0ca254 318                             JSONObject jsonObject = new JSONObject(reportResult);
A 319                             String code = jsonObject.getStr("code");
320                             if("success".equals(code)){
321                                 //如果成功,执行报工成功方法,修改是否报工为1,添加报工时间
ef58b9 322                                 omProductionOrdeInfoService.updateOrderByProductNum("1",daParamCollection.getProductBarcode(),daParamCollection.getLocationCode());
0ca254 323                             }else{
A 324                                 //解析工厂mes返回结果,如果失败,执行报工失败方法,修改是否报工为2,添加报工时间
ef58b9 325                                 omProductionOrdeInfoService.updateOrderByProductNum("2",daParamCollection.getProductBarcode(),daParamCollection.getLocationCode());
0ca254 326                             }
ef58b9 327                             logger.info("OP100报工结束-工厂MES异步方法{}"+reportResult);
0ca254 328                         });
A 329                     }catch (Exception e){
330                         System.out.println(e.getMessage());
331                     }
2de856 332
0ca254 333                 }
A 334
335
336             } catch (Exception e) {
337                 throw new RuntimeException(e);
338             }
339         }
340     }
341
2de856 342
C 343     //半自动工位,先将自动数据保存到数据库
344     public void saveParameters(DaParamCollection daParamCollection) {
345         //添加自动工位参数数据
346         //查询参数配置表
347         List<DaCollectionParamConf> list = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
348                 .eq(DaCollectionParamConf::getProcessesCode, daParamCollection.getLocationCode())//工位
349                 .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
350         );//类型
351
352         List<String> collectAddressList = list.stream()
353                 .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
354         List<ReadWriteEntity> paramCollectionList = null;//模组 参数值
355         try {
356             paramCollectionList = miloService.readFromOpcUa(collectAddressList);
357         } catch (Exception e) {
358             throw new RuntimeException(e);
359         }
360
361         if (CollUtil.isNotEmpty(paramCollectionList)) {
362             List<DaParamCollection> saveParamList = new ArrayList<>();//封装参数采集list
363             List<DaParamCollectionTemp> saveParamListTemp = new ArrayList<>();//封装参数采集list
364             for (int i = 0; i < paramCollectionList.size(); i++) {
365                 DaParamCollection collection = new DaParamCollection();
366                 collection.setSfcCode(daParamCollection.getProductBarcode());//模组码
367                 collection.setParamCode(list.get(i).getCollectParameterId());//参数编码
368                 collection.setParamName(list.get(i).getCollectParameterName());//参数名称
369                 String paramValue = "";
370                 if (ObjectUtil.isNotNull(paramCollectionList.get(i).getValue())) {
371                     paramValue = paramCollectionList.get(i).getValue().toString();//参数值
372                 }
373                 collection.setParamValue(paramValue);//参数值
374                 collection.setLocationCode(daParamCollection.getLocationCode());//工位
375                 collection.setCollectionTime(new Date());//采集时间
376                 saveParamList.add(collection);//封装参数采集list
377
378                 DaParamCollectionTemp collectionTemp = new DaParamCollectionTemp();
379                 collectionTemp.setSfcCode(daParamCollection.getProductBarcode());//模组码
380                 collectionTemp.setParamCode(list.get(i).getCollectParameterId());//参数编码
381                 collectionTemp.setParamName(list.get(i).getCollectParameterName());//参数名称
382
383                 if (ObjectUtil.isNotNull(paramCollectionList.get(i).getValue())) {
384                     paramValue = paramCollectionList.get(i).getValue().toString();//参数值
385                 }
386                 collectionTemp.setParamValue(paramValue);//参数值
387                 collectionTemp.setLocationCode(daParamCollection.getLocationCode());//工位
388                 collectionTemp.setCollectionTime(new Date());//采集时间
389                 saveParamListTemp.add(collectionTemp);//封装参数采集list
390
391             }
392             //插入参数采集表
393             daParamCollectionService.insertBatch(saveParamList);
394             //插入参数采集表
395             daParamCollectionTempService.insertBatch(saveParamListTemp);
396         }
397     }
0ca254 398     @Override
A 399     public void insertBatch(List<DaParamCollection> confList){
400         try{
401             this.saveBatch(confList);
402         }catch (Exception e){
403             return;
404         }
405
406     }
407
408     @Override
409     public void replaceAssemblyCode(DaParamCollection daParamCollection) {
410         List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>()
411                 .eq(DaParamCollection::getSfcCode, daParamCollection.getYzSfcCode())
412         );
413         if(list.size() > 0){
414             for (DaParamCollection paramCollection : list) {
415                 paramCollection.setSfcCode(daParamCollection.getSfcCode());
416                 daParamCollectionService.saveOrUpdate(paramCollection);
417             }
418         }
419
420     }
421
422     @Override
423     public void yzAddBasicParameters(DaParamCollection daParamCollection) {
424         // 假设这是从数据库或其他地方获取的参数数据
425         Map<String, String> map = new HashMap<>();
426 //        map.put("GC", "南浔工厂");
427 //        map.put("CXBH", "Pack线");
428 //        map.put("SBBH", "设备001");
429 //        map.put("YGBH", "员工001");
430 //        map.put("GDBH", daParamCollection.getWorkOrderNo());
431 //        map.put("CPXH", daParamCollection.getModel());
432         map.put("INT", DateUtil.formatDateTime(new Date()));
433
434         map.forEach((key, value) -> {
435             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
436             daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
437             daCollectionParamConf.setCollectParameterId(key);
438             List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
439             DaParamCollection saveData = new DaParamCollection();
440             saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
441             saveData.setProductCode(daParamCollection.getProductCode());
442             saveData.setLocationCode(daParamCollection.getLocationCode());
443             saveData.setSfcCode(daParamCollection.getProductBarcode());
444             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
445             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
446             saveData.setCollectionTime(new Date());
447             saveData.setParamValue(value);
448             daParamCollectionMapper.insertDaParamCollection(saveData);
449         });
450     }
451
452     @Override
453     public void jrmSaveCampaignTimeParameters(DaParamCollection daParamCollection) {
454         DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
455         daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
456         daCollectionParamConf.setCollectParameterId("OUTT");
457         List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
458         DaParamCollection saveData = new DaParamCollection();
459         saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
460         saveData.setProductCode(daParamCollection.getProductCode());
461         saveData.setLocationCode(daParamCollection.getLocationCode());
462         saveData.setSfcCode(daParamCollection.getProductBarcode());
463         saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
464         saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
465         saveData.setCollectionTime(new Date());
466         saveData.setParamValue(DateUtil.formatDateTime(new Date()));
467         daParamCollectionMapper.insertDaParamCollection(saveData);
468
469         //更新过站记录表出站时间
470         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
471         daPassingStationCollection.setWorkOrderNo(daParamCollection.getWorkOrderNo());
472         daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
473         List<DaPassingStationCollection> daPassingStationCollections = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection);
474         daPassingStationCollections.get(0).setOutboundTime(new Date());
475         int i = daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
476
477         try {
478             String strA = daParamCollection.getLocationCode();
479             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+strA+".RecordDataDone").value(21).build());
480         } catch (Exception e) {
481             throw new RuntimeException(e);
482         }
483     }
484
485
486     public void sendToFactoryMes(String stationCode,String productNum ){
487 //        String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
488         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
489         ParentVO vo =new ParentVO();
490         List<ChildVO> checkList = new ArrayList<>();
491         List<DaParamCollection> list = this.list(new LambdaQueryWrapper<DaParamCollection>()
492                 .eq(DaParamCollection::getSfcCode, productNum)
493                 .eq(DaParamCollection::getLocationCode, stationCode));
494         vo.setTotalResult("1");
495         String string = new Random(10).toString();
496         vo.setRecordId(string);
497         vo.setProductNum(productNum);
498         vo.setSiteCode("3983");
499         vo.setStationCode(stationCode);
500         if (CollUtil.isNotEmpty(list)){
501             List<DaParamCollection> collect = list.stream().filter(x -> Constants.NG.equals(x.getParamValue())).collect(Collectors.toList());
502             if (CollUtil.isNotEmpty(collect)){
503                 vo.setTotalResult("0");
504             }
505             List<BsFormulaChildInfo> bsFormulaChildInfoList = bsFormulaChildInfoService.list();
506             for (DaParamCollection daParamCollection : list) {
507                 ChildVO childVO = new ChildVO();
508                 childVO.setItemCode(daParamCollection.getParamCode());
509                 String time = daParamCollection.getCollectionTime() != null ? daParamCollection.getCollectionTime().toString() : "";
510                 childVO.setCheckResult("1");
511                 if (StrUtil.isNotBlank(daParamCollection.getParamValue())){
512                     if (Constants.NG.equals(daParamCollection.getParamValue())){
513                         childVO.setCheckResult("0");
514                     }
515                 }
516                 childVO.setCheckTime(time);
517                 childVO.setItemValue(daParamCollection.getParamValue());
518                 childVO.setItemType("3");
519                 childVO.setItemText(daParamCollection.getParamName());
520                 if (StrUtil.isNotBlank(daParamCollection.getParamCode())){
521                     List<BsFormulaChildInfo> collect1 = bsFormulaChildInfoList.stream().filter(x -> daParamCollection.getParamCode().equals(x.getParamCode())).collect(Collectors.toList());
522                     if (CollUtil.isNotEmpty(collect1)){
523                         BsFormulaChildInfo bsFormulaChildInfo = collect1.get(0);
524                         childVO.setItemType(bsFormulaChildInfo.getOperationType());
525                     }
526                 }
527
528                 checkList.add(childVO);
529             }
530         }
531         vo.setCheckList(checkList);
532         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(vo)).execute();
533
534     }
535
536     @Override
537     public void pushGeelycvMesFeedback(String packID, String stationCode) {
538         logger.info("进入人工工位推送工厂MES数据方法-pushGeelycvMesFeedback-工位{}-pack码{}",stationCode,packID);
539         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
540         String totalResult = "0";
541         List<DaParamCollectionTemp> paramList = daParamCollectionTempService.list(new LambdaQueryWrapper<DaParamCollectionTemp>().eq(DaParamCollectionTemp::getSfcCode, packID).eq(DaParamCollectionTemp::getLocationCode, stationCode));
542         if(paramList.size() > 0){
543             ParentVO parentVO = new ParentVO();
544             parentVO.setSiteCode("3983");
545             parentVO.setRecordId(String.valueOf(Instant.now().toEpochMilli()));
546             parentVO.setStationCode(stationCode);
547             parentVO.setProductNum(packID);
548             parentVO.setTotalResult("1");
549             List<ChildVO> listChildVo = new ArrayList<>();
550
551             for (DaParamCollectionTemp daParamCollection : paramList) {
552                 ChildVO childVO = new ChildVO();
553                 childVO.setItemCode(daParamCollection.getParamCode());
554 //                BsFormulaChildInfo childOne = bsFormulaChildInfoService.getOne(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getParamCode, daParamCollection.getParamCode()));
555 //                DaCollectionParamConf paramConfOne = daCollectionParamConfService.getOne(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
556                 List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
557                 DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
558 //                if(childOne!=null){
559 //                    String operationType = childOne.getOperationType();
560 //                    if(operationType.equals("1")){
561 //                        childVO.setItemType("2");
562 //                    }else if(operationType.equals("2")){
563 //                        childVO.setItemType("1");
564 //                    }
565 //                }else {
566 //                    childVO.setItemType("3");
567 //                }
568                 if(paramConfOne!=null){
9a5ab9 569                     childVO.setItemType(paramConfOne.getItemType());
0ca254 570                     childVO.setItemText(paramConfOne.getCollectParameterName());
A 571                 }else {
572                     childVO.setItemType("3");
573                     childVO.setItemText("");
574                 }
575                 childVO.setItemValue(daParamCollection.getParamValue());
576
577                 if(daParamCollection.getParamValue().equals("1")){
578                     childVO.setCheckResult("1");
579                 }else if(daParamCollection.getParamValue().equals("2")){
580                     childVO.setCheckResult("0");
581                     parentVO.setTotalResult("0");
582                     totalResult = "1";
583                 }else {
584                     childVO.setCheckResult("1");
585                 }
586                 childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
587                 listChildVo.add(childVO);
588
589             }
590             parentVO.setCheckList(listChildVo);
591             try{
592                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
88f7a9 593                     logger.info("手动工位传工厂MES异步方法start,工位号{},入参{}",stationCode,parentVO.toString());
971788 594                     HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
88f7a9 595                     logger.info("手动工位传工厂MES异步方法end工位号{},出参{}",stationCode,execute.body());
0ca254 596
A 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";
db97fb 624         if(!paramList.isEmpty()){
0ca254 625             logger.info("进入工位{}-拼数据",stationCode);
A 626             ParentVO parentVO = new ParentVO();
627             parentVO.setSiteCode("3983");
161650 628             parentVO.setRecordId(UUID.randomUUID().toString());
0ca254 629             parentVO.setStationCode(stationCode);
A 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 }