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

import java.util.List;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.houqin.utils.id.Id;
import com.bonus.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.canteen.core.nutrition.mapper.HealthChronicMapper;
import com.bonus.canteen.core.nutrition.domain.HealthChronic;
import com.bonus.canteen.core.nutrition.service.IHealthChronicService;

/**
 * 慢性病Service业务层处理
 * 
 * @author xsheng
 * @date 2025-05-13
 */
@Service
public class HealthChronicServiceImpl implements IHealthChronicService {
    @Autowired
    private HealthChronicMapper healthChronicMapper;

    /**
     * 查询慢性病
     * 
     * @param id 慢性病主键
     * @return 慢性病
     */
    @Override
    public HealthChronic selectHealthChronicById(Long id) {
        return healthChronicMapper.selectHealthChronicById(id);
    }

    /**
     * 查询慢性病列表
     * 
     * @param healthChronic 慢性病
     * @return 慢性病
     */
    @Override
    public List<HealthChronic> selectHealthChronicList(HealthChronic healthChronic) {
        return healthChronicMapper.selectHealthChronicList(healthChronic);
    }

    /**
     * 新增慢性病
     * 
     * @param healthChronic 慢性病
     * @return 结果
     */
    @Override
    public int insertHealthChronic(HealthChronic healthChronic) {
        healthChronic.setCreateTime(DateUtils.getNowDate());
        healthChronic.setCreateBy(SecurityUtils.getUsername());
        try {
            healthChronic.setChronicId(Id.next());
            return healthChronicMapper.insertHealthChronic(healthChronic);
        } catch (Exception e) {
            throw new ServiceException("新增错误, " + e.getMessage());
        }
    }

    /**
     * 修改慢性病
     * 
     * @param healthChronic 慢性病
     * @return 结果
     */
    @Override
    public int updateHealthChronic(HealthChronic healthChronic) {
        healthChronic.setUpdateTime(DateUtils.getNowDate());
        healthChronic.setUpdateBy(SecurityUtils.getUsername());
        try {
            return healthChronicMapper.updateHealthChronic(healthChronic);
        } catch (Exception e) {
            throw new ServiceException("更新错误, " + e.getMessage());
        }
    }

    /**
     * 批量删除慢性病
     * 
     * @param ids 需要删除的慢性病主键
     * @return 结果
     */
    @Override
    public int deleteHealthChronicByIds(Long[] ids) {
        return healthChronicMapper.deleteHealthChronicByIds(ids);
    }

    /**
     * 删除慢性病信息
     * 
     * @param id 慢性病主键
     * @return 结果
     */
    @Override
    public int deleteHealthChronicById(Long id) {
        return healthChronicMapper.deleteHealthChronicById(id);
    }
}
