删除只建表的Startup类,由CommonStartup类统一执行

This commit is contained in:
WenG 2021-06-14 22:43:02 +08:00
parent e24a2b02e8
commit b4ff18d8dc
16 changed files with 103 additions and 497 deletions

View File

@ -0,0 +1,67 @@
package ink.wgink.common.component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: SpringBeanUtil
* @Description: Spring工具类
* @Author: WangGeng
* @Date: 2021/6/14 22:16
* @Version: 1.0
**/
@Component
public class SpringBeanUtil implements ApplicationContextAware {
protected final static Logger logger = LoggerFactory.getLogger(SpringBeanUtil.class);
private static ApplicationContext ctx = null;
private static Map<String, Properties> propMap = new HashMap<>(0);
@Override
public void setApplicationContext(ApplicationContext ctx) throws BeansException {
SpringBeanUtil.ctx = ctx;
}
public ApplicationContext getApplicationContext() {
return ctx;
}
public <T> T getBean(String prop) {
Object obj = ctx.getBean(prop);
if (logger.isDebugEnabled()) {
logger.debug("property=[" + prop + "],object=[" + obj + "]");
}
return (T) obj;
}
public Properties getProperties(String filepath) {
if (propMap.containsKey(filepath)) {
return propMap.get(filepath);
}
Resource resource = ctx.getResource(filepath);
Properties prop = new Properties();
try {
prop.load(resource.getInputStream());
propMap.put(filepath, prop);
return prop;
} catch (IOException e) {
logger.error("can not find the resource file:[" + filepath + "]", e);
return null;
}
}
}

View File

@ -0,0 +1,35 @@
package ink.wgink.common.startup;
import ink.wgink.interfaces.init.IInitBaseTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: CommonStartup
* @Description: 启动
* @Author: WangGeng
* @Date: 2021/6/14 22:14
* @Version: 1.0
**/
@Component
public class CommonStartup implements ApplicationRunner {
@Autowired
private ApplicationContext applicationContext;
@Override
public void run(ApplicationArguments args) throws Exception {
Map<String, IInitBaseTable> initBaseTableMap = applicationContext.getBeansOfType(IInitBaseTable.class);
for (Map.Entry<String, IInitBaseTable> kv : initBaseTableMap.entrySet()) {
kv.getValue().createTable();
}
}
}

View File

@ -1,47 +0,0 @@
package ink.wgink.login.app.startup;
import ink.wgink.login.app.dao.appdeviceuser.IAppDeviceUserDao;
import ink.wgink.login.app.dao.appversion.IAppVersionDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: LoginAppStartUp
* @Description: app登录
* @Author: wanggeng
* @Date: 2021/4/7 7:00 下午
* @Version: 1.0
*/
@Component
public class LoginAppStartUp implements ApplicationRunner {
private static final Logger LOG = LoggerFactory.getLogger(LoginAppStartUp.class);
@Autowired
private IAppVersionDao appVersionDao;
@Autowired
private IAppDeviceUserDao appDeviceUserDao;
@Override
public void run(ApplicationArguments args) throws Exception {
initTable();
}
/**
* 建表
*/
private void initTable() {
LOG.debug("创建 app_version 表");
appVersionDao.createTable();
LOG.debug("创建 app_device_user 表");
appDeviceUserDao.createTable();
}
}

View File

@ -1,7 +1,6 @@
package ink.wgink.login.base.startup; package ink.wgink.login.base.startup;
import ink.wgink.login.base.dao.config.IConfigDao; import ink.wgink.login.base.dao.config.IConfigDao;
import ink.wgink.login.base.dao.log.ILoginLogDao;
import ink.wgink.login.base.manager.ConfigManager; import ink.wgink.login.base.manager.ConfigManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -27,28 +26,13 @@ public class LoginBaseStartUp implements ApplicationRunner {
@Autowired @Autowired
private IConfigDao configDao; private IConfigDao configDao;
@Autowired
private ILoginLogDao loginLogDao;
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
initTable();
LOG.debug("初始化配置"); LOG.debug("初始化配置");
ConfigManager configManager = ConfigManager.getInstance(); ConfigManager configManager = ConfigManager.getInstance();
configManager.setConfigDao(configDao); configManager.setConfigDao(configDao);
} }
/**
* 建表
*/
private void initTable() {
LOG.debug("创建 sys_config 表");
configDao.createTable();
LOG.debug("创建 log_login_log 表");
loginLogDao.createTable();
}
} }

View File

@ -1,43 +0,0 @@
package ink.wgink.module.article.startup;
import ink.wgink.module.article.dao.category.ICategoryDao;
import ink.wgink.module.article.dao.content.IContentDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: ArticleStartUp
* @Description: 文章模块启动
* @Author: wanggeng
* @Date: 2021/4/14 9:20 下午
* @Version: 1.0
*/
@Component
public class ArticleStartUp implements ApplicationRunner {
private static final Logger LOG = LoggerFactory.getLogger(ArticleStartUp.class);
@Autowired
private ICategoryDao categoryDao;
@Autowired
private IContentDao contentDao;
@Override
public void run(ApplicationArguments args) throws Exception {
initTable();
}
private void initTable() {
LOG.debug("创建 article_category 表");
categoryDao.createTable();
LOG.debug("创建 article_content 表");
contentDao.createTable();
}
}

