admin
2024-07-26 b849c6d6056a6783914546fed92399472e34f9dd
提交 | 用户 | 时间
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");
6e3e50 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());
aa0211 524                 List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
A 525                         .eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode())
526                         .eq(DaCollectionParamConf::getProductModel, "PE01B")
527                 );
8cfe20 528                 DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
A 529                 if(paramConfOne!=null){
530                     childVO.setItemType(paramConfOne.getSpareField1());
531                     childVO.setItemText(paramConfOne.getCollectParameterName());
532                 }else {
533                     childVO.setItemType("3");
534                     childVO.setItemText("");
535                 }
536                 childVO.setItemValue(daParamCollection.getParamValue());
537
538                 if(daParamCollection.getParamValue().equals("1")){
539                     childVO.setCheckResult("1");
540                 }else if(daParamCollection.getParamValue().equals("2")){
541                     childVO.setCheckResult("0");
542                     parentVO.setTotalResult("0");
543                     totalResult = "1";
544                 }else {
545                     childVO.setCheckResult("1");
546                 }
547                 childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
548                 listChildVo.add(childVO);
549
550             }
551             parentVO.setCheckList(listChildVo);
d76bba 552             try{
A 553                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
273d64 554                     logger.info("工位{}---开始执行异步方法---pack码是{}"+stationCode,packID);
d76bba 555                     HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
273d64 556                     logger.info("工位{}---异步方法执行结束---pack码是{}"+stationCode,packID);
A 557                     logger.info("手动工位{}传工厂入参VO{}---pack码是{}" + stationCode,new Gson().toJson(parentVO),packID);
558                     logger.info("手动工位{}传工厂MES异步方法{}---pack码是{}"+stationCode,execute.body(),packID);
2fbce7 559
A 560                     DaParamCollectionTemp daParamCollectionTemp = new DaParamCollectionTemp();
561                     daParamCollectionTemp.setSfcCode(packID);
562                     daParamCollectionTemp.setLocationCode(stationCode);
563                     int i = daParamCollectionTempService.deleteDaParamCollectionTempBySfcCodeAndLocationCode(daParamCollectionTemp);
d76bba 564                     logger.info("删除临时表数据条数{}-工位{}-pack码{}",i,stationCode,packID);
A 565                 });
566             }catch (Exception e){
567                 System.out.println(e.getMessage());
568             }
569             logger.info("结束人工工位推送工厂MES数据方法-pushGeelycvMesFeedback-工位{}-pack码{}",stationCode,packID);
8cfe20 570         }
A 571
572     }
573
574     @Override
575     public void automaticWorkstationPushGeelycvMesFeedback(String packID, String stationCode,List<DaParamCollection> paramList) {
bdb404 576         logger.info("进入工位{}-工厂MES推送数据方法automaticWorkstationPushGeelycvMesFeedback",stationCode);
8cfe20 577         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
6e3e50 578 //        String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
A 579         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
8cfe20 580         String totalResult = "0";
5966d6 581         if(paramList.size() > 0){
bdb404 582             logger.info("进入工位{}-拼数据",stationCode);
5966d6 583             ParentVO parentVO = new ParentVO();
A 584             parentVO.setSiteCode("3983");
585             parentVO.setRecordId(String.valueOf(Instant.now().toEpochMilli()));
586             parentVO.setStationCode(stationCode);
587             parentVO.setProductNum(packID);
588             parentVO.setTotalResult("1");
589             List<ChildVO> listChildVo = new ArrayList<>();
590
591             for (DaParamCollection daParamCollection : paramList) {
592                 ChildVO childVO = new ChildVO();
593                 childVO.setItemCode(daParamCollection.getParamCode());
8cfe20 594 //                BsFormulaChildInfo childOne = bsFormulaChildInfoService.getOne(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getParamCode, daParamCollection.getParamCode()));
A 595 //                DaCollectionParamConf paramConfOne = daCollectionParamConfService.getOne(new LambdaQueryWrapper<DaCollectionParamConf>().eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode()));
aa0211 596                 List<DaCollectionParamConf> paramConfOneList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
A 597                         .eq(DaCollectionParamConf::getCollectParameterId, daParamCollection.getParamCode())
598                         .eq(DaCollectionParamConf::getProductModel, "PE01B")
599                 );
8cfe20 600                 DaCollectionParamConf paramConfOne = paramConfOneList.get(0);
5966d6 601                 if(paramConfOne!=null){
237733 602                     childVO.setItemType(paramConfOne.getSpareField1());
5966d6 603                     childVO.setItemText(paramConfOne.getCollectParameterName());
A 604                 }else {
237733 605                     childVO.setItemType("3");
5966d6 606                     childVO.setItemText("");
A 607                 }
608                 childVO.setItemValue(daParamCollection.getParamValue());
609
610                 if(daParamCollection.getParamValue().equals("1")){
611                     childVO.setCheckResult("1");
612                 }else if(daParamCollection.getParamValue().equals("2")){
613                     childVO.setCheckResult("0");
614                     parentVO.setTotalResult("0");
615                     totalResult = "1";
616                 }else {
617                     childVO.setCheckResult("1");
618                 }
619                 childVO.setCheckTime(format.format(daParamCollection.getCollectionTime()));
620                 listChildVo.add(childVO);
621             }
622             parentVO.setCheckList(listChildVo);
bdb404 623             logger.info("结束工位{}-拼数据",stationCode);
A 624             logger.info("进入工位{}-工厂MES推送数据方法HttpResponseSend",stationCode);
d76bba 625             try{
A 626                 CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
273d64 627                     logger.info("工位{}---自动工位开始执行异步方法---pack码是{}"+stationCode,packID);
d76bba 628                     HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
273d64 629                     logger.info("工位{}---自动工位异步方法执行结束---pack码是{}"+stationCode,packID);
4e83fa 630                     logger.info("自动工位{}传工厂入参VO{}" + stationCode,new Gson().toJson(parentVO));
A 631                     logger.info("自动工位{}传工厂MES异步方法返回{}"+stationCode,execute.body());
d76bba 632                 });
A 633             }catch (Exception e){
634                 System.out.println(e.getMessage());
635             }
636 //            HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
bdb404 637             logger.info("结束工位{}-工厂MES推送数据方法HttpResponseSend",stationCode);
5966d6 638         }
bdb404 639         logger.info("结束工位{}-工厂MES推送数据方法automaticWorkstationPushGeelycvMesFeedback",stationCode);
5966d6 640     }
616f98 641
237733 642     @Override
A 643     public AjaxResult checkRecordDataDone(DaParamCollection daParamCollection) {
644         String result = "";
8cfe20 645
A 646
237733 647         try {
8cfe20 648             List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getSpareField4, "1").eq(BsFormulaChildInfo::getProcessesCode, daParamCollection.getLocationCode()));
A 649             if(list.size()>0){
650                 String results = list.get(0).getResults();
651                 if(results!= null && !results.equals("") && results.equals("OK")){
652                     result = "21";
653                 }
654             }
655             /*Object recordDataDone = miloService.readFromOpcUa("PACK" + "." + daParamCollection.getLocationCode() + ".RecordDataDone").getValue();
237733 656             if(ObjectUtil.isNotNull(recordDataDone)){
A 657                 result = recordDataDone.toString();
8cfe20 658             }*/
237733 659         } catch (Exception e) {
A 660             throw new RuntimeException(e);
661         }
662         return AjaxResult.success(result);
663     }
664
8cfe20 665     @Override
A 666     public void enterWeighing(DaParamCollection daParamCollection) {
667         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
6e3e50 668 //        String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
8cfe20 669         long timestampMillis = Instant.now().toEpochMilli();
A 670         ParentVO parentVO = new ParentVO();
671         ChildVO childVO = new ChildVO();
672         List<ChildVO> childVOList = new ArrayList<>();
673         childVO.setItemCode("PWD_PW");
674         childVO.setItemType("3");
675         childVO.setItemText("Pack重量值");
676         childVO.setItemValue(daParamCollection.getWeightValue());
677         childVO.setCheckTime(format.format(new Date()));
678         childVO.setCheckResult("1");
679         childVOList.add(childVO);
680         parentVO.setSiteCode("3983");
681         parentVO.setRecordId(""+timestampMillis);
4e83fa 682         parentVO.setStationCode("POP430");
8cfe20 683         parentVO.setProductNum(daParamCollection.getSfcCode());
A 684         parentVO.setTotalResult("1");
685         parentVO.setCheckList(childVOList);
686         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
4e83fa 687         RestfulService.getWorkReportResultFeedback(daParamCollection.getSfcCode(),"POP430",format.format(new Date()));
8cfe20 688     }
A 689
768498 690     @Override
A 691     public void manualWorkstationsAddBasicParameters(DaParamCollection daParamCollection) {
692         // 假设这是从数据库或其他地方获取的参数数据
693         Map<String, String> map = new HashMap<>();
694         map.put("GC", "南浔工厂");
695         map.put("CXBH", "Pack线");
696         map.put("SBBH", "设备001");
697         map.put("YGBH", SecurityUtils.getUsername());
698         map.put("GDBH", daParamCollection.getWorkOrderNo());
699         map.put("CPXH", daParamCollection.getProductCode());
700         map.put("INT", format.format(daParamCollection.getInboundTime()));
701         map.put("OUTT",format.format(new Date()));
702
703         map.forEach((key, value) -> {
704             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
705             daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
706             daCollectionParamConf.setCollectParameterId(key);
707             List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
708             DaParamCollection saveData = new DaParamCollection();
709             saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
710             saveData.setProductCode(daParamCollection.getProductCode());
711             saveData.setLocationCode(daParamCollection.getLocationCode());
712             saveData.setSfcCode(daParamCollection.getProductBarcode());
713             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
714             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
715             saveData.setCollectionTime(new Date());
716             saveData.setParamValue(value);
717             daParamCollectionMapper.insertDaParamCollection(saveData);
273d64 718
A 719             DaParamCollectionTemp saveDataTemp = new DaParamCollectionTemp();
720             saveDataTemp.setWorkOrderNo(daParamCollection.getWorkOrderNo());
721             saveDataTemp.setProductCode(daParamCollection.getProductCode());
722             saveDataTemp.setLocationCode(daParamCollection.getLocationCode());
723             saveDataTemp.setSfcCode(daParamCollection.getProductBarcode());
724             saveDataTemp.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
725             saveDataTemp.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
726             saveDataTemp.setCollectionTime(new Date());
727             saveDataTemp.setParamValue(value);
728             daParamCollectionTempService.save(saveDataTemp);
729
768498 730         });
A 731     }
732
733     @Override
734     public void preInstallOut(DaParamCollection daParamCollection) {
4e83fa 735         String locationCode = daParamCollection.getLocationCode();
768498 736         //增加过站记录
A 737         DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
738         daPassingStationCollection.setSfcCode(daParamCollection.getProductBarcode());
4e83fa 739         daPassingStationCollection.setLocationCode(locationCode);
768498 740         daPassingStationCollection.setInboundTime(daParamCollection.getInboundTime());
A 741         daPassingStationCollection.setOutboundTime(new Date());
742         daPassingStationCollection.setCreateTime(new Date());
743         daPassingStationCollection.setOutRsSign("1");
744         boolean save = daPassingStationCollectionService.save(daPassingStationCollection);
745         //添加基础参数
746         this.manualWorkstationsAddBasicParameters(daParamCollection);
4e83fa 747
A 748         try {
749             String str = "PACK."+locationCode+".RecordDataDone";
750             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(21).build());
751             logger.info("预装工位写入OPC成功,工位:{},值{}",str,21);
752         } catch (Exception e) {
753             throw new RuntimeException(e);
754         }
768498 755     }
A 756
01beb5 757     @Override
A 758     public AjaxResult addRepairTighteningData(DaParamCollection daParamCollection) {
759         try {
b849c6 760         String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
A 761 //            String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
01beb5 762             String processesCode =  daParamCollection.getLocationCode();
A 763
764             long timestampMillis = Instant.now().toEpochMilli();
765             ParentVO parentVO = new ParentVO();
766             List<ChildVO> childVOList = new ArrayList<>();
767             parentVO.setSiteCode("3983");
768             parentVO.setRecordId(""+timestampMillis);
769             parentVO.setStationCode(processesCode);
770             parentVO.setProductNum(daParamCollection.getSfcCode());
771             parentVO.setTotalResult("1");
772             parentVO.setCheckList(childVOList);
773
774             String screwNumber = daParamCollection.getScrewNumber();
775             String torque = daParamCollection.getTorque();
776             String angle = daParamCollection.getAngle();
777             String torqueResult = daParamCollection.getTorqueResult();
778             String angleResult = daParamCollection.getAngleResult();
779
780             Map<String, String> map = new HashMap<>();
781             map.put("POP320","模组");
782             map.put("POP400","箱盖");
783
784             List<String> nameLikeString = new ArrayList<>();
785             nameLikeString.add(map.get(processesCode)+"拧紧最终扭矩");
786             nameLikeString.add(map.get(processesCode)+"拧紧最终角度");
787             nameLikeString.add(map.get(processesCode)+"拧紧最终扭矩是否在范围内");
788             nameLikeString.add(map.get(processesCode)+"拧紧最终角度是否在范围内");
789
790             if(screwNumber.contains(",")){
791                 String[] screwNumberSplit = screwNumber.split(",");
792                 String[] torqueSplit = torque.split(",");
793                 String[] angleSplit = angle.split(",");
794                 String[] torqueResultSplit = torqueResult.split(",");
795                 String[] angleResultSplit = angleResult.split(",");
796
797                 List<String[]> dataList = new ArrayList<String[]>();
798                 dataList.add(torqueSplit);
799                 dataList.add(angleSplit);
800                 dataList.add(torqueResultSplit);
801                 dataList.add(angleResultSplit);
802
803                 for (int k = 0; k < nameLikeString.size(); k++) {
804                     for (int i = 0; i < screwNumberSplit.length; i++) {
805                         String s1 = nameLikeString.get(k)+screwNumberSplit[i];
806                         List<DaCollectionParamConf> confList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
807                                 .eq(DaCollectionParamConf::getProcessesCode, processesCode)
808                                 .eq(DaCollectionParamConf::getCollectParameterName, s1)
809                         );
810                         DaCollectionParamConf daCollectionParamConf = confList.get(0);
811                         ChildVO childVO = new ChildVO();
812                         childVO.setItemCode(daCollectionParamConf.getCollectParameterId());
813                         childVO.setItemType(daCollectionParamConf.getSpareField1());
814                         childVO.setItemText(daCollectionParamConf.getCollectParameterName());
815                         String itemValue = dataList.get(k)[i];
816                         childVO.setItemValue(itemValue);
817                         childVO.setCheckTime(format.format(new Date()));
818                         childVO.setCheckResult("1");
819                         childVOList.add(childVO);
820                     }
821                 }
822             }else {
823                 List<String> dataList = new ArrayList<>();
824                 dataList.add(torque);
825                 dataList.add(angle);
826                 dataList.add(torqueResult);
827                 dataList.add(angleResult);
828                 for (int k = 0; k < nameLikeString.size(); k++) {
829                     String collectParameterName = nameLikeString.get(k)+screwNumber;
830                     List<DaCollectionParamConf> confList = daCollectionParamConfService.list(new LambdaQueryWrapper<DaCollectionParamConf>()
831                             .eq(DaCollectionParamConf::getProcessesCode, processesCode)
832                             .eq(DaCollectionParamConf::getCollectParameterName, collectParameterName)
833                     );
834                     DaCollectionParamConf daCollectionParamConf = confList.get(0);
835                     ChildVO childVO = new ChildVO();
836                     childVO.setItemCode(daCollectionParamConf.getCollectParameterId());
837                     childVO.setItemType(daCollectionParamConf.getSpareField1());
838                     childVO.setItemText(daCollectionParamConf.getCollectParameterName());
839                     String itemValue = dataList.get(k);
840                     childVO.setItemValue(itemValue);
841                     childVO.setCheckTime(format.format(new Date()));
842                     childVO.setCheckResult("1");
843                     childVOList.add(childVO);
844                 }
845             }
846
847             System.out.println(childVOList);
848             logger.info("工位{}-----------返修数据上传入参vo:{}",processesCode,new Gson().toJson(parentVO));
849             HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
850             logger.info("工位{}-----------返修数据上传结果:{}",processesCode,execute.body());
851             return AjaxResult.success("上传成功");
852         }catch (Exception e){
853             return AjaxResult.error("上传失败,参数不对请检查!");
854         }
855     }
856
857
e57a89 858 }