MobileController.java 10.7 KB
package com.huaheng.api.tv.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/API/WMS/v2")
public class MobileController extends BaseController {

    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private LocationService locationService;


    /**
     * 当天出入库量
     *
     * @param warehouseCode 仓库编码
     * @return
     */
    @GetMapping("tvTaskNum")
    @ApiOperation("获取电视信息")
    @ResponseBody
    @CrossOrigin
    public AjaxResult tvTaskNum(String warehouseCode) {
        if (StringUtils.isEmpty(warehouseCode)) {
            return AjaxResult.error("请填写仓库");
        }
        ArrayList<Object> result = new ArrayList<>();
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getWarehouseCode, warehouseCode);
        taskHeaderLambdaQueryWrapper.ge(TaskHeader::getCreated, DateUtils.getNowPreDays("yyyy-MM-dd 00:00:00", 0));
        taskHeaderLambdaQueryWrapper.in(TaskHeader::getInternalTaskType, QuantityConstant.TASK_INTENERTYPE_RECEIPT, QuantityConstant.TASK_INTENERTYPE_SHIPMENT);
        List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
        Map<Integer, List<TaskHeader>> taskTypeMap = taskHeaderList.stream().collect(Collectors.groupingBy(TaskHeader::getInternalTaskType));
        List<TaskHeader> receiptTaskList = taskTypeMap.get(QuantityConstant.TASK_INTENERTYPE_RECEIPT);
        List<TaskHeader> shipmentTaskList = taskTypeMap.get(QuantityConstant.TASK_INTENERTYPE_SHIPMENT);
        HashMap<String, Integer> resultMap = new HashMap<>();
        int receiptNum = 0;
        int shipmentNum = 0;
        if (CollectionUtils.isNotEmpty(receiptTaskList)) {
            receiptNum = receiptTaskList.size();
            resultMap.put("receiptNum", receiptNum);
        } else {
            resultMap.put("receiptNum", 0);
        }
        if (CollectionUtils.isNotEmpty(shipmentTaskList)) {
            shipmentNum = shipmentTaskList.size();
            resultMap.put("shipmentNum", shipmentNum);
        } else {
            resultMap.put("shipmentNum", 0);
        }
        if (shipmentNum != 0) {
            float proportion =0;
            if(receiptNum!=0&&shipmentNum!=0){
                proportion = (Math.round(receiptTaskList.size() / (float) shipmentTaskList.size() * 100)) / 100f;
            }
            resultMap.put("proportion", (int) (proportion * 100));
        } else {
            resultMap.put("proportion", 100);
        }

