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