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