MesController.java 4.12 KB
package com.huaheng.api.mes.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.general.domain.ReceiptDomain;
import com.huaheng.api.general.domain.ShipmentDomain;
import com.huaheng.api.general.service.ReceiptApiService;
import com.huaheng.api.general.service.ShipmentApiService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.agv.domain.AgvPort;
import com.huaheng.pc.agv.service.IAgvPortService;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
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.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/MES")
public class MesController {

    @Resource
    private ReceiptApiService receiptApiService;
    @Resource
    private ShipmentApiService shipmentApiService;
    @Resource
    private IAgvPortService agvPortService;

    @PostMapping("/receipt")
    @ResponseBody
    @ApiLogger(apiName = "mes生成入库单", from = "mes", to = "wms")
    public AjaxResult receipt(@RequestBody ReceiptDomain receiptDomain) {
        if (receiptDomain == null) {
            return AjaxResult.error("没有传参");
        }
        if (receiptDomain.getReceiptHeader() == null) {
            return AjaxResult.error("缺少主单据");
        }
        if (receiptDomain.getReceiptDetails() == null) {
            return AjaxResult.error("缺少子单据");
        }
        receiptDomain.getReceiptHeader().setSourcePlatform("MES");
        receiptDomain.getReceiptDetails().forEach(receiptDetail -> {
            if (StringUtils.isEmpty(receiptDetail.getFromPort())) {
                throw new RuntimeException("参数中没有起点位置");
            }
            if(StringUtils.isEmpty(receiptDetail.getContainerCode())){
                throw new RuntimeException("参数中没有托盘号");
            }
        });
        AjaxResult ajaxResult = receiptApiService.receipt(receiptDomain);
        //生成AGV搬运任务 。。。。。。
        return ajaxResult;
    }

    @PostMapping("/shipment")
    @ResponseBody
    @ApiLogger(apiName = "mes生成出库单", from = "mes", to = "wms")
    public AjaxResult shipment(@RequestBody ShipmentDomain shipmentDomain) {
        if (shipmentDomain == null) {
            return AjaxResult.error("没有传参");
        }
        if (shipmentDomain.getShipmentHeader() == null) {
            return AjaxResult.error("缺少主单据");
        }
        if (shipmentDomain.getShipmentDetails() == null) {
            return AjaxResult.error("缺少子单据");
        }
        shipmentDomain.getShipmentHeader().setSourcePlatform("MES");
        shipmentDomain.getShipmentDetails().forEach(shipmentDetail -> {
            shipmentDetail.setSourcePlatform("MES");
            shipmentDetail.setWarehouseCode(QuantityConstant.WAREHOUSECODE);
            shipmentDetail.setCompanyCode(QuantityConstant.COMPANYCODE);
            if (StringUtils.isEmpty(shipmentDetail.getToPort())) {
                throw new RuntimeException("参数中没有终点位置");
            }
        });
        AjaxResult ajaxResult = shipmentApiService.shipment(shipmentDomain);
        //生成AGV搬运任务 。。。。。。
        return ajaxResult;
    }

    @PostMapping("/searchStation")
    @ResponseBody
    @ApiLogger(apiName = "mes查询点位", from = "mes", to = "wms")
    public List<Map<String, Object>> searchStation(){
        LambdaQueryWrapper<AgvPort> agvPortLambdaQueryWrapper = Wrappers.lambdaQuery();
        agvPortLambdaQueryWrapper.select(AgvPort::getCode,AgvPort::getName,AgvPort::getArea).eq(AgvPort::getType,1);
        List<Map<String, Object>> maps = agvPortService.listMaps(agvPortLambdaQueryWrapper);
        return maps;
    }
}