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

import java.util.List;
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 com.bonus.canteen.core.supermarket.mapper.SupermarketInfoMapper;
import com.bonus.canteen.core.supermarket.domain.SupermarketInfo;
import com.bonus.canteen.core.supermarket.service.ISupermarketInfoService;

/**
 * 超市Service业务层处理
 * 
 * @author xsheng
 * @date 2025-05-25
 */
@Service
public class SupermarketInfoServiceImpl implements ISupermarketInfoService {
    @Autowired
    private SupermarketInfoMapper supermarketInfoMapper;

    /**
     * 查询超市
     * 
     * @param supermarketId 超市主键
     * @return 超市
     */
    @Override
    public SupermarketInfo selectSupermarketInfoBySupermarketId(Long supermarketId) {
        return supermarketInfoMapper.selectSupermarketInfoBySupermarketId(supermarketId);
    }

    /**
     * 查询超市列表
     * 
     * @param supermarketInfo 超市
     * @return 超市
     */
    @Override
    public List<SupermarketInfo> selectSupermarketInfoList(SupermarketInfo supermarketInfo) {
        return supermarketInfoMapper.selectSupermarketInfoList(supermarketInfo);
    }

    /**
     * 新增超市
     * 
     * @param supermarketInfo 超市
     * @return 结果
     */
    @Override
    public int insertSupermarketInfo(SupermarketInfo supermarketInfo) {
        supermarketInfo.setCreateTime(DateUtils.getNowDate());
        try {
            return supermarketInfoMapper.insertSupermarketInfo(supermarketInfo);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * 修改超市
     * 
     * @param supermarketInfo 超市
     * @return 结果
     */
    @Override
    public int updateSupermarketInfo(SupermarketInfo supermarketInfo) {
        supermarketInfo.setUpdateTime(DateUtils.getNowDate());
        try {
            return supermarketInfoMapper.updateSupermarketInfo(supermarketInfo);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * 批量删除超市
     * 
     * @param supermarketIds 需要删除的超市主键
     * @return 结果
     */
    @Override
    public int deleteSupermarketInfoBySupermarketIds(Long[] supermarketIds) {
        return supermarketInfoMapper.deleteSupermarketInfoBySupermarketIds(supermarketIds);
    }

    /**
     * 删除超市信息
     * 
     * @param supermarketId 超市主键
     * @return 结果
     */
    @Override
    public int deleteSupermarketInfoBySupermarketId(Long supermarketId) {
        return supermarketInfoMapper.deleteSupermarketInfoBySupermarketId(supermarketId);
    }
}
