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