admin
6 天以前 768498719683f85e5ed19c73eb3d14cdbf420df4
提交 | 用户 | 时间
e57a89 1 package com.jcdm.main.da.paramCollection.service.impl;
2
6a462f 3 import cn.hutool.core.collection.CollUtil;
b64ed2 4 import cn.hutool.core.date.DateUtil;
237733 5 import cn.hutool.core.util.ObjectUtil;
6a462f 6 import cn.hutool.core.util.StrUtil;
8f0f8d 7 import cn.hutool.db.Db;
6a462f 8 import cn.hutool.http.HttpRequest;
W 9 import cn.hutool.http.HttpResponse;
768498 10 import cn.hutool.json.JSONObject;
6a462f 11 import cn.hutool.json.JSONUtil;
7bee80 12 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
768498 13 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
0ce25f 14 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
237733 15 import com.jcdm.common.core.domain.AjaxResult;
e57a89 16 import com.jcdm.common.utils.DateUtils;
768498 17 import com.jcdm.common.utils.SecurityUtils;
a60fef 18 import com.jcdm.common.utils.StringUtils;
7bee80 19 import com.jcdm.main.bs.formula.service.IBsFormulaInfoService;
20 import com.jcdm.main.bs.formula.service.impl.BsFormulaInfoServiceImpl;
b77c7b 21 import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo;
22 import com.jcdm.main.bs.formulaChild.mapper.BsFormulaChildInfoMapper;
7bee80 23 import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService;
6a462f 24 import com.jcdm.main.constant.Constants;
b64ed2 25 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
26 import com.jcdm.main.da.collectionParamConf.mapper.DaCollectionParamConfMapper;
5966d6 27 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
e57a89 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;
8cfe20 31 import com.jcdm.main.da.paramCollectionTemp.domain.DaParamCollectionTemp;
A 32 import com.jcdm.main.da.paramCollectionTemp.service.IDaParamCollectionTempService;
32483a 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;
768498 36 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
2fbce7 37 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
054a69 38 import com.jcdm.main.plcserver.sub.OPCUaSubscription;
237733 39 import com.jcdm.main.restful.factoryMes.service.RestfulService;
6a462f 40 import com.jcdm.main.restful.qingYan.doman.ChildVO;
W 41 import com.jcdm.main.restful.qingYan.doman.ParentVO;
32483a 42 import com.kangaroohy.milo.model.ReadWriteEntity;
43 import com.kangaroohy.milo.service.MiloService;
bdb404 44 import lombok.extern.slf4j.Slf4j;
054a69 45 import org.apache.ibatis.session.ExecutorType;
46 import org.apache.ibatis.session.SqlSession;
47 import org.apache.ibatis.session.SqlSessionFactory;
bdb404 48 import org.slf4j.Logger;
A 49 import org.slf4j.LoggerFactory;
e57a89 50 import org.springframework.beans.factory.annotation.Autowired;
5966d6 51 import org.springframework.security.core.parameters.P;
e57a89 52 import org.springframework.stereotype.Service;
53
054a69 54 import javax.annotation.Resource;
5966d6 55 import java.text.SimpleDateFormat;
A 56 import java.time.Instant;
b64ed2 57 import java.util.*;
d76bba 58 import java.util.concurrent.CompletableFuture;
6a462f 59 import java.util.stream.Collectors;
e57a89 60
61 /**
62  * 设备产品过程参数采集Service业务层处理
63  * 
64  * @author yyt
65  * @date 2023-12-13
66  */
bdb404 67 @Slf4j
e57a89 68 @Service
0ce25f 69 public class DaParamCollectionServiceImpl extends ServiceImpl<DaParamCollectionMapper,DaParamCollection> implements IDaParamCollectionService
e57a89 70 {
bdb404 71     private static final Logger logger = LoggerFactory.getLogger("sys-user");
A 72
e57a89 73     @Autowired
74     private DaParamCollectionMapper daParamCollectionMapper;
b64ed2 75
76     @Autowired
77     private DaCollectionParamConfMapper daCollectionParamConfMapper;
b77c7b 78
79     @Autowired
80     private BsFormulaChildInfoMapper bsFormulaChildInfoMapper;
7bee80 81
82     @Autowired
83     private IBsFormulaChildInfoService bsFormulaChildInfoService;
32483a 84
85     @Autowired
86     private MiloService miloService;
87
88     @Autowired
89     private DaPassingStationCollectionMapper daPassingStationCollectionMapper;
e57a89 90
054a69 91     @Resource
92     private SqlSessionFactory sqlSessionFactory;
93
ddb300 94     @Autowired
A 95     private IDaParamCollectionService daParamCollectionService;
5966d6 96
A 97     @Autowired
98     private IDaCollectionParamConfService daCollectionParamConfService;
8cfe20 99
A 100     @Autowired
101     private IDaParamCollectionTempService daParamCollectionTempService;
2fbce7 102
A 103     @Autowired
104     private IOmProductionOrdeInfoService omProductionOrdeInfoService;
768498 105
A 106     @Autowired
107     private IDaPassingStationCollectionService daPassingStationCollectionService;
237733 108
A 109     public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ddb300 110
e57a89 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);
054a69 133     }
134
135     @Override
136     public void saveBeachDaParamCollection(List<DaParamCollection> list) {
137         // ExecutorType.SIMPLE: 这个执行器类型不做特殊的事情。它为每个语句的执行创建一个新的预处理语句。
138         // ExecutorType.REUSE: 这个执行器类型会复用预处理语句。
139         // ExecutorType.BATCH: 这个执行器会批量执行所有更新语句,如果 SELECT 在它们中间执行还会标定它们是 必须的,来保证一个简单并易于理解的行为。
bdb404 140         logger.info("进入乐工批量方法saveBeachDaParamCollection");
054a69 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();
bdb404 150             logger.info("结束乐工批量方法saveBeachDaParamCollection");
A 151
054a69 152         } catch (Exception e) {
153             sqlSession.rollback();
154         } finally {
155             sqlSession.close();
156         }
e57a89 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     }
b64ed2 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());
3c2299 230             saveData.setSfcCode(daParamCollection.getProductBarcode());
b64ed2 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     }
49c784 238
239     @Override
240     public void addTighteningParameters(DaParamCollection daParamCollection) {
b77c7b 241         String paramCode = daParamCollection.getParamCode();
a60fef 242         String tightenData = daParamCollection.getTightenTheArray();
A 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);
8cfe20 253
A 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());
d76bba 260                 daParamCollectionTemp.setProductCode(daParamCollection.getProductCode());
8cfe20 261                 daParamCollectionTempService.save(daParamCollectionTemp);
a60fef 262             }
b77c7b 263         }
49c784 264     }
32483a 265
266     @Override
267     public void saveCampaignTimeParameters(DaParamCollection daParamCollection) {
768498 268 //        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
A 269 //                .eq(BsFormulaChildInfo::getProcessesCode, daParamCollection.getLocationCode())
270 //                .eq(BsFormulaChildInfo::getSpareField4, "1")
271 //        );
272         BsFormulaChildInfo childInfo = daParamCollection.getFormulaChildEntity();
273         if(StringUtils.isNotBlank(childInfo.getResults())){
274             if(!childInfo.getResults().equals("OK")){
237733 275                 try {
A 276                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(22).build());
277                 } catch (Exception e) {
278                     throw new RuntimeException(e);
279                 }
280                 return;
281             }
282         }else {
7bee80 283             try {
284                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(22).build());
285             } catch (Exception e) {
286                 throw new RuntimeException(e);
287             }
288             return;
289         }
768498 290 //        BsFormulaChildInfo bsFormulaChildInfo = new BsFormulaChildInfo();
A 291 //        bsFormulaChildInfo.setProcessesCode(daParamCollection.getLocationCode());
292 //        bsFormulaChildInfo.setProductCode(daParamCollection.getProductCode());
293 //        bsFormulaChildInfo.setSpareField4("1");
294 //        List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(bsFormulaChildInfo);
295         String result = childInfo.getResults();
32483a 296         if(result != null && !result.isEmpty()){
297             try {
768498 298 //                //更新参数采集配置表
A 299 //                DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
300 //                daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
301 //                daCollectionParamConf.setCollectParameterId("OUTT");
302 //                List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
303 //                DaParamCollection saveData = new DaParamCollection();
304 //                saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
305 //                saveData.setProductCode(daParamCollection.getProductCode());
306 //                saveData.setLocationCode(daParamCollection.getLocationCode());
307 //                saveData.setSfcCode(daParamCollection.getProductBarcode());
308 //                saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
309 //                saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
310 //                saveData.setCollectionTime(new Date());
311 //                saveData.setParamValue(DateUtil.formatDateTime(new Date()));
312 //                daParamCollectionMapper.insertDaParamCollection(saveData);
32483a 313
768498 314                 //增加过站记录
32483a 315                 DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
316                 daPassingStationCollection.setWorkOrderNo(daParamCollection.getWorkOrderNo());
768498 317                 daPassingStationCollection.setSfcCode(daParamCollection.getProductBarcode());
A 318                 daPassingStationCollection.setProductCode(daParamCollection.getProductCode());
1df825 319                 daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
768498 320                 daPassingStationCollection.setInboundTime(daParamCollection.getInboundTime());
A 321                 daPassingStationCollection.setOutboundTime(new Date());
322                 daPassingStationCollection.setCreateTime(new Date());
323                 daPassingStationCollection.setOutRsSign("1");
324                 boolean save = daPassingStationCollectionService.save(daPassingStationCollection);
325
326                 //添加基础参数
327                 this.manualWorkstationsAddBasicParameters(daParamCollection);
328
329 //                //更新过站记录表出站时间
330 //                DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
331 //                daPassingStationCollection.setWorkOrderNo(daParamCollection.getWorkOrderNo());
332 //                daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
333 //                List<DaPassingStationCollection> daPassingStationCollections = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection);
334 //                daPassingStationCollections.get(0).setOutboundTime(new Date());
335 //                int i = daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
32483a 336
8f0f8d 337 //                OPCUaSubscription.SaveParamData(daParamCollection.getProductBarcode(),"OP",daParamCollection.getLocationCode(),daParamCollection.getWorkOrderNo(),daParamCollection.getProductCode());
054a69 338
32483a 339                 //给opc发21
7bee80 340                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(21).build());
237733 341                 if(daParamCollection.getLocationCode().equals("OP240")){
2fbce7 342                     try{
A 343                         CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
344                             logger.info("OP230报工开始-工厂MES异步方法");
345                             String reportResult = RestfulService.getWorkReportResultFeedback(daParamCollection.getProductBarcode(), "OP230", format.format(new Date()));
768498 346                             JSONObject jsonObject = new JSONObject(reportResult);
A 347                             String code = jsonObject.getStr("code");
348                             if("success".equals(code)){
349                                 //如果成功,执行报工成功方法,修改是否报工为1,添加报工时间
350                                 omProductionOrdeInfoService.updateOrderByProductNum("1",daParamCollection.getProductBarcode(),"OP230");
2fbce7 351                             }else{
A 352                                 //解析工厂mes返回结果,如果失败,执行报工失败方法,修改是否报工为2,添加报工时间
768498 353                                 omProductionOrdeInfoService.updateOrderByProductNum("2",daParamCollection.getProductBarcode(),"OP230");
2fbce7 354                             }
A 355                             logger.info("OP230报工结束-工厂MES异步方法{}"+reportResult);
356                         });
357                     }catch (Exception e){
358                         System.out.println(e.getMessage());
359                     }
360 //                    RestfulService.getWorkReportResultFeedback(daParamCollection.getProductBarcode(),"OP230",format.format(new Date()));
237733 361                 }
2fbce7 362
A 363
32483a 364             } catch (Exception e) {
365                 throw new RuntimeException(e);
366             }
367         }
368     }
8f0f8d 369
370     @Override
371     public void insertBatch(List<DaParamCollection> confList){
372         try{
373             this.saveBatch(confList);
374         }catch (Exception e){
375             return;
376         }
377
378     }
ddb300 379
A 380     @Override
381     public void replaceAssemblyCode(DaParamCollection daParamCollection) {
382         List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>()
2c7661 383                 .eq(DaParamCollection::getSfcCode, daParamCollection.getYzSfcCode())
ddb300 384         );
A 385         if(list.size() > 0){
386             for (DaParamCollection paramCollection : list) {
2c7661 387                 paramCollection.setSfcCode(daParamCollection.getSfcCode());
ddb300 388                 daParamCollectionService.saveOrUpdate(paramCollection);
A 389             }
390         }
391
392     }
4a5f2a 393
A 394     @Override
395     public void yzAddBasicParameters(DaParamCollection daParamCollection) {
396         // 假设这是从数据库或其他地方获取的参数数据
397         Map<String, String> map = new HashMap<>();
398 //        map.put("GC", "南浔工厂");
399 //        map.put("CXBH", "Pack线");
400 //        map.put("SBBH", "设备001");
401 //        map.put("YGBH", "员工001");
402 //        map.put("GDBH", daParamCollection.getWorkOrderNo());
403 //        map.put("CPXH", daParamCollection.getModel());
404         map.put("INT", DateUtil.formatDateTime(new Date()));
405
406         map.forEach((key, value) -> {
407             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
408             daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
409             daCollectionParamConf.setCollectParameterId(key);
410             List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
411             DaParamCollection saveData = new DaParamCollection();
412             saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
413             saveData.setProductCode(daParamCollection.getProductCode());
414             saveData.setLocationCode(daParamCollection.getLocationCode());
415             saveData.setSfcCode(daParamCollection.getProductBarcode());
416             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
417             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
418             saveData.setCollectionTime(new Date());
419             saveData.setParamValue(value);
420             daParamCollectionMapper.insertDaParamCollection(saveData);
421         });
422     }
1c84ae 423
A 424     @Override
425     public void jrmSaveCampaignTimeParameters(DaParamCollection daParamCollection) {
426         DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
427         daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
428         daCollectionParamConf.setCollectParameterId("OUTT");
429         List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
430         DaParamCollection saveData = new DaParamCollection();
431         saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
432         saveData.setProductCode(daParamCollection.getProductCode());
433         saveData.setLocationCode(daParamCollection.getLocationCode());
434         saveData.setSfcCode(daParamCollection.getProductBarcode());
435         saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
436         saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
437         saveData.setCollectionTime(new Date());
438         saveData.setParamValue(DateUtil.formatDateTime(new Date()));
439         daParamCollectionMapper.insertDaParamCollection(saveData);
440
441         //更新过站记录表出站时间
442         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
443         daPassingStationCollection.setWorkOrderNo(daParamCollection.getWorkOrderNo());
444         daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
445         List<DaPassingStationCollection> daPassingStationCollections = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection);
446         daPassingStationCollections.get(0).setOutboundTime(new Date());
447         int i = daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
448
449 //                OPCUaSubscription.SaveParamData(daParamCollection.getProductBarcode(),"OP",daParamCollection.getLocationCode(),daParamCollection.getWorkOrderNo(),daParamCollection.getProductCode());
450
451         //给opc发21
452         try {
453 //            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(21).build());
1ccd69 454             String strA = daParamCollection.getLocationCode();
1c84ae 455             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+strA+".RecordDataDone").value(21).build());
A 456         } catch (Exception e) {
457             throw new RuntimeException(e);
458         }
459     }
6a462f 460
W 461
462     public void sendToFactoryMes(String stationCode,String productNum ){
a846f2 463 //        String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
A 464         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
6a462f 465         ParentVO vo =new ParentVO();
W 466         List<ChildVO> checkList = new ArrayList<>();
467         List<DaParamCollection> list = this.list(new LambdaQueryWrapper<DaParamCollection>()
468                 .eq(DaParamCollection::getSfcCode, productNum)
469                 .eq(DaParamCollection::getLocationCode, stationCode));
470         vo.setTotalResult("1");
471         String string = new Random(10).toString();
472         vo.setRecordId(string);
473         vo.setProductNum(productNum);
474         vo.setSiteCode("3983");
475         vo.setStationCode(stationCode);
476         if (CollUtil.isNotEmpty(list)){
477             List<DaParamCollection> collect = list.stream().filter(x -> Constants.NG.equals(x.getParamValue())).collect(Collectors.toList());
478             if (CollUtil.isNotEmpty(collect)){
479                 vo.setTotalResult("0");
480             }
481             List<BsFormulaChildInfo> bsFormulaChildInfoList = bsFormulaChildInfoService.list();
482             for (DaParamCollection daParamCollection : list) {
483                 ChildVO childVO = new ChildVO();
484                 childVO.setItemCode(daParamCollection.getParamCode());
485                 String time = daParamCollection.getCollectionTime() != null ? daParamCollection.getCollectionTime().toString() : "";
486                 childVO.setCheckResult("1");
487                 if (StrUtil.isNotBlank(daParamCollection.getParamValue())){
488                     if (Constants.NG.equals(daParamCollection.getParamValue())){
489                         childVO.setCheckResult("0");
490                     }
491                 }
492                 childVO.setCheckTime(time);
493                 childVO.setItemValue(daParamCollection.getParamValue());
494                 childVO.setItemType("3");
495                 childVO.setItemText(daParamCollection.getParamName());
496                 if (StrUtil.isNotBlank(daParamCollection.getParamCode())){
497                     List<BsFormulaChildInfo> collect1 = bsFormulaChildInfoList.stream().filter(x -> daParamCollection.getParamCode().equals(x.getParamCode())).collect(Collectors.toList());
498                     if (CollUtil.isNotEmpty(collect1)){
499                         BsFormulaChildInfo bsFormulaChildInfo = collect1.get(0);
500                         childVO.setItemType(bsFormulaChildInfo.getOperationType());
501                     }
502                 }
503
504                 checkList.add(childVO);
505             }
506         }
507         vo.setCheckList(checkList);
508         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(vo)).execute();
509
510     }
5966d6 511
A 512     @Override
513     public void pushGeelycvMesFeedback(String packID, String stationCode) {
d76bba 514         logger.info("进入人工工位推送工厂MES数据方法-pushGeelycvMesFeedback-工位{}-pack码{}",stationCode,packID);
5966d6 515         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
768498 516         String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
A 517 //        String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
5966d6 518         String totalResult = "0";
8cfe20 519         List<DaParamCollectionTemp> paramList = daParamCollectionTempService.list(new LambdaQueryWrapper<DaParamCollectionTemp>().eq(DaParamCollectionTemp::getSfcCode, packID).eq(DaParamCollectionTemp::getLocationCode, stationCode));
A 520         if(paramList.size() > 0){
521             ParentVO parentVO = new ParentVO();
522             parentVO.setSiteCode("3983");
523             parentVO.setRecordId(String.valueOf(Instant.now().toEpochMilli()));
524             parentVO.setStationCode(stationCode);
525             parentVO.setProductNum(packID);
526             parentVO.setTotalResult("1");
527             List<ChildVO> listChildVo = new ArrayList<>();
528
529             for (DaParamCollectionTemp daParamCollection : paramList) {
530                 ChildVO childVO = new ChildVO();
531                 childVO.setItemCode(daParamCollection.getParamCode());
532 //                BsFormulaChildInfo childOne = bsFormulaChildInfoService.getOne(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getParamCode, daParamCollection.getParamCode()));
533 //                DaCollectionParamConf paramConfOne = daCollectionParamConfService.getOne(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
534                 List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
535                 DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
536 //                if(childOne!=null){
537 //                    String operationType = childOne.getOperationType();
538 //                    if(operationType.equals("1")){
539 //                        childVO.setItemType("2");
540 //                    }else if(operationType.equals("2")){
541 //                        childVO.setItemType("1");
542 //                    }
543 //                }else {
544 //                    childVO.setItemType("3");
545 //                }
546                 if(paramConfOne!=null){
547                     childVO.setItemType(paramConfOne.getSpareField1());
548                     childVO.setItemText(paramConfOne.getCollectParameterName());
549                 }else {
550                     childVO.setItemType("3");
551                     childVO.setItemText("");
552                 }
553                 childVO.setItemValue(daParamCollection.getParamValue());
554
555                 if(daParamCollection.getParamValue().equals("1")){
556                     childVO.setCheckResult("1");
557                 }else if(daParamCollection.getParamValue().equals("2")){
558                     childVO.setCheckResult("0");
559                     parentVO.setTotalResult("0");
560                     totalResult = "1";
561                 }else {
562                     childVO.setCheckResult("1");
563                 }
564                 childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
565                 listChildVo.add(childVO);
566
567             }
568             parentVO.setCheckList(listChildVo);
d76bba 569             try{
A 570                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
571                     logger.info("开始执行异步方法");
572                     HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
573                     logger.info("异步方法执行结束");
574                     logger.info("手动工位传工厂MES异步方法{}"+execute.body());
2fbce7 575
A 576                     DaParamCollectionTemp daParamCollectionTemp = new DaParamCollectionTemp();
577                     daParamCollectionTemp.setSfcCode(packID);
578                     daParamCollectionTemp.setLocationCode(stationCode);
579                     int i = daParamCollectionTempService.deleteDaParamCollectionTempBySfcCodeAndLocationCode(daParamCollectionTemp);
d76bba 580                     logger.info("删除临时表数据条数{}-工位{}-pack码{}",i,stationCode,packID);
2fbce7 581 //                    List<Long> idsList = paramList.stream().map(DaParamCollectionTemp::getId).collect(Collectors.toList());
A 582 //                    Long[] array = idsList.toArray(new Long[0]);
583 //                    int i = daParamCollectionTempService.deleteDaParamCollectionTempByIds(array);
584 //                    logger.info("删除临时表数据条数{}-工位{}-pack码{}",i,stationCode,packID);
d76bba 585                 });
A 586             }catch (Exception e){
587                 System.out.println(e.getMessage());
588             }
589 //            HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
590
591 //            System.out.println(execute.body());
8cfe20 592             System.out.println("-----------------------"+totalResult);
d76bba 593             logger.info("结束人工工位推送工厂MES数据方法-pushGeelycvMesFeedback-工位{}-pack码{}",stationCode,packID);
8cfe20 594         }
A 595
596     }
597
598     @Override
599     public void automaticWorkstationPushGeelycvMesFeedback(String packID, String stationCode,List<DaParamCollection> paramList) {
bdb404 600         logger.info("进入工位{}-工厂MES推送数据方法automaticWorkstationPushGeelycvMesFeedback",stationCode);
8cfe20 601         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
A 602 //        String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
603         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
604         String totalResult = "0";
5966d6 605         if(paramList.size() > 0){
bdb404 606             logger.info("进入工位{}-拼数据",stationCode);
5966d6 607             ParentVO parentVO = new ParentVO();
A 608             parentVO.setSiteCode("3983");
609             parentVO.setRecordId(String.valueOf(Instant.now().toEpochMilli()));
610             parentVO.setStationCode(stationCode);
611             parentVO.setProductNum(packID);
612             parentVO.setTotalResult("1");
613             List<ChildVO> listChildVo = new ArrayList<>();
614
615             for (DaParamCollection daParamCollection : paramList) {
616                 ChildVO childVO = new ChildVO();
617                 childVO.setItemCode(daParamCollection.getParamCode());
8cfe20 618 //                BsFormulaChildInfo childOne = bsFormulaChildInfoService.getOne(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getParamCode, daParamCollection.getParamCode()));
A 619 //                DaCollectionParamConf paramConfOne = daCollectionParamConfService.getOne(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
620                 List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
621                 DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
237733 622 //                if(childOne!=null){
A 623 //                    String operationType = childOne.getOperationType();
624 //                    if(operationType.equals("1")){
625 //                        childVO.setItemType("2");
626 //                    }else if(operationType.equals("2")){
627 //                        childVO.setItemType("1");
628 //                    }
629 //                }else {
630 //                    childVO.setItemType("3");
631 //                }
5966d6 632                 if(paramConfOne!=null){
237733 633                     childVO.setItemType(paramConfOne.getSpareField1());
5966d6 634                     childVO.setItemText(paramConfOne.getCollectParameterName());
A 635                 }else {
237733 636                     childVO.setItemType("3");
5966d6 637                     childVO.setItemText("");
A 638                 }
639                 childVO.setItemValue(daParamCollection.getParamValue());
640
641                 if(daParamCollection.getParamValue().equals("1")){
642                     childVO.setCheckResult("1");
643                 }else if(daParamCollection.getParamValue().equals("2")){
644                     childVO.setCheckResult("0");
645                     parentVO.setTotalResult("0");
646                     totalResult = "1";
647                 }else {
648                     childVO.setCheckResult("1");
649                 }
650                 childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
651                 listChildVo.add(childVO);
652             }
653             parentVO.setCheckList(listChildVo);
bdb404 654             logger.info("结束工位{}-拼数据",stationCode);
A 655             logger.info("进入工位{}-工厂MES推送数据方法HttpResponseSend",stationCode);
d76bba 656             try{
A 657                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
658                     logger.info("开始执行异步方法");
659                     HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
660                     System.out.println(execute.body());
661                     logger.info("异步方法执行结束");
662                     logger.info("自动工位传工厂MES异步方法{}"+execute.body());
663                 });
664             }catch (Exception e){
665                 System.out.println(e.getMessage());
666             }
667 //            HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
bdb404 668             logger.info("结束工位{}-工厂MES推送数据方法HttpResponseSend",stationCode);
5966d6 669             System.out.println("-----------------------"+totalResult);
A 670         }
bdb404 671         logger.info("结束工位{}-工厂MES推送数据方法automaticWorkstationPushGeelycvMesFeedback",stationCode);
5966d6 672     }
616f98 673
237733 674     @Override
A 675     public AjaxResult checkRecordDataDone(DaParamCollection daParamCollection) {
676         String result = "";
8cfe20 677
A 678
237733 679         try {
8cfe20 680             List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getSpareField4, "1").eq(BsFormulaChildInfo::getProcessesCode, daParamCollection.getLocationCode()));
A 681             if(list.size()>0){
682                 String results = list.get(0).getResults();
683                 if(results!= null && !results.equals("") && results.equals("OK")){
684                     result = "21";
685                 }
686             }
687             /*Object recordDataDone = miloService.readFromOpcUa("PACK" + "." + daParamCollection.getLocationCode() + ".RecordDataDone").getValue();
237733 688             if(ObjectUtil.isNotNull(recordDataDone)){
A 689                 result = recordDataDone.toString();
8cfe20 690             }*/
237733 691         } catch (Exception e) {
A 692             throw new RuntimeException(e);
693         }
694         return AjaxResult.success(result);
695     }
696
8cfe20 697     @Override
A 698     public void enterWeighing(DaParamCollection daParamCollection) {
699         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
700         long timestampMillis = Instant.now().toEpochMilli();
701         ParentVO parentVO = new ParentVO();
702         ChildVO childVO = new ChildVO();
703         List<ChildVO> childVOList = new ArrayList<>();
704         childVO.setItemCode("PWD_PW");
705         childVO.setItemType("3");
706         childVO.setItemText("Pack重量值");
707         childVO.setItemValue(daParamCollection.getWeightValue());
708         childVO.setCheckTime(format.format(new Date()));
709         childVO.setCheckResult("1");
710         childVOList.add(childVO);
711         parentVO.setSiteCode("3983");
712         parentVO.setRecordId(""+timestampMillis);
713         parentVO.setStationCode("OP500");
714         parentVO.setProductNum(daParamCollection.getSfcCode());
715         parentVO.setTotalResult("1");
716         parentVO.setCheckList(childVOList);
717         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
d76bba 718 //        try{
A 719 //            CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
720 //                logger.info("开始执行异步方法");
721 //                HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
722 //                System.out.println(execute.body());
723 //                logger.info("异步方法执行结束");
724 //                logger.info("称重异步方法{}",execute.body());
725 //            });
726 //        }catch (Exception e){
727 //            System.out.println(e.getMessage());
728 //        }
8cfe20 729         RestfulService.getWorkReportResultFeedback(daParamCollection.getSfcCode(),"OP500",format.format(new Date()));
A 730     }
731
768498 732     @Override
A 733     public void manualWorkstationsAddBasicParameters(DaParamCollection daParamCollection) {
734         // 假设这是从数据库或其他地方获取的参数数据
735         Map<String, String> map = new HashMap<>();
736         map.put("GC", "南浔工厂");
737         map.put("CXBH", "Pack线");
738         map.put("SBBH", "设备001");
739         map.put("YGBH", SecurityUtils.getUsername());
740         map.put("GDBH", daParamCollection.getWorkOrderNo());
741         map.put("CPXH", daParamCollection.getProductCode());
742         map.put("INT", format.format(daParamCollection.getInboundTime()));
743         map.put("OUTT",format.format(new Date()));
744
745         map.forEach((key, value) -> {
746             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
747             daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
748             daCollectionParamConf.setCollectParameterId(key);
749             List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
750             DaParamCollection saveData = new DaParamCollection();
751             saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
752             saveData.setProductCode(daParamCollection.getProductCode());
753             saveData.setLocationCode(daParamCollection.getLocationCode());
754             saveData.setSfcCode(daParamCollection.getProductBarcode());
755             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
756             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
757             saveData.setCollectionTime(new Date());
758             saveData.setParamValue(value);
759             daParamCollectionMapper.insertDaParamCollection(saveData);
760         });
761     }
762
763     @Override
764     public void preInstallOut(DaParamCollection daParamCollection) {
765         //增加过站记录
766         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
767         daPassingStationCollection.setSfcCode(daParamCollection.getProductBarcode());
768         daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
769         daPassingStationCollection.setInboundTime(daParamCollection.getInboundTime());
770         daPassingStationCollection.setOutboundTime(new Date());
771         daPassingStationCollection.setCreateTime(new Date());
772         daPassingStationCollection.setOutRsSign("1");
773         boolean save = daPassingStationCollectionService.save(daPassingStationCollection);
774         //添加基础参数
775         this.manualWorkstationsAddBasicParameters(daParamCollection);
776     }
777
e57a89 778 }