admin
2024-07-01 0ca2540bbe77760f8a6d6da2f911b79318cd9df9
提交 | 用户 | 时间
0ca254 1 package com.jcdm.main.restful.qingYan.service;
A 2
3 import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.util.ObjectUtil;
5 import cn.hutool.core.util.StrUtil;
6 import cn.hutool.http.HttpRequest;
7 import cn.hutool.http.HttpResponse;
8 import cn.hutool.json.JSONObject;
9 import cn.hutool.json.JSONUtil;
10 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
11 import com.fasterxml.jackson.core.JsonProcessingException;
12 import com.fasterxml.jackson.databind.ObjectMapper;
13 import com.jcdm.common.core.domain.AjaxResult;
14 import com.jcdm.common.utils.StringUtils;
15 import com.jcdm.framework.websocket.WebSocketUsers;
16 import com.jcdm.main.bs.beatSetting.domain.BsBeatSetting;
17 import com.jcdm.main.bs.beatSetting.service.IBsBeatSettingService;
18 import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo;
19 import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService;
20 import com.jcdm.main.constant.Constants;
21 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
22 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
23 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
24 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
25 import com.jcdm.main.da.testDeviceInterface.domain.DaTestDeviceInterface;
26 import com.jcdm.main.da.testDeviceInterface.service.IDaTestDeviceInterfaceService;
27 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
28 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
29 import com.jcdm.main.restful.factoryMes.service.RestfulService;
30 import com.jcdm.main.restful.qingYan.doman.*;
31 import lombok.extern.slf4j.Slf4j;
32 import org.aspectj.weaver.loadtime.Aj;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.web.bind.annotation.*;
37
38 import javax.annotation.Resource;
39 import javax.websocket.Session;
40 import java.lang.reflect.Field;
41 import java.text.ParseException;
42 import java.text.SimpleDateFormat;
43 import java.util.*;
44 import java.util.concurrent.CompletableFuture;
45 import java.util.stream.Collectors;
46 @Slf4j
47 @RestController
48 @RequestMapping("/jcdmMes")
49 public class ExternalInterface {
50     Map<String, Session> map = WebSocketUsers.getUsers();
51
52     private static final Logger logger = LoggerFactory.getLogger("sys-user");
53
54     public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
55
56     @Autowired
57     private IDaTestDeviceInterfaceService daTestDeviceInterfaceService;
58     @Autowired
59     private IDaParamCollectionService daParamCollectionService;
60
61     @Resource
62     private IDaPassingStationCollectionService daPassingStationCollectionService;
63
64     @Autowired
65     private IOmProductionOrdeInfoService productionOrdeInfoService;
66
67     @Autowired
68     private IOmProductionOrdeInfoService omProductionOrdeInfoService;
69
70     @Autowired
71     private IBsFormulaChildInfoService bsFormulaChildInfoService;
72
73     @Autowired
74     private IBsBeatSettingService bsBeatSettingService;
75
76     private IDaPassingStationCollectionService passingStationCollectionService;
77
78 //    String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
79
80     String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
81
82     /**
83      * 导出点检任务列表
84      */
85     @PostMapping("/deviceResultFeedback")
86     public AjaxResult hdy(@RequestBody ParentVO parentVO)
87     {
88         //保存
89         //过站记录
90 //        String productNum = parentVO.getProductNum();
91 //        if (StrUtil.isNotBlank(productNum)){
92 //            List<OmProductionOrdeInfo> list = productionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, productNum));
93 //            if (CollUtil.isNotEmpty(list)){
94 //                OmProductionOrdeInfo omProductionOrdeInfo = list.get(0);
95 //                DaPassingStationCollection passingStationCollection = new DaPassingStationCollection();
96 //                passingStationCollection.setWorkOrderNo(omProductionOrdeInfo.getWorkOrderNo());
97 //                passingStationCollection.setSfcCode(productNum);
98 //                passingStationCollection.setProductCode(omProductionOrdeInfo.getProductCode());
99 //                passingStationCollection.setLocationCode(parentVO.getStationCode());
100 //                passingStationCollection.setOutRsSign(parentVO.getTotalResult());
101 //                passingStationCollection.setCreateTime(new Date());
102 //
103 //                List<ChildVO> checkList = parentVO.getCheckList();
104 //                if (CollUtil.isNotEmpty(checkList)){
105 //                    List<String> collect = checkList.stream()
106 //                            .filter(x -> Constants.IN_BOUND_TIME_CODE.equals(x.getItemCode()))
107 //                            .map(ChildVO::getItemValue)
108 //                            .collect(Collectors.toList());
109 //                    if (CollUtil.isNotEmpty(collect)){
110 //                        String s = collect.get(0);
111 //                        if (StrUtil.isNotBlank(s)){
112 //                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
113 //                            try {
114 //                                Date parse = simpleDateFormat.parse(s);
115 //                                passingStationCollection.setInboundTime(parse);
116 //                            } catch (ParseException e) {
117 //                                throw new RuntimeException(e);
118 //                            }
119 //                        }
120 //                    }
121 //                    List<String> collect2 = checkList.stream()
122 //                            .filter(x -> Constants.OUT_BOUND_TIME_CODE.equals(x.getItemCode()))
123 //                            .map(ChildVO::getItemValue)
124 //                            .collect(Collectors.toList());
125 //                    if (CollUtil.isNotEmpty(collect2)){
126 //                        String s = collect2.get(0);
127 //                        if (StrUtil.isNotBlank(s)){
128 //                            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
129 //                            try {
130 //                                Date parse = simpleDateFormat.parse(s);
131 //                                passingStationCollection.setOutboundTime(parse);
132 //                            } catch (ParseException e) {
133 //                                throw new RuntimeException(e);
134 //                            }
135 //                        }
136 //                    }
137 //                    daPassingStationCollectionService.save(passingStationCollection);
138 //                    //参数保存
139 //                    List<DaParamCollection> paramCollectionList = new ArrayList<>();
140 //                    for (ChildVO childVO : checkList) {
141 //                        DaParamCollection daParamCollection = new DaParamCollection();
142 //                        daParamCollection.setWorkOrderNo(omProductionOrdeInfo.getWorkOrderNo());
143 //                        daParamCollection.setSfcCode(productNum);
144 //                        daParamCollection.setProductCode(omProductionOrdeInfo.getProductCode());
145 //                        daParamCollection.setLocationCode(omProductionOrdeInfo.getStationCode());
146 //                        daParamCollection.setParamCode(childVO.getItemCode());
147 //                        daParamCollection.setParamValue(childVO.getItemValue());
148 //                        daParamCollection.setCollectionTime(new Date());
149 //                        daParamCollection.setParamName(childVO.getItemText());
150 //                        paramCollectionList.add(daParamCollection);
151 //                    }
152 //                    if (CollUtil.isNotEmpty(paramCollectionList)){
153 //                        daParamCollectionService.insertBatch(paramCollectionList);
154 //                    }
155 //                }
156 //            }
157 //        }
158         ObjectMapper mapper = new ObjectMapper();
159         List<ChildVO> li = parentVO.getCheckList();
160         String s = null;
161         try {
162             s = mapper.writeValueAsString(li);
163         } catch (JsonProcessingException e) {
164             throw new RuntimeException(e);
165         }
166         DaTestDeviceInterface daTestDeviceInterface = new DaTestDeviceInterface();
167         daTestDeviceInterface.setRecordId(parentVO.getRecordId());
168         daTestDeviceInterface.setStationCode(parentVO.getStationCode());
169         daTestDeviceInterface.setProductNum(parentVO.getProductNum());
170         daTestDeviceInterface.setTotalResult(parentVO.getTotalResult());
171         daTestDeviceInterface.setCheckList(s);
172         daTestDeviceInterface.setCreateTime(new Date());
173         daTestDeviceInterfaceService.save(daTestDeviceInterface);
174         if(parentVO.getStationCode().contains("OP480")){
175             if(StringUtils.isNotBlank(parentVO.getProductNum())){
176                 OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, parentVO.getProductNum()));
177                 if(ObjectUtil.isNotNull(one)){
178                     logger.info("解绑小车{},pack码是{}"+one.getTrolleyYard(),one.getProductNum());
179                     one.setTrolleyYard("");
180                     omProductionOrdeInfoService.saveOrUpdate(one);
181                 }
182             }
183         }
184 //        try{
185 //            CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
186 //                logger.info("开始执行异步方法");
187 //                HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
188 //                logger.info("异步方法执行结束");
189 //                logger.info("接收清研,气密异步方法{}"+execute.body());
190 //            });
191 //        }catch (Exception e){
192 //            System.out.println(e.getMessage());
193 //        }
194         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
195         return AjaxResult.success(execute.body());
196     }
197
198     @GetMapping("/productionWorkOrderRequest")
199     public AjaxResult productionWorkOrderRequest(){
200         List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list();
201         List<RestFulOrder> restFulOrders = new ArrayList<>();
202         for (OmProductionOrdeInfo omProductionOrdeInfo : list) {
203             RestFulOrder order = new RestFulOrder();
204             order.setProductionOrderNum(omProductionOrdeInfo.getWorkOrderNo());
205             order.setProductNum(omProductionOrdeInfo.getProductNum());
206             order.setMaterialCode(omProductionOrdeInfo.getMaterialCode());
207             order.setStationCode(omProductionOrdeInfo.getStationCode());
208             order.setPlanQty(omProductionOrdeInfo.getPlanQty());
209             order.setCreateTime(format.format(omProductionOrdeInfo.getCreateTime()));
210             restFulOrders.add(order);
211         }
212         return AjaxResult.success(restFulOrders);
213     }
214
215     public static void main(String[] args) {
216         String str = "0RSPB0011A2E3AE5P0000002  2024-05-28 15:48:51";
217         String[] split = str.split("  ");
218         System.out.println(split[0]);
219         System.out.println(split[1]);
220
221     }
222
223     @GetMapping("/getQualityData")
224     public AjaxResult getQualityData(){
225 //        List<DaPassingStationCollection> qualified = daPassingStationCollectionService.list(new LambdaQueryWrapper<DaPassingStationCollection>().eq(DaPassingStationCollection::getOutRsSign, "1"));
226 //        List<DaPassingStationCollection> unQualified = daPassingStationCollectionService.list(new LambdaQueryWrapper<DaPassingStationCollection>().eq(DaPassingStationCollection::getOutRsSign, "2"));
227 //        Map<String,Integer> map = new HashMap<>();
228 //        map.put("qualified",qualified.size());
229 //        map.put("unQualified",unQualified.size());
230         for (BsBeatSetting bsBeatSetting : bsBeatSettingService.list()) {
231             String str = bsBeatSetting.getProductCode();
232             String[] split = str.split("  ");
233             String reportResult = RestfulService.getWorkReportResultFeedback(split[0], "OP500", "2024-06-27 15:48:51");
234             JSONObject jsonObject = new JSONObject(reportResult);
235             String code = jsonObject.getStr("code");
236             String status = jsonObject.getJSONObject("data").getStr("resultCode");
237             if("success".equals(code)&&"S".equals(status)){
238                 //如果成功,执行报工成功方法,修改是否报工为1,添加报工时间
239                 bsBeatSetting.setProductName("S");
240                 this.bsBeatSettingService.saveOrUpdate(bsBeatSetting);
241             }else{
242                 bsBeatSetting.setProductName("F");
243                 this.bsBeatSettingService.saveOrUpdate(bsBeatSetting);
244             }
245         }
246         return AjaxResult.success();
247     }
248
249
250
251     @GetMapping("/productionOrderComponentRequest")
252     public AjaxResult productionOrderComponentRequest(BsFormulaChildInfo bsFormulaChildInfo){
253         Map<String,List<String>> map = new HashMap<>();
254         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
255                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getProcessesCode())
256                 .eq(BsFormulaChildInfo::getOperationType, "2")
257         );
258         List<ProductionOrderComponentRequest> requests = new ArrayList<>();
259         for (BsFormulaChildInfo info : list) {
260             ProductionOrderComponentRequest request = new ProductionOrderComponentRequest();
261             request.setMaterialCode(info.getMaterialCode());
262             request.setOperationSteps(info.getOperationSteps());
263             requests.add(request);
264         }
265         return AjaxResult.success(requests);
266     }
267
268
269     @PostMapping("/pushParamData")
270     public void receivingData(@RequestBody PostEntity postEntity) throws JsonProcessingException {
271 //        ObjectMapper objectMapper = new ObjectMapper();
272 //        PostEntity person = objectMapper.readValue(postEntity, PostEntity.class);
273
274
275         Class<?> entityClass = PostEntity.class; // 替换为你的实体类
276         String packId = postEntity.getPEOL_PackID();
277         OmProductionOrdeInfo one = productionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, packId));
278         String productType = "type";
279         String workOrderNo = one.getWorkOrderNo();
280         for (Field field : entityClass.getDeclaredFields()) {
281             String fieldName = field.getName();
282             DaParamCollection daParamCollection = new DaParamCollection();
283             daParamCollection.setWorkOrderNo(workOrderNo);
284             daParamCollection.setProductCode(productType);
285             daParamCollection.setSfcCode(packId);
286             daParamCollection.setParamCode(field.getName());
287             daParamCollection.setParamValue((String) getFieldValue(postEntity, fieldName));
288             if(fieldName.contains("GDBH")){
289                 daParamCollection.setParamValue(workOrderNo);
290             }
291             if(fieldName.contains("CPXH")){
292                 daParamCollection.setParamValue(productType);
293             }
294             daParamCollectionService.save(daParamCollection);
295         }
296
297     }
298
299     /**
300      * 放行请空状态
301      */
302     @PostMapping("/sendWebSocket")
303     public void sendWebSocket(@RequestBody BsFormulaChildInfo bsFormulaChildInfo)
304     {
305         WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), bsFormulaChildInfo.getResults());
306     }
307
308     /**
309      * 使用反射获取对象的属性值
310      *
311      * @param obj       目标对象
312      * @param fieldName 属性名
313      * @return 属性值,如果获取失败则返回null
314      */
315     public static Object getFieldValue(Object obj, String fieldName) {
316         if (obj == null) {
317             throw new IllegalArgumentException("Object must not be null");
318         }
319         try {
320             Field field = obj.getClass().getDeclaredField(fieldName);
321             field.setAccessible(true); // 设置可访问性,以便访问私有字段
322             return field.get(obj);
323         } catch (NoSuchFieldException e) {
324             // 如果当前类没有该字段,则尝试从父类中获取
325             Class<?> superClass = obj.getClass().getSuperclass();
326             if (superClass != null && !superClass.equals(Object.class)) {
327                 return getFieldValue(obj, fieldName, superClass);
328             }
329             e.printStackTrace();
330         } catch (IllegalAccessException e) {
331             e.printStackTrace();
332         }
333         return null;
334     }
335
336     private static Object getFieldValue(Object obj, String fieldName, Class<?> superClass) {
337         try {
338             Field field = superClass.getDeclaredField(fieldName);
339             field.setAccessible(true);
340             return field.get(obj);
341         } catch (NoSuchFieldException e) {
342             // 如果父类也没有该字段,则继续向上查找
343             Class<?> grandParentClass = superClass.getSuperclass();
344             if (grandParentClass != null && !grandParentClass.equals(Object.class)) {
345                 return getFieldValue(obj, fieldName, grandParentClass);
346             }
347             e.printStackTrace();
348         } catch (IllegalAccessException e) {
349             e.printStackTrace();
350         }
351         return null;
352     }
353
354 }