Merge branch 'dev' of http://git.estsh.com/i3-IMPP/i3plus-core into dev
commit
e2d315c161
@ -0,0 +1,41 @@
|
||||
package cn.estsh.i3plus.core.api.iservice.base;
|
||||
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* @Description : 系统启动加载服务
|
||||
* @Reference :
|
||||
* @Author : Adair Peng
|
||||
* @CreateDate : 2019-01-11 10:02
|
||||
* @Modify:
|
||||
**/
|
||||
public interface ISystemInitService {
|
||||
|
||||
/**
|
||||
* 系统初始化加载
|
||||
*/
|
||||
@ApiOperation(value = "初始化加载所有数据",notes = "初始化加载所有数据")
|
||||
void loadAll();
|
||||
|
||||
/**
|
||||
* 加载系统配置
|
||||
*/
|
||||
@ApiOperation(value = "加载系统配置",notes = "加载系统配置")
|
||||
void loadSysConfig();
|
||||
|
||||
/**
|
||||
* 加载系统字典
|
||||
*/
|
||||
@ApiOperation(value = "加载字典数据",notes = "加载字典数据")
|
||||
void loadSysDictionary();
|
||||
|
||||
/**
|
||||
* 加载系统语言信息
|
||||
*/
|
||||
@ApiOperation(value = "加载语言数据",notes = "加载语言数据")
|
||||
void loadSysLocaleLanguage();
|
||||
|
||||
@ApiOperation(value = "获取缓存中的数据",notes = "获取缓存中的数据")
|
||||
Object getDataFromCache(String key,Class dataType);
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package cn.estsh.i3plus.core.apiservice.configuration;
|
||||
|
||||
import cn.estsh.i3plus.core.api.iservice.base.ISystemInitService;
|
||||
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Reference :
|
||||
* @Author : Adair Peng
|
||||
* @CreateDate : 2019-01-11 9:55
|
||||
* @Modify:
|
||||
**/
|
||||
@Component
|
||||
public class AppStartSystemInit implements CommandLineRunner {
|
||||
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(CommonConstWords.SYSTEM_LOG);
|
||||
|
||||
@Autowired
|
||||
private ISystemInitService systemInitService;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
LOGGER.info(" Start Core Init Thread ");
|
||||
systemInitService.loadAll();
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
package cn.estsh.i3plus.core.apiservice.serviceimpl.base;
|
||||
|
||||
import cn.estsh.i3plus.core.api.iservice.base.ISystemInitService;
|
||||
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysConfig;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysDictionary;
|
||||
import cn.estsh.i3plus.pojo.platform.repository.SysConfigRepository;
|
||||
import cn.estsh.i3plus.pojo.platform.repository.SysDictionaryRepository;
|
||||
import cn.estsh.i3plus.pojo.platform.repository.SysLocaleLanguageRepository;
|
||||
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Reference :
|
||||
* @Author : Adair Peng
|
||||
* @CreateDate : 2019-01-11 12:34
|
||||
* @Modify:
|
||||
**/
|
||||
@Service
|
||||
public class SystemInitService implements ISystemInitService {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SystemLoginService.class);
|
||||
|
||||
@Autowired
|
||||
private SysConfigRepository configRDao;
|
||||
|
||||
@Autowired
|
||||
private SysDictionaryRepository dictionaryRDao;
|
||||
|
||||
@Autowired
|
||||
private SysLocaleLanguageRepository localeLanguageRDao;
|
||||
|
||||
@Resource(name="redisRes")
|
||||
private ImppRedis redisRes;
|
||||
|
||||
private int type = ImppEnumUtil.SYS_CACHE_TYPE.REDIS.getValue();
|
||||
|
||||
@Override
|
||||
@ApiOperation(value = "初始化加载所有数据",notes = "初始化加载所有数据")
|
||||
public void loadAll() {
|
||||
type = ImppEnumUtil.SYS_CACHE_TYPE.REDIS.getValue();
|
||||
loadSysConfig();
|
||||
loadSysDictionary();
|
||||
loadSysLocaleLanguage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ApiOperation(value = "加载系统配置",notes = "加载系统配置")
|
||||
public void loadSysConfig() {
|
||||
String redisKey = null;
|
||||
List<SysConfig> list = configRDao.findAll();
|
||||
for (SysConfig config : list) {
|
||||
redisKey = CommonConstWords.REDIS_PREFIX_CACHE_CONFIG + "_" + config.getConfigCode();
|
||||
|
||||
//存放于缓存
|
||||
putDataToCache(redisKey, config,SysConfig.class);
|
||||
}
|
||||
LOGGER.info("加载系统配置数量:【{}】",list.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ApiOperation(value = "加载字典数据",notes = "加载字典数据")
|
||||
public void loadSysDictionary() {
|
||||
try {
|
||||
List<SysDictionary> list = dictionaryRDao.findAll();
|
||||
if(list != null && list.size() > 0){
|
||||
Map<String, List<SysDictionary>> parentCodeMap = list.stream().collect(Collectors.groupingBy(SysDictionary::getParentCodeRdd));
|
||||
Map<Long, List<SysDictionary>> parentIdMap = list.stream().collect(Collectors.groupingBy(SysDictionary::getParentId));
|
||||
|
||||
for (String key : parentCodeMap.keySet()) {
|
||||
//存放于缓存
|
||||
putDataToCache(CommonConstWords.REDIS_PREFIX_CACHE_DICTIONARY + "_" + key,
|
||||
parentCodeMap.get(key),List.class);
|
||||
}
|
||||
|
||||
for (long key : parentIdMap.keySet()) {
|
||||
putDataToCache(CommonConstWords.REDIS_PREFIX_CACHE_DICTIONARY + "_" + key,
|
||||
parentIdMap.get(key),List.class);
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ApiOperation(value = "加载语言数据",notes = "加载语言数据")
|
||||
public void loadSysLocaleLanguage() {
|
||||
// Redis 缓存
|
||||
if(type == ImppEnumUtil.SYS_CACHE_TYPE.REDIS.getValue()){
|
||||
// TODO 汪云昊 实现
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 缓存存放数据统一管理
|
||||
* @param key
|
||||
* @param data
|
||||
* @param dataType
|
||||
*/
|
||||
private void putDataToCache(String key,Object data,Class dataType){
|
||||
if(type == ImppEnumUtil.SYS_CACHE_TYPE.REDIS.getValue()){
|
||||
LOGGER.info(" Put Cache Redis Key:{},value:{},dataType:{}",key,data,dataType);
|
||||
// Redis 缓存
|
||||
if(dataType == List.class){
|
||||
redisRes.putList(key,data,-1);
|
||||
}else if(dataType == SysConfig.class){
|
||||
redisRes.putObject(key,data,-1);
|
||||
}else{
|
||||
LOGGER.error("不支持树形{}存放缓存!",dataType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从缓存获取对象数据
|
||||
* @param key
|
||||
* @param dataType
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@ApiOperation(value = "获取缓存中的数据",notes = "获取缓存中的数据")
|
||||
public Object getDataFromCache(String key,Class dataType){
|
||||
if(type == ImppEnumUtil.SYS_CACHE_TYPE.REDIS.getValue()){
|
||||
// Redis 缓存
|
||||
if(dataType == List.class){
|
||||
return redisRes.getList(key,0,-1);
|
||||
}else if(dataType == SysConfig.class){
|
||||
return redisRes.getObject(key);
|
||||
}else{
|
||||
LOGGER.error("不支持树形{}存放缓存!",dataType);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package cn.estsh.i3plus.core.apiservice.util;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @Description : 文件工具类
|
||||
* @Reference :
|
||||
* @Author : yunhao
|
||||
* @CreateDate : 2019-01-11 13:34
|
||||
* @Modify:
|
||||
**/
|
||||
public class FileUtil {
|
||||
|
||||
/**
|
||||
* 对临时生成的文件夹和文件夹下的文件进行删除
|
||||
*/
|
||||
public static void deletefile(String delpath) {
|
||||
try {
|
||||
File file = new File(delpath);
|
||||
if (!file.isDirectory()) {
|
||||
file.delete();
|
||||
} else if (file.isDirectory()) {
|
||||
String[] filelist = file.list();
|
||||
for (int i = 0; i < filelist.length; i++) {
|
||||
File delfile = new File(delpath + File.separator + filelist[i]);
|
||||
if (!delfile.isDirectory()) {
|
||||
delfile.delete();
|
||||
} else if (delfile.isDirectory()) {
|
||||
deletefile(delpath + File.separator + filelist[i]);
|
||||
}
|
||||
}
|
||||
file.delete();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* File 转 byte[]
|
||||
*
|
||||
* @param filePath
|
||||
* @return
|
||||
*/
|
||||
public static byte[] file2Byte(String filePath){
|
||||
byte[] buffer = null;
|
||||
try {
|
||||
File file = new File(filePath);
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
|
||||
byte[] b = new byte[1000];
|
||||
int n;
|
||||
while ((n = fis.read(b)) != -1) {
|
||||
bos.write(b, 0, n);
|
||||
}
|
||||
fis.close();
|
||||
bos.close();
|
||||
buffer = bos.toByteArray();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* byte[] 转 File
|
||||
* @param buf
|
||||
* @param filePath
|
||||
* @param fileName
|
||||
*/
|
||||
public static void byte2File(byte[] buf, String filePath, String fileName) {
|
||||
BufferedOutputStream bos = null;
|
||||
FileOutputStream fos = null;
|
||||
File file = null;
|
||||
try {
|
||||
File dir = new File(filePath);
|
||||
if (!dir.exists() && dir.isDirectory()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
file = new File(filePath + File.separator + fileName);
|
||||
fos = new FileOutputStream(file);
|
||||
bos = new BufferedOutputStream(fos);
|
||||
bos.write(buf);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (bos != null) {
|
||||
try {
|
||||
bos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue