|
@@ -11,6 +11,8 @@ import cn.com.qmth.examcloud.commons.util.DateUtil.DatePatterns;
|
|
import cn.com.qmth.examcloud.core.basic.dao.SystemPropertyRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.SystemPropertyRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.SystemPropertyEntity;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.SystemPropertyEntity;
|
|
import cn.com.qmth.examcloud.core.basic.service.SystemPropertyService;
|
|
import cn.com.qmth.examcloud.core.basic.service.SystemPropertyService;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.cache.SystemPropertyCache;
|
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 系统配置服务
|
|
* 系统配置服务
|
|
@@ -25,6 +27,9 @@ public class SystemPropertyServiceImpl implements SystemPropertyService {
|
|
@Autowired
|
|
@Autowired
|
|
SystemPropertyRepo systemPropertyRepo;
|
|
SystemPropertyRepo systemPropertyRepo;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ SystemPropertyCache systemPropertyCache;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void set(String key, String value) {
|
|
public void set(String key, String value) {
|
|
if (StringUtils.isBlank(key)) {
|
|
if (StringUtils.isBlank(key)) {
|
|
@@ -75,51 +80,8 @@ public class SystemPropertyServiceImpl implements SystemPropertyService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Object get(String key) {
|
|
public Object get(String key) {
|
|
- if (StringUtils.isBlank(key)) {
|
|
|
|
- throw new StatusException("350001", "key is blank");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- SystemPropertyEntity sysConf = systemPropertyRepo.getOne(key);
|
|
|
|
- if (null == sysConf) {
|
|
|
|
- throw new StatusException("350002", "key is wrong");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String value = sysConf.getPropValue();
|
|
|
|
- BasicDataType dataType = sysConf.getPropValueType();
|
|
|
|
-
|
|
|
|
- if (StringUtils.isBlank(value)) {
|
|
|
|
- return null;
|
|
|
|
- } else if (dataType.equals(BasicDataType.STRING)) {
|
|
|
|
- return value;
|
|
|
|
- } else if (dataType.equals(BasicDataType.LONG)) {
|
|
|
|
- try {
|
|
|
|
- return Long.parseLong(value);
|
|
|
|
- } catch (NumberFormatException e) {
|
|
|
|
- throw new StatusException("350002", "value is wrong");
|
|
|
|
- }
|
|
|
|
- } else if (dataType.equals(BasicDataType.INTEGER)) {
|
|
|
|
- try {
|
|
|
|
- return Integer.parseInt(value);
|
|
|
|
- } catch (NumberFormatException e) {
|
|
|
|
- throw new StatusException("350002", "value is wrong");
|
|
|
|
- }
|
|
|
|
- } else if (dataType.equals(BasicDataType.DATE)) {
|
|
|
|
- try {
|
|
|
|
- return DateUtil.parse(value, DatePatterns.CHINA_DEFAULT);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- throw new StatusException("350002", "value is wrong");
|
|
|
|
- }
|
|
|
|
- } else if (dataType.equals(BasicDataType.BOOLEAN)) {
|
|
|
|
- if ("true".equals(value)) {
|
|
|
|
- return true;
|
|
|
|
- } else if ("false".equals(value)) {
|
|
|
|
- return false;
|
|
|
|
- } else {
|
|
|
|
- throw new StatusException("350002", "value is wrong. value=" + value);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- throw new StatusException("350003", "dataType is undefined");
|
|
|
|
- }
|
|
|
|
|
|
+ SysPropertyCacheBean sysPropertyCacheBean = systemPropertyCache.get(key);
|
|
|
|
+ return sysPropertyCacheBean.getValue();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|