提交 | 用户 | 时间
|
258f26
|
1 |
package com.jcdm.main.restful.qingYan.service; |
A |
2 |
|
3581b1
|
3 |
import cn.hutool.http.HttpRequest; |
A |
4 |
import cn.hutool.http.HttpResponse; |
|
5 |
import cn.hutool.json.JSONUtil; |
258f26
|
6 |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
A |
7 |
import com.fasterxml.jackson.core.JsonProcessingException; |
|
8 |
import com.fasterxml.jackson.databind.ObjectMapper; |
|
9 |
import com.google.gson.JsonObject; |
|
10 |
import com.jcdm.common.annotation.Log; |
3581b1
|
11 |
import com.jcdm.common.core.domain.AjaxResult; |
258f26
|
12 |
import com.jcdm.common.enums.BusinessType; |
A |
13 |
import com.jcdm.common.utils.poi.ExcelUtil; |
|
14 |
import com.jcdm.main.da.paramCollection.domain.DaParamCollection; |
|
15 |
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; |
|
16 |
import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo; |
|
17 |
import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService; |
3581b1
|
18 |
import com.jcdm.main.restful.qingYan.doman.ParentVO; |
258f26
|
19 |
import com.jcdm.main.restful.qingYan.doman.PostEntity; |
A |
20 |
import com.jcdm.main.rm.repairData.domain.RmRepairData; |
3581b1
|
21 |
import org.aspectj.weaver.loadtime.Aj; |
258f26
|
22 |
import org.springframework.beans.factory.annotation.Autowired; |
A |
23 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
24 |
import org.springframework.web.bind.annotation.PostMapping; |
|
25 |
import org.springframework.web.bind.annotation.RequestBody; |
|
26 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
27 |
import org.springframework.web.bind.annotation.RestController; |
|
28 |
|
|
29 |
import javax.servlet.http.HttpServletResponse; |
|
30 |
import java.lang.reflect.Field; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
@RestController |
|
34 |
@RequestMapping("/jcdmMes") |
|
35 |
public class ExternalInterface { |
|
36 |
@Autowired |
|
37 |
private IDaParamCollectionService daParamCollectionService; |
|
38 |
|
|
39 |
@Autowired |
|
40 |
private IOmProductionOrdeInfoService productionOrdeInfoService; |
|
41 |
|
3581b1
|
42 |
String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback"; |
A |
43 |
|
|
44 |
/** |
|
45 |
* 导出点检任务列表 |
|
46 |
*/ |
|
47 |
@PostMapping("/deviceResultFeedback") |
|
48 |
public AjaxResult hdy(@RequestBody ParentVO parentVO) |
|
49 |
{ |
|
50 |
HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute(); |
|
51 |
return AjaxResult.success(execute.body()); |
|
52 |
} |
|
53 |
|
258f26
|
54 |
|
A |
55 |
@PostMapping("/pushParamData") |
|
56 |
public void receivingData(@RequestBody PostEntity postEntity) throws JsonProcessingException { |
|
57 |
// ObjectMapper objectMapper = new ObjectMapper(); |
|
58 |
// PostEntity person = objectMapper.readValue(postEntity, PostEntity.class); |
|
59 |
|
|
60 |
|
|
61 |
Class<?> entityClass = PostEntity.class; // 替换为你的实体类 |
|
62 |
String packId = postEntity.getPEOL_PackID(); |
|
63 |
OmProductionOrdeInfo one = productionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, packId)); |
|
64 |
String productType = "type"; |
|
65 |
String workOrderNo = one.getWorkOrderNo(); |
|
66 |
for (Field field : entityClass.getDeclaredFields()) { |
|
67 |
String fieldName = field.getName(); |
|
68 |
DaParamCollection daParamCollection = new DaParamCollection(); |
|
69 |
daParamCollection.setWorkOrderNo(workOrderNo); |
|
70 |
daParamCollection.setProductCode(productType); |
|
71 |
daParamCollection.setSfcCode(packId); |
|
72 |
daParamCollection.setParamCode(field.getName()); |
|
73 |
daParamCollection.setParamValue((String) getFieldValue(postEntity, fieldName)); |
|
74 |
if(fieldName.contains("GDBH")){ |
|
75 |
daParamCollection.setParamValue(workOrderNo); |
|
76 |
} |
|
77 |
if(fieldName.contains("CPXH")){ |
|
78 |
daParamCollection.setParamValue(productType); |
|
79 |
} |
|
80 |
daParamCollectionService.save(daParamCollection); |
|
81 |
} |
|
82 |
|
|
83 |
} |
|
84 |
|
|
85 |
|
|
86 |
/** |
|
87 |
* 使用反射获取对象的属性值 |
|
88 |
* |
|
89 |
* @param obj 目标对象 |
|
90 |
* @param fieldName 属性名 |
|
91 |
* @return 属性值,如果获取失败则返回null |
|
92 |
*/ |
|
93 |
public static Object getFieldValue(Object obj, String fieldName) { |
|
94 |
if (obj == null) { |
|
95 |
throw new IllegalArgumentException("Object must not be null"); |
|
96 |
} |
|
97 |
try { |
|
98 |
Field field = obj.getClass().getDeclaredField(fieldName); |
|
99 |
field.setAccessible(true); // 设置可访问性,以便访问私有字段 |
|
100 |
return field.get(obj); |
|
101 |
} catch (NoSuchFieldException e) { |
|
102 |
// 如果当前类没有该字段,则尝试从父类中获取 |
|
103 |
Class<?> superClass = obj.getClass().getSuperclass(); |
|
104 |
if (superClass != null && !superClass.equals(Object.class)) { |
|
105 |
return getFieldValue(obj, fieldName, superClass); |
|
106 |
} |
|
107 |
e.printStackTrace(); |
|
108 |
} catch (IllegalAccessException e) { |
|
109 |
e.printStackTrace(); |
|
110 |
} |
|
111 |
return null; |
|
112 |
} |
|
113 |
|
|
114 |
private static Object getFieldValue(Object obj, String fieldName, Class<?> superClass) { |
|
115 |
try { |
|
116 |
Field field = superClass.getDeclaredField(fieldName); |
|
117 |
field.setAccessible(true); |
|
118 |
return field.get(obj); |
|
119 |
} catch (NoSuchFieldException e) { |
|
120 |
// 如果父类也没有该字段,则继续向上查找 |
|
121 |
Class<?> grandParentClass = superClass.getSuperclass(); |
|
122 |
if (grandParentClass != null && !grandParentClass.equals(Object.class)) { |
|
123 |
return getFieldValue(obj, fieldName, grandParentClass); |
|
124 |
} |
|
125 |
e.printStackTrace(); |
|
126 |
} catch (IllegalAccessException e) { |
|
127 |
e.printStackTrace(); |
|
128 |
} |
|
129 |
return null; |
|
130 |
} |
|
131 |
|
|
132 |
} |