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