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.SupermarketProductMapper;
import com.bonus.canteen.core.supermarket.domain.SupermarketProduct;
import com.bonus.canteen.core.supermarket.service.ISupermarketProductService;

/**
 * 超市商城商品Service业务层处理
 * 
 * @author xsheng
 * @date 2025-06-03
 */
@Service
public class SupermarketProductServiceImpl implements ISupermarketProductService {
    @Autowired
    private SupermarketProductMapper supermarketProductMapper;

    /**
     * 查询超市商城商品
     * 
     * @param productId 超市商城商品主键
     * @return 超市商城商品
     */
    @Override
    public SupermarketProduct selectSupermarketProductByProductId(Long productId) {
        return supermarketProductMapper.selectSupermarketProductByProductId(productId);
    }

    /**
     * 查询超市商城商品列表
     * 
     * @param supermarketProduct 超市商城商品
     * @return 超市商城商品
     */
    @Override
    public List<SupermarketProduct> selectSupermarketProductList(SupermarketProduct supermarketProduct) {
        return supermarketProductMapper.selectSupermarketProductList(supermarketProduct);
    }

    /**
     * 新增超市商城商品
     * 
     * @param supermarketProduct 超市商城商品
     * @return 结果
     */
    @Override
    public int insertSupermarketProduct(SupermarketProduct supermarketProduct) {
        supermarketProduct.setCreateTime(DateUtils.getNowDate());
        try {
            return supermarketProductMapper.insertSupermarketProduct(supermarketProduct);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * 修改超市商城商品
     * 
     * @param supermarketProduct 超市商城商品
     * @return 结果
     */
    @Override
    public int updateSupermarketProduct(SupermarketProduct supermarketProduct) {
        supermarketProduct.setUpdateTime(DateUtils.getNowDate());
        try {
            return supermarketProductMapper.updateSupermarketProduct(supermarketProduct);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * 批量删除超市商城商品
     * 
     * @param productIds 需要删除的超市商城商品主键
     * @return 结果
     */
    @Override
    public int deleteSupermarketProductByProductIds(Long[] productIds) {
        return supermarketProductMapper.deleteSupermarketProductByProductIds(productIds);
    }

    /**
     * 删除超市商城商品信息
     * 
     * @param productId 超市商城商品主键
     * @return 结果
     */
    @Override
    public int deleteSupermarketProductByProductId(Long productId) {
        return supermarketProductMapper.deleteSupermarketProductByProductId(productId);
    }
}
