package org.dromara.system.service.impl;

import lombok.RequiredArgsConstructor;
import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.core.utils.MapstructUtils;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.dromara.system.domain.SysPhone;
import org.dromara.system.domain.bo.SysPhoneBo;
import org.dromara.system.domain.vo.SysPhoneVo;
import org.dromara.system.mapper.SysPhoneMapper;
import org.dromara.system.service.ISysPhoneService;
import org.springframework.stereotype.Service;

/**
 * 联系电话 Service 业务层处理
 *
 * @author Antigravity
 */
@RequiredArgsConstructor
@Service
public class SysPhoneServiceImpl implements ISysPhoneService {

    private final SysPhoneMapper baseMapper;

    /**
     * 根据ID查询联系电话（走缓存）
     */
    @Cacheable(cacheNames = CacheNames.SYS_PHONE, key = "#id")
    @Override
    public SysPhoneVo queryById(Long id) {
        return baseMapper.selectVoById(id);
    }

    /**
     * 修改联系电话，刷新缓存并返回最新 VO
     */
    @CachePut(cacheNames = CacheNames.SYS_PHONE, key = "#bo.id")
    @Override
    public SysPhoneVo updateByBo(SysPhoneBo bo) {
        SysPhone update = MapstructUtils.convert(bo, SysPhone.class);
        baseMapper.updateById(update);
        return baseMapper.selectVoById(bo.getId());
    }

}
