【7.6.0】【sys】整理starter模块

pull/57/head
fengshuonan 2023-06-18 09:52:29 +08:00
parent 24243e7e02
commit a123ebaa3f
11 changed files with 555 additions and 6 deletions

View File

@ -47,4 +47,14 @@ public interface SysConstants {
*/
String DEFAULT_LOGIN_PASSWORD = "Aa123456!";
/**
*
*/
String SUPER_ADMIN_ROLE_CODE = "superAdmin";
/**
*
*/
Integer SUPER_ADMIN_INIT_LISTENER_SORT = 400;
}

View File

@ -22,7 +22,135 @@
<groupId>cn.stylefeng.roses</groupId>
<artifactId>sys-business-hr</artifactId>
<version>${roses.version}</version>
</dependency>
</dependency>
<!--应用权限管理模块-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>sys-business-permission</artifactId>
<version>${roses.version}</version>
</dependency>
<!--门户业务-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>sys-business-portal</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>
<!--将常用的模块集成在system中主项目中保持简洁-->
<!--认证和鉴权模块-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>auth-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
<!--安全模块-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>security-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
<!--数据源连接和dao框架-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>db-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
<!--文件管理-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>file-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
<!--资源扫描-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>scanner-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
<!--字典业务-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>dict-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
<!--c端用户-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>customer-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
<!--日志模块-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>log-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
<!--定时任务-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>timer-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
<!--Socket模块-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>socket-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
<!--wrapper工具-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>wrapper-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
<!--多数据源配置-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>ds-container-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
<!--硬件信息获取-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>monitor-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
<!--字段拓展信息-->
<dependency>
<groupId>cn.stylefeng.roses</groupId>
<artifactId>expand-spring-boot-starter</artifactId>
<version>${roses.version}</version>
</dependency>
</dependencies>

View File

@ -0,0 +1,40 @@
package cn.stylefeng.roses.kernel.sys.starter;
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
import cn.stylefeng.roses.kernel.rule.util.ResponseRenderUtil;
import org.springframework.web.servlet.View;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
/**
* 404
*
* @author fengshuonan
* @since 2021/5/17 10:45
*/
public class ErrorStaticJsonView implements View {
@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
if (response.isCommitted()) {
// response已经提交不能响应
return;
}
// 如果是运维平台404Redirect到首页
if (model.get("path") != null && String.valueOf(model.get("path")).startsWith("/guns-devops")) {
response.sendRedirect("/guns-devops");
} else {
ErrorResponseData<Object> errorResponseData = new ErrorResponseData<>("404", "请求资源不存在");
ResponseRenderUtil.renderJsonResponse(response, errorResponseData);
}
}
@Override
public String getContentType() {
return "text/html";
}
}

View File

@ -0,0 +1,59 @@
/*
* 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.
*
* GunsAPACHE 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.sys.starter.cache;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.cache.api.constants.CacheConstants;
import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.ResourceDefinition;
import cn.stylefeng.roses.kernel.sys.modular.resource.cache.MemoryResourceCache;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
*
* @author fengshuonan
* @since 2021/5/17 16:44
*/
@Configuration
@ConditionalOnMissingClass("org.springframework.data.redis.connection.RedisConnectionFactory")
public class ResourceMemoryCacheAutoConfiguration {
/**
*
*
* @author fengshuonan
* @since 2021/5/17 16:44
*/
@Bean
public CacheOperatorApi<ResourceDefinition> resourceCache() {
TimedCache<String, ResourceDefinition> timedCache = CacheUtil.newTimedCache(CacheConstants.NONE_EXPIRED_TIME);
return new MemoryResourceCache(timedCache);
}
}

View File

@ -0,0 +1,59 @@
/*
* 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.
*
* GunsAPACHE 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.sys.starter.cache;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.cache.redis.util.CreateRedisTemplateUtil;
import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.ResourceDefinition;
import cn.stylefeng.roses.kernel.sys.modular.resource.cache.RedisResourceCache;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
/**
* Redis
*
* @author fengshuonan
* @since 2022/11/8 23:26
*/
@Configuration
@ConditionalOnClass(name = "org.springframework.data.redis.connection.RedisConnectionFactory")
public class ResourceRedisCacheAutoConfiguration {
/**
*
*
* @author fengshuonan
* @since 2022/11/8 23:27
*/
@Bean
public CacheOperatorApi<ResourceDefinition> resourceCache(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, ResourceDefinition> redisTemplate = CreateRedisTemplateUtil.createObject(redisConnectionFactory);
return new RedisResourceCache(redisTemplate);
}
}

View File