        LambdaQueryWrapper<TaskHeader> monthLambdaQueryWrapper = Wrappers.lambdaQuery();
        monthLambdaQueryWrapper.eq(TaskHeader::getWarehouseCode, warehouseCode);
        monthLambdaQueryWrapper.ge(TaskHeader::getCreated, DateUtils.getNowPreDays("yyyy-MM-dd", 30));
        monthLambdaQueryWrapper.in(TaskHeader::getInternalTaskType, QuantityConstant.TASK_INTENERTYPE_RECEIPT, QuantityConstant.TASK_INTENERTYPE_SHIPMENT);
        List<TaskHeader> taskHeaderList2 = taskHeaderService.list(monthLambdaQueryWrapper);
        Map<Integer, List<TaskHeader>> taskTypeMap2 = taskHeaderList2.stream().collect(Collectors.groupingBy(TaskHeader::getInternalTaskType));
        List<TaskHeader> receiptTaskList2 = taskTypeMap2.get(QuantityConstant.TASK_INTENERTYPE_RECEIPT);
        List<TaskHeader> shipmentTaskList2 = taskTypeMap2.get(QuantityConstant.TASK_INTENERTYPE_SHIPMENT);
        int receiptNumMonth = 0;
        int shipmentNumMonth = 0;
        if (CollectionUtils.isNotEmpty(receiptTaskList2)) {
            receiptNumMonth = receiptTaskList2.size();
            resultMap.put("receiptNumMonth", receiptNumMonth);
        } else {
            resultMap.put("receiptNumMonth", 0);
        }
        if (CollectionUtils.isNotEmpty(shipmentTaskList2)) {
            shipmentNumMonth = shipmentTaskList2.size();
            resultMap.put("shipmentNumMonth", shipmentNumMonth);
        } else {
            resultMap.put("shipmentNumMonth", 0);
        }
        if (shipmentNum != 0) {
            float proportion =0;
            if(receiptNumMonth!=0&&shipmentNumMonth!=0){
                proportion = (Math.round(receiptTaskList2.size() / (float) shipmentTaskList2.size() * 100)) / 100f;
            }
            resultMap.put("proportionMonth", (int) (proportion * 100));
        } else {
            resultMap.put("proportionMonth", 100);
        }
        result.add(resultMap);
        return AjaxResult.success(result);
    }

    /**
     * 库位使用情况(按巷道来)
     *
     * @param warehouseCode
     * @return
     */
    @GetMapping("roadWayLocation")
    @ApiOperation("获取电视信息")
    @ResponseBody
    @CrossOrigin
    public AjaxResult roadWayLocation(String warehouseCode) {
        if (StringUtils.isEmpty(warehouseCode)) {
            return AjaxResult.error("请填写仓库");
        }
        ArrayList<Object> result = new ArrayList<>();
        LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
        locationLambdaQueryWrapper.eq(Location::getWarehouseCode, warehouseCode);
        locationLambdaQueryWrapper.eq(Location::getZoneCode, "LK");
        List<Location> locationList = locationService.list(locationLambdaQueryWrapper);
        Map<String, List<Location>> locationMap = locationList.stream().collect(Collectors.groupingBy(Location::getRoadway));
        for (Map.Entry<String, List<Location>> entry : locationMap.entrySet()) {
            HashMap<String, String> resultMap = new HashMap<>();
            String roadWay = entry.getKey();
            List<Location> sumLocationList = entry.getValue();
            int sumNum = sumLocationList.size();
            int haveContainerNum = (int) sumLocationList.stream().filter(l -> StringUtils.isNotEmpty(l.getContainerCode())).count();
            int unHaveContainerNum = sumLocationList.size() - haveContainerNum;
            resultMap.put("roadWay", roadWay + "号巷道");

            resultMap.put("sumNum", String.valueOf(sumNum));
            resultMap.put("haveContainerNum", String.valueOf(haveContainerNum));
            resultMap.put("unHaveContainerNum", String.valueOf(unHaveContainerNum));
            float usagerate = (Math.round(haveContainerNum / (float) sumNum * 100)) / 100f;
            resultMap.put("usagerate", (int) (usagerate * 100) + "%");
            result.add(resultMap);
        }
        return AjaxResult.success(result);
    }

    /**
     * 任务趋势(一周)
     *
     * @param warehouseCode
     * @return
     */
    @GetMapping("taskOfWeek")
    @ApiOperation("获取电视信息")
    @ResponseBody
    @CrossOrigin
    public AjaxResult taskOfWeek(String warehouseCode) {
        if (StringUtils.isEmpty(warehouseCode)) {
            return AjaxResult.error("请填写仓库");
        }
        HashMap<String, Integer> resultMap = new HashMap<>();
        ArrayList<Object> result = new ArrayList<>();
        String times = DateUtils.getNowPreDays("yyyy-MM-dd 00:00:00", 7);
        List<Map<String, Object>> list = taskHeaderService.selectTaskInWeek(times, warehouseCode);
        if (list != null && list.size() > 0) {
        }
        return AjaxResult.success(list);
    }

    /**
     * 24小时任务趋势()
     *
     * @param warehouseCode
     * @return
     */
    @GetMapping("taskOfDay")
    @ApiOperation("获取电视信息")
    @ResponseBody
    @CrossOrigin
    public AjaxResult taskOfDay(String warehouseCode) {
        if (StringUtils.isEmpty(warehouseCode)) {
            return AjaxResult.error("请填写仓库");
        }
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getWarehouseCode, warehouseCode);
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getZoneCode, "LK");
        taskHeaderLambdaQueryWrapper.ge(TaskHeader::getCreated, DateUtils.getNowPreDays("yyyy-MM-dd 00:00:00", 1));
        taskHeaderLambdaQueryWrapper.in(TaskHeader::getInternalTaskType, QuantityConstant.TASK_INTENERTYPE_RECEIPT, QuantityConstant.TASK_INTENERTYPE_SHIPMENT, QuantityConstant.TASK_INTENERTYPE_WORK);
//        taskHeaderLambdaQueryWrapper.ne(TaskHeader::getFromLocation, "");
//        taskHeaderLambdaQueryWrapper.ne(TaskHeader::getToLocation, "");
        taskHeaderLambdaQueryWrapper.apply("(fromLocation!='' or toLocation!='' )");
        taskHeaderLambdaQueryWrapper.orderByDesc(TaskHeader::getId);
        taskHeaderLambdaQueryWrapper.last("limit 20");
        List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (TaskHeader task : taskHeaderList) {
            Map map = new HashMap();
            if (task.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_RECEIPT)) {
                map.put("type", "入库");
            } else if (task.getInternalTaskType().equals(QuantityConstant.TASK_INTENERTYPE_SHIPMENT)) {
                map.put("type", "出库");
            } else {
                map.put("type", "工作");
            }
            if (task.getStatus() == 100) {
                map.put("status", "任务完成");
            } else if (task.getStatus() == 1) {
                map.put("status", "任务生成");
            } else if (task.getStatus() == 10) {
                map.put("status", "下达任务");
            } else if (task.getStatus() == 20) {
                map.put("status", "开始执行");
            } else if (task.getStatus() == 30) {
                map.put("status", "到达拣选台");
            } else {
                map.put("status", "开始执行");
            }
            map.put("fromLocation", task.getFromLocation());
            map.put("toLocation", task.getToLocation());
            resultList.add(map);
        }
        return AjaxResult.success(resultList);
    }
}