懒羊羊
2023-11-14 8286c62256f23bc2367a6729c0f46f84215e380b
提交 | 用户 | 时间
8286c6 1 package cn.stylefeng.guns.modular.dq.materialTraceability.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.bomInfo.entity.BomInfo;
7 import cn.stylefeng.guns.modular.bs.bomInfo.service.BomInfoService;
8 import cn.stylefeng.guns.modular.bs.lineInfo.entity.LineInfo;
9 import cn.stylefeng.guns.modular.bs.lineInfo.service.LineInfoService;
10 import cn.stylefeng.guns.modular.bs.locationInfo.entity.LocationInfo;
11 import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
12 import cn.stylefeng.guns.modular.dq.materialTraceability.entity.MaterialTraceability;
13 import cn.stylefeng.guns.modular.dq.materialTraceability.mapper.MaterialTraceabilityMapper;
14 import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
15 import cn.stylefeng.guns.modular.dq.materialTraceability.model.result.MaterialTraceabilityResult;
16 import  cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
17 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.entity.ProductionOrderBatchInfo;
18 import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
19 import cn.stylefeng.roses.core.util.ToolUtil;
20 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
21 import com.baomidou.mybatisplus.core.metadata.IPage;
22 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
23 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Service;
26
27 import java.io.Serializable;
28 import java.lang.reflect.Field;
29 import java.text.SimpleDateFormat;
30 import java.util.Date;
31 import java.util.List;
32 import java.util.stream.Stream;
33
34 /**
35  * <p>
36  * 物料追溯 服务实现类
37  * </p>
38  *
39  * @author cl
40  * @since 2022-10-29
41  */
42 @Service
43 public class MaterialTraceabilityServiceImpl extends ServiceImpl<MaterialTraceabilityMapper, MaterialTraceability> implements MaterialTraceabilityService {
44     private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
45
46     @Autowired
47     private BomInfoService bomInfoService;
48
49     @Autowired
50     private MaterialTraceabilityService traceabilityService;
51
52     @Autowired
53     private LocationInfoService locationInfoService;
54
55     @Override
56     public void add(MaterialTraceabilityParam param){
57 //        param.setAssemblyUser(LoginContextHolder.getContext().getUser().getUsername());
58 //        param.setAssemblyTime(new Date());
59 //        param.setProductNo(getSfcCode(param.getLocationCode()+"_S_SFC_CODE"));
60         MaterialTraceability entity = getEntity(param);
61         this.save(entity);
62     }
63
64     @Override
65     public void lineFeedingAddItem(MaterialTraceabilityParam param) {
66         param.setAssemblyUser(LoginContextHolder.getContext().getUser().getUsername());
67         param.setAssemblyTime(new Date());
68         param.setProductNo(getSfcCode(param.getLocationCode()+"_S_SFC_CODE"));
69         MaterialTraceability entity = getEntity(param);
70         this.save(entity);
71     }
72
73     @Override
74     public List<MaterialTraceabilityResult> exportTable(MaterialTraceabilityParam param) {
75         return this.baseMapper.customList(param);
76     }
77
78     @Override
79     public void delete(MaterialTraceabilityParam param){
80         this.removeById(getKey(param));
81     }
82
83     @Override
84     public void update(MaterialTraceabilityParam param){
85         MaterialTraceability oldEntity = getOldEntity(param);
86         MaterialTraceability newEntity = getEntity(param);
87         ToolUtil.copyProperties(newEntity, oldEntity);
88         this.updateById(newEntity);
89     }
90
91     public static String getSfcCode(String str){
92         String sfcCode = "";
93         try {
94             Class<?> clazz = Class.forName("cn.stylefeng.guns.plcserver.opc.GlobalVariable");
95             Field[] fields = clazz.getFields();
96             for (Field field : fields) {
97                 String name = field.getName();
98                 if (name.equals(str)) {
99                     try {
100                         return String.valueOf(field.get(null));
101                     } catch (IllegalAccessException e) {
102                         e.printStackTrace();
103                     }
104                 }
105             }
106         } catch (ClassNotFoundException e) {
107             e.printStackTrace();
108         }
109         return sfcCode;
110     }
111
112     @Override
113     public MaterialTraceabilityResult findBySpec(MaterialTraceabilityParam param){
114         return null;
115     }
116
117     @Override
118     public List<MaterialTraceabilityResult> findListBySpec(MaterialTraceabilityParam param){
119         return this.baseMapper.customList(param);
120     }
121
122     @Override
123     public LayuiPageInfo findPageBySpec(MaterialTraceabilityParam param){
124         Page pageContext = getPageContext();
125         IPage page = this.baseMapper.customPageList(pageContext, param);
126         return LayuiPageFactory.createPageInfo(page);
127     }
128
129     @Override
130     public int barCodeCheck(ProductionOrderBatchInfoParam productionOrderBatchInfoParam) {
131         int i =  traceabilityService.count(new QueryWrapper<MaterialTraceability>()
132                 .eq("work_order_no", productionOrderBatchInfoParam.getWorkOrderNo())
133                 .eq("material_code", productionOrderBatchInfoParam.getMaterialCode())
134         );
135         return i;
136     }
137
138     private Serializable getKey(MaterialTraceabilityParam param){
139         return param.getId();
140     }
141
142     private Page getPageContext() {
143         return LayuiPageFactory.defaultPage();
144     }
145
146     private MaterialTraceability getOldEntity(MaterialTraceabilityParam param) {
147         return this.getById(getKey(param));
148     }
149
150     private MaterialTraceability getEntity(MaterialTraceabilityParam param) {
151         MaterialTraceability entity = new MaterialTraceability();
152         ToolUtil.copyProperties(param, entity);
153         return entity;
154     }
155     @Override
156     public int updateSFC(String sfcCode, String childSfcCode) {
157         return this.baseMapper.updateSFC(sfcCode, childSfcCode);
158     }
159
160
161 }