
package com.tmerclub.cloud.user.service.impl;

import com.tmerclub.cloud.common.cache.constant.UserCacheNames;
import com.tmerclub.cloud.user.mapper.UserConsigneeMapper;
import com.tmerclub.cloud.user.model.UserConsignee;
import com.tmerclub.cloud.user.service.UserConsigneeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * 用户提货人信息
 *
 * @author tmerclub
 * @date 2020-12-15 17:18:56
 */
@Service
public class UserConsigneeServiceImpl implements UserConsigneeService {

    @Autowired
    private UserConsigneeMapper userConsigneeMapper;

    @Override
    @Cacheable(cacheNames = UserCacheNames.USER_DEFAULT_CONSIGNEE, key = "#userId")
    public UserConsignee getByUserId(Long userId) {
        return userConsigneeMapper.getByUserId(userId);
    }

    @Override
    @CacheEvict(cacheNames = UserCacheNames.USER_DEFAULT_CONSIGNEE, key = "#userConsignee.userId")
    public void save(UserConsignee userConsignee) {
        userConsigneeMapper.save(userConsignee);
    }

    @Override
    @CacheEvict(cacheNames = UserCacheNames.USER_DEFAULT_CONSIGNEE, key = "#userConsignee.userId")
    public void update(UserConsignee userConsignee) {
        userConsigneeMapper.update(userConsignee);
    }

    @Override
    public void deleteByUserId(Long userId) {
        userConsigneeMapper.deleteByUserId(userId);
    }
}
