ReceiptContainerHeaderController.java 12.2 KB
package com.huaheng.pc.receipt.receiptContainerHeader.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaheng.common.utils.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.common.constant.HttpConstant;
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.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.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.PositionBean;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.receipt.receiving.service.ReceivingService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.ReceiptTaskService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 入库组盘头表控制
 * @author mahuaheng
 */
@Controller
@RequestMapping("/receipt/receiptContainerHeader")
public class ReceiptContainerHeaderController extends BaseController {

    @Resource
    private ReceiptContainerHeaderService receiptContainerHeaderService;
    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private ReceivingService receivingService;
    @Resource
    private ReceiptContainerDetailService receiptContainerDetailService;
    @Resource
    private ReceiptTaskService receiptTaskService;

    private String prefix = "receipt/receiptContainerHeader";

    @RequiresPermissions("receipt:receiptContainer:view")
    @GetMapping()
    public String containerCapacity()
    {
        return prefix + "/receiptContainerHeader";
    }

    /**
     * 查询入库组盘
     */
    @RequiresPermissions("receipt:receiptContainer:list")
    @Log(title = "入库-入库单组盘", operating = "查看入库组盘列表", action = BusinessType.GRANT)
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@ApiParam(name="receiptDetail",value="入库组盘头表") ReceiptContainerHeader receiptContainerHeader,
                              @ApiParam(name = "receiptCode",value = "入库单号")String receiptCode,
                              @ApiParam(name = "createdBegin", value = "起止时间") String createdBegin,
                              @ApiParam(name = "createdEnd", value = "结束时间") String createdEnd) {
        LambdaQueryWrapper<ReceiptContainerHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        String sql = null;
        if (StringUtils.isNotEmpty(receiptCode)) {
            sql = "select receiptContainerId from receipt_container_detail where receiptCode = \'"+receiptCode+"\'";
        }
        lambdaQueryWrapper.ge(StringUtils.isNotEmpty(createdBegin), ReceiptContainerHeader::getCreated, createdBegin)
                .le(StringUtils.isNotEmpty(createdEnd), ReceiptContainerHeader::getCreated, createdEnd)
                .eq(ReceiptContainerHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .eq(StringUtils.isNotEmpty(receiptContainerHeader.getContainerCode()),ReceiptContainerHeader::getContainerCode, receiptContainerHeader.getContainerCode())
                .eq(StringUtils.isNotEmpty(receiptContainerHeader.getToLocation()),ReceiptContainerHeader::getToLocation, receiptContainerHeader.getToLocation())
                .eq(StringUtils.isNotNull(receiptContainerHeader.getTaskType()),ReceiptContainerHeader::getTaskType, receiptContainerHeader.getTaskType())
                .eq(StringUtils.isNotNull(receiptContainerHeader.getStatus()),ReceiptContainerHeader::getStatus, receiptContainerHeader.getStatus())
                .eq(StringUtils.isNotEmpty(receiptContainerHeader.getCreatedBy()),ReceiptContainerHeader::getCreatedBy, receiptContainerHeader.getCreatedBy())
                .inSql(StringUtils.isNotEmpty(receiptCode), ReceiptContainerHeader::getId, sql)
                .orderByAsc(ReceiptContainerHeader::getStatus)
                .orderByDesc(ReceiptContainerHeader::getId);

        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)){
            Page<ReceiptContainerHeader> page = new Page<>(pageNum, pageSize);
            IPage<ReceiptContainerHeader> iPage = receiptContainerHeaderService.page(page, lambdaQueryWrapper);
            return getMpDataTable(iPage.getRecords(),iPage.getTotal());
        } else {
            List<ReceiptContainerHeader> list = receiptContainerHeaderService.list(lambdaQueryWrapper);
            return getDataTable(list);
        }
    }

    /**
     * 删除入库组盘
     */
    @ApiOperation(value="取消", notes="取消入库组盘", httpMethod = "POST")
    @RequiresPermissions("receipt:receiptContainer:remove")
    @Log(title = "入库-入库单 ",operating = "取消入库组盘", action = BusinessType.UPDATE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(@ApiParam(name = "id", value = "入库头表id字符串")String ids){
        if (StringUtils.isNull(ids)){
            return AjaxResult.error("id为空");
        }
        List<Integer> idList = Arrays.asList(Convert.toIntArray(ids));
        return toAjax(receiptContainerHeaderService.cancelByIds(idList));
    }

    /**
     * 选择出库口
     */
    @GetMapping("/chooseStation/{ids}")
    public String chooseStation(@PathVariable("ids")String ids, ModelMap mmap) {
        List<Integer> idList = Arrays.asList(Convert.toIntArray(ids));
        List<Integer> idsList = idList.stream().distinct().collect(Collectors.toList());
        ReceiptContainerHeader receiptContainerHeader = receiptContainerHeaderService.getById(idsList.get(0));
        String containerCode = receiptContainerHeader.getContainerCode();
        mmap.put("containerCode", containerCode);
        mmap.put("id", ids);
        int taskType = receiptContainerHeader.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 (String ids, String type, String containerCode, String port){
        List<Integer> idList = Arrays.asList(Convert.toIntArray(ids));
        List<Integer> idsList = idList.stream().distinct().collect(Collectors.toList());
        for(Integer id : idsList) {
            LambdaQueryWrapper<ReceiptContainerHeader> receiptContainerHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
            receiptContainerHeaderLambdaQueryWrapper.eq(ReceiptContainerHeader::getId, id);
            ReceiptContainerHeader receiptContainerHeader1 = receiptContainerHeaderService.getOne(receiptContainerHeaderLambdaQueryWrapper);
            receiptContainerHeader1.setPort(port);
            receiptContainerHeaderService.update(receiptContainerHeader1, receiptContainerHeaderLambdaQueryWrapper);
        }
        return addTask(ids);
    }

    /**
     * 生成任务
     */
    @RequiresPermissions("receipt:receiptContainer:createTask")
    @Log(title = "入库-任务生成", operating = "生成入库任务", action = BusinessType.INSERT)
    @PostMapping( "/createTask")
    @ResponseBody
    public AjaxResult addTask(String ids) {
        if (StringUtils.isEmpty(ids)){
            return AjaxResult.error("id不能为空");
        }
        List<Integer> idList = Arrays.asList(Convert.toIntArray(ids));
        List<Integer> idsList = idList.stream().distinct().collect(Collectors.toList());
        AjaxResult ajaxResult1 = handleMultiProcess(new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult =receiptTaskService.createReceiptTask(idsList);
                return ajaxResult;
            }
        });
        return ajaxResult1;
    }

    /**
     * 定位
     */
    @RequiresPermissions("receipt:receiptContainer:position")
    @Log(title = "入库-定位", operating = "定位", action = BusinessType.INSERT)
    @PostMapping( "/position")
    @ResponseBody
    public AjaxResult position(PositionBean positionBean){
        if (StringUtils.isEmpty(positionBean.getIds())){
            return AjaxResult.error("id不能为空");
        }
        boolean result = false;
        List<Integer> idList = Arrays.asList(Convert.toIntArray(positionBean.getIds()));
        List<Integer> idsList = idList.stream().distinct().collect(Collectors.toList());
        for (int i = 0; i<idsList.size(); i++) {
            LambdaQueryWrapper<ReceiptContainerDetail> lambda = Wrappers.lambdaQuery();
            lambda.eq(ReceiptContainerDetail::getReceiptContainerId, idsList.get(i));
            List<ReceiptContainerDetail> receiptContainerDetails = receiptContainerDetailService.list(lambda);
            for (ReceiptContainerDetail receiptContainerDetail : receiptContainerDetails) {
                result =  receivingService.position(receiptContainerDetail, positionBean.getArea());
            }
        }
        if(!result) {
            return AjaxResult.error("定位失败");
        }
        return AjaxResult.success("定位成功");
    }

    /**
     * 取消定位
     */
    @RequiresPermissions("receipt:receiptContainer:canalPosition")
    @Log(title = "入库-取消定位", operating = "取消定位", action = BusinessType.OTHER)
    @PostMapping( "/cancelPosition")
    @ResponseBody
    public AjaxResult cancelPosition(String ids){
        if (StringUtils.isEmpty(ids)){
            return AjaxResult.error("id不能为空");
        }
        List<Integer> idList = Arrays.asList(Convert.toIntArray(ids));
        for (int i = 0; i<idList.size(); i++){
            LambdaQueryWrapper<ReceiptContainerDetail> lambda = Wrappers.lambdaQuery();
            lambda.eq(ReceiptContainerDetail::getReceiptContainerId, idList.get(i));
            List<ReceiptContainerDetail> receiptContainerDetails = receiptContainerDetailService.list(lambda);
            for (ReceiptContainerDetail receiptContainerDetail : receiptContainerDetails) {
                receivingService.cancelPosition(receiptContainerDetail);
            }
        }
        return AjaxResult.success("取消定位成功");
    }

    /**
     * 定位
     */
    @GetMapping("/positioning/{ids}")
    public String positioning(@PathVariable("ids")String ids, ModelMap mmap){
        mmap.put("ids", ids);
        return "receipt/receiving" + "/positioning";
    }
}