View File

@ -1,45 +0,0 @@
package ink.wgink.module.dictionary.startup;
import ink.wgink.module.dictionary.dao.IAreaDao;
import ink.wgink.module.dictionary.dao.IDataDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: ModuleDictionaryStartUp
* @Description: 字典模块启动
* @Author: wanggeng
* @Date: 2021/2/11 9:41 下午
* @Version: 1.0
*/
@Component
public class ModuleDictionaryStartUp implements ApplicationRunner {
private static final Logger LOG = LoggerFactory.getLogger(ModuleDictionaryStartUp.class);
@Autowired
private IDataDao dataDao;
@Autowired
private IAreaDao areaDao;
@Override
public void run(ApplicationArguments args) throws Exception {
initTable();
}
/**
* 建表
*/
private void initTable() {
LOG.debug("创建 data_data 表");
dataDao.createTable();
LOG.debug("创建 data_area 表");
areaDao.createTable();
}
}

View File

@ -1,40 +0,0 @@
package ink.wgink.module.file.startup;
import ink.wgink.module.file.dao.IFileDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: ModuleFileStartUp
* @Description: 文件模块启动
* @Author: wanggeng
* @Date: 2021/2/9 9:18 下午
* @Version: 1.0
*/
@Component
public class ModuleFileStartUp implements ApplicationRunner {
private static final Logger LOG = LoggerFactory.getLogger(ModuleFileStartUp.class);
@Autowired
private IFileDao fileDao;
@Override
public void run(ApplicationArguments args) throws Exception {
initTable();
}
/**
* 建表
*/
private void initTable() {
LOG.debug("创建 sys_file 表");
fileDao.createTable();
}
}

View File

