-
admin
2024-04-29 2c7661d0bca739a9b403cdd420d2b91eb77470e6
提交 | 用户 | 时间
e57a89 1 package com.jcdm.main.bs.formulaChild.service.impl;
2
5316c5 3 import java.util.ArrayList;
b64ed2 4 import java.util.Date;
e57a89 5 import java.util.List;
3c2299 6 import java.util.Map;
7bee80 7 import java.util.stream.Collectors;
e57a89 8
7bee80 9 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
10 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
0ce25f 11 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
e57a89 12 import com.jcdm.common.core.domain.AjaxResult;
13 import com.jcdm.common.utils.DateUtils;
3c2299 14 import com.jcdm.framework.websocket.WebSocketUsers;
b64ed2 15 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
16 import com.jcdm.main.da.paramCollection.mapper.DaParamCollectionMapper;
32483a 17 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
18 import com.jcdm.main.da.passingStationCollection.mapper.DaPassingStationCollectionMapper;
3c2299 19 import com.kangaroohy.milo.model.ReadWriteEntity;
20 import com.kangaroohy.milo.service.MiloService;
b77303 21 import org.aspectj.weaver.loadtime.Aj;
e57a89 22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.stereotype.Service;
24 import com.jcdm.main.bs.formulaChild.mapper.BsFormulaChildInfoMapper;
25 import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo;
26 import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService;
3c2299 27
28 import javax.websocket.Session;
e57a89 29
30 /**
31  * 配方配置子信息Service业务层处理
32  * 
33  * @author ruimin
34  * @date 2023-12-26
35  */
36 @Service
0ce25f 37 public class BsFormulaChildInfoServiceImpl extends ServiceImpl<BsFormulaChildInfoMapper,BsFormulaChildInfo> implements IBsFormulaChildInfoService
e57a89 38 {
39     @Autowired
40     private BsFormulaChildInfoMapper bsFormulaChildInfoMapper;
b64ed2 41
42     @Autowired
63b254 43     private IBsFormulaChildInfoService bsFormulaChildInfoService;
44
45     @Autowired
b64ed2 46     private DaParamCollectionMapper daParamCollectionMapper;
3c2299 47
48     @Autowired
49     private MiloService miloService;
32483a 50
51     @Autowired
52     private DaPassingStationCollectionMapper daPassingStationCollectionMapper;
3c2299 53
54     Map<String, Session> map = WebSocketUsers.getUsers();
e57a89 55
56     /**
57      * 查询配方配置子信息
58      * 
59      * @param id 配方配置子信息主键
60      * @return 配方配置子信息
61      */
62     @Override
63     public BsFormulaChildInfo selectBsFormulaChildInfoById(Long id)
64     {
65         return bsFormulaChildInfoMapper.selectBsFormulaChildInfoById(id);
66     }
67
68     /**
69      * 查询配方配置子信息列表
70      * 
71      * @param bsFormulaChildInfo 配方配置子信息
72      * @return 配方配置子信息
73      */
74     @Override
75     public List<BsFormulaChildInfo> selectBsFormulaChildInfoList(BsFormulaChildInfo bsFormulaChildInfo)
76     {
77         return bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(bsFormulaChildInfo);
78     }
79
80     /**
81      * 新增配方配置子信息
82      * 
83      * @param bsFormulaChildInfo 配方配置子信息
84      * @return 结果
85      */
86     @Override
87     public int insertBsFormulaChildInfo(BsFormulaChildInfo bsFormulaChildInfo)
88     {
89         bsFormulaChildInfo.setCreateTime(DateUtils.getNowDate());
90         return bsFormulaChildInfoMapper.insertBsFormulaChildInfo(bsFormulaChildInfo);
91     }
92
93     /**
94      * 修改配方配置子信息
95      * 
96      * @param bsFormulaChildInfo 配方配置子信息
97      * @return 结果
98      */
99     @Override
100     public int updateBsFormulaChildInfo(BsFormulaChildInfo bsFormulaChildInfo)
101     {
102         bsFormulaChildInfo.setUpdateTime(DateUtils.getNowDate());
103         return bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfo);
104     }
105
106     /**
107      * 批量删除配方配置子信息
108      * 
109      * @param ids 需要删除的配方配置子信息主键
110      * @return 结果
111      */
112     @Override
113     public int deleteBsFormulaChildInfoByIds(Long[] ids)
114     {
115         return bsFormulaChildInfoMapper.deleteBsFormulaChildInfoByIds(ids);
116     }
117
118     /**
119      * 删除配方配置子信息信息
120      * 
121      * @param id 配方配置子信息主键
122      * @return 结果
123      */
124     @Override
125     public int deleteBsFormulaChildInfoById(Long id)
126     {
127         return bsFormulaChildInfoMapper.deleteBsFormulaChildInfoById(id);
128     }
129
130     @Override
131     public BsFormulaChildInfo selectBsFormulaChildInfoByTypeTopOne(String type,String productCode,String processesCode) {
132         BsFormulaChildInfo info = new BsFormulaChildInfo();
133         info.setOperationType(type);
134         info.setProcessesCode(processesCode);
135         info.setProductCode(productCode);
136         return bsFormulaChildInfoMapper.selectBsFormulaChildInfoByTypeTopOne(info);
137     }
138
139     @Override
b77303 140     public BsFormulaChildInfo getCount(String productCode, String processesCode) {
141         BsFormulaChildInfo info = new BsFormulaChildInfo();
142         info.setProcessesCode(processesCode);
143         info.setProductCode(productCode);
144         return bsFormulaChildInfoMapper.getCount(info);
145     }
146
147     @Override
2c7661 148     public AjaxResult yzUpdateResults(BsFormulaChildInfo bsFormulaChildInfo) {
A 149         String result = "";
150         List<BsFormulaChildInfo> bsFormulaChildInfos = new ArrayList<>();
151         List<BsFormulaChildInfo> infos = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
152                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
153                 .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode())
154                 .eq(BsFormulaChildInfo::getOperationType, "2")
155         );
156         for (BsFormulaChildInfo formulaChildInfo : infos) {
157             if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())){
158                 bsFormulaChildInfos.add(formulaChildInfo);
159                 break;
160             }
161         }
162         if(bsFormulaChildInfos.size()>0){
163             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
164             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getScanBarcode());
165             bsFormulaChildInfos.get(0).setResults("OK");
166             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
167             bsFormulaChildInfo.setParamValue(bsFormulaChildInfo.getScanBarcode());
168             bsFormulaChildInfo.setParamCode(bsFormulaChildInfos.get(0).getParamCode());
169             bsFormulaChildInfo.setSfcBarcode(bsFormulaChildInfo.getSfcBarcode());
170             addParameterCollection(bsFormulaChildInfo);
171             if (spareField4 != null && !spareField4.isEmpty()) {
172                 // 执行操作
173                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
174                     try {
175                         result = "3";
176                     } catch (Exception e) {
177                         throw new RuntimeException(e);
178                     }
179                 }
180             }
181         }else {
182             result = "1";
183         }
184         return AjaxResult.success(result);
185     }
186
187     @Override
188     public AjaxResult yzUpdateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo) {
189         String result = "1";
190         BsFormulaChildInfo getMaterTwo = new BsFormulaChildInfo();
191         getMaterTwo.setProcessesCode(bsFormulaChildInfo.getLocationCode());
192         getMaterTwo.setOperationType("2");
193         List<BsFormulaChildInfo> operationType = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(getMaterTwo);
194         List<String> collect = operationType.stream().map(BsFormulaChildInfo::getResults).collect(Collectors.toList());
195         for (String s : collect) {
196             if(s.equals("")){
197                 return AjaxResult.error("扫描未完成,禁止拧紧操作!");
198             }
199         }
200         BsFormulaChildInfo listQuery = new BsFormulaChildInfo();
201         listQuery.setParamCode(bsFormulaChildInfo.getParamCode());
202         String paramCode = bsFormulaChildInfo.getTightenTheArray();
203         if(paramCode.contains("N")){
204             List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
205             bsFormulaChildInfos.get(0).setResults("NG");
206             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
207             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
208             return AjaxResult.error("扫描结果NG,请重新扫描!");
209         }else {
210             List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
211             bsFormulaChildInfos.get(0).setResults("OK");
212             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
213             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
214             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
215             if (spareField4 != null && !spareField4.isEmpty()) {
216                 // 执行操作
217                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
218                     try {
219 //                        WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), "OUT");
220                         result = "2";
221                     } catch (Exception e) {
222                         throw new RuntimeException(e);
223                     }
224                 }
225             }
226
227         }
228         return AjaxResult.success(result);
229     }
230
231     @Override
b77303 232     public BsFormulaChildInfo releaseCheck(BsFormulaChildInfo bsFormulaChildInfo) {
e57a89 233         return bsFormulaChildInfoMapper.releaseCheck(bsFormulaChildInfo);
234     }
235
c5e9c5 236     //1-非本工位物料 2-正常扫描可继续下次 3-扫描结束已经是最后一位工步
e57a89 237     @Override
238     public AjaxResult updateResults(BsFormulaChildInfo bsFormulaChildInfo) {
c5e9c5 239         String result = "";
5316c5 240         List<BsFormulaChildInfo> bsFormulaChildInfos = new ArrayList<>();
A 241         List<BsFormulaChildInfo> infos = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
e70fb4 242                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
A 243                 .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode())
5316c5 244                 .eq(BsFormulaChildInfo::getOperationType, "2")
e70fb4 245         );
5316c5 246         for (BsFormulaChildInfo formulaChildInfo : infos) {
A 247             if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())){
248                 bsFormulaChildInfos.add(formulaChildInfo);
249                 break;
250             }
251         }
e57a89 252         if(bsFormulaChildInfos.size()>0){
c5e9c5 253             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
3c2299 254             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getScanBarcode());
e57a89 255             bsFormulaChildInfos.get(0).setResults("OK");
256             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
49c784 257             bsFormulaChildInfo.setParamValue(bsFormulaChildInfo.getScanBarcode());
b64ed2 258             bsFormulaChildInfo.setParamCode(bsFormulaChildInfos.get(0).getParamCode());
49c784 259             bsFormulaChildInfo.setSfcBarcode(bsFormulaChildInfo.getSfcBarcode());
b64ed2 260             addParameterCollection(bsFormulaChildInfo);
c5e9c5 261             if (spareField4 != null && !spareField4.isEmpty()) {
262                 // 执行操作
263                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
264                     try {
265                         result = "3";
266                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".RecordDataDone").value(21).build());
267                     } catch (Exception e) {
268                         throw new RuntimeException(e);
269                     }
270                 }
271             }
e57a89 272         }else {
c5e9c5 273             result = "1";
e57a89 274         }
c5e9c5 275         return AjaxResult.success(result);
e57a89 276     }
277
b64ed2 278     public void addParameterCollection(BsFormulaChildInfo bsFormulaChildInfo){
279         DaParamCollection daParamCollection = new DaParamCollection();
280         daParamCollection.setParamCode(bsFormulaChildInfo.getParamCode());
281         daParamCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo());
282         daParamCollection.setLocationCode(bsFormulaChildInfo.getLocationCode());
283         daParamCollection.setParamValue(bsFormulaChildInfo.getParamValue());
284         daParamCollection.setProductCode(bsFormulaChildInfo.getProductCode());
285         daParamCollection.setCollectionTime(new Date());
49c784 286         daParamCollection.setSfcCode(bsFormulaChildInfo.getSfcBarcode());
b64ed2 287         daParamCollectionMapper.insertDaParamCollection(daParamCollection);
288     }
289
e57a89 290     @Override
291     public AjaxResult workpieceRelease(BsFormulaChildInfo bsFormulaChildInfo) {
63b254 292         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
293                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
294                 .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
295         for (BsFormulaChildInfo info : list) {
e70fb4 296             info.setCollectData("");
63b254 297             info.setResults("");
298             bsFormulaChildInfoService.saveOrUpdate(info);
299         }
e57a89 300         return AjaxResult.success();
301     }
b77303 302
303     @Override
304     public AjaxResult updateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo) {
7bee80 305         BsFormulaChildInfo getMaterTwo = new BsFormulaChildInfo();
306         getMaterTwo.setProcessesCode(bsFormulaChildInfo.getLocationCode());
307         getMaterTwo.setOperationType("2");
308         List<BsFormulaChildInfo> operationType = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(getMaterTwo);
309         List<String> collect = operationType.stream().map(BsFormulaChildInfo::getResults).collect(Collectors.toList());
310         for (String s : collect) {
311             if(s.equals("")){
312                 return AjaxResult.error("扫描未完成,禁止拧紧操作!");
313             }
314         }
b77303 315         BsFormulaChildInfo listQuery = new BsFormulaChildInfo();
316         listQuery.setParamCode(bsFormulaChildInfo.getParamCode());
317         String paramCode = bsFormulaChildInfo.getTightenTheArray();
318         if(paramCode.contains("N")){
319             List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
320             bsFormulaChildInfos.get(0).setResults("NG");
321             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
322             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
323             return AjaxResult.error("扫描结果NG,请重新扫描!");
324         }else {
325             List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
326             bsFormulaChildInfos.get(0).setResults("OK");
327             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
328             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
3c2299 329             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
330             if (spareField4 != null && !spareField4.isEmpty()) {
331                 // 执行操作
332                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
333                     try {
32483a 334 //                        //更新过站记录表出站时间
335 //                        DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
336 //                        daPassingStationCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo());
337 //                        List<DaPassingStationCollection> daPassingStationCollections = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection);
338 //                        daPassingStationCollections.get(0).setOutboundTime(new Date());
339 //                        daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
b5fcd8 340                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".RecordDataDone").value(21).build());
3c2299 341                         WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), "OUT");
342                     } catch (Exception e) {
343                         throw new RuntimeException(e);
344                     }
345                 }
346             }
347
b77303 348         }
349         return AjaxResult.success("扫描成功!");
350     }
351
352
353
354
e57a89 355 }