|
@@ -1,5 +1,6 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.thread.ThreadUtil;
|
|
|
import com.ruoyi.common.annotation.DataSource;
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
@@ -11,8 +12,10 @@ import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.system.domain.SysConfig;
|
|
|
import com.ruoyi.system.mapper.SysConfigMapper;
|
|
|
import com.ruoyi.system.service.ISysConfigService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
@@ -22,9 +25,9 @@ import java.util.List;
|
|
|
*
|
|
|
* @author ruoyi
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
-public class SysConfigServiceImpl implements ISysConfigService
|
|
|
-{
|
|
|
+public class SysConfigServiceImpl implements ISysConfigService {
|
|
|
@Autowired
|
|
|
private SysConfigMapper configMapper;
|
|
|
|
|
@@ -35,8 +38,7 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* 项目启动时,初始化参数到缓存
|
|
|
*/
|
|
|
@PostConstruct
|
|
|
- public void init()
|
|
|
- {
|
|
|
+ public void init() {
|
|
|
loadingConfigCache();
|
|
|
}
|
|
|
|
|
@@ -48,8 +50,7 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
*/
|
|
|
@Override
|
|
|
@DataSource(DataSourceType.MASTER)
|
|
|
- public SysConfig selectConfigById(Long configId)
|
|
|
- {
|
|
|
+ public SysConfig selectConfigById(Long configId) {
|
|
|
SysConfig config = new SysConfig();
|
|
|
config.setConfigId(configId);
|
|
|
return configMapper.selectConfig(config);
|
|
@@ -62,18 +63,15 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* @return 参数键值
|
|
|
*/
|
|
|
@Override
|
|
|
- public String selectConfigByKey(String configKey)
|
|
|
- {
|
|
|
+ public String selectConfigByKey(String configKey) {
|
|
|
String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey)));
|
|
|
- if (StringUtils.isNotEmpty(configValue))
|
|
|
- {
|
|
|
+ if (StringUtils.isNotEmpty(configValue)) {
|
|
|
return configValue;
|
|
|
}
|
|
|
SysConfig config = new SysConfig();
|
|
|
config.setConfigKey(configKey);
|
|
|
SysConfig retConfig = configMapper.selectConfig(config);
|
|
|
- if (StringUtils.isNotNull(retConfig))
|
|
|
- {
|
|
|
+ if (StringUtils.isNotNull(retConfig)) {
|
|
|
redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
|
|
|
return retConfig.getConfigValue();
|
|
|
}
|
|
@@ -86,11 +84,9 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* @return true开启,false关闭
|
|
|
*/
|
|
|
@Override
|
|
|
- public boolean selectCaptchaOnOff()
|
|
|
- {
|
|
|
+ public boolean selectCaptchaOnOff() {
|
|
|
String captchaOnOff = selectConfigByKey("sys.account.captchaOnOff");
|
|
|
- if (StringUtils.isEmpty(captchaOnOff))
|
|
|
- {
|
|
|
+ if (StringUtils.isEmpty(captchaOnOff)) {
|
|
|
return true;
|
|
|
}
|
|
|
return Convert.toBool(captchaOnOff);
|
|
@@ -103,11 +99,16 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* @return 参数配置集合
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<SysConfig> selectConfigList(SysConfig config)
|
|
|
- {
|
|
|
+ public List<SysConfig> selectConfigList(SysConfig config) {
|
|
|
return configMapper.selectConfigList(config);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public SysConfig selectByConfigKey(SysConfig config) {
|
|
|
+ List<SysConfig> sysConfigs = this.selectConfigList(config);
|
|
|
+ return sysConfigs.size() > 0 ? sysConfigs.get(0) : null;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 新增参数配置
|
|
|
*
|
|
@@ -115,11 +116,9 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int insertConfig(SysConfig config)
|
|
|
- {
|
|
|
+ public int insertConfig(SysConfig config) {
|
|
|
int row = configMapper.insertConfig(config);
|
|
|
- if (row > 0)
|
|
|
- {
|
|
|
+ if (row > 0) {
|
|
|
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
}
|
|
|
return row;
|
|
@@ -132,11 +131,9 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateConfig(SysConfig config)
|
|
|
- {
|
|
|
+ public int updateConfig(SysConfig config) {
|
|
|
int row = configMapper.updateConfig(config);
|
|
|
- if (row > 0)
|
|
|
- {
|
|
|
+ if (row > 0) {
|
|
|
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
}
|
|
|
return row;
|
|
@@ -149,13 +146,10 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public void deleteConfigByIds(Long[] configIds)
|
|
|
- {
|
|
|
- for (Long configId : configIds)
|
|
|
- {
|
|
|
+ public void deleteConfigByIds(Long[] configIds) {
|
|
|
+ for (Long configId : configIds) {
|
|
|
SysConfig config = selectConfigById(configId);
|
|
|
- if (StringUtils.equals(UserConstants.YES, config.getConfigType()))
|
|
|
- {
|
|
|
+ if (StringUtils.equals(UserConstants.YES, config.getConfigType())) {
|
|
|
throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
|
|
|
}
|
|
|
configMapper.deleteConfigById(configId);
|
|
@@ -167,11 +161,9 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* 加载参数缓存数据
|
|
|
*/
|
|
|
@Override
|
|
|
- public void loadingConfigCache()
|
|
|
- {
|
|
|
+ public void loadingConfigCache() {
|
|
|
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
|
|
|
- for (SysConfig config : configsList)
|
|
|
- {
|
|
|
+ for (SysConfig config : configsList) {
|
|
|
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
}
|
|
|
}
|
|
@@ -180,8 +172,7 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* 清空参数缓存数据
|
|
|
*/
|
|
|
@Override
|
|
|
- public void clearConfigCache()
|
|
|
- {
|
|
|
+ public void clearConfigCache() {
|
|
|
Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
|
|
|
redisCache.deleteObject(keys);
|
|
|
}
|
|
@@ -190,8 +181,7 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* 重置参数缓存数据
|
|
|
*/
|
|
|
@Override
|
|
|
- public void resetConfigCache()
|
|
|
- {
|
|
|
+ public void resetConfigCache() {
|
|
|
clearConfigCache();
|
|
|
loadingConfigCache();
|
|
|
}
|
|
@@ -203,12 +193,10 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public String checkConfigKeyUnique(SysConfig config)
|
|
|
- {
|
|
|
+ public String checkConfigKeyUnique(SysConfig config) {
|
|
|
Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId();
|
|
|
SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey());
|
|
|
- if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue())
|
|
|
- {
|
|
|
+ if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) {
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
}
|
|
|
return UserConstants.UNIQUE;
|
|
@@ -220,22 +208,44 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* @param configKey 参数键
|
|
|
* @return 缓存键key
|
|
|
*/
|
|
|
- private String getCacheKey(String configKey)
|
|
|
- {
|
|
|
+ private String getCacheKey(String configKey) {
|
|
|
return Constants.SYS_CONFIG_KEY + configKey;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public boolean checkGratingIsSuperHigh(String gratingConfigKey) {
|
|
|
+ SysConfig sysConfigQuery = new SysConfig();
|
|
|
+ sysConfigQuery.setConfigKey(gratingConfigKey);
|
|
|
+ SysConfig sysConfig = this.selectByConfigKey(sysConfigQuery);
|
|
|
+
|
|
|
+ // 检测之前需要开启检测开关
|
|
|
+ SysConfig sysConfigUpdate = new SysConfig();
|
|
|
+ sysConfigUpdate.setConfigId(sysConfig.getConfigId());
|
|
|
+ sysConfigUpdate.setConfigValue("Y");
|
|
|
+ this.updateConfig(sysConfigUpdate);
|
|
|
+
|
|
|
+ // 超高状态 Y超高 | N不超高
|
|
|
String endState = "";
|
|
|
- SysConfig sysConfig = new SysConfig();
|
|
|
- sysConfig.setConfigKey(gratingConfigKey);
|
|
|
- List<SysConfig> sysConfigs = this.selectConfigList(sysConfig);
|
|
|
- if (sysConfigs.size() > 0) {
|
|
|
- String configType = sysConfigs.get(0).getConfigType();
|
|
|
- endState = configType;
|
|
|
+ SysConfig sysConfigState = null;
|
|
|
+ int checkNum = 0; // 查询次数
|
|
|
+ for (; ; ) {
|
|
|
+ if (checkNum > 10) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ ThreadUtil.sleep(500);
|
|
|
+ sysConfigQuery.setConfigValue("N"); // plc会写成功会置为N
|
|
|
+ sysConfigState = this.selectByConfigKey(sysConfigQuery);
|
|
|
+ if (sysConfigState != null) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ checkNum++;
|
|
|
+ }
|
|
|
+ if (sysConfigState == null) {
|
|
|
+ log.error("和光栅服务器通讯可能断开:" + gratingConfigKey);
|
|
|
+ return true;
|
|
|
}
|
|
|
+ endState = sysConfigState.getConfigType();
|
|
|
return endState.equals("Y");
|
|
|
}
|
|
|
}
|