AgvPortServiceImpl.java 4.27 KB
package com.huaheng.api.acs.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.api.acs.domain.AgvPort;
import com.huaheng.api.acs.mapper.AgvPortCsMapper;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.domain.AjaxResult;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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


/**
 * 【请填写功能名称】 服务层实现
 *
 * @author huaheng
 * @date 2022-07-27
 */
@Service
public class AgvPortServiceImpl extends ServiceImpl<AgvPortCsMapper, AgvPort> implements AgvPortService {
    @Resource
    private AgvPortCsMapper agvPortCsMapper;
    @Override
    public List<AgvPort> getListByContainerCode(String containerCode) {
        LambdaQueryWrapper<AgvPort> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AgvPort::getContainerCode, containerCode);
        return list(queryWrapper);
    }

    @Override
    public AgvPort getByContainerCode(String containerCode) {
        LambdaQueryWrapper<AgvPort> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AgvPort::getContainerCode, containerCode).orderByAsc(AgvPort::getType).last("limit 1");
        return getOne(queryWrapper);
    }

    @Override
    public boolean lockById(Long id) {
        AgvPort agvPort = getById(id);
        agvPort.setStatus("lock");
        return updateById(agvPort);
    }

    @Override
    public boolean unlockById(Long id) {
        AgvPort agvPort = getById(id);
        agvPort.setStatus("empty");
        return updateById(agvPort);
    }

    @Override
    public boolean clearContainerCodeById(Long id) {
        AgvPort agvPort = getById(id);
        agvPort.setContainerCode("");
        return updateById(agvPort);
    }


    @Override
    public boolean setContainerCodeById(Long id, String containerCode) {
        AgvPort agvPort = getById(id);
        agvPort.setContainerCode(containerCode);
        return updateById(agvPort);
    }

    @Override
    public boolean containerInPort(String containerCode) {
        List list = getListByContainerCode(containerCode);
        if(list == null || list.size() == 0){
            return false;
        }
        return  true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addAgvPort(String startNum,String endNum,String name,String workStationId,String containerCode,String type,String area) {
        List agvPorts = new ArrayList();
        for(int i=Integer.valueOf(startNum);i<=Integer.valueOf(endNum);i++){
            AgvPort agvPort=new AgvPort();
            agvPort.setCode("Work"+" "+i);
            agvPort.setName(name+""+i);
            if(StringUtils.isNotEmpty(workStationId)){
                agvPort.setWorkStationId(Long.valueOf(workStationId));
            }
            agvPort.setType(Long.valueOf(type));
            agvPort.setArea(area);
            agvPort.setStatus("empty");
            agvPorts.add(agvPort);
        }
        return agvPortCsMapper.addList(agvPorts);
    }

    @Override
    public AgvPort getAgvportByCode(String code) {
        LambdaQueryWrapper<AgvPort> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(AgvPort::getCode, code).orderByAsc(AgvPort::getType).last("limit 1");
        return this.getOne(queryWrapper);
    }

    @Override
    public void updateStatus(String code, String status) {
        if (StringUtils.isNotEmpty(code)) {
            agvPortCsMapper.updateStatus(code, status);
        }
    }

    @Override
    public void setContainerCode(String code, String containerCode) {
        if(StringUtils.isNotEmpty(code)){
            agvPortCsMapper.setContainerCode(code,containerCode);
        }
    }

    @Override
    public AjaxResult<List<AgvPort>> insertAgvport(String portType, Integer quantity) {
        return AjaxResult.success();
    }

    @Override
    public boolean clearContainerCodeByCode(String code) {
        return agvPortCsMapper.clearContainerCodeByCode(code);
    }

    @Override
    public List<String> getSize2Code(Long id) {
         return agvPortCsMapper.getSize2Code(id);
    }
}