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