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 com.bonus.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.canteen.core.supermarket.mapper.SupermarketUnitMapper;
import com.bonus.canteen.core.supermarket.domain.SupermarketUnit;
import com.bonus.canteen.core.supermarket.service.ISupermarketUnitService;

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

    /**
     * 查询计量单位
     * 
     * @param unitId 计量单位主键
     * @return 计量单位
     */
    @Override
    public SupermarketUnit selectSupermarketUnitByUnitId(Long unitId) {
        return supermarketUnitMapper.selectSupermarketUnitByUnitId(unitId);
    }

    /**
     * 查询计量单位列表
     * 
     * @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());
        supermarketUnit.setCreateBy(SecurityUtils.getUsername());
        try {
            return supermarketUnitMapper.insertSupermarketUnit(supermarketUnit);
        } catch (Exception e) {
            throw new ServiceException("错误信息描述, " + e.getMessage());
        }
    }

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

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

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