mirror of https://gitee.com/stylefeng/roses
【7.1.6】【theme】更新获取主题的接口
parent
76f38094b3
commit
1a55b4db8b
|
@ -67,4 +67,9 @@ public interface SystemCachesConstants {
|
||||||
*/
|
*/
|
||||||
String ROLE_DATA_SCOPE_CACHE_PREFIX = "role_data_scope:";
|
String ROLE_DATA_SCOPE_CACHE_PREFIX = "role_data_scope:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统主题的缓存
|
||||||
|
*/
|
||||||
|
String SYSTEM_THEME_CACHE_PREFIX = "system_cache:";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,5 +61,26 @@
|
||||||
<artifactId>file-business</artifactId>
|
<artifactId>file-business</artifactId>
|
||||||
<version>${roses.version}</version>
|
<version>${roses.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--缓存api-->
|
||||||
|
<!--默认主题查询到会缓存-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.stylefeng.roses</groupId>
|
||||||
|
<artifactId>cache-api</artifactId>
|
||||||
|
<version>${roses.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.stylefeng.roses</groupId>
|
||||||
|
<artifactId>cache-sdk-memory</artifactId>
|
||||||
|
<version>${roses.version}</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.stylefeng.roses</groupId>
|
||||||
|
<artifactId>cache-sdk-redis</artifactId>
|
||||||
|
<version>${roses.version}</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||||
|
*
|
||||||
|
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||||
|
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||||
|
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||||
|
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||||
|
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||||
|
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||||
|
*/
|
||||||
|
package cn.stylefeng.roses.kernel.system.modular.theme.cache;
|
||||||
|
|
||||||
|
import cn.hutool.cache.impl.TimedCache;
|
||||||
|
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
|
||||||
|
import cn.stylefeng.roses.kernel.system.api.constants.SystemCachesConstants;
|
||||||
|
import cn.stylefeng.roses.kernel.system.modular.theme.pojo.DefaultTheme;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统主题缓存
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2022/1/11 9:37
|
||||||
|
*/
|
||||||
|
public class ThemeMemoryCache extends AbstractMemoryCacheOperator<DefaultTheme> {
|
||||||
|
|
||||||
|
public ThemeMemoryCache(TimedCache<String, DefaultTheme> timedCache) {
|
||||||
|
super(timedCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommonKeyPrefix() {
|
||||||
|
return SystemCachesConstants.SYSTEM_THEME_CACHE_PREFIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||||
|
*
|
||||||
|
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||||
|
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||||
|
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||||
|
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||||
|
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||||
|
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||||
|
*/
|
||||||
|
package cn.stylefeng.roses.kernel.system.modular.theme.cache;
|
||||||
|
|
||||||
|
import cn.stylefeng.roses.kernel.cache.redis.AbstractRedisCacheOperator;
|
||||||
|
import cn.stylefeng.roses.kernel.system.api.constants.SystemCachesConstants;
|
||||||
|
import cn.stylefeng.roses.kernel.system.modular.theme.pojo.DefaultTheme;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统主题缓存
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2022/1/11 9:37
|
||||||
|
*/
|
||||||
|
public class ThemeRedisCache extends AbstractRedisCacheOperator<DefaultTheme> {
|
||||||
|
|
||||||
|
public ThemeRedisCache(RedisTemplate<String, DefaultTheme> redisTemplate) {
|
||||||
|
super(redisTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCommonKeyPrefix() {
|
||||||
|
return SystemCachesConstants.SYSTEM_THEME_CACHE_PREFIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package cn.stylefeng.roses.kernel.system.modular.theme.controller;
|
||||||
|
|
||||||
|
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||||
|
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||||
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
||||||
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
||||||
|
import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeRequest;
|
||||||
|
import cn.stylefeng.roses.kernel.system.modular.theme.pojo.DefaultTheme;
|
||||||
|
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeService;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主题开放接口的API
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2022/1/10 18:27
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@ApiResource(name = "主题开放接口的API")
|
||||||
|
public class SysThemeApiController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysThemeService sysThemeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前Guns管理系统的主题数据
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2022/1/10 18:29
|
||||||
|
*/
|
||||||
|
@PostResource(name = "获取当前Guns管理系统的主题数据", path = "/theme/currentThemeInfo", requiredPermission = false, requiredLogin = false)
|
||||||
|
public ResponseData currentThemeInfo(SysThemeRequest sysThemeParam) {
|
||||||
|
DefaultTheme defaultTheme = sysThemeService.currentThemeInfo(sysThemeParam);
|
||||||
|
return new SuccessResponseData(defaultTheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
package cn.stylefeng.roses.kernel.system.modular.theme.factory;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.stylefeng.roses.kernel.system.modular.theme.pojo.DefaultTheme;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.beans.IntrospectionException;
|
||||||
|
import java.beans.PropertyDescriptor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果当前激活的系统主题没有,或者获取不到,则使用本类创建的默认系统主题
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2022/1/11 9:30
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class DefaultThemeFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统默认主题
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2022/1/11 9:31
|
||||||
|
*/
|
||||||
|
public static DefaultTheme getSystemDefaultTheme() {
|
||||||
|
DefaultTheme defaultTheme = new DefaultTheme();
|
||||||
|
defaultTheme.setGunsMgrBeiUrl("https://beian.miit.gov.cn/");
|
||||||
|
defaultTheme.setGunsMgrBeiNo("京ICP备001-1");
|
||||||
|
defaultTheme.setGunsMgrFavicon("1479753047148322818");
|
||||||
|
defaultTheme.setGunsMgrFooterText("stylefeng开源技术 javaguns.com");
|
||||||
|
defaultTheme.setGunsMgrLogo("1479753047148322818");
|
||||||
|
defaultTheme.setGunsMgrName("Guns Tech.");
|
||||||
|
defaultTheme.setGunsMgrLoginBackgroundImg("1479751422149074948");
|
||||||
|
return defaultTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过jsonObject解析默认主题数据
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2022/1/11 9:31
|
||||||
|
*/
|
||||||
|
public static DefaultTheme parseDefaultTheme(JSONObject jsonObject) {
|
||||||
|
|
||||||
|
// 初始化主题参数
|
||||||
|
DefaultTheme defaultTheme = new DefaultTheme();
|
||||||
|
|
||||||
|
// 存放没有被set值的key列表
|
||||||
|
ArrayList<String> noneSetKeys = new ArrayList<>();
|
||||||
|
|
||||||
|
// 遍历Key值,为对应的key属性赋值
|
||||||
|
for (String jsonObjectKey : jsonObject.keySet()) {
|
||||||
|
String propertyName = StrUtil.toCamelCase(jsonObjectKey);
|
||||||
|
try {
|
||||||
|
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(propertyName, DefaultTheme.class);
|
||||||
|
Method writeMethod = propertyDescriptor.getWriteMethod();
|
||||||
|
writeMethod.invoke(defaultTheme, jsonObject.getString(jsonObjectKey));
|
||||||
|
} catch (IntrospectionException | InvocationTargetException | IllegalAccessException e) {
|
||||||
|
noneSetKeys.add(jsonObjectKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 遍历没有被set值的key,放到单独的map中
|
||||||
|
HashMap<String, String> otherInfos = new HashMap<>();
|
||||||
|
for (String noneSetKey : noneSetKeys) {
|
||||||
|
String propertyName = StrUtil.toCamelCase(noneSetKey);
|
||||||
|
String value = jsonObject.getString(noneSetKey);
|
||||||
|
otherInfos.put(propertyName, value);
|
||||||
|
}
|
||||||
|
defaultTheme.setOtherConfigs(otherInfos);
|
||||||
|
|
||||||
|
return defaultTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
DefaultTheme defaultTheme = new DefaultTheme();
|
||||||
|
PropertyDescriptor propertyDescriptor = new PropertyDescriptor("abc", DefaultTheme.class);
|
||||||
|
Method writeMethod = propertyDescriptor.getWriteMethod();
|
||||||
|
writeMethod.invoke(defaultTheme, "123123");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
package cn.stylefeng.roses.kernel.system.modular.theme.pojo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guns默认主题控制的字段
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2022/1/10 18:30
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class DefaultTheme {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 平台名称
|
||||||
|
*/
|
||||||
|
private String gunsMgrName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录页背景图片
|
||||||
|
*/
|
||||||
|
private String gunsMgrLoginBackgroundImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 平台LOGO
|
||||||
|
*/
|
||||||
|
private String gunsMgrLogo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 浏览器Icon
|
||||||
|
*/
|
||||||
|
private String gunsMgrFavicon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页脚文字
|
||||||
|
*/
|
||||||
|
private String gunsMgrFooterText;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备案号
|
||||||
|
*/
|
||||||
|
private String gunsMgrBeiNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备案号跳转链接
|
||||||
|
*/
|
||||||
|
private String gunsMgrBeiUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 其他的主题配置
|
||||||
|
*/
|
||||||
|
private Map<String, String> otherConfigs;
|
||||||
|
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||||
import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeDTO;
|
import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeDTO;
|
||||||
import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeRequest;
|
import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeRequest;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysTheme;
|
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysTheme;
|
||||||
|
import cn.stylefeng.roses.kernel.system.modular.theme.pojo.DefaultTheme;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,4 +64,13 @@ public interface SysThemeService extends IService<SysTheme> {
|
||||||
* @date 2021/12/17 17:06
|
* @date 2021/12/17 17:06
|
||||||
*/
|
*/
|
||||||
void updateThemeStatus(SysThemeRequest sysThemeRequest);
|
void updateThemeStatus(SysThemeRequest sysThemeRequest);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前系统主题数据
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2022/1/10 18:30
|
||||||
|
*/
|
||||||
|
DefaultTheme currentThemeInfo(SysThemeRequest sysThemeParam);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,10 @@ package cn.stylefeng.roses.kernel.system.modular.theme.service.impl;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||||
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||||
|
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||||
import cn.stylefeng.roses.kernel.file.api.FileInfoApi;
|
import cn.stylefeng.roses.kernel.file.api.FileInfoApi;
|
||||||
import cn.stylefeng.roses.kernel.file.api.pojo.request.SysFileInfoRequest;
|
import cn.stylefeng.roses.kernel.file.api.pojo.request.SysFileInfoRequest;
|
||||||
|
@ -12,6 +14,7 @@ import cn.stylefeng.roses.kernel.file.api.pojo.response.SysFileInfoResponse;
|
||||||
import cn.stylefeng.roses.kernel.file.modular.service.SysFileInfoService;
|
import cn.stylefeng.roses.kernel.file.modular.service.SysFileInfoService;
|
||||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||||
import cn.stylefeng.roses.kernel.system.api.ThemeServiceApi;
|
import cn.stylefeng.roses.kernel.system.api.ThemeServiceApi;
|
||||||
|
import cn.stylefeng.roses.kernel.system.api.constants.SystemConstants;
|
||||||
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
|
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
|
||||||
import cn.stylefeng.roses.kernel.system.api.exception.enums.theme.SysThemeExceptionEnum;
|
import cn.stylefeng.roses.kernel.system.api.exception.enums.theme.SysThemeExceptionEnum;
|
||||||
import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeDTO;
|
import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeDTO;
|
||||||
|
@ -20,8 +23,10 @@ import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysTheme;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplate;
|
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplate;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplateField;
|
import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplateField;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.theme.enums.FieldTypeEnum;
|
import cn.stylefeng.roses.kernel.system.modular.theme.enums.FieldTypeEnum;
|
||||||
|
import cn.stylefeng.roses.kernel.system.modular.theme.factory.DefaultThemeFactory;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.theme.mapper.SysThemeMapper;
|
import cn.stylefeng.roses.kernel.system.modular.theme.mapper.SysThemeMapper;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.theme.pojo.AntdvFileInfo;
|
import cn.stylefeng.roses.kernel.system.modular.theme.pojo.AntdvFileInfo;
|
||||||
|
import cn.stylefeng.roses.kernel.system.modular.theme.pojo.DefaultTheme;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeService;
|
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeService;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateFieldService;
|
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateFieldService;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateService;
|
import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateService;
|
||||||
|
@ -31,6 +36,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -47,6 +53,7 @@ import java.util.stream.Collectors;
|
||||||
* @date 2021/12/17 16:17
|
* @date 2021/12/17 16:17
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class SysThemeServiceImpl extends ServiceImpl<SysThemeMapper, SysTheme> implements SysThemeService, ThemeServiceApi {
|
public class SysThemeServiceImpl extends ServiceImpl<SysThemeMapper, SysTheme> implements SysThemeService, ThemeServiceApi {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -61,10 +68,14 @@ public class SysThemeServiceImpl extends ServiceImpl<SysThemeMapper, SysTheme> i
|
||||||
@Resource
|
@Resource
|
||||||
private FileInfoApi fileInfoApi;
|
private FileInfoApi fileInfoApi;
|
||||||
|
|
||||||
|
@Resource(name = "themeCacheApi")
|
||||||
|
private CacheOperatorApi<DefaultTheme> themeCacheApi;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(SysThemeRequest sysThemeRequest) {
|
public void add(SysThemeRequest sysThemeRequest) {
|
||||||
// 查询模板状态
|
// 查询模板状态
|
||||||
SysThemeTemplate sysThemeTemplate = sysThemeTemplateService.getById(sysThemeRequest.getTemplateId());
|
SysThemeTemplate sysThemeTemplate = sysThemeTemplateService.getById(sysThemeRequest.getTemplateId());
|
||||||
|
|
||||||
// 判断模板启用状态:如果为禁用状态不允许使用
|
// 判断模板启用状态:如果为禁用状态不允许使用
|
||||||
if (YesOrNotEnum.N.getCode().equals(sysThemeTemplate.getStatusFlag().toString())) {
|
if (YesOrNotEnum.N.getCode().equals(sysThemeTemplate.getStatusFlag().toString())) {
|
||||||
throw new SystemModularException(SysThemeExceptionEnum.THEME_TEMPLATE_IS_DISABLE);
|
throw new SystemModularException(SysThemeExceptionEnum.THEME_TEMPLATE_IS_DISABLE);
|
||||||
|
@ -218,6 +229,30 @@ public class SysThemeServiceImpl extends ServiceImpl<SysThemeMapper, SysTheme> i
|
||||||
this.updateById(sysTheme);
|
this.updateById(sysTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DefaultTheme currentThemeInfo(SysThemeRequest sysThemeParam) {
|
||||||
|
|
||||||
|
// 获取缓存中是否有默认主题
|
||||||
|
DefaultTheme defaultTheme = themeCacheApi.get(SystemConstants.THEME_GUNS_PLATFORM);
|
||||||
|
if (defaultTheme != null) {
|
||||||
|
return defaultTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询系统中激活的主题
|
||||||
|
DefaultTheme result = null;
|
||||||
|
try {
|
||||||
|
result = this.querySystemTheme();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取当前系统主题出错", e);
|
||||||
|
return DefaultThemeFactory.getSystemDefaultTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 缓存系统中激活的主题
|
||||||
|
themeCacheApi.put(SystemConstants.THEME_GUNS_PLATFORM, result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询单个系统主题
|
* 查询单个系统主题
|
||||||
*
|
*
|
||||||
|
@ -231,4 +266,44 @@ public class SysThemeServiceImpl extends ServiceImpl<SysThemeMapper, SysTheme> i
|
||||||
}
|
}
|
||||||
return sysTheme;
|
return sysTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查找系统中默认的主题
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2022/1/11 9:44
|
||||||
|
*/
|
||||||
|
private DefaultTheme querySystemTheme() {
|
||||||
|
|
||||||
|
// 查询编码为GUNS_PLATFORM的主题模板id
|
||||||
|
LambdaQueryWrapper<SysThemeTemplate> sysThemeTemplateLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
sysThemeTemplateLambdaQueryWrapper.eq(SysThemeTemplate::getTemplateCode, SystemConstants.THEME_GUNS_PLATFORM);
|
||||||
|
SysThemeTemplate sysThemeTemplate = this.sysThemeTemplateService.getOne(sysThemeTemplateLambdaQueryWrapper, false);
|
||||||
|
if (sysThemeTemplate == null) {
|
||||||
|
log.error("当前系统主题模板编码GUNS_PLATFORM不存在,请检查数据库数据是否正常!");
|
||||||
|
return DefaultThemeFactory.getSystemDefaultTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找改模板激活的主题,如果没有就返回默认主题
|
||||||
|
LambdaQueryWrapper<SysTheme> sysThemeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
sysThemeLambdaQueryWrapper.eq(SysTheme::getTemplateId, sysThemeTemplate.getTemplateId());
|
||||||
|
sysThemeLambdaQueryWrapper.eq(SysTheme::getStatusFlag, YesOrNotEnum.Y.getCode());
|
||||||
|
sysThemeLambdaQueryWrapper.orderByDesc(BaseEntity::getCreateTime);
|
||||||
|
SysTheme sysTheme = this.getOne(sysThemeLambdaQueryWrapper, false);
|
||||||
|
if (sysTheme == null) {
|
||||||
|
log.error("当前系统主题模板编码为GUNS_PLATFORM的主题不存在,请检查数据库数据是否正常!");
|
||||||
|
return DefaultThemeFactory.getSystemDefaultTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析主题中的json字符串
|
||||||
|
String themeValue = sysTheme.getThemeValue();
|
||||||
|
if (StrUtil.isBlank(themeValue)) {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(themeValue);
|
||||||
|
return DefaultThemeFactory.parseDefaultTheme(jsonObject);
|
||||||
|
} else {
|
||||||
|
return DefaultThemeFactory.getSystemDefaultTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,8 @@ import cn.stylefeng.roses.kernel.system.modular.role.cache.RoleDataScopeMemoryCa
|
||||||
import cn.stylefeng.roses.kernel.system.modular.role.cache.RoleMemoryCache;
|
import cn.stylefeng.roses.kernel.system.modular.role.cache.RoleMemoryCache;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.role.cache.RoleResourceMemoryCache;
|
import cn.stylefeng.roses.kernel.system.modular.role.cache.RoleResourceMemoryCache;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRole;
|
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRole;
|
||||||
|
import cn.stylefeng.roses.kernel.system.modular.theme.cache.ThemeMemoryCache;
|
||||||
|
import cn.stylefeng.roses.kernel.system.modular.theme.pojo.DefaultTheme;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.user.cache.SysUserMemoryCache;
|
import cn.stylefeng.roses.kernel.system.modular.user.cache.SysUserMemoryCache;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.user.cache.UserOrgMemoryCache;
|
import cn.stylefeng.roses.kernel.system.modular.user.cache.UserOrgMemoryCache;
|
||||||
import cn.stylefeng.roses.kernel.system.modular.user.cache.UserRoleMemoryCache;
|
import cn.stylefeng.roses.kernel.system.modular.user.cache.UserRoleMemoryCache;
|
||||||
|
@ -130,4 +132,17 @@ public class GunsSystemCacheAutoConfiguration {
|
||||||
return new RoleDataScopeMemoryCache(roleCache);
|
return new RoleDataScopeMemoryCache(roleCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主题的缓存
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/7/31 17:59
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(name = "themeCacheApi")
|
||||||
|
public CacheOperatorApi<DefaultTheme> themeCacheApi() {
|
||||||
|
TimedCache<String, DefaultTheme> themeCache = CacheUtil.newTimedCache(Long.MAX_VALUE);
|
||||||
|
return new ThemeMemoryCache(themeCache);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue