-
admin
2024-06-06 019f1c8bac7e8986d299aff70c123dedc1747d72
提交 | 用户 | 时间
258f26 1 package com.jcdm.main.restful.qingYan.service;
A 2
fd7bc3 3 import cn.hutool.core.collection.CollUtil;
a846f2 4 import cn.hutool.core.util.ObjectUtil;
fd7bc3 5 import cn.hutool.core.util.StrUtil;
3581b1 6 import cn.hutool.http.HttpRequest;
A 7 import cn.hutool.http.HttpResponse;
8 import cn.hutool.json.JSONUtil;
258f26 9 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
A 10 import com.fasterxml.jackson.core.JsonProcessingException;
616f98 11 import com.fasterxml.jackson.databind.ObjectMapper;
3581b1 12 import com.jcdm.common.core.domain.AjaxResult;
a846f2 13 import com.jcdm.common.utils.StringUtils;
1ccd69 14 import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo;
A 15 import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService;
fd7bc3 16 import com.jcdm.main.constant.Constants;
258f26 17 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
A 18 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
fd7bc3 19 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
W 20 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
616f98 21 import com.jcdm.main.da.testDeviceInterface.domain.DaTestDeviceInterface;
A 22 import com.jcdm.main.da.testDeviceInterface.service.IDaTestDeviceInterfaceService;
258f26 23 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
A 24 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
68f0c8 25 import com.jcdm.main.restful.qingYan.doman.*;
1ccd69 26 import org.aspectj.weaver.loadtime.Aj;
258f26 27 import org.springframework.beans.factory.annotation.Autowired;
1ccd69 28 import org.springframework.web.bind.annotation.*;
258f26 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;
1ccd69 34 import java.util.*;
fd7bc3 35 import java.util.stream.Collectors;
258f26 36
A 37 @RestController
38 @RequestMapping("/jcdmMes")
39 public class ExternalInterface {
019f1c 40     public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
A 41
258f26 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;
1ccd69 52
A 53     @Autowired
54     private IOmProductionOrdeInfoService omProductionOrdeInfoService;
55
56     @Autowired
57     private IBsFormulaChildInfoService bsFormulaChildInfoService;
68f0c8 58
A 59     private IDaPassingStationCollectionService passingStationCollectionService;
1ccd69 60
a846f2 61 //    String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
982c84 62
a846f2 63     String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
3581b1 64
A 65     /**
66      * 导出点检任务列表
67      */
68     @PostMapping("/deviceResultFeedback")
69     public AjaxResult hdy(@RequestBody ParentVO parentVO)
70     {
fd7bc3 71         //保存
W 72         //过站记录
616f98 73 //        String productNum = parentVO.getProductNum();
A 74 //        if (StrUtil.isNotBlank(productNum)){
75 //            List<OmProductionOrdeInfo> list = productionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, productNum));
76 //            if (CollUtil.isNotEmpty(list)){
77 //                OmProductionOrdeInfo omProductionOrdeInfo = list.get(0);
78 //                DaPassingStationCollection passingStationCollection = new DaPassingStationCollection();
79 //                passingStationCollection.setWorkOrderNo(omProductionOrdeInfo.getWorkOrderNo());
80 //                passingStationCollection.setSfcCode(productNum);
81 //                passingStationCollection.setProductCode(omProductionOrdeInfo.getProductCode());
82 //                passingStationCollection.setLocationCode(parentVO.getStationCode());
83 //                passingStationCollection.setOutRsSign(parentVO.getTotalResult());
84 //                passingStationCollection.setCreateTime(new Date());
85 //
86 //                List<ChildVO> checkList = parentVO.getCheckList();
87 //                if (CollUtil.isNotEmpty(checkList)){
88 //                    List<String> collect = checkList.stream()
89 //                            .filter(x -> Constants.IN_BOUND_TIME_CODE.equals(x.getItemCode()))
90 //                            .map(ChildVO::getItemValue)
91 //                            .collect(Collectors.toList());
92 //                    if (CollUtil.isNotEmpty(collect)){
93 //                        String s = collect.get(0);
94 //                        if (StrUtil.isNotBlank(s)){
95 //                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
96 //                            try {
97 //                                Date parse = simpleDateFormat.parse(s);
98 //                                passingStationCollection.setInboundTime(parse);
99 //                            } catch (ParseException e) {
100 //                                throw new RuntimeException(e);
101 //                            }
102 //                        }
103 //                    }
104 //                    List<String> collect2 = checkList.stream()
105 //                            .filter(x -> Constants.OUT_BOUND_TIME_CODE.equals(x.getItemCode()))
106 //                            .map(ChildVO::getItemValue)
107 //                            .collect(Collectors.toList());
108 //                    if (CollUtil.isNotEmpty(collect2)){
109 //                        String s = collect2.get(0);
110 //                        if (StrUtil.isNotBlank(s)){
111 //                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
112 //                            try {
113 //                                Date parse = simpleDateFormat.parse(s);
114 //                                passingStationCollection.setOutboundTime(parse);
115 //                            } catch (ParseException e) {
116 //                                throw new RuntimeException(e);
117 //                            }
118 //                        }
119 //                    }
120 //                    daPassingStationCollectionService.save(passingStationCollection);
121 //                    //参数保存
122 //                    List<DaParamCollection> paramCollectionList = new ArrayList<>();
123 //                    for (ChildVO childVO : checkList) {
124 //                        DaParamCollection daParamCollection = new DaParamCollection();
125 //                        daParamCollection.setWorkOrderNo(omProductionOrdeInfo.getWorkOrderNo());
126 //                        daParamCollection.setSfcCode(productNum);
127 //                        daParamCollection.setProductCode(omProductionOrdeInfo.getProductCode());
128 //                        daParamCollection.setLocationCode(omProductionOrdeInfo.getStationCode());
129 //                        daParamCollection.setParamCode(childVO.getItemCode());
130 //                        daParamCollection.setParamValue(childVO.getItemValue());
131 //                        daParamCollection.setCollectionTime(new Date());
132 //                        daParamCollection.setParamName(childVO.getItemText());
133 //                        paramCollectionList.add(daParamCollection);
134 //                    }
135 //                    if (CollUtil.isNotEmpty(paramCollectionList)){
136 //                        daParamCollectionService.insertBatch(paramCollectionList);
137 //                    }
138 //                }
139 //            }
140 //        }
141         ObjectMapper mapper = new ObjectMapper();
142         List<ChildVO> li = parentVO.getCheckList();
143         String s = null;
144         try {
145             s = mapper.writeValueAsString(li);
146         } catch (JsonProcessingException e) {
147             throw new RuntimeException(e);
fd7bc3 148         }
616f98 149         DaTestDeviceInterface daTestDeviceInterface = new DaTestDeviceInterface();
A 150         daTestDeviceInterface.setRecordId(parentVO.getRecordId());
151         daTestDeviceInterface.setStationCode(parentVO.getStationCode());
152         daTestDeviceInterface.setProductNum(parentVO.getProductNum());
153         daTestDeviceInterface.setTotalResult(parentVO.getTotalResult());
154         daTestDeviceInterface.setCheckList(s);
a846f2 155         daTestDeviceInterface.setCreateTime(new Date());
616f98 156         daTestDeviceInterfaceService.save(daTestDeviceInterface);
a846f2 157         if(parentVO.getStationCode().contains("OP480")){
A 158             if(StringUtils.isNotBlank(parentVO.getProductNum())){
159                 OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, parentVO.getProductNum()));
160                 if(ObjectUtil.isNotNull(one)){
161                     one.setTrolleyYard("");
162                     omProductionOrdeInfoService.saveOrUpdate(one);
163                 }
164             }
165         }
3581b1 166         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
A 167         return AjaxResult.success(execute.body());
168     }
169
1ccd69 170     @GetMapping("/productionWorkOrderRequest")
A 171     public AjaxResult productionWorkOrderRequest(){
172         List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list();
68f0c8 173         List<RestFulOrder> restFulOrders = new ArrayList<>();
A 174         for (OmProductionOrdeInfo omProductionOrdeInfo : list) {
175             RestFulOrder order = new RestFulOrder();
176             order.setProductionOrderNum(omProductionOrdeInfo.getWorkOrderNo());
177             order.setProductNum(omProductionOrdeInfo.getProductNum());
178             order.setMaterialCode(omProductionOrdeInfo.getMaterialCode());
179             order.setStationCode(omProductionOrdeInfo.getStationCode());
982c84 180             order.setPlanQty(omProductionOrdeInfo.getPlanQty());
019f1c 181             order.setCreateTime(format.format(omProductionOrdeInfo.getCreateTime()));
68f0c8 182             restFulOrders.add(order);
A 183         }
184         return AjaxResult.success(restFulOrders);
1ccd69 185     }
68f0c8 186
A 187     @GetMapping("/getQualityData")
188     public AjaxResult getQualityData(){
189         List<DaPassingStationCollection> qualified = daPassingStationCollectionService.list(new LambdaQueryWrapper<DaPassingStationCollection>().eq(DaPassingStationCollection::getOutRsSign, "1"));
190         List<DaPassingStationCollection> unQualified = daPassingStationCollectionService.list(new LambdaQueryWrapper<DaPassingStationCollection>().eq(DaPassingStationCollection::getOutRsSign, "2"));
191         Map<String,Integer> map = new HashMap<>();
192         map.put("qualified",qualified.size());
193         map.put("unQualified",unQualified.size());
194         return AjaxResult.success(map);
195     }
196
197
1ccd69 198
A 199     @GetMapping("/productionOrderComponentRequest")
200     public AjaxResult productionOrderComponentRequest(BsFormulaChildInfo bsFormulaChildInfo){
201         Map<String,List<String>> map = new HashMap<>();
202         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
203                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getProcessesCode())
204                 .eq(BsFormulaChildInfo::getOperationType, "2")
205         );
68f0c8 206         List<ProductionOrderComponentRequest> requests = new ArrayList<>();
A 207         for (BsFormulaChildInfo info : list) {
208             ProductionOrderComponentRequest request = new ProductionOrderComponentRequest();
209             request.setMaterialCode(info.getMaterialCode());
210             request.setOperationSteps(info.getOperationSteps());
211             requests.add(request);
212         }
213         return AjaxResult.success(requests);
1ccd69 214     }
A 215
258f26 216
A 217     @PostMapping("/pushParamData")
218     public void receivingData(@RequestBody PostEntity postEntity) throws JsonProcessingException {
219 //        ObjectMapper objectMapper = new ObjectMapper();
220 //        PostEntity person = objectMapper.readValue(postEntity, PostEntity.class);
221
222
223         Class<?> entityClass = PostEntity.class; // 替换为你的实体类
224         String packId = postEntity.getPEOL_PackID();
225         OmProductionOrdeInfo one = productionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, packId));
226         String productType = "type";
227         String workOrderNo = one.getWorkOrderNo();
228         for (Field field : entityClass.getDeclaredFields()) {
229             String fieldName = field.getName();
230             DaParamCollection daParamCollection = new DaParamCollection();
231             daParamCollection.setWorkOrderNo(workOrderNo);
232             daParamCollection.setProductCode(productType);
233             daParamCollection.setSfcCode(packId);
234             daParamCollection.setParamCode(field.getName());
235             daParamCollection.setParamValue((String) getFieldValue(postEntity, fieldName));
236             if(fieldName.contains("GDBH")){
237                 daParamCollection.setParamValue(workOrderNo);
238             }
239             if(fieldName.contains("CPXH")){
240                 daParamCollection.setParamValue(productType);
241             }
242             daParamCollectionService.save(daParamCollection);
243         }
244
245     }
246
247
248     /**
249      * 使用反射获取对象的属性值
250      *
251      * @param obj       目标对象
252      * @param fieldName 属性名
253      * @return 属性值,如果获取失败则返回null
254      */
255     public static Object getFieldValue(Object obj, String fieldName) {
256         if (obj == null) {
257             throw new IllegalArgumentException("Object must not be null");
258         }
259         try {
260             Field field = obj.getClass().getDeclaredField(fieldName);
261             field.setAccessible(true); // 设置可访问性,以便访问私有字段
262             return field.get(obj);
263         } catch (NoSuchFieldException e) {
264             // 如果当前类没有该字段,则尝试从父类中获取
265             Class<?> superClass = obj.getClass().getSuperclass();
266             if (superClass != null && !superClass.equals(Object.class)) {
267                 return getFieldValue(obj, fieldName, superClass);
268             }
269             e.printStackTrace();
270         } catch (IllegalAccessException e) {
271             e.printStackTrace();
272         }
273         return null;
274     }
275
276     private static Object getFieldValue(Object obj, String fieldName, Class<?> superClass) {
277         try {
278             Field field = superClass.getDeclaredField(fieldName);
279             field.setAccessible(true);
280             return field.get(obj);
281         } catch (NoSuchFieldException e) {
282             // 如果父类也没有该字段,则继续向上查找
283             Class<?> grandParentClass = superClass.getSuperclass();
284             if (grandParentClass != null && !grandParentClass.equals(Object.class)) {
285                 return getFieldValue(obj, fieldName, grandParentClass);
286             }
287             e.printStackTrace();
288         } catch (IllegalAccessException e) {
289             e.printStackTrace();
290         }
291         return null;
292     }
293
294 }