项目初始化任务异步调用
This commit is contained in:
parent
2df905c1b3
commit
a18b715bba
@ -149,8 +149,6 @@ public class CommonUtil {
|
||||
return xmAlarmdetailMapper.getXmAlarmdetail(yq, xmdh);
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
|
||||
//服务器时间方法
|
||||
public Date getCurrentTime() {
|
||||
@ -212,6 +210,15 @@ public class CommonUtil {
|
||||
return comDictMapper.getComDictIdByName(zdlb, zdmc);
|
||||
}
|
||||
|
||||
public List<ComDict> getComDictList(String zdlb){
|
||||
List<ComDict> dictCacheList = getDictCache(zdlb);
|
||||
if(dictCacheList != null){
|
||||
return dictCacheList;
|
||||
}else{
|
||||
return comDictMapper.getComDictListByZdlb(zdlb);
|
||||
}
|
||||
}
|
||||
|
||||
public String getComOptValue(String yq, String xxdh) {
|
||||
ComOpt comOpt = getOptCache(yq, xxdh);
|
||||
if (comOpt != null) {
|
||||
@ -226,6 +233,11 @@ public class CommonUtil {
|
||||
|
||||
}
|
||||
|
||||
public void setDictCache(String zdlb, List<ComDict> dictDatas){
|
||||
ComDictUtils.setDictCache(zdlb,dictDatas);
|
||||
}
|
||||
|
||||
|
||||
public List<LabReqdetail> getLabReqdetailList(String sqh) {
|
||||
return labReqdetailMapper.getLabReqdetailList(sqh);
|
||||
}
|
||||
|
||||
@ -33,8 +33,9 @@ public class SysJobServiceImpl implements ISysJobService {
|
||||
|
||||
/**
|
||||
* 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
|
||||
* 统一在applicationconfig类中进行异步调用
|
||||
*/
|
||||
@PostConstruct
|
||||
//@PostConstruct
|
||||
public void init() throws SchedulerException, TaskException {
|
||||
scheduler.clear();
|
||||
List<SysJob> jobList = jobMapper.selectJobAll();
|
||||
|
||||
@ -1,15 +1,26 @@
|
||||
package com.czlis.system.config;
|
||||
|
||||
import com.czlis.common.asyncmanager.AsyncManager;
|
||||
import com.czlis.common.utils.ComDictUtils;
|
||||
import com.czlis.interfaceCommon.mapper.ComDictMapper;
|
||||
import com.czlis.quartz.service.impl.SysJobServiceImpl;
|
||||
import com.czlis.system.service.impl.SysConfigServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* 程序注解配置
|
||||
* 项目初始化运行逻辑
|
||||
*
|
||||
* @author admin
|
||||
*/
|
||||
@ -18,7 +29,19 @@ import java.util.TimeZone;
|
||||
@EnableAspectJAutoProxy(exposeProxy = true)
|
||||
// 指定要扫描的Mapper类的包的路径
|
||||
@MapperScan("com.czlis.**.mapper")
|
||||
@Slf4j
|
||||
public class ApplicationConfig {
|
||||
|
||||
@Autowired
|
||||
private ComDictMapper comDictMapper;
|
||||
@Autowired
|
||||
private SysConfigServiceImpl sysConfigService;
|
||||
@Autowired
|
||||
private SysJobServiceImpl sysJobService;
|
||||
|
||||
//选择性提供缓存的字典类别
|
||||
private List<String> list = Arrays.asList("GROUP","AU","BT","DG", "DP", "FT", "HOS","LG","PT","PW","SRD","SX","UT","CM","VF");
|
||||
|
||||
/**
|
||||
* 时区配置
|
||||
*/
|
||||
@ -26,4 +49,67 @@ public class ApplicationConfig {
|
||||
public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() {
|
||||
return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载字典缓存数据
|
||||
*/
|
||||
@Bean
|
||||
public void loadingDictCache() {
|
||||
TimerTask task = new TimerTask(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
//清空所有com_dict缓存
|
||||
ComDictUtils.clearDictCache();
|
||||
list.stream().forEach(zdlb -> ComDictUtils.setDictCache(zdlb, comDictMapper.getComDictListByZdlb(zdlb)));
|
||||
} catch (Exception e) {
|
||||
log.error("获取lis代码字典失败,异步执行{}方法失败",this, e);
|
||||
}
|
||||
}
|
||||
};
|
||||
AsyncManager.me().execute(task);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载系统配置缓存
|
||||
*/
|
||||
@Bean
|
||||
public void loadingSysConfigCache() {
|
||||
TimerTask task = new TimerTask(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sysConfigService.loadingConfigCache();
|
||||
} catch (Exception e) {
|
||||
log.error("获取系统配置字典失败,异步执行{}方法失败",this, e);
|
||||
}
|
||||
}
|
||||
};
|
||||
AsyncManager.me().execute(task);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载定时任务列表
|
||||
*/
|
||||
@Bean
|
||||
public void loadingSysJobCache() {
|
||||
TimerTask task = new TimerTask(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sysJobService.init();
|
||||
} catch (Exception e) {
|
||||
log.error("获取系统配置字典失败,异步执行{}方法失败",this, e);
|
||||
}
|
||||
}
|
||||
};
|
||||
AsyncManager.me().execute(task);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -34,10 +34,10 @@ public class SysConfigServiceImpl implements ISysConfigService {
|
||||
/**
|
||||
* 项目启动时,初始化参数到缓存
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
loadingConfigCache();
|
||||
}
|
||||
// @PostConstruct
|
||||
// public void init() {
|
||||
// loadingConfigCache();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 查询参数配置信息
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
package com.czlis.liswork.service.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
import cn.hutool.extra.pinyin.PinyinUtil;
|
||||
import com.czlis.common.asyncmanager.AsyncManager;
|
||||
import com.czlis.common.core.domain.Result;
|
||||
import com.czlis.common.utils.ComDictUtils;
|
||||
import com.czlis.common.utils.StringUtils;
|
||||
import com.czlis.interfaceCommon.mapper.ComDictMapper;
|
||||
import com.czlis.common.core.domain.entity.lis.ComDict;
|
||||
import com.czlis.interfaceCommon.utils.CommonUtil;
|
||||
import com.czlis.liswork.service.ComDictService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -16,65 +15,35 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
* lis字典管理
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ComDictServiceImpl implements ComDictService {
|
||||
//选择性提供缓存的字典类别
|
||||
private List<String> list = Arrays.asList("GROUP","AU","BT","DG", "DP", "FT", "HOS","LG","PT","PW","SRD","SX","UT","CM","VF");
|
||||
|
||||
@Autowired
|
||||
private ComDictMapper comDictMapper;
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
TimerTask task = new TimerTask(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// 异步执行目标方法
|
||||
loadingDictCache();
|
||||
} catch (Exception e) {
|
||||
log.error("获取lis代码字典失败,异步执行{}方法失败","loadingDictCache", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
AsyncManager.me().execute(task);
|
||||
}
|
||||
/**
|
||||
* 加载字典缓存数据
|
||||
*/
|
||||
private void loadingDictCache() {
|
||||
//清空所有com_dict缓存
|
||||
ComDictUtils.clearDictCache();
|
||||
list.stream().forEach(zdlb -> ComDictUtils.setDictCache(zdlb, comDictMapper.getComDictListByZdlb(zdlb)));
|
||||
}
|
||||
private void setDictCache(String zdlb,List<ComDict> comDictList) {
|
||||
boolean isPresent = list.contains(zdlb);
|
||||
if(isPresent)ComDictUtils.setDictCache(zdlb,comDictList);
|
||||
}
|
||||
private List<ComDict> getDictCache(String zdlb) {
|
||||
boolean isPresent = list.contains(zdlb);
|
||||
if(isPresent) return ComDictUtils.getDictCache(zdlb);
|
||||
else return comDictMapper.getComDictListByZdlb(zdlb);
|
||||
}
|
||||
@Autowired
|
||||
private CommonUtil commonUtil;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<ComDict> getComDictList(ComDict comDict) {
|
||||
return getDictCache(comDict.getZdlb());
|
||||
return commonUtil.getComDictList(comDict.getZdlb());
|
||||
}
|
||||
@Override
|
||||
public Result getComDicts(String zdlb) {
|
||||
List<ComDict> comDictList = getDictCache(zdlb);
|
||||
List<ComDict> comDictList = commonUtil.getComDictList(zdlb);
|
||||
return new Result("0", "成功!",comDictList);
|
||||
}
|
||||
//根据编号查名称
|
||||
public Result getComDictNameById(String zdlb,String zddh) {
|
||||
List<ComDict> comDictList =getDictCache(zdlb);
|
||||
List<ComDict> comDictList =commonUtil.getComDictList(zdlb);
|
||||
for (ComDict dict : comDictList) {
|
||||
if (zddh.equals(dict.getZddh())) {
|
||||
return new Result("0", "成功!",dict.getZdmc());
|
||||
@ -84,7 +53,7 @@ public class ComDictServiceImpl implements ComDictService {
|
||||
}
|
||||
//根据名称查编号
|
||||
public Result getComDictIdByName(String zdlb,String zdmc) {
|
||||
List<ComDict> comDictList =getDictCache(zdlb);
|
||||
List<ComDict> comDictList =commonUtil.getComDictList(zdlb);
|
||||
for (ComDict dict : comDictList) {
|
||||
if (zdmc.equals(dict.getZdmc())) {
|
||||
return new Result("0", "成功!",dict.getZddh());
|
||||
@ -109,7 +78,7 @@ public class ComDictServiceImpl implements ComDictService {
|
||||
int row = comDictMapper.insertComDict(comDict);
|
||||
if (row > 0) {
|
||||
List<ComDict> comDictList = comDictMapper.getComDictList(comDict);
|
||||
setDictCache(comDict.getZdlb(), comDictList);
|
||||
commonUtil.setDictCache(comDict.getZdlb(), comDictList);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -158,7 +127,7 @@ public class ComDictServiceImpl implements ComDictService {
|
||||
ComDict comDict0 = new ComDict();
|
||||
comDict0.setZdlb(zdlb);
|
||||
List<ComDict> comDictList1 = comDictMapper.getComDictList(comDict0);
|
||||
setDictCache(comDict0.getZdlb(), comDictList1);
|
||||
commonUtil.setDictCache(comDict0.getZdlb(), comDictList1);
|
||||
if (failureNum == comDictList.size()) {
|
||||
return new Result("0", "数据已全部导入成功!共 " + comDictList.size() + " 条");
|
||||
} else {
|
||||
@ -196,7 +165,7 @@ public class ComDictServiceImpl implements ComDictService {
|
||||
if (zddh == null || zddh.equals("")) return new Result("-1", "字典代号不能为空!");
|
||||
if (yljg == null || yljg.equals("")) return new Result("-1", "医疗机构不能为空!");
|
||||
int row = comDictMapper.delComDict(comDict);
|
||||
if (row > 0) setDictCache(zdlb, comDictMapper.getComDictListByZdlb(zdlb));
|
||||
if (row > 0) commonUtil.setDictCache(zdlb,comDictMapper.getComDictListByZdlb(zdlb));
|
||||
return new Result("0", "删除成功!");
|
||||
}
|
||||
|
||||
@ -206,7 +175,7 @@ public class ComDictServiceImpl implements ComDictService {
|
||||
int row = comDictMapper.updateComDict(comDict);
|
||||
if (row > 0) {
|
||||
List<ComDict> comDictList = comDictMapper.getComDictList(comDict);
|
||||
setDictCache(comDict.getZdlb(), comDictList);
|
||||
commonUtil.setDictCache(comDict.getZdlb(), comDictList);
|
||||
}
|
||||
return new Result("0", "修改成功!");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user