MobileInventoryController.java 4.86 KB
package com.huaheng.mobile.inventory;


import com.alibaba.fastjson.JSONException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.general.location.domain.Location;
import com.huaheng.pc.general.location.service.ILocationService;
import com.huaheng.pc.inventory.inventory.domain.Inventory;
import com.huaheng.pc.inventory.inventory.service.IInventoryService;
import com.huaheng.pc.task.task.service.ITaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

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

@CrossOrigin
@RestController
@RequestMapping("/mobile/inventory")
@Api(tags = {"MobileInventoryController"}, description = "手机立体库库存相关")
public class MobileInventoryController {

    @Resource
    private IInventoryService inventoryService;
    @Resource
    private ITaskService taskService;
    @Resource
    private ILocationService locationService;

    @PostMapping("/getInventoryInfo")
    @ApiOperation("移动端获得库存详情")
    @Log(title = "移动端获得库存详情", action = BusinessType.OTHER)
    public AjaxResult getInventoryInfo(@RequestBody @ApiParam(value="物料编码或者库位号") Map<String, String> param) {
        if  (param.get("code") == null || param.get("code").trim().length() < 1)
            throw new JSONException("查询码(code)不能为空");
       return  inventoryService.selectListEntityByCode(param.get("code"));
    }

    @PostMapping("/getInventoryForecast")
    @ApiOperation("移动端获得库存联想词")
    @Log(title = "移动端获得库存联想词", action = BusinessType.OTHER)
    public AjaxResult getInventoryForecast(@RequestBody @ApiParam(value="物料编码或者库位号") Map<String, String> param) {
        if  (param.get("code") == null || param.get("code").trim().length() < 1)
            throw new JSONException("查询码(code)不能为空");
        return  inventoryService.getInventoryForecast(param.get("code"));
    }

    @PostMapping("/createCheckOutTask")
    @ApiOperation("移动端创建出库查看任务")
    @ResponseBody
    public AjaxResult createCheckOutTask(@RequestBody @ApiParam(value="库存ids") Map<String, String> param){
        String ids = param.get("ids");
        if(StringUtils.isEmpty(ids)){
            return AjaxResult.error("ids不能为空");
        }
        return taskService.createMobileCheckOutTask(ids.split(","));
    }

    @PostMapping("/transfer")
    @ApiOperation("移动端创建移库任务")
    @ResponseBody
    public AjaxResult transfer(@RequestBody @ApiParam(value="库位情况") Map<String, String> param){
        String sourceLocation = param.get("sourceLocation");
        String destinationLocation = param.get("destinationLocation");
        return taskService.createMobileTransferTask(sourceLocation,destinationLocation);
    }

    @PostMapping( "/execute")
    @ApiOperation("执行立库任务")
    @ResponseBody
    public AjaxResult execute(@RequestBody @ApiParam(value="任务id") Map<String, String> param)
    {
        String taskId = param.get("taskId");
        if (StringUtils.isEmpty(taskId))
            return AjaxResult.error("taskId不能为空");
        AjaxResult ajaxResult = taskService.sendTaskToWcs(Convert.toIntArray(taskId));
        return ajaxResult;
    }

    @PostMapping( "/isLocation")
    @ApiOperation("判断是不是库位")
    @ResponseBody
    public AjaxResult isLocation(@RequestBody @ApiParam(value="任务id") Map<String, String> param)
    {
        String code = param.get("code");
        if (StringUtils.isEmpty(code))
            return AjaxResult.error("location不能为空");
        Location condition = new Location();
        condition.setCode(code);
        Location location = locationService.selectFirstEntity(condition);
        if(location == null) {
            return AjaxResult.error("没有这个库位");
        }
        return AjaxResult.success("库位存在");
    }

    @PostMapping("/getLocationCode")
    @ApiOperation("移动端获得库位联想词")
    @Log(title = "移动端获得库位联想词", action = BusinessType.OTHER)
    public AjaxResult getLocationCode(@RequestBody @ApiParam(value="库位号") Map<String, String> param) {
        if  (param.get("code") == null || param.get("code").trim().length() < 1)
            throw new JSONException("查询码(code)不能为空");
        String type = param.get("type");
        if  (type == null || type.trim().length() < 1)
            throw new JSONException("type不能为空");
        return  inventoryService.getLocationForecast(param.get("code"), Integer.parseInt(type));
    }
}