数据缓存及业务缓存优化完成
parent
8f2d13a3c2
commit
cd86301a83
@ -0,0 +1,20 @@
|
||||
package cn.estsh.i3plus.core.api.iservice.busi;
|
||||
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysDataSource;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysPosition;
|
||||
import cn.estsh.impp.framework.base.service.ICacheCrudService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* @Description : 数据源接口
|
||||
* @Reference :
|
||||
* @Author : wei.peng
|
||||
* @Date : 2018-10-19 16:36
|
||||
* @Modify :
|
||||
**/
|
||||
public interface ISysDataSourceService extends ICacheCrudService<SysDataSource> {
|
||||
|
||||
@ApiOperation(value = "数据源检查",notes = "数据源唯一检查(软件类型,数据源代码)")
|
||||
void checkSysDataSourceOnly(SysDataSource bean);
|
||||
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package cn.estsh.i3plus.core.apiservice.controller.busi;
|
||||
|
||||
import cn.estsh.i3plus.core.api.iservice.busi.ISysDataSourceService;
|
||||
import cn.estsh.i3plus.core.api.iservice.busi.ISysPojoVersionPlanService;
|
||||
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
||||
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysDataSource;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysFile;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysPojoVersionPlan;
|
||||
import cn.estsh.impp.framework.base.controller.CrudBaseController;
|
||||
import cn.estsh.impp.framework.base.service.ICrudService;
|
||||
import cn.estsh.impp.framework.boot.datasource.ImppJdbcTemplateFactory;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
||||
import cn.estsh.impp.framework.boot.util.ResultBean;
|
||||
import cn.estsh.impp.framework.boot.util.ValidatorBean;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Reference :
|
||||
* @Author : wei.peng
|
||||
* @CreateDate : 20-4-21 下午2:56
|
||||
* @Modify:
|
||||
**/
|
||||
@RestController
|
||||
@Api(tags = "数据源服务")
|
||||
@RequestMapping(CommonConstWords.BASE_URL_CORE+"/data-source")
|
||||
public class SysDataSourceController extends CrudBaseController<SysDataSource> {
|
||||
@Autowired
|
||||
private ISysDataSourceService dataSourceService;
|
||||
|
||||
@Override
|
||||
public ICrudService getCrudService() {
|
||||
return dataSourceService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysDataSource validatorInsertBean(SysDataSource bean) throws Exception {
|
||||
ValidatorBean.beginValid(bean)
|
||||
.notNull("sourceName",bean.getSourceName())
|
||||
.notNull("softType",bean.getSoftType())
|
||||
.notNull("sourceCode",bean.getSourceCode())
|
||||
.notNull("sourceType",bean.getSourceType())
|
||||
.notNull("sourceHost",bean.getSourceHost())
|
||||
.notNull("sourcePort",bean.getSourcePort())
|
||||
.notNull("sourceUserName",bean.getSourceUserName())
|
||||
.notNull("sourcePassword",bean.getSourcePassword());
|
||||
|
||||
try {
|
||||
bean.setSourceStatus(CommonEnumUtil.DATA_SOURCE_STATUS.CONN_FAILURE.getValue());
|
||||
NamedParameterJdbcTemplate template = ImppJdbcTemplateFactory.getNamedParameterJdbcTemplate(bean);
|
||||
if(template != null) {
|
||||
try {
|
||||
Connection conn = template.getJdbcTemplate().getDataSource().getConnection();
|
||||
if(Objects.nonNull(conn)){
|
||||
bean.setSourceStatus(CommonEnumUtil.DATA_SOURCE_STATUS.CONN_SUCCESS.getValue());
|
||||
}
|
||||
}catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/connection-check/{id}")
|
||||
@ApiOperation(value = "数据源连接检查")
|
||||
public ResultBean<SysDataSource> checkConnection(@PathVariable("id") Long id) {
|
||||
try {
|
||||
SysDataSource source = dataSourceService.get(id);
|
||||
NamedParameterJdbcTemplate template = ImppJdbcTemplateFactory.getNamedParameterJdbcTemplate(source);
|
||||
if(template != null) {
|
||||
try {
|
||||
Connection conn = template.getJdbcTemplate().getDataSource().getConnection();
|
||||
if(Objects.nonNull(conn)){
|
||||
source.setSourceStatus(CommonEnumUtil.DATA_SOURCE_STATUS.CONN_SUCCESS.getValue());
|
||||
dataSourceService.update(source);
|
||||
|
||||
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
}
|
||||
}catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return ResultBean.fail("操作失败").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
} catch (ImppBusiException busExcep) {
|
||||
return ResultBean.fail(busExcep);
|
||||
} catch (Exception e) {
|
||||
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package cn.estsh.i3plus.core.apiservice.serviceimpl.busi;
|
||||
|
||||
import cn.estsh.i3plus.core.api.iservice.busi.ISysDataSourceService;
|
||||
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
||||
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
||||
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.base.jpa.dao.BaseRepository;
|
||||
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysDataSource;
|
||||
import cn.estsh.i3plus.pojo.platform.repository.SysDataSourceRepository;
|
||||
import cn.estsh.i3plus.pojo.platform.sqlpack.CoreHqlPack;
|
||||
import cn.estsh.impp.framework.base.service.CacheCrudService;
|
||||
import cn.estsh.impp.framework.boot.datasource.ImppJdbcTemplateFactory;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
||||
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Reference :
|
||||
* @Author : wei.peng
|
||||
* @CreateDate : 20-5-11 上午11:12
|
||||
* @Modify:
|
||||
**/
|
||||
@Service
|
||||
public class SysDataSourceService extends CacheCrudService<SysDataSource> implements ISysDataSourceService {
|
||||
|
||||
@Autowired
|
||||
private SysDataSourceRepository dataSourceRDao;
|
||||
|
||||
@Override
|
||||
public BaseRepository<SysDataSource, Long> getRepository() {
|
||||
return dataSourceRDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkSysDataSourceOnly(SysDataSource bean) {
|
||||
DdlPackBean packBean = DdlPackBean.getDdlPackBean(bean);
|
||||
DdlPreparedPack.getNumNOEqualPack(bean.getId(),"id",packBean);
|
||||
DdlPreparedPack.getNumEqualPack(bean.getSoftType(),"softType",packBean);
|
||||
DdlPreparedPack.getStringEqualPack(bean.getSourceCode(),"sourceCode",packBean);
|
||||
|
||||
if(dataSourceRDao.findByHqlWhereCount(packBean) > 0){
|
||||
throw ImppExceptionBuilder.newInstance()
|
||||
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||
.setErrorCode(ImppExceptionEnum.IO_EXCEPTION.getCode())
|
||||
.setErrorDetail("数据代码已存在")
|
||||
.setErrorSolution("请重新操作")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packAfterRefreshCache() {
|
||||
List<SysDataSource> list = getMemCacheDataSource();
|
||||
ImppRedis imppRedis = getRedisBusiCache();
|
||||
if(CollectionUtils.isNotEmpty(list)){
|
||||
if(Objects.nonNull(imppRedis)){
|
||||
for (SysDataSource source : list) {
|
||||
String redisKey = ImppJdbcTemplateFactory.getDataSourceName(source.getSourceName());
|
||||
imppRedis.putObject(redisKey, JSON.toJSONString(source), -1);
|
||||
}
|
||||
}else{
|
||||
LOGGER.info("同步数据到错误:无法获取Redis连接信息");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DdlPackBean getFindPagerPackBean(SysDataSource bean) {
|
||||
return CoreHqlPack.packSysDataSource(bean);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue