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