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