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