TransmissionLineInteractionController.java 4.3 KB
package com.huaheng.api.wcs.controller;

import com.huaheng.api.acs.service.AcsService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.agv.domain.AgvInventory;
import com.huaheng.pc.agv.domain.AgvPort;
import com.huaheng.pc.agv.domain.AgvTaskDetail;
import com.huaheng.pc.agv.domain.WorkStation;
import com.huaheng.pc.agv.service.*;
import com.huaheng.pc.config.container.service.ContainerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/transmissionLine")
public class TransmissionLineInteractionController {
    @Autowired
    private AcsService acsService;

    @Autowired
    private IAgvPortService agvPortService;

    @Autowired
    private IAgvInventoryService agvInventoryService;

    @Autowired
    private IAgvTaskDetailService agvTaskDetailService;

    @Autowired
    private IWorkStationService workStationService;

    @Autowired
    private ContainerService containerService;

    @PostMapping("/getContainerCode")
    @ApiLogger(apiName = "wcs输送线交互点位请求托盘", from = "wcs", to = "wms")
    public AjaxResult wcsGetContainerCode(@RequestBody Map map) {
        String wcsLinePort = (String)map.get("port");
        if (StringUtils.isEmpty(wcsLinePort)) {
            return AjaxResult.error("port不能为空");
        }
        AgvPort agvPort = agvPortService.getByWcsLinePort(wcsLinePort);
        if (agvPort == null) {
            return AjaxResult.error("没有找到:" + wcsLinePort + " 对应的agv点位");
        }
        String code = agvPort.getCode();
        String containerCode = agvPort.getContainerCode();
        if (StringUtils.isEmpty(containerCode)) {
            return AjaxResult.error("位置{},无容器号!", code);
        }
        agvPortService.clearContainerCodeByCode(code);
        agvInventoryService.removeByPortCode(code);
        containerService.updateSetLocationNullByCode(containerCode, QuantityConstant.STATUS_POSITION_EMPTY);
        return AjaxResult.success("成功").setData(containerCode);
    }

    @PostMapping("/setContainerCode")
    @ApiLogger(apiName = "wcs输送线交互点位托盘到达", from = "wcs", to = "wms")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult wcsSetContainerCode(@RequestBody Map map) {
        String wcsLinePort = (String)map.get("port");
        if (StringUtils.isEmpty(wcsLinePort)) {
            return AjaxResult.error("port不能为空");
        }
        AgvPort agvPort = agvPortService.getByWcsLinePort(wcsLinePort);
        if (agvPort == null) {
            return AjaxResult.error("没有找到:" + wcsLinePort + " 对应的agv点位");
        }

        String containerCode = (String)map.get("containerCode");
        if (StringUtils.isEmpty(containerCode)) {
            return AjaxResult.error("containerCode不能为空");
        }
        List<AgvTaskDetail> list = agvTaskDetailService.getListByContainer(containerCode);
        agvPort.setContainerCode(containerCode);
        agvPortService.updateById(agvPort);
        if (list != null) {
            List<AgvInventory> agvInvs = new ArrayList<>();
            list.forEach(it -> {
                AgvInventory inv = new AgvInventory();
                inv.setQty(it.getQty().longValue());
                inv.setStatus("empty");
                inv.setContainerCode(containerCode);
                inv.setMaterialCode(it.getMaterialCode());
                inv.setMaterialName(it.getMaterialName());
                inv.setAgvPortCode(agvPort.getCode());
                inv.setAgvPortId(agvPort.getId());
                inv.setWorkStationId(agvPort.getWorkStationId());
                agvInvs.add(inv);
            });
            agvInventoryService.saveBatch(agvInvs);
        }
        return AjaxResult.success("接收到了");
    }
}