| | |
| | | package com.billion.main.api; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.billion.main.api.domain.OutPutParameters; |
| | | import com.billion.main.api.domain.OutPutParametersChild; |
| | | import com.billion.main.api.domain.ApiResponse; |
| | | import com.billion.main.api.domain.CollectQualityData; |
| | | import com.billion.main.api.domain.WorkOrdersInfo; |
| | | import com.billion.main.api.domain.WorkOrdersInfoChild; |
| | | import com.billion.main.bs.domain.BsBomChildInfo; |
| | | import com.billion.main.bs.domain.BsBomInfo; |
| | | import com.billion.main.bs.service.IBsBomChildInfoService; |
| | | import com.billion.main.bs.service.IBsBomInfoService; |
| | | import com.billion.main.om.domain.OmProductionOrderInfo; |
| | | import com.billion.main.om.service.IOmProductionOrderInfoService; |
| | | import com.billion.main.api.service.IWorkOrdersInfoService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | |
| | | @RestController |
| | | //@Component |
| | | @RequestMapping("/dmMes") |
| | | public class RestfulAPI { |
| | | |
| | | @Autowired |
| | | private IOmProductionOrderInfoService OmProductionOrderInfoService; |
| | | @Autowired |
| | | private IBsBomInfoService bsBomInfoService; |
| | | @Autowired |
| | | private IBsBomChildInfoService bsBomChildInfoService; |
| | | private IWorkOrdersInfoService iWorkOrdersInfoService; |
| | | |
| | | public static final String getQualityData = "IP地址/CollectQualityData"; |
| | | /** |
| | |
| | | * 2、产线MES将接收到的工单信息存入到工单表和BOM表 |
| | | */ |
| | | @PostMapping("/receiveWorkOrdersInfo") |
| | | public OutPutParameters receiveWorkOrdersInfo(@RequestBody WorkOrdersInfo workOrdersInfo) { |
| | | //保存参数 |
| | | List<OmProductionOrderInfo> productionOrderInfoList = new ArrayList<>(); |
| | | List<BsBomInfo> bomInfoList = new ArrayList<>(); |
| | | List<BsBomChildInfo> bomChildInfoList = new ArrayList<>(); |
| | | List<WorkOrdersInfoChild> data = workOrdersInfo.getData(); |
| | | for (WorkOrdersInfoChild workOrdersInfoChild : data) { |
| | | OmProductionOrderInfo omProductionOrderInfo = new OmProductionOrderInfo(); |
| | | BsBomInfo bsBomInfo = new BsBomInfo(); |
| | | BsBomChildInfo bsBomChildInfo = new BsBomChildInfo(); |
| | | //保存工单信息 |
| | | omProductionOrderInfo.setWorkOrderNo(workOrdersInfo.getOrderNumber()); |
| | | omProductionOrderInfo.setSalesOrderCode(workOrdersInfo.getBatchNumber()); |
| | | omProductionOrderInfo.setProductCode(workOrdersInfo.getMaterialNumber()); |
| | | omProductionOrderInfo.setEngineTye(workOrdersInfo.getEngineType()); |
| | | omProductionOrderInfo.setEngineName(workOrdersInfo.getEngineName()); |
| | | omProductionOrderInfo.setPlanQty(Long.valueOf(workOrdersInfo.getProduction_Plan())); |
| | | omProductionOrderInfo.setPlanStartTime(workOrdersInfo.getStartTime()); |
| | | omProductionOrderInfo.setRemarks(workOrdersInfo.getDescription()); |
| | | omProductionOrderInfo.setOrderStatus(workOrdersInfo.getState()); |
| | | omProductionOrderInfo.setFlag(workOrdersInfo.getFLAG()); |
| | | //保存BOM主表信息 |
| | | bsBomInfo.setBomCode(workOrdersInfo.getBomName()); |
| | | bsBomInfo.setBomName(workOrdersInfo.getBomName()); |
| | | bsBomInfo.setProductCode(workOrdersInfo.getMaterialNumber()); |
| | | bsBomInfo.setProductName(workOrdersInfo.getMaterialNumber()); |
| | | //保存BOM子表信息 |
| | | bsBomChildInfo.setProductCode(workOrdersInfo.getMaterialNumber()); |
| | | bsBomChildInfo.setProductName(workOrdersInfo.getMaterialNumber()); |
| | | bsBomChildInfo.setBomCode(workOrdersInfo.getBomName()); |
| | | bsBomChildInfo.setLocationCode(workOrdersInfoChild.getStationName()); |
| | | bsBomChildInfo.setLocationName(workOrdersInfoChild.getStationName()); |
| | | bsBomChildInfo.setMaterialCode(workOrdersInfoChild.getMaterial()); |
| | | bsBomChildInfo.setCostQty(workOrdersInfoChild.getCount()); |
| | | bsBomChildInfo.setChecked(workOrdersInfoChild.getChecked()); |
| | | bsBomChildInfo.setMaterialName(workOrdersInfoChild.getMaterialName()); |
| | | // |
| | | public ApiResponse receiveWorkOrdersInfo(@RequestBody WorkOrdersInfo workOrdersInfo) { |
| | | try { |
| | | // 调用service层保存数据 |
| | | boolean saveResult = iWorkOrdersInfoService.saveWorkOrders(workOrdersInfo); |
| | | // 构建响应数据 |
| | | ApiResponse response = new ApiResponse(); |
| | | List<ApiResponse.ResponseData> dataList = new ArrayList<>(); |
| | | ApiResponse.ResponseData responseData = new ApiResponse.ResponseData(); |
| | | if (saveResult) { |
| | | response.setCode("success"); |
| | | response.setMessage("API调用成功"); |
| | | responseData.setProductionID(workOrdersInfo.getProductionID()); |
| | | responseData.setResultCode("S"); |
| | | responseData.setResultText("采集完成"); |
| | | } else { |
| | | response.setCode("fail"); |
| | | response.setMessage("API调用失败"); |
| | | responseData.setProductionID(workOrdersInfo.getProductionID()); |
| | | responseData.setResultCode("F"); |
| | | responseData.setResultText("采集失败"); |
| | | } |
| | | dataList.add(responseData); |
| | | response.setData(dataList); |
| | | return response; |
| | | } catch (Exception e) { |
| | | // 异常处理 |
| | | ApiResponse response = new ApiResponse(); |
| | | response.setCode("fail"); |
| | | response.setMessage("API调用失败"); |
| | | List<ApiResponse.ResponseData> dataList = new ArrayList<>(); |
| | | ApiResponse.ResponseData responseData = new ApiResponse.ResponseData(); |
| | | responseData.setProductionID(workOrdersInfo.getProductionID()); |
| | | responseData.setResultCode("F"); |
| | | responseData.setResultText("采集失败"); |
| | | dataList.add(responseData); |
| | | response.setData(dataList); |
| | | return response; |
| | | } |
| | | OutPutParameters outputParams = new OutPutParameters(); |
| | | //判断保存的三个list是否为空 |
| | | if (CollUtil.isNotEmpty(productionOrderInfoList) && CollUtil.isNotEmpty(bomInfoList) && CollUtil.isNotEmpty(bomChildInfoList)) { |
| | | //插入数据库 |
| | | OmProductionOrderInfoService.insertBatch(productionOrderInfoList); |
| | | bsBomInfoService.insertBatch(bomInfoList); |
| | | bsBomChildInfoService.insertBatch(bomChildInfoList); |
| | | //出参 |
| | | OutPutParametersChild child = new OutPutParametersChild(workOrdersInfo.getMaterialNumber(), "S", "采集完成"); |
| | | outputParams.addData(child); |
| | | } else { |
| | | OutPutParametersChild child = new OutPutParametersChild(workOrdersInfo.getMaterialNumber(), "F", "采集失败"); |
| | | outputParams.addData(child); |
| | | } |
| | | |
| | | return outputParams; |
| | | } |
| | | @PostMapping("/CollectQualityData") |
| | | public CollectQualityData CollectQualityData(@RequestBody CollectQualityData collectQualityData){ |
| | | |
| | | return collectQualityData; |
| | | } |
| | | |
| | | |
| | | } |