LkTaskMenuControlletr.java 6.42 KB
package com.huaheng.pc.task.LkMenuTask;


import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
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.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;

import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@Controller
@RequestMapping("/task/lkMenuTask")
public class LkTaskMenuControlletr extends BaseController {

    @Resource
    private TaskDetailService taskDetailService;
    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private ContainerService containerService;

    private String prefix = "task/lkMenuTask";



    @RequiresPermissions("task:lkMenuTask:view")
    @GetMapping()
    public String locationStatus()
    {
        return prefix + "/lkMenu";
    }


    /**
     * 更换容器
     */
    @GetMapping("/replaceContainer/{code}/{ids}")
    public String replaceContainer(@PathVariable("code") String code, @PathVariable("ids") String ids, ModelMap map){
        if (StringUtils.isEmpty(code) && StringUtils.isEmpty(ids)){
            throw new ServiceException("没有任务明细行");
        }
        Container container = containerService.getContainerByCode(code);
        map.put("container", container);
        map.put("ids", ids);
        return prefix+"/containerSelection";
    }


    @PostMapping("/getContainerList")
    @ResponseBody
    public TableDataInfo getContainerList(String code) {
        if (StringUtils.isEmpty(code)){
            return null;
        }
        Container container = containerService.getContainerByCode(code);
        Container query = new Container();
        // 状态为空
        query.setStatus("empty");
        // 仓库编码一致
        query.setWarehouseCode(container.getWarehouseCode());
        // 货主编码一致
        query.setCompanyCode(container.getCompanyCode());
        // u8仓库保持一致
        query.setUWarehouseCode(container.getUWarehouseCode());
        // 大小保持一致
        query.setContainerType(container.getContainerType());
        // 状态一致
        query.setEnable(container.getEnable());
        // 删除状态一致
//        query.setDeleted(container.getDeleted());
        List<Container> list = containerService.selectEmptyList(query);
        if (list.size() > 1){
            list.removeIf(item -> code.contains(item.getCode()));
        }
        return getDataTable(list);
    }


    /**
     * 获取当前托盘要完成的任务
     *      *
     */
    @ResponseBody
    @PostMapping("/getLkTasks")
    @RequiresPermissions("task:lkMenuTask:list")
    @Log(title = "LK任务-任务管理", operating ="任务显示", action = BusinessType.OTHER)
    public List<TaskDetail> getLkTasks(String containerCode){
        TaskDetail taskDetail =new TaskDetail();
        taskDetail.setContainerCode(containerCode);
        taskDetail.setWarehouseCode(ShiroUtils.getWarehouseCode());
        taskDetail.setStatus(1);
        taskDetail.setNumber(1);
        Container container = new Container();
        container.setCode(containerCode);
        container = containerService.selectFirstEntity(container);
        if(container == null){
            return null;
        }
        /*if(container.getContainerType().equals(QuantityConstant.CONTAINER_TYPEC)){
            taskDetail.setZoneCode(QuantityConstant.ZONECODE_XC);
        }else {
            taskDetail.setZoneCode(QuantityConstant.ZONECODE_LK);
        }*/
        List<TaskDetail> taskDetails =taskDetailService.selectListEntityUndone(taskDetail);
        if(taskDetails!=null){
            for(TaskDetail item :taskDetails) {
                taskDetailService.updateByInventory(item);
            }
        }
        return taskDetails;
    }


    /**
     * LK任务界面中完成任务
     */
    @RequiresPermissions("task:lkMenuTask:list")
    @Log(title = "LK任务-任务管理", operating = "PC完成LK任务", action = BusinessType.UPDATE)
    @PostMapping( "/completeTaskByLK")
    @ResponseBody
    public AjaxResult completeTaskByLK(Integer id, String num){
        if(id==null){
            return AjaxResult.error("没有任务");
        }
        TaskDetail taskDetail =taskDetailService.getById(id);
        taskDetail.setNumber(2);
        if(num==null){
            taskDetailService.updateById(taskDetail);
        }else {
            BigDecimal number=new BigDecimal(num);
            if(number.compareTo(taskDetail.getQty())>0){
                return AjaxResult.error("完成数量大于任务数量");
            }else  if(number.compareTo(taskDetail.getQty())==0){
                taskDetailService.updateById(taskDetail);
            }else {
//                taskDetailService.updateTask(taskDetail,number);
                taskDetailService.updateById(taskDetail);
            }
        }
        return AjaxResult.success("成功");
    }

    /**
     * 更换容器提交
     */
    @Log(title = "更换容器提交", operating = "更换容器提交", action = BusinessType.UPDATE)
    @PostMapping( "/submitComplete")
    @ResponseBody
    public AjaxResult submitComplete(String ids, String code){
        return taskDetailService.updateTaskDetail(ids, code);
    }


    /**
     * 补充入库
     */
    @GetMapping("/replenIn")
    public String replenIn(){
        return prefix+"/replenIn";
    }

    /**
     * 补充入库
     */
    @RequiresPermissions("task:lkMenuTask:list")
    @Log(title = "LK任务-任务管理", operating = "PC补充入库", action = BusinessType.UPDATE)
    @PostMapping( "/replenIn")
    @ResponseBody
    public AjaxResult replenIn(String containerCode){
        return taskHeaderService.replenIn(containerCode);
    }


}