[add]支持其他平台通过ApiKey调用系统相关接口
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.genersoft.iot.vmp.storager.dao.dto.UserApiKey;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
public interface IUserApiKeyService {
|
||||
int addApiKey(UserApiKey userApiKey);
|
||||
|
||||
boolean isApiKeyExists(String apiKey);
|
||||
|
||||
PageInfo<UserApiKey> getUserApiKeys(int page, int count);
|
||||
|
||||
int enable(Integer id);
|
||||
|
||||
int disable(Integer id);
|
||||
|
||||
int remark(Integer id, String remark);
|
||||
|
||||
int delete(Integer id);
|
||||
|
||||
UserApiKey getUserApiKeyById(Integer id);
|
||||
|
||||
int reset(Integer id, String apiKey);
|
||||
|
||||
}
|
||||
@@ -11,6 +11,8 @@ public interface IUserService {
|
||||
|
||||
boolean changePassword(int id, String password);
|
||||
|
||||
User getUserById(int id);
|
||||
|
||||
User getUserByUsername(String username);
|
||||
|
||||
int addUser(User user);
|
||||
|
||||
@@ -0,0 +1,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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,6 +31,11 @@ public class UserServiceImpl implements IUserService {
|
||||
return userMapper.update(user) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserById(int id) {
|
||||
return userMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserByUsername(String username) {
|
||||
return userMapper.getUserByUsername(username);
|
||||
|
||||
Reference in New Issue
Block a user