MobileTaskForASRSController.java 6.52 KB
package com.huaheng.mobile.shipment;

import com.huaheng.common.utils.security.ShiroUtils;
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.system.dict.domain.DictData;
import com.huaheng.pc.system.dict.service.IDictDataService;
import com.huaheng.pc.task.task.domain.Task;
import com.huaheng.pc.task.task.service.ITaskService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.domain.TaskWithDetailsModel;
import com.huaheng.pc.task.taskDetail.service.ITaskDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/mobile/task/taskForASRS")
@Api(tags = {"MobileTaskForASRSController"}, description = "手机立体库任务拣货相关")
public class MobileTaskForASRSController {

    @Resource
    private ITaskService taskService;
    @Resource
    private ITaskDetailService taskDetailService;
    @Resource
    IDictDataService  dictDataService;

    /**
     * 根据任务号或者托盘号,获取任务明细
     *
     * @return
     */
    @GetMapping("/taskAndDetails")
    @ApiOperation("移动端扫描容器号(托盘)或者任务号")
    @Log(title = "手机扫描容器收货上架", action = BusinessType.OTHER)
    public AjaxResult getAllTaskDetails(@Param("code") @ApiParam(value = "容器号或任务号") String code)  {
        //先检查是不是任务号
        int taskId;
        TaskWithDetailsModel taskWithDetailsModel = new TaskWithDetailsModel();
        try {
            taskId = Integer.parseInt(code);
        } catch (Throwable throwable) {
            taskId = -1;
        }
        if (taskId != -1) {
            //说明可以顺利转成int型,查找对应任务
            Task task = taskService.selectEntityById(taskId);
            if (task != null) {
                //就算是已完成的任务,也可以查看
//                if(task.getStatus()>=40){
//                    return RetResponse.makeErrRsp("任务已完成");
//                }
                if(task.getType() != 300 && task.getType() != 400) {
                    return AjaxResult.error("不是出库任务");
                }
                //获取明细
                TaskDetail condition = new TaskDetail();
                condition.setTaskId(task.getId());
                List<TaskDetail> taskDetails = taskDetailService.selectListEntityByEqual(condition);
                if (taskDetails == null || taskDetails.size() == 0) {
                    return AjaxResult.error("任务没有明细");
                }
                if (taskDetails.stream().anyMatch(x -> x.getStatus() < 40)) {
                    taskWithDetailsModel.setTask(task);
                    taskWithDetailsModel.setTaskDetails(taskDetails);
                } else {
                    return AjaxResult.error("任务已完成");
                }
            }
        }
        if (taskWithDetailsModel.getTask() == null) {
            //说明按照任务号并没有查找到,则再按照容器号来查找
            Task task = null;
            Task condition = new Task();
            condition.setContainerCode(code);
            condition.setWarehouseId(ShiroUtils.getWarehouseId());
            List<Task> tasks = taskService.selectListEntityByEqual(condition);
            if (tasks == null || tasks.size() == 0) {
                return AjaxResult.error("任务未找到");
            }
            for (Task item : tasks) {
                if (item.getStatus() > 20 && item.getStatus() < 40) {
                    task = item;
                    break;
                }
            }
            if (task != null) {
                //查找明细
                TaskDetail condition2 = new TaskDetail();
                condition2.setTaskId(task.getId());
                List<TaskDetail> taskDetails = taskDetailService.selectListEntityByEqual(condition2);
                if (taskDetails == null || taskDetails.size() == 0) {
                    return AjaxResult.error("任务没有明细");
                }
                if(task.getType() != 300 && task.getType() != 400) {
                    return AjaxResult.error("不是出库任务");
                }
                taskWithDetailsModel.setTask(task);
                taskWithDetailsModel.setTaskDetails(taskDetails);
            } else {
                task = tasks.stream().min((a, b) -> a.getCreated().compareTo(b.getCreated()) > 0 ? -1 : 1).get();
                //检查子任务是否都完成
                TaskDetail condition2 = new TaskDetail();
                condition2.setTaskId(task.getId());
                List<TaskDetail> taskDetails = taskDetailService.selectListEntityByEqual(condition2);
                if (taskDetails == null || taskDetails.size() == 0) {
                    return AjaxResult.error("任务没有明细");
                }
                if(task.getType() != 300 && task.getType() != 400) {
                    return AjaxResult.error("不是出库任务");
                }
                if (taskDetails.stream().anyMatch(x -> x.getStatus() < 40)) {
                    taskWithDetailsModel.setTask(task);
                    taskWithDetailsModel.setTaskDetails(taskDetails);
                } else {
                    return AjaxResult.error("任务已完成");
                }
            }
        }
        //添加config
        List<DictData> result = dictDataService.selectDictDataByType("taskStatus");
        if (result.size() < 1) {
            taskWithDetailsModel.setTaskStatusConfig(null);
        } else {
            taskWithDetailsModel.setTaskStatusConfig(result);
        }
        result = dictDataService.selectDictDataByType("taskDetailStatus");
        if (result.size() < 1) {
            taskWithDetailsModel.setTaskDetailStatusConfig(null);
        } else {
            taskWithDetailsModel.setTaskDetailStatusConfig(result);
        }
        return AjaxResult.success(taskWithDetailsModel);
    }

    @PostMapping("/completeTaskDetails")
    @ApiOperation("完成立体库子任务")
    @Log(title = "完成立体库子任务", action = BusinessType.OTHER)
    public AjaxResult completeTaskDetails(@RequestBody int[] taskDetailIds) {
        return taskService.completeTaskDetailsForMobile(taskDetailIds);
    }

}