package com.bonus.canteen.core.supermarket.service.impl;

import com.bonus.canteen.core.supermarket.domain.SupermarketUnit;
import com.bonus.canteen.core.supermarket.mapper.SupermarketUnitMapper;
import com.bonus.canteen.core.supermarket.service.SupermarketUnitService;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 单位Service业务层处理
 * 
 * @author xsheng
 * @date 2025-04-05
 */
@Service
public class SupermarketUnitServiceImpl implements SupermarketUnitService {
    @Autowired
    private SupermarketUnitMapper supermarketUnitMapper;

    /**
     * 查询单位列表
     * 
     * @param SupermarketUnit 单位
     * @return 单位
     */
    @Override
    public List<SupermarketUnit> selectSupermarketUnitList(SupermarketUnit SupermarketUnit) {
        return supermarketUnitMapper.selectSupermarketUnitList(SupermarketUnit);
    }

    /**
     * 新增单位
     * 
     * @param SupermarketUnit 单位
     * @return 结果
     */
    @Override
    public int insertSupermarketUnit(SupermarketUnit SupermarketUnit) {
        SupermarketUnit.setCreateTime(DateUtils.getNowDate());
        try {
            return supermarketUnitMapper.insertSupermarketUnit(SupermarketUnit);
        } catch (Exception e) {
            throw new ServiceException("错误信息描述");
        }
    }

    /**
     * 修改单位
     * 
     * @param SupermarketUnit 单位
     * @return 结果
     */
    @Override
    public int updateSupermarketUnit(SupermarketUnit SupermarketUnit) {
        SupermarketUnit.setUpdateTime(DateUtils.getNowDate());
        try {
            return supermarketUnitMapper.updateSupermarketUnit(SupermarketUnit);
        } catch (Exception e) {
            throw new ServiceException("错误信息描述");
        }
    }

    /**
     * 批量删除单位
     * 
     * @param SupermarketIds 需要删除的单位主键
     * @return 结果
     */
    @Override
    public int deleteSupermarketUnitBySupermarketIds(Long[] SupermarketIds) {
        return supermarketUnitMapper.deleteSupermarketUnitBySupermarketIds(SupermarketIds);
    }

    /**
     * 删除单位信息
     * 
     * @param SupermarketId 单位主键
     * @return 结果
     */
    @Override
    public int deleteSupermarketUnitBySupermarketId(Long SupermarketId) {
        return supermarketUnitMapper.deleteSupermarketUnitBySupermarketId(SupermarketId);
    }
}
