-
懒羊羊
2024-04-15 63b2548414682dd0127f0bffe3313ea465046957
提交 | 用户 | 时间
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
63b254 42     private IBsFormulaChildInfoService bsFormulaChildInfoService;
43
44     @Autowired
b64ed2 45     private DaParamCollectionMapper daParamCollectionMapper;
3c2299 46
47     @Autowired
48     private MiloService miloService;
32483a 49
50     @Autowired
51     private DaPassingStationCollectionMapper daPassingStationCollectionMapper;
3c2299 52
53     Map<String, Session> map = WebSocketUsers.getUsers();
e57a89 54
55     /**
56      * 查询配方配置子信息
57      * 
58      * @param id 配方配置子信息主键
59      * @return 配方配置子信息
60      */
61     @Override
62     public BsFormulaChildInfo selectBsFormulaChildInfoById(Long id)
63     {
64         return bsFormulaChildInfoMapper.selectBsFormulaChildInfoById(id);
65     }
66
67     /**
68      * 查询配方配置子信息列表
69      * 
70      * @param bsFormulaChildInfo 配方配置子信息
71      * @return 配方配置子信息
72      */
73     @Override
74     public List<BsFormulaChildInfo> selectBsFormulaChildInfoList(BsFormulaChildInfo bsFormulaChildInfo)
75     {
76         return bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(bsFormulaChildInfo);
77     }
78
79     /**
80      * 新增配方配置子信息
81      * 
82      * @param bsFormulaChildInfo 配方配置子信息
83      * @return 结果
84      */
85     @Override
86     public int insertBsFormulaChildInfo(BsFormulaChildInfo bsFormulaChildInfo)
87     {
88         bsFormulaChildInfo.setCreateTime(DateUtils.getNowDate());
89         return bsFormulaChildInfoMapper.insertBsFormulaChildInfo(bsFormulaChildInfo);
90     }
91
92     /**
93      * 修改配方配置子信息
94      * 
95      * @param bsFormulaChildInfo 配方配置子信息
96      * @return 结果
97      */
98     @Override
99     public int updateBsFormulaChildInfo(BsFormulaChildInfo bsFormulaChildInfo)
100     {
101         bsFormulaChildInfo.setUpdateTime(DateUtils.getNowDate());
102         return bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfo);
103     }
104
105     /**
106      * 批量删除配方配置子信息
107      * 
108      * @param ids 需要删除的配方配置子信息主键
109      * @return 结果
110      */
111     @Override
112     public int deleteBsFormulaChildInfoByIds(Long[] ids)
113     {
114         return bsFormulaChildInfoMapper.deleteBsFormulaChildInfoByIds(ids);
115     }
116
117     /**
118      * 删除配方配置子信息信息
119      * 
120      * @param id 配方配置子信息主键
121      * @return 结果
122      */
123     @Override
124     public int deleteBsFormulaChildInfoById(Long id)
125     {
126         return bsFormulaChildInfoMapper.deleteBsFormulaChildInfoById(id);
127     }
128
129     @Override
130     public BsFormulaChildInfo selectBsFormulaChildInfoByTypeTopOne(String type,String productCode,String processesCode) {
131         BsFormulaChildInfo info = new BsFormulaChildInfo();
132         info.setOperationType(type);
133         info.setProcessesCode(processesCode);
134         info.setProductCode(productCode);
135         return bsFormulaChildInfoMapper.selectBsFormulaChildInfoByTypeTopOne(info);
136     }
137
138     @Override
b77303 139     public BsFormulaChildInfo getCount(String productCode, String processesCode) {
140         BsFormulaChildInfo info = new BsFormulaChildInfo();
141         info.setProcessesCode(processesCode);
142         info.setProductCode(productCode);
143         return bsFormulaChildInfoMapper.getCount(info);
144     }
145
146     @Override
147     public BsFormulaChildInfo releaseCheck(BsFormulaChildInfo bsFormulaChildInfo) {
e57a89 148         return bsFormulaChildInfoMapper.releaseCheck(bsFormulaChildInfo);
149     }
150
c5e9c5 151     //1-非本工位物料 2-正常扫描可继续下次 3-扫描结束已经是最后一位工步
e57a89 152     @Override
153     public AjaxResult updateResults(BsFormulaChildInfo bsFormulaChildInfo) {
c5e9c5 154         String result = "";
b77303 155         BsFormulaChildInfo checkInfo = new BsFormulaChildInfo();
156         checkInfo.setProcessesCode(bsFormulaChildInfo.getLocationCode());
157         checkInfo.setProductCode(bsFormulaChildInfo.getProductCode());
63b254 158         checkInfo.setMaterialCode(bsFormulaChildInfo.getScanBarcode());
b5fcd8 159 //        bsFormulaChildInfo.setMaterialCode(bsFormulaChildInfo.getScanBarcode().substring(1,2));
160         List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(checkInfo);
e57a89 161         if(bsFormulaChildInfos.size()>0){
c5e9c5 162             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
3c2299 163             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getScanBarcode());
e57a89 164             bsFormulaChildInfos.get(0).setResults("OK");
165             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
49c784 166             bsFormulaChildInfo.setParamValue(bsFormulaChildInfo.getScanBarcode());
b64ed2 167             bsFormulaChildInfo.setParamCode(bsFormulaChildInfos.get(0).getParamCode());
49c784 168             bsFormulaChildInfo.setSfcBarcode(bsFormulaChildInfo.getSfcBarcode());
b64ed2 169             addParameterCollection(bsFormulaChildInfo);
c5e9c5 170             if (spareField4 != null && !spareField4.isEmpty()) {
171                 // 执行操作
172                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
173                     try {
174                         result = "3";
175                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".RecordDataDone").value(21).build());
176                     } catch (Exception e) {
177                         throw new RuntimeException(e);
178                     }
179                 }
180             }
e57a89 181         }else {
c5e9c5 182             result = "1";
e57a89 183         }
c5e9c5 184         return AjaxResult.success(result);
e57a89 185     }
186
b64ed2 187     public void addParameterCollection(BsFormulaChildInfo bsFormulaChildInfo){
188         DaParamCollection daParamCollection = new DaParamCollection();
189         daParamCollection.setParamCode(bsFormulaChildInfo.getParamCode());
190         daParamCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo());
191         daParamCollection.setLocationCode(bsFormulaChildInfo.getLocationCode());
192         daParamCollection.setParamValue(bsFormulaChildInfo.getParamValue());
193         daParamCollection.setProductCode(bsFormulaChildInfo.getProductCode());
194         daParamCollection.setCollectionTime(new Date());
49c784 195         daParamCollection.setSfcCode(bsFormulaChildInfo.getSfcBarcode());
b64ed2 196         daParamCollectionMapper.insertDaParamCollection(daParamCollection);
197     }
198
e57a89 199     @Override
200     public AjaxResult workpieceRelease(BsFormulaChildInfo bsFormulaChildInfo) {
63b254 201         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
202                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
203                 .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
204         for (BsFormulaChildInfo info : list) {
205             info.setSpareField4("");
206             info.setResults("");
207             bsFormulaChildInfoService.saveOrUpdate(info);
208         }
e57a89 209         return AjaxResult.success();
210     }
b77303 211
212     @Override
213     public AjaxResult updateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo) {
7bee80 214         BsFormulaChildInfo getMaterTwo = new BsFormulaChildInfo();
215         getMaterTwo.setProcessesCode(bsFormulaChildInfo.getLocationCode());
216         getMaterTwo.setOperationType("2");
217         List<BsFormulaChildInfo> operationType = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(getMaterTwo);
218         List<String> collect = operationType.stream().map(BsFormulaChildInfo::getResults).collect(Collectors.toList());
219         for (String s : collect) {
220             if(s.equals("")){
221                 return AjaxResult.error("扫描未完成,禁止拧紧操作!");
222             }
223         }
b77303 224         BsFormulaChildInfo listQuery = new BsFormulaChildInfo();
225         listQuery.setParamCode(bsFormulaChildInfo.getParamCode());
226         String paramCode = bsFormulaChildInfo.getTightenTheArray();
227         if(paramCode.contains("N")){
228             List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
229             bsFormulaChildInfos.get(0).setResults("NG");
230             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
231             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
232             return AjaxResult.error("扫描结果NG,请重新扫描!");
233         }else {
234             List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
235             bsFormulaChildInfos.get(0).setResults("OK");
236             bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
237             bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
3c2299 238             String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
239             if (spareField4 != null && !spareField4.isEmpty()) {
240                 // 执行操作
241                 if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
242                     try {
32483a 243 //                        //更新过站记录表出站时间
244 //                        DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
245 //                        daPassingStationCollection.setWorkOrderNo(bsFormulaChildInfo.getWorkOrderNo());
246 //                        List<DaPassingStationCollection> daPassingStationCollections = daPassingStationCollectionMapper.selectDaPassingStationCollectionList(daPassingStationCollection);
247 //                        daPassingStationCollections.get(0).setOutboundTime(new Date());
248 //                        daPassingStationCollectionMapper.updateDaPassingStationCollection(daPassingStationCollections.get(0));
b5fcd8 249                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".RecordDataDone").value(21).build());
3c2299 250                         WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), "OUT");
251                     } catch (Exception e) {
252                         throw new RuntimeException(e);
253                     }
254                 }
255             }
256
b77303 257         }
258         return AjaxResult.success("扫描成功!");
259     }
260
261
262
263
e57a89 264 }