leesam
2024-03-19 76208975bffec39eb62f8599a68d583a5cb6da18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.genersoft.iot.vmp.service.impl;
 
import com.baomidou.dynamic.datasource.annotation.DS;
import com.genersoft.iot.vmp.service.IUserApiKeyService;
import com.genersoft.iot.vmp.storager.dao.UserApiKeyMapper;
import com.genersoft.iot.vmp.storager.dao.dto.UserApiKey;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
@Service
@DS("master")
public class UserApiKeyServiceImpl implements IUserApiKeyService {
 
    @Autowired
    UserApiKeyMapper userApiKeyMapper;
 
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;
 
    @Override
    public int addApiKey(UserApiKey userApiKey) {
        return userApiKeyMapper.add(userApiKey);
    }
 
    @Override
    public boolean isApiKeyExists(String apiKey) {
        return userApiKeyMapper.isApiKeyExists(apiKey);
    }
 
    @Override
    public PageInfo<UserApiKey> getUserApiKeys(int page, int count) {
        PageHelper.startPage(page, count);
        List<UserApiKey> userApiKeys = userApiKeyMapper.getUserApiKeys();
        return new PageInfo<>(userApiKeys);
    }
 
    @Cacheable(cacheNames = "userApiKey", key = "#id", sync = true)
    @Override
    public UserApiKey getUserApiKeyById(Integer id) {
        return userApiKeyMapper.selectById(id);
    }
 
    @CacheEvict(cacheNames = "userApiKey", key = "#id")
    @Override
    public int enable(Integer id) {
        return userApiKeyMapper.enable(id);
    }
 
    @CacheEvict(cacheNames = "userApiKey", key = "#id")
    @Override
    public int disable(Integer id) {
        return userApiKeyMapper.disable(id);
    }
 
    @CacheEvict(cacheNames = "userApiKey", key = "#id")
    @Override
    public int remark(Integer id, String remark) {
        return userApiKeyMapper.remark(id, remark);
    }
 
    @CacheEvict(cacheNames = "userApiKey", key = "#id")
    @Override
    public int delete(Integer id) {
        return userApiKeyMapper.delete(id);
    }
 
    @CacheEvict(cacheNames = "userApiKey", key = "#id")
    @Override
    public int reset(Integer id, String apiKey) {
        return userApiKeyMapper.apiKey(id, apiKey);
    }
 
}