ArrivedNoticeController.java 5.6 KB
package com.huaheng.api.wcs.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.service.ConfigService;
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.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.shipment.shipmentContainerAdvice.domain.ShipmentContainerAdvice;
import com.huaheng.pc.shipment.shipmentContainerAdvice.service.IShipmentContainerAdviceService;
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.apache.commons.lang.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

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

    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private TaskDetailService taskDetailService;
    @Resource
    private InventoryDetailService inventoryDetailService;
    @Resource
    private LocationService locationService;
    @Resource
    private IShipmentContainerAdviceService shipmentContainerAdviceService;
    @Resource
    private ContainerService containerService;
    @Resource
    private ConfigService configService;

    @PostMapping("/arrivedNotice")
    @ApiOperation("到达拣选台")
    @ApiLogger(apiName = "到达拣选台", from="ROBOT")
    @Transactional(rollbackFor = Exception.class)
    @ResponseBody
    public AjaxResult arrivedNotice(@RequestBody Map<String,String> map) {
        String warehouseCode = "CS0001";
        String taskNo = map.get("taskNo");
        String port = map.get("port");
        String msg = map.get("msg");
        String state = map.get("state");
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getId, taskNo);
        TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
        if(taskHeader != null) {
            taskHeader.setStatus(QuantityConstant.TASK_STATUS_ARRIVED_STATION);
        } else {
            return AjaxResult.error("没有找到任务taskNo:" + taskNo);
        }
        int taskType = taskHeader.getTaskType();
        int status = taskHeader.getStatus();
        if(status == QuantityConstant.TASK_STATUS_COMPLETED) {
            return AjaxResult.success("更新到达站台成功, 任务已经完成");
        }
        String value = configService.getKey(QuantityConstant.RULE_TASK_LOCATION);
        int taskLocationRule = Integer.parseInt(value);
        // 非入库任务,并且没有分配库位的,到达站台时,解除库位锁定
        if (taskLocationRule == QuantityConstant.RULE_TASK_NOT_LOCATION) {
            if (taskType != QuantityConstant.TASK_TYPE_WHOLERECEIPT
                    || taskType != QuantityConstant.TASK_TYPE_EMPTYRECEIPT
                    || taskType != QuantityConstant.TASK_TYPE_MANY_EMPTYRECEIPT) {  //非整入情况
                String fromLocationCode = taskHeader.getFromLocation();
                if (StringUtils.isNotEmpty(fromLocationCode)) {
                    Location location = locationService.getLocationByCode(
                            fromLocationCode, taskHeader.getWarehouseCode());
                    if (location != null) {
//                        locationService.updateStatus(fromLocationCode,
//                                QuantityConstant.STATUS_LOCATION_EMPTY, warehouseCode);
                        locationService.updateContainerCodeAndStatus(fromLocationCode, "", QuantityConstant.STATUS_LOCATION_LOCK, warehouseCode);
                        containerService.updateLocationCodeAndStatus(taskHeader.getContainerCode(), "", QuantityConstant.STATUS_CONTAINER_EMPTY, warehouseCode);
                    }
                }
            }
        }
        boolean result = taskHeaderService.updateById(taskHeader);
        if (taskType == QuantityConstant.TASK_TYPE_WHOLESHIPMENT || taskType == QuantityConstant.TASK_TYPE_SORTINGSHIPMENT){
            //更新预组盘明细状态
            List<ShipmentContainerAdvice> list = new ArrayList<>();
            LambdaQueryWrapper<ShipmentContainerAdvice> wrapper = Wrappers.lambdaQuery();
            wrapper.eq(ShipmentContainerAdvice::getShippingContainerId, taskHeader.getAllocationHeadId());
            List<ShipmentContainerAdvice> lst = shipmentContainerAdviceService.list(wrapper);
            if (lst.size() > 0){
                for(ShipmentContainerAdvice advice: lst){
                    advice.setPort(port);
                    list.add(advice);
                }
                if (!shipmentContainerAdviceService.updateBatchById(list)){
                    return AjaxResult.error("更新到达站台失败");
                }
            }
        }
        if(!result) {
            return AjaxResult.error("更新到达站台失败");
        }
        return AjaxResult.success("更新到达站台成功");
    }
}