-
admin
2024-04-25 5316c506119ad056a5640650e5e79babe4194d38
提交 | 用户 | 时间
e57a89 1 package com.jcdm.main.da.paramCollection.service.impl;
2
b64ed2 3 import cn.hutool.core.date.DateUtil;
8f0f8d 4 import cn.hutool.db.Db;
7bee80 5 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
0ce25f 6 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
e57a89 7 import com.jcdm.common.utils.DateUtils;
7bee80 8 import com.jcdm.main.bs.formula.service.IBsFormulaInfoService;
9 import com.jcdm.main.bs.formula.service.impl.BsFormulaInfoServiceImpl;
b77c7b 10 import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo;
11 import com.jcdm.main.bs.formulaChild.mapper.BsFormulaChildInfoMapper;
7bee80 12 import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService;
b64ed2 13 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
14 import com.jcdm.main.da.collectionParamConf.mapper.DaCollectionParamConfMapper;
e57a89 15 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
16 import com.jcdm.main.da.paramCollection.mapper.DaParamCollectionMapper;
17 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
32483a 18 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
19 import com.jcdm.main.da.passingStationCollection.mapper.DaPassingStationCollectionMapper;
20 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
054a69 21 import com.jcdm.main.plcserver.sub.OPCUaSubscription;
32483a 22 import com.kangaroohy.milo.model.ReadWriteEntity;
23 import com.kangaroohy.milo.service.MiloService;
054a69 24 import org.apache.ibatis.session.ExecutorType;
25 import org.apache.ibatis.session.SqlSession;
26 import org.apache.ibatis.session.SqlSessionFactory;
e57a89 27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.stereotype.Service;
29
054a69 30 import javax.annotation.Resource;
b64ed2 31 import java.util.*;
e57a89 32
33 /**
34  * 设备产品过程参数采集Service业务层处理
35  * 
36  * @author yyt
37  * @date 2023-12-13
38  */
39 @Service
0ce25f 40 public class DaParamCollectionServiceImpl extends ServiceImpl<DaParamCollectionMapper,DaParamCollection> implements IDaParamCollectionService
e57a89 41 {
42     @Autowired
43     private DaParamCollectionMapper daParamCollectionMapper;
b64ed2 44
45     @Autowired
46     private DaCollectionParamConfMapper daCollectionParamConfMapper;
b77c7b 47
48     @Autowired
49     private BsFormulaChildInfoMapper bsFormulaChildInfoMapper;
7bee80 50
51     @Autowired
52     private IBsFormulaChildInfoService bsFormulaChildInfoService;
32483a 53
54     @Autowired
55     private MiloService miloService;
56
57     @Autowired
58     private DaPassingStationCollectionMapper daPassingStationCollectionMapper;
e57a89 59
054a69 60     @Resource
61     private SqlSessionFactory sqlSessionFactory;
62
ddb300 63     @Autowired
A 64     private IDaParamCollectionService daParamCollectionService;
65
e57a89 66     /**
67      * 查询设备产品过程参数采集
68      * 
69      * @param id 设备产品过程参数采集主键
70      * @return 设备产品过程参数采集
71      */
72     @Override
73     public DaParamCollection selectDaParamCollectionById(Long id)
74     {
75         return daParamCollectionMapper.selectDaParamCollectionById(id);
76     }
77
78     /**
79      * 查询设备产品过程参数采集列表
80      * 
81      * @param daParamCollection 设备产品过程参数采集
82      * @return 设备产品过程参数采集
83      */
84     @Override
85     public List<DaParamCollection> selectDaParamCollectionList(DaParamCollection daParamCollection)
86     {
87         return daParamCollectionMapper.selectDaParamCollectionList(daParamCollection);
054a69 88     }
89
90     @Override
91     public void saveBeachDaParamCollection(List<DaParamCollection> list) {
92         // ExecutorType.SIMPLE: 这个执行器类型不做特殊的事情。它为每个语句的执行创建一个新的预处理语句。
93         // ExecutorType.REUSE: 这个执行器类型会复用预处理语句。
94         // ExecutorType.BATCH: 这个执行器会批量执行所有更新语句,如果 SELECT 在它们中间执行还会标定它们是 必须的,来保证一个简单并易于理解的行为。
95
96         // 关闭session的自动提交
97         SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
98         try {
99             DaParamCollectionMapper userMapper = sqlSession.getMapper(DaParamCollectionMapper.class);
100             list.stream().forEach(DaParamCollection -> userMapper.insertDaParamCollection(DaParamCollection));
101             // 提交数据
102             sqlSession.commit();
103             sqlSession.rollback();
104         } catch (Exception e) {
105             sqlSession.rollback();
106         } finally {
107             sqlSession.close();
108         }
e57a89 109     }
110
111     /**
112      * 新增设备产品过程参数采集
113      * 
114      * @param daParamCollection 设备产品过程参数采集
115      * @return 结果
116      */
117     @Override
118     public int insertDaParamCollection(DaParamCollection daParamCollection)
119     {
120         daParamCollection.setCreateTime(DateUtils.getNowDate());
121         return daParamCollectionMapper.insertDaParamCollection(daParamCollection);
122     }
123
124     /**
125      * 修改设备产品过程参数采集
126      * 
127      * @param daParamCollection 设备产品过程参数采集
128      * @return 结果
129      */
130     @Override
131     public int updateDaParamCollection(DaParamCollection daParamCollection)
132     {
133         daParamCollection.setUpdateTime(DateUtils.getNowDate());
134         return daParamCollectionMapper.updateDaParamCollection(daParamCollection);
135     }
136
137     /**
138      * 批量删除设备产品过程参数采集
139      * 
140      * @param ids 需要删除的设备产品过程参数采集主键
141      * @return 结果
142      */
143     @Override
144     public int deleteDaParamCollectionByIds(Long[] ids)
145     {
146         return daParamCollectionMapper.deleteDaParamCollectionByIds(ids);
147     }
148
149     /**
150      * 删除设备产品过程参数采集信息
151      * 
152      * @param id 设备产品过程参数采集主键
153      * @return 结果
154      */
155     @Override
156     public int deleteDaParamCollectionById(Long id)
157     {
158         return daParamCollectionMapper.deleteDaParamCollectionById(id);
159     }
b64ed2 160
161     @Override
162     public void addBasicParameters(DaParamCollection daParamCollection) {
163         // 假设这是从数据库或其他地方获取的参数数据
164         Map<String, String> map = new HashMap<>();
165         map.put("GC", "南浔工厂");
166         map.put("CXBH", "Pack线");
167         map.put("SBBH", "设备001");
168         map.put("YGBH", "员工001");
169         map.put("GDBH", daParamCollection.getWorkOrderNo());
170         map.put("CPXH", daParamCollection.getModel());
171         map.put("INT", DateUtil.formatDateTime(new Date()));
172
173         map.forEach((key, value) -> {
174             DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
175             daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
176             daCollectionParamConf.setCollectParameterId(key);
177             List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
178             DaParamCollection saveData = new DaParamCollection();
179             saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
180             saveData.setProductCode(daParamCollection.getProductCode());
181             saveData.setLocationCode(daParamCollection.getLocationCode());
3c2299 182             saveData.setSfcCode(daParamCollection.getProductBarcode());
b64ed2 183             saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
184             saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
185             saveData.setCollectionTime(new Date());
186             saveData.setParamValue(value);
187             daParamCollectionMapper.insertDaParamCollection(saveData);
188         });
189     }
49c784 190
191     @Override
192     public void addTighteningParameters(DaParamCollection daParamCollection) {
b77c7b 193         String tightenData = daParamCollection.getTightenTheArray();
194         tightenData = tightenData.replace("[", "").replace("]", "").replace(" ", "");
195         String[] tightenDataParts = tightenData.split(",");
196         String paramCode = daParamCollection.getParamCode();
197         String[] paramCodeParts = paramCode.split(",");
198         for (int i = 0; i < paramCodeParts.length; i++) {
199             daParamCollection.setParamValue(tightenDataParts[i]);
200             daParamCollection.setParamCode(paramCodeParts[i]);
201             daParamCollection.setCollectionTime(new Date());
202             daParamCollection.setSfcCode(daParamCollection.getProductBarcode());
203             daParamCollectionMapper.insertDaParamCollection(daParamCollection);
204         }
49c784 205     }
32483a 206
207     @Override
208     public void saveCampaignTimeParameters(DaParamCollection daParamCollection) {
7bee80 209         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
210                 .eq(BsFormulaChildInfo::getProcessesCode, daParamCollection.getLocationCode())
211                 .eq(BsFormulaChildInfo::getSpareField4, "1")
212         );
213         if(!list.get(0).getResults().equals("OK")){
214             try {
215                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(22).build());
216             } catch (Exception e) {
217                 throw new RuntimeException(e);
218             }
219             return;
220         }
32483a 221         BsFormulaChildInfo bsFormulaChildInfo = new BsFormulaChildInfo();
222         bsFormulaChildInfo.setProcessesCode(daParamCollection.getLocationCode());
223         bsFormulaChildInfo.setProductCode(daParamCollection.getProductCode());
224         bsFormulaChildInfo.setSpareField4("1");
225         List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(bsFormulaChildInfo);
226         String result = bsFormulaChildInfos.get(0).getResults();
227         if(result != null && !result.isEmpty()){
228             try {
229                 //过站参数采集记录出站时间
230                 DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
231                 daCollectionParamConf.setProcessesCode(daParamCollection.getLocationCode());
232                 daCollectionParamConf.setCollectParameterId("OUTT");
233                 List<DaCollectionParamConf> daCollectionParamConfs = daCollectionParamConfMapper.selectDaCollectionParamConfList(daCollectionParamConf);
234                 DaParamCollection saveData = new DaParamCollection();
235                 saveData.setWorkOrderNo(daParamCollection.getWorkOrderNo());
236                 saveData.setProductCode(daParamCollection.getProductCode());
237                 saveData.setLocationCode(daParamCollection.getLocationCode());
238                 saveData.setSfcCode(daParamCollection.getProductBarcode());
239                 saveData.setParamCode(daCollectionParamConfs.get(0).getCollectParameterId());
240                 saveData.setParamName(daCollectionParamConfs.get(0).getCollectParameterName());
241                 saveData.setCollectionTime(new Date());
242                 saveData.setParamValue(DateUtil.formatDateTime(new Date()));
243                 daParamCollectionMapper.insertDaParamCollection(saveData);
244
245                 //更新过站记录表出站时间
246                 DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
247                 daPassingStationCollection.setWorkOrderNo(daParamCollection.getWorkOrderNo());
1df825 248                 daPassingStationCollection.setLocationCode(daParamCollection.getLocationCode());
32483a 249                 List<DaPassingStationCollection> daPassingStationCollections = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection);
250                 daPassingStationCollections.get(0).setOutboundTime(new Date());
251                 int i = daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
252
8f0f8d 253 //                OPCUaSubscription.SaveParamData(daParamCollection.getProductBarcode(),"OP",daParamCollection.getLocationCode(),daParamCollection.getWorkOrderNo(),daParamCollection.getProductCode());
054a69 254
32483a 255                 //给opc发21
7bee80 256                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+daParamCollection.getLocationCode()+".RecordDataDone").value(21).build());
32483a 257             } catch (Exception e) {
258                 throw new RuntimeException(e);
259             }
260         }
261     }
8f0f8d 262
263     @Override
264     public void insertBatch(List<DaParamCollection> confList){
265         try{
266             this.saveBatch(confList);
267         }catch (Exception e){
268             return;
269         }
270
271     }
ddb300 272
A 273     @Override
274     public void replaceAssemblyCode(DaParamCollection daParamCollection) {
275         List<DaParamCollection> list = daParamCollectionService.list(new LambdaQueryWrapper<DaParamCollection>()
276                 .eq(DaParamCollection::getSfcCode, daParamCollection.getSfcCode())
277                 .eq(DaParamCollection::getLocationCode, daParamCollection.getLocationCode())
278         );
279         if(list.size() > 0){
280             for (DaParamCollection paramCollection : list) {
281                 paramCollection.setSfcCode(daParamCollection.getYzSfcCode());
282                 daParamCollectionService.saveOrUpdate(paramCollection);
283             }
284         }
285
286     }
e57a89 287 }