fix:项目初始化优化

V0.5.x
xiwa 2023-07-09 15:15:50 +08:00
parent c7906551ae
commit eae8dba660
2 changed files with 8 additions and 8 deletions

View File

@ -9,10 +9,10 @@
*/
package cc.iotkit.data.dao;
import cc.iotkit.data.model.TbSysDept;
import cc.iotkit.data.model.TbSysTenant;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
public interface SysTenantRepository extends JpaRepository<TbSysDept, Long>, QuerydslPredicateExecutor<TbSysDept> {
public interface SysTenantRepository extends JpaRepository<TbSysTenant, Long>, QuerydslPredicateExecutor<TbSysTenant> {
}

View File

@ -39,6 +39,7 @@ import cc.iotkit.temporal.IDbStructureData;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.hibernate.exception.DataException;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@ -264,18 +265,13 @@ public class ExampleDataInit implements SmartInitializingSingleton {
initData("sys_role", sysRoleData, new TypeReference<List<SysRole>>() {
});
initData("sys_dept", sysDeptData, new TypeReference<List<SysDept>>() {
});
initData("sys_role_dept", sysRoleDeptData, new TypeReference<List<SysRoleDept>>() {
});
initData("sys_role_menu", sysRoleMenuData, new TypeReference<List<SysRoleMenu>>() {
});
initData("sys_tenant",sysTenantData , new TypeReference<List<SysTenant>>() {
initData("sys_tenant", sysTenantData, new TypeReference<List<SysTenant>>() {
});
initData("sys_tenant_package", sysTenantPackageData, new TypeReference<List<SysTenantPackage>>() {
@ -293,6 +289,10 @@ public class ExampleDataInit implements SmartInitializingSingleton {
private <T> T initData(String name, ICommonData service, TypeReference<T> type) throws IOException {
log.info("init {} data...", name);
if (service.count() > 0) {
new RuntimeException("原数据库已存在" + name + "的旧数据,请清除后再重新初始化!").printStackTrace();
System.exit(0);
}
String json = FileUtils.readFileToString(new File("./data/init/" + name + ".json"), StandardCharsets.UTF_8);
List list = (List) JsonUtils.parseObject(json, type);
for (Object obj : list) {