@ -22,17 +22,37 @@
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.sys.starter;
package cn.stylefeng.roses.kernel.sys.starter.cache;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.sys.modular.theme.cache.ThemeMemoryCache;
import cn.stylefeng.roses.kernel.sys.modular.theme.pojo.DefaultTheme;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
*
*
* @author fengshuonan
* @date 2023-06-10 20:50:43
* @since 2021/2/28 10:29
*/
@Configuration
public class SysAutoConfiguration {
@ConditionalOnMissingClass("org.springframework.data.redis.connection.RedisConnectionFactory")
public class SystemMemoryCacheAutoConfiguration {
/**
*
*
* @author fengshuonan
* @since 2021/7/31 17:59
*/
@Bean
public CacheOperatorApi<DefaultTheme> themeCacheApi() {
TimedCache<String, DefaultTheme> themeCache = CacheUtil.newTimedCache(Long.MAX_VALUE);
return new ThemeMemoryCache(themeCache);
}
}

View File

@ -0,0 +1,59 @@
/*
* 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.
*
* GunsAPACHE 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.sys.starter.cache;
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
import cn.stylefeng.roses.kernel.cache.redis.util.CreateRedisTemplateUtil;
import cn.stylefeng.roses.kernel.sys.modular.theme.cache.ThemeRedisCache;
import cn.stylefeng.roses.kernel.sys.modular.theme.pojo.DefaultTheme;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
/**
* Redis
*
* @author fengshuonan
* @since 2022/11/8 23:26
*/
@Configuration
@ConditionalOnClass(name = "org.springframework.data.redis.connection.RedisConnectionFactory")
public class SystemRedisCacheAutoConfiguration {
/**
*
*
* @author fengshuonan
* @since 2022/11/8 23:32
*/
@Bean
public CacheOperatorApi<DefaultTheme> themeCacheApi(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, DefaultTheme> redisTemplate = CreateRedisTemplateUtil.createObject(redisConnectionFactory);
return new ThemeRedisCache(redisTemplate);
}
}

View File

@ -0,0 +1,32 @@
package cn.stylefeng.roses.kernel.sys.starter.config;
import cn.stylefeng.roses.kernel.sys.starter.ErrorStaticJsonView;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 404
*
* @author fengshuonan
* @since 2021/5/17 11:16
*/
@Configuration
@AutoConfigureBefore(ErrorMvcAutoConfiguration.class)
public class RestErrorViewAutoConfiguration {
/**
* json
*
* @author fengshuonan
* @since 2020/12/16 15:47
*/
@Bean("error")
@ConditionalOnMissingBean(name = "error")
public ErrorStaticJsonView error() {
return new ErrorStaticJsonView();
}
}

View File

@ -0,0 +1,75 @@
/*
* 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.
*
* GunsAPACHE 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.sys.starter.init;
import cn.stylefeng.roses.kernel.sys.api.constants.SysConstants;
import cn.stylefeng.roses.kernel.sys.modular.resource.service.SysResourceService;
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRole;
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleResourceService;
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
/**
* admin
*
* @author fengshuonan
* @since 2020/12/17 21:56
*/
@Service
public class InitAdminService {
@Resource
private SysRoleService sysRoleService;
@Resource
private SysResourceService sysResourceService;
@Resource
private SysRoleResourceService sysRoleResourceService;
/**
*
*
* @author fengshuonan
* @since 2020/12/17 21:57
*/
@Transactional(rollbackFor = Exception.class)
public void initSuperAdmin() {
// 找到超级管理员的角色id
LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysRole::getRoleCode, SysConstants.SUPER_ADMIN_ROLE_CODE);
SysRole superAdminRole = sysRoleService.getOne(queryWrapper);
// todo 超级管理员绑定所有的菜单 和 菜单功能
}
}

View File

@ -0,0 +1,62 @@
/*
* 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.
*
* GunsAPACHE 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.sys.starter.listener;
import cn.stylefeng.roses.kernel.rule.listener.ApplicationReadyListener;
import cn.stylefeng.roses.kernel.sys.api.constants.SysConstants;
import cn.stylefeng.roses.kernel.sys.starter.init.InitAdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
*
*
* @author fengshuonan
* @since 2020/12/17 21:44
*/
@Component
@Slf4j
public class SuperAdminInitListener extends ApplicationReadyListener implements Ordered {
@Resource
private InitAdminService initAdminService;
@Override
public void eventCallback(ApplicationReadyEvent event) {
long startTime = System.currentTimeMillis();
initAdminService.initSuperAdmin();
log.info("初始化超级管理员权限完成,耗时:{}ms", (System.currentTimeMillis() - startTime));
}
@Override
public int getOrder() {
return SysConstants.SUPER_ADMIN_INIT_LISTENER_SORT;
}
}

View File

@ -1,2 +1,7 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.stylefeng.roses.kernel.sys.starter.SysAutoConfiguration
cn.stylefeng.roses.kernel.sys.starter.cache.SystemMemoryCacheAutoConfiguration,\
cn.stylefeng.roses.kernel.sys.starter.cache.SystemRedisCacheAutoConfiguration,\
cn.stylefeng.roses.kernel.sys.starter.cache.ResourceMemoryCacheAutoConfiguration,\
cn.stylefeng.roses.kernel.sys.starter.cache.ResourceRedisCacheAutoConfiguration,\
cn.stylefeng.roses.kernel.sys.starter.SystemHomeStatisticsAutoConfiguration,\
cn.stylefeng.roses.kernel.sys.starter.config.RestErrorViewAutoConfiguration