EmptyContainerController.java 6.42 KB
package com.huaheng.api.wcs.controller;


import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.wcs.domain.ManyEmptyDomain;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
import com.huaheng.api.wcs.service.warecellAllocation.LocationAllocationService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
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.framework.web.service.ConfigService;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.containerType.domain.ContainerType;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.locationHigh.domain.LocationHigh;
import com.huaheng.pc.config.locationHigh.service.LocationHighService;
import com.huaheng.pc.config.locationType.domain.LocationType;
import com.huaheng.pc.config.locationType.service.LocationTypeService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import com.huaheng.pc.task.taskHeader.service.WorkTaskService;
//import com.sun.javafx.tk.Toolkit;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

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

    @Resource
    private WorkTaskService workTaskService;
    @Resource
    private LocationAllocationService allocationService;
    @Resource
    private ConfigService configService;
    @Resource
    private ZoneService zoneService;
    @Resource
    private LocationService locationService;
    @Resource
    private LocationTypeService locationTypeService;
    @Resource
    private LocationHighService locationHighService;
    @Resource
    private ContainerService containerService;
    @Resource
    private ContainerTypeService containerTypeService;
    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private TaskAssignService taskAssignService;
    @Resource
    private InventoryHeaderService inventoryHeaderService;

    /**
     * 生成空托盘组入库任务
     * @return
     */
    @PostMapping("/manyEmptyIn")
    @Log(title = "任务-任务管理", operating = "生成空托盘组入库任务", action = BusinessType.INSERT)
    @Transactional
    @ApiLogger(apiName = "manyEmptyIn", from="WCS")
    public AjaxResult manyEmptyIn(@RequestBody ManyEmptyDomain manyEmptyDomain) {
        return handleMultiProcess(() -> containerService.innerManyEmptyIn(manyEmptyDomain));
    }

    /**
     * 生成空托盘组出库任务
     * @return
     */
    @PostMapping("/manyEmptyOut")
    @Log(title = "任务-任务管理", operating = "生成空托盘组出库任务", action = BusinessType.INSERT)
    @Transactional
    @ApiLogger(apiName = "manyEmptyOut", from="WCS")
    public AjaxResult manyEmptyOut(@RequestBody ManyEmptyDomain manyEmptyDomain) {
        return handleMultiProcess(() -> containerService.innerManyEmptyOut(manyEmptyDomain));
    }

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

    private AjaxResult innerWcsCallEmptyOut(ManyEmptyDomain manyEmptyDomain) {
        String warehouseCode = manyEmptyDomain.getWarehouseCode();
        String area = manyEmptyDomain.getArea();
        String port = manyEmptyDomain.getPort();
        if(warehouseCode == null) {
            return AjaxResult.error("warehouseCode 不能为空");
        }
        if(area == null) {
            return AjaxResult.error("area 不能为空");
        }
        if(port == null) {
            return AjaxResult.error("port 不能为空");
        }
        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不正确,没有找到对应区域");
        }
        String zoneCode = zone.getCode();
        List<Location> list = containerService.getEmptyContainerInLocation(zoneCode,
                "","", warehouseCode);
        if(list == null || list.size() <= 0) {
            return AjaxResult.error("没有找到空托盘");
        }
        Location location = list.get(0);
        String containerCode = location.getContainerCode();
        String locationCode = location.getCode();
        return inventoryHeaderService.createEmptyOut(containerCode, locationCode, port, warehouseCode);
    }
}