@ -1,13 +1,8 @@
package ink.wgink.module.sms.startup; package ink.wgink.module.sms.startup;
import ink.wgink.module.sms.dao.email.IEmailDao;
import ink.wgink.module.sms.dao.sms.ISmsDao;
import ink.wgink.module.sms.manager.VerifyCodeManager; import ink.wgink.module.sms.manager.VerifyCodeManager;
import ink.wgink.properties.sms.EmailProperties;
import ink.wgink.properties.sms.SmsProperties;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
@ -27,29 +22,9 @@ import org.springframework.stereotype.Component;
public class SmsStartUp implements ApplicationRunner { public class SmsStartUp implements ApplicationRunner {
private static final Logger LOG = LoggerFactory.getLogger(SmsStartUp.class); private static final Logger LOG = LoggerFactory.getLogger(SmsStartUp.class);
@Autowired
private SmsProperties smsProperties;
@Autowired
private EmailProperties emailProperties;
@Autowired
private ISmsDao smsDao;
@Autowired
private IEmailDao emailDao;
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
initTable();
}
public void initTable() {
if (smsProperties.getActive()) {
LOG.debug("创建 sms_sms 表");
smsDao.createTable();
}
if(emailProperties.getActive()) {
LOG.debug("创建 sms_email 表");
emailDao.createTable();
}
} }
/** /**

View File

@ -37,24 +37,9 @@ public class WechatStartUp implements ApplicationRunner {
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
initTable();
new Thread(() -> refreshOfficialAccountAccessToken()).start(); new Thread(() -> refreshOfficialAccountAccessToken()).start();
} }
/**
* 建表
*/
private void initTable() {
if (miniAppProperties.getActive()) {
LOG.debug("创建 wechat_mini_app_user 表");
miniAppUserDao.createTable();
}
if (officialAccountProperties.getActivate()) {
LOG.debug("创建 wechat_official_account_user 表");
officialAccountUserDao.createTable();
}
}
@Scheduled(cron = "0 0/5 * * * ?") @Scheduled(cron = "0 0/5 * * * ?")
public void refreshOfficialAccountAccessToken() { public void refreshOfficialAccountAccessToken() {
if (!officialAccountProperties.getActivate()) { if (!officialAccountProperties.getActivate()) {

View File

@ -1,58 +0,0 @@
package ink.wgink.service.department.startup;
import ink.wgink.service.department.dao.IDepartmentAdjustmentDao;
import ink.wgink.service.department.dao.IDepartmentDao;
import ink.wgink.service.department.dao.IDepartmentUserAdjustmentDao;
import ink.wgink.service.department.dao.IDepartmentUserDao;
import ink.wgink.service.department.service.IDepartmentUserAdjustmentService;
import ink.wgink.service.department.service.IDepartmentUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: ServiceDepartmentStartUp
* @Description: 组织机构业务
* @Author: wanggeng
* @Date: 2021/2/12 8:39 下午
* @Version: 1.0
*/
@Component
public class ServiceDepartmentStartUp implements ApplicationRunner {
private static final Logger LOG = LoggerFactory.getLogger(ServiceDepartmentStartUp.class);
@Autowired
private IDepartmentDao departmentDao;
@Autowired
private IDepartmentAdjustmentDao departmentAdjustmentDao;
@Autowired
private IDepartmentUserDao departmentUserDao;
@Autowired
private IDepartmentUserAdjustmentDao departmentUserAdjustmentDao;
@Override
public void run(ApplicationArguments args) throws Exception {
initTable();
}
private void initTable() {
LOG.debug("创建 sys_department 表");
departmentDao.createTable();
LOG.debug("创建 sys_department_adjustment 表");
departmentAdjustmentDao.createTable();
LOG.debug("创建 sys_department_user 表");
departmentUserDao.createTable();
LOG.debug("创建 sys_department_user_adjustment 表");
departmentUserAdjustmentDao.createTable();
}
}

View File

@ -1,44 +0,0 @@
package ink.wgink.service.group.startup;
import ink.wgink.service.group.dao.IGroupDao;
import ink.wgink.service.group.dao.IGroupUserDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: ServiceGroupStartUp
* @Description: 用户组启动
* @Author: wanggeng
* @Date: 2021/2/15 9:11 上午
* @Version: 1.0
*/
@Component
public class ServiceGroupStartUp implements ApplicationRunner {
private static final Logger LOG = LoggerFactory.getLogger(ServiceGroupStartUp.class);
@Autowired
private IGroupDao groupDao;
@Autowired
private IGroupUserDao groupUserDao;
@Override
public void run(ApplicationArguments args) throws Exception {
initTable();
}
private void initTable() {
LOG.debug("创建 sys_group 表");
groupDao.createTable();
LOG.debug("创建 sys_group_user 表");
groupUserDao.createTable();
}
}

View File

@ -67,15 +67,6 @@ public class ServiceMenuStartUp implements ApplicationRunner {
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
initTable();
}
/**
* 建表
*/
private void initTable() {
LOG.debug("创建 sys_menu 表");
menuDao.createTable();
initMenu(); initMenu();
} }

View File

@ -1,42 +0,0 @@
package ink.wgink.service.permission.startup;
import ink.wgink.service.permission.dao.IPermissionDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: ModulePermissionStartUp
* @Description: 权限模块
* @Author: wanggeng
* @Date: 2021/2/17 10:34 上午
* @Version: 1.0
*/
@Component
public class ServicePermissionStartUp implements ApplicationRunner {
private static final Logger LOG = LoggerFactory.getLogger(ServicePermissionStartUp.class);
@Autowired
private IPermissionDao permissionDao;
@Override
public void run(ApplicationArguments args) throws Exception {
initTable();
}
/**
* 初始化表
*/
private void initTable() {
LOG.debug("创建 sys_permission 表");
permissionDao.createTable();
}
}

View File

@ -1,46 +0,0 @@
package ink.wgink.service.position.startup;
import ink.wgink.service.position.dao.IPositionDao;
import ink.wgink.service.position.dao.IPositionUserDao;
import ink.wgink.service.position.service.IPositionUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: ServicePositionStartUp
* @Description: 职位业务
* @Author: WangGeng
* @Date: 2021/2/16 17:42
* @Version: 1.0
**/
@Component
public class ServicePositionStartUp implements ApplicationRunner {
private static final Logger LOG = LoggerFactory.getLogger(ServicePositionStartUp.class);
@Autowired
private IPositionDao positionDao;
@Autowired
private IPositionUserDao positionUserDao;
@Override
public void run(ApplicationArguments args) throws Exception {
initTable();
}
private void initTable() {
LOG.debug("创建 sys_position 表");
positionDao.createTable();
LOG.debug("创建 sys_position_user 表");
positionUserDao.createTable();
}
}

View File

@ -1,66 +0,0 @@
package ink.wgink.service.role.startup;
import ink.wgink.pojo.dtos.user.UserDTO;
import ink.wgink.service.role.dao.*;
import ink.wgink.util.date.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: ServiceRoleStartUp
* @Description: 角色业务
* @Author: WangGeng
* @Date: 2021/2/17 22:58
* @Version: 1.0
**/
@Component
public class ServiceRoleStartUp implements ApplicationRunner {
private static final Logger LOG = LoggerFactory.getLogger(ServiceRoleStartUp.class);
@Autowired
private IRoleDao roleDao;
@Autowired
private IRoleUserDao roleUserDao;
@Autowired
private IRolePermissionDao rolePermissionDao;
@Autowired
private IRoleDataRightDao roleDataRightDao;
@Autowired
private IRoleMenuDao roleMenuDao;
@Override
public void run(ApplicationArguments args) throws Exception {
initTable();
}
/**
* 建表
*/
private void initTable() {
LOG.debug("创建 sys_role 表");
roleDao.createTable();
LOG.debug("创建 sys_role_user 表");
roleUserDao.createTable();
LOG.debug("创建 sys_role_permission 表");
rolePermissionDao.createTable();
LOG.debug("创建 sys_role_data_right 表");
roleDataRightDao.createTable();
LOG.debug("创建 sys_role_menu 表");
roleMenuDao.createTable();
}
}

View File

@ -39,7 +39,7 @@ public class ServiceUserStartUp implements ApplicationRunner {
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
initTable(); // initTable();
} }
/** /**