MobileTaskController.java 10.4 KB
package com.huaheng.mobile.task;

import com.alibaba.fastjson.JSONException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.api.general.domain.ShipmentDomain;
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.domain.AjaxResult;
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
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.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Enzo Cotter
 * @date 2019/12/15
 */
@CrossOrigin
@RestController
@RequestMapping("/mobile/task")
@Api(tags = {"手持立体库库存相关"}, value = "手持立体库库存相关")
public class MobileTaskController  {

    @Autowired
    private TaskHeaderService taskHeaderService;
    @Autowired
    private TaskDetailService taskDetailService;
    @Autowired
    private InventoryTransactionService inventoryTransactionService;
    @PostMapping("/searchTask")
    @ApiOperation("移动端查询任务")
    @Log(title = "移动端查询任务", action = BusinessType.OTHER)
    public AjaxResult searchTask(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
        String companyCode = param.get("companyCode");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String now = df.format(new Date());
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, -7);
        Date first = c.getTime();
        String start = df.format(first);//前一天
        LambdaQueryWrapper<TaskHeader> taskHeaderQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderQueryWrapper.eq(TaskHeader::getCompanyCode, companyCode)
                .eq(TaskHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .le(TaskHeader::getCreated, now)
                .gt(TaskHeader::getCreated, start)
                .orderByDesc(TaskHeader::getCreated);
        List<TaskHeader> taslHeaderList = taskHeaderService.list(taskHeaderQueryWrapper);
        return AjaxResult.success(taslHeaderList);
    }

    @PostMapping("/searchTaskInCondition")
    @ApiOperation("移动端查询任务")
    @Log(title = "移动端查询任务", action = BusinessType.OTHER)
    public AjaxResult searchTaskInCondition(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
        String companyCode = param.get("companyCode");
        String taskType = param.get("taskType");
        String containerCode = param.get("containerCode");
        String fromLocatrion = param.get("fromLocatrion");
        String toLocation = param.get("toLocation");
        String status = param.get("status");
        String startTime = param.get("startTime");
        String endTime = param.get("endTime");
        LambdaQueryWrapper<TaskHeader> taskHeaderQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderQueryWrapper
                .eq(TaskHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .eq(StringUtils.isNotEmpty(taskType), TaskHeader::getTaskType, taskType)
                .eq(StringUtils.isNotEmpty(containerCode), TaskHeader::getContainerCode, containerCode)
                .eq(StringUtils.isNotEmpty(fromLocatrion), TaskHeader::getFromLocation, fromLocatrion)
                .eq(StringUtils.isNotEmpty(toLocation), TaskHeader::getToLocation, toLocation)
                .eq(StringUtils.isNotEmpty(status), TaskHeader::getStatus, status)
                .gt(StringUtils.isNotEmpty(startTime), TaskHeader::getCreated, startTime)
                .le(StringUtils.isNotEmpty(endTime), TaskHeader::getCreated, endTime)
                .orderByDesc(TaskHeader::getCreated);
        if(status.equals("99")) {
            taskHeaderQueryWrapper = Wrappers.lambdaQuery();
            taskHeaderQueryWrapper
                    .eq(TaskHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                    .eq(StringUtils.isNotEmpty(taskType), TaskHeader::getTaskType, taskType)
                    .eq(StringUtils.isNotEmpty(containerCode), TaskHeader::getContainerCode, containerCode)
                    .eq(StringUtils.isNotEmpty(fromLocatrion), TaskHeader::getFromLocation, fromLocatrion)
                    .eq(StringUtils.isNotEmpty(toLocation), TaskHeader::getToLocation, toLocation)
                    .le(StringUtils.isNotEmpty(status), TaskHeader::getStatus, status)
                    .gt(StringUtils.isNotEmpty(startTime), TaskHeader::getCreated, startTime)
                    .le(StringUtils.isNotEmpty(endTime), TaskHeader::getCreated, endTime)
                    .orderByDesc(TaskHeader::getCreated);
        }

        List<TaskHeader>  taskHeaderList = taskHeaderService.list(taskHeaderQueryWrapper);
        return AjaxResult.success(taskHeaderList);
    }


    @PostMapping("/findTask")
    @ApiOperation("移动端查询任务详情")
    @Log(title = "移动端查询任务详情", action = BusinessType.OTHER)
    public AjaxResult findTask(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
        String taskHeadId = param.get("taskHeadId");
        String companyCode = param.get("companyCode");
        if (StringUtils.isNull(taskHeadId)){
            return AjaxResult.error("任务id为空");
        } else if (StringUtils.isNull(companyCode)){
            return AjaxResult.error("公司编码为空");
        }

        /* 查询入库单,如果数据库中不存在,则调用ERP接口拉取单据,成功后再次查询返回结果*/
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getId, taskHeadId);
        TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
        if(taskHeader == null) {
            return AjaxResult.error("没有找到任务");
        }
        TaskDomain taskDomain = new TaskDomain();
        taskDomain.setTaskHeader(taskHeader);

        LambdaQueryWrapper<TaskDetail> taskDetailQueryWrapper = Wrappers.lambdaQuery();
        taskDetailQueryWrapper.eq(TaskDetail::getTaskId, taskHeader.getId());
        List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailQueryWrapper);
        taskDomain.setTaskDetails(taskDetailList);
        return AjaxResult.success(taskDomain);
    }

