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