cl
2024-08-02 549c25d81575704403813abe2bdd3ee0f626bd46
提交 | 用户 | 时间
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());//模组码
549c25 374                 collection.setWorkOrderNo(daParamCollection.getWorkOrderNo());//工单号
b78728 375                 collection.setParamCode(list.get(i).getCollectParameterId());//参数编码
A 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     }
406     @Override
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()));
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);
A 568 //                if(childOne!=null){
569 //                    String operationType = childOne.getOperationType();
570 //                    if(operationType.equals("1")){
571 //                        childVO.setItemType("2");
572 //                    }else if(operationType.equals("2")){
573 //                        childVO.setItemType("1");
574 //                    }
575 //                }else {
576 //                    childVO.setItemType("3");
577 //                }
578                 if(paramConfOne!=null){
579                     childVO.setItemType(paramConfOne.getItemType());
580                     childVO.setItemText(paramConfOne.getCollectParameterName());
581                 }else {
582                     childVO.setItemType("3");
583                     childVO.setItemText("");
584                 }
585                 childVO.setItemValue(daParamCollection.getParamValue());
586
587                 if(daParamCollection.getParamValue().equals("1")){
588                     childVO.setCheckResult("1");
589                 }else if(daParamCollection.getParamValue().equals("2")){
590                     childVO.setCheckResult("0");
591                     parentVO.setTotalResult("0");
592                     totalResult = "1";
593                 }else {
594                     childVO.setCheckResult("1");
595                 }
596                 childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
597                 listChildVo.add(childVO);
598
599             }
600             parentVO.setCheckList(listChildVo);
601             try{
602                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
603                     logger.info("手动工位传工厂MES异步方法start,工位号{},入参{}",stationCode,parentVO.toString());
604                     HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
605                     logger.info("手动工位传工厂MES异步方法end工位号{},出参{}",stationCode,execute.body());
606
607                     DaParamCollectionTemp daParamCollectionTemp = new DaParamCollectionTemp();
608                     daParamCollectionTemp.setSfcCode(packID);
609                     daParamCollectionTemp.setLocationCode(stationCode);
610                     int i = daParamCollectionTempService.deleteDaParamCollectionTempBySfcCodeAndLocationCode(daParamCollectionTemp);
611                     logger.info("删除临时表数据条数{}-工位{}-pack码{}",i,stationCode,packID);
612 //                    List<Long> idsList = paramList.stream().map(DaParamCollectionTemp::getId).collect(Collectors.toList());
613 //                    Long[] array = idsList.toArray(new Long[0]);
614 //                    int i = daParamCollectionTempService.deleteDaParamCollectionTempByIds(array);
615 //                    logger.info("删除临时表数据条数{}-工位{}-pack码{}",i,stationCode,packID);
616                 });
617             }catch (Exception e){
618                 System.out.println(e.getMessage());
619             }
620 //            HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
621
622 //            System.out.println(execute.body());
623             System.out.println("-----------------------"+totalResult);
624             logger.info("结束人工工位推送工厂MES数据方法-pushGeelycvMesFeedback-工位{}-pack码{}",stationCode,packID);
625         }
626
627     }
628
629     @Override
630     public void automaticWorkstationPushGeelycvMesFeedback(String packID, String stationCode,List<DaParamCollection> paramList) {
631         logger.info("进入工位{}-工厂MES推送数据方法automaticWorkstationPushGeelycvMesFeedback",stationCode);
632         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
633         String totalResult = "0";
634         if(!paramList.isEmpty()){
635             logger.info("进入工位{}-拼数据",stationCode);
636             ParentVO parentVO = new ParentVO();
637             parentVO.setSiteCode("3983");
638             parentVO.setRecordId(UUID.randomUUID().toString());
639             parentVO.setStationCode(stationCode);
640             parentVO.setProductNum(packID);
641             parentVO.setTotalResult("1");
642             List<ChildVO> listChildVo = new ArrayList<>();
643
644             for (DaParamCollection daParamCollection : paramList) {
645                 ChildVO childVO = new ChildVO();
646                 childVO.setItemCode(daParamCollection.getParamCode());
647 //                BsFormulaChildInfo childOne = bsFormulaChildInfoService.getOne(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getParamCode, daParamCollection.getParamCode()));
648 //                DaCollectionParamConf paramConfOne = daCollectionParamConfService.getOne(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
649                 List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
650                 DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
651 //                if(childOne!=null){
652 //                    String operationType = childOne.getOperationType();
653 //                    if(operationType.equals("1")){
654 //                        childVO.setItemType("2");
655 //                    }else if(operationType.equals("2")){
656 //                        childVO.setItemType("1");
657 //                    }
658 //                }else {
659 //                    childVO.setItemType("3");
660 //                }
661                 if(paramConfOne!=null){
662                     childVO.setItemType(paramConfOne.getSpareField1());
663                     childVO.setItemText(paramConfOne.getCollectParameterName());
664                 }else {
665                     childVO.setItemType("3");
666                     childVO.setItemText("");
667                 }
668                 childVO.setItemValue(daParamCollection.getParamValue());
669
670                 if(daParamCollection.getParamValue().equals("1")){
671                     childVO.setCheckResult("1");
672                 }else if(daParamCollection.getParamValue().equals("2")){
673                     childVO.setCheckResult("0");
674                     parentVO.setTotalResult("0");
675                     totalResult = "1";
676                 }else {
677                     childVO.setCheckResult("1");
678                 }
679                 childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
680                 listChildVo.add(childVO);
681             }
682             parentVO.setCheckList(listChildVo);
683             logger.info("结束工位{}-拼数据",stationCode);
684             logger.info("进入工位{}-工厂MES推送数据方法HttpResponseSend",stationCode);
685             try{
686                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
687                     logger.info("开始执行异步方法");
688                     HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
689                     System.out.println(execute.body());
690                     logger.info("异步方法执行结束");
691                     logger.info("自动工位传工厂MES异步方法{}"+execute.body());
692                 });
693             }catch (Exception e){
694                 System.out.println(e.getMessage());
695             }
696 //            HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
697             logger.info("结束工位{}-工厂MES推送数据方法HttpResponseSend",stationCode);
698             System.out.println("-----------------------"+totalResult);
699         }
700         logger.info("结束工位{}-工厂MES推送数据方法automaticWorkstationPushGeelycvMesFeedback",stationCode);
701     }
702
703     @Override
704     public AjaxResult checkRecordDataDone(DaParamCollection daParamCollection) {
705         String result = "";
706
707
708         try {
709             List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getSpareField4, "1").eq(BsFormulaChildInfo::getProcessesCode, daParamCollection.getLocationCode()));
710             if(list.size()>0){
711                 String results = list.get(0).getResults();
712                 if(results!= null && !results.equals("") && results.equals("OK")){
713                     result = "21";
714                 }
715             }
716             /*Object recordDataDone = miloService.readFromOpcUa("PACK" + "." + daParamCollection.getLocationCode() + ".RecordDataDone").getValue();
717             if(ObjectUtil.isNotNull(recordDataDone)){
718                 result = recordDataDone.toString();
719             }*/
720         } catch (Exception e) {
721             throw new RuntimeException(e);
722         }
723         return AjaxResult.success(result);
724     }
725
726     @Override
727     public void enterWeighing(DaParamCollection daParamCollection) {
728         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
729         long timestampMillis = Instant.now().toEpochMilli();
730         ParentVO parentVO = new ParentVO();
731         ChildVO childVO = new ChildVO();
732         List<ChildVO> childVOList = new ArrayList<>();
733         childVO.setItemCode("PWD_PW");
734         childVO.setItemType("3");
735         childVO.setItemText("Pack重量值");
736         childVO.setItemValue(daParamCollection.getWeightValue());
737         childVO.setCheckTime(format.format(new Date()));
738         childVO.setCheckResult("1");
739         childVOList.add(childVO);
740         parentVO.setSiteCode("3983");
741         parentVO.setRecordId(""+timestampMillis);
742         parentVO.setStationCode("OP500");
743         parentVO.setProductNum(daParamCollection.getSfcCode());
744         parentVO.setTotalResult("1");
745         parentVO.setCheckList(childVOList);
746         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
747 //        try{
748 //            CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
749 //                logger.info("开始执行异步方法");
750 //                HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
751 //                System.out.println(execute.body());
752 //                logger.info("异步方法执行结束");
753 //                logger.info("称重异步方法{}",execute.body());
754 //            });
755 //        }catch (Exception e){
756 //            System.out.println(e.getMessage());
757 //        }
758         RestfulService.getWorkReportResultFeedback(daParamCollection.getSfcCode(),"OP500",format.format(new Date()));
759     }
760
761     @Override
762     public void manualWorkstationsAddBasicParameters(DaParamCollection daParamCollection) {
763         // 假设这是从数据库或其他地方获取的参数数据
764         Map<String, String> map = new HashMap<>();
765         map.put("GC", "南浔工厂");
766         map.put("CXBH", "Pack线");
767         map.put("SBBH", "设备001");
768         map.put("YGBH", SecurityUtils.getUsername());
769         map.put("GDBH", daParamCollection.getWorkOrderNo());
770         map.put("CPXH", daParamCollection.getProductCode());
771         map.put("INT", format.format(daParamCollection.getInboundTime()));
772         map.put("OUTT",format.format(new Date()));
773
774         map.forEach((key, value) -> {
775             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
776             daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
777             daCollectionParamConf.setCollectParameterId(key);
778             List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
779             DaParamCollection saveData = new DaParamCollection();
780             saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
781             saveData.setProductCode(daParamCollection.getProductCode());
782             saveData.setLocationCode(daParamCollection.getLocationCode());
783             saveData.setSfcCode(daParamCollection.getProductBarcode());
784             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
785             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
786             saveData.setCollectionTime(new Date());
787             saveData.setParamValue(value);
788             daParamCollectionMapper.insertDaParamCollection(saveData);
789         });
790     }
791
792     @Override
793     public void preInstallOut(DaParamCollection daParamCollection) {
794         //增加过站记录
795         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
796         daPassingStationCollection.setSfcCode(daParamCollection.getProductBarcode());
797         daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
798         daPassingStationCollection.setInboundTime(daParamCollection.getInboundTime());
799         daPassingStationCollection.setOutboundTime(new Date());
800         daPassingStationCollection.setCreateTime(new Date());
801         daPassingStationCollection.setOutRsSign("1");
802         boolean save = daPassingStationCollectionService.save(daPassingStationCollection);
803         //添加基础参数
804         this.manualWorkstationsAddBasicParameters(daParamCollection);
805     }
806
807 }