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