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