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