cl
2024-07-11 6c345c06709a286a2a7dd3fa27d5348e7a57bfa0
提交 | 用户 | 时间
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) {
1c7c81 197                     //电芯挡位
A 198                     String batteryCellGear = checkNode.path("cellItem").toString().replaceAll("\"", "");
199                     if(batteryCellGear.equals("电芯档位")){
22c9e0 200                         DaCellData daCellData = new DaCellData();
A 201                         daCellData.setSiteCode(jsonObject.getStr("siteCode"));
202                         daCellData.setModuleSerial(jsonObject.getStr("moduleSerial"));
203                         daCellData.setModuleModel(jsonObject.getStr("moduleModel"));
204                         daCellData.setAbModule(jsonObject.getStr("ABModule"));
205                         daCellData.setPackageNo(jsonObject.getStr("packageNo"));
206                         daCellData.setSupplierModuleBarcode(jsonObject.getStr("supplierModuleBarcode"));
207                         daCellData.setCustomerModuleBarcode(jsonObject.getStr("customerModuleBarcode"));
208                         daCellData.setCellSerial(jsonNode.path("cellSerial").toString().replaceAll("\"", ""));
209                         daCellData.setCellModel(jsonNode.path("cellModel").toString().replaceAll("\"", ""));
210                         daCellData.setGbCellCode(jsonNode.path("GBCellCode").toString().replaceAll("\"", ""));
211                         daCellData.setGbModuleCode(jsonNode.path("GBModuleCode").toString().replaceAll("\"", ""));
212                         daCellData.setCellItem(checkNode.path("cellItem").toString().replaceAll("\"", ""));
213                         daCellData.setCellValue(checkNode.path("cellValue").toString().replaceAll("\"", ""));
214                         daCellData.setCreateUser("工厂MES");
215                         daCellData.setCreateTime(new Date());
216                         daCellDataList.add(daCellData);
217                     }
bd9653 218                 }
0ca254 219             }
8f92f2 220             CompletableFuture<Void> cp1 = CompletableFuture.runAsync(() -> {
5e34d9 221                 logger.info("接收电芯开始执行异步方法");
8f92f2 222                 daCellDataService.insertBatch(daCellDataList);
A 223                 logger.info("接收电芯异步方法执行结束");
224             });
225
bd9653 226             return AjaxResult.success("API调用成功");
A 227         }catch (Exception e){
228             return AjaxResult.error("API调用失败");
0ca254 229         }
A 230     }
231
232 }