|
@@ -1,9 +1,5 @@
|
|
|
package cn.com.qmth.examcloud.core.basic.service.cache;
|
|
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
import cn.com.qmth.examcloud.api.commons.enums.BasicDataType;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.util.DateUtil;
|
|
@@ -11,87 +7,91 @@ 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.entity.SystemPropertyEntity;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.SystemPropertyService;
|
|
|
+import cn.com.qmth.examcloud.support.CacheConstants;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
|
|
|
import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
|
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
|
@Service
|
|
|
public class SystemPropertyCache extends RandomObjectRedisCache<SysPropertyCacheBean> {
|
|
|
|
|
|
- @Autowired
|
|
|
- SystemPropertyRepo systemPropertyRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- SystemPropertyService systemPropertyService;
|
|
|
-
|
|
|
- @Override
|
|
|
- public SysPropertyCacheBean loadFromResource(Object... keys) {
|
|
|
- String propKey = (String) keys[0];
|
|
|
-
|
|
|
- SysPropertyCacheBean b = new SysPropertyCacheBean();
|
|
|
-
|
|
|
- SystemPropertyEntity sysConf = GlobalHelper.getEntity(systemPropertyRepo, propKey,
|
|
|
- SystemPropertyEntity.class);
|
|
|
- if (null == sysConf) {
|
|
|
- b.setHasValue(false);
|
|
|
- return b;
|
|
|
- }
|
|
|
-
|
|
|
- String value = sysConf.getPropValue();
|
|
|
- BasicDataType propValueType = sysConf.getPropValueType();
|
|
|
-
|
|
|
- Object propValue = null;
|
|
|
-
|
|
|
- if (StringUtils.isBlank(value)) {
|
|
|
- propValue = null;
|
|
|
- } else if (propValueType.equals(BasicDataType.STRING)) {
|
|
|
- propValue = value;
|
|
|
- } else if (propValueType.equals(BasicDataType.LONG)) {
|
|
|
- try {
|
|
|
- propValue = Long.parseLong(value);
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- throw new StatusException("350002", "value is wrong");
|
|
|
- }
|
|
|
- } else if (propValueType.equals(BasicDataType.INTEGER)) {
|
|
|
- try {
|
|
|
- propValue = Integer.parseInt(value);
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- throw new StatusException("350002", "value is wrong");
|
|
|
- }
|
|
|
- } else if (propValueType.equals(BasicDataType.DATE)) {
|
|
|
- try {
|
|
|
- propValue = DateUtil.parse(value, DatePatterns.CHINA_DEFAULT);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new StatusException("350002", "value is wrong");
|
|
|
- }
|
|
|
- } else if (propValueType.equals(BasicDataType.BOOLEAN)) {
|
|
|
- if ("true".equals(value)) {
|
|
|
- propValue = true;
|
|
|
- } else if ("false".equals(value)) {
|
|
|
- propValue = false;
|
|
|
- } else {
|
|
|
- throw new StatusException("350002", "value is wrong. value=" + value);
|
|
|
- }
|
|
|
- } else {
|
|
|
- throw new StatusException("350003", "data type is undefined");
|
|
|
- }
|
|
|
-
|
|
|
- b.setHasValue(true);
|
|
|
- b.setValueType(propValueType);
|
|
|
- b.setValue(propValue);
|
|
|
-
|
|
|
- return b;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected String getKeyPrefix() {
|
|
|
- return "$_SYS_PROP:";
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected int getTimeout() {
|
|
|
- // 60分钟
|
|
|
- return 60 * 60;
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ SystemPropertyRepo systemPropertyRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SystemPropertyService systemPropertyService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SysPropertyCacheBean loadFromResource(Object... keys) {
|
|
|
+ String propKey = (String) keys[0];
|
|
|
+
|
|
|
+ SysPropertyCacheBean b = new SysPropertyCacheBean();
|
|
|
+
|
|
|
+ SystemPropertyEntity sysConf = GlobalHelper.getEntity(systemPropertyRepo, propKey,
|
|
|
+ SystemPropertyEntity.class);
|
|
|
+ if (null == sysConf) {
|
|
|
+ b.setHasValue(false);
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+
|
|
|
+ String value = sysConf.getPropValue();
|
|
|
+ BasicDataType propValueType = sysConf.getPropValueType();
|
|
|
+
|
|
|
+ Object propValue = null;
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(value)) {
|
|
|
+ propValue = null;
|
|
|
+ } else if (propValueType.equals(BasicDataType.STRING)) {
|
|
|
+ propValue = value;
|
|
|
+ } else if (propValueType.equals(BasicDataType.LONG)) {
|
|
|
+ try {
|
|
|
+ propValue = Long.parseLong(value);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new StatusException("350002", "value is wrong");
|
|
|
+ }
|
|
|
+ } else if (propValueType.equals(BasicDataType.INTEGER)) {
|
|
|
+ try {
|
|
|
+ propValue = Integer.parseInt(value);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new StatusException("350002", "value is wrong");
|
|
|
+ }
|
|
|
+ } else if (propValueType.equals(BasicDataType.DATE)) {
|
|
|
+ try {
|
|
|
+ propValue = DateUtil.parse(value, DatePatterns.CHINA_DEFAULT);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new StatusException("350002", "value is wrong");
|
|
|
+ }
|
|
|
+ } else if (propValueType.equals(BasicDataType.BOOLEAN)) {
|
|
|
+ if ("true".equals(value)) {
|
|
|
+ propValue = true;
|
|
|
+ } else if ("false".equals(value)) {
|
|
|
+ propValue = false;
|
|
|
+ } else {
|
|
|
+ throw new StatusException("350002", "value is wrong. value=" + value);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new StatusException("350003", "data type is undefined");
|
|
|
+ }
|
|
|
+
|
|
|
+ b.setHasValue(true);
|
|
|
+ b.setValueType(propValueType);
|
|
|
+ b.setValue(propValue);
|
|
|
+
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected String getKeyPrefix() {
|
|
|
+ return CacheConstants.CACHE_B_SYS_PROP;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getTimeout() {
|
|
|
+ // 60分钟
|
|
|
+ return 60 * 60;
|
|
|
+ }
|
|
|
|
|
|
}
|