mirror of
https://github.com/thousmile/molly-multi-tenant.git
synced 2025-12-30 04:32:26 +00:00
1.更新 字段数据页面
2.添加 JsonUtils.isJsonValid()
This commit is contained in:
@@ -105,6 +105,35 @@ public class JsonUtils {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断 string 是否为json
|
||||
*
|
||||
* @param jsonStr
|
||||
* @return boolean
|
||||
* @author Wang Chen Chen <932560435@qq.com>
|
||||
* @date 2023/11/03 15:26
|
||||
*/
|
||||
public static boolean isJsonValid(String jsonStr) {
|
||||
var stringObjectMap = toMap(jsonStr, String.class, Object.class);
|
||||
return stringObjectMap != null && !stringObjectMap.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断 string 是否为json
|
||||
*
|
||||
* @param jsonBytes
|
||||
* @return boolean
|
||||
* @author Wang Chen Chen <932560435@qq.com>
|
||||
* @date 2023/11/03 15:26
|
||||
*/
|
||||
public static boolean isJsonValid(byte[] jsonBytes) {
|
||||
var stringObjectMap = toMap(jsonBytes, String.class, Object.class);
|
||||
return stringObjectMap != null && !stringObjectMap.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将对象转换成 二进制
|
||||
*
|
||||
@@ -119,7 +148,7 @@ public class JsonUtils {
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -132,9 +161,9 @@ public class JsonUtils {
|
||||
* @author Wang Chen Chen <932560435@qq.com>
|
||||
* @date 2019/4/18 15:26
|
||||
*/
|
||||
public static <T> T toPojo(String jsonData, Class<T> beanType) {
|
||||
public static <T> T toPojo(String jsonStr, Class<T> beanType) {
|
||||
try {
|
||||
return MAPPER.readValue(jsonData, beanType);
|
||||
return MAPPER.readValue(jsonStr, beanType);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
@@ -151,87 +180,89 @@ public class JsonUtils {
|
||||
* @author Wang Chen Chen <932560435@qq.com>
|
||||
* @date 2019/4/18 15:26
|
||||
*/
|
||||
public static <T> T toPojo(byte[] src, Class<T> beanType) {
|
||||
public static <T> T toPojo(byte[] jsonBytes, Class<T> beanType) {
|
||||
try {
|
||||
return MAPPER.readValue(src, beanType);
|
||||
return MAPPER.readValue(jsonBytes, beanType);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将json数据转换成pojo对象list
|
||||
*
|
||||
* @param jsonData
|
||||
* @param jsonStr
|
||||
* @param beanType
|
||||
* @return java.util.List<T>
|
||||
* @author Wang Chen Chen <932560435@qq.com>
|
||||
* @date 2019/4/18 15:26
|
||||
*/
|
||||
public static <T> List<T> toListPojo(String jsonData, Class<T> beanType) {
|
||||
public static <T> List<T> toListPojo(String jsonStr, Class<T> beanType) {
|
||||
try {
|
||||
return MAPPER.readValue(jsonData, MAPPER.getTypeFactory().constructCollectionType(ArrayList.class, beanType));
|
||||
return MAPPER.readValue(jsonStr, MAPPER.getTypeFactory().constructCollectionType(ArrayList.class, beanType));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将json数据转换成 Map
|
||||
*
|
||||
* @param jsonData
|
||||
* @param jsonBytes
|
||||
* @param keyType
|
||||
* @param valueType
|
||||
* @return java.util.List<T>
|
||||
* @author Wang Chen Chen <932560435@qq.com>
|
||||
* @date 2019/4/18 15:26
|
||||
*/
|
||||
public static <K, V> Map<K, V> toMap(byte[] src, Class<K> keyType, Class<V> valueType) {
|
||||
public static <K, V> Map<K, V> toMap(byte[] jsonBytes, Class<K> keyType, Class<V> valueType) {
|
||||
try {
|
||||
return MAPPER.readValue(src, MAPPER.getTypeFactory().constructMapType(HashMap.class, keyType, valueType));
|
||||
return MAPPER.readValue(jsonBytes, MAPPER.getTypeFactory().constructMapType(HashMap.class, keyType, valueType));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将json数据转换成 Map
|
||||
*
|
||||
* @param jsonData
|
||||
* @param jsonStr
|
||||
* @param keyType
|
||||
* @param valueType
|
||||
* @return java.util.List<T>
|
||||
* @author Wang Chen Chen <932560435@qq.com>
|
||||
* @date 2019/4/18 15:26
|
||||
*/
|
||||
public static <K, V> Map<K, V> toMap(String jsonData, Class<K> keyType, Class<V> valueType) {
|
||||
public static <K, V> Map<K, V> toMap(String jsonStr, Class<K> keyType, Class<V> valueType) {
|
||||
try {
|
||||
return MAPPER.readValue(jsonData, MAPPER.getTypeFactory().constructMapType(HashMap.class, keyType, valueType));
|
||||
return MAPPER.readValue(jsonStr, MAPPER.getTypeFactory().constructMapType(HashMap.class, keyType, valueType));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将json数据转换成pojo对象list
|
||||
*
|
||||
* @param jsonData
|
||||
* @param jsonStr
|
||||
* @param keyType
|
||||
* @param valueType
|
||||
* @return java.util.List<T>
|
||||
* @author Wang Chen Chen <932560435@qq.com>
|
||||
* @date 2019/4/18 15:26
|
||||
*/
|
||||
public static <K, V> List<Map<K, V>> toListMap(String jsonData, Class<K> keyType, Class<V> valueType) {
|
||||
public static <K, V> List<Map<K, V>> toListMap(String jsonStr, Class<K> keyType, Class<V> valueType) {
|
||||
try {
|
||||
return MAPPER.readValue(
|
||||
jsonData,
|
||||
jsonStr,
|
||||
MAPPER.getTypeFactory().constructCollectionType(List.class,
|
||||
MAPPER.getTypeFactory().constructMapType(HashMap.class, keyType, valueType)
|
||||
)
|
||||
@@ -239,29 +270,7 @@ public class JsonUtils {
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断字符串是否为 json
|
||||
*
|
||||
* @param str
|
||||
* @return java.util.List<T>
|
||||
* @author Wang Chen Chen <932560435@qq.com>
|
||||
* @date 2019/4/18 15:26
|
||||
*/
|
||||
public static boolean isJson(String str) {
|
||||
boolean result = false;
|
||||
if (StringUtils.isNotBlank(str)) {
|
||||
str = str.trim();
|
||||
if (str.startsWith("{") && str.endsWith("}")) {
|
||||
result = true;
|
||||
} else if (str.startsWith("[") && str.endsWith("]")) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ spring:
|
||||
# 多租户配置
|
||||
multi:
|
||||
tenant:
|
||||
create-table: true
|
||||
master-change-log: classpath:db/changelog-master.xml
|
||||
other-change-log: classpath:db/changelog-other.xml
|
||||
prefix: molly_
|
||||
@@ -35,6 +34,7 @@ multi:
|
||||
db-name: ${multi.tenant.prefix}${multi.tenant.default-tenant-id}
|
||||
enable: true
|
||||
enable-project: true
|
||||
create-table: true
|
||||
|
||||
|
||||
# mybatis-plus 自动配置
|
||||
|
||||
@@ -77,4 +77,5 @@ public class MollyApplicationTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@ import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNode;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
import com.xaaef.molly.auth.jwt.JwtSecurityUtils;
|
||||
import com.xaaef.molly.common.util.JsonUtils;
|
||||
import liquibase.integration.spring.MultiTenantSpringLiquibase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.io.FileSystemResourceLoader;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
@@ -87,4 +90,19 @@ public class NoSpringTests {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test10() throws Exception {
|
||||
var ds1 = new MysqlDataSource();
|
||||
ds1.setURL("jdbc:mysql://192.168.0.188:3306/hello1?characterEncoding=utf8&useSSL=false");
|
||||
ds1.setUser("test123");
|
||||
ds1.setPassword("mht123456");
|
||||
var liquibase1 = new MultiTenantSpringLiquibase();
|
||||
liquibase1.setDataSource(ds1);
|
||||
liquibase1.setResourceLoader(new FileSystemResourceLoader());
|
||||
liquibase1.setChangeLog("C:\\Users\\demo\\code\\javaProjects\\molly-multi-tenant\\server\\molly-service\\src\\main\\resources\\db\\changelog-other.xml");
|
||||
liquibase1.setSchemas(List.of("hello1", "hello2", "hello3"));
|
||||
liquibase1.afterPropertiesSet();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -85,9 +85,9 @@ public class SysMenu extends BaseEntity {
|
||||
private Byte target;
|
||||
|
||||
/**
|
||||
* 菜单类型(0.菜单 1.按钮)
|
||||
* 菜单类型(0.菜单 1.按钮 2.外链)
|
||||
*/
|
||||
@Schema(description = "菜单类型(0.菜单 1.按钮)")
|
||||
@Schema(description = "菜单类型(0.菜单 1.按钮 2.外链)")
|
||||
private Byte menuType;
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,7 +51,10 @@ public class TenantTableRunner implements ApplicationRunner {
|
||||
if (props.getEnable()) {
|
||||
log.info("Execute TenantTableRunner run() ...");
|
||||
log.info("ignore tenant_id intercept table name : \n{}", JsonUtils.toJson(MbpConst.TENANT_IGNORE_TABLES));
|
||||
// 获取默认租户Id
|
||||
var defaultTenantId = props.getDefaultTenantId();
|
||||
// 是否创建表结构
|
||||
var createTable = props.getCreateTable();
|
||||
var count = tenantMapper.selectCount(null);
|
||||
var pageSize = 100;
|
||||
var pageCount = (count / pageSize) + 1;
|
||||
@@ -66,7 +69,9 @@ public class TenantTableRunner implements ApplicationRunner {
|
||||
.filter(tenantId -> !StringUtils.equals(tenantId, defaultTenantId))
|
||||
.forEach(tenantId -> {
|
||||
tenantManager.addTenantId(tenantId);
|
||||
databaseManager.updateTable(tenantId);
|
||||
if (createTable) {
|
||||
databaseManager.updateTable(tenantId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,18 @@ interface SelectOption {
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
/** 接口响应格式 */
|
||||
interface ApiData {
|
||||
code: number
|
||||
data: SelectOption[]
|
||||
message: string
|
||||
}
|
||||
|
||||
/** 入参格式,暂时只需要传递 api 函数即可 */
|
||||
interface FetchSelectProps {
|
||||
api: () => Promise<ApiData>
|
||||
api: () => Promise<IJsonResult<SelectOption[]>>
|
||||
}
|
||||
|
||||
export function useFetchSelect(props: FetchSelectProps) {
|
||||
const { api } = props
|
||||
|
||||
const loading = ref<boolean>(false)
|
||||
|
||||
const options = ref<SelectOption[]>([])
|
||||
|
||||
const value = ref<OptionValue>("")
|
||||
|
||||
/** 调用接口获取数据 */
|
||||
@@ -33,8 +28,11 @@ export function useFetchSelect(props: FetchSelectProps) {
|
||||
loading.value = true
|
||||
options.value = []
|
||||
api()
|
||||
.then((res) => {
|
||||
options.value = res.data
|
||||
.then((resp) => {
|
||||
const { status, data } = resp
|
||||
if (status === 200) {
|
||||
options.value = data
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false
|
||||
|
||||
@@ -61,7 +61,7 @@ export const constantRoutes: RouteRecordRaw[] = [
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/personal",
|
||||
path: "personal",
|
||||
component: () => import("@/views/personal/index.vue"),
|
||||
name: "Personal",
|
||||
meta: {
|
||||
|
||||
@@ -135,7 +135,8 @@ const params = reactive({
|
||||
pageIndex: 1,
|
||||
pageSize: 10,
|
||||
keywords: "",
|
||||
dictTypeKey: typeKey
|
||||
dictTypeKey: typeKey,
|
||||
includeCauu: true
|
||||
})
|
||||
|
||||
/// 表单数据
|
||||
@@ -160,13 +161,7 @@ const entityFormRules: FormRules = {
|
||||
// 获取数据
|
||||
const getTableData = () => {
|
||||
loading.value = true
|
||||
const p: ISearchQuery = {
|
||||
pageIndex: params.pageIndex,
|
||||
pageSize: params.pageSize,
|
||||
keywords: params.keywords,
|
||||
includeCauu: true
|
||||
}
|
||||
queryDictDataApi(p)
|
||||
queryDictDataApi(params)
|
||||
.then((resp) => {
|
||||
tableData.value = resp.data.list
|
||||
params.pageTotal = resp.data.total
|
||||
|
||||
Reference in New Issue
Block a user