admin
2024-09-09 3c8909327df2b42d79a8b30ffa8e816419574653
提交 | 用户 | 时间
b78728 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.JsonNode;
13 import com.fasterxml.jackson.databind.ObjectMapper;
14 import com.jcdm.common.core.domain.AjaxResult;
15 import com.jcdm.common.utils.StringUtils;
16 import com.jcdm.framework.websocket.WebSocketUsers;
17 import com.jcdm.main.bs.beatSetting.domain.BsBeatSetting;
18 import com.jcdm.main.bs.beatSetting.service.IBsBeatSettingService;
19 import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo;
20 import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService;
21 import com.jcdm.main.constant.Constants;
22 import com.jcdm.main.da.cellData.domain.DaCellData;
23 import com.jcdm.main.da.cellData.service.IDaCellDataService;
24 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
25 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
26 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
27 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
28 import com.jcdm.main.da.testDeviceInterface.domain.DaTestDeviceInterface;
29 import com.jcdm.main.da.testDeviceInterface.service.IDaTestDeviceInterfaceService;
30 import com.jcdm.main.da.testDeviceInterfaceTemp.domain.DaTestDeviceInterfaceTemp;
31 import com.jcdm.main.da.testDeviceInterfaceTemp.service.IDaTestDeviceInterfaceTempService;
32 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
33 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
34 import com.jcdm.main.restful.factoryMes.service.RestfulService;
35 import com.jcdm.main.restful.qingYan.doman.*;
36 import lombok.extern.slf4j.Slf4j;
37 import org.aspectj.weaver.loadtime.Aj;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.web.bind.annotation.*;
42
43 import javax.annotation.Resource;
44 import javax.websocket.Session;
45 import java.lang.reflect.Field;
46 import java.text.ParseException;
47 import java.text.SimpleDateFormat;
48 import java.util.*;
49 import java.util.concurrent.CompletableFuture;
50 import java.util.stream.Collectors;
51 @Slf4j
52 @RestController
53 @RequestMapping("/jcdmMes")
54 public class ExternalInterface {
55     Map<String, Session> map = WebSocketUsers.getUsers();
56
57     private static final Logger logger = LoggerFactory.getLogger("sys-user");
58
59     public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
60
61     @Autowired
62     private IDaTestDeviceInterfaceService daTestDeviceInterfaceService;
63
64     @Autowired
65     private IOmProductionOrdeInfoService omProductionOrdeInfoService;
66
67     @Autowired
68     private IBsFormulaChildInfoService bsFormulaChildInfoService;
69
70     @Autowired
71     private IDaCellDataService daCellDataService;
72
73     @Autowired
74     private IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService;
75
3c8909 76     @Autowired
A 77     private IBsBeatSettingService bsBeatSettingService;
78
b78728 79     /**
A 80      * 导出点检任务列表
81      */
82     @PostMapping("/deviceResultFeedback")
83     public AjaxResult deviceResultFeedback(@RequestBody ParentVO parentVO)
84     {
85         ObjectMapper mapper = new ObjectMapper();
86         List<ChildVO> li = parentVO.getCheckList();
87         String checkList = "";
88         try {
89             checkList = mapper.writeValueAsString(li);
90         } catch (JsonProcessingException e) {
91             throw new RuntimeException(e);
92         }
93         this.saveDaTestDeviceInterface(parentVO,checkList);
94         if(parentVO.getStationCode().equals("M1OP020")){
95             this.saveDaTestDeviceInterfaceTemp(parentVO,checkList);
96         }
97         HttpResponse execute = HttpRequest.post(Constants.FACTORY_EMS_UAT_GET_RUL+"deviceResultFeedback").body(JSONUtil.toJsonStr(parentVO)).execute();
98         return AjaxResult.success(execute.body());
99     }
100
101     public void saveDaTestDeviceInterface(ParentVO parentVO,String checkList){
102         DaTestDeviceInterface daTestDeviceInterface = new DaTestDeviceInterface();
103         daTestDeviceInterface.setRecordId(parentVO.getRecordId());
104         daTestDeviceInterface.setStationCode(parentVO.getStationCode());
105         daTestDeviceInterface.setProductNum(parentVO.getProductNum());
106         daTestDeviceInterface.setTotalResult(parentVO.getTotalResult());
107         daTestDeviceInterface.setCheckList(checkList);
108         daTestDeviceInterface.setCreateTime(new Date());
109         daTestDeviceInterfaceService.save(daTestDeviceInterface);
110     }
111
112     public void saveDaTestDeviceInterfaceTemp(ParentVO parentVO,String checkList){
113         DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = new DaTestDeviceInterfaceTemp();
114         daTestDeviceInterfaceTemp.setRecordId(parentVO.getRecordId());
115         daTestDeviceInterfaceTemp.setStationCode(parentVO.getStationCode());
116         daTestDeviceInterfaceTemp.setProductNum(parentVO.getProductNum());
117         daTestDeviceInterfaceTemp.setTotalResult(parentVO.getTotalResult());
118         daTestDeviceInterfaceTemp.setCheckList(checkList);
119         daTestDeviceInterfaceTemp.setCreateTime(new Date());
120         daTestDeviceInterfaceTempService.save(daTestDeviceInterfaceTemp);
121     }
122
123     @GetMapping("/productionWorkOrderRequest")
124     public AjaxResult productionWorkOrderRequest(){
125         List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list();
126         List<RestFulOrder> restFulOrders = new ArrayList<>();
127         for (OmProductionOrdeInfo omProductionOrdeInfo : list) {
128             RestFulOrder order = new RestFulOrder();
129             order.setProductionOrderNum(omProductionOrdeInfo.getWorkOrderNo());
130             order.setProductNum(omProductionOrdeInfo.getProductNum());
131             order.setMaterialCode(omProductionOrdeInfo.getMaterialCode());
132             order.setStationCode(omProductionOrdeInfo.getStationCode());
133             order.setPlanQty(omProductionOrdeInfo.getPlanQty());
134             order.setCreateTime(format.format(omProductionOrdeInfo.getCreateTime()));
135             restFulOrders.add(order);
136         }
137         return AjaxResult.success(restFulOrders);
138     }
139
140     @GetMapping("/productionOrderComponentRequest")
3c8909 141     public AjaxResult productionOrderComponentRequest(@RequestParam String stationCode,@RequestParam String confirmTime){
A 142         List<BsBeatSetting> list = bsBeatSettingService.list();
143         for (BsBeatSetting bsBeatSetting : list) {
144             String workReportResultFeedback = RestfulService.getWorkReportResultFeedback(bsBeatSetting.getProductCode(), stationCode, confirmTime);
145             System.out.println(workReportResultFeedback);
b78728 146         }
3c8909 147         return AjaxResult.success();
b78728 148     }
A 149
150     /**
151      * 放行请空状态
152      */
153     @PostMapping("/sendWebSocket")
154     public void sendWebSocket(@RequestBody BsFormulaChildInfo bsFormulaChildInfo)
155     {
156         CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
157             logger.info("接收电芯开始执行异步方法");
158             WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), bsFormulaChildInfo.getResults());
159             logger.info("接收电芯异步方法执行结束");
160         });
161 //        WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), bsFormulaChildInfo.getResults());
162     }
163
164     /**
165      * 接收电芯数据
166      */
167     @PostMapping("/receivingBatteryCellData")
168     public AjaxResult receivingBatteryCellData(@RequestBody CellDataVo cellDataVo){
169         try {
170             ObjectMapper objectMapper = new ObjectMapper();
171             JSONObject jsonObject = new JSONObject(cellDataVo);
172             String cellListString = jsonObject.getStr("cellList");
173             JsonNode cellListNode = objectMapper.readValue(cellListString, JsonNode.class);
174             List<DaCellData> daCellDataList = new ArrayList<>();
175             for (JsonNode jsonNode : cellListNode) {
176                 String cellCheckListString = jsonNode.path("cellCheckList").toString();
177                 JsonNode cellCheckListNode = objectMapper.readValue(cellCheckListString, JsonNode.class);
178                 for (JsonNode checkNode : cellCheckListNode) {
179                     //电芯挡位
180                     String batteryCellGear = checkNode.path("cellItem").toString().replaceAll("\"", "");
181                     if(batteryCellGear.equals("电芯档位")){
182                         DaCellData daCellData = new DaCellData();
183                         daCellData.setSiteCode(jsonObject.getStr("siteCode"));
184                         daCellData.setModuleSerial(jsonObject.getStr("moduleSerial"));
185                         daCellData.setModuleModel(jsonObject.getStr("moduleModel"));
186                         daCellData.setAbModule(jsonObject.getStr("ABModule"));
187                         daCellData.setPackageNo(jsonObject.getStr("packageNo"));
188                         daCellData.setSupplierModuleBarcode(jsonObject.getStr("supplierModuleBarcode"));
189                         daCellData.setCustomerModuleBarcode(jsonObject.getStr("customerModuleBarcode"));
190                         daCellData.setCellSerial(jsonNode.path("cellSerial").toString().replaceAll("\"", ""));
191                         daCellData.setCellModel(jsonNode.path("cellModel").toString().replaceAll("\"", ""));
192                         daCellData.setGbCellCode(jsonNode.path("GBCellCode").toString().replaceAll("\"", ""));
193                         daCellData.setGbModuleCode(jsonNode.path("GBModuleCode").toString().replaceAll("\"", ""));
194                         daCellData.setCellItem(checkNode.path("cellItem").toString().replaceAll("\"", ""));
195                         daCellData.setCellValue(checkNode.path("cellValue").toString().replaceAll("\"", ""));
196                         daCellData.setCreateUser("工厂MES");
197                         daCellData.setCreateTime(new Date());
198                         daCellDataList.add(daCellData);
199                     }
200                 }
201             }
202             CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
203                 logger.info("接收电芯开始执行异步方法");
204                 daCellDataService.insertBatch(daCellDataList);
205                 logger.info("接收电芯异步方法执行结束");
206             });
207
208             return AjaxResult.success("API调用成功");
209         }catch (Exception e){
210             return AjaxResult.error("API调用失败");
211         }
212     }
213
214 }