cheng
2023-12-12 c64c9f6fb38f65be99b827c1af8d3c3852f68ba4
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.modular.rm.recipeManage.service.impl;
2
3 import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
4 import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
5 import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
6 import cn.stylefeng.guns.modular.bs.collectionParamConf.entity.CollectionParamConf;
7 import cn.stylefeng.guns.modular.bs.collectionParamConf.service.CollectionParamConfService;
8 import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam;
9 import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
10 import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
11 import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
12 import cn.stylefeng.guns.modular.rm.recipeManage.entity.RecipeManage;
13 import cn.stylefeng.guns.modular.rm.recipeManage.mapper.RecipeManageMapper;
14 import cn.stylefeng.guns.modular.rm.recipeManage.model.params.RecipeManageParam;
15 import cn.stylefeng.guns.modular.rm.recipeManage.model.result.RecipeManageResult;
16 import  cn.stylefeng.guns.modular.rm.recipeManage.service.RecipeManageService;
17 import cn.stylefeng.roses.core.util.ToolUtil;
18 import cn.stylefeng.roses.kernel.model.response.ResponseData;
19 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
20 import com.baomidou.mybatisplus.core.metadata.IPage;
21 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
22 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.security.core.parameters.P;
25 import org.springframework.stereotype.Service;
26
27 import java.io.Serializable;
28 import java.util.Date;
29 import java.util.List;
30
31 /**
32  * <p>
33  * 配方管理 服务实现类
34  * </p>
35  *
36  * @author ruimin
37  * @since 2023-08-04
38  */
39 @Service
40 public class RecipeManageServiceImpl extends ServiceImpl<RecipeManageMapper, RecipeManage> implements RecipeManageService {
41     @Autowired
42     RecipeManageService recipeManageService;
43
44     //物料追溯
45     @Autowired
46     MaterialTraceabilityService materialTraceabilityService;
47
48     //设备产品过程参数采集
49     @Autowired
50     ParamCollectionService paramCollectionService;
51
52     //参数采集配置基础数据表
53     @Autowired
54     CollectionParamConfService collectionParamConfService;
55
56
57     @Override
58     public void add(RecipeManageParam param){
59         RecipeManage entity = getEntity(param);
60         this.save(entity);
61     }
62
63     @Override
64     public void delete(RecipeManageParam param){
65         this.removeById(getKey(param));
66     }
67
68     @Override
69     public void update(RecipeManageParam param){
70         RecipeManage oldEntity = getOldEntity(param);
71         RecipeManage newEntity = getEntity(param);
72         ToolUtil.copyProperties(newEntity, oldEntity);
73         this.updateById(newEntity);
74     }
75
76     @Override
77     public RecipeManageResult findBySpec(RecipeManageParam param){
78         return null;
79     }
80
81     @Override
82     public List<RecipeManageResult> findListBySpec(RecipeManageParam param){
83         return null;
84     }
85
86     @Override
87     public LayuiPageInfo findPageBySpec(RecipeManageParam param){
88         Page pageContext = getPageContext();
89         IPage page = this.baseMapper.customPageList(pageContext, param);
90         List<RecipeManageResult> result = page.getRecords();
91         try {
92             for (RecipeManageResult recipeManageResult : result) {
93                 switch (recipeManageResult.getOperationType()){
94                     case "1":
95                         recipeManageResult.setOperationType("扫描产品条码类");
96                         break;
97                     case "2":
98                         recipeManageResult.setOperationType("扫描物料类");
99                         break;
100                     case "3":
101                         recipeManageResult.setOperationType("拧紧类");
102                         break;
103                     default:
104                 }
105             }
106         }catch (Exception e){
107             e.printStackTrace();
108         }
109         return LayuiPageFactory.createPageInfo(page);
110     }
111
112     @Override
113     public LayuiPageInfo viewList(RecipeManageParam param) {
114         Page pageContext = getPageContext();
115         IPage page = this.baseMapper.customPageList(pageContext, param);
116         return LayuiPageFactory.createPageInfo(page);
117     }
118
119     @Override
120     public String editItemView(RecipeManageParam param) {
121         List<RecipeManage> list = listRecipeManage(param);
122         Integer i = 0;
123         for (RecipeManage recipeManage : list) {
124             if(recipeManage.getSpareField3().equals("OK")){
125                 i = i+1;
126             }
127         }
128         if(list.size() == i){
129             return "已全部扫描完成请确认!";
130         }
131         for (RecipeManage recipeManage : list) {
132             if(recipeManage.getSpareField3().equals("NG")){
133                 switch(recipeManage.getOperationType()){
134                     case "2":
135                         if(param.getSoketData().contains(recipeManage.getMaterialCode())){
136                             recipeManage.setSpareField1(param.getSoketData());
137                             recipeManage.setSpareField3("OK");
138                             recipeManageService.saveOrUpdate(recipeManage);
139                         }else {
140                             recipeManage.setSpareField1(param.getSoketData());
141                             recipeManage.setSpareField3("NG");
142                             recipeManageService.saveOrUpdate(recipeManage);
143                             return "您扫描的条码不对结果为NG"+param.getSoketData();
144                         }
145                         break;
146                     case "3" :
147                             String[] parmCode;
148                             String delimiter = ",";// 指定分割字符
149                             parmCode = param.getSoketData().split(delimiter);
150                             if(parmCode[2].equals("1")){
151                                 recipeManage.setSpareField2(param.getSoketData());
152                                 recipeManage.setSpareField3("OK");
153                                 recipeManageService.saveOrUpdate(recipeManage);
154                             }else {
155                                 recipeManage.setSpareField2(param.getSoketData());
156                                 recipeManage.setSpareField3("NG");
157                                 recipeManageService.saveOrUpdate(recipeManage);
158                                 return "扫描的拧紧数结果NG!请重新扫描";
159                             }
160                         break;
161                     default:
162                 }
163                 return "扫描成功";
164             }
165             if(recipeManage.getSpareField3()==null||recipeManage.getSpareField3().equals("")){
166                 switch(recipeManage.getOperationType()){
167                     case "1":
168                         recipeManage.setSpareField1(param.getSoketData());
169                         recipeManage.setSpareField3("OK");
170                         break;
171                     case "2":
172                         if(param.getSoketData().contains(recipeManage.getMaterialCode())){
173                             recipeManage.setSpareField1(param.getSoketData());
174                             recipeManage.setSpareField3("OK");
175                         }else {
176                             recipeManage.setSpareField1(param.getSoketData());
177                             recipeManage.setSpareField3("NG");
178 //                            return "您扫描的物料条码为"+param.getSoketData()+"文本格式不对,请重新扫描";
179                         }
180                         break;
181                     case "3" :
182                         if(param.getSoketData().contains(",")){
183                             String[] parmCode;
184                             String delimiter = ",";// 指定分割字符
185                             parmCode = param.getSoketData().split(delimiter);
186                             if(parmCode[2].equals("1")){
187                                 recipeManage.setSpareField2(param.getSoketData());
188                                 recipeManage.setSpareField3("OK");
189                                 recipeManageService.saveOrUpdate(recipeManage);
190                                 return "扫描成功";
191                             }else {
192 //                                return "您扫描的拧紧枪数据为"+param.getSoketData()+"结果NG请重新扫描";
193                                 recipeManage.setSpareField2(param.getSoketData());
194                                 recipeManage.setSpareField3("NG");
195                                 recipeManageService.saveOrUpdate(recipeManage);
196                                 return "扫描的拧紧数结果NG!请重新扫描";
197                             }
198                         }else {
199 //                            return "您扫描的拧紧枪数据为"+param.getSoketData()+"文本格式不对,请重新扫描";
200                             recipeManage.setSpareField2(param.getSoketData());
201                             recipeManage.setSpareField3("NG");
202                             recipeManageService.saveOrUpdate(recipeManage);
203                             return "扫描的拧紧数据格式不对!请重新扫描";
204                         }
205 //                        break;
206                     default:
207                 }
208 //                recipeManage.setSpareField3("OK");
209                 recipeManageService.saveOrUpdate(recipeManage);
210                 break;
211             }
212 //            else {
213 //                return "已全部扫描请确认完成!";
214 //            }
215         }
216         return "扫描成功";
217     }
218
219     @Override
220     public Integer finish(RecipeManageParam param) {
221         String sfc = "";
222         Integer i = 0;
223         List<RecipeManage> recipeManages = listRecipeManage(param);
224         for (RecipeManage recipeManage : recipeManages) {
225             if(recipeManage.getSpareField3()==null||recipeManage.getSpareField3().equals("")){
226                 i+=1;
227             }
228         }
229         if(i>0){
230             return i;
231         }else {
232             //保存需要的表
233             for (RecipeManage recipeManage : recipeManages) {
234                 if(recipeManage.getSpareField3()!=null||!recipeManage.getSpareField3().equals("")) {
235                     switch (recipeManage.getOperationType()) {
236                         case "1":
237                             sfc = recipeManage.getSpareField1();
238                             break;
239                         case "2":
240                             MaterialTraceabilityParam materialParam = new MaterialTraceabilityParam();
241                             materialParam.setProductNo(recipeManage.getSpareField1());
242                             materialParam.setWorkOrderNo(param.getWorkOrderNo());
243                             materialParam.setProductCode(param.getProductCode());
244                             materialParam.setLineCode(param.getLineCode());
245                             materialParam.setMaterialCode(recipeManage.getMaterialCode());
246                             materialParam.setLocationCode(param.getLocationCode());
247                             materialParam.setAssemblyTime(new Date());
248                             materialParam.setAssemblyUser(LoginContextHolder.getContext().getUser().getName());
249                             materialTraceabilityService.add(materialParam);
250                             break;
251                         case "3":
252                             String[] temp;
253                             String[] parmCode;
254                             String delimiter = ",";// 指定分割字符
255                             temp = recipeManage.getSpareField2().split(delimiter);// 分割字符串
256                             parmCode = recipeManage.getParamCode().split(delimiter);
257                             for (int i1 = 0; i1 < 3; i1++) {
258                                 CollectionParamConf paramOne = collectionParamConfService.getOne(new QueryWrapper<CollectionParamConf>().eq("param_code", parmCode[i1]));
259                                 ParamCollectionParam deviceParam = new ParamCollectionParam();
260                                 deviceParam.setSfcCode(sfc);
261                                 deviceParam.setWorkOrderNo(param.getWorkOrderNo());
262                                 deviceParam.setProductCode(param.getProductCode());
263                                 deviceParam.setLocationCode(param.getLocationCode());
264                                 deviceParam.setProductionLine(param.getLineCode());
265                                 deviceParam.setParamValue(temp[i1]);
266                                 deviceParam.setParamCode(parmCode[i1]);
267                                 deviceParam.setCollectionTime(new Date());
268                                 deviceParam.setParamName(paramOne.getParamName());
269                                 deviceParam.setUnit(paramOne.getUnit());
270                                 deviceParam.setParamUpper(paramOne.getParamUpper());
271                                 deviceParam.setParamLower(paramOne.getParamLower());
272                                 deviceParam.setParamStandard(paramOne.getParamCentral());
273                                 paramCollectionService.add(deviceParam);
274                             }
275                             break;
276                         default:
277                     }
278                 }
279             }
280             //删除数据重新加载列表
281             List<RecipeManage> list = listRecipeManage(param);
282             for (RecipeManage recipeManage : list) {
283                 recipeManage.setSpareField1("");
284                 recipeManage.setSpareField2("");
285                 recipeManage.setSpareField3("");
286                 recipeManageService.saveOrUpdate(recipeManage);
287             }
288             if(list.size() == 0){
289                 return 980;
290             }
291             return i;
292         }
293     }
294
295     @Override
296     public void heavyLoad(RecipeManageParam recipeManageParam) {
297         List<RecipeManage> list = listRecipeManage(recipeManageParam);
298         for (RecipeManage recipeManage : list) {
299             recipeManage.setSpareField1("");
300             recipeManage.setSpareField2("");
301             recipeManage.setSpareField3("");
302             recipeManageService.saveOrUpdate(recipeManage);
303         }
304     }
305
306     @Override
307     public void singleRowDelete(RecipeManageParam recipeManageParam) {
308         RecipeManage byId = recipeManageService.getById(recipeManageParam.getId());
309         byId.setSpareField1("");
310         byId.setSpareField2("");
311         byId.setSpareField3("");
312         recipeManageService.saveOrUpdate(byId);
313     }
314
315     public List<RecipeManage> listRecipeManage(RecipeManageParam param) {
316         List<RecipeManage> list = recipeManageService.list(new QueryWrapper<RecipeManage>()
317                 .eq("location_code", param.getLocationCode())
318                 .eq("product_code", param.getProductCode())
319                 .orderByAsc("step_sort")
320         );
321         return list;
322     }
323
324     private Serializable getKey(RecipeManageParam param){
325         return param.getId();
326     }
327
328     private Page getPageContext() {
329         return LayuiPageFactory.defaultPage();
330     }
331
332     private RecipeManage getOldEntity(RecipeManageParam param) {
333         return this.getById(getKey(param));
334     }
335
336     private RecipeManage getEntity(RecipeManageParam param) {
337         RecipeManage entity = new RecipeManage();
338         ToolUtil.copyProperties(param, entity);
339         return entity;
340     }
341
342 }