ContainerServiceImpl.java 6.33 KB
package com.huaheng.pc.general.container.service;

import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.pc.config.containerType.service.IContainerTypeService;
import com.huaheng.pc.general.container.domain.Container;
import com.huaheng.pc.config.containercapacity.domain.ContainerCapacity;
import com.huaheng.pc.general.container.domain.ContainerStatus;
import com.huaheng.pc.general.container.mapper.ContainerMapperAuto;
import com.huaheng.pc.general.container.mapper.ContainerMapper;
import com.huaheng.pc.general.location.domain.Location;
import com.huaheng.pc.general.location.domain.LocationPosition;
import com.huaheng.pc.general.location.mapper.LocationMapper;
import com.huaheng.pc.general.location.mapper.LocationMapperAuto;
import com.huaheng.pc.inventory.inventory.service.IInventoryService;
import com.huaheng.pc.system.dict.service.IDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 容器 服务层实现
 * 
 * @author huaheng
 * @date 2018-08-19
 */
@Service
public class ContainerServiceImpl  implements IContainerService {

    @Autowired
    private IContainerTypeService containerTypeService;
    @Autowired
    private IDictDataService dictDataService;
    @Autowired
    private IInventoryService inventoryService;
    @Resource
    private ContainerMapper containerMapper;
    @Resource
    private ContainerMapperAuto aotuMapper;
    @Resource
    private LocationMapperAuto locationAutoMapper;
    @Resource
    LocationMapper locationMapper;

    public List<Container> selectListEntityByLike(Container condition) {
        return aotuMapper.selectListEntityByLike(condition);
    }

    public List<Container> selectListEntityByEqual(Container condition) {
        return aotuMapper.selectListEntityByEqual(condition);
    }

    public Container selectFirstEntity(Container condition) {
        Container item = aotuMapper.selectFirstEntity(condition);
        return item;
    }

    public Container selectEntityById(Integer id) {
        return aotuMapper.selectEntityById(id);
    }

    public List<Map<String, Object>> selectListMapByEqual(String columns, Container condition) {
        return aotuMapper.selectListMapByEqual(columns, condition);
    }

    public Map<String, Object> selectFirstMap(String columns, Container condition) {
        Map<String, Object> item = aotuMapper.selectFirstMap(columns, condition);
        return item;
    }

    public int insert(Container record) {
        return aotuMapper.insert(record);
    }

    public int updateByModel(Container record) {
        return aotuMapper.updateByModel(record);
    }

    public int updateByCondition(Container record, Container condition) {
        return aotuMapper.updateByCondition(record, condition);
    }

    public int deleteById(Integer id) {
        return aotuMapper.deleteById(id);
    }

    public int deleteByCondition(Container condition) {
        return aotuMapper.deleteByCondition(condition);
    }

    @Override
    public Boolean insertContainer(String type, Integer quantity) {
        Integer number = getNumber(type);
//        List<Container>  containerList = new ArrayList<>();
        for(int i=0; i<quantity; i++)
        {
            number++;
            Container container = new Container();
            container.setId(null);
            container.setType(type);
            container.setCode(String.format("%s%05d", type, number));
            container.setStatus(ContainerStatus.empty.name());
            container.setCreated(new Date());
            container.setCreatedBy(ShiroUtils.getLoginName());
            container.setLastUpdated(null);
            container.setLastUpdatedBy(null);
            container.setEnable(true);
            container.setDeleted(false);
            container.setWarehouseId(ShiroUtils.getWarehouseId());
            container.setWarehouseCode(ShiroUtils.getWarehouseCode());
//            containerList.add(container);
            this.insert(container);
        }
        return true;
    }

    @Override
    public List<Location> getEmptyContainerInLocation(String containerCode, String locationCode, Integer warehouseId) {
        return locationMapper.getEmptyContainerInLocation(containerCode,locationCode,warehouseId);
    }

    @Override
    public void updateStatus(String containerCode, String status) {
        if (StringUtils.isNotEmpty(containerCode))
            containerMapper.updateStatus(ShiroUtils.getWarehouseCode(), containerCode, status);
    }

    @Override
    public void updateLocationCodeAndStatus(String containerCode, String locationCode, String status) {
        if (StringUtils.isNotEmpty(containerCode))
            containerMapper.updateLocationCodeAndStatus(ShiroUtils.getWarehouseCode(), containerCode, locationCode, status);
    }

    @Override
    public ContainerCapacity selectContainerCapacity(ContainerCapacity record) {
        return containerMapper.selectContainerCapacity(record);
    }

    @Override
    public Container selectFirstContainer(String containerCode, String code) {
        return containerMapper.selectFirstContainer(containerCode, code);
    }

    @Override
    public Container selectContainer(Container container) {
        return containerMapper.selectContainer(container) ;
    }

//    @Override
//    public List<Container> selectContainerList(Container container) {
//        return containerMapper.selectContainerList(container);
//    }

    @Override
    public int updateLocationCode(Container container, LocationPosition locationPosition) {
        return containerMapper.updateLocationCode(container,locationPosition);
    }

    private Integer getNumber(String type) {
        if (!containerTypeService.checkConfig(type))
            throw new ServiceException("容器类型编码不存在");
        String maxCode = containerMapper.getMaxCode(type);

        //如果指定类型的最后的code存在,那么 code = 容器类型 + (排序号 + 1)
        if (maxCode != null)
        {
            Integer number = Integer.valueOf(maxCode.substring(maxCode.length() - 5, maxCode.length()));
            return  number;
        }
        else
        {
            return  0;
        }
    }

}