提交 | 用户 | 时间
|
258f26
|
1 |
package com.jcdm.main.restful.qingYan.service; |
A |
2 |
|
fd7bc3
|
3 |
import cn.hutool.core.collection.CollUtil; |
W |
4 |
import cn.hutool.core.util.StrUtil; |
3581b1
|
5 |
import cn.hutool.http.HttpRequest; |
A |
6 |
import cn.hutool.http.HttpResponse; |
|
7 |
import cn.hutool.json.JSONUtil; |
258f26
|
8 |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
A |
9 |
import com.fasterxml.jackson.core.JsonProcessingException; |
616f98
|
10 |
import com.fasterxml.jackson.databind.ObjectMapper; |
3581b1
|
11 |
import com.jcdm.common.core.domain.AjaxResult; |
1ccd69
|
12 |
import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo; |
A |
13 |
import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService; |
fd7bc3
|
14 |
import com.jcdm.main.constant.Constants; |
258f26
|
15 |
import com.jcdm.main.da.paramCollection.domain.DaParamCollection; |
A |
16 |
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; |
fd7bc3
|
17 |
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; |
W |
18 |
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; |
616f98
|
19 |
import com.jcdm.main.da.testDeviceInterface.domain.DaTestDeviceInterface; |
A |
20 |
import com.jcdm.main.da.testDeviceInterface.service.IDaTestDeviceInterfaceService; |
258f26
|
21 |
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo; |
A |
22 |
import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService; |
fd7bc3
|
23 |
import com.jcdm.main.restful.qingYan.doman.ChildVO; |
3581b1
|
24 |
import com.jcdm.main.restful.qingYan.doman.ParentVO; |
258f26
|
25 |
import com.jcdm.main.restful.qingYan.doman.PostEntity; |
1ccd69
|
26 |
import org.aspectj.weaver.loadtime.Aj; |
258f26
|
27 |
import org.springframework.beans.factory.annotation.Autowired; |
1ccd69
|
28 |
import org.springframework.web.bind.annotation.*; |
258f26
|
29 |
|
fd7bc3
|
30 |
import javax.annotation.Resource; |
258f26
|
31 |
import java.lang.reflect.Field; |
fd7bc3
|
32 |
import java.text.ParseException; |
W |
33 |
import java.text.SimpleDateFormat; |
1ccd69
|
34 |
import java.util.*; |
fd7bc3
|
35 |
import java.util.stream.Collectors; |
258f26
|
36 |
|
A |
37 |
@RestController |
|
38 |
@RequestMapping("/jcdmMes") |
|
39 |
public class ExternalInterface { |
|
40 |
@Autowired |
616f98
|
41 |
private IDaTestDeviceInterfaceService daTestDeviceInterfaceService; |
A |
42 |
@Autowired |
258f26
|
43 |
private IDaParamCollectionService daParamCollectionService; |
fd7bc3
|
44 |
|
W |
45 |
@Resource |
|
46 |
private IDaPassingStationCollectionService daPassingStationCollectionService; |
258f26
|
47 |
|
A |
48 |
@Autowired |
|
49 |
private IOmProductionOrdeInfoService productionOrdeInfoService; |
1ccd69
|
50 |
|
A |
51 |
@Autowired |
|
52 |
private IOmProductionOrdeInfoService omProductionOrdeInfoService; |
|
53 |
|
|
54 |
@Autowired |
|
55 |
private IBsFormulaChildInfoService bsFormulaChildInfoService; |
|
56 |
|
258f26
|
57 |
|
3581b1
|
58 |
String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback"; |
A |
59 |
|
|
60 |
/** |
|
61 |
* 导出点检任务列表 |
|
62 |
*/ |
|
63 |
@PostMapping("/deviceResultFeedback") |
|
64 |
public AjaxResult hdy(@RequestBody ParentVO parentVO) |
|
65 |
{ |
fd7bc3
|
66 |
//保存 |
W |
67 |
//过站记录 |
616f98
|
68 |
// String productNum = parentVO.getProductNum(); |
A |
69 |
// if (StrUtil.isNotBlank(productNum)){ |
|
70 |
// List<OmProductionOrdeInfo> list = productionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, productNum)); |
|
71 |
// if (CollUtil.isNotEmpty(list)){ |
|
72 |
// OmProductionOrdeInfo omProductionOrdeInfo = list.get(0); |
|
73 |
// DaPassingStationCollection passingStationCollection = new DaPassingStationCollection(); |
|
74 |
// passingStationCollection.setWorkOrderNo(omProductionOrdeInfo.getWorkOrderNo()); |
|
75 |
// passingStationCollection.setSfcCode(productNum); |
|
76 |
// passingStationCollection.setProductCode(omProductionOrdeInfo.getProductCode()); |
|
77 |
// passingStationCollection.setLocationCode(parentVO.getStationCode()); |
|
78 |
// passingStationCollection.setOutRsSign(parentVO.getTotalResult()); |
|
79 |
// passingStationCollection.setCreateTime(new Date()); |
|
80 |
// |
|
81 |
// List<ChildVO> checkList = parentVO.getCheckList(); |
|
82 |
// if (CollUtil.isNotEmpty(checkList)){ |
|
83 |
// List<String> collect = checkList.stream() |
|
84 |
// .filter(x -> Constants.IN_BOUND_TIME_CODE.equals(x.getItemCode())) |
|
85 |
// .map(ChildVO::getItemValue) |
|
86 |
// .collect(Collectors.toList()); |
|
87 |
// if (CollUtil.isNotEmpty(collect)){ |
|
88 |
// String s = collect.get(0); |
|
89 |
// if (StrUtil.isNotBlank(s)){ |
|
90 |
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
91 |
// try { |
|
92 |
// Date parse = simpleDateFormat.parse(s); |
|
93 |
// passingStationCollection.setInboundTime(parse); |
|
94 |
// } catch (ParseException e) { |
|
95 |
// throw new RuntimeException(e); |
|
96 |
// } |
|
97 |
// } |
|
98 |
// } |
|
99 |
// List<String> collect2 = checkList.stream() |
|
100 |
// .filter(x -> Constants.OUT_BOUND_TIME_CODE.equals(x.getItemCode())) |
|
101 |
// .map(ChildVO::getItemValue) |
|
102 |
// .collect(Collectors.toList()); |
|
103 |
// if (CollUtil.isNotEmpty(collect2)){ |
|
104 |
// String s = collect2.get(0); |
|
105 |
// if (StrUtil.isNotBlank(s)){ |
|
106 |
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
107 |
// try { |
|
108 |
// Date parse = simpleDateFormat.parse(s); |
|
109 |
// passingStationCollection.setOutboundTime(parse); |
|
110 |
// } catch (ParseException e) { |
|
111 |
// throw new RuntimeException(e); |
|
112 |
// } |
|
113 |
// } |
|
114 |
// } |
|
115 |
// daPassingStationCollectionService.save(passingStationCollection); |
|
116 |
// //参数保存 |
|
117 |
// List<DaParamCollection> paramCollectionList = new ArrayList<>(); |
|
118 |
// for (ChildVO childVO : checkList) { |
|
119 |
// DaParamCollection daParamCollection = new DaParamCollection(); |
|
120 |
// daParamCollection.setWorkOrderNo(omProductionOrdeInfo.getWorkOrderNo()); |
|
121 |
// daParamCollection.setSfcCode(productNum); |
|
122 |
// daParamCollection.setProductCode(omProductionOrdeInfo.getProductCode()); |
|
123 |
// daParamCollection.setLocationCode(omProductionOrdeInfo.getStationCode()); |
|
124 |
// daParamCollection.setParamCode(childVO.getItemCode()); |
|
125 |
// daParamCollection.setParamValue(childVO.getItemValue()); |
|
126 |
// daParamCollection.setCollectionTime(new Date()); |
|
127 |
// daParamCollection.setParamName(childVO.getItemText()); |
|
128 |
// paramCollectionList.add(daParamCollection); |
|
129 |
// } |
|
130 |
// if (CollUtil.isNotEmpty(paramCollectionList)){ |
|
131 |
// daParamCollectionService.insertBatch(paramCollectionList); |
|
132 |
// } |
|
133 |
// } |
|
134 |
// } |
|
135 |
// } |
|
136 |
ObjectMapper mapper = new ObjectMapper(); |
|
137 |
List<ChildVO> li = parentVO.getCheckList(); |
|
138 |
String s = null; |
|
139 |
try { |
|
140 |
s = mapper.writeValueAsString(li); |
|
141 |
} catch (JsonProcessingException e) { |
|
142 |
throw new RuntimeException(e); |
fd7bc3
|
143 |
} |
616f98
|
144 |
DaTestDeviceInterface daTestDeviceInterface = new DaTestDeviceInterface(); |
A |
145 |
daTestDeviceInterface.setRecordId(parentVO.getRecordId()); |
|
146 |
daTestDeviceInterface.setStationCode(parentVO.getStationCode()); |
|
147 |
daTestDeviceInterface.setProductNum(parentVO.getProductNum()); |
|
148 |
daTestDeviceInterface.setTotalResult(parentVO.getTotalResult()); |
|
149 |
daTestDeviceInterface.setCheckList(s); |
|
150 |
daTestDeviceInterfaceService.save(daTestDeviceInterface); |
3581b1
|
151 |
HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute(); |
A |
152 |
return AjaxResult.success(execute.body()); |
|
153 |
} |
|
154 |
|
1ccd69
|
155 |
@GetMapping("/productionWorkOrderRequest") |
A |
156 |
public AjaxResult productionWorkOrderRequest(){ |
|
157 |
List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(); |
|
158 |
|
|
159 |
return AjaxResult.success(list); |
|
160 |
} |
|
161 |
|
|
162 |
@GetMapping("/productionOrderComponentRequest") |
|
163 |
public AjaxResult productionOrderComponentRequest(BsFormulaChildInfo bsFormulaChildInfo){ |
|
164 |
Map<String,List<String>> map = new HashMap<>(); |
|
165 |
List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>() |
|
166 |
.eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getProcessesCode()) |
|
167 |
.eq(BsFormulaChildInfo::getOperationType, "2") |
|
168 |
); |
|
169 |
List<String> materialCode = list.stream().map(BsFormulaChildInfo::getMaterialCode).collect(Collectors.toList()); |
|
170 |
List<String> operationSteps = list.stream().map(BsFormulaChildInfo::getOperationSteps).collect(Collectors.toList()); |
|
171 |
map.put("materialCode",materialCode); |
|
172 |
map.put("operationSteps",operationSteps); |
|
173 |
return AjaxResult.success(map); |
|
174 |
} |
|
175 |
|
258f26
|
176 |
|
A |
177 |
@PostMapping("/pushParamData") |
|
178 |
public void receivingData(@RequestBody PostEntity postEntity) throws JsonProcessingException { |
|
179 |
// ObjectMapper objectMapper = new ObjectMapper(); |
|
180 |
// PostEntity person = objectMapper.readValue(postEntity, PostEntity.class); |
|
181 |
|
|
182 |
|
|
183 |
Class<?> entityClass = PostEntity.class; // 替换为你的实体类 |
|
184 |
String packId = postEntity.getPEOL_PackID(); |
|
185 |
OmProductionOrdeInfo one = productionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, packId)); |
|
186 |
String productType = "type"; |
|
187 |
String workOrderNo = one.getWorkOrderNo(); |
|
188 |
for (Field field : entityClass.getDeclaredFields()) { |
|
189 |
String fieldName = field.getName(); |
|
190 |
DaParamCollection daParamCollection = new DaParamCollection(); |
|
191 |
daParamCollection.setWorkOrderNo(workOrderNo); |
|
192 |
daParamCollection.setProductCode(productType); |
|
193 |
daParamCollection.setSfcCode(packId); |
|
194 |
daParamCollection.setParamCode(field.getName()); |
|
195 |
daParamCollection.setParamValue((String) getFieldValue(postEntity, fieldName)); |
|
196 |
if(fieldName.contains("GDBH")){ |
|
197 |
daParamCollection.setParamValue(workOrderNo); |
|
198 |
} |
|
199 |
if(fieldName.contains("CPXH")){ |
|
200 |
daParamCollection.setParamValue(productType); |
|
201 |
} |
|
202 |
daParamCollectionService.save(daParamCollection); |
|
203 |
} |
|
204 |
|
|
205 |
} |
|
206 |
|
|
207 |
|
|
208 |
/** |
|
209 |
* 使用反射获取对象的属性值 |
|
210 |
* |
|
211 |
* @param obj 目标对象 |
|
212 |
* @param fieldName 属性名 |
|
213 |
* @return 属性值,如果获取失败则返回null |
|
214 |
*/ |
|
215 |
public static Object getFieldValue(Object obj, String fieldName) { |
|
216 |
if (obj == null) { |
|
217 |
throw new IllegalArgumentException("Object must not be null"); |
|
218 |
} |
|
219 |
try { |
|
220 |
Field field = obj.getClass().getDeclaredField(fieldName); |
|
221 |
field.setAccessible(true); // 设置可访问性,以便访问私有字段 |
|
222 |
return field.get(obj); |
|
223 |
} catch (NoSuchFieldException e) { |
|
224 |
// 如果当前类没有该字段,则尝试从父类中获取 |
|
225 |
Class<?> superClass = obj.getClass().getSuperclass(); |
|
226 |
if (superClass != null && !superClass.equals(Object.class)) { |
|
227 |
return getFieldValue(obj, fieldName, superClass); |
|
228 |
} |
|
229 |
e.printStackTrace(); |
|
230 |
} catch (IllegalAccessException e) { |
|
231 |
e.printStackTrace(); |
|
232 |
} |
|
233 |
return null; |
|
234 |
} |
|
235 |
|
|
236 |
private static Object getFieldValue(Object obj, String fieldName, Class<?> superClass) { |
|
237 |
try { |
|
238 |
Field field = superClass.getDeclaredField(fieldName); |
|
239 |
field.setAccessible(true); |
|
240 |
return field.get(obj); |
|
241 |
} catch (NoSuchFieldException e) { |
|
242 |
// 如果父类也没有该字段,则继续向上查找 |
|
243 |
Class<?> grandParentClass = superClass.getSuperclass(); |
|
244 |
if (grandParentClass != null && !grandParentClass.equals(Object.class)) { |
|
245 |
return getFieldValue(obj, fieldName, grandParentClass); |
|
246 |
} |
|
247 |
e.printStackTrace(); |
|
248 |
} catch (IllegalAccessException e) { |
|
249 |
e.printStackTrace(); |
|
250 |
} |
|
251 |
return null; |
|
252 |
} |
|
253 |
|
|
254 |
} |