admin
2024-07-05 20635fa3540068045b07471f08ab107b9d0f4281
提交 | 用户 | 时间
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;
0691dd 12 import com.fasterxml.jackson.databind.JsonNode;
0ca254 13 import com.fasterxml.jackson.databind.ObjectMapper;
A 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;
0691dd 22 import com.jcdm.main.da.cellData.domain.DaCellData;
A 23 import com.jcdm.main.da.cellData.service.IDaCellDataService;
0ca254 24 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
A 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;
475e40 30 import com.jcdm.main.da.testDeviceInterfaceTemp.domain.DaTestDeviceInterfaceTemp;
A 31 import com.jcdm.main.da.testDeviceInterfaceTemp.service.IDaTestDeviceInterfaceTempService;
0ca254 32 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
A 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
0691dd 71     private IDaCellDataService daCellDataService;
0ca254 72
475e40 73     @Autowired
A 74     private IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService;
20635f 75     String url = Constants.FACTORY_EMS_UAT_RUL+"deviceResultFeedback";
475e40 76
20635f 77 //    String url = "https://imes-uat-group.geelycv-test.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
0ca254 78
0691dd 79 //    String url = "https://imes-group.geelycv.com/api/mom-open/restful/aMesSysIntegration/deviceResultFeedback";
0ca254 80
0691dd 81     /**
A 82      * 20工位接收清研数据
83      */
84     @PostMapping("/receiveOVCDataFrom020Workstations")
85     public AjaxResult receiveOVCDataFrom020Workstations(@RequestBody ParentVO parentVO)
86     {
87
88         return AjaxResult.success(null);
89     }
0ca254 90
A 91     /**
92      * 导出点检任务列表
93      */
94     @PostMapping("/deviceResultFeedback")
0691dd 95     public AjaxResult deviceResultFeedback(@RequestBody ParentVO parentVO)
0ca254 96     {
A 97         ObjectMapper mapper = new ObjectMapper();
98         List<ChildVO> li = parentVO.getCheckList();
475e40 99         String checkList = "";
0ca254 100         try {
475e40 101             checkList = mapper.writeValueAsString(li);
0ca254 102         } catch (JsonProcessingException e) {
A 103             throw new RuntimeException(e);
104         }
475e40 105         this.saveDaTestDeviceInterface(parentVO,checkList);
A 106         if(parentVO.getStationCode().equals("M1OP020")){
107             this.saveDaTestDeviceInterfaceTemp(parentVO,checkList);
108         }
109         HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(parentVO)).execute();
110         return AjaxResult.success(execute.body());
111     }
112
113     public void saveDaTestDeviceInterface(ParentVO parentVO,String checkList){
0ca254 114         DaTestDeviceInterface daTestDeviceInterface = new DaTestDeviceInterface();
A 115         daTestDeviceInterface.setRecordId(parentVO.getRecordId());
116         daTestDeviceInterface.setStationCode(parentVO.getStationCode());
117         daTestDeviceInterface.setProductNum(parentVO.getProductNum());
118         daTestDeviceInterface.setTotalResult(parentVO.getTotalResult());
475e40 119         daTestDeviceInterface.setCheckList(checkList);
0ca254 120         daTestDeviceInterface.setCreateTime(new Date());
A 121         daTestDeviceInterfaceService.save(daTestDeviceInterface);
475e40 122     }
A 123
124     public void saveDaTestDeviceInterfaceTemp(ParentVO parentVO,String checkList){
125         DaTestDeviceInterfaceTemp daTestDeviceInterfaceTemp = new DaTestDeviceInterfaceTemp();
126         daTestDeviceInterfaceTemp.setRecordId(parentVO.getRecordId());
127         daTestDeviceInterfaceTemp.setStationCode(parentVO.getStationCode());
128         daTestDeviceInterfaceTemp.setProductNum(parentVO.getProductNum());
129         daTestDeviceInterfaceTemp.setTotalResult(parentVO.getTotalResult());
130         daTestDeviceInterfaceTemp.setCheckList(checkList);
131         daTestDeviceInterfaceTemp.setCreateTime(new Date());
132         daTestDeviceInterfaceTempService.save(daTestDeviceInterfaceTemp);
0ca254 133     }
A 134
135     @GetMapping("/productionWorkOrderRequest")
136     public AjaxResult productionWorkOrderRequest(){
137         List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list();
138         List<RestFulOrder> restFulOrders = new ArrayList<>();
139         for (OmProductionOrdeInfo omProductionOrdeInfo : list) {
140             RestFulOrder order = new RestFulOrder();
141             order.setProductionOrderNum(omProductionOrdeInfo.getWorkOrderNo());
142             order.setProductNum(omProductionOrdeInfo.getProductNum());
143             order.setMaterialCode(omProductionOrdeInfo.getMaterialCode());
144             order.setStationCode(omProductionOrdeInfo.getStationCode());
145             order.setPlanQty(omProductionOrdeInfo.getPlanQty());
146             order.setCreateTime(format.format(omProductionOrdeInfo.getCreateTime()));
147             restFulOrders.add(order);
148         }
149         return AjaxResult.success(restFulOrders);
150     }
151
152     @GetMapping("/productionOrderComponentRequest")
153     public AjaxResult productionOrderComponentRequest(BsFormulaChildInfo bsFormulaChildInfo){
154         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
155                 .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getProcessesCode())
156                 .eq(BsFormulaChildInfo::getOperationType, "2")
157         );
158         List<ProductionOrderComponentRequest> requests = new ArrayList<>();
159         for (BsFormulaChildInfo info : list) {
160             ProductionOrderComponentRequest request = new ProductionOrderComponentRequest();
161             request.setMaterialCode(info.getMaterialCode());
162             request.setOperationSteps(info.getOperationSteps());
163             requests.add(request);
164         }
165         return AjaxResult.success(requests);
166     }
167
168     /**
169      * 放行请空状态
170      */
171     @PostMapping("/sendWebSocket")
172     public void sendWebSocket(@RequestBody BsFormulaChildInfo bsFormulaChildInfo)
173     {
22c9e0 174         CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
A 175             logger.info("接收电芯开始执行异步方法");
176             WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), bsFormulaChildInfo.getResults());
177             logger.info("接收电芯异步方法执行结束");
178         });
179 //        WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), bsFormulaChildInfo.getResults());
0ca254 180     }
A 181
182     /**
0691dd 183      * 接收电芯数据
0ca254 184      */
0691dd 185     @PostMapping("/receivingBatteryCellData")
bd9653 186     public AjaxResult receivingBatteryCellData(@RequestBody CellDataVo cellDataVo){
A 187         try {
188             ObjectMapper objectMapper = new ObjectMapper();
189             JSONObject jsonObject = new JSONObject(cellDataVo);
190             String cellListString = jsonObject.getStr("cellList");
191             JsonNode cellListNode = objectMapper.readValue(cellListString, JsonNode.class);
192             List<DaCellData> daCellDataList = new ArrayList<>();
193             for (JsonNode jsonNode : cellListNode) {
194                 String cellCheckListString = jsonNode.path("cellCheckList").toString();
195                 JsonNode cellCheckListNode = objectMapper.readValue(cellCheckListString, JsonNode.class);
196                 for (JsonNode checkNode : cellCheckListNode) {
22c9e0 197                     if(checkNode.path("cellItem").toString().replaceAll("\"", "").equals("电芯挡位")){
A 198                         DaCellData daCellData = new DaCellData();
199                         daCellData.setSiteCode(jsonObject.getStr("siteCode"));
200                         daCellData.setModuleSerial(jsonObject.getStr("moduleSerial"));
201                         daCellData.setModuleModel(jsonObject.getStr("moduleModel"));
202                         daCellData.setAbModule(jsonObject.getStr("ABModule"));
203                         daCellData.setPackageNo(jsonObject.getStr("packageNo"));
204                         daCellData.setSupplierModuleBarcode(jsonObject.getStr("supplierModuleBarcode"));
205                         daCellData.setCustomerModuleBarcode(jsonObject.getStr("customerModuleBarcode"));
206                         daCellData.setCellSerial(jsonNode.path("cellSerial").toString().replaceAll("\"", ""));
207                         daCellData.setCellModel(jsonNode.path("cellModel").toString().replaceAll("\"", ""));
208                         daCellData.setGbCellCode(jsonNode.path("GBCellCode").toString().replaceAll("\"", ""));
209                         daCellData.setGbModuleCode(jsonNode.path("GBModuleCode").toString().replaceAll("\"", ""));
210                         daCellData.setCellItem(checkNode.path("cellItem").toString().replaceAll("\"", ""));
211                         daCellData.setCellValue(checkNode.path("cellValue").toString().replaceAll("\"", ""));
212                         daCellData.setCreateUser("工厂MES");
213                         daCellData.setCreateTime(new Date());
214                         daCellDataList.add(daCellData);
215                     }
216 //                    DaCellData daCellData = new DaCellData();
217 //                    daCellData.setSiteCode(jsonObject.getStr("siteCode"));
218 //                    daCellData.setModuleSerial(jsonObject.getStr("moduleSerial"));
219 //                    daCellData.setModuleModel(jsonObject.getStr("moduleModel"));
220 //                    daCellData.setAbModule(jsonObject.getStr("ABModule"));
221 //                    daCellData.setPackageNo(jsonObject.getStr("packageNo"));
222 //                    daCellData.setSupplierModuleBarcode(jsonObject.getStr("supplierModuleBarcode"));
223 //                    daCellData.setCustomerModuleBarcode(jsonObject.getStr("customerModuleBarcode"));
224 //                    daCellData.setCellSerial(jsonNode.path("cellSerial").toString().replaceAll("\"", ""));
225 //                    daCellData.setCellModel(jsonNode.path("cellModel").toString().replaceAll("\"", ""));
226 //                    daCellData.setGbCellCode(jsonNode.path("GBCellCode").toString().replaceAll("\"", ""));
227 //                    daCellData.setGbModuleCode(jsonNode.path("GBModuleCode").toString().replaceAll("\"", ""));
228 //                    daCellData.setCellItem(checkNode.path("cellItem").toString().replaceAll("\"", ""));
229 //                    daCellData.setCellValue(checkNode.path("cellValue").toString().replaceAll("\"", ""));
230 //                    daCellData.setCreateUser("工厂MES");
231 //                    daCellData.setCreateTime(new Date());
232 //                    daCellDataList.add(daCellData);
bd9653 233                 }
0ca254 234             }
8f92f2 235             CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
5e34d9 236                 logger.info("接收电芯开始执行异步方法");
8f92f2 237                 daCellDataService.insertBatch(daCellDataList);
A 238                 logger.info("接收电芯异步方法执行结束");
239             });
240
bd9653 241             return AjaxResult.success("API调用成功");
A 242         }catch (Exception e){
243             return AjaxResult.error("API调用失败");
0ca254 244         }
A 245     }
246
247 }