From 2152260c1fbeafedff72bcd8a7134dc3b4af90f7 Mon Sep 17 00:00:00 2001 From: pbn32vpxk <3032484890@qq.com> Date: Sun, 15 Dec 2024 21:44:56 +0800 Subject: [PATCH] 1 (#4) --- .idea/.gitignore | 8 + .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/tamguo.iml | 11 + .idea/uiDesigner.xml | 124 ++++ .idea/vcs.xml | 6 + .../config/dao/MyMetaObjectHandler.java | 19 +- .../tamguo/config/dao/MybatisPlusConfig.java | 57 +- .../com/tamguo/config/shiro/MemberRealm.java | 89 ++- .../config/shiro/ShiroConfiguration.java | 43 +- .../tamguo/config/web/ErrorConfigurar.java | 29 +- .../tamguo/config/web/ThymeleafConfig.java | 85 ++- .../java/com/tamguo/config/web/WebConfig.java | 70 ++- .../java/com/tamguo/utils/FileMd5Utils.java | 47 +- .../java/com/tamguo/utils/ShiroUtils.java | 57 +- .../com/tamguo/web/AccountController.java | 62 +- .../tamguo/web/BookCategoryController.java | 94 +-- .../java/com/tamguo/web/BookController.java | 158 +++-- .../com/tamguo/web/DocumentController.java | 244 ++++---- .../java/com/tamguo/web/EmailController.java | 43 +- .../java/com/tamguo/web/FileController.java | 112 ++-- .../com/tamguo/web/HistoryDocController.java | 88 ++- .../java/com/tamguo/web/IndexController.java | 38 +- .../java/com/tamguo/web/LoginController.java | 104 +++- .../java/com/tamguo/web/LogoutController.java | 33 +- .../com/tamguo/web/PasswordController.java | 136 +++-- .../com/tamguo/web/RegisterController.java | 60 +- .../java/com/tamguo/web/SmsController.java | 23 +- .../web/interceptor/MemberInterceptor.java | 82 +-- .../com/tamguo/config/redis/CacheService.java | 301 ++++----- .../tamguo/config/redis/PoolConfigBean.java | 46 +- .../config/redis/RedisServerNodeBean.java | 63 +- .../config/redis/RedisXMLConfigure.java | 209 ++++--- .../book/model/BookCategoryEntity.java | 40 +- .../tamguo/modules/book/model/BookEntity.java | 40 +- .../modules/book/model/DocumentEntity.java | 57 +- .../tamguo/modules/book/model/FileEntity.java | 19 +- .../modules/book/model/FileUploadEntity.java | 34 +- .../modules/book/model/enums/BizTypeEnum.java | 36 +- .../book/model/enums/DocumentStatusEnum.java | 39 +- .../model/enums/FileUploadStatusEnum.java | 39 +- .../book/service/impl/BookServiceImpl.java | 32 +- .../service/impl/DocumentServiceImpl.java | 61 +- .../modules/member/model/MemberEntity.java | 21 +- .../model/condition/MemberCondition.java | 64 +- .../member/service/impl/MemberService.java | 571 ++++++++++++++++-- .../modules/sys/model/SysAreaEntity.java | 39 +- .../modules/sys/model/SysCompanyEntity.java | 34 +- .../modules/sys/model/SysMenuEntity.java | 45 +- .../modules/sys/model/SysOfficeEntity.java | 38 +- .../modules/sys/model/SysPostEntity.java | 26 +- .../modules/sys/model/SysUserEntity.java | 92 ++- .../sys/model/condition/SysUserCondition.java | 198 +++++- .../modules/tiku/model/ChapterEntity.java | 67 +- .../modules/tiku/model/CourseEntity.java | 75 ++- .../tiku/model/condition/BookCondition.java | 75 ++- .../model/condition/ChapterCondition.java | 64 +- .../tiku/model/condition/CourseCondition.java | 75 ++- .../model/condition/SubjectCondition.java | 66 +- .../tiku/model/enums/QuestionTypeEnum.java | 133 ++-- .../tiku/service/impl/ChapterServiceImpl.java | 287 +++++---- .../tiku/service/impl/CourseServiceImpl.java | 240 +++++--- .../service/impl/KnowPointServiceImpl.java | 253 +++++--- .../tiku/service/impl/MenuServiceImpl.java | 77 ++- .../tiku/service/impl/PaperServiceImpl.java | 163 +++-- .../service/impl/QuestionServiceImpl.java | 105 +++- .../tiku/service/impl/SchoolService.java | 51 +- .../tiku/service/impl/SubjectServiceImpl.java | 80 ++- 68 files changed, 4251 insertions(+), 1640 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/tamguo.iml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a9ea907 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/tamguo.iml b/.idea/tamguo.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/.idea/tamguo.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/config/dao/MyMetaObjectHandler.java b/tamguo-mms/src/main/java/com/tamguo/config/dao/MyMetaObjectHandler.java index 9b0c21d..58ae1c7 100644 --- a/tamguo-mms/src/main/java/com/tamguo/config/dao/MyMetaObjectHandler.java +++ b/tamguo-mms/src/main/java/com/tamguo/config/dao/MyMetaObjectHandler.java @@ -8,16 +8,29 @@ import org.slf4j.LoggerFactory; /** * 注入公共字段自动填充,任选注入方式即可 */ -//@Component +// 可以将 @Component 注释添加在这里,以将该类注册为 Spring 组件 public class MyMetaObjectHandler extends MetaObjectHandler { + // 定义一个静态的日志记录器 protected final static Logger logger = LoggerFactory.getLogger(MyMetaObjectHandler.class); - + + /** + * 在插入操作时进行字段填充的方法 + * + * @param metaObject 元对象 + */ @Override public void insertFill(MetaObject metaObject) { } + /** + * 在更新操作时进行字段填充的方法 + + * + * + * @param metaObject 元对象 + */ @Override public void updateFill(MetaObject metaObject) { } -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/config/dao/MybatisPlusConfig.java b/tamguo-mms/src/main/java/com/tamguo/config/dao/MybatisPlusConfig.java index 47d0386..b312f53 100644 --- a/tamguo-mms/src/main/java/com/tamguo/config/dao/MybatisPlusConfig.java +++ b/tamguo-mms/src/main/java/com/tamguo/config/dao/MybatisPlusConfig.java @@ -19,50 +19,58 @@ import com.baomidou.mybatisplus.plugins.parser.tenant.TenantSqlParser; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.LongValue; -@Configuration -@MapperScan("com.tamguo.modules.*.dao*") +/** + * MybatisPlusConfig 类,用于配置 Mybatis-Plus 的相关设置 + */ +@Configuration // 表示这是一个配置类 +@MapperScan("com.tamguo.modules.*.dao*") // 扫描指定包下的 Mapper 接口 public class MybatisPlusConfig { + /** + * 创建 PerformanceInterceptor 实例的方法 + * @return PerformanceInterceptor 性能拦截器实例 + */ @Bean public PerformanceInterceptor performanceInterceptor() { - return new PerformanceInterceptor(); + return new PerformanceInterceptor(); // 创建并返回性能拦截器实例 } /** - * mybatis-plus分页插件
- * 文档:http://mp.baomidou.com
+ * 创建 PaginationInterceptor 分页拦截器实例的方法 + * @return PaginationInterceptor 分页拦截器实例 */ @Bean public PaginationInterceptor paginationInterceptor() { - PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); - paginationInterceptor.setLocalPage(true);// 开启 PageHelper 的支持 + PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); // 创建分页拦截器实例 + paginationInterceptor.setLocalPage(true); // 开启 PageHelper 的支持 + /* - * 【测试多租户】 SQL 解析处理拦截器
- * 这里固定写成住户 1 实际情况你可以从cookie读取,因此数据看不到 【 麻花藤 】 这条记录( 注意观察 SQL )
+ * 【测试多租户】SQL 解析处理拦截器相关设置 */ - List sqlParserList = new ArrayList<>(); - TenantSqlParser tenantSqlParser = new TenantSqlParser(); - tenantSqlParser.setTenantHandler(new TenantHandler() { + List sqlParserList = new ArrayList<>(); // 创建 SQL 解析器列表 + TenantSqlParser tenantSqlParser = new TenantSqlParser(); // 创建租户 SQL 解析器实例 + + tenantSqlParser.setTenantHandler(new TenantHandler() { // 设置租户处理逻辑 @Override public Expression getTenantId() { - return new LongValue(1L); + return new LongValue(1L); // 返回表示租户 ID 的表达式 } @Override public String getTenantIdColumn() { - return "course_id"; + return "course_id"; // 返回租户 ID 所在的列名 } @Override public boolean doTableFilter(String tableName) { // 这里可以判断是否过滤表 - return true; + return true; // 返回是否过滤表的标志 } }); + sqlParserList.add(tenantSqlParser); // 将租户 SQL 解析器添加到列表中 + paginationInterceptor.setSqlParserList(sqlParserList); // 设置分页拦截器的 SQL 解析器列表 - sqlParserList.add(tenantSqlParser); - paginationInterceptor.setSqlParserList(sqlParserList); // 以下过滤方式与 @SqlParser(filter = true) 注解等效 // paginationInterceptor.setSqlParserFilter(new ISqlParserFilter() { // @Override @@ -78,16 +86,23 @@ public class MybatisPlusConfig { return paginationInterceptor; } + /** + * 创建 MetaObjectHandler 实例的方法 + * @return MetaObjectHandler 元对象处理实例 + */ + @Bean public MetaObjectHandler metaObjectHandler(){ - return new MyMetaObjectHandler(); + return new MyMetaObjectHandler(); // 创建并返回元对象处理实例 } /** - * 注入sql注入器 + * + * 创建 ISqlInjector 实例的方法 + * @return ISqlInjector SQL 注入器实例 */ @Bean public ISqlInjector sqlInjector(){ - return new LogicSqlInjector(); + return new LogicSqlInjector(); // 创建并返回逻辑 SQL 注入器实例 } -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/config/shiro/MemberRealm.java b/tamguo-mms/src/main/java/com/tamguo/config/shiro/MemberRealm.java index 6a55f8d..2fa9c54 100644 --- a/tamguo-mms/src/main/java/com/tamguo/config/shiro/MemberRealm.java +++ b/tamguo-mms/src/main/java/com/tamguo/config/shiro/MemberRealm.java @@ -1,6 +1,7 @@ package com.tamguo.config.shiro; import java.util.Set; + import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.AuthenticationInfo; import org.apache.shiro.authc.AuthenticationToken; @@ -12,61 +13,87 @@ import org.apache.shiro.authz.AuthorizationInfo; import org.apache.shiro.authz.SimpleAuthorizationInfo; import org.apache.shiro.crypto.hash.Sha256Hash; import org.apache.shiro.realm.AuthorizingRealm; -import org.apache.shiro.subject.PrincipalCollection; import org.springframework.beans.factory.annotation.Autowired; import com.tamguo.modules.member.model.MemberEntity; import com.tamguo.modules.member.service.IMemberService; /** - * 认证 - * + * 认证 Realm 类 + * */ + public class MemberRealm extends AuthorizingRealm { - + + // 依赖注入 MemberService 实例 @Autowired private IMemberService iMemberService; - - /** - * 授权(验证权限时调用) - */ + + /** + * 授权方法(验证权限时调用) + * + * @param principals 主体集合 + * @return 授权信息 + */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { - Set permsSet = null; + // 权限集合 + Set permsSet = null; + + // 创建简单授权信息对象 SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); + + // 设置权限集合 info.setStringPermissions(permsSet); - + return info; } /** - * 认证(登录时调用) + * 认证方法(登录时调用) + * + * @param token 认证令牌 + * @return 认证信息 + * @throws AuthenticationException 认证异常 */ @Override - protected AuthenticationInfo doGetAuthenticationInfo( - AuthenticationToken token) throws AuthenticationException { + protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { + // 获取用户名 String username = (String) token.getPrincipal(); - String password = new String((char[]) token.getCredentials()); - - MemberEntity member = iMemberService.findByUsername(username); - if(member == null) { - throw new UnknownAccountException("用户名或密码有误,请重新输入或找回密码"); - } - Integer loginFailureCount = iMemberService.getLoginFailureCount(member); - if(loginFailureCount > 10) { - throw new LockedAccountException("账号被锁定"); - } - - if(!new Sha256Hash(password).toHex().equals(member.getPassword())){ + + // 获取密码 + String password = new String((char[]) token.getCredentials()); + + // 根据用户名查询 MemberEntity 对象 + MemberEntity member = iMemberService.findByUsername(username); + + // 如果用户不存在 + if (member == null) { + throw new UnknownAccountException("用户名或密码有误,请重新输入或找回密码"); + } + + // 获取登录失败次数 + Integer loginFailureCount = iMemberService.getLoginFailureCount(member); + + // 如果登录失败次数大于 10 + if (loginFailureCount > 10) { + throw new LockedAccountException("账号被锁定"); + } + + // 如果密码不匹配 + if (!new Sha256Hash(password).toHex().equals(member.getPassword())) { loginFailureCount++; - iMemberService.updateLoginFailureCount(member , loginFailureCount); + iMemberService.updateLoginFailureCount(member, loginFailureCount); + throw new IncorrectCredentialsException("用户名或密码有误,请重新输入或找回密码"); } + // 更新登录时间 iMemberService.updateLastLoginTime(member.getId()); - - SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(member, password, getName()); - return info; - } -} + // 创建简单认证信息对象 + SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(member, password, getName()); + + return info; + } +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/config/shiro/ShiroConfiguration.java b/tamguo-mms/src/main/java/com/tamguo/config/shiro/ShiroConfiguration.java index 96f9ab3..c8878a5 100644 --- a/tamguo-mms/src/main/java/com/tamguo/config/shiro/ShiroConfiguration.java +++ b/tamguo-mms/src/main/java/com/tamguo/config/shiro/ShiroConfiguration.java @@ -12,55 +12,96 @@ import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreato import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +/** + * Shiro 配置类 + */ @Configuration public class ShiroConfiguration { + + // 定义过滤链定义映射,用于配置 Shiro 的权限控制规则 private static Map filterChainDefinitionMap = new LinkedHashMap(); + /** + * 获取 Shiro 领域对象,即自定义的 MemberRealm 实例 + * @return MemberRealm 对象 + */ @Bean(name = "shiroRealm") public MemberRealm getShiroRealm() { + // 创建 MemberRealm 实例 return new MemberRealm(); } + /** + * 获取 EhCache 管理器,用于缓存 Shiro 的相关数据 + * @return EhCacheManager 对象 + */ @Bean(name = "shiroEhcacheManager") public EhCacheManager getEhCacheManager() { + // 创建 EhCacheManager 实例,并设置其配置文件路径 EhCacheManager em = new EhCacheManager(); em.setCacheManagerConfigFile("classpath:ehcache-shiro.xml"); return em; } + /** + * 获取生命周期 Bean 后处理器,用于管理 Shiro 相关 Bean 的生命周期 + * @return LifecycleBeanPostProcessor 对象 + */ @Bean(name = "lifecycleBeanPostProcessor") public LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() { + // 创建 LifecycleBeanPostProcessor 实例 return new LifecycleBeanPostProcessor(); } + /** + * 获取默认顾问自动代理创建器,用于自动创建代理对象 + * @return DefaultAdvisorAutoProxyCreator 对象 + */ @Bean public DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator() { + // 创建 DefaultAdvisorAutoProxyCreator 实例,并设置代理目标类为 true DefaultAdvisorAutoProxyCreator daap = new DefaultAdvisorAutoProxyCreator(); daap.setProxyTargetClass(true); return daap; } + /** + * 获取默认 Web 安全管理器,用于整合 Shiro 的各种组件 + * @return DefaultWebSecurityManager 对象 + */ @Bean(name = "securityManager") public DefaultWebSecurityManager getDefaultWebSecurityManager() { + // 创建 DefaultWebSecurityManager 实例,并设置相关属性 DefaultWebSecurityManager dwsm = new DefaultWebSecurityManager(); dwsm.setRealm(getShiroRealm()); dwsm.setCacheManager(getEhCacheManager()); return dwsm; } + /** + * 获取授权属性源顾问,用于在 Spring AOP 中进行授权检查 + * @return AuthorizationAttributeSourceAdvisor 对象 + */ @Bean public AuthorizationAttributeSourceAdvisor getAuthorizationAttributeSourceAdvisor() { + // 创建 AuthorizationAttributeSourceAdvisor 实例,并设置相关属性 AuthorizationAttributeSourceAdvisor aasa = new AuthorizationAttributeSourceAdvisor(); aasa.setSecurityManager(getDefaultWebSecurityManager()); - return new AuthorizationAttributeSourceAdvisor(); + return aasa; } + /** + * 获取 Shiro 过滤器工厂 Bean,用于配置 Shiro 的过滤器链 + * @return ShiroFilterFactoryBean 对象 + */ @Bean(name = "shiroFilter") public ShiroFilterFactoryBean getShiroFilterFactoryBean() { + // 创建 ShiroFilterFactoryBean 实例,并设置相关属性 ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); shiroFilterFactoryBean.setSecurityManager(getDefaultWebSecurityManager()); shiroFilterFactoryBean.setLoginUrl("/login"); shiroFilterFactoryBean.setSuccessUrl("/index"); + // 设置过滤链定义映射 filterChainDefinitionMap.put("/member/**", "authc"); filterChainDefinitionMap.put("/**", "anon"); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); diff --git a/tamguo-mms/src/main/java/com/tamguo/config/web/ErrorConfigurar.java b/tamguo-mms/src/main/java/com/tamguo/config/web/ErrorConfigurar.java index 9267271..6a9759d 100644 --- a/tamguo-mms/src/main/java/com/tamguo/config/web/ErrorConfigurar.java +++ b/tamguo-mms/src/main/java/com/tamguo/config/web/ErrorConfigurar.java @@ -6,16 +6,33 @@ import org.springframework.boot.web.server.ErrorPageRegistry; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; +/** + * 定义一个错误配置类,实现 ErrorPageRegistrar 接口 + */ @Component public class ErrorConfigurar implements ErrorPageRegistrar { + /** + * + * 注册错误页面的方法 + * @param registry 错误页面注册表 + */ @Override public void registerErrorPages(ErrorPageRegistry registry) { - ErrorPage[] errorPages=new ErrorPage[2]; - errorPages[0]=new ErrorPage(HttpStatus.NOT_FOUND,"/error404"); - errorPages[1]=new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,"/error500"); + // 创建一个错误页面数组 + ErrorPage[] errorPages = new ErrorPage[2]; - registry.addErrorPages(errorPages); + // 创建一个表示 404 状态的错误页面,并指定其重定向路径 + ErrorPage errorPage404 = new ErrorPage(HttpStatus.NOT_FOUND, "/error404"); + + // 创建一个表示 500 状态的错误页面,并指定其重定向路径 + ErrorPage errorPage500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error500"); + + // 将两个错误页面添加到错误页面数组中 + errorPages[0] = errorPage404; + errorPages[1] = errorPage500; + + // 将错误页面数组添加到错误页面注册表中 + registry.addErrorPages(errorPages); } - -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/config/web/ThymeleafConfig.java b/tamguo-mms/src/main/java/com/tamguo/config/web/ThymeleafConfig.java index aa95073..c55d2bc 100644 --- a/tamguo-mms/src/main/java/com/tamguo/config/web/ThymeleafConfig.java +++ b/tamguo-mms/src/main/java/com/tamguo/config/web/ThymeleafConfig.java @@ -10,32 +10,83 @@ import org.springframework.stereotype.Component; import org.thymeleaf.spring5.view.ThymeleafViewResolver; import com.tamguo.common.utils.SystemConstant; - +/** + * ThymeleafConfig 类,实现 EnvironmentAware 接口 + */ @Component -public class ThymeleafConfig implements EnvironmentAware{ +public class ThymeleafConfig implements EnvironmentAware { + /** + * 注入环境变量对象 + */ @Resource - private Environment env; + private Environment env; + /** + * 配置 Thymeleaf 静态变量的方法 + * @param viewResolver ThymeleafViewResolver 对象 + */ @Resource private void configureThymeleafStaticVars(ThymeleafViewResolver viewResolver) { - if(viewResolver != null) { - Map vars = new HashMap<>(); - vars.put("domainName", env.getProperty("domain.name")); - vars.put("bookDomainName", env.getProperty("book.domain.name")); - vars.put("tamguoDomainName", env.getProperty("tamguo.domain.name")); - vars.put("PAPER_TYPE_ZHENTI", SystemConstant.ZHENGTI_PAPER_ID); - vars.put("PAPER_TYPE_MONI", SystemConstant.MONI_PAPER_ID); - vars.put("PAPER_TYPE_YATI", SystemConstant.YATI_PAPER_ID); - vars.put("PAPER_TYPE_MINGXIAO", SystemConstant.MINGXIAO_PAPER_ID); - vars.put("BEIJING_AREA_ID", SystemConstant.BEIJING_AREA_ID); - viewResolver.setStaticVariables(vars); - } + if (viewResolver!= null) { + /** + * 创建一个存储静态变量的 Map + */ + Map vars = new HashMap<>(); + + /** + * 将环境变量中 domain.name 的值放入变量中 + */ + vars.put("domainName", env.getProperty("domain.name")); + + /** + * 将环境变量中 book.domain.name 的值放入变量中 + */ + vars.put("bookDomainName", env.getProperty("book.domain.name")); + + /** + * 将环境变量中 tamguo.domain.name 的值放入变量中 + */ + vars.put("tamguoDomainName", env.getProperty("tamguo.domain.name")); + + /** + * 将系统常量中 ZHENGTI_PAPER_ID 的值放入变量中 + */ + vars.put("PAPER_TYPE_ZHENTI", SystemConstant.ZHENGTI_PAPER_ID); + + /** + * 将系统常量中 MONI_PAPER_ID 的值放入变量中 + */ + vars.put("PAPER_TYPE_MONI", SystemConstant.MONI_PAPER_ID); + + /** + * 将系统常量中 YATI_PAPER_ID 的值放入变量中 + */ + vars.put("PAPER_TYPE_YATI", SystemConstant.YATI_PAPER_ID); + + /** + * 将系统常量中 MINGXIAO_PAPER_ID 的值放入变量中 + */ + vars.put("PAPER_TYPE_MINGXIAO", SystemConstant.MINGXIAO_PAPER_ID); + + /** + * 将系统常量中 BEIJING_AREA_ID 的值放入变量中 + */ + vars.put("BEIJING_AREA_ID", SystemConstant.BEIJING_AREA_ID); + + /** + * 设置 ThymeleafViewResolver 的静态变量 + */ + viewResolver.setStaticVariables(vars); + } } + /** + * 实现 EnvironmentAware 接口的方法,设置环境变量 + * @param environment 环境变量对象 + */ @Override public void setEnvironment(Environment environment) { env = environment; } - -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/config/web/WebConfig.java b/tamguo-mms/src/main/java/com/tamguo/config/web/WebConfig.java index 5235434..ddc89ea 100644 --- a/tamguo-mms/src/main/java/com/tamguo/config/web/WebConfig.java +++ b/tamguo-mms/src/main/java/com/tamguo/config/web/WebConfig.java @@ -12,36 +12,64 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import com.tamguo.web.interceptor.MemberInterceptor; - +/** + * WebConfig 类,实现 WebMvcConfigurer 接口,用于配置 Web 相关的设置 + */ @Configuration public class WebConfig implements WebMvcConfigurer { - - @Value("${file.storage.path}") - private String fileStoragePath; - @Value("${cookie.domian.name}") - private String cookieDomianName; - - @Autowired - private MemberInterceptor memberInterceptor; - - - @Override - public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(memberInterceptor).addPathPatterns("/**").excludePathPatterns("/login.html","/register.html","/password/**","/captcha.jpg" , "/submitLogin.html" , "/miniLogin.html","/static/**","/sendFindPasswordSms","/subRegister","/checkMobile.html","/checkUsername.html"); - } - + + /** + * 从配置文件中获取文件存储路径的值 + */ + @Value("${file.storage.path}") + private String fileStoragePath; + + /** + * 从配置文件中获取 Cookie 域名的值 + */ + @Value("${cookie.domian.name}") + private String cookieDomianName; + + /** + * 自动注入 MemberInterceptor 实例 + */ + @Autowired + private MemberInterceptor memberInterceptor; + + /** + * 重写 addInterceptors 方法,添加拦截器 + * @param registry 拦截器注册器 + */ + @Override + public void addInterceptors(InterceptorRegistry registry) { + // 添加拦截器,并设置拦截路径和排除路径 + registry.addInterceptor(memberInterceptor).addPathPatterns("/**").excludePathPatterns("/login.html", "/register.html", "/password/**", "/captcha.jpg", "/submitLogin.html", "/miniLogin.html", "/static/**", "/sendFindPasswordSms", "/subRegister", "/checkMobile.html", "/checkUsername.html"); + } + + /** + * 重写 addResourceHandlers 方法,添加资源处理器 + * @param registry 资源处理器注册器 + */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/files/**").addResourceLocations("file:"+fileStoragePath); + // 添加资源处理器,处理/files/** 路径的资源,并设置资源位置为文件系统中的指定路径 + registry.addResourceHandler("/files/**").addResourceLocations("file:" + fileStoragePath); } - + + /** + * 创建默认的 CookieSerializer 实例的方法 + * @return 默认的 CookieSerializer 实例 + */ @Bean - public CookieSerializer defaultCookieSerializer(){ + public CookieSerializer defaultCookieSerializer() { + // 创建默认的 CookieSerializer 实例 DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer(); + // 设置 Cookie 名称 defaultCookieSerializer.setCookieName("sessionId"); + // 设置 Cookie 域名 defaultCookieSerializer.setDomainName(cookieDomianName); + // 设置 Cookie 路径 defaultCookieSerializer.setCookiePath("/"); return defaultCookieSerializer; } - -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/utils/FileMd5Utils.java b/tamguo-mms/src/main/java/com/tamguo/utils/FileMd5Utils.java index 539a8ba..f109114 100644 --- a/tamguo-mms/src/main/java/com/tamguo/utils/FileMd5Utils.java +++ b/tamguo-mms/src/main/java/com/tamguo/utils/FileMd5Utils.java @@ -1,37 +1,42 @@ package com.tamguo.utils; -import java.io.FileInputStream; -import java.io.IOException; -import java.security.MessageDigest; -import org.apache.commons.codec.binary.Hex; +import java.io.FileInputStream; // 导入文件输入流类 +import java.io.IOException; // 导入输入输出异常类 +import java.security.MessageDigest; // 导入消息摘要类 +import org.apache.commons.codec.binary.Hex; // 导入十六进制编码类 +/** + * FileMd5Utils 类,用于获取文件的 MD5 值(可处理大文件) + */ public class FileMd5Utils { /** - * 获取一个文件的md5值(可处理大文件) - * @return md5 value + * 获取一个文件的 MD5 值的方法 + * @param fileInputStream 文件输入流 + * @return MD5 值字符串 */ public static String getMD5(FileInputStream fileInputStream) { try { + // 获取 MD5 消息摘要实例 MessageDigest MD5 = MessageDigest.getInstance("MD5"); + // 创建字节数组,大小为 8192 字节 byte[] buffer = new byte[8192]; - int length; - while ((length = fileInputStream.read(buffer)) != -1) { - MD5.update(buffer, 0, length); + int length; // 定义读取到的字节长度变量 + while ((length = fileInputStream.read(buffer))!= -1) { // 循环读取文件内容 + MD5.update(buffer, 0, length); // 更新消息摘要 } - return new String(Hex.encodeHex(MD5.digest())); - } catch (Exception e) { - e.printStackTrace(); - return null; - } finally { + return new String(Hex.encodeHex(MD5.digest())); // 将消息摘要的结果进行十六进制编码并转换为字符串返回 + } catch (Exception e) { // 捕获异常 + e.printStackTrace(); // 打印异常信息 + return null; // 返回空值 + } finally { // 无论是否发生异常,都会执行以下代码块 try { - if (fileInputStream != null){ - fileInputStream.close(); - } - } catch (IOException e) { - e.printStackTrace(); + if (fileInputStream!= null) { // 如果文件输入流不为空 + fileInputStream.close(); // 关闭文件输入流 + } + } catch (IOException e) { // 捕获输入输出异常 + e.printStackTrace(); // 打印异常信息 } } } - -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/utils/ShiroUtils.java b/tamguo-mms/src/main/java/com/tamguo/utils/ShiroUtils.java index a31888d..fed6a02 100644 --- a/tamguo-mms/src/main/java/com/tamguo/utils/ShiroUtils.java +++ b/tamguo-mms/src/main/java/com/tamguo/utils/ShiroUtils.java @@ -1,43 +1,68 @@ package com.tamguo.utils; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.session.Session; -import org.apache.shiro.subject.Subject; - -import com.tamguo.modules.member.model.MemberEntity; +import org.apache.shiro.SecurityUtils; // 导入 Shiro 的安全工具类 +import org.apache.shiro.session.Session; // 导入 Shiro 的会话类 +import org.apache.shiro.subject.Subject; // 导入 Shiro 的主体类 +import com.tamguo.modules.member.model.MemberEntity; // 导入会员实体类 +/** + * ShiroUtils 类,提供与 Shiro 相关的工具方法 + */ public class ShiroUtils { + /** + * 获取当前会话 + */ public static Session getSession() { - return SecurityUtils.getSubject().getSession(); + return SecurityUtils.getSubject().getSession(); // 获取 Shiro 主体的会话 } + /** + * 获取当前主体 + */ public static Subject getSubject() { - return SecurityUtils.getSubject(); + return SecurityUtils.getSubject(); // 获取 Shiro 主体 } + /** + * 获取当前登录的会员实体 + */ public static MemberEntity getMember() { - return (MemberEntity)SecurityUtils.getSubject().getPrincipal(); + return (MemberEntity)SecurityUtils.getSubject().getPrincipal(); // 获取 Shiro 主体的主要对象(会员实体) } + /** + * 获取当前登录会员的 ID + */ public static String getMemberId() { - return getMember().getId(); + return getMember().getId(); // 获取会员实体的 ID } - + + /** + * 设置会话属性 + */ public static void setSessionAttribute(Object key, Object value) { - getSession().setAttribute(key, value); + getSession().setAttribute(key, value); // 在会话中设置属性键值对 } + /** + * 获取会话属性 + */ public static Object getSessionAttribute(Object key) { - return getSession().getAttribute(key); + return getSession().getAttribute(key); // 获取会话中指定键的属性值 } + /** + * 判断是否登录 + */ public static boolean isLogin() { - return SecurityUtils.getSubject().getPrincipal() != null; + return SecurityUtils.getSubject().getPrincipal()!= null; // 判断 Shiro 主体的主要对象是否不为空 } + /** + * 注销登录 + */ public static void logout() { - SecurityUtils.getSubject().logout(); + SecurityUtils.getSubject().logout(); // 执行 Shiro 主体的注销操作 } - -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/web/AccountController.java b/tamguo-mms/src/main/java/com/tamguo/web/AccountController.java index 2808dda..ffee72b 100644 --- a/tamguo-mms/src/main/java/com/tamguo/web/AccountController.java +++ b/tamguo-mms/src/main/java/com/tamguo/web/AccountController.java @@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; import com.tamguo.common.utils.DateUtils; @@ -29,42 +28,83 @@ import com.tamguo.config.redis.CacheService; import com.tamguo.modules.member.service.IMemberService; import com.tamguo.utils.ShiroUtils; +/** + * AccountController 类,处理账户相关的请求 + */ @Controller public class AccountController { + /** + * 文件存储路径配置项 + */ @Value("${file.storage.path}") String fileStoragePath; + + /** + * 域名配置项 + */ @Value("${tamguo.domain.name}") String tamguoDomainName; + + /** + * 注入会员服务 + */ @Autowired IMemberService iMemberService; + + /** + * 注入缓存服务 + */ @Autowired CacheService cacheService; + /** + * 头像编号无格式字符串 + */ private static final String AVATOR_NO_FORMAT = "00000"; + + /** + * 头像前缀 + */ private static final String AVATOR_PREFIX = "MTX"; - + + /** + * 处理 "account.html" 请求,返回账户页面视图和会员信息 + * @param model 模型视图对象 + * @return 模型视图对象 + */ @RequestMapping(value = {"account.html"}, method = RequestMethod.GET) public ModelAndView list(ModelAndView model) { model.setViewName("account"); model.addObject("member", iMemberService.findByUid(ShiroUtils.getMemberId())); return model; } - + + /** + * 获取当前会员信息的请求处理 + * @return 结果对象,包含会员信息和状态信息 + */ @RequestMapping(value = {"getCurrentMember"}, method = RequestMethod.GET) @ResponseBody public Result getCurrentMember() { return Result.result(0, iMemberService.findByUid(ShiroUtils.getMemberId()), "success"); } - + + /** + * 处理文件上传请求 + * @param file 上传的文件 + * @param request HTTP 请求对象 + * @return 文件上传消息对象 + * @throws IOException 文件操作异常 + */ @RequestMapping(value = "uploadFile", method = RequestMethod.POST) @ResponseBody - public UploaderMessage uploadFileHandler(@RequestParam("file") MultipartFile file,HttpServletRequest request) throws IOException { + public UploaderMessage uploadFileHandler(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws IOException { if (!file.isEmpty()) { InputStream in = null; OutputStream out = null; - + try { String path = fileStoragePath + DateUtils.format(new Date(), "yyyyMMdd"); File dir = new File(path); @@ -93,12 +133,12 @@ public class AccountController { msg.setError("File upload file"); return msg; } finally { - if (out != null) { + if (out!= null) { out.close(); out = null; } - if (in != null) { + if (in!= null) { in.close(); in = null; } @@ -111,6 +151,10 @@ public class AccountController { } } + /** + * 获取头像编号的方法 + * @return 头像编号 + */ private String getAvatorNo() { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM"); String format = sdf.format(new Date()); @@ -120,4 +164,4 @@ public class AccountController { String avatorNo = AVATOR_PREFIX + df.format(incr); return avatorNo; } -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/web/BookCategoryController.java b/tamguo-mms/src/main/java/com/tamguo/web/BookCategoryController.java index 29390e8..d3b1ef7 100644 --- a/tamguo-mms/src/main/java/com/tamguo/web/BookCategoryController.java +++ b/tamguo-mms/src/main/java/com/tamguo/web/BookCategoryController.java @@ -1,63 +1,75 @@ package com.tamguo.web; import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - -import com.alibaba.druid.util.StringUtils; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.mapper.Condition; -import com.tamguo.common.utils.Result; -import com.tamguo.modules.book.model.BookCategoryEntity; -import com.tamguo.modules.book.service.IBookCategoryService; +import org.slf4j.Logger; // 导入日志记录器接口 +import org.slf4j.LoggerFactory; // 导入日志工厂类 +import org.springframework.beans.factory.annotation.Autowired; // 导入自动注入注解 +import org.springframework.stereotype.Controller; // 导入控制器注解 +import org.springframework.web.bind.annotation.RequestMapping; // 导入请求映射注解 +import org.springframework.web.bind.annotation.RequestMethod; // 导入请求方法注解 +import org.springframework.web.bind.annotation.ResponseBody; // 导入响应体注解 +import com.alibaba.druid.util.StringUtils; // 导入字符串工具类 +import com.alibaba.fastjson.JSONArray; // 导入 JSON 数组类 +import com.alibaba.fastjson.JSONObject; // 导入 JSON 对象类 +import com.baomidou.mybatisplus.mapper.Condition; // 导入条件构建器类 +import com.tamguo.modules.book.model.BookCategoryEntity; // 导入图书分类实体类 +import com.tamguo.modules.book.service.IBookCategoryService; // 导入图书分类服务接口 + +/** + * BookCategoryController 类,处理图书分类相关的请求 + */ @Controller public class BookCategoryController { - - private Logger logger = LoggerFactory.getLogger(getClass()); + + private Logger logger = LoggerFactory.getLogger(getClass()); // 创建日志记录器实例 @Autowired - private IBookCategoryService iBookCategoryService; - + private IBookCategoryService iBookCategoryService; // 自动注入图书分类服务实例 + + /** + * 处理获取图书分类的请求,通过 POST 方法 + * @param parentId 父分类 ID + * @return 返回处理结果 + */ @SuppressWarnings("unchecked") @RequestMapping(value = {"getBookCategory.html"}, method = RequestMethod.POST) @ResponseBody public Result getBookCategory(String parentId) { try { - List bookCategoryList = null; - if(StringUtils.isEmpty(parentId)) { - bookCategoryList = iBookCategoryService.selectList(Condition.create().eq("parent_id", "0")); - }else { - bookCategoryList = iBookCategoryService.selectList(Condition.create().eq("parent_id", parentId)); + List bookCategoryList = null; // 定义图书分类列表变量 + if(StringUtils.isEmpty(parentId)) { // 如果父分类 ID 为空 + bookCategoryList = iBookCategoryService.selectList(Condition.create().eq("parent_id", "0")); // 查询父分类为 0 的图书分类列表 + } else { + bookCategoryList = iBookCategoryService.selectList(Condition.create().eq("parent_id", parentId)); // 查询指定父分类 ID 的图书分类列表 } - - return Result.successResult(processBookCategoryList(bookCategoryList)); + + return Result.successResult(processBookCategoryList(bookCategoryList)); // 返回处理后的图书分类列表结果,并标记为成功 } catch (Exception e) { - logger.error(e.getMessage() , e); - return Result.failResult("查询失败!"); + logger.error(e.getMessage(), e); // 记录异常日志 + return Result.failResult("查询失败!"); // 返回失败结果及错误信息 } } - + + /** + * 处理图书分类列表,生成 JSON 数组 + * @param bookCategoryList 图书分类列表 + * @return 返回处理后的 JSON 数组 + */ @SuppressWarnings("unchecked") private JSONArray processBookCategoryList(List bookCategoryList) { - JSONArray entitys = new JSONArray(); - for(int i=0 ; i 0) { - entity.put("children", new JSONArray()); + entity.put("children", new JSONArray()); // 如果有子分类,设置子分类数组 } - entitys.add(entity); + entitys.add(entity); // 将当前分类对象添加到 JSON 数组中 } - return entitys; + return entitys; // 返回处理后的 JSON 数组 } -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/web/BookController.java b/tamguo-mms/src/main/java/com/tamguo/web/BookController.java index 36c3774..70da6e0 100644 --- a/tamguo-mms/src/main/java/com/tamguo/web/BookController.java +++ b/tamguo-mms/src/main/java/com/tamguo/web/BookController.java @@ -28,105 +28,145 @@ import com.tamguo.modules.book.service.IBookService; import com.tamguo.modules.book.service.IDocumentService; import com.tamguo.utils.ShiroUtils; +/** + * BookController 类,处理图书相关的请求 + */ @Controller public class BookController { - - private Logger logger = LoggerFactory.getLogger(getClass()); + + private Logger logger = LoggerFactory.getLogger(getClass()); // 创建日志记录器对象 @Autowired - private IBookService iBookService; + private IBookService iBookService; // 自动注入图书服务 @Autowired - private IDocumentService iDocumentService; - + private IDocumentService iDocumentService; // 自动注入文档服务 + + /** + * 处理编辑图书的请求 + * @param bookId 图书 ID + * @param model 模型视图对象 + * @return 模型视图对象 + */ @RequestMapping(value = "editBook/{bookId}", method = RequestMethod.GET) - public ModelAndView edit(@PathVariable String bookId , ModelAndView model) { - model.setViewName("book/edit"); - model.addObject("bookId", bookId); - return model; + public ModelAndView edit(@PathVariable String bookId, ModelAndView model) { + model.setViewName("book/edit"); // 设置视图名称 + model.addObject("bookId", bookId); // 添加图书 ID 到模型中 + return model; // 返回模型视图对象 } + /** + * 处理图书列表的请求 + * @param model 模型视图对象 + * @return 模型视图对象 + */ @RequestMapping(value = {"booklist.html"}, method = RequestMethod.GET) public ModelAndView list(ModelAndView model) { - model.setViewName("booklist"); - return model; + model.setViewName("booklist"); // 设置视图名称 + return model; // 返回模型视图对象 } + /** + * 处理获取文档列表的请求 + * @param id 图书 ID + * @return 返回处理结果 + */ @SuppressWarnings("unchecked") @RequestMapping(value = "getDocumentList", method = RequestMethod.POST) @ResponseBody public Result getDocumentList(String id) { - Map map = new HashMap<>(); + Map map = new HashMap<>(); // 创建一个 Map 对象 try { - BookEntity book = iBookService.selectById(id); - List documentList = iDocumentService.selectList(Condition.create().eq("book_id", id).eq("status", DocumentStatusEnum.NORMAL.getValue())); - - map.put("documentList", this.processDocumentList(documentList)); - map.put("book", book); + BookEntity book = iBookService.selectById(id); // 根据图书 ID 获取图书信息 + List documentList = iDocumentService.selectList(Condition.create().eq("book_id", id).eq("status", DocumentStatusEnum.NORMAL.getValue())); // 根据图书 ID 和文档状态获取文档列表 + + map.put("documentList", this.processDocumentList(documentList)); // 处理文档列表并将结果放入 Map 中 + map.put("book", book); // 将图书信息放入 Map 中 } catch (Exception e) { - logger.error(e.getMessage() , e ); - return Result.failResult("查询失败"); + logger.error(e.getMessage(), e); // 记录错误日志 + return Result.failResult("查询失败"); // 返回查询失败的结果 } - return Result.successResult(map); + return Result.successResult(map); // 返回查询成功的结果 } - + + /** + * 处理获取图书列表的请求 + * @return 返回处理结果 + */ @SuppressWarnings("unchecked") @RequestMapping(value = {"getBookList.html"}, method = RequestMethod.POST) @ResponseBody public Result getBookList() { try { - List bookList = iBookService.selectList(Condition.create().eq("owner", ShiroUtils.getMemberId()).orderDesc(Arrays.asList("create_date"))); - return Result.successResult(bookList); + List bookList = iBookService.selectList(Condition.create().eq("owner", ShiroUtils.getMemberId()).orderByDesc(Arrays.asList("create_date"))); // 根据当前用户 ID 获取图书列表 + return Result.successResult(bookList); // 返回图书列表 } catch (Exception e) { - logger.error(e.getMessage() , e); - return Result.failResult("查询失败!"); + logger.error(e.getMessage(), e); // 记录错误日志 + return Result.failResult("查询失败!"); // 返回查询失败的结果 } } - + + /** + * 处理保存图书的请求 + * @param book 图书实体 + * @return 返回处理结果 + */ @RequestMapping(value = {"saveBook"}, method = RequestMethod.POST) @ResponseBody public Result saveBook(@RequestBody BookEntity book) { try { - book.setOwner(ShiroUtils.getMemberId()); - book.setCategoryId(StringUtils.join(book.getCategoryIds(), ",")); - iBookService.saveBook(book); - return Result.result(0, null, "保存成功"); + book.setOwner(ShiroUtils.getMemberId()); // 设置图书的所有者为当前用户 + book.setCategoryId(StringUtils.join(book.getCategoryIds(), ",")); // 设置图书的分类 ID 为逗号分隔的字符串 + iBookService.saveBook(book); // 保存图书 + return Result.result(0, null, "保存成功"); // 返回保存成功的结果 } catch (Exception e) { - logger.error(e.getMessage() , e); - return Result.result(1, null, "保存失败"); + logger.error(e.getMessage(), e); // 记录错误日志 + return Result.result(1, null, "保存失败"); // 返回保存失败的结果 } } - + + /** + * 处理文档列表,生成 JSON 数组 + * @param documentList 文档列表 + * @return 返回处理后的 JSON 数组 + */ private JSONArray processDocumentList(List documentList) { - JSONArray entitys = new JSONArray(); - for(int i=0 ; i fileUploads = iFileUploadService.selectList(Condition.create().eq("biz_key", document.getId()).eq("biz_type", BizTypeEnum.DOCUMENT.getValue())); - if(!CollectionUtils.isEmpty(fileUploads)) { - for(int i=0 ; i + * 按分数降序分页获取有序集合中的内容 + * + * @param key 键 + * @param pageNo 页码(从 1 开始) + * @param pageSize 每页大小 + * @return 有序集合的内容 */ public Set getSortedSetByPage(String key, int pageNo, int pageSize) { key = getPreKey(key); @@ -365,11 +362,17 @@ public class CacheService { } catch (Exception ex) { ex.printStackTrace(); } finally { - redisXMLConfigure.closeConnection(conn); + redisXML Configure.closeConnection(conn); } return null; } + /** + * 获取列表的表头元素 + * + * @param key 键 + * @return 列表的表头元素 + */ public List getListHead(String key) { key = getPreKey(key); ShardedJedis conn = null; @@ -386,12 +389,12 @@ public class CacheService { } /** - * 存储map - * - * @param key 键值 - * @param field map field - * @param value map value - * @return if filed exist return 0 else return 1 + * 存储 Map 到 Redis + * + * @param key 键 + * @param field Map 的字段 + * @param value Map 的值 + * @return 如果字段已存在返回 0,否则返回 1 */ public Long hset(String key, String field, String value) { key = getPreKey(key); @@ -400,10 +403,17 @@ public class CacheService { conn = redisXMLConfigure.getConnection(); return conn.hset(key, field, value); } finally { - redisXMLConfigure.closeConnection(conn); + redisXML Configure.closeConnection(conn); } } + /** + * 存储 Map 到 Redis + * + * @param key 键 + * @param values Map + * @return 设置结果 + */ public String hset(String key, Map values) { key = getPreKey(key); ShardedJedis conn = null; @@ -411,10 +421,18 @@ public class CacheService { conn = redisXMLConfigure.getConnection(); return conn.hmset(key, values); } finally { - redisXMLConfigure.closeConnection(conn); + redisXML Configure.closeConnection(conn); } } + /** + * 存储 Map 到 Redis,并设置过期时间 + * + * @param key 键 + * @param values Map + * @param time 过期时间(单位:秒) + * @return 设置结果 + */ public String hset(String key, Map values, int time) { key = getPreKey(key); ShardedJedis conn = null; @@ -429,28 +447,28 @@ public class CacheService { } /** - * 得到map中存储的field值 - * - * @param key 键值 - * @param field map field - * @return + * 获取 Map 中指定字段的值 + * + * @param key 键 + * @param field 字段 + * @return 值 */ public String hget(String key, String field) { key = getPreKey(key); ShardedJedis conn = null; try { - conn = redisXMLConfigure.getConnection(); + conn = redisXML Configure.getConnection(); return conn.hget(key, field); } finally { - redisXMLConfigure.closeConnection(conn); + redisXML Configure.closeConnection(conn); } } /** - * 名称为key的string减1操作 - * - * @param key - * @return + * 将名称为 key 的字符串减 1 + * + * @param key 键 + * @return 减 1 后的结果 */ public Long decr(String key) { key = getPreKey(key); @@ -462,24 +480,30 @@ public class CacheService { redisXMLConfigure.closeConnection(conn); } } - + /** - * 名称为key的string加1操作 - * - * @param key - * @return + * 将名称为 key 的字符串加 1 + * + * @param key 键 + * @return 加 1 后的结果 */ public Long incr(String key) { key = getPreKey(key); ShardedJedis conn = null; try { - conn = redisXMLConfigure.getConnection(); + conn = redisXML Configure.getConnection(); return conn.incr(key); } finally { redisXMLConfigure.closeConnection(conn); } } + /** + * 获取 Redis 键的完整路径 + * + * @param key 键 + * @return 完整路径 + */ private String getPreKey(String key) { String temp_pre = redisXMLConfigure.getPreKey(); if (null == temp_pre) { @@ -487,5 +511,4 @@ public class CacheService { } return temp_pre + key; } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/config/redis/PoolConfigBean.java b/tamguo-modules-core/src/main/java/com/tamguo/config/redis/PoolConfigBean.java index c1b9bc1..92407c1 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/config/redis/PoolConfigBean.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/config/redis/PoolConfigBean.java @@ -1,13 +1,28 @@ package com.tamguo.config.redis; +/** + * PoolConfigBean 类,用于配置 Redis 连接池 + */ public class PoolConfigBean { + // 最大活跃连接数 private int max_active; + // 最大空闲连接数 private int max_idle; + // 最大等待时间(毫秒) private long max_wait; + /** + * 无参构造函数 + */ public PoolConfigBean() { } + /** + * 全参构造函数 + * @param max_active 最大活跃连接数 + * @param max_idle 最大空闲连接数 + * @param max_wait 最大等待时间(毫秒) + */ public PoolConfigBean(int max_active, int max_idle, long max_wait) { super(); this.max_active = max_active; @@ -15,33 +30,60 @@ public class PoolConfigBean { this.max_wait = max_wait; } + /** + * 获取最大活跃连接数 + * @return 最大活跃连接数 + */ public int getMax_active() { return max_active; } + /** + * 设置最大活跃连接数 + * @param max_active 最大活跃连接数 + */ public void setMax_active(int max_active) { this.max_active = max_active; } + /** + * 获取最大空闲连接数 + * @return 最大空闲连接数 + */ public int getMax_idle() { return max_idle; } + /** + * 设置最大空闲连接数 + * @param max_idle 最大空闲连接数 + */ public void setMax_idle(int max_idle) { this.max_idle = max_idle; } + /** + * 获取最大等待时间(毫秒) + * @return 最大等待时间(毫秒) + */ public long getMax_wait() { return max_wait; } + /** + * 设置最大等待时间(毫秒) + * @param max_wait 最大等待时间(毫秒) + */ public void setMax_wait(long max_wait) { this.max_wait = max_wait; } + /** + * 重写 toString 方法,返回对象的字符串表示 + * @return 对象的字符串表示 + */ @Override public String toString() { return "PoolConfig [max_active=" + max_active + ", max_idle=" + max_idle + ", max_wait=" + max_wait + "]"; } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/config/redis/RedisServerNodeBean.java b/tamguo-modules-core/src/main/java/com/tamguo/config/redis/RedisServerNodeBean.java index d8b4297..a26bb81 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/config/redis/RedisServerNodeBean.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/config/redis/RedisServerNodeBean.java @@ -1,11 +1,26 @@ package com.tamguo.config.redis; +/** + * RedisServerNodeBean 类,用于表示 Redis 服务器节点的信息 + */ public class RedisServerNodeBean { + // Redis 服务器的 IP 地址 private String ip; + // Redis 服务器的端口号 private int port; + // 是否需要身份验证 private boolean needAuth; + // 身份验证密码 private String auth; + /** + * 构造函数,用于创建 RedisServerNodeBean 对象 + * + * @param ip Redis 服务器的 IP 地址 + * @param port Redis 服务器的端口号 + * @param needAuth 是否需要身份验证 + * @param auth 身份验证密码 + */ public RedisServerNodeBean(String ip, int port, boolean needAuth, String auth) { this.ip = ip; this.port = port; @@ -13,41 +28,85 @@ public class RedisServerNodeBean { this.auth = auth; } + /** + * 获取 Redis 服务器的 IP 地址 + * + * @return Redis 服务器的 IP 地址 + */ public String getIp() { return ip; } + /** + * 设置 Redis 服务器的 IP 地址 + * + * @param ip Redis 服务器的 IP 地址 + */ public void setIp(String ip) { this.ip = ip; } + /** + * 获取 Redis 服务器的端口号 + * + * @return Redis 服务器的端口号 + */ public int getPort() { return port; } + /** + * 设置 Redis 服务器的端口号 + * + * @param port Redis 服务器的端口号 + */ public void setPort(int port) { this.port = port; } + /** + * 获取是否需要身份验证 + * + * @return 是否需要身份验证 + */ public boolean isNeedAuth() { return needAuth; } + /** + * 设置是否需要身份验证 + * + * @param needAuth 是否需要身份验证 + */ public void setNeedAuth(boolean needAuth) { this.needAuth = needAuth; } + /** + * 获取身份验证密码 + * + * @return 身份验证密码 + */ public String getAuth() { return auth; } + /** + * 设置身份验证密码 + * + * @param auth 身份验证密码 + */ public void setAuth(String auth) { this.auth = auth; } + /** + * 重写 toString 方法,返回 RedisServerNodeBean 对象的字符串表示 + * + * @return RedisServerNodeBean 对象的字符串表示 + */ @Override public String toString() { return "RedisServer [ip=" + ip + ", port=" + port + ", needAuth=" + needAuth + ", auth=" + auth + "]"; } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/config/redis/RedisXMLConfigure.java b/tamguo-modules-core/src/main/java/com/tamguo/config/redis/RedisXMLConfigure.java index 0fe52c0..f233da6 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/config/redis/RedisXMLConfigure.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/config/redis/RedisXMLConfigure.java @@ -18,158 +18,187 @@ import redis.clients.jedis.JedisShardInfo; import redis.clients.jedis.ShardedJedis; import redis.clients.jedis.ShardedJedisPool; +/** + * RedisXMLConfigure 类,用于从 XML 配置文件中读取 Redis 服务器节点信息,并创建 ShardedJedisPool + */ @Component("redisConfigure") public class RedisXMLConfigure implements InitializingBean { - private static final Logger logger = Logger.getLogger(RedisXMLConfigure.class); - private static String preKey; - private static Document document = null; - private ShardedJedisPool shardedJedisPool; + private static final Logger logger = Logger.getLogger(RedisXMLConfigure.class); // 日志记录器 + private static String preKey; // Redis 键的前缀 + private static Document document = null; // XML 文档对象 + private ShardedJedisPool shardedJedisPool; // ShardedJedis 连接池 + /** + * 在所有属性设置后执行的初始化方法 + * 从 XML 配置文件中读取 Redis 服务器节点信息,并创建 ShardedJedisPool + * @throws Exception 可能抛出的异常 + */ @Override public void afterPropertiesSet() throws Exception { - XMLConfiguration xmlConfiguration = new XMLConfiguration(); - String REDIS_PATH = "redis.xml"; - InputStream stream = null; + XMLConfiguration xmlConfiguration = new XMLConfiguration(); // 创建 XML 配置对象 + String REDIS_PATH = "redis.xml"; // XML 配置文件路径 + InputStream stream = null; // 输入流对象 + try { - stream = this.getClass().getClassLoader().getResourceAsStream(REDIS_PATH); - if (stream == null) { - logger.error("load redis.xml failed!!!" + REDIS_PATH); - throw new RuntimeException("load redis.xml failed"); + stream = this.getClass().getClassLoader().getResourceAsStream(REDIS_PATH); // 获取 XML 配置文件的输入流 + if (stream == null) { // 如果输入流为空 + logger.error("load redis.xml failed!!!" + REDIS_PATH); // 记录错误日志 + throw new RuntimeException("load redis.xml failed"); // 抛出运行时异常 } - logger.info("Redis XML config path:" + REDIS_PATH); - if (xmlConfiguration.readConfigFile(stream)) { - document = xmlConfiguration.getDocument(); + logger.info("Redis XML config path:" + REDIS_PATH); // 记录日志 + if (xmlConfiguration.readConfigFile(stream)) { // 如果成功读取 XML 配置文件 + document = xmlConfiguration.getDocument(); // 获取 XML 文档对象 } else { - logger.error("load redis.xml failed!!!"); + logger.error("load redis.xml failed!!!"); // 记录错误日志 } } finally { - if (null != stream) - stream.close(); + if (null!= stream) // 如果输入流不为空 + stream.close(); // 关闭输入流 } - //初始化参数 - initPreKey(); - PoolConfigBean pcb = initPoolConfigBean(); - List rsnbs = initRedisServerNodeBeans(); - //实现shardedJedisPool + + // 初始化参数 + initPreKey(); // 初始化 Redis 键的前缀 + PoolConfigBean pcb = initPoolConfigBean(); // 初始化连接池配置对象 + List rsnbs = initRedisServerNodeBeans(); // 初始化 Redis 服务器节点信息列表 + + // 创建 JedisPoolConfig 对象 JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); - //no maxActive config + // 设置最大空闲连接数 jedisPoolConfig.setMaxIdle(pcb.getMax_idle()); + // 设置最大等待时间(毫秒) jedisPoolConfig.setMaxWaitMillis(pcb.getMax_wait()); - shardedJedisPool = new ShardedJedisPool(jedisPoolConfig,getJedisShardInfo(rsnbs)); - if(shardedJedisPool == null){ - throw new RuntimeException("config redis.xml error"); + // 创建 ShardedJedisPool 对象 + shardedJedisPool = new ShardedJedisPool(jedisPoolConfig, getJedisShardInfo(rsnbs)); + if (shardedJedisPool == null) { // 如果 ShardedJedisPool 对象为空 + throw new RuntimeException("config redis.xml error"); // 抛出运行时异常 } } /** - * 初始化jedis参数 + * 初始化连接池配置对象 + * @return 连接池配置对象 */ private PoolConfigBean initPoolConfigBean() { - PoolConfigBean poolConfigBean = new PoolConfigBean(); - Element poolElement = (Element) document.getElementsByTagName("pool").item(0); - int max_active = poolElement.hasAttribute("maxActive") ? Integer.parseInt(poolElement.getAttribute("maxActive")) : -1; - int max_idle = poolElement.hasAttribute("maxIdle") ? Integer.parseInt(poolElement.getAttribute("maxIdle")) : -1; - long max_wait = poolElement.hasAttribute("maxWait") ? Long.parseLong(poolElement.getAttribute("maxWait")) : -1; - poolConfigBean.setMax_active(max_active); - poolConfigBean.setMax_idle(max_idle); - poolConfigBean.setMax_wait(max_wait); + PoolConfigBean poolConfigBean = new PoolConfigBean(); // 创建连接池配置对象 + Element poolElement = (Element) document.getElementsByTagName("pool").item(0); // 获取 pool 元素 + + int max_active = poolElement.hasAttribute("maxActive")? Integer.parseInt(poolElement.getAttribute("maxActive")) : -1; // 获取最大活跃连接数 + int max_idle = poolElement.hasAttribute("maxIdle")? Integer.parseInt(poolElement.getAttribute("maxIdle")) : -1; // 获取最大空闲连接数 + long max_wait = poolElement.hasAttribute("maxWait")? Long.parseLong(poolElement.getAttribute("maxWait")) : -1; // 获取最大等待时间(毫秒) + + poolConfigBean.setMax_active(max_active); // 设置最大活跃连接数 + poolConfigBean.setMax_idle(max_idle); // 设置最大空闲连接数 + poolConfigBean.setMax_wait(max_wait); // 设置最大等待时间(毫秒) + return poolConfigBean; } /** - * 解析配置redis的server列表 + * 初始化 Redis 服务器节点信息列表 + * @return Redis 服务器节点信息列表 */ private List initRedisServerNodeBeans() { - List redisServers = new ArrayList(); - NodeList serverElements = document.getElementsByTagName("server"); - int serverLen = serverElements.getLength(); - if (serverLen < 1) { - logger.error("redis.servers.server must have one !"); - return null; + List redisServers = new ArrayList(); // 创建 Redis 服务器节点信息列表 + + NodeList serverElements = document.getElementsByTagName("server"); // 获取所有 server 元素 + int serverLen = serverElements.getLength(); // 获取 server 元素的数量 + + if (serverLen < 1) { // 如果 server 元素的数量小于 1 + logger.error("redis.servers.server must have one!"); // 记录错误日志 + return null; // 返回空列表 } - for (int i = 0; i < serverLen; i++) { - Element serverElement = (Element) serverElements.item(i); - String temp_ip = serverElement.hasAttribute("ip") ? serverElement.getAttribute("ip") : null; - if (temp_ip == null) { - logger.error("redis.servers.server.ip must be supplied!"); - return null; + + for (int i = 0; i < serverLen; i++) { // 遍历所有 server 元素 + Element serverElement = (Element) serverElements.item(i); // 获取当前 server 元素 + + String temp_ip = serverElement.hasAttribute("ip")? serverElement.getAttribute("ip") : null; // 获取 IP 地址 + if (temp_ip == null) { // 如果 IP 地址为空 + logger.error("redis.servers.server.ip must be supplied!"); // 记录错误日志 + return null; // 返回空列表 } - String temp_port = serverElement.hasAttribute("port") ? serverElement.getAttribute("port") : "6379"; - String temp_needAuth = serverElement.hasAttribute("needAuth") ? serverElement.getAttribute("needAuth") : "false"; - String temp_auth = null; - // need auth + String temp_port = serverElement.hasAttribute("port")? serverElement.getAttribute("port") : "6379"; // 获取端口号 + String temp_needAuth = serverElement.hasAttribute("needAuth")? serverElement.getAttribute("needAuth") : "false"; // 获取是否需要身份验证 + String temp_auth = null; // 身份验证密码 + + // 需要身份验证 if ("true".equals(temp_needAuth)) { - temp_auth = serverElement.hasAttribute("auth") ? serverElement.getAttribute("auth") : null; - if (null == temp_auth) { - logger.error("since needAuth is true,auth must be supplied!"); - return null; + temp_auth = serverElement.hasAttribute("auth")? serverElement.getAttribute("auth") : null; // 获取身份验证密码 + if (null == temp_auth) { // 如果身份验证密码为空 + logger.error("since needAuth is true, auth must be supplied!"); // 记录错误日志 + return null; // 返回空列表 } } - RedisServerNodeBean rs = null; + RedisServerNodeBean rs = null; // 创建 Redis 服务器节点对象 try { - rs = new RedisServerNodeBean(temp_ip, Integer.parseInt(temp_port), Boolean.parseBoolean(temp_needAuth), temp_auth); - } catch (NumberFormatException e) { - logger.error("port must be a number!\n" + e.getMessage()); - return null; + rs = new RedisServerNodeBean(temp_ip, Integer.parseInt(temp_port), Boolean.parseBoolean(temp_needAuth), temp_auth); // 创建 Redis 服务器节点对象 + } catch (NumberFormatException e) { // 如果端口号转换为整数时发生异常 + logger.error("port must be a number!\n" + e.getMessage()); // 记录错误日志 + return null; // 返回空列表 } - redisServers.add(rs); + redisServers.add(rs); // 将 Redis 服务器节点对象添加到列表中 } return redisServers; } /** - * 转换自定义配置为JedisShardInfo对象 - * @param redisServers - * @return + * 将自定义配置转换为 JedisShardInfo 对象列表 + * @param redisServers Redis 服务器节点信息列表 + * @return JedisShardInfo 对象列表 */ private List getJedisShardInfo(List redisServers) { - if(redisServers == null){ - logger.error("redisServers must not be empty null"); - return null; + if (redisServers == null) { // 如果 Redis 服务器节点信息列表为空 + logger.error("redisServers must not be empty null"); // 记录错误日志 + return null; // 返回空列表 } - int serverLen = redisServers.size(); - if (serverLen < 1) { - logger.error("redisServers must not be empty "); - return null; + int serverLen = redisServers.size(); // 获取 Redis 服务器节点的数量 + if (serverLen < 1) { // 如果 Redis 服务器节点的数量小于 1 + logger.error("redisServers must not be empty "); // 记录错误日志 + return null; // 返回空列表 } - List servers = new ArrayList(serverLen); - for (int i = 0; i < serverLen; i++) { - RedisServerNodeBean redisServer = redisServers.get(i); - JedisShardInfo jedisShardInfo = new JedisShardInfo(redisServer.getIp(), redisServer.getPort()); - if (redisServer.isNeedAuth()) { - jedisShardInfo.setPassword(redisServer.getAuth()); + List servers = new ArrayList(serverLen); // 创建 JedisShardInfo 对象列表 + + for (int i = 0; i < serverLen; i++) { // 遍历 Redis 服务器节点信息列表 + RedisServerNodeBean redisServer = redisServers.get(i); // 获取当前 Redis 服务器节点对象 + JedisShardInfo jedisShardInfo = new JedisShardInfo(redisServer.getIp(), redisServer.getPort()); // 创建 JedisShardInfo 对象 + if (redisServer.isNeedAuth()) { // 如果需要身份验证 + jedisShardInfo.setPassword(redisServer.getAuth()); // 设置身份验证密码 } - servers.add(jedisShardInfo); + servers.add(jedisShardInfo); // 将 JedisShardInfo 对象添加到列表中 } return servers; } - - /* - * 初始化redis的key前缀 + + /** + * 初始化 Redis 键的前缀 */ private void initPreKey() { - Element preKeyElement = (Element) document.getElementsByTagName("preKey").item(0); - preKey = preKeyElement.hasAttribute("value") ? preKeyElement.getAttribute("value") : ""; + Element preKeyElement = (Element) document.getElementsByTagName("preKey").item(0); // 获取 preKey 元素 + preKey = preKeyElement.hasAttribute("value")? preKeyElement.getAttribute("value") : ""; // 获取前缀值 } + /** + * 获取 Redis 键的前缀 + * @return Redis 键的前缀 + */ public String getPreKey() { return preKey; } + /** - * 从jedis连接池获得一个连接 - * @return + * 从 Jedis 连接池获取一个连接 + * @return Jedis 连接 */ public ShardedJedis getConnection() { return shardedJedisPool.getResource(); } + /** - * 把连接放回jedis连接池 - * @param resource + * 将连接放回 Jedis 连接池 + * @param resource Jedis 连接 */ public void closeConnection(ShardedJedis resource) { resource.close(); } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookCategoryEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookCategoryEntity.java index 885f04d..0e0b159 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookCategoryEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookCategoryEntity.java @@ -8,31 +8,35 @@ import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; import lombok.Data; +/** + * BookCategoryEntity 类,用于表示书籍分类信息 + */ @Data @TableName(value="b_book_category") -public class BookCategoryEntity extends Model{ +public class BookCategoryEntity extends Model { private static final long serialVersionUID = 1L; - + + // 定义字段 @TableId - private String id; - private String parentId; - private String parentIds; - private String treeSort; - private String treeSorts; - private String treeLeaf; - private String treeLevel; - private String treeNames; - private String name; - private String seoTitle; - private String seoKeywords; - private String seoDescription; - private Date createDate; - private Date updateDate; + private String id; // 分类 ID + private String parentId; // 父分类 ID + private String parentIds; // 父分类 ID 列表 + private String treeSort; // 树排序 + private String treeSorts; // 树排序列表 + private String treeLeaf; // 是否叶子节点 + private String treeLevel; // 树层次 + private String treeNames; // 树名称 + private String name; // 分类名称 + private String seoTitle; // SEO 标题 + private String seoKeywords; // SEO 关键词 + private String seoDescription; // SEO 描述 + private Date createDate; // 创建日期 + private Date updateDate; // 更新日期 + // 重写 pkVal 方法,返回 ID 作为主键值 @Override protected Serializable pkVal() { return getId(); } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookEntity.java index c13b405..1c62cf4 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/BookEntity.java @@ -10,33 +10,39 @@ import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; import lombok.Data; +/** + * BookEntity 类,用于表示书籍信息 + */ @Data @TableName(value="b_book") -public class BookEntity extends Model{ +public class BookEntity extends Model { private static final long serialVersionUID = 1L; - + + // 定义字段 @TableId - private String id; - private String categoryId; - private String bookImage; - private String owner; - private String name; - private String seoTitle; - private String seoKeywords; - private String seoDescription; - private Date createDate; - private Date updateDate; - + private String id; // 书籍 ID + private String categoryId; // 书籍分类 ID + private String bookImage; // 书籍图片 + private String owner; // 书籍所有者 + private String name; // 书籍名称 + private String seoTitle; // SEO 标题 + private String seoKeywords; // SEO 关键词 + private String seoDescription; // SEO 描述 + private Date createDate; // 创建日期 + private Date updateDate; // 更新日期 + + // 定义关联字段 @TableField(exist=false) - private List categoryIds; + private List categoryIds; // 分类 ID 列表 @TableField(exist=false) - private String memberName; + private String memberName; // 会员名称 @TableField(exist=false) - private String categoryName; + private String categoryName; // 分类名称 + // 重写 pkVal 方法,返回 ID 作为主键值 @Override protected Serializable pkVal() { return getId(); } -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/DocumentEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/DocumentEntity.java index d8bce1e..b756bae 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/DocumentEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/DocumentEntity.java @@ -13,46 +13,51 @@ import com.baomidou.mybatisplus.annotations.TableName; import com.tamguo.modules.book.model.enums.DocumentStatusEnum; import lombok.Data; +/** + * DocumentEntity 类,用于表示文档信息 + */ @Data @TableName(value="b_document") -public class DocumentEntity extends Model{ +public class DocumentEntity extends Model { private static final long serialVersionUID = 1L; - + + // 定义字段 @TableId - private String id; - private String batchNo; - private String parentId; - private String bookId; - private String owner; - private String name; - @JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString) - private DocumentStatusEnum status; + private String id; // 文档 ID + private String batchNo; // 批次号 + private String parentId; // 父文档 ID + private String bookId; // 所属书籍 ID + private String owner; // 所有者 + private String name; // 文档名称 + @JSONField(serialzeFeatures=SerializerFeature.WriteEnumUsingToString) + private DocumentStatusEnum status; // 文档状态 @TableField(value="is_open") - private String isOpen; - private Date createDate; - private Date updateDate; - - private String content; - private String markdown; - + private String isOpen; // 是否公开 + private Date createDate; // 创建日期 + private Date updateDate; // 更新日期 + + // 定义关联字段 + private String content; // 文档内容 + private String markdown; // Markdown 内容 + @TableField(exist=false) - private Integer level; + private Integer level; // 层级 @TableField(exist=false) - private String rootId; + private String rootId; // 根文档 ID @TableField(exist=false) - private boolean leaf; + private boolean leaf; // 是否叶子节点 @TableField(exist=false) - private List children; + private List children; // 子文档列表 @TableField(exist=false) - private String cover; - + private String cover; // 封面 + @TableField(exist=false) - private List fileUploads; + private List fileUploads; // 文件上传列表 + // 重写 pkVal 方法,返回 ID 作为主键值 @Override protected Serializable pkVal() { return getId(); } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/FileEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/FileEntity.java index 40fe810..b7f969f 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/FileEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/FileEntity.java @@ -4,16 +4,29 @@ import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; import lombok.Data; +/** + * FileEntity 类,用于表示文件实体 + */ @Data @TableName(value="b_file_entity") public class FileEntity { - @TableId("file_id") + // 文件 ID + @TableId("file_id") private String fileId; - + + // 文件 MD5 值 private String fileMd5; + + // 文件路径 private String filePath; + + // 文件类型 private String fileContentType; + + // 文件扩展名 private String fileExtension; + + // 文件大小(字节数) private Long fileSize; -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/FileUploadEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/FileUploadEntity.java index 4921c8e..63b0560 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/FileUploadEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/FileUploadEntity.java @@ -12,33 +12,51 @@ import com.tamguo.modules.book.model.enums.BizTypeEnum; import com.tamguo.modules.book.model.enums.FileUploadStatusEnum; import lombok.Data; +/** + * FileUploadEntity 类,用于表示文件上传信息 + */ @Data @TableName(value="b_file_upload") -public class FileUploadEntity extends Model{ - +public class FileUploadEntity extends Model { + private static final long serialVersionUID = 1L; - + + // 文件上传 ID private String id; + // 文件 ID private String fileId; + // 文件名 private String fileName; + // 文件类型 private String fileType; - private String bizKey; - @JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString) + // 业务键 + private String bizKey; + // 业务类型 + @JSONField(serialzeFeatures = SerializerFeature.WriteEnumUsingToString) private BizTypeEnum bizType; - @JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString) + // 文件上传状态 + @JSONField(serialzeFeatures = SerializerFeature.WriteEnumUsingToString) private FileUploadStatusEnum status; + // 创建人 private String createBy; + // 创建日期 private Date createDate; + // 更新人 private String updateBy; + // 更新日期 private Date updateDate; + // 备注 private String remarks; + // 文件路径(不存在数据库中,通过查询关联表得到) @TableField(exist=false) private String filePath; + // 文件大小(字节数)(不存在数据库中,通过查询关联表得到) @TableField(exist=false) private Long fileSize; + + // 重写 pkVal 方法,返回 ID 作为主键值 @Override protected Serializable pkVal() { return getId(); } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/BizTypeEnum.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/BizTypeEnum.java index e3258dd..c52f156 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/BizTypeEnum.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/BizTypeEnum.java @@ -1,32 +1,50 @@ package com.tamguo.modules.book.model.enums; -import java.io.Serializable; -import com.baomidou.mybatisplus.enums.IEnum; +import java.io.Serializable; // 导入 Serializable 接口 +import com.baomidou.mybatisplus.enums.IEnum; // 导入 IEnum 接口 /** - * 用户状态 + * 用户状态枚举类,实现了 IEnum 接口 */ public enum BizTypeEnum implements IEnum { - DOCUMENT("document", "文档"); + // 文档类型 + DOCUMENT("document", "文档"); - private String value; - private String desc; + private String value; // 枚举值 + private String desc; // 枚举描述 + /** + * 构造函数,用于初始化枚举值和描述 + * @param value 枚举值 + * @param desc 枚举描述 + */ BizTypeEnum(final String value, final String desc) { this.value = value; this.desc = desc; } + /** + * 获取枚举值 + * @return 枚举值 + */ public Serializable getValue() { return this.value; } + /** + * 获取枚举描述 + * @return 枚举描述 + */ public String getDesc(){ return this.desc; } - + + /** + * 重写 toString 方法,返回枚举值 + * @return 枚举值 + */ @Override public String toString() { - return this.value; + return this.value; } -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/DocumentStatusEnum.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/DocumentStatusEnum.java index 582e08b..41781c5 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/DocumentStatusEnum.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/DocumentStatusEnum.java @@ -4,30 +4,53 @@ import java.io.Serializable; import com.baomidou.mybatisplus.enums.IEnum; /** - * 用户状态 + * 文档状态枚举类 */ public enum DocumentStatusEnum implements IEnum { - NORMAL("normal", "正常"), - HISTORY("history", "历史版本"); + /** + * 正常状态 + */ + NORMAL("normal", "正常"), + /** + * 历史版本状态 + */ + HISTORY("history", "历史版本"); - private String value; - private String desc; + private String value; // 状态值 + private String desc; // 状态描述 + /** + * 构造函数,用于初始化状态值和描述 + * @param value 状态值 + * @param desc 状态描述 + */ DocumentStatusEnum(final String value, final String desc) { this.value = value; this.desc = desc; } + /** + * 获取状态值 + * @return 状态值 + */ public Serializable getValue() { return this.value; } + /** + * 获取状态描述 + * @return 状态描述 + */ public String getDesc(){ return this.desc; } - + + /** + * 重写 toString 方法,返回状态值 + * @return 状态值 + */ @Override public String toString() { - return this.value; + return this.value; } -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/FileUploadStatusEnum.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/FileUploadStatusEnum.java index ff95cc3..f180b2e 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/FileUploadStatusEnum.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/model/enums/FileUploadStatusEnum.java @@ -4,30 +4,53 @@ import java.io.Serializable; import com.baomidou.mybatisplus.enums.IEnum; /** - * 用户状态 + * 文件上传状态枚举类 */ public enum FileUploadStatusEnum implements IEnum { - NORMAL("normal", "正常"), - DELETE("delete", "删除"); + /** + * 正常状态 + */ + NORMAL("normal", "正常"), + /** + * 删除状态 + */ + DELETE("delete", "删除"); - private String value; - private String desc; + private String value; // 状态值 + private String desc; // 状态描述 + /** + * 构造函数,用于初始化状态值和描述 + * @param value 状态值 + * @param desc 状态描述 + */ FileUploadStatusEnum(final String value, final String desc) { this.value = value; this.desc = desc; } + /** + * 获取状态值 + * @return 状态值 + */ public Serializable getValue() { return this.value; } + /** + * 获取状态描述 + * @return 状态描述 + */ public String getDesc(){ return this.desc; } - + + /** + * 重写 toString 方法,返回状态值 + * @return 状态值 + */ @Override public String toString() { - return this.value; + return this.value; } -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/BookServiceImpl.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/BookServiceImpl.java index 1e9c942..e0b88af 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/BookServiceImpl.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/BookServiceImpl.java @@ -11,22 +11,30 @@ import com.tamguo.modules.book.dao.BookMapper; import com.tamguo.modules.book.model.BookEntity; import com.tamguo.modules.book.service.IBookService; +/** + * BookServiceImpl 类,实现了 IBookService 接口 + */ @Service(value="bbookServiceImpl") -public class BookServiceImpl extends ServiceImpl implements IBookService{ +public class BookServiceImpl extends ServiceImpl implements IBookService { + /** + * 保存书籍信息 + * + * @param book 书籍实体 + */ @Transactional(readOnly=false) @Override public void saveBook(BookEntity book) { - book.setCreateDate(new Date()); - book.setUpdateDate(new Date()); - book.setSeoDescription(book.getName()); - book.setSeoKeywords(book.getName()); - book.setSeoTitle(book.getName()); - if(StringUtils.isEmpty(book.getId())) { - this.insert(book); - }else { - this.updateById(book); + book.setCreateDate(new Date()); // 设置创建日期为当前日期 + book.setUpdateDate(new Date()); // 设置更新日期为当前日期 + book.setSeoDescription(book.getName()); // 设置 SEO 描述为书籍名称 + book.setSeoKeywords(book.getName()); // 设置 SEO 关键词为书籍名称 + book.setSeoTitle(book.getName()); // 设置 SEO 标题为书籍名称 + + if (StringUtils.isEmpty(book.getId())) { // 如果书籍 ID 为空 + this.insert(book); // 执行插入操作 + } else { + this.updateById(book); // 执行更新操作 } } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/DocumentServiceImpl.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/DocumentServiceImpl.java index bb950b5..5eb219f 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/DocumentServiceImpl.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/book/service/impl/DocumentServiceImpl.java @@ -12,14 +12,23 @@ import com.tamguo.modules.book.model.DocumentEntity; import com.tamguo.modules.book.model.enums.DocumentStatusEnum; import com.tamguo.modules.book.service.IDocumentService; +/** + * DocumentServiceImpl 类,实现了 IDocumentService 接口 + */ @Service -public class DocumentServiceImpl extends ServiceImpl implements IDocumentService{ +public class DocumentServiceImpl extends ServiceImpl implements IDocumentService { - @Transactional(readOnly=false) + /** + * 修改文档 + * + * @param document 文档实体 + */ + @Transactional(readOnly = false) @Override public void modify(DocumentEntity document) { - DocumentEntity entity = this.selectById(document.getId()); - if("yes".equals(document.getCover())) { + DocumentEntity entity = this.selectById(document.getId()); // 根据 ID 获取文档实体 + + if ("yes".equals(document.getCover())) { // 覆盖修改 entity.setContent(document.getContent()); entity.setMarkdown(document.getMarkdown()); @@ -28,47 +37,51 @@ public class DocumentServiceImpl extends ServiceImpl implements Serializable { private static final long serialVersionUID = 1L; - + + // 用户名 private String username; + // 昵称 private String nickName; + // 密码 private String password; + // 头像 private String avatar; + // 手机号 private String mobile; + // 邮箱 private String email; + // 积分 private Integer point; + // 余额 private BigDecimal amount; + // 最后登录时间 private Date lastLoginTime; + // 发布文章数 private Integer paperNum; + // 提问数 private Integer questionNum; + // 下载数 private Integer downNum; + // 点击数 private Integer hitsNum; + // 验证码(数据库中不存在该字段) @TableField(exist=false) private String verifyCode; + // 当前密码(数据库中不存在该字段) @TableField(exist=false) private String nowPassword; - } \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/member/model/condition/MemberCondition.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/member/model/condition/MemberCondition.java index 5d2e855..994f66f 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/member/model/condition/MemberCondition.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/member/model/condition/MemberCondition.java @@ -1,43 +1,99 @@ package com.tamguo.modules.member.model.condition; +/** + * MemberCondition 类,用于封装会员查询条件 + */ public class MemberCondition { - + + // 当前页码 private Integer pageNo; + // 每页显示数量 private Integer pageSize; + // 手机号码 private String mobile; + // 用户名 private String username; + // 昵称 private String nickName; - + + /** + * 获取手机号码 + * @return 手机号码 + */ public String getMobile() { return mobile; } + + /** + * 设置手机号码 + * @param mobile 手机号码 + */ public void setMobile(String mobile) { this.mobile = mobile; } + + /** + * 获取用户名 + * @return 用户名 + */ public String getUsername() { return username; } + + /** + * 设置用户名 + * @param username 用户名 + */ public void setUsername(String username) { this.username = username; } + + /** + * 获取昵称 + * @return 昵称 + */ public String getNickName() { return nickName; } + + /** + * 设置昵称 + * @param nickName 昵称 + */ public void setNickName(String nickName) { this.nickName = nickName; } + + /** + * 获取当前页码 + * @return 当前页码 + */ public Integer getPageNo() { return pageNo; } + + /** + * 设置当前页码 + * @param pageNo 当前页码 + */ public void setPageNo(Integer pageNo) { this.pageNo = pageNo; } + + /** + * 获取每页显示数量 + * @return 每页显示数量 + */ public Integer getPageSize() { return pageSize; } + + /** + * 设置每页显示数量 + * @param pageSize 每页显示数量 + */ public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/member/service/impl/MemberService.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/member/service/impl/MemberService.java index 438a5c8..33ff565 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/member/service/impl/MemberService.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/member/service/impl/MemberService.java @@ -239,49 +239,532 @@ public class MemberService extends ServiceImpl imple if(!entity.getPassword().equals(new Sha256Hash(member.getPassword()).toHex())) { return Result.result(501, null, "旧密码错误!"); } - if(!cacheService.isExist(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile())){ - return Result.result(502, null, "验证码错误"); - } - entity.setPassword(new Sha256Hash(member.getNowPassword()).toHex()); - return Result.result(0, null, "修改成功"); - } + package com.tamguo.modules.member.service.impl; - @SuppressWarnings("unchecked") - @Transactional(readOnly=true) - @Override - public Page listData(MemberCondition condition) { - Page page = new Page<>(condition.getPageNo(), condition.getPageSize()); - Condition query = Condition.create(); - if(!StringUtils.isEmpty(condition.getMobile())) { - query.eq("mobile", condition.getMobile()); - } - if(!StringUtils.isEmpty(condition.getNickName())) { - query.like("nick_name", condition.getNickName()); - } - if(!StringUtils.isEmpty(condition.getUsername())) { - query.eq("username", condition.getUsername()); - } - return this.selectPage(page, query); - } +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.UUID; +import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.crypto.hash.Sha256Hash; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; - @Transactional(readOnly=false) - @Override - public void reward(String id ,String bookId , Integer rewardPoint, BigDecimal rewardMoney) { - MemberEntity member = memberMapper.selectById(id); - - // 更新记录 - member.setPoint(member.getPoint() + rewardPoint); - member.setAmount(member.getAmount().add(rewardMoney)); - this.updateById(member); - - BookEntity book = iBookService.selectById(bookId); - - // 发送短信 - try { - iSmsService.sendRewardSms(member.getMobile(), member.getUsername(), book.getName(), rewardPoint, rewardMoney); - } catch (ClientException e) { - e.printStackTrace(); - } - } - -} +import com.aliyuncs.exceptions.ClientException; +import com.baomidou.mybatisplus.mapper.Condition; +import com.baomidou.mybatisplus.plugins.Page; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.tamguo.common.utils.Result; +import com.tamguo.common.utils.SystemConstant; +import com.tamguo.config.redis.CacheService; +import com.tamguo.modules.book.model.BookEntity; +import com.tamguo.modules.book.service.IBookService; +import com.tamguo.modules.member.dao.MemberMapper; +import com.tamguo.modules.member.model.MemberEntity; +import com.tamguo.modules.member.model.condition.MemberCondition; +import com.tamguo.modules.member.service.IMemberService; +import com.tamguo.modules.sys.service.ISmsService; + +/** + * MemberServiceImpl 类,实现了 IMemberService 接口 + */ + @Service + public class MemberServiceImpl extends ServiceImpl implements IMemberService { + + // 注入 MemberMapper + @Autowired + private MemberMapper memberMapper; + + // 注入 CacheService + @Autowired + private CacheService cacheService; + + // 注入 ISmsService + @Autowired + private ISmsService iSmsService; + + // 注入 IBookService + @Autowired + private IBookService iBookService; + + /** + * 登录方法 + * + * @param username 用户名 + * @param password 密码 + * @return 登录结果 + */ + @Override + public Result login(String username, String password) { + // 创建 MemberEntity 对象 + MemberEntity condition = new MemberEntity(); + // 设置用户名 + condition.setUsername(username); + // 从数据库中查询该用户 + MemberEntity member = memberMapper.selectOne(condition); + // 如果用户不存在 + if (member == null) { + // 返回错误结果,提示用户名 或 password 有误 + return Result.result(201, member, "用户名或密码有误,请重新输入或找回密码"); + } + // 获取该用户的登录失败次数 + Integer loginFailureCount = this.getLoginFailureCount(member); + // 如果密码错误 + if (!new Sha256Hash(password).toHex().equals(member.getPassword())) { + // 登录失败次数加 1 + loginFailureCount++; + // 更新登录失败次数 + this.updateLoginFailureCount(member, loginFailureCount); + // 返回错误结果,提示用户名 或 password 有误 + return Result.result(202, member, "用户名或密码有误,请重新输入或找回密码"); + } + // 更新登录失败次数为 0 + this.updateLoginFailureCount(member, 0); + // 返回正确结果,提示登录成功 + return Result.result(200, member, "登录成功"); + } + + /** + * 更新登录失败次数 + * + * @param member 会员实体 + * @param loginFailureCount 登录失败次数 + */ + public void updateLoginFailureCount(MemberEntity member, Integer loginFailureCount) { + // 将登录失败次数存储到缓存中,key 为 LOGIN_FAILURE_COUNT + member.getId() + cacheService.setObject(SystemConstant.LOGIN_FAILURE_COUNT + member.getId(), loginFailureCount, 2 * 60 * 60); + } + + /** + * 获取登录失败次数 + * + * @param member 会员实体 + * @return 登录失败次数 + */ + public Integer getLoginFailureCount(MemberEntity member) { + // 如果 member 为空 + if (member == null) { + // 返回 0 + return 0; + } + // 如果缓存中不存在登录失败次数 + if (!cacheService.isExist(SystemConstant.LOGIN_FAILURE_COUNT + member.getId())) { + // 返回 0 + return 0; + } + // 从缓存中获取登录失败次数 + return (Integer) cacheService.getObject(SystemConstant.LOGIN_FAILURE_COUNT + member.getId()); + } + + /** + * 检查用户名是否存在 + * + * @param username 用户名 + * @return 检查结果 + */ + @Override + public Result checkUsername(String username) { + // 创建 MemberEntity 对象 + MemberEntity condition = new MemberEntity(); + // 设置用户名 + condition.setUsername(username); + // 从数据库中查询该用户 + MemberEntity member = memberMapper.selectOne(condition); + // 如果用户存在 + if (member!= null) { + // 返回错误结果,提示该用户名已经存在 + return Result.result(201, null, "该用户名已经存在"); + } + // 返回正确结果,提示该用户名可用 + return Result.result(200, null, "该用户名可用"); + } + + /** + * 检查手机号是否存在 + * + * @param mobile 手机号 + * @return 检查结果 + */ + @Override + public Result checkMobile(String mobile) { + // 创建 MemberEntity 对象 + MemberEntity condition = new MemberEntity(); + // 设置手机号 + condition.setMobile(mobile); + // 从数据库中查询该用户 + MemberEntity member = memberMapper.selectOne(condition); + // 如果用户存在 + if (member!= null) { + // 返回错误结果,提示该手机号已经存在 + return Result.result(201, null, "该手机号已经存在"); + } + // 返回正确结果,提示该手机号可用 + return Result.result(200, null, "该手机号可用"); + } + + /** + * 注册方法 + * + * @param member 会员实体 + * @return 注册结果 + */ + @Transactional(readOnly = false) + @Override + public Result register(MemberEntity member) { + // 创建 MemberEntity 对象 + MemberEntity condition = new MemberEntity(); + // 设置用户名 + condition.setUsername(member.getUsername()); + // 从数据库中查询该用户 + MemberEntity m = memberMapper.selectOne(condition); + // 如果用户已存在 + if (m!= null) { + // 返回错误结果,提示该用户已经存在 + return Result.result(201, null, "该用户已经存在"); + } + // 创建 MemberEntity 对象 + condition = new MemberEntity(); + // 设置手机号 + condition.setMobile(member.getMobile()); + // 从数据库中查询该用户 + m = memberMapper.selectOne(condition); + // 如果手机号已存在 + if (m!= null) { + // 返回错误结果,提示该手机号已经存在 + return Result.result(202, null, "该手机号已经存在"); + } + // 如果缓存中不存在验证码 + if (!cacheService.isExist(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile())) { + // 返回错误结果,提示验证码错误 + return Result.result(203, null, "验证码错误"); + } + // 从缓存中获取验证码 + String code = (String) cacheService.getObject(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile()); + // 如果验证码错误 + if (!code.equals(member.getVerifyCode())) { + // 返回错误结果,提示验证码错误 + return Result.result(204, null, "验证码错误"); + } + // 创建 MemberEntity 对象 + MemberEntity entity = new MemberEntity(); + // 设置头像 + entity.setAvatar(SystemConstant.DEFAULT_MEMBER_AVATAR); + // 设置手机号 + entity.setMobile(member.getMobile()); + // 设置密码 + entity.setPassword(new Sha256Hash(member.getPassword()).toHex()); + // 设置用户名 + entity.setUsername(member.getUsername()); + // 设置昵称 + entity.setNickName(member.getUsername()); + // 设置邮箱 + entity.setEmail(member.getEmail()); + // 插入会员信息 + memberMapper.insert(entity); + // 返回正确结果,提示注册成功 + return Result.result(200, entity, "注册成功"); + } + + /** + * 检查帐号是否存在 + * + * @param account 帐号 + * @return 检查结果 + */ + @SuppressWarnings("unchecked") + @Override + public Result checkAccount(String account) { + // 如果帐号为空 + if (StringUtils.isEmpty(account)) { + // 返回错误结果,提示帐号不存在 + return Result.result(201, null, "帐号不存在!"); + } + // 创建 Condition 对象 + Condition query = Condition.create(); + // 添加条件,根据帐号查询会员信息 + query.eq("user_name", account).or().eq("mobile", account); + // 从数据库中查询会员信息 + List members = memberMapper.selectList(query); + // 如果没有查询到会员信息 + if (members.size() == 0) { + // 返回错误结果,提示帐号不存在 + return Result.result(201, null, "帐号不存在!"); + } + // 返回正确结果,提示帐号存在,并返回会员信息 + return Result.result(200, members.get(0), "该帐号存在"); + } + + /** + * 确认帐号是否存在 + * + * @param account 帐号 + * @param veritycode 验证码 + * @return 确认结果 + */ + @SuppressWarnings("unchecked") + @Override + public Result confirmAccount(String account, String veritycode) { + // 如果帐号为空 + if (StringUtils.isEmpty(account)) { + // 返回错误结果,提示帐号不存在 + return Result.result(201, null, "帐号不存在!"); + } + // 创建 Condition 对象 + Condition query = Condition.create(); + // 添加条件,根据帐号查询会员信息 + query.eq("username", account).or().eq("mobile", account); + // 从数据库中查询会员信息 + List members = memberMapper.selectList(query); + // 如果没有查询到会员信息 + if (members.size() == 0) { + // 返回错误结果,提示帐号不存在 + return Result.result(201, null, "帐号不存在!"); + } + // 返回正确结果,提示帐号存在,并返回会员信息 + return Result.result(200, members.get(0), "该帐号存在"); + } + + /** + * 安全检查 + * + * @param username 用户名 + * @param isEmail 是否为邮箱 + * @param vcode 验证码 + * @return 安全检查结果 + */ + @Override + public Result securityCheck(String username, String isEmail, String vcode) { + // 创建 MemberEntity 对象 + MemberEntity condition = new MemberEntity(); + // 设置用户名 + condition.setUsername(username); + // 从数据库中查询该用户 + MemberEntity member = memberMapper.selectOne(condition); + // 如果用户不存在 + if (member == null) { + // 返回错误结果,提示用户不存在 + return Result.result(201, member, "用户不存在"); + } + // 如果是邮箱验证 + if ("1".equals(isEmail)) { + // 如果缓存中不存在验证码 + if (!cacheService.isExist(SystemConstant.ALIYUN_MAIL_FIND_PASSWORD_PREFIX + member.getEmail())) { + // 返回错误结果,提示验证码错误 + return Result.result(201, member, "验证码错误"); + } + // 从缓存中获取验证码 + String code = (String) cacheService.getObject(SystemConstant.ALIYUN_MAIL_FIND_PASSWORD_PREFIX + member.getEmail()); + // 如果验证码错误 + if (!code.equals(vcode)) { + // 返回错误结果,提示验证码错误 + return Result.result(202, member, "验证码错误"); + } + } else { + // 如果缓存中不存在验证码 + if (!cacheService.isExist(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile())) { + // 返回错误结果,提示验证码错误 + return Result.result(203, member, "验证码错误"); + } + // 从缓存中获取验证码 + String code = (String) cacheService.getObject(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile()); + // 如果验证码错误 + if (!code.equals(vcode)) { + // 返回错误结果,提示验证码错误 + return Result.result(204, member, "验证码错误"); + } + } + // 创建随机字符串 + String key = UUID.randomUUID().toString(); + // 将用户名存储到缓存中,key 为 SECURITY_CHECK_PREFIX + key + cacheService.setObject(SystemConstant.SECURITY_CHECK_PREFIX + key, username, 2 * 60 * 60); + // 返回正确结果,提示安全验证通过,并返回随机字符串 + return Result.result(200, key, "安全验证通过"); + } + + /** + * 重置密码 + * + * @param resetPasswordKey 重置密码 key + * @param username 用户名 + * @param password 新密码 + * @param verifypwd 确认密码 + * @return 重置密码结果 + */ + @Override + public Result resetPassword(String resetPasswordKey, String username, String password, String verifypwd) { + // 如果缓存中存在重置密码 key + if (cacheService.isExist(SystemConstant.SECURITY_CHECK_PREFIX + resetPasswordKey)) { + // 创建 MemberEntity 对象 + MemberEntity condition = new MemberEntity(); + // 设置用户名 + condition.setUsername(username); + // 从数据库中查询该用户 + MemberEntity member = memberMapper.selectOne(condition); + // 如果密码和确认密码不一致 + if (!password.equals(verifypwd)) { + // 返回错误结果,提示密码不一致 + return Result.result(201, null, "密码不一致"); + } + // 设置密码 + member.setPassword(new Sha256Hash(password).toHex()); + // 更新会员信息 + memberMapper.updateById(member); + } + // 返回正确结果,提示更新成功 + return Result.result(200, null, "更新成功"); + } + + /** + * 更新会员信息 + * + * @param member 会员实体 + */ + @Transactional(readOnly = false) + @Override + public void updateMember(MemberEntity member) { + // 获取会员信息 + MemberEntity entity = memberMapper.selectById(member.getId()); + // 设置头像 + entity.setAvatar(member.getAvatar()); + // 设置邮箱 + entity.setEmail(member.getEmail()); + // 设置手机号 + entity.setMobile(member.getMobile()); + // 设置昵称 + entity.setNickName(member.getNickName()); + // 更新会员信息 + memberMapper.updateById(entity); + } + + /** + * 根据 uid 查询会员信息 + * + * @param uid uid + * @return 会员信息 + */ + @Transactional(readOnly = true) + @Override + public MemberEntity findByUid(String uid) { + // 根据 uid 查询会员信息 + return memberMapper.selectById(uid); + } + + /** + * 根据用户名查询会员信息 + * + * @param username 用户名 + * @return 会员信息 + */ + @SuppressWarnings("unchecked") + @Transactional(readOnly = true) + @Override + public MemberEntity findByUsername(String username) { + // 创建 Condition 对象 + Condition query = Condition.create(); + // 添加条件,根据用户名查询会员信息 + query.eq("username", username).or().eq("mobile", username).or().eq("email", username); + // 从数据库中查询会员信息 + return this.selectOne(query); + } + + /** + * 更新会员最后登录时间 + * + * @param uid uid + */ + @Transactional(readOnly = false) + @Override + public void updateLastLoginTime(String uid) { + // 获取会员信息 + MemberEntity member = memberMapper.selectById(uid); + // 设置最后登录时间为当前时间 + member.setLastLoginTime(new Date()); + // 更新会员信息 + memberMapper.updateById(member); + } + + /** + * 获取当前会员信息 + * + * @param id id + * @return 会员信息 + */ + @Override + public MemberEntity findCurrMember(String id) { + // 获取会员信息 + MemberEntity member = memberMapper.selectById(id); + // 将密码设置为 null + member.setPassword(null); + // 返回会员信息 + return member; + } + + /** + * 更新密码 + * + * @param member 会员实体 + * @return 更新结果 + */ + @Transactional(readOnly = false) + @Override + public Result updatePwd(MemberEntity member) { + // 获取会员信息 + MemberEntity entity = memberMapper.selectById(member.getId()); + // 如果旧密码错误 + if (!entity.getPassword().equals(new Sha256Hash(member.getPassword()).toHex())) { + // 返回错误结果,提示旧密码错误 + return Result.result(501, null, "旧密码错误!"); + } + // 如果缓存中不存在验证码 + if (!cacheService.isExist(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile())){ + // 如果缓存服务中不存在指定的验证码前缀与会员手机号的组合 + return Result.result(502, null, "验证码错误"); + } + entity.setPassword(new Sha256Hash(member.getNowPassword()).toHex()); +// 设置实体的密码为会员当前密码的 Sha256 哈希值的十六进制表示 + return Result.result(0, null, "修改成功"); + } + + @SuppressWarnings("unchecked") + @Transactional(readOnly=true) + @Override + public Page listData(MemberCondition condition) { + // 创建分页对象 + Page page = new Page<>(condition.getPageNo(), condition.getPageSize()); + Condition query = Condition.create(); + // 如果条件中的手机号不为空 + if(!StringUtils.isEmpty(condition.getMobile())) { + query.eq("mobile", condition.getMobile()); + } + // 如果条件中的昵称不为空 + if(!StringUtils.isEmpty(condition.getNickName())) { + query.like("nick_name", condition.getNickName()); + } + // 如果条件中的用户名不为空 + if(!StringUtils.isEmpty(condition.getUsername())) { + query.eq("username", condition.getUsername()); + } + return this.selectPage(page, query); + } + + @Transactional(readOnly=false) + @Override + public void reward(String id,String bookId, Integer rewardPoint, BigDecimal rewardMoney) { + MemberEntity member = memberMapper.selectById(id); + // 获取会员实体 + // 更新会员的积分和金额 + member.setPoint(member.getPoint() + rewardPoint); + member.setAmount(member.getAmount().add(rewardMoney)); + this.updateById(member); + + BookEntity book = iBookService.selectById(bookId); + // 获取书籍实体 + + // 发送短信 + try { + iSmsService.sendRewardSms(member.getMobile(), member.getUsername(), book.getName(), rewardPoint, rewardMoney); + } catch (ClientException e) { + e.printStackTrace(); + } + } diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysAreaEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysAreaEntity.java index 66195eb..f4be33e 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysAreaEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysAreaEntity.java @@ -14,48 +14,67 @@ import com.baomidou.mybatisplus.enums.FieldFill; import com.tamguo.modules.sys.model.enums.SysAreaStatusEnum; import lombok.Data; - /** - * The persistent class for the sys_area database table. - * + * SysAreaEntity 类,用于表示系统区域实体 */ @Data -@TableName(value="sys_area") +@TableName(value = "sys_area") public class SysAreaEntity implements Serializable { private static final long serialVersionUID = 1L; - + + // 根区域编码 public static final String ROOT_AREA_CODE = "0"; + // 区域编码分隔符 public static final String TREE_CODE_AREA_SEPARATE = ","; + // 区域名称分隔符 public static final String TREE_NAME_AREA_SEPARATE = "/"; + // 区域编码 @TableId private String areaCode; + // 区域名称 private String areaName; + // 区域类型 private String areaType; + // 创建人 @TableField(fill = FieldFill.INSERT_UPDATE) private String createBy; + // 创建时间 @TableField(fill = FieldFill.INSERT_UPDATE) private Date createDate; + // 父区域编码 private String parentCode; + // 父区域编码列表 private String parentCodes; + // 备注 private String remarks; - - @JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString) + + // 区域状态枚举 + @JSONField(serialzeFeatures = SerializerFeature.WriteEnumUsingToString) private SysAreaStatusEnum status; - + + // 是否为叶子节点 private Boolean treeLeaf; + // 树层次 private BigDecimal treeLevel; + // 树名称 private String treeNames; + // 树排序 private BigDecimal treeSort; + // 树排序字符串 private String treeSorts; + // 更新人 @TableField(fill = FieldFill.INSERT_UPDATE) private String updateBy; + // 更新时间 @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateDate; - - @TableField(exist=false) + + // 子区域列表 + @TableField(exist = false) private List children; + // 获取区域编码 public String getId() { return areaCode; } diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysCompanyEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysCompanyEntity.java index 43b654b..1d946e6 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysCompanyEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysCompanyEntity.java @@ -11,44 +11,72 @@ import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.enums.FieldFill; import lombok.Data; +/** + * SysCompanyEntity 类,用于表示系统公司实体 + */ @Data -@TableName(value="sys_company") +@TableName(value = "sys_company") @KeySequence public class SysCompanyEntity implements Serializable { private static final long serialVersionUID = 1L; - + + // 根公司编码 public static final String ROOT_COMPANY_CODE = "0"; + // 公司编码分隔符 public static final String TREE_CODE_COMPANY_SEPARATE = ","; + // 公司名称分隔符 public static final String TREE_NAME_COMPANY_SEPARATE = "/"; + // 公司编码 @TableId private String companyCode; + // 区域编码 private String areaCode; + // 公司名称 private String companyName; + // 企业编码 private String corpCode; + // 企业名称 private String corpName; + // 创建人 @TableField(fill = FieldFill.INSERT_UPDATE) private String createBy; + // 创建时间 @TableField(fill = FieldFill.INSERT_UPDATE) private Date createDate; + // 公司全称 private String fullName; + // 父公司编码 private String parentCode; + // 父公司编码列表 private String parentCodes; + // 备注 private String remarks; + // 公司状态 private String status; + // 是否为叶子节点 private Boolean treeLeaf; + // 树层次 private BigDecimal treeLevel; + // 树名称 private String treeNames; + // 树排序 private String treeSort; + // 树排序字符串 private String treeSorts; + // 更新人 @TableField(fill = FieldFill.INSERT) private String updateBy; + // 更新时间 @TableField(fill = FieldFill.INSERT) private Date updateDate; + // 视图编码 private String viewCode; - @TableField(exist=false) + // 树区域名称 + @TableField(exist = false) private String treeAreaNames; + // 获取公司编码 public String getId() { return companyCode; } diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysMenuEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysMenuEntity.java index 7a32013..a6ab485 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysMenuEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysMenuEntity.java @@ -13,48 +13,79 @@ import com.baomidou.mybatisplus.enums.FieldFill; import com.tamguo.modules.sys.model.enums.SysMenuStatusEnum; import lombok.Data; +/** + * SysMenuEntity 类,用于表示系统菜单实体 + */ @Data -@TableName(value="sys_menu") +@TableName(value = "sys_menu") public class SysMenuEntity implements Serializable { private static final long serialVersionUID = 1L; - + + // 根菜单编码 public static final String ROOT_MENU_CODE = "0"; + // 菜单编码分隔符 public static final String TREE_CODE_MENU_SEPARATE = ","; + // 菜单名称分隔符 public static final String TREE_NAME_MENU_SEPARATE = "/"; + // 菜单编码 @TableId private String menuCode; + // 创建人 @TableField(fill = FieldFill.INSERT_UPDATE) private String createBy; + // 创建时间 @TableField(fill = FieldFill.INSERT_UPDATE) private Date createDate; + // 是否显示 private String isShow; + // 菜单颜色 private String menuColor; + // 菜单链接 private String menuHref; + // 菜单图标 private String menuIcon; + // 菜单名称 private String menuName; + // 菜单目标 private String menuTarget; + // 菜单类型 private String menuType; + // 父菜单编码 private String parentCode; + // 父菜单编码列表 private String parentCodes; + // 权限 private String permission; + // 备注 private String remarks; - - @JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString) + + // 菜单状态枚举 + @JSONField(serialzeFeatures = SerializerFeature.WriteEnumUsingToString) private SysMenuStatusEnum status; + // 系统编码 private String sysCode; + // 是否为叶子节点 private Boolean treeLeaf; + // 树层次 private BigDecimal treeLevel; + // 树名称 private String treeNames; + // 树排序 private BigDecimal treeSort; + // 树排序字符串 private String treeSorts; + // 更新人 @TableField(fill = FieldFill.INSERT_UPDATE) private String updateBy; + // 更新时间 @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateDate; + // 权重 private BigDecimal weight; - public String getId() { - return menuCode; - } + // 获取菜单编码 + public String getId() { + return menuCode; + } } \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysOfficeEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysOfficeEntity.java index 4efd0f6..1f60586 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysOfficeEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysOfficeEntity.java @@ -10,53 +10,79 @@ import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.enums.FieldFill; import lombok.Data; - /** - * The persistent class for the sys_office database table. - * + * SysOfficeEntity 类,用于表示系统部门实体 */ @Data -@TableName(value="sys_office") +@TableName(value = "sys_office") public class SysOfficeEntity implements Serializable { private static final long serialVersionUID = 1L; + // 根部门编码 public static final String ROOT_OFFICE_CODE = "0"; + // 部门编码分隔符 public static final String TREE_CODE_OFFICE_SEPARATE = ","; + // 部门名称分隔符 public static final String TREE_NAME_OFFICE_SEPARATE = "/"; - + + // 部门编码 @TableId private String officeCode; + // 地址 private String address; + // 企业编码 private String corpCode; + // 企业名称 private String corpName; + // 创建人 @TableField(fill = FieldFill.INSERT_UPDATE) private String createBy; + // 创建时间 @TableField(fill = FieldFill.INSERT_UPDATE) private Date createDate; + // 邮箱 private String email; + // 部门全称 private String fullName; + // 负责人 private String leader; + // 部门名称 private String officeName; + // 部门类型 private String officeType; + // 父部门编码 private String parentCode; + // 父部门编码列表 private String parentCodes; + // 电话 private String phone; + // 备注 private String remarks; + // 部门状态 private String status; + // 是否为叶子节点 private Boolean treeLeaf; + // 树层次 private BigDecimal treeLevel; + // 树名称 private String treeNames; + // 树排序 private BigDecimal treeSort; + // 树排序字符串 private String treeSorts; + // 更新人 @TableField(fill = FieldFill.INSERT_UPDATE) private String updateBy; + // 更新时间 @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateDate; + // 视图编码 private String viewCode; + // 邮政编码 private String zipCode; // grid tree + // 获取部门编码 public String getId() { return this.getOfficeCode(); } - } \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysPostEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysPostEntity.java index 64a25de..a656bac 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysPostEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysPostEntity.java @@ -14,34 +14,52 @@ import com.baomidou.mybatisplus.enums.FieldFill; import com.tamguo.modules.sys.model.enums.SysPostStatusEnum; import lombok.Data; +/** + * SysPostEntity 类,用于表示系统岗位实体 + */ @Data -@TableName(value="sys_post") +@TableName(value = "sys_post") public class SysPostEntity extends Model implements Serializable { private static final long serialVersionUID = 1L; + // 岗位编码 @TableId private String postCode; + // 企业编码 private String corpCode; + // 企业名称 private String corpName; + // 创建人 @TableField(fill = FieldFill.INSERT_UPDATE) private String createBy; + // 创建时间 @TableField(fill = FieldFill.INSERT_UPDATE) private Date createDate; + // 岗位名称 private String postName; + // 岗位排序 private BigDecimal postSort; + // 岗位类型 private String postType; + // 备注 private String remarks; - - @JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString) + + // 岗位状态枚举 + @JSONField(serialzeFeatures = SerializerFeature.WriteEnumUsingToString) private SysPostStatusEnum status; + // 更新人 @TableField(fill = FieldFill.INSERT_UPDATE) private String updateBy; + // 更新时间 @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateDate; + /** + * 重写 pkVal 方法,返回岗位编码作为主键值 + * @return 岗位编码 + */ @Override protected Serializable pkVal() { return getPostCode(); } - } \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysUserEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysUserEntity.java index 2f7a4e4..47a74ef 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysUserEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/SysUserEntity.java @@ -17,87 +17,139 @@ import com.tamguo.modules.sys.model.enums.SysUserStatusEnum; import com.tamguo.modules.sys.model.enums.SysUserTypeEnum; import lombok.Data; +/** + * SysUserEntity 类,用于表示系统用户实体 + */ @Data -@TableName(value="sys_user") +@TableName(value = "sys_user") public class SysUserEntity extends Model implements Serializable { private static final long serialVersionUID = 1L; + // 用户编码 @TableId private String userCode; + // 部门编码 private String officeCode; + // 部门名称 private String officeName; + // 公司编码 private String companyCode; + // 公司名称 private String companyName; + // 头像 private String avatar; + // 企业编码 private String corpCode; + // 企业名称 private String corpName; + // 创建人 @TableField(fill = FieldFill.INSERT_UPDATE) private String createBy; + // 创建时间 @TableField(fill = FieldFill.INSERT_UPDATE) private Date createDate; + // 邮箱 private String email; + // 冻结原因 private String freezeCause; + // 冻结日期 private Date freezeDate; + // 最后登录日期 private Date lastLoginDate; + // 最后登录 IP private String lastLoginIp; + // 登录账号 private String loginCode; - - @JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString) + + // 用户管理类型枚举 + @JSONField(serialzeFeatures = SerializerFeature.WriteEnumUsingToString) private SysUserMgrTypeEnum mgrType; + // 手机号 private String mobile; + // 手机 IMEI 码 private String mobileImei; + // 密码 private String password; + // 电话 private String phone; + // 密码问题更新日期 private Date pwdQuestUpdateDate; + // 密码问题 private String pwdQuestion; - @TableField(value="pwd_question_2") + // 第二个密码问题 + @TableField(value = "pwd_question_2") private String pwdQuestion2; - @TableField(value="pwd_question_3") + // 第三个密码问题 + @TableField(value = "pwd_question_3") private String pwdQuestion3; + // 密码问题答案 private String pwdQuestionAnswer; - @TableField(value="pwd_question_answer_2") + // 第二个密码问题答案 + @TableField(value = "pwd_question_answer_2") private String pwdQuestionAnswer2; - @TableField(value="pwd_question_answer_3") + // 第三个密码问题答案 + @TableField(value = "pwd_question_answer_3") private String pwdQuestionAnswer3; + // 密码安全级别 private BigDecimal pwdSecurityLevel; + // 密码更新日期 private Date pwdUpdateDate; + // 密码更新记录 private String pwdUpdateRecord; + // 推荐码 private String refCode; + // 推荐人名称 private String refName; + // 备注 private String remarks; + // 性别 private String sex; + // 个性签名 private String sign; - - @JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString) + + // 用户状态枚举 + @JSONField(serialzeFeatures = SerializerFeature.WriteEnumUsingToString) private SysUserStatusEnum status; - + + // 更新人 @TableField(fill = FieldFill.INSERT_UPDATE) private String updateBy; + // 更新时间 @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateDate; + // 用户名 private String userName; + // 员工姓名 private String empName; - - @JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString) + + // 用户类型枚举 + @JSONField(serialzeFeatures = SerializerFeature.WriteEnumUsingToString) private SysUserTypeEnum userType; - + + // 用户权重 private BigDecimal userWeight; + // 微信 OpenID private String wxOpenid; + // 英文名 private String userNameEn; - - @TableField(exist=false) + + // 员工岗位列表(不存在数据库字段) + @TableField(exist = false) private List employeePosts; - @TableField(exist=false) + // 用户角色字符串(不存在数据库字段) + @TableField(exist = false) private String userRoleString; - @TableField(exist=false) + // 用户数据范围列表 JSON 字符串(不存在数据库字段) + @TableField(exist = false) private String userDataScopeListJson; - + /** + * 重写 pkVal 方法,返回用户编码作为主键值 + * @return 用户编码 + */ @Override protected Serializable pkVal() { return getUserCode(); } - - } \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/condition/SysUserCondition.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/condition/SysUserCondition.java index a87e171..b49005c 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/condition/SysUserCondition.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/sys/model/condition/SysUserCondition.java @@ -1,128 +1,316 @@ package com.tamguo.modules.sys.model.condition; +/** + * SysUserCondition 类,用于系统用户查询条件 + */ public class SysUserCondition { + // 当前页码 private Integer pageNo; + // 每页显示数量 private Integer pageSize; - + + // 登录账号 private String loginCode; + // 用户名 private String userName; + // 邮箱 private String email; + // 手机号 private String mobile; + // 电话号码 private String phone; + // 推荐人名称 private String refName; + // 部门名称 private String officeName; + // 部门编码 private String officeCode; + // 公司编码 private String companyCode; + // 公司名称 private String companyName; + // 岗位编码 private String postCode; + // 用户状态 private String status; + // 用户类型 private String userType; + // 管理类型 private String mgrType; - + + // 排序字段 private String orderBy; - + + /** + * 获取当前页码 + * @return 当前页码 + */ public Integer getPageNo() { return pageNo; } + + /** + * 设置当前页码 + * @param pageNo 当前页码 + */ public void setPageNo(Integer pageNo) { this.pageNo = pageNo; } + + /** + * 获取每页显示数量 + * @return 每页显示数量 + */ public Integer getPageSize() { return pageSize; } + + /** + * 设置每页显示数量 + * @param pageSize 每页显示数量 + */ public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } + + /** + * 获取登录账号 + * @return 登录账号 + */ public String getLoginCode() { return loginCode; } + + /** + * 设置登录账号 + * @param loginCode 登录账号 + */ public void setLoginCode(String loginCode) { this.loginCode = loginCode; } + + /** + * 获取用户名 + * @return 用户名 + */ public String getUserName() { return userName; } + + /** + * 设置用户名 + * @param userName 用户名 + */ public void setUserName(String userName) { this.userName = userName; } + + /** + * 获取邮箱 + * @return 邮箱 + */ public String getEmail() { return email; } + + /** + * 设置邮箱 + * @param email 邮箱 + */ public void setEmail(String email) { this.email = email; } + + /** + * 获取手机号 + * @return 手机号 + */ public String getMobile() { return mobile; } + + /** + * 设置手机号 + * @param mobile 手机号 + */ public void setMobile(String mobile) { this.mobile = mobile; } + + /** + * 获取电话号码 + * @return 电话号码 + */ public String getPhone() { return phone; } + + /** + * 设置电话号码 + * @param phone 电话号码 + */ public void setPhone(String phone) { this.phone = phone; } + + /** + * 获取推荐人名称 + * @return 推荐人名称 + */ public String getRefName() { return refName; } + + /** + * 设置推荐人名称 + * @param refName 推荐人名称 + */ public void setRefName(String refName) { this.refName = refName; } + + /** + * 获取部门名称 + * @return 部门名称 + */ public String getOfficeName() { return officeName; } + + /** + * 设置部门名称 + * @param officeName 部门名称 + */ public void setOfficeName(String officeName) { this.officeName = officeName; } + + /** + * 获取部门编码 + * @return 部门编码 + */ public String getOfficeCode() { return officeCode; } + + /** + * 设置部门编码 + * @param officeCode 部门编码 + */ public void setOfficeCode(String officeCode) { this.officeCode = officeCode; } + + /** + * 获取公司编码 + * @return 公司编码 + */ public String getCompanyCode() { return companyCode; } + + /** + * 设置公司编码 + * @param companyCode 公司编码 + */ public void setCompanyCode(String companyCode) { this.companyCode = companyCode; } + + /** + * 获取公司名称 + * @return 公司名称 + */ public String getCompanyName() { return companyName; } + + /** + * 设置公司名称 + * @param companyName 公司名称 + */ public void setCompanyName(String companyName) { this.companyName = companyName; } + + /** + * 获取岗位编码 + * @return 岗位编码 + */ public String getPostCode() { return postCode; } + + /** + * 设置岗位编码 + * @param postCode 岗位编码 + */ public void setPostCode(String postCode) { this.postCode = postCode; } + + /** + * 获取用户状态 + * @return 用户状态 + */ public String getStatus() { return status; } + + /** + * 设置用户状态 + * @param status 用户状态 + */ public void setStatus(String status) { this.status = status; } + + /** + * 获取用户类型 + * @return 用户类型 + */ public String getUserType() { return userType; } + + /** + * 设置用户类型 + * @param userType 用户类型 + */ public void setUserType(String userType) { this.userType = userType; } + + /** + * 获取排序字段 + * @return 排序字段 + */ public String getOrderBy() { return orderBy; } + + /** + * 设置排序字段 + * @param orderBy 排序字段 + */ public void setOrderBy(String orderBy) { this.orderBy = orderBy; } + + /** + * 获取管理类型 + * @return 管理类型 + */ public String getMgrType() { return mgrType; } + + /** + * 设置管理类型 + * @param mgrType 管理类型 + */ public void setMgrType(String mgrType) { this.mgrType = mgrType; } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/ChapterEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/ChapterEntity.java index 168e7c7..bc12a53 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/ChapterEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/ChapterEntity.java @@ -2,45 +2,40 @@ package com.tamguo.modules.tiku.model; import java.io.Serializable; -import com.alibaba.fastjson.annotation.JSONField; -import com.alibaba.fastjson.serializer.SerializerFeature; -import com.baomidou.mybatisplus.annotations.TableField; -import com.baomidou.mybatisplus.annotations.TableName; -import com.tamguo.config.dao.SuperEntity; -import com.tamguo.modules.tiku.model.enums.ChapterStatusEnum; -import lombok.Data; - -import java.util.List; - +import com.alibaba.fastjson.annotation.JSONField; // 用于 JSON 序列化时的注解 +import com.alibaba.fastjson.serializer.SerializerFeature; // JSON 序列化特性 +import com.baomidou.mybatisplus.annotations.TableField; // 与数据库表字段相关的注解 +import com.baomidou.mybatisplus.annotations.TableName; // 表名注解 +import com.tamguo.config.dao.SuperEntity; // 父类实体 +import com.tamguo.modules.tiku.model.enums.ChapterStatusEnum; // 章节状态枚举 +import lombok.Data; // Lombok 的数据注解 /** - * The persistent class for the t_chapter database table. - * + * t_chapter 数据库表的持久化类 */ -@TableName(value="t_chapter") -@Data -public class ChapterEntity extends SuperEntity implements Serializable { - private static final long serialVersionUID = 1L; +@TableName(value = "t_chapter") // 指定表名为 t_chapter +@Data // Lombok 的数据注解,自动生成 getter 和 setter 等方法 +public class ChapterEntity extends SuperEntity implements Serializable { // 继承父类实体,实现序列化接口 + private static final long serialVersionUID = 1L; // 序列化版本号 + + private String courseId; // 课程 ID + private String bookId; // 书籍 ID + private String name; // 章节名称 + private String parentCode; // 父章节代码 + private String parentCodes; // 父章节代码列表 + private Integer questionNum; // 问题数量 + private Integer pointNum; // 知识点数量 + private Integer orders; // 排序序号 + private Boolean treeLeaf; // 是否为叶子节点 + private Integer treeLevel; // 树的层级 + + private String seoTitle; // SEO 标题 + private String seoKeywords; // SEO 关键字 + private String seoDescription; // SEO 描述 - private String courseId; - private String bookId; - private String name; - private String parentCode; - private String parentCodes; - private Integer questionNum; - private Integer pointNum; - private Integer orders; - private Boolean treeLeaf; - private Integer treeLevel; - - private String seoTitle; - private String seoKeywords; - private String seoDescription; - - @TableField(exist=false) - private List childChapterList; - - @JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString) - private ChapterStatusEnum status; + @TableField(exist = false) // 表示该字段在数据库中不存在 + private List childChapterList; // 子章节列表 + @JSONField(serialzeFeatures = SerializerFeature.WriteEnumUsingToString) // 指定 JSON 序列化枚举时的特性 + private ChapterStatusEnum status; // 章节状态枚举 } \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/CourseEntity.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/CourseEntity.java index 4f289cb..6d13f65 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/CourseEntity.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/CourseEntity.java @@ -1,43 +1,42 @@ package com.tamguo.modules.tiku.model; -import java.util.Date; -import com.alibaba.fastjson.annotation.JSONField; -import com.alibaba.fastjson.serializer.SerializerFeature; -import com.baomidou.mybatisplus.annotations.TableField; -import com.baomidou.mybatisplus.annotations.TableId; -import com.baomidou.mybatisplus.annotations.TableName; -import com.baomidou.mybatisplus.enums.FieldFill; -import com.tamguo.modules.tiku.model.enums.CourseStatusEnum; -import lombok.Data; +import java.util.Date; // 日期类 -@Data -@TableName(value="t_course") +import com.alibaba.fastjson.annotation.JSONField; // 用于 JSON 序列化时的注解 +import com.alibaba.fastjson.serializer.SerializerFeature; // JSON 序列化特性 +import com.baomidou.mybatisplus.annotations.TableField; // 与数据库表字段相关的注解 +import com.baomidou.mybatisplus.annotations.TableId; // 表主键注解 +import com.baomidou.mybatisplus.annotations.TableName; // 表名注解 +import com.baomidou.mybatisplus.enums.FieldFill; // 字段填充策略枚举 +import com.tamguo.modules.tiku.model.enums.CourseStatusEnum; // 课程状态枚举 +import lombok.Data; // Lombok 的数据注解 + +@Data // Lombok 的数据注解,自动生成 getter 和 setter 等方法 +@TableName(value = "t_course") // 指定表名为 t_course public class CourseEntity { - - @TableId - private String id; - private String subjectId; - private String name; - private Integer sort; - private Integer questionNum; - private Integer pointNum; - private String remarks; - private String icon; - - private String seoTitle; - private String seoKeywords; - private String seoDescription; - - @TableField(fill = FieldFill.INSERT_UPDATE) - private String createBy; - @TableField(fill = FieldFill.INSERT_UPDATE) - private String updateBy; - @TableField(fill = FieldFill.INSERT_UPDATE) - private Date createDate; - @TableField(fill = FieldFill.INSERT_UPDATE) - private Date updateDate; - - @JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString) - private CourseStatusEnum status; + @TableId // 标识为主键 + private String id; // 课程 ID + private String subjectId; // 科目 ID + private String name; // 课程名称 + private Integer sort; // 排序号 + private Integer questionNum; // 问题数量 + private Integer pointNum; // 知识点数量 + private String remarks; // 备注 + private String icon; // 图标 + + private String seoTitle; // SEO 标题 + private String seoKeywords; // SEO 关键字 + private String seoDescription; // SEO 描述 + + @TableField(fill = FieldFill.INSERT_UPDATE) // 字段填充策略,在插入和更新时填充 + private String createBy; // 创建人 + @TableField(fill = FieldFill.INSERT_UPDATE) // 字段填充策略,在插入和更新时填充 + private String updateBy; // 更新人 + @TableField(fill = FieldFill.INSERT_UPDATE) // 字段填充策略,在插入和更新时填充 + private Date createDate; // 创建日期 + @TableField(fill = FieldFill.INSERT_UPDATE) // 字段填充策略,在插入和更新时填充 + private Date updateDate; // 更新日期 -} + @JSONField(serialzeFeatures = SerializerFeature.WriteEnumUsingToString) // 指定 JSON 序列化枚举时的特性 + private CourseStatusEnum status; // 课程状态枚举 +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/BookCondition.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/BookCondition.java index 30e15ed..d715585 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/BookCondition.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/BookCondition.java @@ -1,50 +1,117 @@ package com.tamguo.modules.tiku.model.condition; +/** + * BookCondition 类,用于书籍查询条件 + */ public class BookCondition { + // 当前页码 private Integer pageNo; + // 每页显示数量 private Integer pageSize; - + + // 书籍 ID private String id; + // 出版社 private String publishingHouse; + // 书名 private String name; + // 课程 ID private String courseId; - + + /** + * 获取当前页码 + * @return 当前页码 + */ public Integer getPageNo() { return pageNo; } + + /** + * 设置当前页码 + * @param pageNo 当前页码 + */ public void setPageNo(Integer pageNo) { this.pageNo = pageNo; } + + /** + * 获取每页显示数量 + * @return 每页显示数量 + */ public Integer getPageSize() { return pageSize; } + + /** + * 设置每页显示数量 + * @param pageSize 每页显示数量 + */ public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } + + /** + * 获取课程 ID + * @return 课程 ID + */ public String getCourseId() { return courseId; } + + /** + * 设置课程 ID + * @param courseId 课程 ID + */ public void setCourseId(String courseId) { this.courseId = courseId; } + + /** + * 获取出版社 + * @return 出版社 + */ public String getPublishingHouse() { return publishingHouse; } + + /** + * 设置出版社 + * @param publishingHouse 出版社 + */ public void setPublishingHouse(String publishingHouse) { this.publishingHouse = publishingHouse; } + + /** + * 获取书名 + * @return 书名 + */ public String getName() { return name; } + + /** + * 设置书名 + * @param name 书名 + */ public void setName(String name) { this.name = name; } + + /** + * 获取书籍 ID + * @return 书籍 ID + */ public String getId() { return id; } + + /** + * 设置书籍 ID + * @param id 书籍 ID + */ public void setId(String id) { this.id = id; } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/ChapterCondition.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/ChapterCondition.java index 254b794..365663a 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/ChapterCondition.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/ChapterCondition.java @@ -1,42 +1,98 @@ package com.tamguo.modules.tiku.model.condition; +/** + * ChapterCondition 类,用于章节查询条件 + */ public class ChapterCondition { - + + // 父章节编码 private String parentCode; + // 章节 ID private String id; + // 章节名称 private String name; + // 所属书籍 ID private String bookId; + // 所属书籍名称 private String bookName; - + + /** + * 获取父章节编码 + * @return 父章节编码 + */ public String getParentCode() { return parentCode; } + + /** + * 设置父章节编码 + * @param parentCode 父章节编码 + */ public void setParentCode(String parentCode) { this.parentCode = parentCode; } + + /** + * 获取章节 ID + * @return 章节 ID + */ public String getId() { return id; } + + /** + * 设置章节 ID + * @param id 章节 ID + */ public void setId(String id) { this.id = id; } + + /** + * 获取章节名称 + * @return 章节名称 + */ public String getName() { return name; } + + /** + * 设置章节名称 + * @param name 章节名称 + */ public void setName(String name) { this.name = name; } + + /** + * 获取所属书籍 ID + * @return 所属书籍 ID + */ public String getBookId() { return bookId; } + + /** + * 设置所属书籍 ID + * @param bookId 所属书籍 ID + */ public void setBookId(String bookId) { this.bookId = bookId; } + + /** + * 获取所属书籍名称 + * @return 所属书籍名称 + */ public String getBookName() { return bookName; } + + /** + * 设置所属书籍名称 + * @param bookName 所属书籍名称 + */ public void setBookName(String bookName) { this.bookName = bookName; } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/CourseCondition.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/CourseCondition.java index bc2ec27..75a3173 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/CourseCondition.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/CourseCondition.java @@ -1,50 +1,117 @@ package com.tamguo.modules.tiku.model.condition; +/** + * CourseCondition 类,用于课程条件的封装 + */ public class CourseCondition { + // 当前页码 private Integer pageNo; + // 每页显示数量 private Integer pageSize; - + + // 课程 ID private String id; + // 课程名称 private String name; + // 课程状态 private String status; + // 学科 ID private String subjectId; - + + /** + * 获取当前页码 + * @return 当前页码 + */ public Integer getPageNo() { return pageNo; } + + /** + * 设置当前页码 + * @param pageNo 当前页码 + */ public void setPageNo(Integer pageNo) { this.pageNo = pageNo; } + + /** + * 获取每页显示数量 + * @return 每页显示数量 + */ public Integer getPageSize() { return pageSize; } + + /** + * 设置每页显示数量 + * @param pageSize 每页显示数量 + */ public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } + + /** + * 获取课程名称 + * @return 课程名称 + */ public String getName() { return name; } + + /** + * 设置课程名称 + * @param name 课程名称 + */ public void setName(String name) { this.name = name; } + + /** + * 获取课程状态 + * @return 课程状态 + */ public String getStatus() { return status; } + + /** + * 设置课程状态 + * @param status 课程状态 + */ public void setStatus(String status) { this.status = status; } + + /** + * 获取学科 ID + * @return 学科 ID + */ public String getSubjectId() { return subjectId; } + + /** + * 设置学科 ID + * @param subjectId 学科 ID + */ public void setSubjectId(String subjectId) { this.subjectId = subjectId; } + + /** + * 获取课程 ID + * @return 课程 ID + */ public String getId() { return id; } + + /** + * 设置课程 ID + * @param id 课程 ID + */ public void setId(String id) { this.id = id; } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/SubjectCondition.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/SubjectCondition.java index 41c9a0f..7125601 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/SubjectCondition.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/condition/SubjectCondition.java @@ -1,43 +1,99 @@ package com.tamguo.modules.tiku.model.condition; +/** + * SubjectCondition 类,用于学科条件的封装 + */ public class SubjectCondition { - + + // 当前页码 private Integer pageNo; + // 每页显示数量 private Integer pageSize; - + + // 用户 ID private String uid; + // 学科名称 private String name; + // 学科状态 private String status; - + + /** + * 获取每页显示数量 + * @return 每页显示数量 + */ public Integer getPageSize() { return pageSize; } + + /** + * 设置每页显示数量 + * @param pageSize 每页显示数量 + */ public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } + + /** + * 获取当前页码 + * @return 当前页码 + */ public Integer getPageNo() { return pageNo; } + + /** + * 设置当前页码 + * @param pageNo 当前页码 + */ public void setPageNo(Integer pageNo) { this.pageNo = pageNo; } + + /** + * 获取用户 ID + * @return 用户 ID + */ public String getUid() { return uid; } + + /** + * 设置用户 ID + * @param uid 用户 ID + */ public void setUid(String uid) { this.uid = uid; } + + /** + * 获取学科名称 + * @return 学科名称 + */ public String getName() { return name; } + + /** + * 设置学科名称 + * @param name 学科名称 + */ public void setName(String name) { this.name = name; } + + /** + * 获取学科状态 + * @return 学科状态 + */ public String getStatus() { return status; } + + /** + * 设置学科状态 + * @param status 学科状态 + */ public void setStatus(String status) { this.status = status; } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/enums/QuestionTypeEnum.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/enums/QuestionTypeEnum.java index d37264a..fec2a8e 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/enums/QuestionTypeEnum.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/model/enums/QuestionTypeEnum.java @@ -1,54 +1,103 @@ package com.tamguo.modules.tiku.model.enums; -import java.io.Serializable; /** - * 试题类型、、题目类型(1.单选题;2.多选题; 3.解答题) - * - * @author tamguo + * 试题类型枚举 + * 题目类型:(1. 单选题;2. 多选题;3. 填空题;4. 判断题;5. 问答题) * + * @author tamguo */ public enum QuestionTypeEnum { - + + /** + * 单选题 + * @param value 值 + * @param desc 描述 + */ DANXUANTI("1", "单选题"), + + /** + * 多选题 + * @param value 值 + * @param desc 描述 + */ DUOXUANTI("2", "多选题"), + + /** + * 填空题 + * @param value 值 + * @param desc 描述 + */ TIANKONGTI("3", "填空题"), + + /** + * 判断题 + * @param value 值 + * @param desc 描述 + */ PANDUANTI("4", "判断题"), + + /** + * 问答题 + * @param value 值 + * @param desc 描述 + */ WENDATI("5", "问答题"); - private String value; - private String desc; - - QuestionTypeEnum(final String value, final String desc) { - this.value = value; - this.desc = desc; - } - - public static QuestionTypeEnum getQuestionType(String value) { - if("1".equals(value)) { - return DANXUANTI; - }else if("2".equals(value)) { - return DUOXUANTI; - }else if("3".equals(value)) { - return TIANKONGTI; - }else if("4".equals(value)) { - return PANDUANTI; - }else if("5".equals(value)) { - return WENDATI; - } - return WENDATI; - } - - public Serializable getValue() { - return this.value; - } - - public String getDesc(){ - return this.desc; - } - - @Override - public String toString() { - return this.value; - } - -} + private String value; // 枚举值 + private String desc; // 描述 + + /** + * 构造函数,初始化枚举值和描述 + * @param value 值 + * @param desc 描述 + */ + QuestionTypeEnum(final String value, final String desc) { + this.value = value; + this.desc = desc; + } + + /** + * 根据传入的 value 获取对应的枚举类型 + * @param value 要查询的 value 值 + * @return 对应的枚举类型,如果未找到则返回 WENDATI + */ + public static QuestionTypeEnum getQuestionType(String value) { + if ("1".equals(value)) { + return DANXUANTI; + } else if ("2".equals(value)) { + return DUOXUANTI; + } else if ("3".equals(value)) { + return TIANKONGTI; + } else if ("4".equals(value)) { + return PANDUANTI; + } else if ("5".equals(value)) { + return WENDATI; + } + return WENDATI; + } + + /** + * 获取枚举值 + * @return 枚举值 + */ + public Serializable getValue() { + return this.value; + } + + /** + * 获取描述 + * @return 描述 + */ + public String getDesc() { + return this.desc; + } + + /** + * 将枚举值转换为字符串 + * @return 枚举值的字符串表示 + */ + @Override + public String toString() { + return this.value; + } +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/ChapterServiceImpl.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/ChapterServiceImpl.java index 0661670..abbe076 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/ChapterServiceImpl.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/ChapterServiceImpl.java @@ -1,79 +1,93 @@ package com.tamguo.modules.tiku.service.impl; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.mapper.Condition; -import com.baomidou.mybatisplus.plugins.Page; -import com.baomidou.mybatisplus.service.impl.ServiceImpl; -import com.tamguo.common.utils.SystemConstant; -import com.tamguo.modules.tiku.dao.KnowPointMapper; -import com.tamguo.modules.tiku.dao.ChapterMapper; -import com.tamguo.modules.tiku.dao.CourseMapper; -import com.tamguo.modules.tiku.model.KnowPointEntity; -import com.tamguo.modules.tiku.model.ChapterEntity; -import com.tamguo.modules.tiku.model.condition.ChapterCondition; -import com.tamguo.modules.tiku.model.enums.ChapterStatusEnum; -import com.tamguo.modules.tiku.service.IChapterService; - -@Service -public class ChapterServiceImpl extends ServiceImpl implements IChapterService{ - - @Autowired - ChapterMapper chapterMapper; - @Autowired - CourseMapper courseMapper; - @Autowired - KnowPointMapper bookMapper; - - @Transactional(readOnly=false) - @SuppressWarnings("unchecked") +import java.util.ArrayList; // 导入 ArrayList 类,用于存储章节列表 +import java.util.List; // 导入 List 接口,用于存储章节实体列表 + +import org.apache.commons.lang3.StringUtils; // 导入StringUtils 类,用于字符串操作 +import org.springframework.beans.factory.annotation.Autowired; // 导入 Autowired 注解,用于依赖注入 +import org.springframework.stereotype.Service; // 导入 Service 注解,标识为服务层实现类 +import org.springframework.transaction.annotation.Transactional; // 导入 Transactional 注解,用于事务管理 + +import com.alibaba.fastjson.JSONArray; // 导入 JSONArray 类,用于处理 JSON 数组 +import com.alibaba.fastjson.JSONObject; // 导入 JSONObject 类,用于处理 JSON 对象 +import com.baomidou.mybatisplus.mapper.Condition; // 导入 Condition 类,用于构建查询条件 +import com.baomidou.mybatisplus.plugins.Page; // 导入 Page 类,用于分页查询 +import com.baomidou.mybatisplus.service.impl.ServiceImpl; // 导入 ServiceImpl 类,作为服务层实现类的父类 +import com.tamguo.common.utils.SystemConstant; // 导入 SystemConstant 类,用于定义系统常量 +import com.tamguo.modules.tiku.dao.KnowPointMapper; // 导入 KnowPointMapper 接口,用于知识关键点的数据访问 +import com.tamguo.modules.tiku.dao.ChapterMapper; // 导入 ChapterMapper 接口,用于章节的数据访问 +import com.tamguo.modules.tiku.dao.CourseMapper; // 导入 CourseMapper 接口,用于课程的数据访问 +import com.tamguo.modules.tiku.model.KnowPointEntity; // 导入 KnowPointEntity 类,代表知识关键点实体 +import com.tamguo.modules.tiku.model.ChapterEntity; // 导入 ChapterEntity 类,代表章节实体 +import com.tamguo.modules.tiku.model.condition.ChapterCondition; // 导入 ChapterCondition 类,代表章节查询条件 +import com.tamguo.modules.tiku.model.enums.ChapterStatusEnum; // 导入 ChapterStatusEnum 枚举,代表章节状态 +import com.tamguo.modules.tiku.service.IChapterService; // 导入 IChapterService 接口,定义章节服务的接口 + +@Service // 标识为服务层实现类 +public class ChapterServiceImpl extends ServiceImpl implements IChapterService { + + @Autowired // 自动注入 ChapterMapper 实例 + private ChapterMapper chapterMapper; + + @Autowired // 自动注入 CourseMapper 实例 + private CourseMapper courseMapper; + + @Autowired // 自动注入 KnowPointMapper 实例 + private KnowPointMapper bookMapper; + + /** + * 查找章节树结构 + * + * @param bookId 书籍 ID + * @return 章节树结构的根节点列表 + */ + @Transactional(readOnly = false) // 开启事务,设置只读为 false + @SuppressWarnings("unchecked") // 抑制unchecked 警告 @Override public List findChapterTree(String bookId) { + // 根据书籍 ID 查询章节列表 List chapterList = baseMapper.selectList(Condition.create().eq("book_id", bookId)); - - // 获取根chapter UID + + // 获取根章节 UID String rootUid = StringUtils.EMPTY; - for(int i=0 ; i entitys = new ArrayList<>(); - for(int i=0 ; i childs = new ArrayList<>(); - for(int k=0 ; k childs = entitys.get(i).getChildChapterList(); - for(int k=0 ; k tmpChilds = new ArrayList<>(); - for(int n=0 ; n listData(ChapterCondition condition) { - Condition query = Condition.create(); - if(!StringUtils.isEmpty(condition.getParentCode())) { - query.eq("parent_code", condition.getParentCode()); - }else { - query.eq("tree_level", "0"); + Condition query = Condition.create(); // 创建查询条件对象 + if (!StringUtils.isEmpty(condition.getParentCode())) { + query.eq("parent_code", condition.getParentCode()); // 添加父章节代码条件 + } else { + query.eq("tree_level", "0"); // 添加树级别为 0 的条件(即根章节) } - if(!StringUtils.isEmpty(condition.getId())) { - query.eq("id", condition.getId()); + if (!StringUtils.isEmpty(condition.getId())) { + query.eq("id", condition.getId()); // 添加章节 ID 条件 } - if(!StringUtils.isEmpty(condition.getName())) { - query.like("name", condition.getName()); + if (!StringUtils.isEmpty(condition.getName())) { + query.like("name", condition.getName()); // 添加章节名称模糊匹配条件 } - if(!StringUtils.isEmpty(condition.getBookId())) { - query.andNew().eq("course_id", condition.getBookId()).or().eq("book_id", condition.getBookId()).or().eq("subject_id", condition.getBookId());; + if (!StringUtils.isEmpty(condition.getBookId())) { + query.andNew().eq("course_id", condition.getBookId()).or().eq("book_id", condition.getBookId()).or().eq("subject_id", condition.getBookId()); // 添加课程 ID、书籍 ID 或科目 ID 条件 } - return chapterMapper.selectList(query); + return chapterMapper.selectList(query); // 执行查询并返回结果 } - @SuppressWarnings("unchecked") - @Override - public JSONArray treeData(String courseId, String excludeId) { - List chapterList = null; - if(StringUtils.isEmpty(excludeId)) { - chapterList = chapterMapper.selectList(Condition.EMPTY); - } else { - chapterList = chapterMapper.selectList(Condition.create().notLike("parent_codes", excludeId).eq("id", excludeId)); - } - return turnZTreeData(chapterList); - } - + /** + * 将章节数据转换为 ZTree 格式的 JSON 数组 + * + * @param chapterList 章节实体列表 + * @return ZTree 格式的 JSON 数组 + */ private JSONArray turnZTreeData(List chapterList) { - if(chapterList != null) { - JSONArray nodes = new JSONArray(); - for(int i=0 ; i chapterList = chapterMapper.selectList(Condition.create().like("parent_codes", entity.getId())); - for(int i=0 ; i childs = chapterMapper.selectList(Condition.create().like("parent_codes", id)); - for(int i=0 ; i findCourseChapter(String courseId) { + // 根据课程 ID 查询知识关键点列表 List bookList = bookMapper.selectList(Condition.create().eq("course_id", courseId)); - if(bookList.size() == 0) { - return null; + if (bookList.size() == 0) { + return null; // 如果没有找到知识关键点,则返回 null } - Condition condition = Condition.create(); - condition.eq("tree_level", 1); - condition.eq("book_id", bookList.get(0).getId()); + + Condition condition = Condition.create(); // 创建查询条件对象 + condition.eq("tree_level", 1); // 设置树级别为 1 + condition.eq("book_id", bookList.get(0).getId()); // 设置书籍 ID + + // 根据条件查询章节列表 List list = chapterMapper.selectPage(new Page<>(1, 5), condition); - return list; + return list; // 返回章节列表 } - @Transactional(readOnly=true) + /** + * 根据父章节代码和当前章节 ID 查询下一个章节 + * + * @param parentCode 父章节代码 + * @param id 当前章节 ID + * @return 下一个章节实体 + */ + @Transactional(readOnly = true) // 开启事务,设置只读为 true @Override - public ChapterEntity selectNextChapter(String parentCode , String id) { - return chapterMapper.selectNextChapter(parentCode , id); + public ChapterEntity selectNextChapter(String parentCode, String id) { + return chapterMapper.selectNextChapter(parentCode, id); // 查询下一个章节 } -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/CourseServiceImpl.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/CourseServiceImpl.java index 840baed..9177181 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/CourseServiceImpl.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/CourseServiceImpl.java @@ -1,125 +1,185 @@ package com.tamguo.modules.tiku.service.impl; -import java.util.Arrays; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.mapper.Condition; -import com.baomidou.mybatisplus.plugins.Page; -import com.baomidou.mybatisplus.service.impl.ServiceImpl; -import com.tamguo.modules.tiku.dao.CourseMapper; -import com.tamguo.modules.tiku.dao.SubjectMapper; -import com.tamguo.modules.tiku.model.CourseEntity; -import com.tamguo.modules.tiku.model.SubjectEntity; -import com.tamguo.modules.tiku.model.condition.CourseCondition; -import com.tamguo.modules.tiku.model.enums.CourseStatusEnum; -import com.tamguo.modules.tiku.model.enums.SubjectStatusEnum; -import com.tamguo.modules.tiku.service.ICourseService; - -@Service -public class CourseServiceImpl extends ServiceImpl implements ICourseService{ - - @Autowired - public CourseMapper courseMapper; - @Autowired - public SubjectMapper subjectMapper; - - @SuppressWarnings("unchecked") - @Transactional(readOnly=true) +import java.util.Arrays; // 导入 Arrays 类,用于操作数组 +import java.util.List; // 导入 List 接口,用于存储科目和课程实体列表 + +import org.springframework.beans.factory.annotation.Autowired; // 导入 Autowired 注解,用于依赖注入 +import org.springframework.stereotype.Service; // 导入 Service 注解,标识为服务层实现类 +import org.springframework.transaction.annotation.Transactional; // 导入 Transactional 注解,用于事务管理 +import org.springframework.util.StringUtils; // 导入 StringUtils 类,用于字符串操作 + +import com.alibaba.fastjson.JSONArray; // 导入 JSONArray 类,用于处理 JSON 数组 +import com.alibaba.fastjson.JSONObject; // 导入 JSONObject 类,用于处理 JSON 对象 +import com.baomidou.mybatisplus.mapper.Condition; // 导入 Condition 类,用于构建查询条件 +import com.baomidou.mybatisplus.plugins.Page; // 导入 Page 类,用于分页查询 +import com.baomidou.mybatisplus.service.impl.ServiceImpl; // 导入 ServiceImpl 类,作为服务层实现类的父类 +import com.tamguo.modules.tiku.dao.CourseMapper; // 导入 CourseMapper 接口,用于课程的数据访问 +import com.tamguo.modules.tiku.dao.SubjectMapper; // 导入 SubjectMapper 接口,用于科目的数据访问 +import com.tamguo.modules.tiku.model.CourseEntity; // 导入 CourseEntity 类,代表课程实体 +import com.tamguo.modules.tiku.model.SubjectEntity; // 导入 SubjectEntity 类,代表科目实体 +import com.tamguo.modules.tiku.model.condition.CourseCondition; // 导入 CourseCondition 类,代表课程查询条件 +import com.tamguo.modules.tiku.model.enums.CourseStatusEnum; // 导入 CourseStatusEnum 枚举,代表课程状态 +import com.tamguo.modules.tiku.model.enums.SubjectStatusEnum; // 导入 SubjectStatusEnum 枚举,代表科目状态 +import com.tamguo.modules.tiku.service.ICourseService; // 导入 ICourseService 接口,定义课程服务的接口 + +@Service // 标识为服务层实现类 +public class CourseServiceImpl extends ServiceImpl implements ICourseService { + + @Autowired // 自动注入 CourseMapper 实例 + private CourseMapper courseMapper; + + @Autowired // 自动注入 SubjectMapper 实例 + private SubjectMapper subjectMapper; + + /** + * 根据条件查询课程数据 + * + * @param condition 课程查询条件 + * @return 包含课程数据的分页对象 + */ + @SuppressWarnings("unchecked") // 抑制unchecked 警告 + @Transactional(readOnly = true) // 开启事务,设置只读为 true @Override public Page listData(CourseCondition condition) { - Page page = new Page<>(condition.getPageNo() , condition.getPageSize()); - Condition query = Condition.create(); - if(!StringUtils.isEmpty(condition.getId())) { - query.eq("id", condition.getId()); + Page page = new Page<>(condition.getPageNo(), condition.getPageSize()); // 创建分页对象 + + Condition query = Condition.create(); // 创建查询条件对象 + if (!StringUtils.isEmpty(condition.getId())) { + query.eq("id", condition.getId()); // 添加课程 ID 条件 } - if(!StringUtils.isEmpty(condition.getName())) { - query.like("name", condition.getName()); + if (!StringUtils.isEmpty(condition.getName())) { + query.like("name", condition.getName()); // 添加课程名称模糊匹配条件 } - if(!StringUtils.isEmpty(condition.getSubjectId())) { - query.eq("subject_id", condition.getSubjectId()); + if (!StringUtils.isEmpty(condition.getSubjectId())) { + query.eq("subject_id", condition.getSubjectId()); // 添加科目 ID 条件 } - if(!StringUtils.isEmpty(condition.getStatus())) { - query.eq("status", condition.getStatus()); + if (!StringUtils.isEmpty(condition.getStatus())) { + query.eq("status", condition.getStatus()); // 添加课程状态条件 } - query.orderAsc(Arrays.asList("sort")); - return page.setRecords(courseMapper.selectPage(page , query)); + query.orderAsc(Arrays.asList("sort")); // 根据排序字段升序排序 + + return page.setRecords(courseMapper.selectPage(page, query)); // 执行查询并设置分页结果 } - @Transactional(readOnly=false) + /** + * 保存课程信息 + * + * @param course 课程实体 + */ + @Transactional(readOnly = false) // 开启事务,设置只读为 false @Override public void save(CourseEntity course) { - course.setStatus(CourseStatusEnum.NORMAL); - courseMapper.insert(course); + course.setStatus(CourseStatusEnum.NORMAL); // 设置课程状态为正常 + courseMapper.insert(course); // 插入课程记录 } - @Transactional(readOnly=false) + /** + * 更新课程信息 + * + * @param course 课程实体 + */ + @Transactional(readOnly = false) // 开启事务,设置只读为 false @Override public void update(CourseEntity course) { - CourseEntity entity = courseMapper.selectById(course.getId()); - entity.setName(course.getName()); - entity.setSubjectId(course.getSubjectId()); - entity.setSort(course.getSort()); - entity.setRemarks(course.getRemarks()); - courseMapper.updateById(entity); + CourseEntity entity = courseMapper.selectById(course.getId()); // 获取要更新的课程实体 + + entity.setName(course.getName()); // 更新课程名称 + entity.setSubjectId(course.getSubjectId()); // 更新科目 ID + entity.setSort(course.getSort()); // 更新排序号 + entity.setRemarks(course.getRemarks()); // 更新备注 + + courseMapper.updateById(entity); // 更新课程记录 } - @Transactional(readOnly=false) + /** + * 删除课程信息 + * + * @param uid 课程 ID + */ + @Transactional(readOnly = false) // 开启事务,设置只读为 false @Override public void delete(String uid) { - CourseEntity entity = courseMapper.selectById(uid); - entity.setStatus(CourseStatusEnum.DELETE); - courseMapper.updateById(entity); + CourseEntity entity = courseMapper.selectById(uid); // 获取要删除的课程实体 + + entity.setStatus(CourseStatusEnum.DELETE); // 设置课程状态为已删除 + courseMapper.updateById(entity); // 更新课程记录 } - @Transactional(readOnly=false) + /** + * 启用课程 + * + * @param uid 课程 ID + */ + @Transactional(readOnly = false) // 开启事务,设置只读为 false @Override public void enable(String uid) { - CourseEntity entity = courseMapper.selectById(uid); - entity.setStatus(CourseStatusEnum.NORMAL); - courseMapper.updateById(entity); + CourseEntity entity = courseMapper.selectById(uid); // 获取要启用的课程实体 + + entity.setStatus(CourseStatusEnum.NORMAL); // 设置课程状态为正常 + courseMapper.updateById(entity); // 更新课程记录 } - @Transactional(readOnly=false) + /** + * 禁用课程 + * + * @param uid 课程 ID + */ + @Transactional(readOnly = false) // 开启事务,设置只读为 false @Override public void disabled(String uid) { - CourseEntity entity = courseMapper.selectById(uid); - entity.setStatus(CourseStatusEnum.DISABLED); - courseMapper.updateById(entity); + CourseEntity entity = courseMapper.selectById(uid); // 获取要禁用的课程实体 + + entity.setStatus(CourseStatusEnum.DISABLED); // 设置课程状态为禁用 + courseMapper.updateById(entity); // 更新课程记录 } - - @SuppressWarnings("unchecked") + + /** + * 将科目和课程数据转换为 ZTree 格式的 JSON 数组 + * + * @return ZTree 格式的 JSON 数组 + */ + @SuppressWarnings("unchecked") // 抑制 unchecked 警告 + @Transactional(readOnly = false) // 开启事务,设置只读为 false @Override public JSONArray treeData() { - List subjectList = subjectMapper.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue())); - List courseList = courseMapper.selectList(Condition.create().eq("status", CourseStatusEnum.NORMAL.getValue())); - return transform(subjectList, courseList); + List subjectList = subjectMapper.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue())); // 查询正常状态的科目列表 + List courseList = courseMapper.selectList(Condition.create().eq("status", CourseStatusEnum.NORMAL.getValue())); // 查询正常状态的课程列表 + + return transform(subjectList, courseList); // 转换科目和课程数据为 JSON 数组 } - - private JSONArray transform(List subjectList , List courseList) { - JSONArray entitys = new JSONArray(); - for(int i=0 ; i subjectList, List courseList) { + JSONArray entitys = new JSONArray(); // 创建 JSON 数组对象 + + for (int i = 0; i < subjectList.size(); i++) { + JSONObject entity = new JSONObject(); // 创建 JSON 对象 + + SubjectEntity subject = subjectList.get(i); // 获取科目实体 + entity.put("id", subject.getId()); // 设置科目 ID + entity.put("name", subject.getName()); // 设置科目名称 + entity.put("pId", "0"); // 设置父节点 ID 为 0 + + entitys.add(entity); // 将科目对象添加到 JSON 数组中 } - return entitys; - } + for (int i = 0; i < courseList.size(); i++) { + JSONObject entity = new JSONObject(); // 创建 JSON 对象 + + CourseEntity course = courseList.get(i); // 获取课程实体 + entity.put("id", course.getId()); // 设置课程 ID + entity.put("name", course.getName()); // 设置课程名称 + entity.put("pId", course.getSubjectId()); // 设置父节点 ID 为课程所属科目 ID -} + entitys.add(entity); // 将课程对象添加到 JSON 数组中 + } + + return entitys; // 返回转换后的 JSON 数组 + } +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/KnowPointServiceImpl.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/KnowPointServiceImpl.java index e25f77f..97bb6eb 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/KnowPointServiceImpl.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/KnowPointServiceImpl.java @@ -1,129 +1,192 @@ package com.tamguo.modules.tiku.service.impl; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.mapper.Condition; -import com.baomidou.mybatisplus.plugins.Page; -import com.baomidou.mybatisplus.service.impl.ServiceImpl; -import com.tamguo.modules.tiku.dao.KnowPointMapper; -import com.tamguo.modules.tiku.dao.CourseMapper; -import com.tamguo.modules.tiku.dao.SubjectMapper; -import com.tamguo.modules.tiku.model.KnowPointEntity; -import com.tamguo.modules.tiku.model.CourseEntity; -import com.tamguo.modules.tiku.model.SubjectEntity; -import com.tamguo.modules.tiku.model.condition.BookCondition; -import com.tamguo.modules.tiku.model.enums.BookStatusEnum; -import com.tamguo.modules.tiku.model.enums.CourseStatusEnum; -import com.tamguo.modules.tiku.model.enums.SubjectStatusEnum; -import com.tamguo.modules.tiku.service.IKnowPointService; - -@Service -public class KnowPointServiceImpl extends ServiceImpl implements IKnowPointService{ - - @Autowired - KnowPointMapper knowPointMapper; - @Autowired - CourseMapper courseMapper; - @Autowired - SubjectMapper subjectMapper; - - @Transactional(readOnly=false) +import java.util.List; // 导入 List 接口,用于存储科目、课程和知识点实体列表 + +import org.springframework.beans.factory.annotation.Autowired; // 导入 Autowired 注解,用于依赖注入 +import org.springframework.stereotype.Service; // 导入 Service 注解,标识为服务层实现类 +import org.springframework.transaction.annotation.Transactional; // 导入 Transactional 注解,用于事务管理 + +import com.alibaba.fastjson.JSONArray; // 导入 JSONArray 类,用于处理 JSON 数组 +import com.alibaba.fastjson.JSONObject; // 导入 JSONObject 类,用于处理 JSON 对象 +import com.baomidou.mybatisplus.mapper.Condition; // 导入 Condition 类,用于构建查询条件 +import com.baomidou.mybatisplus.plugins.Page; // 导入 Page 类,用于分页查询 +import com.baomidou.mybatisplus.service.impl.ServiceImpl; // 导入 ServiceImpl 类,作为服务层实现类的父类 +import com.tamguo.modules.tiku.dao.KnowPointMapper; // 导入 KnowPointMapper 接口,用于知识点的数据访问 +import com.tamguo.modules.tiku.dao.CourseMapper; // 导入 CourseMapper 接口,用于课程的数据访问 +import com.tamguo.modules.tiku.dao.SubjectMapper; // 导入 SubjectMapper 接口,用于科目的数据访问 +import com.tamguo.modules.tiku.model.KnowPointEntity; // 导入 KnowPointEntity 类,代表知识点实体 +import com.tamguo.modules.tiku.model.CourseEntity; // 导入 CourseEntity 类,代表课程实体 +import com.tamguo.modules.tiku.model.SubjectEntity; // 导入 SubjectEntity 类,代表科目实体 +import com.tamguo.modules.tiku.model.condition.BookCondition; // 导入 BookCondition 类,代表知识点查询条件 +import com.tamguo.modules.tiku.model.enums.BookStatusEnum; // 导入 BookStatusEnum 枚举,代表知识点状态 +import com.tamguo.modules.tiku.model.enums.CourseStatusEnum; // 导入 CourseStatusEnum 枚举,代表课程状态 +import com.tamguo.modules.tiku.model.enums.SubjectStatusEnum; // 导入 SubjectStatusEnum 枚举,代表科目状态 +import com.tamguo.modules.tiku.service.IKnowPointService; // 导入 IKnowPointService 接口,定义知识点服务的接口 + +@Service // 标识为服务层实现类 +public class KnowPointServiceImpl extends ServiceImpl implements IKnowPointService { + + @Autowired // 自动注入 KnowPointMapper 实例 + private KnowPointMapper knowPointMapper; + + @Autowired // 自动注入 CourseMapper 实例 + private CourseMapper courseMapper; + + @Autowired // 自动注入 SubjectMapper 实例 + private SubjectMapper subjectMapper; + + /** + * 根据条件查询知识点数据 + * + * @param condition 知识点查询条件 + * @return 包含知识点数据的分页对象 + */ + @Transactional(readOnly = false) // 开启事务,设置只读为 false @Override public Page listData(BookCondition condition) { - Page page = new Page<>(condition.getPageNo() , condition.getPageSize()); - return page.setRecords(knowPointMapper.listData(page, condition)); + Page page = new Page<>(condition.getPageNo(), condition.getPageSize()); // 创建分页对象 + return page.setRecords(knowPointMapper.listData(page, condition)); // 执行查询并设置分页结果 } - @Transactional(readOnly=false) + /** + * 保存知识点信息 + * + * @param book 知识点实体 + */ + @Transactional(readOnly = false) // 开启事务,设置只读为 false @Override public void save(KnowPointEntity book) { - CourseEntity course = courseMapper.selectById(book.getCourseId()); - - book.setStatus(BookStatusEnum.NORMAL); - book.setSubjectId(course.getSubjectId()); - knowPointMapper.insert(book); + CourseEntity course = courseMapper.selectById(book.getCourseId()); // 获取课程实体 + + book.setStatus(BookStatusEnum.NORMAL); // 设置知识点状态为正常 + book.setSubjectId(course.getSubjectId()); // 设置知识点所属科目 ID + knowPointMapper.insert(book); // 插入知识点记录 } - @Transactional(readOnly=false) + /** + * 更新知识点信息 + * + * @param book 知识点实体 + */ + @Transactional(readOnly = false) // 开启事务,设置只读为 false @Override public void update(KnowPointEntity book) { - CourseEntity course = courseMapper.selectById(book.getCourseId()); - KnowPointEntity entity = knowPointMapper.selectById(book.getId()); - - entity.setName(book.getName()); - entity.setPointNum(book.getPointNum()); - entity.setQuestionNum(book.getQuestionNum()); - entity.setRemarks(book.getRemarks()); - entity.setPublishingHouse(book.getPublishingHouse()); - entity.setSort(book.getSort()); - entity.setCourseId(course.getId()); - - knowPointMapper.updateById(entity); + CourseEntity course = courseMapper.selectById(book.getCourseId()); // 获取课程实体 + KnowPointEntity entity = knowPointMapper.selectById(book.getId()); // 获取要更新的知识点实体 + + entity.setName(book.getName()); // 更新知识点名称 + entity.setPointNum(book.getPointNum()); // 更新知识点数量 + entity.setQuestionNum(book.getQuestionNum()); // 更新问题数量 + entity.setRemarks(book.getRemarks()); // 更新备注 + entity.setPublishingHouse(book.getPublishingHouse()); // 更新出版社 + entity.setSort(book.getSort()); // 更新排序号 + entity.setCourseId(course.getId()); // 更新课程 ID + + knowPointMapper.updateById(entity); // 更新知识点记录 } - @Transactional(readOnly=false) + /** + * 删除知识点信息 + * + * @param id 知识点 ID + */ + @Transactional(readOnly = false) // 开启事务,设置只读为 false @Override public void delete(String id) { - KnowPointEntity book = knowPointMapper.selectById(id); - book.setStatus(BookStatusEnum.DELETE); - knowPointMapper.updateById(book); + KnowPointEntity book = knowPointMapper.selectById(id); // 获取要删除的知识点实体 + + book.setStatus(BookStatusEnum.DELETE); // 设置知识点状态为已删除 + knowPointMapper.updateById(book); // 更新知识点记录 } - @Transactional(readOnly=false) + /** + * 启用知识点 + * + * @param id 知识点 ID + */ + @Transactional(readOnly = false) // 开启事务,设置只读为 false @Override public void enable(String id) { - KnowPointEntity book = knowPointMapper.selectById(id); - book.setStatus(BookStatusEnum.NORMAL); - knowPointMapper.updateById(book); + KnowPointEntity book = knowPointMapper.selectById(id); // 获取要启用的知识点实体 + + book.setStatus(BookStatusEnum.NORMAL); // 设置知识点状态为正常 + knowPointMapper.updateById(book); // 更新知识点记录 } - @Transactional(readOnly=false) + /** + * 禁用知识点 + * + * @param id 知识点 ID + */ + @Transactional(readOnly = false) // 开启事务,设置只读为 false @Override public void disabled(String id) { - KnowPointEntity book = knowPointMapper.selectById(id); - book.setStatus(BookStatusEnum.DISABLED); - knowPointMapper.updateById(book); + KnowPointEntity book = knowPointMapper.selectById(id); // 获取要禁用的知识点实体 + + book.setStatus(BookStatusEnum.DISABLED); // 设置知识点状态为禁用 + knowPointMapper.updateById(book); // 更新知识点记录 } - @Transactional(readOnly=false) - @SuppressWarnings("unchecked") + /** + * 将科目、课程和知识点数据转换为 ZTree 格式的 JSON 数组 + * + * @return ZTree 格式的 JSON 数组 + */ + @Transactional(readOnly = false) // 开启事务,设置只读为 false + @SuppressWarnings("unchecked") // 抑制 unchecked 警告 @Override public JSONArray treeData() { - List subjectList = subjectMapper.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue())); - List courseList = courseMapper.selectList(Condition.create().eq("status", CourseStatusEnum.NORMAL.getValue())); - List bookList = knowPointMapper.selectList(Condition.create().eq("status", BookStatusEnum.NORMAL.getValue())); - return transform(subjectList, courseList , bookList); + List subjectList = subjectMapper.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue())); // 查询正常状态的科目列表 + List courseList = courseMapper.selectList(Condition.create().eq("status", CourseStatusEnum.NORMAL.getValue())); // 查询正常状态的课程列表 + List bookList = knowPointMapper.selectList(Condition.create().eq("status", BookStatusEnum.NORMAL.getValue())); // 查询正常状态的知识点列表 + + return transform(subjectList, courseList, bookList); // 转换科目、课程和知识点数据为 JSON 数组 } - private JSONArray transform(List subjectList , List courseList , List bookList) { - JSONArray entitys = new JSONArray(); - for(int i=0 ; i subjectList, List courseList, List bookList) { + JSONArray entitys = new JSONArray(); // 创建 JSON 数组对象 + + for (int i = 0; i < subjectList.size(); i++) { + JSONObject entity = new JSONObject(); // 创建 JSON 对象 + + SubjectEntity subject = subjectList.get(i); // 获取科目实体 + entity.put("id", subject.getId()); // 设置科目 ID + entity.put("name", subject.getName()); // 设置科目名称 + entity.put("pId", "0"); // 设置父节点 ID 为 0 + + entitys.add(entity); // 将科目对象添加到 JSON 数组中 } - for(int i=0 ; i implements IMenuService{ - +public class MenuServiceImpl extends ServiceImpl implements IMenuService { + + /** + * 自动注入的 MenuMapper + */ @Autowired private MenuMapper menuMapper; + + /** + * 自动注入的缓存服务 + */ @Autowired private CacheService cacheService; + /** + * 获取菜单列表 + * @return 菜单列表 + */ @SuppressWarnings("unchecked") @Override public List findMenus() { List menuList = ((List) cacheService.getObject(SystemConstant.INDEX_MENU)); if (menuList == null) { menuList = menuMapper.selectList(Condition.create().eq("parent_id", 1).eq("is_show", 1).orderDesc(Arrays.asList("orders"))); - for(MenuEntity menu : menuList){ + for (MenuEntity menu : menuList) { List childSubjects = menuMapper.selectList(Condition.create().eq("parent_id", menu.getId()).orderDesc(Arrays.asList("orders"))); menu.setChildSubjects(childSubjects); } - cacheService.setObject(SystemConstant.INDEX_MENU, menuList , 2 * 60 * 60); + cacheService.setObject(SystemConstant.INDEX_MENU, menuList, 2 * 60 * 60); } return menuList; } + /** + * 获取所有菜单列表 + * @return 所有菜单列表 + */ @SuppressWarnings("unchecked") @Override public List findAllMenus() { List allMenuList = ((List) cacheService.getObject(SystemConstant.ALL_INDEX_MENU)); - if(allMenuList == null){ + if (allMenuList == null) { allMenuList = menuMapper.selectList(Condition.create().eq("parent_id", 1).orderDesc(Arrays.asList("orders"))); - for(MenuEntity menu : allMenuList){ + for (MenuEntity menu : allMenuList) { List childSubjects = menuMapper.selectList(Condition.create().eq("parent_id", menu.getId()).orderDesc(Arrays.asList("orders"))); menu.setChildSubjects(childSubjects); } - cacheService.setObject(SystemConstant.ALL_INDEX_MENU, allMenuList , 2 * 60 * 60); + cacheService.setObject(SystemConstant.ALL_INDEX_MENU, allMenuList, 2 * 60 * 60); } return allMenuList; } + /** + * 获取左侧菜单列表 + * @return 左侧菜单列表 + */ @SuppressWarnings("unchecked") @Override public List findLeftMenus() { List leftMenuList = ((List) cacheService.getObject(SystemConstant.LEFT_INDEX_MENU)); - if(leftMenuList == null){ + if (leftMenuList == null) { leftMenuList = menuMapper.selectList(Condition.create().eq("parent_id", 2).orderDesc(Arrays.asList("orders"))); - for(MenuEntity menu : leftMenuList){ + for (MenuEntity menu : leftMenuList) { List childSubjects = menuMapper.selectList(Condition.create().eq("parent_id", menu.getId()).orderDesc(Arrays.asList("orders"))); menu.setChildSubjects(childSubjects); } - cacheService.setObject(SystemConstant.LEFT_INDEX_MENU, leftMenuList , 2 * 60 * 60); + cacheService.setObject(SystemConstant.LEFT_INDEX_MENU, leftMenuList, 2 * 60 * 60); } return leftMenuList; } - + /** + * 获取章节菜单列表 + * @return 章节菜单列表 + */ @SuppressWarnings("unchecked") @Override public List findChapterMenus() { List chapterMenuList = ((List) cacheService.getObject(SystemConstant.CHAPTER_INDEX_MENU)); - if(chapterMenuList == null){ + if (chapterMenuList == null) { chapterMenuList = menuMapper.selectList(Condition.create().eq("parent_id", 4).orderAsc(Arrays.asList("orders"))); - for(MenuEntity menu : chapterMenuList){ + for (MenuEntity menu : chapterMenuList) { List childSubjects = menuMapper.selectList(Condition.create().eq("parent_id", menu.getId()).orderDesc(Arrays.asList("orders"))); menu.setChildSubjects(childSubjects); } - cacheService.setObject(SystemConstant.CHAPTER_INDEX_MENU, chapterMenuList , 2 * 60 * 60); + cacheService.setObject(SystemConstant.CHAPTER_INDEX_MENU, chapterMenuList, 2 * 60 * 60); } return chapterMenuList; } - + /** + * 获取页脚菜单列表 + * @return 页脚菜单列表 + */ @SuppressWarnings("unchecked") @Override public List findFooterMenus() { List footerMenuList = ((List) cacheService.getObject(SystemConstant.FOOTER_INDEX_MENU)); - if(footerMenuList == null){ + if (footerMenuList == null) { footerMenuList = menuMapper.selectList(Condition.create().eq("parent_id", 3).orderDesc(Arrays.asList("orders"))); - for(MenuEntity menu : footerMenuList){ + for (MenuEntity menu : footerMenuList) { List childSubjects = menuMapper.selectList(Condition.create().eq("parent_id", menu.getId()).orderDesc(Arrays.asList("orders"))); menu.setChildSubjects(childSubjects); } - cacheService.setObject(SystemConstant.FOOTER_INDEX_MENU, footerMenuList , 2 * 60 * 60); + cacheService.setObject(SystemConstant.FOOTER_INDEX_MENU, footerMenuList, 2 * 60 * 60); } return footerMenuList; } + /** + * 获取菜单树 + * @return 菜单树 + */ @SuppressWarnings("unchecked") @Override public List getMenuTree() { return menuMapper.selectList(Condition.EMPTY); } + /** + * 根据 ID 查找菜单实体 + * @param uid 菜单 ID + * @return 菜单实体 + */ @Override public MenuEntity findById(String uid) { return menuMapper.selectById(uid); } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/PaperServiceImpl.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/PaperServiceImpl.java index 22c2077..ee55487 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/PaperServiceImpl.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/PaperServiceImpl.java @@ -27,84 +27,134 @@ import com.tamguo.modules.tiku.service.ICourseService; import com.tamguo.modules.tiku.service.IPaperService; import com.tamguo.modules.tiku.service.ISubjectService; +/** + * PaperServiceImpl 类,实现 IPaperService 接口 + */ @Service -public class PaperServiceImpl extends ServiceImpl implements IPaperService{ - +public class PaperServiceImpl extends ServiceImpl implements IPaperService { + + /** + * 自动注入的 ISubjectService + */ @Autowired private ISubjectService iSubjectService; + + /** + * 自动注入的 ICourseService + */ @Autowired private ICourseService iCourseService; + + /** + * 自动注入的 ISysAreaService + */ @Autowired private ISysAreaService iSysAreaService; + + /** + * 自动注入的 PaperMapper + */ @Autowired private PaperMapper paperMapper; + + /** + * 自动注入的 CacheService + */ @Autowired private CacheService cacheService; + + /** + * 自动注入的 QuestionMapper + */ @Autowired private QuestionMapper questionMapper; + + /** + * 自动注入的 QuestionOptionsMapper + */ @Autowired private QuestionOptionsMapper questionOptionsMapper; - + + /** + * 获取历史试卷列表 + * @return 历史试卷列表 + */ @SuppressWarnings("unchecked") @Override public List findHistoryPaper() { List paperList = (List) cacheService.getObject(SystemConstant.HISTORY_PAPER); - if(paperList == null){ - Page page = new Page<>(1 , 6); + if (paperList == null) { + Page page = new Page<>(1, 6); paperList = paperMapper.selectPage(page, Condition.create().eq("type", SystemConstant.ZHENGTI_PAPER_ID).orderDesc(Arrays.asList("id"))); - for(int i=0 ; i findSimulationPaper() { List paperList = (List) cacheService.getObject(SystemConstant.SIMULATION_PAPER); - if(paperList == null){ - Page page = new Page<>(1 , 6); + if (paperList == null) { + Page page = new Page<>(1, 6); paperList = paperMapper.selectPage(page, Condition.create().eq("type", SystemConstant.MONI_PAPER_ID).orderDesc(Arrays.asList("id"))); - for(int i=0 ; i findHotPaper(String areaId) { List paperList = (List) cacheService.getObject(SystemConstant.HOT_PAPER); - if(paperList == null){ - Page page = new Page<>(1 , 10); + if (paperList == null) { + Page page = new Page<>(1, 10); paperList = paperMapper.selectPage(page, Condition.create().orderDesc(Arrays.asList("id"))); - for(int i=0 ; i impl entity.put("type", type); entity.put("id", UUID.randomUUID().toString()); qList.add(entity); - + paper.setQuestionInfo(qList.toString()); paperMapper.updateById(paper); } - @Transactional(readOnly=false) + /** + * 更新试卷问题信息 + * @param paperId 试卷 ID + * @param title 标题 + * @param name 名称 + * @param type 类型 + * @param uid 问题 ID + */ + @Transactional(readOnly = false) @Override public void updatePaperQuestionInfo(String paperId, String title, String name, String type, String uid) { PaperEntity paper = paperMapper.selectById(paperId); JSONArray qList = JSONArray.parseArray(paper.getQuestionInfo()); - for(int i =0 ; i impl return Result.result(Result.SUCCESS_CODE, null, "删除子卷成功"); } - @Transactional(readOnly=false) + /** + * 添加试卷 + * @param paper 试卷实体 + */ + @Transactional(readOnly = false) @Override public void addPaper(PaperEntity paper) { paper.setDownHits(0); paper.setOpenHits(0); paper.setQuestionInfo("[]"); - - // 写入seo信息 + + // 写入 seo 信息 paper.setSeoTitle(paper.getName()); paper.setSeoKeywords(paper.getName()); paper.setSeoDescription(paper.getName()); paperMapper.insert(paper); } + /** + * 更新试卷 + * @param paper 试卷实体 + * @param currMemberId 当前用户 ID + * @return 更新结果 + */ @Override - public Result updatePaper(PaperEntity paper ,String currMemberId) { + public Result updatePaper(PaperEntity paper, String CurrMemberId) { PaperEntity entity = paperMapper.selectById(paper.getId()); - if(!entity.getCreaterId().equals(currMemberId)) { + if (!entity.getCreaterId().equals(currMemberId)) { return Result.failResult("试卷属于当前用户,不能修改!"); } paper.setCreaterId(currMemberId); @@ -192,15 +273,19 @@ public class PaperServiceImpl extends ServiceImpl impl return Result.result(Result.SUCCESS_CODE, paper, "修改成功"); } + /** + * 获取试卷问题列表 + * @param paperId 试卷 ID + * @return 问题列表 + */ @Override public List findQuestionList(String paperId) { // 查询选项信息 List questionList = questionMapper.selectList(Condition.create().eq("paper_id", paperId)); questionList.forEach(question -> { - List questionOptions = questionOptionsMapper.selectList(Condition.create().eq("question_id" , question.getId())); + List questionOptions = questionOptionsMapper.selectList(Condition.create().eq("question_id", question.getId())); question.setQuestionOptions(questionOptions); }); return questionList; } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/QuestionServiceImpl.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/QuestionServiceImpl.java index f8713c5..a470578 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/QuestionServiceImpl.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/QuestionServiceImpl.java @@ -15,67 +15,136 @@ import com.tamguo.modules.tiku.model.PaperEntity; import com.tamguo.modules.tiku.model.QuestionEntity; import com.tamguo.modules.tiku.service.IQuestionService; +// 标识这是一个Spring的服务层组件类,用于实现IQuestionService接口中定义的与题目(Question)相关的业务逻辑方法, +// 它继承自ServicePlus框架提供的ServiceImpl类,借助其提供的通用数据库操作能力,结合自身的业务逻辑实现对题目数据的添加、查询、更新和删除等操作,并且通过依赖注入获取相关的Mapper对象来与数据库进行交互。 @Service -public class QuestionServiceImpl extends ServiceImpl implements IQuestionService{ - +public class QuestionServiceImpl extends ServiceImpl implements IQuestionService { + + // 自动注入PaperMapper,用于操作试卷(Paper)相关的数据,比如通过试卷ID查询试卷信息等操作,在题目相关业务逻辑中可能需要获取试卷的创建者等信息来进行权限判断等操作,依赖该Mapper与数据库的试卷表进行交互。 @Autowired private PaperMapper paperMapper; + + // 自动注入QuestionMapper,用于操作题目(Question)相关的数据,比如插入题目、根据条件查询题目、更新题目以及删除题目等数据库操作,是实现题目业务逻辑中与数据库进行交互的核心依赖对象,直接对应数据库中的题目表。 @Autowired private QuestionMapper questionMapper; + /** + * 添加题目业务逻辑方法 + * 该方法用于向数据库中添加一道新的题目信息,在添加之前会先根据传入题目所属试卷的ID去查询试卷信息,判断当前登录用户是否为该试卷的创建者, + * 如果不是则返回无权操作的提示信息;若是,则设置题目中的课程ID(从对应的试卷信息中获取),然后将题目信息插入到数据库中,并返回添加成功的提示信息。 + * + * @param question 要添加的题目实体对象,包含了题目相关的各种属性信息(如题目内容、所属试卷ID等),这些信息将被插入到数据库的题目表中,需要保证其属性值符合数据库表结构及业务要求。 + * @param currMemberId 当前登录会员的ID,用于判断当前用户是否有权限添加该题目,通过与试卷创建者的ID进行比对来确定权限,只有试卷创建者才有添加对应试卷下题目的权限,确保数据的安全性和权限控制。 + * @return 返回一个Result对象,该对象包含了操作的状态码、数据以及提示信息,用于告知调用者题目添加操作的结果,如果添加成功状态码为0,若无权操作则状态码为501,并携带相应的提示信息说明情况。 + */ @Override - public Result addQuestion(QuestionEntity question , String currMemberId) { + public Result addQuestion(QuestionEntity question, String currMemberId) { + // 根据题目实体对象中携带的试卷ID,通过PaperMapper从数据库中查询对应的试卷实体信息,用于后续判断当前用户对该试卷是否有操作权限(即是否为试卷创建者)。 PaperEntity paper = paperMapper.selectById(question.getPaperId().toString()); - if(!currMemberId.equals(paper.getCreaterId())) { + // 判断当前登录会员的ID与查询到的试卷创建者的ID是否相等,如果不相等,表示当前用户无权操作该试卷下的题目,返回包含相应错误提示信息和状态码(501)的Result对象给调用者。 + if (!currMemberId.equals(paper.getCreaterId())) { return Result.result(501, null, "改试卷不属于您!"); } + // 如果当前用户有权限添加题目,将从试卷实体对象中获取的课程ID设置到题目实体对象中,保证题目与试卷在课程维度上的关联关系正确,便于后续按课程等维度进行题目相关的查询、统计等业务操作。 question.setCourseId(paper.getCourseId()); + // 通过QuestionMapper将题目实体对象插入到数据库的题目表中,完成题目添加的数据库操作,若插入成功,则数据库中会新增一条对应的题目记录。 questionMapper.insert(question); + // 返回包含添加成功提示信息和状态码(0表示成功)的Result对象给调用者,告知题目添加操作已成功完成。 return Result.result(0, null, "添加成功!"); } + /** + * 查询题目列表业务逻辑方法 + * 根据传入的多个查询条件(如题目类型、题目ID、题目内容、所属试卷ID以及当前登录会员ID等)来查询符合条件的题目列表信息, + * 在查询之前会先根据试卷ID和当前登录会员ID判断用户是否有权限查询该试卷下的题目,如果无权则返回空的题目列表;若有权限,则根据其他条件构建查询条件对象, + * 通过MyBatis Plus的分页查询功能从数据库中获取相应的题目列表数据,并返回包含查询结果的分页对象。 + * + * @param questionType 题目类型,用于筛选特定类型的题目,若为空字符串则表示不按题目类型进行筛选,根据业务需求传入相应的题目类型值,与数据库题目表中的题目类型字段进行匹配查询。 + * @param id 题目ID,用于精确查找特定ID的题目,若为空则不按此ID进行筛选,方便根据已知的题目唯一标识来获取具体的题目信息,与数据库题目表中的题目ID字段进行匹配查询。 + * @param content 题目内容,用于模糊查询包含指定内容的题目,若为空则不按此内容进行筛选,可用于根据部分题目内容关键字来查找相关题目,通过数据库的模糊查询(LIKE操作符)与题目表中的题目内容字段进行匹配查询。 + * @param paperId 所属试卷ID,用于指定要查询题目所属的试卷,是判断权限以及确定查询范围的重要依据,通过该试卷ID结合当前登录会员ID来验证用户是否有权查询该试卷下的题目,同时也是构建查询条件与数据库题目表中所属试卷ID字段进行匹配查询的关键参数。 + * @param currMemberId 当前登录会员的ID,用于进行权限判断,通过与试卷创建者的ID对比来确定当前用户是否有权限查询该试卷下的题目,只有试卷创建者才能查询对应试卷下的题目信息,确保数据的访问权限控制。 + * @param p 分页对象,包含了分页相关的参数信息(如页码、每页记录数等),用于进行分页查询,在查询符合条件的题目列表时,会按照该分页对象的设置来获取相应分页的数据,方便在前端进行分页展示等操作。 + * @return 返回一个包含题目列表数据的Page分页对象,如果用户无权查询则返回的分页对象中记录列表为空(通过p.setRecords(null)设置),若有权查询则返回包含符合条件题目列表数据的分页对象,供前端进行分页展示等处理。 + */ @SuppressWarnings("unchecked") @Override - public Page queryQuestionList(String questionType, String id, String content, String paperId, String currMemberId , - Page p) { - if(!currMemberId.equals(paperMapper.selectById(paperId).getCreaterId())) { + public Page queryQuestionList(String questionType, String id, String content, String paperId, String currMemberId, + Page p) { + // 根据传入的试卷ID从数据库中查询对应的试卷实体信息,然后判断当前登录会员的ID与查询到的试卷创建者的ID是否相等,如果不相等,表示当前用户无权查询该试卷下的题目,直接返回传入的分页对象,并将其记录列表设置为空,表示无权获取题目数据。 + if (!currMemberId.equals(paperMapper.selectById(paperId).getCreaterId())) { return p.setRecords(null); } + // 创建一个MyBatis Plus的查询条件对象,用于构建后续查询题目时的各种条件,通过该对象可以方便地添加等于、大于、小于、模糊匹配等各种条件来精确筛选题目数据,符合MyBatis Plus的条件查询规范。 Condition condition = new Condition(); - if(!StringUtils.isEmpty(questionType)) { + // 判断题目类型是否不为空字符串,如果不为空,则添加一个等于(eq)条件到查询条件对象中,使得查询时只会获取指定题目类型的题目,与数据库题目表中的题目类型字段进行精确匹配查询。 + if (!StringUtils.isEmpty(questionType)) { condition.eq("question_type", questionType); } - if(!StringUtils.isEmpty(id)) { + // 判断题目ID是否不为空字符串,如果不为空,则添加一个等于(eq)条件到查询条件对象中,使得查询时只会获取指定ID的题目,与数据库题目表中的题目ID字段进行精确匹配查询,用于精确查找特定题目。 + if (!StringUtils.isEmpty(id)) { condition.eq("id", id); } - if(!StringUtils.isEmpty(content)) { + // 判断题目内容是否不为空字符串,如果不为空,则添加一个模糊匹配(like)条件到查询条件对象中,使得查询时会获取题目内容包含指定关键字的题目,通过数据库的模糊查询(LIKE操作符)与题目表中的题目内容字段进行匹配查询,用于根据部分内容查找相关题目。 + if (!StringUtils.isEmpty(content)) { condition.like("content", content); } + // 添加一个等于(eq)条件到查询条件对象中,指定要查询的题目所属的试卷ID,与数据库题目表中的所属试卷ID字段进行精确匹配查询,确保获取的题目都是属于指定试卷的。 condition.eq("paper_id", paperId); + // 通过QuestionMapper结合分页对象和构建好的查询条件对象进行分页查询,从数据库中获取符合条件的题目列表数据,并将查询结果设置到传入的分页对象的记录列表中,最后返回该分页对象,供前端进行分页展示等操作。 return p.setRecords(questionMapper.selectPage(p, condition)); } - @Transactional(readOnly=false) + /** + * 更新题目业务逻辑方法 + * 该方法用于更新数据库中已存在的题目信息,在更新之前会先根据传入题目所属试卷的ID去查询试卷信息,判断当前登录用户是否为该试卷的创建者, + * 如果不是则返回无权操作的提示信息;若是,则通过QuestionMapper根据题目ID更新相应的题目信息,并返回更新成功的提示信息。 + * 该方法使用了事务控制,确保在更新题目数据的过程中,如果出现异常情况,数据库操作能够回滚,保证数据的一致性和完整性。 + * + * @param question 要更新的题目实体对象,包含了更新后的题目相关属性信息(如更新后的题目内容、所属试卷ID等),这些信息将覆盖数据库中对应题目记录的原有属性值,需要保证其属性值符合数据库表结构及业务要求。 + * @param currMemberId 当前登录会员的ID,用于判断当前用户是否有权限更新该题目,通过与试卷创建者的ID进行比对来确定权限,只有试卷创建者才有更新对应试卷下题目的权限,确保数据的安全性和权限控制。 + * @return 返回一个Result对象,该对象包含了操作的状态码、数据以及提示信息,用于告知调用者题目更新操作的结果,如果更新成功状态码为0,若无权操作则状态码为501,并携带相应的提示信息说明情况。 + */ + @Transactional(readOnly = false) @Override - public Result updateQuestion(QuestionEntity question , String currMemberId) { + public Result updateQuestion(QuestionEntity question, String currMemberId) { + // 根据题目实体对象中携带的试卷ID,通过PaperMapper从数据库中查询对应的试卷实体信息,用于后续判断当前用户对该试卷是否有操作权限(即是否为试卷创建者)。 PaperEntity paper = paperMapper.selectById(question.getPaperId().toString()); - if(!currMemberId.equals(paper.getCreaterId())) { + // 判断当前登录会员的ID与查询到的试卷创建者的ID是否相等,如果不相等,表示当前用户无权操作该试卷下的题目,返回包含相应错误提示信息和状态码(501)的Result对象给调用者。 + if (!currMemberId.equals(paper.getCreaterId())) { return Result.result(501, null, "改试卷不属于您!"); } + // 如果当前用户有权限更新题目,通过QuestionMapper根据题目实体对象的ID更新数据库中对应的题目记录,将传入的题目实体对象中的属性值覆盖原有记录中的相应属性值,完成题目信息的更新操作。 questionMapper.updateById(question); + // 返回包含更新成功提示信息和状态码(0表示成功)的Result对象给调用者,告知题目更新操作已成功完成。 return Result.result(0, null, "修改成功!"); } - @Transactional(readOnly=false) + /** + * 删除题目业务逻辑方法 + * 该方法用于从数据库中删除指定ID的题目信息,在删除之前会先根据传入题目ID获取题目所属试卷的信息,判断当前登录用户是否为该试卷的创建者, + * 如果不是则返回无权操作的提示信息;若是,则通过QuestionMapper根据题目ID删除对应的题目记录,并返回删除成功的提示信息。 + * 该方法使用了事务控制,确保在删除题目数据的过程中,如果出现异常情况,数据库操作能够回滚,保证数据的一致性和完整性。 + * + * @param uid 要删除题目的唯一标识ID,用于准确指定要从数据库中删除的题目记录,通过该ID可以在数据库题目表中定位到对应的题目记录并进行删除操作,确保删除操作的准确性。 + * @param currMemberId 当前登录会员的ID,用于判断当前用户是否有权限删除该题目,通过与试卷创建者的ID进行比对来确定权限,只有试卷创建者才有删除对应试卷下题目的权限,确保数据的安全性和权限控制。 + * @return 返回一个Result对象,该对象包含了操作的状态码、数据以及提示信息,用于告知调用者题目删除操作的结果,如果删除成功状态码为0,若无权操作则状态码为501,并携带相应的提示信息说明情况。 + */ + @Transactional(readOnly = false) @Override - public Result delete(String uid , String currMemberId) { + public Result delete(String uid, String currMemberId) { + // 根据传入的题目ID,通过QuestionMapper从数据库中查询对应的题目实体信息,用于获取该题目所属试卷的ID,以便后续判断当前用户对该试卷是否有操作权限(即是否为试卷创建者)。 QuestionEntity question = questionMapper.selectById(uid); + // 根据题目所属试卷的ID,通过PaperMapper从数据库中查询对应的试卷实体信息,用于后续判断当前用户对该试卷是否有操作权限(即是否为试卷创建者)。 PaperEntity paper = paperMapper.selectById(question.getPaperId().toString()); - if(!currMemberId.equals(paper.getCreaterId())) { + // 判断当前登录会员的ID与查询到的试卷创建者的ID是否相等,如果不相等,表示当前用户无权操作该试卷下的题目,返回包含相应错误提示信息和状态码(501)的Result对象给调用者。 + if (!currMemberId.equals(paper.getCreaterId())) { return Result.result(501, null, "改试卷不属于您!"); } + // 如果当前用户有权限删除题目,通过QuestionMapper根据题目ID删除数据库中对应的题目记录,完成题目删除的数据库操作,从数据库表中移除该题目对应的行数据。 questionMapper.deleteById(uid); + // 返回包含删除成功提示信息和状态码(0表示成功)的Result对象给调用者,告知题目删除操作已成功完成。 return Result.result(0, null, "删除成功!"); } - -} + +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/SchoolService.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/SchoolService.java index 376212e..6498f5b 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/SchoolService.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/SchoolService.java @@ -19,51 +19,78 @@ import com.tamguo.modules.tiku.model.PaperEntity; import com.tamguo.modules.tiku.model.SchoolEntity; import com.tamguo.modules.tiku.service.ISchoolService; +/** + * SchoolServiceImpl 类,实现 ISchoolService 接口 + */ @Service -public class SchoolService extends ServiceImpl implements ISchoolService { +public class SchoolServiceImpl extends ServiceImpl implements ISchoolService { + /** + * 自动注入的 SchoolMapper + */ @Autowired private SchoolMapper schoolMapper; + + /** + * 自动注入的 PaperMapper + */ @Autowired private PaperMapper paperMapper; + + /** + * 自动注入的 CacheService + */ @Autowired private CacheService cacheService; + /** + * 获取精英学校试卷 + * @param shcoolId 学校 ID + * @return 精英学校试卷列表 + */ @SuppressWarnings("unchecked") @Override public List findEliteSchoolPaper(String shcoolId) { List schoolList = (List) cacheService.getObject(SystemConstant.ELITE_SCHOOL_PAPER); // 获取名校试卷 - if(schoolList == null){ - Page page = new Page<>(1 , 3); + if (schoolList == null) { + Page page = new Page<>(1, 3); schoolList = schoolMapper.selectPage(page, Condition.create().eq("id", shcoolId)); - for(SchoolEntity school : schoolList){ - Page p = new Page<>(1 , 3); + for (SchoolEntity school : schoolList) { + Page p = new Page<>(1, 3); List paperList = paperMapper.selectPage(p, Condition.create().eq("school_id", school.getId())); school.setPaperList(paperList); } - cacheService.setObject(SystemConstant.ELITE_SCHOOL_PAPER, schoolList , 2 * 60 * 60); + cacheService.setObject(SystemConstant.ELITE_SCHOOL_PAPER, schoolList, 2 * 60 * 60); } return schoolList; } + /** + * 获取精英学校 + * @return 精英学校列表 + */ @SuppressWarnings("unchecked") @Override public List findEliteSchool() { List schoolList = (List) cacheService.getObject(SystemConstant.ELITE_PAPER); - if(schoolList == null){ - RowBounds row = new RowBounds(1 , 6); + if (schoolList == null) { + RowBounds row = new RowBounds(1, 6); schoolList = schoolMapper.selectPage(row, Condition.EMPTY); - cacheService.setObject(SystemConstant.ELITE_PAPER, schoolList , 2 * 60 * 60); + cacheService.setObject(SystemConstant.ELITE_PAPER, schoolList, 2 * 60 * 60); } return schoolList; } - @Transactional(readOnly=true) + /** + * 根据地区 ID 查询学校 + * @param areaId 地区 ID + * @return 学校列表 + */ + @Transactional(readOnly = true) @SuppressWarnings("unchecked") @Override public List findSchoolByAreaId(String areaId) { return schoolMapper.selectList(Condition.create().in("area_id", Arrays.asList(areaId.split(",")))); } - -} +} \ No newline at end of file diff --git a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/SubjectServiceImpl.java b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/SubjectServiceImpl.java index df19e70..cedb415 100644 --- a/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/SubjectServiceImpl.java +++ b/tamguo-modules-core/src/main/java/com/tamguo/modules/tiku/service/impl/SubjectServiceImpl.java @@ -19,39 +19,62 @@ import com.tamguo.modules.tiku.model.condition.SubjectCondition; import com.tamguo.modules.tiku.model.enums.SubjectStatusEnum; import com.tamguo.modules.tiku.service.ISubjectService; +/** + * SubjectServiceImpl 类,实现 ISubjectService 接口 + */ @Service -public class SubjectServiceImpl extends ServiceImpl implements ISubjectService{ - +public class SubjectServiceImpl extends ServiceImpl implements ISubjectService { + + /** + * 自动注入的 SubjectMapper + */ @Autowired private SubjectMapper subjectMapper; + + /** + * 自动注入的 CourseMapper + */ @Autowired private CourseMapper courseMapper; - @Transactional(readOnly=false) + /** + * 列表数据 + * @param condition 条件 + * @return 页面对象 + */ + @Transactional(readOnly = false) @SuppressWarnings("unchecked") @Override public Page listData(SubjectCondition condition) { Page page = new Page<>(condition.getPageNo(), condition.getPageSize()); Condition query = Condition.create(); - if(!StringUtils.isEmpty(condition.getUid())) { + if (!StringUtils.isEmpty(condition.getUid())) { query.eq("uid", condition.getUid()); - }else if(!StringUtils.isEmpty(condition.getName())) { + } else if (!StringUtils.isEmpty(condition.getName())) { query.eq("name", condition.getName()); - }else if(!StringUtils.isEmpty(condition.getStatus())) { + } else if (!StringUtils.isEmpty(condition.getStatus())) { query.eq("status", condition.getStatus()); } query.ne("status", SubjectStatusEnum.DELETE.getValue()); return page.setRecords(subjectMapper.selectPage(page, query)); } - @Transactional(readOnly=false) + /** + * 保存 + * @param subject 实体 + */ + @Transactional(readOnly = false) @Override public void save(SubjectEntity subject) { subject.setStatus(SubjectStatusEnum.NORMAL); subjectMapper.insert(subject); } - @Transactional(readOnly=false) + /** + * 更新 + * @param subject 实体 + */ + @Transactional(readOnly = false) @Override public void update(SubjectEntity subject) { SubjectEntity entity = subjectMapper.selectById(subject.getId()); @@ -64,7 +87,11 @@ public class SubjectServiceImpl extends ServiceImpl subjectList = subjectMapper.selectList(Condition.EMPTY); - for(int i=0 ; i courseList = courseMapper.selectList(Condition.create().eq("subject_id", subject.getId())); - for(int k=0 ; k subjectList = subjectMapper.selectList(Condition.EMPTY); - for(int i=0 ; i