hdy
2024-12-28 9e2f3b91a51c181cb4a0d247419c58daa3937b7b
billion-main/src/main/java/com/billion/main/api/RestfulAPI.java
@@ -1,17 +1,103 @@
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.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 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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;
    public static final String getQualityData = "IP地址/CollectQualityData";
    /**
     * 接收工单信息
     * 1、工厂MES调用接收工单接口,将工单信息发送给产线MES
     * 2、产线MES将接收到的工单信息存入到工单表和BOM表
     */
    @PostMapping("/receiveWorkOrdersInfo")
    public void receiveWorkOrdersInfo(@RequestBody Object object){
    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());
            //
        }
        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);
            outputParams.toJson();
        } else {
            OutPutParametersChild child = new OutPutParametersChild(workOrdersInfo.getMaterialNumber(), "F", "采集失败");
            outputParams.addData(child);
            outputParams.toJson();
        }
        return outputParams;
    }
}