    @PostMapping("/searchTodayInfo")
    @ApiOperation("移动端查询今天信息")
    @Log(title = "移动端查询今天信息", action = BusinessType.OTHER)
    public AjaxResult searchTodayInfo(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
        TodayInfo todayInfo = new TodayInfo();
        String companyCode = param.get("companyCode");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String now = df.format(new Date());
        now = now + " 23:59:59";
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, 0);
        Date first = c.getTime();
        String start = df.format(first);//前一天
        start = start + " 00:00:00";
        LambdaQueryWrapper<TaskHeader> taskHeaderQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderQueryWrapper.eq(TaskHeader::getCompanyCode, companyCode)
                .eq(TaskHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .le(TaskHeader::getCreated, now)
                .gt(TaskHeader::getCreated, start)
                .orderByDesc(TaskHeader::getCreated);
        List<TaskHeader> taslHeaderList = taskHeaderService.list(taskHeaderQueryWrapper);
        todayInfo.setTodayTAask(taslHeaderList.size());

        LambdaQueryWrapper<InventoryTransaction> inventoryTransactionLambdaQueryWrapperQuery = Wrappers.lambdaQuery();
        inventoryTransactionLambdaQueryWrapperQuery.eq(InventoryTransaction::getCompanyCode, companyCode)
                .eq(InventoryTransaction::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .le(InventoryTransaction::getCreated, now)
                .gt(InventoryTransaction::getCreated, start)
                .orderByDesc(InventoryTransaction::getCreated);
        int todayReceipt = 0, todayShipment = 0;
        List<InventoryTransaction> inventoryTransactionList = inventoryTransactionService.list(inventoryTransactionLambdaQueryWrapperQuery);
        if(inventoryTransactionList != null) {
            for (InventoryTransaction inventoryTransaction : inventoryTransactionList) {
                if(inventoryTransaction.getTransactionType() == 10) {
                    todayReceipt = todayReceipt + inventoryTransaction.getTaskQty().intValue();
                } else  if(inventoryTransaction.getTransactionType() == 20) {
                    todayShipment = todayShipment + inventoryTransaction.getTaskQty().intValue();
                }
            }
        }
        todayInfo.setTodayReceipt(todayReceipt);
        todayInfo.setTodayShipment(todayShipment);
        return AjaxResult.success(todayInfo);
    }

    @Log(title = "移动端设置任务的站台", operating = "设置站台", action = BusinessType.GRANT)
    @PostMapping("/setTaskStation")
    @ResponseBody
    public AjaxResult setTaskStation (String id, String port){
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getId, id);
        TaskHeader taskHeader1 = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
        taskHeader1.setPort(port);
        taskHeaderService.update(taskHeader1, taskHeaderLambdaQueryWrapper);
        return AjaxResult.success();
    }

}