AcsController.java 8.53 KB
package com.huaheng.api.acs.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.huaheng.api.acs.domain.*;
import com.huaheng.api.wcs.controller.EmptyContainerController;
import com.huaheng.api.wcs.domain.ManyEmptyDomain;
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.pc.task.agvTask.domain.AgvTask;
import org.springframework.web.bind.annotation.*;

import com.huaheng.api.acs.service.AcsReceiptService;
import com.huaheng.api.acs.service.AcsService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.OkHttpUtils;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.mobile.receipt.ReceiptBill;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.sap.domain.WeightRollNumberInfo;
import com.huaheng.pc.sap.service.WeightRollNumberInfoService;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/agv")
public class AcsController extends BaseController {

    @Resource
    private AcsService acsService;
    @Resource
    private WeightRollNumberInfoService weightRollNumberInfoService;
    @Resource
    private AddressService addressService;
    @Resource
    private AcsReceiptService acsReceiptService;
    @Resource
    private EmptyContainerController emptyContainerController;
    @Resource
    private ConfigService configService;


    /**
     * status 20 任务执行中;
     * 50 取货完成;
     * 90 任务完成;
     * @param  acsStatus
     * @return
     */
    @PostMapping("/notifyAGVTask")
    @ApiOperation("更新AGV状态")
    @ResponseBody
    @ApiLogger(apiName = "更新AGV状态", from = "acs")
    public AjaxResult notifyAGVTask(@RequestBody AcsStatus acsStatus) {

        if(acsStatus.getStatus() > 0){
            switch (acsStatus.getStatus()){
                case 100:
                    AgvTask agvTask = new AgvTask();
                    agvTask.setTaskNo(Integer.valueOf(acsStatus.getTaskNo()));
                    agvTask.setState(acsStatus.getStatus());
                    agvTask.setZoneCode("AGV");
                    return acsService.busTaskFinish(agvTask);
                default:
                    return AjaxResult.success();
            }
        }

        AjaxResult ajaxResult = handleMultiProcess("notifyAGVTask", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = acsService.notifyAGVTask(acsStatus);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }

    /**
     * status 20 任务执行中;
     * 50 取货完成;
     * 90 任务完成;
     * @param  acsStatus
     * @return
     */
    @PostMapping("/bindContainer")
    @ApiOperation("玻璃布物料绑定托盘")
    @ResponseBody
    @ApiLogger(apiName = "玻璃布物料绑定托盘", from = "acs")
    public AjaxResult bindContainer(@RequestBody AcsStatus acsStatus) {
        AjaxResult ajaxResult = handleMultiProcess("bindContainer", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = acsService.bindContainer(acsStatus);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }



    /**
     * pltype 1->片状托架0->卷状托架,2->特殊托架
     * containerType 1.请求入库卷托盘;2.请求入库片托盘;
     * 3.请求出库卷托盘;0.请求出片状托盘
     * @param  param
     * @return
     */

    @PostMapping("/agvCallEmptyOut")
    @ApiOperation("ACS呼叫空托盘出库")
    @ResponseBody
    @ApiLogger(apiName = "ACS呼叫空托盘出库", from = "acs")
    public AjaxResult agvCallEmptyOut(@RequestBody AGVCallParam param) {
        Integer containerType = param.getContainerType();
        Integer taskId = param.getTaskId();
        String port = param.getPort();
        int area = param.getArea();
        String warehouseCode = param.getWarehouseCode();
        if (area == 0) {
            return AjaxResult.error("库区不嫩为空");
        }
//        if (area == 1) {
//            containerType = 0;
//        }
        if (containerType == null) {
            return AjaxResult.error("容器类型不存在");
        }
        if (StringUtils.isEmpty(port)) {
            return AjaxResult.error("站台不能为空");
        }
        if (StringUtils.isEmpty(warehouseCode)) {
            return AjaxResult.error("仓库不能为空");
        }
        AjaxResult ajaxResult = null;
        Integer finalContainerType = containerType;
        if(area == 1){
            ManyEmptyDomain domain = new ManyEmptyDomain();
            domain.setWarehouseCode(QuantityConstant.WAREHOUSECODE);
            domain.setArea("1");
            domain.setPort(port);
            domain.setTaskId(taskId);
            ajaxResult = emptyContainerController.wcsCallEmptyOut(domain);
        }else{
            ajaxResult = handleQuest("agvCallEmptyOut", new MultiProcessListener() {
                @Override
                public AjaxResult doProcess() {
                    AjaxResult ajaxResult = acsService.agvCallEmptyOut(area, port, warehouseCode, finalContainerType);
                    return ajaxResult;
                }
            });
        }

        return ajaxResult;
    }

    @PostMapping("/getReceiptContainerByB")
    @ApiOperation("ACS传入入库数据")
    @ResponseBody
    @ApiLogger(apiName = "ACS传入入库数据", from = "acs")
    public AjaxResult getReceiptContainerByB(@RequestBody RobotDomain robotDomain) {
        if(robotDomain == null){
            return AjaxResult.error("请求内容不能为空");
        }
        // 容器
        String containerCode = robotDomain.getContainerCode();
        // 位置
        Integer position = robotDomain.getPosition();
        // 垛型
        Integer stackType = robotDomain.getStackType();
        // 子托盘高度
        Integer height = robotDomain.getHeight();
        // 结束标志
        Integer finish = robotDomain.getFinish();
        // 物料编码
        String materialCode = robotDomain.getMaterialCode();
        // 数量
        BigDecimal qty = robotDomain.getQty();
        // 批次
        String lot = robotDomain.getLot();
        //箱类型
        Integer boxType = robotDomain.getBoxType();

        if(StringUtils.isEmpty(containerCode)){
            return AjaxResult.error("托盘号不能为空!");
        }
        if(StringUtils.isNull(position)){
            return AjaxResult.error("位置号不能为空!");
        }
        if(StringUtils.isNull(stackType)){
            return AjaxResult.error("垛型不能为空!");
        }
        AjaxResult ajaxResult = handleQuest("agvCallEmptyOut", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                return acsReceiptService.saveReceiptDetail(robotDomain);
            }
        });

        return ajaxResult;
    }

    @PostMapping("/pushWeightRollNumber")
    @ApiOperation("推送卷号重量信息")
    @ResponseBody
    @ApiLogger(apiName = "推送卷号重量信息", from = "acs")
    public AjaxResult pushWeightRollNumber(@RequestBody WeightRollNumberInfo weightRollNumberInfo) {
        String rollNumber = weightRollNumberInfo.getRollNumber();
        if (StringUtils.isEmpty(rollNumber)) {
            return AjaxResult.error("卷号不为空:");
        }
        AjaxResult ajaxResult = handleQuest("pushWeightRollNumber", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                boolean save = weightRollNumberInfoService.save(weightRollNumberInfo);
                Map<String,String> headerBodyPost = null;
                try {
                    String url = configService.getKey(QuantityConstant.WEIGHT_ROLLNUMBER_URL);
                    url = url + "?charg="+rollNumber+"&werks=SC00";
                    headerBodyPost = OkHttpUtils.sendGet(url);
                    weightRollNumberInfo.setSend(1);
                    weightRollNumberInfoService.updateById(weightRollNumberInfo);
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    return AjaxResult.toAjax(save).setData(headerBodyPost);
                }
            }
        });
        return ajaxResult;
    }
}