JSL_OrganizeInternalOA/src/main/java/com/jsl/oa/JslOrganizeInternalOaRunnerApplication.java
XiaoLFeng 5f0e58ab06
All checks were successful
代码检查 / 代码检查 (pull_request) Successful in 19s
feat: 代码规约修改,BUG 补丁
2024-04-11 19:31:16 +08:00

60 lines
2.0 KiB
Java

package com.jsl.oa;
import com.google.gson.Gson;
import com.jsl.oa.common.constant.SafeConstants;
import com.jsl.oa.mapper.InfoMapper;
import com.jsl.oa.model.dodata.ConfigDO;
import com.jsl.oa.model.vodata.business.InfoAboutSecurityKey;
import com.jsl.oa.utils.Processing;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.stereotype.Component;
import java.sql.Timestamp;
/**
* <h1>启动类</h1>
* <hr/>
* 用于启动项目
*
* @version v1.1.0
* @see org.springframework.boot.SpringApplication
* @see org.springframework.boot.autoconfigure.SpringBootApplication
* @since v1.1.0
* @author xiaofeng
*/
@Component
@RequiredArgsConstructor
public class JslOrganizeInternalOaRunnerApplication implements SmartInitializingSingleton {
private final Gson gson = new Gson();
private final InfoMapper infoMapper;
/**
* <h1>获取安全密钥</h1>
* <hr/>
* 从数据库中获取安全密钥
*/
@Override
public void afterSingletonsInstantiated() {
// 获取数据库中的 SecurityKey
try {
SafeConstants.setSecretKey(infoMapper.getSecurityKey().getData());
} catch (NullPointerException exception) {
// 生成密钥
String key = Processing.generateKey(System.currentTimeMillis());
InfoAboutSecurityKey infoAboutSecurityKey = new InfoAboutSecurityKey();
infoAboutSecurityKey.setKey(key)
.setUpdateTime(System.currentTimeMillis());
String json = gson.toJson(infoAboutSecurityKey, InfoAboutSecurityKey.class);
// 更新密钥
ConfigDO configDO = new ConfigDO();
configDO.setValue("security_key")
.setData(json)
.setCreatedAt(new Timestamp(System.currentTimeMillis()));
infoMapper.insertSecurityKey(configDO);
SafeConstants.setSecretKey(key);
}
}
}