TaskHeaderController.java 16.1 KB
package com.huaheng.pc.task.taskHeader.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaheng.api.acs.service.AcsService;
import com.huaheng.common.utils.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.api.wcs.service.taskCancel.TaskCancelService;
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.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.framework.web.service.ConfigService;
import com.huaheng.pc.config.configValue.domain.ConfigValue;
import com.huaheng.pc.config.configValue.service.ConfigValueService;
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.material.service.MaterialService;
import com.huaheng.pc.config.warehouse.domain.Warehouse;
import com.huaheng.pc.inventory.cycleCountDetail.domain.CycleCountDetail;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
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.mapper.TaskHeaderMapper;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import com.huaheng.pc.task.taskHeader.service.WorkTaskService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.session.Session;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


@Controller
@RequestMapping("/task/taskHeader")


public class TaskHeaderController extends BaseController {


    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private WorkTaskService workTaskService;
    @Resource
    private TaskCancelService taskCancelService;
    @Resource
    private ConfigService configService;
    @Resource
    private ContainerService containerService;
    @Resource
    private ContainerTypeService containerTypeService;
    @Resource
    private AcsService acsService;


    private String prefix = "task/taskHeader";

    @RequiresPermissions("task:taskHeader:view")
    @GetMapping()
    public String taskHeader(HttpServletRequest request, ModelMap mmap) {
        String InternalTaskType= request.getParameter("InternalTaskType");
        mmap.put("InternalTaskType",InternalTaskType);
        return prefix + "/taskHeader";
    }

    @RequiresPermissions("task:taskHeader:view")
    @GetMapping("taskHeaderV")
    public String taskHeaderV( ModelMap mmap) {
        return prefix + "/taskHeaderV";
    }

    /**
     * 查询任务列表
     */
    @RequiresPermissions("task:taskHeader:list")
    @Log(title = "任务-上架任务", operating = "查看任务列表", action = BusinessType.GRANT)
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TaskHeader taskHeader,@ApiParam(name="internalTaskType",value="类型") Integer internalTaskType,
                              @ApiParam(name="createdBegin",value="类型") String createdBegin,@ApiParam(name="createdEnd",value="类型") String createdEnd) {
        if(internalTaskType!=null&&internalTaskType==0){
            internalTaskType=null;
        }
        LambdaQueryWrapper<TaskHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(TaskHeader::getWarehouseCode,ShiroUtils.getWarehouseCode())
                .eq(StringUtils.isNotNull(internalTaskType),TaskHeader::getInternalTaskType,internalTaskType)
                .eq(StringUtils.isNotNull(taskHeader.getId()),TaskHeader::getId,taskHeader.getId())
                .eq(StringUtils.isNotEmpty(taskHeader.getContainerCode()),TaskHeader::getContainerCode,taskHeader.getContainerCode())
                .eq(StringUtils.isNotEmpty(taskHeader.getToLocation()),TaskHeader::getToLocation,taskHeader.getToLocation())
                .eq(StringUtils.isNotEmpty(taskHeader.getFromLocation()),TaskHeader::getFromLocation,taskHeader.getFromLocation())
                .eq(StringUtils.isNotEmpty(taskHeader.getZoneCode()),TaskHeader::getZoneCode,taskHeader.getZoneCode())
                .eq(StringUtils.isNotNull(taskHeader.getPriority()),TaskHeader::getPriority,taskHeader.getPriority())
                .gt(StringUtils.isNotEmpty(createdBegin),TaskHeader::getCreated,createdBegin)
                .lt(StringUtils.isNotEmpty(createdEnd),TaskHeader::getCreated,createdEnd)
                .eq(StringUtils.isNotNull(taskHeader.getIsReturn()),TaskHeader::getIsReturn,taskHeader.getIsReturn())
//                .lt(TaskHeader::getStatus,QuantityConstant.TASK_STATUS_COMPLETED)
                .orderByAsc(TaskHeader::getStatus)
                .orderByDesc(TaskHeader::getId);

        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        /**
         * 使用分页查询
         */
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)){
            Page<TaskHeader> page = new Page<>(pageNum, pageSize);
            IPage<TaskHeader> iPage = taskHeaderService.page(page, lambdaQueryWrapper);
            List<TaskHeader> iPages = iPage.getRecords();
            return getMpDataTable(iPages, iPage.getTotal());
        } else {
            List<TaskHeader> list = taskHeaderService.list(lambdaQueryWrapper);
            return getDataTable(list);
        }
    }

    /**
     * 下发任务
     */
    @RequiresPermissions("task:taskHeader:execute")
    @Log(title = "任务-任务管理", operating = "下发立库任务", action = BusinessType.UPDATE)
    @PostMapping( "/execute")
    @ResponseBody
    public AjaxResult execute(String taskId)
    {
        if (StringUtils.isEmpty(taskId)){
            return AjaxResult.error("taskId不能为空");
        }
        AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult =null;
                try{
                    ajaxResult = taskHeaderService.sendTaskToWcs(Convert.toIntArray(taskId));
                }catch (Exception e){
                    ajaxResult=AjaxResult.error(e.getMessage());
                }
                return ajaxResult;
            }
        });
        return ajaxResult;
    }
    /**
     * 修改最大优先级
     */
    @ApiOperation(value = "最大优先级", notes = "最大优先级", httpMethod = "POST")
    @PostMapping("/prioritymax")
    @ResponseBody
    public AjaxResult editBatchSave (String ids) {
        return toAjax(taskHeaderService.prioritymax(ids));
    }
    /**
     * 修改最小优先级
     */
    @ApiOperation(value = "最小优先级", notes = "最小优先级", httpMethod = "POST")
    @PostMapping("/prioritymin")
    @ResponseBody
    public AjaxResult prioritymin (String ids) {
        return  toAjax( taskHeaderService.prioritymin(ids));
    }


