TvController.java 7.41 KB
package com.huaheng.api.tv.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.huaheng.api.tv.domain.*;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.InventoryMaterialSummary.domain.InventoryMaterialSummary;
import com.huaheng.pc.inventory.InventoryMaterialSummary.service.InventoryMaterialSummaryService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
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.service.TaskHeaderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/tv")
public class TvController extends BaseController {

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

    @GetMapping("/taskOfstation")
    @ApiOperation("获取电视信息")
    public AjaxResult taskOfStation() {

        // 获取状态为到达拣选台状态的分拣任务
        LambdaQueryWrapper<TaskHeader> taskHeaderQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderQueryWrapper
                .eq(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT)
                .eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_ARRIVED_STATION);
        List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderQueryWrapper);

        List<TaskOfStationVo> taskOfStationVoList = new ArrayList<>();
        taskHeaderList.forEach(taskHeader -> {
            TaskOfStationVo taskOfStationVo = new TaskOfStationVo();
            taskOfStationVo.setTaskHeader(taskHeader);

            LambdaQueryWrapper<TaskDetail> taskDetailQueryWrapper = Wrappers.lambdaQuery();
            taskDetailQueryWrapper
                    .eq(TaskDetail::getTaskId, taskHeader.getId());
            List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailQueryWrapper);
            taskOfStationVo.setTaskDetailList(taskDetailList);

            taskOfStationVoList.add(taskOfStationVo);
        });
        return AjaxResult.success(taskOfStationVoList);
    }

    /*@GetMapping("/getTvView")
    @ApiOperation("获取电视信息")
    public AjaxResult getTvView(@RequestParam(name = "station") String station) {
        LambdaQueryWrapper<TaskHeader> headerLambdaQuery = Wrappers.lambdaQuery();
        LambdaQueryWrapper<TaskDetail> detailLambdaQuery = Wrappers.lambdaQuery();
        //查询入库任务,状态不为为完成(<100)的站台
        ArrayList<Integer> taskType = new ArrayList<>();
        taskType.add(QuantityConstant.TASK_TYPE_WHOLERECEIPT);//整盘入库---100
        taskType.add(QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT);
        taskType.add(QuantityConstant.TASK_TYPE_EMPTYRECEIPT);//空托盘入库---500
        taskType.add(QuantityConstant.TASK_TYPE_MANY_EMPTYRECEIPT);//空托盘组入库---1100
        taskType.add(QuantityConstant.TASK_TYPE_WHOLESHIPMENT);//整盘出库---300
        taskType.add(QuantityConstant.TASK_TYPE_MANY_EMPTYSHIPMENT);//空托盘组出库库---1200
        taskType.add(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT);//分拣出库---400
        headerLambdaQuery.in(TaskHeader::getTaskType,taskType);
        headerLambdaQuery.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);//小于任务完成状态的
        if(station==null || "P1001".equals(station)){//异常口入库,没有站台号
            headerLambdaQuery.isNull(TaskHeader::getPort)
                    .or()
                    .eq(TaskHeader::getPort, "P1001")
            .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);//小于任务完成状态的
        }else{
            headerLambdaQuery.eq(TaskHeader::getPort, "P1010");
        }
        List<TaskHeader> allHeader = taskHeaderService.list(headerLambdaQuery);
        if (ObjectUtils.isEmpty(allHeader)) {
            return AjaxResult.success().setData(Lists.newArrayList());
        }
        List<Integer> ids = allHeader.stream().map(TaskHeader::getId).collect(Collectors.toList());//获取任务ID
        detailLambdaQuery.in(TaskDetail::getTaskId, ids);
        List<TaskDetail> allDetail = taskDetailService.list(detailLambdaQuery);//详情列表
        //详情map,以任务头id分组
        Map<Integer, List<TaskDetail>> map = allDetail.stream().collect(Collectors.groupingBy(TaskDetail::getTaskId));
        //显示列表
        List<PortViewVO> portViewVOs = new ArrayList<>();

        for (TaskHeader taskHeader : allHeader) {
            PortViewVO portViewVO = new PortViewVO();//返回对象
            TaskHeaderVO header = new TaskHeaderVO();//返回头任务VO
            BeanUtils.copyProperties(taskHeader, header);

            header.setType(taskHeader.getTaskType());
            header.setSourceLocation(taskHeader.getFromLocation());
            header.setDestinationLocation(taskHeader.getToLocation());
            List<TaskDetail> tempDetails = map.get(taskHeader.getId());//通过id,获取详细

            List<TaskDetailsVO> list = new ArrayList<>();
            BigDecimal sum = BigDecimal.valueOf(0);//每个返回头任务VO的总数量
            if(tempDetails != null) {
                for (TaskDetail tempDetail : tempDetails) {
                    TaskDetailsVO taskDetailsVO = new TaskDetailsVO();//任务详情vo
                    BeanUtils.copyProperties(tempDetail, taskDetailsVO);
                    taskDetailsVO.setSourceLocation(taskHeader.getFromLocation());
                    taskDetailsVO.setDestinationLocation(taskHeader.getToLocation());
                    list.add(taskDetailsVO);
                    if (taskDetailsVO.getQty() != null){//统计总数量
                        BigDecimal add = sum.add(taskDetailsVO.getQty());
                        sum = add;
                    }
                }
            }
            header.setQty(sum);//总数量
            portViewVO.setTaskHeader(header);//头
            portViewVO.setTaskDetails(list);//详情
            portViewVOs.add(portViewVO);
        }
        return AjaxResult.success(portViewVOs);
    }*/
}