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