admin
2024-07-18 0aaabac24ac4ebc2fe3e54c56e95f250ea238d5b
提交 | 用户 | 时间
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());
273d64 262                 daParamCollectionTemp.setWorkOrderNo(daParamCollection.getWorkOrderNo());
8cfe20 263                 daParamCollectionTempService.save(daParamCollectionTemp);
a60fef 264             }
b77c7b 265         }
49c784 266     }
32483a 267
268     @Override
269     public void saveCampaignTimeParameters(DaParamCollection daParamCollection) {
768498 270 //        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
A 271 //                .eq(BsFormulaChildInfo::getProcessesCode, daParamCollection.getLocationCode())
272 //                .eq(BsFormulaChildInfo::getSpareField4, "1")
273 //        );
274         BsFormulaChildInfo childInfo = daParamCollection.getFormulaChildEntity();
275         if(StringUtils.isNotBlank(childInfo.getResults())){
276             if(!childInfo.getResults().equals("OK")){
237733 277                 try {
A 278                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(22).build());
279                 } catch (Exception e) {
280                     throw new RuntimeException(e);
281                 }
282                 return;
283             }
284         }else {
7bee80 285             try {
286                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(22).build());
287             } catch (Exception e) {
288                 throw new RuntimeException(e);
289             }
290             return;
291         }
768498 292 //        BsFormulaChildInfo bsFormulaChildInfo = new BsFormulaChildInfo();
A 293 //        bsFormulaChildInfo.setProcessesCode(daParamCollection.getLocationCode());
294 //        bsFormulaChildInfo.setProductCode(daParamCollection.getProductCode());
295 //        bsFormulaChildInfo.setSpareField4("1");
296 //        List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(bsFormulaChildInfo);
297         String result = childInfo.getResults();
32483a 298         if(result != null && !result.isEmpty()){
299             try {
768498 300 //                //更新参数采集配置表
A 301 //                DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
302 //                daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
303 //                daCollectionParamConf.setCollectParameterId("OUTT");
304 //                List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
305 //                DaParamCollection saveData = new DaParamCollection();
306 //                saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
307 //                saveData.setProductCode(daParamCollection.getProductCode());
308 //                saveData.setLocationCode(daParamCollection.getLocationCode());
309 //                saveData.setSfcCode(daParamCollection.getProductBarcode());
310 //                saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
311 //                saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
312 //                saveData.setCollectionTime(new Date());
313 //                saveData.setParamValue(DateUtil.formatDateTime(new Date()));
314 //                daParamCollectionMapper.insertDaParamCollection(saveData);
32483a 315
768498 316                 //增加过站记录
32483a 317                 DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
318                 daPassingStationCollection.setWorkOrderNo(daParamCollection.getWorkOrderNo());
768498 319                 daPassingStationCollection.setSfcCode(daParamCollection.getProductBarcode());
A 320                 daPassingStationCollection.setProductCode(daParamCollection.getProductCode());
1df825 321                 daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
768498 322                 daPassingStationCollection.setInboundTime(daParamCollection.getInboundTime());
A 323                 daPassingStationCollection.setOutboundTime(new Date());
324                 daPassingStationCollection.setCreateTime(new Date());
325                 daPassingStationCollection.setOutRsSign("1");
326                 boolean save = daPassingStationCollectionService.save(daPassingStationCollection);
327
328                 //添加基础参数
329                 this.manualWorkstationsAddBasicParameters(daParamCollection);
330
331 //                //更新过站记录表出站时间
332 //                DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
333 //                daPassingStationCollection.setWorkOrderNo(daParamCollection.getWorkOrderNo());
334 //                daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
335 //                List<DaPassingStationCollection> daPassingStationCollections = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection);
336 //                daPassingStationCollections.get(0).setOutboundTime(new Date());
337 //                int i = daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
32483a 338
8f0f8d 339 //                OPCUaSubscription.SaveParamData(daParamCollection.getProductBarcode(),"OP",daParamCollection.getLocationCode(),daParamCollection.getWorkOrderNo(),daParamCollection.getProductCode());
054a69 340
32483a 341                 //给opc发21
7bee80 342                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(21).build());
273d64 343                 if(daParamCollection.getLocationCode().equals("POP240")){
2fbce7 344                     try{
A 345                         CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
346                             logger.info("OP230报工开始-工厂MES异步方法");
4e83fa 347                             String reportResult = RestfulService.getWorkReportResultFeedback(daParamCollection.getProductBarcode(), "POP230", format.format(new Date()));
768498 348                             JSONObject jsonObject = new JSONObject(reportResult);
A 349                             String code = jsonObject.getStr("code");
350                             if("success".equals(code)){
351                                 //如果成功,执行报工成功方法,修改是否报工为1,添加报工时间
4e83fa 352                                 omProductionOrdeInfoService.updateOrderByProductNum("1",daParamCollection.getProductBarcode(),"POP230");
2fbce7 353                             }else{
A 354                                 //解析工厂mes返回结果,如果失败,执行报工失败方法,修改是否报工为2,添加报工时间
4e83fa 355                                 omProductionOrdeInfoService.updateOrderByProductNum("2",daParamCollection.getProductBarcode(),"POP230");
2fbce7 356                             }
A 357                             logger.info("OP230报工结束-工厂MES异步方法{}"+reportResult);
358                         });
359                     }catch (Exception e){
360                         System.out.println(e.getMessage());
361                     }
362 //                    RestfulService.getWorkReportResultFeedback(daParamCollection.getProductBarcode(),"OP230",format.format(new Date()));
237733 363                 }
2fbce7 364
A 365
32483a 366             } catch (Exception e) {
367                 throw new RuntimeException(e);
368             }
369         }
370     }
8f0f8d 371
372     @Override
373     public void insertBatch(List<DaParamCollection> confList){
374         try{
375             this.saveBatch(confList);
376         }catch (Exception e){
377             return;
378         }
379
380     }
ddb300 381
A 382     @Override
383     public void replaceAssemblyCode(DaParamCollection daParamCollection) {
384         List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>()
2c7661 385                 .eq(DaParamCollection::getSfcCode, daParamCollection.getYzSfcCode())
ddb300 386         );
A 387         if(list.size() > 0){
388             for (DaParamCollection paramCollection : list) {
2c7661 389                 paramCollection.setSfcCode(daParamCollection.getSfcCode());
ddb300 390                 daParamCollectionService.saveOrUpdate(paramCollection);
A 391             }
392         }
393
394     }
4a5f2a 395
A 396     @Override
397     public void yzAddBasicParameters(DaParamCollection daParamCollection) {
398         // 假设这是从数据库或其他地方获取的参数数据
399         Map<String, String> map = new HashMap<>();
400 //        map.put("GC", "南浔工厂");
401 //        map.put("CXBH", "Pack线");
402 //        map.put("SBBH", "设备001");
403 //        map.put("YGBH", "员工001");
404 //        map.put("GDBH", daParamCollection.getWorkOrderNo());
405 //        map.put("CPXH", daParamCollection.getModel());
406         map.put("INT", DateUtil.formatDateTime(new Date()));
407
408         map.forEach((key, value) -> {
409             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
410             daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
411             daCollectionParamConf.setCollectParameterId(key);
412             List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
413             DaParamCollection saveData = new DaParamCollection();
414             saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
415             saveData.setProductCode(daParamCollection.getProductCode());
416             saveData.setLocationCode(daParamCollection.getLocationCode());
417             saveData.setSfcCode(daParamCollection.getProductBarcode());
418             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
419             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
420             saveData.setCollectionTime(new Date());
421             saveData.setParamValue(value);
422             daParamCollectionMapper.insertDaParamCollection(saveData);
423         });
424     }
1c84ae 425
A 426     @Override
427     public void jrmSaveCampaignTimeParameters(DaParamCollection daParamCollection) {
4e83fa 428         //增加过站记录
1c84ae 429         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
A 430         daPassingStationCollection.setWorkOrderNo(daParamCollection.getWorkOrderNo());
4e83fa 431         daPassingStationCollection.setSfcCode(daParamCollection.getProductBarcode());
A 432         daPassingStationCollection.setProductCode(daParamCollection.getProductCode());
1c84ae 433         daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
4e83fa 434         daPassingStationCollection.setInboundTime(daParamCollection.getInboundTime());
A 435         daPassingStationCollection.setOutboundTime(new Date());
436         daPassingStationCollection.setCreateTime(new Date());
437         daPassingStationCollection.setOutRsSign("1");
438         boolean save = daPassingStationCollectionService.save(daPassingStationCollection);
1c84ae 439
4e83fa 440         //添加基础参数
A 441         this.manualWorkstationsAddBasicParameters(daParamCollection);
1c84ae 442
A 443         //给opc发21
444         try {
445 //            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(21).build());
4e83fa 446             String str = daParamCollection.getLocationCode();
A 447             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+str+".RecordDataDone").value(21).build());
1c84ae 448         } catch (Exception e) {
A 449             throw new RuntimeException(e);
450         }
451     }
6a462f 452
W 453
454     public void sendToFactoryMes(String stationCode,String productNum ){
a846f2 455 //        String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
A 456         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
6a462f 457         ParentVO vo =new ParentVO();
W 458         List<ChildVO> checkList = new ArrayList<>();
459         List<DaParamCollection> list = this.list(new LambdaQueryWrapper<DaParamCollection>()
460                 .eq(DaParamCollection::getSfcCode, productNum)
461                 .eq(DaParamCollection::getLocationCode, stationCode));
462         vo.setTotalResult("1");
463         String string = new Random(10).toString();
464         vo.setRecordId(string);
465         vo.setProductNum(productNum);
466         vo.setSiteCode("3983");
467         vo.setStationCode(stationCode);
468         if (CollUtil.isNotEmpty(list)){
469             List<DaParamCollection> collect = list.stream().filter(x -> Constants.NG.equals(x.getParamValue())).collect(Collectors.toList());
470             if (CollUtil.isNotEmpty(collect)){
471                 vo.setTotalResult("0");
472             }
473             List<BsFormulaChildInfo> bsFormulaChildInfoList = bsFormulaChildInfoService.list();
474             for (DaParamCollection daParamCollection : list) {
475                 ChildVO childVO = new ChildVO();
476                 childVO.setItemCode(daParamCollection.getParamCode());
477                 String time = daParamCollection.getCollectionTime() != null ? daParamCollection.getCollectionTime().toString() : "";
478                 childVO.setCheckResult("1");
479                 if (StrUtil.isNotBlank(daParamCollection.getParamValue())){
480                     if (Constants.NG.equals(daParamCollection.getParamValue())){
481                         childVO.setCheckResult("0");
482                     }
483                 }
484                 childVO.setCheckTime(time);
485                 childVO.setItemValue(daParamCollection.getParamValue());
486                 childVO.setItemType("3");
487                 childVO.setItemText(daParamCollection.getParamName());
488                 if (StrUtil.isNotBlank(daParamCollection.getParamCode())){
489                     List<BsFormulaChildInfo> collect1 = bsFormulaChildInfoList.stream().filter(x -> daParamCollection.getParamCode().equals(x.getParamCode())).collect(Collectors.toList());
490                     if (CollUtil.isNotEmpty(collect1)){
491                         BsFormulaChildInfo bsFormulaChildInfo = collect1.get(0);
492                         childVO.setItemType(bsFormulaChildInfo.getOperationType());
493                     }
494                 }
495
496                 checkList.add(childVO);
497             }
498         }
499         vo.setCheckList(checkList);
500         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(vo)).execute();
501
502     }
5966d6 503
A 504     @Override
505     public void pushGeelycvMesFeedback(String packID, String stationCode) {
d76bba 506         logger.info("进入人工工位推送工厂MES数据方法-pushGeelycvMesFeedback-工位{}-pack码{}",stationCode,packID);
5966d6 507         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
768498 508         String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
A 509 //        String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
5966d6 510         String totalResult = "0";
8cfe20 511         List<DaParamCollectionTemp> paramList = daParamCollectionTempService.list(new LambdaQueryWrapper<DaParamCollectionTemp>().eq(DaParamCollectionTemp::getSfcCode, packID).eq(DaParamCollectionTemp::getLocationCode, stationCode));
A 512         if(paramList.size() > 0){
513             ParentVO parentVO = new ParentVO();
514             parentVO.setSiteCode("3983");
515             parentVO.setRecordId(String.valueOf(Instant.now().toEpochMilli()));
516             parentVO.setStationCode(stationCode);
517             parentVO.setProductNum(packID);
518             parentVO.setTotalResult("1");
519             List<ChildVO> listChildVo = new ArrayList<>();
520
521             for (DaParamCollectionTemp daParamCollection : paramList) {
522                 ChildVO childVO = new ChildVO();
523                 childVO.setItemCode(daParamCollection.getParamCode());
524                 List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
525                 DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
526                 if(paramConfOne!=null){
527                     childVO.setItemType(paramConfOne.getSpareField1());
528                     childVO.setItemText(paramConfOne.getCollectParameterName());
529                 }else {
530                     childVO.setItemType("3");
531                     childVO.setItemText("");
532                 }
533                 childVO.setItemValue(daParamCollection.getParamValue());
534
535                 if(daParamCollection.getParamValue().equals("1")){
536                     childVO.setCheckResult("1");
537                 }else if(daParamCollection.getParamValue().equals("2")){
538                     childVO.setCheckResult("0");
539                     parentVO.setTotalResult("0");
540                     totalResult = "1";
541                 }else {
542                     childVO.setCheckResult("1");
543                 }
544                 childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
545                 listChildVo.add(childVO);
546
547             }
548             parentVO.setCheckList(listChildVo);
d76bba 549             try{
A 550                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
273d64 551                     logger.info("工位{}---开始执行异步方法---pack码是{}"+stationCode,packID);
d76bba 552                     HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
273d64 553                     logger.info("工位{}---异步方法执行结束---pack码是{}"+stationCode,packID);
A 554                     logger.info("手动工位{}传工厂入参VO{}---pack码是{}" + stationCode,new Gson().toJson(parentVO),packID);
555                     logger.info("手动工位{}传工厂MES异步方法{}---pack码是{}"+stationCode,execute.body(),packID);
2fbce7 556
A 557                     DaParamCollectionTemp daParamCollectionTemp = new DaParamCollectionTemp();
558                     daParamCollectionTemp.setSfcCode(packID);
559                     daParamCollectionTemp.setLocationCode(stationCode);
560                     int i = daParamCollectionTempService.deleteDaParamCollectionTempBySfcCodeAndLocationCode(daParamCollectionTemp);
d76bba 561                     logger.info("删除临时表数据条数{}-工位{}-pack码{}",i,stationCode,packID);
A 562                 });
563             }catch (Exception e){
564                 System.out.println(e.getMessage());
565             }
566             logger.info("结束人工工位推送工厂MES数据方法-pushGeelycvMesFeedback-工位{}-pack码{}",stationCode,packID);
8cfe20 567         }
A 568
569     }
570
571     @Override
572     public void automaticWorkstationPushGeelycvMesFeedback(String packID, String stationCode,List<DaParamCollection> paramList) {
bdb404 573         logger.info("进入工位{}-工厂MES推送数据方法automaticWorkstationPushGeelycvMesFeedback",stationCode);
8cfe20 574         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
273d64 575         String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
A 576 //        String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
8cfe20 577         String totalResult = "0";
5966d6 578         if(paramList.size() > 0){
bdb404 579             logger.info("进入工位{}-拼数据",stationCode);
5966d6 580             ParentVO parentVO = new ParentVO();
A 581             parentVO.setSiteCode("3983");
582             parentVO.setRecordId(String.valueOf(Instant.now().toEpochMilli()));
583             parentVO.setStationCode(stationCode);
584             parentVO.setProductNum(packID);
585             parentVO.setTotalResult("1");
586             List<ChildVO> listChildVo = new ArrayList<>();
587
588             for (DaParamCollection daParamCollection : paramList) {
589                 ChildVO childVO = new ChildVO();
590                 childVO.setItemCode(daParamCollection.getParamCode());
8cfe20 591 //                BsFormulaChildInfo childOne = bsFormulaChildInfoService.getOne(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getParamCode, daParamCollection.getParamCode()));
A 592 //                DaCollectionParamConf paramConfOne = daCollectionParamConfService.getOne(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
593                 List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
594                 DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
5966d6 595                 if(paramConfOne!=null){
237733 596                     childVO.setItemType(paramConfOne.getSpareField1());
5966d6 597                     childVO.setItemText(paramConfOne.getCollectParameterName());
A 598                 }else {
237733 599                     childVO.setItemType("3");
5966d6 600                     childVO.setItemText("");
A 601                 }
602                 childVO.setItemValue(daParamCollection.getParamValue());
603
604                 if(daParamCollection.getParamValue().equals("1")){
605                     childVO.setCheckResult("1");
606                 }else if(daParamCollection.getParamValue().equals("2")){
607                     childVO.setCheckResult("0");
608                     parentVO.setTotalResult("0");
609                     totalResult = "1";
610                 }else {
611                     childVO.setCheckResult("1");
612                 }
613                 childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
614                 listChildVo.add(childVO);
615             }
616             parentVO.setCheckList(listChildVo);
bdb404 617             logger.info("结束工位{}-拼数据",stationCode);
A 618             logger.info("进入工位{}-工厂MES推送数据方法HttpResponseSend",stationCode);
d76bba 619             try{
A 620                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
273d64 621                     logger.info("工位{}---自动工位开始执行异步方法---pack码是{}"+stationCode,packID);
d76bba 622                     HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
273d64 623                     logger.info("工位{}---自动工位异步方法执行结束---pack码是{}"+stationCode,packID);
4e83fa 624                     logger.info("自动工位{}传工厂入参VO{}" + stationCode,new Gson().toJson(parentVO));
A 625                     logger.info("自动工位{}传工厂MES异步方法返回{}"+stationCode,execute.body());
d76bba 626                 });
A 627             }catch (Exception e){
628                 System.out.println(e.getMessage());
629             }
630 //            HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
bdb404 631             logger.info("结束工位{}-工厂MES推送数据方法HttpResponseSend",stationCode);
5966d6 632         }
bdb404 633         logger.info("结束工位{}-工厂MES推送数据方法automaticWorkstationPushGeelycvMesFeedback",stationCode);
5966d6 634     }
616f98 635
237733 636     @Override
A 637     public AjaxResult checkRecordDataDone(DaParamCollection daParamCollection) {
638         String result = "";
8cfe20 639
A 640
237733 641         try {
8cfe20 642             List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getSpareField4, "1").eq(BsFormulaChildInfo::getProcessesCode, daParamCollection.getLocationCode()));
A 643             if(list.size()>0){
644                 String results = list.get(0).getResults();
645                 if(results!= null && !results.equals("") && results.equals("OK")){
646                     result = "21";
647                 }
648             }
649             /*Object recordDataDone = miloService.readFromOpcUa("PACK" + "." + daParamCollection.getLocationCode() + ".RecordDataDone").getValue();
237733 650             if(ObjectUtil.isNotNull(recordDataDone)){
A 651                 result = recordDataDone.toString();
8cfe20 652             }*/
237733 653         } catch (Exception e) {
A 654             throw new RuntimeException(e);
655         }
656         return AjaxResult.success(result);
657     }
658
8cfe20 659     @Override
A 660     public void enterWeighing(DaParamCollection daParamCollection) {
661         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
662         long timestampMillis = Instant.now().toEpochMilli();
663         ParentVO parentVO = new ParentVO();
664         ChildVO childVO = new ChildVO();
665         List<ChildVO> childVOList = new ArrayList<>();
666         childVO.setItemCode("PWD_PW");
667         childVO.setItemType("3");
668         childVO.setItemText("Pack重量值");
669         childVO.setItemValue(daParamCollection.getWeightValue());
670         childVO.setCheckTime(format.format(new Date()));
671         childVO.setCheckResult("1");
672         childVOList.add(childVO);
673         parentVO.setSiteCode("3983");
674         parentVO.setRecordId(""+timestampMillis);
4e83fa 675         parentVO.setStationCode("POP430");
8cfe20 676         parentVO.setProductNum(daParamCollection.getSfcCode());
A 677         parentVO.setTotalResult("1");
678         parentVO.setCheckList(childVOList);
679         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
4e83fa 680         RestfulService.getWorkReportResultFeedback(daParamCollection.getSfcCode(),"POP430",format.format(new Date()));
8cfe20 681     }
A 682
768498 683     @Override
A 684     public void manualWorkstationsAddBasicParameters(DaParamCollection daParamCollection) {
685         // 假设这是从数据库或其他地方获取的参数数据
686         Map<String, String> map = new HashMap<>();
687         map.put("GC", "南浔工厂");
688         map.put("CXBH", "Pack线");
689         map.put("SBBH", "设备001");
690         map.put("YGBH", SecurityUtils.getUsername());
691         map.put("GDBH", daParamCollection.getWorkOrderNo());
692         map.put("CPXH", daParamCollection.getProductCode());
693         map.put("INT", format.format(daParamCollection.getInboundTime()));
694         map.put("OUTT",format.format(new Date()));
695
696         map.forEach((key, value) -> {
697             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
698             daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
699             daCollectionParamConf.setCollectParameterId(key);
700             List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
701             DaParamCollection saveData = new DaParamCollection();
702             saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
703             saveData.setProductCode(daParamCollection.getProductCode());
704             saveData.setLocationCode(daParamCollection.getLocationCode());
705             saveData.setSfcCode(daParamCollection.getProductBarcode());
706             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
707             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
708             saveData.setCollectionTime(new Date());
709             saveData.setParamValue(value);
710             daParamCollectionMapper.insertDaParamCollection(saveData);
273d64 711
A 712             DaParamCollectionTemp saveDataTemp = new DaParamCollectionTemp();
713             saveDataTemp.setWorkOrderNo(daParamCollection.getWorkOrderNo());
714             saveDataTemp.setProductCode(daParamCollection.getProductCode());
715             saveDataTemp.setLocationCode(daParamCollection.getLocationCode());
716             saveDataTemp.setSfcCode(daParamCollection.getProductBarcode());
717             saveDataTemp.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
718             saveDataTemp.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
719             saveDataTemp.setCollectionTime(new Date());
720             saveDataTemp.setParamValue(value);
721             daParamCollectionTempService.save(saveDataTemp);
722
768498 723         });
A 724     }
725
726     @Override
727     public void preInstallOut(DaParamCollection daParamCollection) {
4e83fa 728         String locationCode = daParamCollection.getLocationCode();
768498 729         //增加过站记录
A 730         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
731         daPassingStationCollection.setSfcCode(daParamCollection.getProductBarcode());
4e83fa 732         daPassingStationCollection.setLocationCode(locationCode);
768498 733         daPassingStationCollection.setInboundTime(daParamCollection.getInboundTime());
A 734         daPassingStationCollection.setOutboundTime(new Date());
735         daPassingStationCollection.setCreateTime(new Date());
736         daPassingStationCollection.setOutRsSign("1");
737         boolean save = daPassingStationCollectionService.save(daPassingStationCollection);
738         //添加基础参数
739         this.manualWorkstationsAddBasicParameters(daParamCollection);
4e83fa 740
A 741         try {
742             String str = "PACK."+locationCode+".RecordDataDone";
743             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(21).build());
744             logger.info("预装工位写入OPC成功,工位:{},值{}",str,21);
745         } catch (Exception e) {
746             throw new RuntimeException(e);
747         }
768498 748     }
A 749
e57a89 750 }