deason 1 сар өмнө
parent
commit
dd717d2007

+ 14 - 3
src/main/java/com/qmth/exam/reserve/controller/admin/TimePeriodExamSiteController.java

@@ -3,11 +3,14 @@ package com.qmth.exam.reserve.controller.admin;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.boot.core.exception.StatusException;
+import com.qmth.exam.reserve.bean.Constants;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteReq;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteVo;
 import com.qmth.exam.reserve.controller.BaseController;
+import com.qmth.exam.reserve.enums.EventType;
 import com.qmth.exam.reserve.enums.Role;
+import com.qmth.exam.reserve.service.OperateLogService;
 import com.qmth.exam.reserve.service.SystemPropertyService;
 import com.qmth.exam.reserve.service.TimePeriodExamSiteService;
 import io.swagger.annotations.Api;
@@ -18,7 +21,6 @@ import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Objects;
 
 @RestController
 @Api(tags = "【管理端】考点预约设置相关接口")
@@ -32,6 +34,9 @@ public class TimePeriodExamSiteController extends BaseController {
     @Autowired
     private SystemPropertyService systemPropertyService;
 
+    @Autowired
+    private OperateLogService operateLogService;
+
     @ApiOperation(value = "时段区间列表")
     @PostMapping(value = "/list")
     public List<String> list(@ApiParam("预约任务ID") @RequestParam(required = false) Long taskId) {
@@ -41,7 +46,7 @@ public class TimePeriodExamSiteController extends BaseController {
     @ApiOperation(value = "日期时段列表")
     @PostMapping(value = "/detail/list")
     public List<TimePeriodExamSiteVo> ListDetail(@ApiParam("考点ID") @RequestParam(required = false) Long examSiteId) {
-        if(examSiteId == null) {
+        if (examSiteId == null) {
             return new ArrayList<>();
         }
         return timePeriodExamSiteService.ListDetail(examSiteId);
@@ -61,6 +66,12 @@ public class TimePeriodExamSiteController extends BaseController {
         if (!loginUser.getRole().equals(Role.ADMIN)) {
             throw new StatusException("无权限");
         }
-        systemPropertyService.enableSwitch(loginUser.getId(), status);
+
+        systemPropertyService.updatePropValue(loginUser.getOrgId(), Constants.APPLY_SWITCH,
+                status ? Constants.APPLY_SWITCH_OPEN : Constants.APPLY_SWITCH_CLOSE);
+
+        // 记录操作日志
+        operateLogService.insertOperateLog(loginUser.getId(), EventType.APPLY_SWITCH, status ? "启用" : "禁用");
     }
+
 }

+ 1 - 1
src/main/java/com/qmth/exam/reserve/service/SystemPropertyService.java

@@ -9,6 +9,6 @@ public interface SystemPropertyService extends IService<SystemPropertyEntity> {
 
     boolean existPropValue(Long orgId, String propKey, String propValue);
 
-    void enableSwitch(Long userId, Boolean status);
+    void updatePropValue(Long orgId, String propKey, String propValue);
 
 }

+ 20 - 53
src/main/java/com/qmth/exam/reserve/service/impl/SystemPropertyServiceImpl.java

@@ -3,17 +3,12 @@ package com.qmth.exam.reserve.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 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.entity.SystemPropertyEntity;
-import com.qmth.exam.reserve.enums.EventType;
-import com.qmth.exam.reserve.service.OperateLogService;
 import com.qmth.exam.reserve.service.SystemPropertyService;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 @Service
@@ -21,12 +16,6 @@ public class SystemPropertyServiceImpl extends ServiceImpl<SystemPropertyDao, Sy
 
     private static final Logger log = LoggerFactory.getLogger(SystemPropertyServiceImpl.class);
 
-    @Autowired
-    private OrgCacheService orgCacheService;
-
-    @Autowired
-    private OperateLogService operateLogService;
-
     @Override
     public SystemPropertyEntity findByPropKey(Long orgId, String propKey) {
         LambdaQueryWrapper<SystemPropertyEntity> wrapper = new LambdaQueryWrapper<>();
@@ -47,54 +36,32 @@ public class SystemPropertyServiceImpl extends ServiceImpl<SystemPropertyDao, Sy
     }
 
     @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) {
-            // 插入新记录
-            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 {
-            // 如果当前值与目标值不同,则更新
-            if (!systemProperty.getPropValue().equals(targetValue)) {
-                systemProperty.setPropValue(targetValue);
-                baseMapper.updateById(systemProperty);
-            }
+            systemProperty.setPropValue(propValue);
+            systemProperty.setUpdateTime(System.currentTimeMillis());
+            baseMapper.updateById(systemProperty);
         }
     }
 
-
 }