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