MobilePutawayController.java 9.86 KB
package com.huaheng.mobile.receipt;

import com.alibaba.fastjson.JSONException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
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.page.PageDomain;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.framework.web.page.TableSupport;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

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

/**
 *
 * @author Enzo Cotter
 * @date 2019/12/16
 */
@RestController
@RequestMapping("/mobile/putaway/execute")
@Api(tags = {"手机收货上架"}, value = "手机收货上架MobilePutawayController")
public class MobilePutawayController extends BaseController {

    @Resource
    private TaskHeaderService taskService;
    @Resource
    private LocationService locationService;

    @Resource
    private TaskDetailService taskDetailService;

    @Resource
    private MaterialService materialService;

    @PostMapping("/createReceiptTask")
    @ApiOperation("手机扫描容器收货上架")
    @Log(title = "手机扫描容器收货上架", action = BusinessType.OTHER)
    public AjaxResult createReceiptTask(@RequestBody @ApiParam(value="容器号") Map<String, String> param) throws Exception {
        if  (param.get("containerCode") == null || param.get("containerCode").trim().length() < 1) {
            throw new JSONException("容器号(containerCode)不能为空");
        }
        AjaxResult retResult = taskService.mobileCreateReceiptTask(param.get("containerCode"), "L10-27-01");
        return retResult;
    }

    @PostMapping("/getLocationFromContainer")
    @ApiOperation("手机扫描容器获得库位号")
    @Log(title = "手机扫描容器获得库位号", action = BusinessType.OTHER)
    public AjaxResult getLocationFromContainer(@RequestBody @ApiParam(value="容器号") Map<String, String> param) throws Exception {
        if  (param.get("containerCode") == null || param.get("containerCode").trim().length() < 1) {
            throw new JSONException("容器号(containerCode)不能为空");
        }
        LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(Location::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .eq(Location::getDeleted, false)
                .eq(Location::getContainerCode, param.get("containerCode"));
        Location location = locationService.getOne(queryWrapper);
        if(location == null) {
            return AjaxResult.error("没有该库位");
        }
        return AjaxResult.success("获取成功",location.getCode());
    }

    @PostMapping("/createQuickTask")
    @ApiOperation("手机扫描容器收货上架")
    @Log(title = "手机扫描容器收货上架", action = BusinessType.OTHER)
    public AjaxResult createQuickTask(@RequestBody @ApiParam(value="容器号") Map<String, String> param) throws Exception {
        if  (param.get("containerCode") == null || param.get("containerCode").trim().length() < 1) {
            throw new JSONException("容器号(containerCode)不能为空");
        }

        AjaxResult retResult = taskService.createQuickTask(param.get("containerCode"));
        return retResult;
    }

    @PostMapping("/scanLocationCode")
    @ApiOperation("手机扫描库位收货上架")
    @Log(title = "手机扫描库位收货上架", action = BusinessType.OTHER)
    public AjaxResult scanLocationCode(@RequestBody @ApiParam(value="库位编码") Map<String, String> param) throws Exception {
        if  (param.get("locationCode") == null || param.get("locationCode").trim().length() < 1) {
            throw new JSONException("库位号(locationCode)不能为空");
        }
        AjaxResult retResult = taskService.completeTask(param.get("locationCode"));
        return retResult;
    }

    @PostMapping("/createReplenishTask")
    @ApiOperation("手机扫描容器创建补充入库任务")
    @Log(title = "手机扫描容器创建补充入库任务", action = BusinessType.OTHER)
    public AjaxResult createReplenishTask(@RequestBody @ApiParam(value="容器号") Map<String, String> param) throws Exception {
        if  (param.get("containerCode") == null || param.get("containerCode").trim().length() < 1) {
            throw new JSONException("容器号(containerCode)不能为空");
        }
        AjaxResult retResult = taskService.createReplenishTask(param.get("containerCode"), 1);
        return retResult;
    }
    /**
     * PDA根据物料快速查找托盘
     *
     */
    @ApiOperation(value="PDA归还查询", notes="归还查询 ", httpMethod = "POST")
    @Log(title = "查找物料历史托盘 ",operating = "PDA快速查找托盘 ", action = BusinessType.INSERT)
    @PostMapping("/pdaSelect")
    @ApiLogger(from = "PDA", apiName = "PDA快速查找托盘")
    public AjaxResult pdaSelect(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) {
        if  (param.get("materialCode") == null || param.get("materialCode").trim().length() < 1) {
            throw new JSONException("物料编码(materialCode)不能为空");
        }
        LambdaQueryWrapper<TaskDetail> lambda = new LambdaQueryWrapper<>();
        lambda.eq(TaskDetail::getMaterialCode, param.get("materialCode"));
//                .last("order by id desc limit 1");
        List<TaskDetail> taskDetail = taskDetailService.list(lambda);
        if (taskDetail == null){
            return AjaxResult.error("没有该物料容器");
        }
        List<Location> location =null;
        for (TaskDetail detail : taskDetail) {
            String containerCode = detail.getContainerCode();
            LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();
            queryWrapper.eq(Location::getContainerCode, containerCode);
            location = locationService.list(queryWrapper);
        }
//        String containerCode = taskDetail.getContainerCode();
//        LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();
//        queryWrapper.eq(Location::getContainerCode, containerCode);
//        List<Location> location = locationService.list(queryWrapper);

        return  AjaxResult.success(location);
    }
    /**
     * 查询物料列表
     */
    @ApiOperation(value = "查看物料列表",
            notes = "根据物料编码、名称、规格、物料类别、创建时间获取物料的详细信息",
            httpMethod = "POST")
    @Log(title = "通用-物料管理", operating = "查看物料列表", action = BusinessType.GRANT)
    @PostMapping("/listMaterial")
    public TableDataInfo list (
            @ApiParam(name = "location", value = "物料编码、名称、规格、物料类别") Material material,
            @ApiParam(name = "createdBegin", value = "起止时间") String createdBegin,
            @ApiParam(name = "createdEnd", value = "结束时间") String createdEnd) {

        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        LambdaQueryWrapper<Material> lambda = Wrappers.lambdaQuery();
        lambda.gt(StringUtils.isNotEmpty(createdBegin), Material::getCreated, createdBegin)
                .lt(StringUtils.isNotEmpty(createdEnd), Material::getCreated, createdEnd)
                .eq(StringUtils.isNotNull(material.getCode()) && StringUtils.isNotEmpty(material.getCode()), Material::getCode, material.getCode())
                .like(StringUtils.isNotNull(material.getName()) && StringUtils.isNotEmpty(material.getName()), Material::getName, material.getName())
//              .like(StringUtils.isNotNull(material.getEscrowNum()) && StringUtils.isNotEmpty(material.getEscrowNum()), Material::getEscrowNum, material.getEscrowNum())//代管号
//              .like(StringUtils.isNotNull(material.getFigureNum()) && StringUtils.isNotEmpty(material.getFigureNum()), Material::getFigureNum, material.getFigureNum())//图号
                .eq(StringUtils.isNotEmpty(material.getType()), Material::getType, material.getType())
                .like(StringUtils.isNotNull(material.getSpec()) && StringUtils.isNotEmpty(material.getSpec()), Material::getSpec, material.getSpec())
                .eq(Material::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .eq(Material::getDeleted, false);

        if(StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            /*使用分页查询*/
            Page<Material> page = new Page<>(pageNum, pageSize);
            IPage<Material> iPage = materialService.page(page, lambda);
            return getMpDataTable(iPage.getRecords(), iPage.getTotal());
        } else {
            List<Material> list = materialService.list(lambda);
            return getDataTable(list);
        }
    }
}