
package com.tmerclub.cloud.product.service.impl;

import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.util.PageUtil;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.product.dto.WarehouseAreaDTO;
import com.tmerclub.cloud.product.mapper.WarehouseAreaMapper;
import com.tmerclub.cloud.product.model.WarehouseArea;
import com.tmerclub.cloud.product.service.WarehouseAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 仓库项和供货城市关联信息
 *
 * @author tmerclub
 * @date 2023-11-08 11:11:44
 */
@Service
public class WarehouseAreaServiceImpl implements WarehouseAreaService {

    @Autowired
    private WarehouseAreaMapper warehouseAreaMapper;

    @Override
    public PageVO<WarehouseArea> page(PageDTO pageDTO) {
        return PageUtil.doPage(pageDTO, () -> warehouseAreaMapper.list());
    }

    @Override
    public WarehouseArea getByWarehouseAreaId(Long warehouseAreaId) {
        return warehouseAreaMapper.getByWarehouseAreaId(warehouseAreaId);
    }

    @Override
    public void save(WarehouseArea warehouseArea) {
        warehouseAreaMapper.save(warehouseArea);
    }

    @Override
    public void update(WarehouseArea warehouseArea) {
        warehouseAreaMapper.update(warehouseArea);
    }

    @Override
    public void deleteById(Long warehouseAreaId) {
        warehouseAreaMapper.deleteById(warehouseAreaId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void batchSave(List<WarehouseAreaDTO> warehouseAreaDTOList) {
        if (CollectionUtils.isEmpty(warehouseAreaDTOList)) {
            return;
        }
        warehouseAreaMapper.batchSave(warehouseAreaDTOList);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteByWarehouseId(Long warehouseId) {
        warehouseAreaMapper.deleteByWarehouseId(warehouseId);
    }
}
