提交 | 用户 | 时间
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{
6a53e6 314                         //更新工单状态为已执行
C 315                         LambdaUpdateWrapper<OmProductionOrdeInfo> updateWrapper = new LambdaUpdateWrapper<>();
316                         updateWrapper.set(OmProductionOrdeInfo::getOrderStatus,"3");
317                         updateWrapper.eq(OmProductionOrdeInfo::getProductNum,daParamCollection.getProductBarcode());
318                         omProductionOrdeInfoService.update(new OmProductionOrdeInfo(),updateWrapper);
319
320                         //上传工厂MES报工
0ca254 321                         CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
ef58b9 322                             logger.info("OP100报工开始-工厂MES异步方法");
6a53e6 323                             String stationCode = "M1P100";//因为上层系统只支持6位,所有报工工位为M1P100
997e69 324                             String reportResult = RestfulService.getWorkReportResultFeedback(daParamCollection.getProductBarcode(), stationCode, format.format(new Date()));
0ca254 325                             JSONObject jsonObject = new JSONObject(reportResult);
A 326                             String code = jsonObject.getStr("code");
327                             if("success".equals(code)){
328                                 //如果成功,执行报工成功方法,修改是否报工为1,添加报工时间
ef58b9 329                                 omProductionOrdeInfoService.updateOrderByProductNum("1",daParamCollection.getProductBarcode(),daParamCollection.getLocationCode());
0ca254 330                             }else{
A 331                                 //解析工厂mes返回结果,如果失败,执行报工失败方法,修改是否报工为2,添加报工时间
ef58b9 332                                 omProductionOrdeInfoService.updateOrderByProductNum("2",daParamCollection.getProductBarcode(),daParamCollection.getLocationCode());
0ca254 333                             }
ef58b9 334                             logger.info("OP100报工结束-工厂MES异步方法{}"+reportResult);
0ca254 335                         });
A 336                     }catch (Exception e){
337                         System.out.println(e.getMessage());
338                     }
2de856 339
0ca254 340                 }
A 341
342
343             } catch (Exception e) {
344                 throw new RuntimeException(e);
345             }
346         }
347     }
348
2de856 349
C 350     //半自动工位,先将自动数据保存到数据库
351     public void saveParameters(DaParamCollection daParamCollection) {
352         //添加自动工位参数数据
353         //查询参数配置表
354         List<DaCollectionParamConf> list = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
355                 .eq(DaCollectionParamConf::getProcessesCode, daParamCollection.getLocationCode())//工位
356                 .eq(DaCollectionParamConf::getWhetherToCollect, Constants.ONE)//是否采集
357         );//类型
358
359         List<String> collectAddressList = list.stream()
360                 .map(DaCollectionParamConf::getGatherAddress).collect(Collectors.toList());
361         List<ReadWriteEntity> paramCollectionList = null;//模组 参数值
362         try {
363             paramCollectionList = miloService.readFromOpcUa(collectAddressList);
364         } catch (Exception e) {
365             throw new RuntimeException(e);
366         }
367
368         if (CollUtil.isNotEmpty(paramCollectionList)) {
369             List<DaParamCollection> saveParamList = new ArrayList<>();//封装参数采集list
370             List<DaParamCollectionTemp> saveParamListTemp = new ArrayList<>();//封装参数采集list
371             for (int i = 0; i < paramCollectionList.size(); i++) {
372                 DaParamCollection collection = new DaParamCollection();
373                 collection.setSfcCode(daParamCollection.getProductBarcode());//模组码
374                 collection.setParamCode(list.get(i).getCollectParameterId());//参数编码
375                 collection.setParamName(list.get(i).getCollectParameterName());//参数名称
376                 String paramValue = "";
377                 if (ObjectUtil.isNotNull(paramCollectionList.get(i).getValue())) {
378                     paramValue = paramCollectionList.get(i).getValue().toString();//参数值
379                 }
380                 collection.setParamValue(paramValue);//参数值
381                 collection.setLocationCode(daParamCollection.getLocationCode());//工位
382                 collection.setCollectionTime(new Date());//采集时间
383                 saveParamList.add(collection);//封装参数采集list
384
385                 DaParamCollectionTemp collectionTemp = new DaParamCollectionTemp();
386                 collectionTemp.setSfcCode(daParamCollection.getProductBarcode());//模组码
387                 collectionTemp.setParamCode(list.get(i).getCollectParameterId());//参数编码
388                 collectionTemp.setParamName(list.get(i).getCollectParameterName());//参数名称
389
390                 if (ObjectUtil.isNotNull(paramCollectionList.get(i).getValue())) {
391                     paramValue = paramCollectionList.get(i).getValue().toString();//参数值
392                 }
393                 collectionTemp.setParamValue(paramValue);//参数值
394                 collectionTemp.setLocationCode(daParamCollection.getLocationCode());//工位
395                 collectionTemp.setCollectionTime(new Date());//采集时间
396                 saveParamListTemp.add(collectionTemp);//封装参数采集list
397
398             }
399             //插入参数采集表
400             daParamCollectionService.insertBatch(saveParamList);
401             //插入参数采集表
402             daParamCollectionTempService.insertBatch(saveParamListTemp);
403         }
404     }
0ca254 405     @Override
A 406     public void insertBatch(List<DaParamCollection> confList){
407         try{
408             this.saveBatch(confList);
409         }catch (Exception e){
410             return;
411         }
412
413     }
414
415     @Override
416     public void replaceAssemblyCode(DaParamCollection daParamCollection) {
417         List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>()
418                 .eq(DaParamCollection::getSfcCode, daParamCollection.getYzSfcCode())
419         );
420         if(list.size() > 0){
421             for (DaParamCollection paramCollection : list) {
422                 paramCollection.setSfcCode(daParamCollection.getSfcCode());
423                 daParamCollectionService.saveOrUpdate(paramCollection);
424             }
425         }
426
427     }
428
429     @Override
430     public void yzAddBasicParameters(DaParamCollection daParamCollection) {
431         // 假设这是从数据库或其他地方获取的参数数据
432         Map<String, String> map = new HashMap<>();
433 //        map.put("GC", "南浔工厂");
434 //        map.put("CXBH", "Pack线");
435 //        map.put("SBBH", "设备001");
436 //        map.put("YGBH", "员工001");
437 //        map.put("GDBH", daParamCollection.getWorkOrderNo());
438 //        map.put("CPXH", daParamCollection.getModel());
439         map.put("INT", DateUtil.formatDateTime(new Date()));
440
441         map.forEach((key, value) -> {
442             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
443             daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
444             daCollectionParamConf.setCollectParameterId(key);
445             List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
446             DaParamCollection saveData = new DaParamCollection();
447             saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
448             saveData.setProductCode(daParamCollection.getProductCode());
449             saveData.setLocationCode(daParamCollection.getLocationCode());
450             saveData.setSfcCode(daParamCollection.getProductBarcode());
451             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
452             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
453             saveData.setCollectionTime(new Date());
454             saveData.setParamValue(value);
455             daParamCollectionMapper.insertDaParamCollection(saveData);
456         });
457     }
458
459     @Override
460     public void jrmSaveCampaignTimeParameters(DaParamCollection daParamCollection) {
461         DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
462         daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
463         daCollectionParamConf.setCollectParameterId("OUTT");
464         List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
465         DaParamCollection saveData = new DaParamCollection();
466         saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
467         saveData.setProductCode(daParamCollection.getProductCode());
468         saveData.setLocationCode(daParamCollection.getLocationCode());
469         saveData.setSfcCode(daParamCollection.getProductBarcode());
470         saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
471         saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
472         saveData.setCollectionTime(new Date());
473         saveData.setParamValue(DateUtil.formatDateTime(new Date()));
474         daParamCollectionMapper.insertDaParamCollection(saveData);
475
476         //更新过站记录表出站时间
477         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
478         daPassingStationCollection.setWorkOrderNo(daParamCollection.getWorkOrderNo());
479         daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
480         List<DaPassingStationCollection> daPassingStationCollections = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection);
481         daPassingStationCollections.get(0).setOutboundTime(new Date());
482         int i = daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
483
484         try {
485             String strA = daParamCollection.getLocationCode();
486             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+strA+".RecordDataDone").value(21).build());
487         } catch (Exception e) {
488             throw new RuntimeException(e);
489         }
490     }
491
492
493     public void sendToFactoryMes(String stationCode,String productNum ){
494 //        String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
495         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
496         ParentVO vo =new ParentVO();
497         List<ChildVO> checkList = new ArrayList<>();
498         List<DaParamCollection> list = this.list(new LambdaQueryWrapper<DaParamCollection>()
499                 .eq(DaParamCollection::getSfcCode, productNum)
500                 .eq(DaParamCollection::getLocationCode, stationCode));
501         vo.setTotalResult("1");
502         String string = new Random(10).toString();
503         vo.setRecordId(string);
504         vo.setProductNum(productNum);
505         vo.setSiteCode("3983");
506         vo.setStationCode(stationCode);
507         if (CollUtil.isNotEmpty(list)){
508             List<DaParamCollection> collect = list.stream().filter(x -> Constants.NG.equals(x.getParamValue())).collect(Collectors.toList());
509             if (CollUtil.isNotEmpty(collect)){
510                 vo.setTotalResult("0");
511             }
512             List<BsFormulaChildInfo> bsFormulaChildInfoList = bsFormulaChildInfoService.list();
513             for (DaParamCollection daParamCollection : list) {
514                 ChildVO childVO = new ChildVO();
515                 childVO.setItemCode(daParamCollection.getParamCode());
516                 String time = daParamCollection.getCollectionTime() != null ? daParamCollection.getCollectionTime().toString() : "";
517                 childVO.setCheckResult("1");
518                 if (StrUtil.isNotBlank(daParamCollection.getParamValue())){
519                     if (Constants.NG.equals(daParamCollection.getParamValue())){
520                         childVO.setCheckResult("0");
521                     }
522                 }
523                 childVO.setCheckTime(time);
524                 childVO.setItemValue(daParamCollection.getParamValue());
525                 childVO.setItemType("3");
526                 childVO.setItemText(daParamCollection.getParamName());
527                 if (StrUtil.isNotBlank(daParamCollection.getParamCode())){
528                     List<BsFormulaChildInfo> collect1 = bsFormulaChildInfoList.stream().filter(x -> daParamCollection.getParamCode().equals(x.getParamCode())).collect(Collectors.toList());
529                     if (CollUtil.isNotEmpty(collect1)){
530                         BsFormulaChildInfo bsFormulaChildInfo = collect1.get(0);
531                         childVO.setItemType(bsFormulaChildInfo.getOperationType());
532                     }
533                 }
534
535                 checkList.add(childVO);
536             }
537         }
538         vo.setCheckList(checkList);
539         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(vo)).execute();
540
541     }
542
543     @Override
544     public void pushGeelycvMesFeedback(String packID, String stationCode) {
545         logger.info("进入人工工位推送工厂MES数据方法-pushGeelycvMesFeedback-工位{}-pack码{}",stationCode,packID);
546         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
547         String totalResult = "0";
548         List<DaParamCollectionTemp> paramList = daParamCollectionTempService.list(new LambdaQueryWrapper<DaParamCollectionTemp>().eq(DaParamCollectionTemp::getSfcCode, packID).eq(DaParamCollectionTemp::getLocationCode, stationCode));
549         if(paramList.size() > 0){
550             ParentVO parentVO = new ParentVO();
551             parentVO.setSiteCode("3983");
552             parentVO.setRecordId(String.valueOf(Instant.now().toEpochMilli()));
553             parentVO.setStationCode(stationCode);
554             parentVO.setProductNum(packID);
555             parentVO.setTotalResult("1");
556             List<ChildVO> listChildVo = new ArrayList<>();
557
558             for (DaParamCollectionTemp daParamCollection : paramList) {
559                 ChildVO childVO = new ChildVO();
560                 childVO.setItemCode(daParamCollection.getParamCode());
561 //                BsFormulaChildInfo childOne = bsFormulaChildInfoService.getOne(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getParamCode, daParamCollection.getParamCode()));
562 //                DaCollectionParamConf paramConfOne = daCollectionParamConfService.getOne(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
563                 List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
564                 DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
565 //                if(childOne!=null){
566 //                    String operationType = childOne.getOperationType();
567 //                    if(operationType.equals("1")){
568 //                        childVO.setItemType("2");
569 //                    }else if(operationType.equals("2")){
570 //                        childVO.setItemType("1");
571 //                    }
572 //                }else {
573 //                    childVO.setItemType("3");
574 //                }
575                 if(paramConfOne!=null){
9a5ab9 576                     childVO.setItemType(paramConfOne.getItemType());
0ca254 577                     childVO.setItemText(paramConfOne.getCollectParameterName());
A 578                 }else {
579                     childVO.setItemType("3");
580                     childVO.setItemText("");
581                 }
582                 childVO.setItemValue(daParamCollection.getParamValue());
583
584                 if(daParamCollection.getParamValue().equals("1")){
585                     childVO.setCheckResult("1");
586                 }else if(daParamCollection.getParamValue().equals("2")){
587                     childVO.setCheckResult("0");
588                     parentVO.setTotalResult("0");
589                     totalResult = "1";
590                 }else {
591                     childVO.setCheckResult("1");
592                 }
593                 childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
594                 listChildVo.add(childVO);
595
596             }
597             parentVO.setCheckList(listChildVo);
598             try{
599                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
88f7a9 600                     logger.info("手动工位传工厂MES异步方法start,工位号{},入参{}",stationCode,parentVO.toString());
971788 601                     HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
88f7a9 602                     logger.info("手动工位传工厂MES异步方法end工位号{},出参{}",stationCode,execute.body());
0ca254 603
A 604                     DaParamCollectionTemp daParamCollectionTemp = new DaParamCollectionTemp();
605                     daParamCollectionTemp.setSfcCode(packID);
606                     daParamCollectionTemp.setLocationCode(stationCode);
607                     int i = daParamCollectionTempService.deleteDaParamCollectionTempBySfcCodeAndLocationCode(daParamCollectionTemp);
608                     logger.info("删除临时表数据条数{}-工位{}-pack码{}",i,stationCode,packID);
609 //                    List<Long> idsList = paramList.stream().map(DaParamCollectionTemp::getId).collect(Collectors.toList());
610 //                    Long[] array = idsList.toArray(new Long[0]);
611 //                    int i = daParamCollectionTempService.deleteDaParamCollectionTempByIds(array);
612 //                    logger.info("删除临时表数据条数{}-工位{}-pack码{}",i,stationCode,packID);
613                 });
614             }catch (Exception e){
615                 System.out.println(e.getMessage());
616             }
617 //            HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
618
619 //            System.out.println(execute.body());
620             System.out.println("-----------------------"+totalResult);
621             logger.info("结束人工工位推送工厂MES数据方法-pushGeelycvMesFeedback-工位{}-pack码{}",stationCode,packID);
622         }
623
624     }
625
626     @Override
627     public void automaticWorkstationPushGeelycvMesFeedback(String packID, String stationCode,List<DaParamCollection> paramList) {
628         logger.info("进入工位{}-工厂MES推送数据方法automaticWorkstationPushGeelycvMesFeedback",stationCode);
629         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
630         String totalResult = "0";
db97fb 631         if(!paramList.isEmpty()){
0ca254 632             logger.info("进入工位{}-拼数据",stationCode);
A 633             ParentVO parentVO = new ParentVO();
634             parentVO.setSiteCode("3983");
161650 635             parentVO.setRecordId(UUID.randomUUID().toString());
0ca254 636             parentVO.setStationCode(stationCode);
A 637             parentVO.setProductNum(packID);
638             parentVO.setTotalResult("1");
639             List<ChildVO> listChildVo = new ArrayList<>();
640
641             for (DaParamCollection daParamCollection : paramList) {
642                 ChildVO childVO = new ChildVO();
643                 childVO.setItemCode(daParamCollection.getParamCode());
644 //                BsFormulaChildInfo childOne = bsFormulaChildInfoService.getOne(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getParamCode, daParamCollection.getParamCode()));
645 //                DaCollectionParamConf paramConfOne = daCollectionParamConfService.getOne(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
646                 List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
647                 DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
648 //                if(childOne!=null){
649 //                    String operationType = childOne.getOperationType();
650 //                    if(operationType.equals("1")){
651 //                        childVO.setItemType("2");
652 //                    }else if(operationType.equals("2")){
653 //                        childVO.setItemType("1");
654 //                    }
655 //                }else {
656 //                    childVO.setItemType("3");
657 //                }
658                 if(paramConfOne!=null){
659                     childVO.setItemType(paramConfOne.getSpareField1());
660                     childVO.setItemText(paramConfOne.getCollectParameterName());
661                 }else {
662                     childVO.setItemType("3");
663                     childVO.setItemText("");
664                 }
665                 childVO.setItemValue(daParamCollection.getParamValue());
666
667                 if(daParamCollection.getParamValue().equals("1")){
668                     childVO.setCheckResult("1");
669                 }else if(daParamCollection.getParamValue().equals("2")){
670                     childVO.setCheckResult("0");
671                     parentVO.setTotalResult("0");
672                     totalResult = "1";
673                 }else {
674                     childVO.setCheckResult("1");
675                 }
676                 childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
677                 listChildVo.add(childVO);
678             }
679             parentVO.setCheckList(listChildVo);
680             logger.info("结束工位{}-拼数据",stationCode);
681             logger.info("进入工位{}-工厂MES推送数据方法HttpResponseSend",stationCode);
682             try{
683                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
684                     logger.info("开始执行异步方法");
971788 685                     HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
0ca254 686                     System.out.println(execute.body());
A 687                     logger.info("异步方法执行结束");
688                     logger.info("自动工位传工厂MES异步方法{}"+execute.body());
689                 });
690             }catch (Exception e){
691                 System.out.println(e.getMessage());
692             }
693 //            HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
694             logger.info("结束工位{}-工厂MES推送数据方法HttpResponseSend",stationCode);
695             System.out.println("-----------------------"+totalResult);
696         }
697         logger.info("结束工位{}-工厂MES推送数据方法automaticWorkstationPushGeelycvMesFeedback",stationCode);
698     }
699
700     @Override
701     public AjaxResult checkRecordDataDone(DaParamCollection daParamCollection) {
702         String result = "";
703
704
705         try {
706             List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getSpareField4, "1").eq(BsFormulaChildInfo::getProcessesCode, daParamCollection.getLocationCode()));
707             if(list.size()>0){
708                 String results = list.get(0).getResults();
709                 if(results!= null && !results.equals("") && results.equals("OK")){
710                     result = "21";
711                 }
712             }
713             /*Object recordDataDone = miloService.readFromOpcUa("PACK" + "." + daParamCollection.getLocationCode() + ".RecordDataDone").getValue();
714             if(ObjectUtil.isNotNull(recordDataDone)){
715                 result = recordDataDone.toString();
716             }*/
717         } catch (Exception e) {
718             throw new RuntimeException(e);
719         }
720         return AjaxResult.success(result);
721     }
722
723     @Override
724     public void enterWeighing(DaParamCollection daParamCollection) {
725         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
726         long timestampMillis = Instant.now().toEpochMilli();
727         ParentVO parentVO = new ParentVO();
728         ChildVO childVO = new ChildVO();
729         List<ChildVO> childVOList = new ArrayList<>();
730         childVO.setItemCode("PWD_PW");
731         childVO.setItemType("3");
732         childVO.setItemText("Pack重量值");
733         childVO.setItemValue(daParamCollection.getWeightValue());
734         childVO.setCheckTime(format.format(new Date()));
735         childVO.setCheckResult("1");
736         childVOList.add(childVO);
737         parentVO.setSiteCode("3983");
738         parentVO.setRecordId(""+timestampMillis);
739         parentVO.setStationCode("OP500");
740         parentVO.setProductNum(daParamCollection.getSfcCode());
741         parentVO.setTotalResult("1");
742         parentVO.setCheckList(childVOList);
743         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
744 //        try{
745 //            CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
746 //                logger.info("开始执行异步方法");
747 //                HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
748 //                System.out.println(execute.body());
749 //                logger.info("异步方法执行结束");
750 //                logger.info("称重异步方法{}",execute.body());
751 //            });
752 //        }catch (Exception e){
753 //            System.out.println(e.getMessage());
754 //        }
755         RestfulService.getWorkReportResultFeedback(daParamCollection.getSfcCode(),"OP500",format.format(new Date()));
756     }
757
758     @Override
759     public void manualWorkstationsAddBasicParameters(DaParamCollection daParamCollection) {
760         // 假设这是从数据库或其他地方获取的参数数据
761         Map<String, String> map = new HashMap<>();
762         map.put("GC", "南浔工厂");
763         map.put("CXBH", "Pack线");
764         map.put("SBBH", "设备001");
765         map.put("YGBH", SecurityUtils.getUsername());
766         map.put("GDBH", daParamCollection.getWorkOrderNo());
767         map.put("CPXH", daParamCollection.getProductCode());
768         map.put("INT", format.format(daParamCollection.getInboundTime()));
769         map.put("OUTT",format.format(new Date()));
770
771         map.forEach((key, value) -> {
772             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
773             daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
774             daCollectionParamConf.setCollectParameterId(key);
775             List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
776             DaParamCollection saveData = new DaParamCollection();
777             saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
778             saveData.setProductCode(daParamCollection.getProductCode());
779             saveData.setLocationCode(daParamCollection.getLocationCode());
780             saveData.setSfcCode(daParamCollection.getProductBarcode());
781             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
782             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
783             saveData.setCollectionTime(new Date());
784             saveData.setParamValue(value);
785             daParamCollectionMapper.insertDaParamCollection(saveData);
786         });
787     }
788
789     @Override
790     public void preInstallOut(DaParamCollection daParamCollection) {
791         //增加过站记录
792         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
793         daPassingStationCollection.setSfcCode(daParamCollection.getProductBarcode());
794         daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
795         daPassingStationCollection.setInboundTime(daParamCollection.getInboundTime());
796         daPassingStationCollection.setOutboundTime(new Date());
797         daPassingStationCollection.setCreateTime(new Date());
798         daPassingStationCollection.setOutRsSign("1");
799         boolean save = daPassingStationCollectionService.save(daPassingStationCollection);
800         //添加基础参数
801         this.manualWorkstationsAddBasicParameters(daParamCollection);
802     }
803
804 }