//    @ApiOperation(value = "最大优先级", notes = "最大优先级", httpMethod = "POST")
//    @PostMapping("/priorityedit")
//    @ResponseBody
//    public AjaxResult editBatchSave (String ids) {
//        System.out.println(taskHeaderService.editBatchSave(ids));
//        return toAjax(1);
//    }
//
//    @ApiOperation(value = "最小优先级", notes = "最小优先级", httpMethod = "POST")
//    @PostMapping("/upmin")
//    @ResponseBody
//    public AjaxResult upmin (String ids) {
//        System.out.println(taskHeaderService.editmin(ids));
//        return toAjax(1);
//    }
//
//    @ApiOperation(value = "单个优先级", notes = "单个优先级", httpMethod = "POST")
//    @PostMapping("/updateid")
//    @ResponseBody
//    public AjaxResult editBatchSave (String id, String priority) {
//        System.out.println("-------------------------------------------"+id);
//        System.out.println("-------------------------------------------"+priority);
//        System.out.println(taskHeaderService.editID(id,priority));
//        return toAjax(1);
//    }


    /**
     * 完成任务
     */
    @RequiresPermissions("task:taskHeader:complete")
    @Log(title = "任务-任务管理", operating = "PC完成立库任务", action = BusinessType.UPDATE)
    @PostMapping( "/completeTaskByWMS")
    @ResponseBody
    @ApiLogger(apiName = "wcs任务完成", from="PC")
    public AjaxResult completeTaskByWMS(String taskId){
        if (StringUtils.isEmpty(taskId)){
            return AjaxResult.error("taskId不能为空");
        }
        return taskHeaderService.completeTaskByWMS(Convert.toIntArray(taskId), null);
    }

    /**
     * 删除立库任务
     */
    @RequiresPermissions("task:taskHeader:remove")
    @Log(title = "任务-任务管理", operating = "删除立库任务", action = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        if (StringUtils.isEmpty(ids)) {
            return AjaxResult.error("taskId不能为空");
        }
        Integer[] idList = Convert.toIntArray(ids);
        for (int id : idList) {
            TaskHeader taskHeader = taskHeaderService.getById(id);
            if(taskHeader.getStatus().intValue()  <= QuantityConstant.TASK_STATUS_BUILD) {
                continue;
            }
            String containerCode = taskHeader.getContainerCode();
            if (StringUtils.isEmpty(containerCode)) {
                return AjaxResult.error("空托盘");
            }
            Container container = containerService.getContainerByCode(
                        containerCode, taskHeader.getWarehouseCode());
           /* LambdaQueryWrapper<ContainerType> containerTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
            containerTypeLambdaQueryWrapper.eq(ContainerType::getCode, container.getContainerType());
            ContainerType containerType = containerTypeService.getContainerTypeByCode(
                                    container.getContainerType(), container.getWarehouseCode());*/
            AjaxResult ajaxResult =null;
            switch (taskHeader.getWarehouseCode()){
                case "CS0001":
                    ajaxResult = taskCancelService.cancelTask(String.valueOf(id),
                            taskHeader.getWarehouseCode(), container.getNumber());
                    if (ajaxResult.hasErr()) {
                        return ajaxResult;
                    }
                    break;
                case "KS0001":
                    if(taskHeader.getZoneCode().equals("LK") || taskHeader.getZoneCode().equals("XC")){
                        ajaxResult = taskCancelService.cancelTask(String.valueOf(id),
                                taskHeader.getWarehouseCode(), container.getNumber());
                    }
                    if(taskHeader.getZoneCode().equals("AGV")){
                        ajaxResult = acsService.taskCancel("取消");
                    }
                    if(ajaxResult.hasErr()){
                        return ajaxResult;
                    }
                    break;
            }

        }


        return taskHeaderService.cancelTask(Convert.toIntArray(ids));
    }

    /**
     * 自动分配任务库位
     * WCS
     * @param taskId
     * @param high
     * @return
     */
    @PostMapping("/setLocationCode")
    @ResponseBody
    public AjaxResult setLocationCode( Integer taskId, Integer high){
        if (taskId == null){
            return AjaxResult.error("任务id不能为空");
        }
        if (high == null){
            return AjaxResult.error("高库位标识不能为空");
        }
        return taskHeaderService.setLocationCode(taskId, high);
    }

    @Log(title = "库位监控-出库查看", operating = "出库查看", action = BusinessType.GRANT)
    @PostMapping("/checkLocationCode")
    @ResponseBody
    public AjaxResult checkLocationCode (String locationCode) {
        if (StringUtils.isEmpty(locationCode)) {
            return AjaxResult.error("库位不能为空!");
        }
        List<String> list = new ArrayList<>();
        list.add(locationCode);
        return workTaskService.createCheckOutTask(list, null);
    }

    /**
     * 分配站台
     */
    @GetMapping("/chooseStation/{taskId}")
    public String chooseStation(@PathVariable("taskId")String taskId, ModelMap mmap) {
        TaskHeader taskHeader = taskHeaderService.getById(taskId);
        String containerCode = taskHeader.getContainerCode();
        mmap.put("containerCode", containerCode);
        mmap.put("id", taskId);
        int taskType = taskHeader.getTaskType().intValue();
        if(taskType == QuantityConstant.TASK_TYPE_WHOLESHIPMENT ||
                taskType == QuantityConstant.TASK_TYPE_EMPTYSHIPMENT)  {
            mmap.put("type", QuantityConstant.STATION_OUT);
        } else if(taskType == QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT ||
                taskType == QuantityConstant.TASK_TYPE_SORTINGSHIPMENT ||
                taskType == QuantityConstant.TASK_TYPE_VIEW ||
                taskType == QuantityConstant.TASK_TYPE_CYCLECOUNT) {
            mmap.put("type", QuantityConstant.STATION_PICK);
        } else {
            throw new ServiceException("任务类型不需要选站台");
        }
        return prefix + "/chooseStation";
    }

    @Log(title = "分配站台", operating = "分配站台", action = BusinessType.GRANT)
    @PostMapping("/setStation")
    @ResponseBody
    public AjaxResult setStation (TaskHeader taskHeader){
        Integer taskiId = taskHeader.getId();
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getId, taskiId);
        TaskHeader taskHeader1 = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
        taskHeader1.setPort(taskHeader.getPort());
        taskHeaderService.update(taskHeader1, taskHeaderLambdaQueryWrapper);
        AjaxResult execute = execute(String.valueOf(taskiId));
        if(execute.hasErr()){
            taskHeader1.setPort("");
            taskHeaderService.updateById(taskHeader1);
        }
        return execute;
    }

    @Log(title = "手动回传", operating = "手动回传", action = BusinessType.GRANT)
    @PostMapping("/handleBack")
    @ResponseBody
    public AjaxResult handleBack (Integer taskId){
        taskHeaderService.handleBack(taskId);
        return AjaxResult.success();
    }

    @RequiresPermissions("task:task:deliveryReport")
    @Log(title = "任务-任务管理", operating = "打印明细报表", action = BusinessType.OTHER)
    @GetMapping("/deliveryReport/{ids}")
    public String deliveryReport(@PathVariable("ids") Integer[] ids, ModelMap mmap)
    {
        ModelMap modelMap = taskHeaderService.deliveryReport(ids, mmap);
        return prefix + "/deliveryReport";
    }

}