add
This commit is contained in:
@ -17,7 +17,6 @@
|
||||
<module>qiaoba-common-web</module>
|
||||
<module>qiaoba-common-doc</module>
|
||||
<module>qiaoba-common-redis</module>
|
||||
<module>qiaoba-common-security</module>
|
||||
<module>qiaoba-common-poi</module>
|
||||
</modules>
|
||||
|
||||
|
@ -16,5 +16,9 @@
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.qiaoba.common.database.utils;
|
||||
package com.qiaoba.common.base.utils;
|
||||
|
||||
/**
|
||||
* 租户工具类
|
@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
|
||||
import com.qiaoba.common.database.utils.TenantUtil;
|
||||
import com.qiaoba.common.base.utils.TenantUtil;
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
import net.sf.jsqlparser.expression.StringValue;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -1,14 +1,10 @@
|
||||
package com.qiaoba.common.database.entity;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分页查询实体类
|
||||
@ -31,16 +27,6 @@ public class PageQuery implements Serializable {
|
||||
*/
|
||||
private Integer pageNum;
|
||||
|
||||
/**
|
||||
* 排序列
|
||||
*/
|
||||
private String orderByColumn;
|
||||
|
||||
/**
|
||||
* 排序的方向desc或者asc
|
||||
*/
|
||||
private String isAsc;
|
||||
|
||||
/**
|
||||
* 当前记录起始索引 默认值
|
||||
*/
|
||||
@ -57,12 +43,7 @@ public class PageQuery implements Serializable {
|
||||
if (pageNum <= 0) {
|
||||
pageNum = DEFAULT_PAGE_NUM;
|
||||
}
|
||||
Page<T> page = new Page<>(pageNum, pageSize);
|
||||
/* List<OrderItem> orderItems = buildOrderItem();
|
||||
if (CollUtil.isNotEmpty(orderItems)) {
|
||||
page.addOrder(orderItems);
|
||||
}*/
|
||||
return page;
|
||||
return new Page<>(pageNum, pageSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,14 +2,13 @@ package com.qiaoba.common.database.filters;
|
||||
|
||||
import com.qiaoba.common.database.config.DynamicDataSourceContext;
|
||||
import com.qiaoba.common.database.constants.DynamicDatasourceConstant;
|
||||
import com.qiaoba.common.database.utils.TenantUtil;
|
||||
import com.qiaoba.common.base.utils.TenantUtil;
|
||||
import com.qiaoba.common.web.utils.ResponseUtil;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.qiaoba.common.database.factories.DynamicDataSourceFactory,\
|
||||
com.qiaoba.common.database.config.MybatisPlusConfig
|
||||
|
||||
|
||||
|
@ -17,10 +17,14 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-common-base</artifactId>
|
||||
</dependency>
|
||||
<!-- Jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
</project>
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.qiaoba.common.redis.service.impl;
|
||||
|
||||
|
||||
import com.qiaoba.common.base.utils.TenantUtil;
|
||||
import com.qiaoba.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -20,33 +21,34 @@ import java.util.concurrent.TimeUnit;
|
||||
* @since 2021/10/2 0003 下午 17:44
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class RedisServiceImpl implements RedisService {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
private final RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Override
|
||||
public void set(String key, Object value, long time) {
|
||||
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
|
||||
redisTemplate.opsForValue().set(handleKey(key), value, time, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(String key, Object value) {
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
redisTemplate.opsForValue().set(handleKey(key), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String key) {
|
||||
return redisTemplate.opsForValue().get(key);
|
||||
return redisTemplate.opsForValue().get(handleKey(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean del(String key) {
|
||||
return redisTemplate.delete(key);
|
||||
return redisTemplate.delete(handleKey(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void del(Collection<String> collection) {
|
||||
// todo
|
||||
redisTemplate.delete(collection);
|
||||
}
|
||||
|
||||
@ -57,168 +59,178 @@ public class RedisServiceImpl implements RedisService {
|
||||
|
||||
@Override
|
||||
public Long getExpire(String key) {
|
||||
return redisTemplate.getExpire(key, TimeUnit.SECONDS);
|
||||
return redisTemplate.getExpire(handleKey(key), TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean hasKey(String key) {
|
||||
return redisTemplate.hasKey(key);
|
||||
return redisTemplate.hasKey(handleKey(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long incr(String key, long delta) {
|
||||
return redisTemplate.opsForValue().increment(key, delta);
|
||||
return redisTemplate.opsForValue().increment(handleKey(key), delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long decr(String key, long delta) {
|
||||
return redisTemplate.opsForValue().increment(key, -delta);
|
||||
return redisTemplate.opsForValue().increment(handleKey(key), -delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object hGet(String key, String hashKey) {
|
||||
return redisTemplate.opsForHash().get(key, hashKey);
|
||||
return redisTemplate.opsForHash().get(handleKey(key), hashKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean hSet(String key, String hashKey, Object value, long time) {
|
||||
redisTemplate.opsForHash().put(key, hashKey, value);
|
||||
return expire(key, time);
|
||||
String newKey = handleKey(key);
|
||||
redisTemplate.opsForHash().put(newKey, hashKey, value);
|
||||
return expire(newKey, time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hSet(String key, String hashKey, Object value) {
|
||||
redisTemplate.opsForHash().put(key, hashKey, value);
|
||||
redisTemplate.opsForHash().put(handleKey(key), hashKey, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Object, Object> hGetAll(String key) {
|
||||
return redisTemplate.opsForHash().entries(key);
|
||||
return redisTemplate.opsForHash().entries(handleKey(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean hSetAll(String key, Map<String, Object> map, long time) {
|
||||
redisTemplate.opsForHash().putAll(key, map);
|
||||
return expire(key, time);
|
||||
String newKey = handleKey(key);
|
||||
redisTemplate.opsForHash().putAll(newKey, map);
|
||||
return expire(newKey, time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hSetAll(String key, Map<String, ?> map) {
|
||||
redisTemplate.opsForHash().putAll(key, map);
|
||||
redisTemplate.opsForHash().putAll(handleKey(key), map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hDel(String key, Object... hashKey) {
|
||||
redisTemplate.opsForHash().delete(key, hashKey);
|
||||
redisTemplate.opsForHash().delete(handleKey(key), hashKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean hHasKey(String key, String hashKey) {
|
||||
return redisTemplate.opsForHash().hasKey(key, hashKey);
|
||||
return redisTemplate.opsForHash().hasKey(handleKey(key), hashKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long hIncr(String key, String hashKey, Long delta) {
|
||||
return redisTemplate.opsForHash().increment(key, hashKey, delta);
|
||||
return redisTemplate.opsForHash().increment(handleKey(key), hashKey, delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long hDecr(String key, String hashKey, Long delta) {
|
||||
return redisTemplate.opsForHash().increment(key, hashKey, -delta);
|
||||
return redisTemplate.opsForHash().increment(handleKey(key), hashKey, -delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Object> sMembers(String key) {
|
||||
return redisTemplate.opsForSet().members(key);
|
||||
return redisTemplate.opsForSet().members(handleKey(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long sAdd(String key, Object... values) {
|
||||
return redisTemplate.opsForSet().add(key, values);
|
||||
return redisTemplate.opsForSet().add(handleKey(key), values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long sAdd(String key, long time, Object... values) {
|
||||
Long count = redisTemplate.opsForSet().add(key, values);
|
||||
expire(key, time);
|
||||
String newKey = handleKey(key);
|
||||
Long count = redisTemplate.opsForSet().add(newKey, values);
|
||||
expire(newKey, time);
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean sIsMember(String key, Object value) {
|
||||
return redisTemplate.opsForSet().isMember(key, value);
|
||||
return redisTemplate.opsForSet().isMember(handleKey(key), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long sSize(String key) {
|
||||
return redisTemplate.opsForSet().size(key);
|
||||
return redisTemplate.opsForSet().size(handleKey(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long sRemove(String key, Object... values) {
|
||||
return redisTemplate.opsForSet().remove(key, values);
|
||||
return redisTemplate.opsForSet().remove(handleKey(key), values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> lRange(String key, long start, long end) {
|
||||
return redisTemplate.opsForList().range(key, start, end);
|
||||
return redisTemplate.opsForList().range(handleKey(key), start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long lSize(String key) {
|
||||
return redisTemplate.opsForList().size(key);
|
||||
return redisTemplate.opsForList().size(handleKey(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object lIndex(String key, long index) {
|
||||
return redisTemplate.opsForList().index(key, index);
|
||||
return redisTemplate.opsForList().index(handleKey(key), index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long lPush(String key, Object value) {
|
||||
return redisTemplate.opsForList().rightPush(key, value);
|
||||
return redisTemplate.opsForList().rightPush(handleKey(key), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long lPush(String key, Object value, long time) {
|
||||
Long index = redisTemplate.opsForList().rightPush(key, value);
|
||||
expire(key, time);
|
||||
String newKey = handleKey(key);
|
||||
Long index = redisTemplate.opsForList().rightPush(newKey, value);
|
||||
expire(newKey, time);
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long lPushAll(String key, Object... values) {
|
||||
return redisTemplate.opsForList().rightPushAll(key, values);
|
||||
return redisTemplate.opsForList().rightPushAll(handleKey(key), values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long lPushAll(String key, Long time, Object... values) {
|
||||
Long count = redisTemplate.opsForList().rightPushAll(key, values);
|
||||
expire(key, time);
|
||||
String newKey = handleKey(key);
|
||||
Long count = redisTemplate.opsForList().rightPushAll(newKey, values);
|
||||
expire(newKey, time);
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long lRemove(String key, long count, Object value) {
|
||||
return redisTemplate.opsForList().remove(key, count, value);
|
||||
return redisTemplate.opsForList().remove(handleKey(key), count, value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<String> getKeys(String key) {
|
||||
return redisTemplate.keys(key);
|
||||
return redisTemplate.keys(handleKey(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getObject(String key, Class<T> clazz) {
|
||||
return (T) get(key);
|
||||
return (T) get(handleKey(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> getObjectList(String key, Class<T> clazz) {
|
||||
return (List<T>) get(key);
|
||||
return (List<T>) get(handleKey(key));
|
||||
}
|
||||
|
||||
private String handleKey(String key) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("tenant_").append(TenantUtil.getTenantId()).append(":").append(key);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>qiaoba-commons</artifactId>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>qiaoba-common-security</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-common-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,30 +0,0 @@
|
||||
package com.qiaoba.common.security.utils;
|
||||
|
||||
/**
|
||||
* SecurityUtil
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/9 9:22
|
||||
*/
|
||||
public class SecurityUtil {
|
||||
|
||||
/**
|
||||
* 获取登录用户的账号
|
||||
*
|
||||
* @return username
|
||||
*/
|
||||
public static String getLoginUsername() {
|
||||
return "admin";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录用户的ID
|
||||
*
|
||||
* @return username
|
||||
*/
|
||||
public static String getLoginUserId() {
|
||||
return "1L";
|
||||
}
|
||||
|
||||
}
|
@ -3,10 +3,14 @@ package com.qiaoba.common.web.advice;
|
||||
|
||||
import com.qiaoba.common.base.exceptions.ServiceException;
|
||||
import com.qiaoba.common.base.result.AjaxResult;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 全局异常处理
|
||||
*
|
||||
@ -38,8 +42,31 @@ public class ExceptionAdvice {
|
||||
*/
|
||||
@ExceptionHandler(ServiceException.class)
|
||||
@ResponseBody
|
||||
public AjaxResult handlerApiException(ServiceException e) {
|
||||
public AjaxResult handlerServiceException(ServiceException e) {
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验
|
||||
*
|
||||
* @param e MethodArgumentNotValidException
|
||||
* @return AjaxResult
|
||||
*/
|
||||
@ExceptionHandler({MethodArgumentNotValidException.class})
|
||||
@ResponseBody
|
||||
public AjaxResult handlerValidException(MethodArgumentNotValidException e) {
|
||||
return AjaxResult.error(Objects.isNull(e.getBindingResult().getFieldError()) ? e.getMessage() : e.getBindingResult().getFieldError().getDefaultMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验
|
||||
*
|
||||
* @param e BindException
|
||||
* @return AjaxResult
|
||||
*/
|
||||
@ExceptionHandler({BindException.class})
|
||||
@ResponseBody
|
||||
public AjaxResult handlerValidException(BindException e) {
|
||||
return AjaxResult.error(Objects.isNull(e.getBindingResult().getFieldError()) ? e.getMessage() : e.getBindingResult().getFieldError().getDefaultMessage());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user