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