Bladeren bron

update sysConfig配置修改

ct 1 week geleden
bovenliggende
commit
abbb2bbfac

+ 21 - 22
fs-admin-saas/src/main/java/com/fs/his/controller/FsCompanyController.java

@@ -6,6 +6,7 @@ import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.fs.common.annotation.RepeatSubmit;
 import com.fs.common.core.domain.R;
+import com.fs.common.core.domain.model.LoginUser;
 import com.fs.common.enums.DataSourceType;
 import com.fs.common.utils.SecurityUtils;
 import com.fs.common.utils.ServletUtils;
@@ -87,16 +88,15 @@ public class FsCompanyController extends BaseController {
     @GetMapping("/list")
     public TableDataInfo list(Company company)
     {
-//        startPage();
-//        com.fs.framework.security.LoginUser loginUser = (com.fs.framework.security.LoginUser) tokenService.getLoginUser(ServletUtils.getRequest());
-//        String json = configService.selectConfigByKey("course.config");
-//        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
-//        if(!loginUser.isAdmin() && config.getDept() != null && config.getDept()){
-//            company.setDeptId(loginUser.getDeptId());
-//        }
-//        List<CompanyVO> list = companyService.selectCompanyListVO(company);
-//        return getDataTable(list);
-        throw new RuntimeException("未实现");
+        startPage();
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        String json = configService.selectConfigByKey("course.config");
+        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
+        if(!loginUser.isAdmin() && config.getDept() != null && config.getDept()){
+            company.setDeptId(loginUser.getDeptId());
+        }
+        List<CompanyVO> list = companyService.selectCompanyListVO(company);
+        return getDataTable(list);
     }
 
     @GetMapping("/companyList")
@@ -161,18 +161,17 @@ public class FsCompanyController extends BaseController {
     @PostMapping
     public R add(@RequestBody Company company, HttpServletRequest request)
     {
-//        com.fs.framework.security.LoginUser loginUser = (com.fs.framework.security.LoginUser) tokenService.getLoginUser(ServletUtils.getRequest());
-//        String json = configService.selectConfigByKey("course.config");
-//        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
-//        if(!loginUser.isAdmin() && config.getDept() != null && config.getDept()){
-//            company.setDeptId(loginUser.getDeptId());
-//        }
-//
-//        if (isQuantityExceeded(request)){
-//            return R.error("公司数量已达上限");
-//        }
-//        return companyService.insertCompany(company);
-        throw new RuntimeException("未实现");
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        String json = configService.selectConfigByKey("course.config");
+        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
+        if(!loginUser.isAdmin() && config.getDept() != null && config.getDept()){
+            company.setDeptId(loginUser.getDeptId());
+        }
+
+        if (isQuantityExceeded(request)){
+            return R.error("公司数量已达上限");
+        }
+        return companyService.insertCompany(company);
     }
 
     /**

+ 18 - 3
fs-admin/src/main/java/com/fs/web/controller/system/SysConfigController.java

@@ -134,9 +134,9 @@ public class SysConfigController extends BaseController {
                                      @RequestParam(value = "tenantId", required = false) Long tenantId) {
         SysConfig configByKey;
         if (tenantId == null) {
-            configByKey = tenantSysConfigService.getConfigByKey(configKey);
+            configByKey = configService.selectConfigByConfigKey(configKey);
         } else {
-            configByKey = tenantContextHelper.executeInTenant(tenantId, () -> tenantSysConfigService.getConfigByKey(configKey));
+            configByKey = tenantContextHelper.executeInTenant(tenantId, () -> configService.selectConfigByConfigKey(configKey));
         }
 
         return AjaxResult.success(configByKey);
@@ -150,7 +150,22 @@ public class SysConfigController extends BaseController {
     @RepeatSubmit
     public AjaxResult updateConfigByKey(@Validated @RequestBody SysConfig config) {
         config.setCreateBy(SecurityUtils.getUsername());
-        return toAjax(tenantSysConfigService.updateConfigByKey(config));
+        Long tenantId = config.getTenantId();
+        if (tenantId == null){
+            if (null != config.getConfigId()) {
+                return toAjax(configService.updateConfig(config));
+            } else {
+                return toAjax(configService.insertConfig(config));
+            }
+        } else {
+            if (null != config.getConfigId()) {
+                return toAjax(tenantContextHelper.executeInTenant(tenantId, () ->configService.updateConfig(config)));
+            } else {
+                return toAjax(tenantContextHelper.executeInTenant(tenantId, () ->configService.insertConfig(config)));
+            }
+        }
+        //修复只能更新的BUG
+
     }
 
 

+ 40 - 4
fs-agent/src/main/java/com/fs/admin/controller/CompanyAdminController.java

@@ -212,10 +212,8 @@ public class CompanyAdminController extends BaseController {
     @PostMapping("/{id}/menu/edit")
     public R tenantMenuEdit(@PathVariable String id, @RequestBody Map<String, Object> params) {
         String flag = (String) params.getOrDefault("flag", "sys");
-        @SuppressWarnings("unchecked")
-        List<Long> selected = params.get("selected") != null ? (List<Long>) params.get("selected") : new ArrayList<>();
-        @SuppressWarnings("unchecked")
-        List<Long> unSelected = params.get("unSelected") != null ? (List<Long>) params.get("unSelected") : new ArrayList<>();
+        List<Long> selected = toLongIdList(params.get("selected"));
+        List<Long> unSelected = toLongIdList(params.get("unSelected"));
 
         TenantInfo tenantInfo = tenantInfoMapper.selectTenantInfoById(id);
         if (tenantInfo == null) return R.error("租户不存在");
@@ -260,6 +258,44 @@ public class CompanyAdminController extends BaseController {
         return new ArrayList<>();
     }
 
+    private static List<Long> toLongIdList(Object raw) {
+        if (raw == null) {
+            return new ArrayList<>();
+        }
+        if (!(raw instanceof List)) {
+            return new ArrayList<>();
+        }
+        List<?> list = (List<?>) raw;
+        List<Long> result = new ArrayList<>(list.size());
+        for (Object item : list) {
+            Long id = toLongId(item);
+            if (id != null) {
+                result.add(id);
+            }
+        }
+        return result;
+    }
+
+    private static Long toLongId(Object value) {
+        if (value == null) {
+            return null;
+        }
+        if (value instanceof Long) {
+            return (Long) value;
+        }
+        if (value instanceof Number) {
+            return ((Number) value).longValue();
+        }
+        if (value instanceof String) {
+            String s = ((String) value).trim();
+            if (s.isEmpty()) {
+                return null;
+            }
+            return Long.parseLong(s);
+        }
+        return null;
+    }
+
     /**
      * 重置租户管理员密码
      */

+ 36 - 6
fs-service/src/main/java/com/fs/system/service/impl/SysConfigServiceImpl.java

@@ -232,16 +232,46 @@ public class SysConfigServiceImpl implements ISysConfigService
 
     @Override
     public SysConfig selectConfigByConfigKey(String configKey) {
-        //TODO 可以先查询这个key是否在数据库中存在,
-        // 如果不存在就返回表中id+1的数为新id,以及将查询的key作为key返回,
-        // 并在前端提示更新就可以了
-        // 否做会出现bug
-        return configMapper.selectConfigByConfigKey(configKey);
+        if (StringUtils.isEmpty(configKey)) {
+            return new SysConfig();
+        }
+        String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey)));
+        if (StringUtils.isNotEmpty(configValue)) {
+            return buildConfigFromCache(configKey, configValue);
+        }
+        Object keyLock = KEY_LOCKS.computeIfAbsent(configKey, k -> new Object());
+        synchronized (keyLock) {
+            configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey)));
+            if (StringUtils.isNotEmpty(configValue)) {
+                return buildConfigFromCache(configKey, configValue);
+            }
+            SysConfig retConfig = configMapper.selectConfigByConfigKey(configKey);
+            if (StringUtils.isNotNull(retConfig)) {
+                redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
+                return retConfig;
+            }
+            SysConfig empty = new SysConfig();
+            empty.setConfigKey(configKey);
+            return empty;
+        }
+    }
+
+    private SysConfig buildConfigFromCache(String configKey, String configValue) {
+        SysConfig config = new SysConfig();
+        config.setConfigKey(configKey);
+        config.setConfigValue(configValue);
+        SysConfig db = configMapper.selectConfigByConfigKey(configKey);
+        if (StringUtils.isNotNull(db)) {
+            config.setConfigId(db.getConfigId());
+            config.setConfigName(db.getConfigName());
+            config.setConfigType(db.getConfigType());
+        }
+        return config;
     }
 
     @Override
     public ProjectConfig getProjectConfig() {
-        SysConfig sysConfig = configMapper.selectConfigByConfigKey("projectConfig");
+        SysConfig sysConfig = selectConfigByConfigKey("projectConfig");
         if (sysConfig == null || StringUtils.isEmpty(sysConfig.getConfigValue())) {
             return null;
         }