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