PdaCallEmptyOut.java 4.49 KB
package com.huaheng.api.pda.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


@RestController
@RequestMapping("/API/WMS/v2")
public class PdaCallEmptyOut extends BaseController {

    @Resource
    private ZoneService zoneService;
    @Resource
    private ContainerService containerService;
    @Resource
    private InventoryHeaderService inventoryHeaderService;

    /**
     * 生成空托出库任务
     * @return
     */
    @PostMapping("/PdaCallEmptyOut")
    @Log(title = "任务-任务管理", operating = "PDA生成空托出库任务", action = BusinessType.INSERT)
    @ResponseBody
    @Transactional
    @ApiLogger(apiName = "PDA生成空托出库任务", from="PDA")
    public AjaxResult wcsCallEmptyOut(Integer count,String port) {
        AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = innerWcsCallEmptyOut(count,port);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }

    private AjaxResult innerWcsCallEmptyOut(Integer count,String port) {
        String warehouseCode = "CS0001";
        String area = "1";
        if (count == null){
            return AjaxResult.error("数量不能为空");
        }
        if (count>5){
            return AjaxResult.error("数量不能大于5");
        }
        if (count<=0){
            return AjaxResult.error("数量不能小于等于0");
        }
        if(port == null) {
            return AjaxResult.error("port 不能为空");
        }
        if (!port.equals("P2001")&&!port.equals("P1001")){
            return AjaxResult.error("没有"+port+"这个站台");
        }
        AjaxResult ajaxResult =new AjaxResult();
        List<String> roadWay=new ArrayList<>();
        roadWay.add("1");
        roadWay.add("2");
        for (int i = 0; i < count; i++) {
            LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
            zoneLambdaQueryWrapper.eq(Zone::getWarehouseCode, warehouseCode)
                    .eq(Zone::getArea, area);
            Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
            if(zone == null) {
                return AjaxResult.error("area不正确,没有找到对应区域");
            }
            Collections.shuffle(roadWay);
            String roadWays = roadWay.get(0);
            String zoneCode = zone.getCode();
            List<Location> list = containerService.getEmptyContainerInLocation(zoneCode, "","", warehouseCode,roadWays);
            if(list == null || list.size() <= 0) {
                roadWays = roadWay.get(1);
                list = containerService.getEmptyContainerInLocation(zoneCode,
                        "","", warehouseCode,roadWays);
                if(list == null || list.size() <= 0) {
                    return AjaxResult.error("已呼叫"+(i+1)+"个托盘,库内已没有空托盘");
                }
            }
            Location location = list.get(0);
            String containerCode = location.getContainerCode();
            String locationCode = location.getCode();
            ajaxResult=inventoryHeaderService.createEmptyOut(containerCode, locationCode, port, warehouseCode);
            if (ajaxResult.hasErr()){
                return AjaxResult.error("在呼叫第"+(i+1)+"个空托失败,"+ajaxResult.getMsg());
            }
        }
        return ajaxResult;
    }

}