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