TaskDetailController.java 4.7 KB
package com.huaheng.pc.task.taskDetail.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.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.page.PageDomain;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.framework.web.page.TableSupport;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.MobileTask;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
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 javax.sql.rowset.serial.SerialException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 立库任务明细 信息操作处理
 *
 * @author huaheng
 * @date 2018-08-19
 */
@Controller
@RequestMapping("/task/taskDetail")
public class TaskDetailController extends BaseController {
    private String prefix = "task/taskDetail";

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

    @RequiresPermissions("task:taskHeader:view")
    @GetMapping("/{taskId}")
    public String taskDetail(@PathVariable("taskId") String taskId, ModelMap mmap) {
        mmap.put("taskId", taskId);
        return prefix + "/taskDetail";
    }

    /**
     * 查询立库任务明细列表
     */
    @RequiresPermissions("task:taskHeader:list")
    @Log(title = "任务-任务管理1", operating = "查看立库任务明细1", action = BusinessType.GRANT)
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TaskDetail taskDetail) {
        LambdaQueryWrapper<TaskDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(TaskDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .in(TaskDetail::getCompanyCode, ShiroUtils.getCompanyCodeList())
                .eq(TaskDetail::getTaskId, taskDetail.getTaskId());
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        /**
         * 使用分页查询
         * 700盘点
         */
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            Page<TaskDetail> page = new Page<>(pageNum, pageSize);
            IPage<TaskDetail> iPage = taskDetailService.page(page, lambdaQueryWrapper);
            List<TaskDetail> iPages = iPage.getRecords();
            for (TaskDetail item : iPages) {
                if (item.getTaskType() == 700) {
                    iPages = taskDetailService.preferenceRealize(iPages);
                }
            }
            return getMpDataTable(iPages, iPage.getTotal());
        } else {
            List<TaskDetail> list = taskDetailService.list(lambdaQueryWrapper);
            for (TaskDetail items : list) {
                if (items.getTaskType() == 700) {
                    list = taskDetailService.preferenceRealize(list);
                }
            }
            return getDataTable(list);
        }
    }

    //@RequiresPermissions("task:taskHeader:report")
    @Log(title = "任务", operating = "打印任务明细报表", action = BusinessType.OTHER)
    @GetMapping("/report/{ids}")
    public String report(@PathVariable("ids") Integer[] ids, ModelMap mmap) {
        List<TaskDetail> taskDetailList = taskDetailService.findByTaskId(ids);
        mmap.put("task", taskDetailList);
        TaskHeader taskHeader = taskHeaderService.getById(taskDetailList.get(0).getTaskId());
        mmap.put("taskHeader",taskHeader);
        //总行数,总物料数
        int totalLines = 0;
        totalLines = taskDetailList.size();
        //总物料数
        BigDecimal t = taskDetailList.stream()
                .map(TaskDetail::getQty)
                .reduce(BigDecimal.ZERO,BigDecimal::add);
        int totalQty = t.intValue();
        mmap.put("totalLines",totalLines);
        mmap.put("totalQty",totalQty);
        return prefix + "/report";
    }
}