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