|
@@ -3,17 +3,12 @@ package com.qmth.exam.reserve.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
-import com.qmth.exam.reserve.bean.Constants;
|
|
|
|
-import com.qmth.exam.reserve.bean.org.OrgInfo;
|
|
|
|
-import com.qmth.exam.reserve.cache.impl.OrgCacheService;
|
|
|
|
import com.qmth.exam.reserve.dao.SystemPropertyDao;
|
|
import com.qmth.exam.reserve.dao.SystemPropertyDao;
|
|
import com.qmth.exam.reserve.entity.SystemPropertyEntity;
|
|
import com.qmth.exam.reserve.entity.SystemPropertyEntity;
|
|
-import com.qmth.exam.reserve.enums.EventType;
|
|
|
|
-import com.qmth.exam.reserve.service.OperateLogService;
|
|
|
|
import com.qmth.exam.reserve.service.SystemPropertyService;
|
|
import com.qmth.exam.reserve.service.SystemPropertyService;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -21,12 +16,6 @@ public class SystemPropertyServiceImpl extends ServiceImpl<SystemPropertyDao, Sy
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(SystemPropertyServiceImpl.class);
|
|
private static final Logger log = LoggerFactory.getLogger(SystemPropertyServiceImpl.class);
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private OrgCacheService orgCacheService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private OperateLogService operateLogService;
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public SystemPropertyEntity findByPropKey(Long orgId, String propKey) {
|
|
public SystemPropertyEntity findByPropKey(Long orgId, String propKey) {
|
|
LambdaQueryWrapper<SystemPropertyEntity> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<SystemPropertyEntity> wrapper = new LambdaQueryWrapper<>();
|
|
@@ -47,54 +36,32 @@ public class SystemPropertyServiceImpl extends ServiceImpl<SystemPropertyDao, Sy
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void enableSwitch(Long userId, Boolean status) {
|
|
|
|
- if (status == null) {
|
|
|
|
- log.error("[enableSwitch] 参数不能为空");
|
|
|
|
- throw new StatusException("参数不能为空");
|
|
|
|
- }
|
|
|
|
- // 获取当前机构信息
|
|
|
|
- OrgInfo org = orgCacheService.currentOrg();
|
|
|
|
- if (org == null) {
|
|
|
|
- log.warn("[enableSwitch] 当前机构不存在");
|
|
|
|
- throw new StatusException("当前机构不存在");
|
|
|
|
|
|
+ public void updatePropValue(Long orgId, String propKey, String propValue) {
|
|
|
|
+ if (orgId == null) {
|
|
|
|
+ throw new StatusException("orgId值不能为空");
|
|
}
|
|
}
|
|
-
|
|
|
|
- try {
|
|
|
|
- // 更新或插入系统属性
|
|
|
|
- updateOrInsertSystemProperty(org.getOrgId(), status);
|
|
|
|
-
|
|
|
|
- // 记录操作日志
|
|
|
|
- operateLogService.insertOperateLog(userId, EventType.APPLY_SWITCH, status ? "启用" : "禁用");
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("[enableSwitch] 操作失败: orgId={}, propKey={}, status={}", org.getOrgId(), Constants.APPLY_SWITCH, status, e);
|
|
|
|
- throw new RuntimeException("操作失败", e);
|
|
|
|
|
|
+ if (StringUtils.isBlank(propKey)) {
|
|
|
|
+ throw new StatusException("propKey值不能为空");
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- private void updateOrInsertSystemProperty(Long orgId, Boolean status) {
|
|
|
|
- LambdaQueryWrapper<SystemPropertyEntity> lw = new LambdaQueryWrapper<>();
|
|
|
|
- lw.eq(SystemPropertyEntity::getOrgId, orgId);
|
|
|
|
- lw.eq(SystemPropertyEntity::getPropKey, Constants.APPLY_SWITCH);
|
|
|
|
-
|
|
|
|
- SystemPropertyEntity systemProperty = baseMapper.selectOne(lw);
|
|
|
|
-
|
|
|
|
- String targetValue = status ? "1" : "0";
|
|
|
|
|
|
+ LambdaQueryWrapper<SystemPropertyEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ wrapper.eq(SystemPropertyEntity::getOrgId, orgId);
|
|
|
|
+ wrapper.eq(SystemPropertyEntity::getPropKey, propKey);
|
|
|
|
|
|
|
|
+ SystemPropertyEntity systemProperty = baseMapper.selectOne(wrapper);
|
|
if (systemProperty == null) {
|
|
if (systemProperty == null) {
|
|
- // 插入新记录
|
|
|
|
- SystemPropertyEntity entity = new SystemPropertyEntity();
|
|
|
|
- entity.setOrgId(orgId);
|
|
|
|
- entity.setPropKey(Constants.APPLY_SWITCH);
|
|
|
|
- entity.setPropValue(targetValue);
|
|
|
|
- baseMapper.insert(entity);
|
|
|
|
|
|
+ systemProperty = new SystemPropertyEntity();
|
|
|
|
+ systemProperty.setOrgId(orgId);
|
|
|
|
+ systemProperty.setPropKey(propKey);
|
|
|
|
+ systemProperty.setPropValue(propValue);
|
|
|
|
+ systemProperty.setCreateTime(System.currentTimeMillis());
|
|
|
|
+ systemProperty.setUpdateTime(System.currentTimeMillis());
|
|
|
|
+ baseMapper.insert(systemProperty);
|
|
} else {
|
|
} else {
|
|
- // 如果当前值与目标值不同,则更新
|
|
|
|
- if (!systemProperty.getPropValue().equals(targetValue)) {
|
|
|
|
- systemProperty.setPropValue(targetValue);
|
|
|
|
- baseMapper.updateById(systemProperty);
|
|
|
|
- }
|
|
|
|
|
|
+ systemProperty.setPropValue(propValue);
|
|
|
|
+ systemProperty.setUpdateTime(System.currentTimeMillis());
|
|
|
|
+ baseMapper.updateById(systemProperty);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
}
|
|
}
|