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