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