solved problem

后台运营yy
李宏杰 8 months ago
commit 8375311bc4

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="17 (2)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -2,7 +2,6 @@
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

@ -8,15 +8,28 @@ 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) {
}

@ -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<br>
* http://mp.baomidou.com<br>
* PaginationInterceptor
* @return PaginationInterceptor
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); // 创建分页拦截器实例
paginationInterceptor.setLocalPage(true); // 开启 PageHelper 的支持
/*
* SQL <br>
* 1 cookie SQL <br>
* SQL
*/
List<ISqlParser> sqlParserList = new ArrayList<>();
TenantSqlParser tenantSqlParser = new TenantSqlParser();
tenantSqlParser.setTenantHandler(new TenantHandler() {
List<ISqlParser> 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 注入器实例
}
}

@ -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<String> 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 对象
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);
throw new IncorrectCredentialsException("用户名或密码有误,请重新输入或找回密码");
}
// 更新登录时间
iMemberService.updateLastLoginTime(member.getId());
// 创建简单认证信息对象
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(member, password, getName());
return info;
}
}

@ -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<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
/**
* 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);

@ -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");
// 创建一个表示 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);
}
}

@ -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 {
/**
*
*/
@Resource
private Environment env;
/**
* Thymeleaf
* @param viewResolver ThymeleafViewResolver
*/
@Resource
private void configureThymeleafStaticVars(ThymeleafViewResolver viewResolver) {
if (viewResolver!= null) {
/**
* Map
*/
Map<String, Object> 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;
}
}

@ -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;
/**
* 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) {
// 添加资源处理器,处理/files/** 路径的资源,并设置资源位置为文件系统中的指定路径
registry.addResourceHandler("/files/**").addResourceLocations("file:" + fileStoragePath);
}
/**
* CookieSerializer
* @return CookieSerializer
*/
@Bean
public CookieSerializer defaultCookieSerializer() {
// 创建默认的 CookieSerializer 实例
DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer();
// 设置 Cookie 名称
defaultCookieSerializer.setCookieName("sessionId");
// 设置 Cookie 域名
defaultCookieSerializer.setDomainName(cookieDomianName);
// 设置 Cookie 路径
defaultCookieSerializer.setCookiePath("/");
return defaultCookieSerializer;
}
}

@ -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();
if (fileInputStream!= null) { // 如果文件输入流不为空
fileInputStream.close(); // 关闭文件输入流
}
} catch (IOException e) {
e.printStackTrace();
} catch (IOException e) { // 捕获输入输出异常
e.printStackTrace(); // 打印异常信息
}
}
}
}

@ -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 主体的注销操作
}
}

@ -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,21 +28,51 @@ 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");
@ -51,12 +80,23 @@ public class AccountController {
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 {
@ -111,6 +151,10 @@ public class AccountController {
}
}
/**
*
* @return
*/
private String getAvatorNo() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
String format = sdf.format(new Date());

@ -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<BookCategoryEntity> bookCategoryList = null;
if(StringUtils.isEmpty(parentId)) {
bookCategoryList = iBookCategoryService.selectList(Condition.create().eq("parent_id", "0"));
List<BookCategoryEntity> 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));
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<BookCategoryEntity> bookCategoryList) {
JSONArray entitys = new JSONArray();
for(int i=0 ; i<bookCategoryList.size() ; i++) {
BookCategoryEntity bc = bookCategoryList.get(i);
JSONObject entity = new JSONObject();
entity.put("label", bc.getName());
entity.put("value", bc.getId());
Integer count = iBookCategoryService.selectCount(Condition.create().eq("parent_id", bc.getId()));
JSONArray entitys = new JSONArray(); // 创建 JSON 数组实例
for(int i = 0; i < bookCategoryList.size(); i++) { // 遍历图书分类列表
BookCategoryEntity bc = bookCategoryList.get(i); // 获取当前图书分类实体
JSONObject entity = new JSONObject(); // 创建 JSON 对象实例
entity.put("label", bc.getName()); // 设置标签为分类名称
entity.put("value", bc.getId()); // 设置值为分类 ID
Integer count = iBookCategoryService.selectCount(Condition.create().eq("parent_id", bc.getId())); // 获取当前分类的子分类数量
if(count > 0) {
entity.put("children", new JSONArray());
entity.put("children", new JSONArray()); // 如果有子分类,设置子分类数组
}
entitys.add(entity);
entitys.add(entity); // 将当前分类对象添加到 JSON 数组中
}
return entitys;
return entitys; // 返回处理后的 JSON 数组
}
}

@ -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;
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<String, Object> map = new HashMap<>();
Map<String, Object> map = new HashMap<>(); // 创建一个 Map 对象
try {
BookEntity book = iBookService.selectById(id);
List<DocumentEntity> documentList = iDocumentService.selectList(Condition.create().eq("book_id", id).eq("status", DocumentStatusEnum.NORMAL.getValue()));
BookEntity book = iBookService.selectById(id); // 根据图书 ID 获取图书信息
List<DocumentEntity> documentList = iDocumentService.selectList(Condition.create().eq("book_id", id).eq("status", DocumentStatusEnum.NORMAL.getValue())); // 根据图书 ID 和文档状态获取文档列表
map.put("documentList", this.processDocumentList(documentList));
map.put("book", book);
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<BookEntity> bookList = iBookService.selectList(Condition.create().eq("owner", ShiroUtils.getMemberId()).orderDesc(Arrays.asList("create_date")));
return Result.successResult(bookList);
List<BookEntity> 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<DocumentEntity> documentList) {
JSONArray entitys = new JSONArray();
for(int i=0 ; i<documentList.size() ; i ++) {
DocumentEntity doc = documentList.get(i);
JSONObject entity = new JSONObject();
entity.put("id", doc.getId());
entity.put("text", doc.getName());
entity.put("parent", "0".equals(doc.getParentId()) ? "#" : doc.getParentId());
entity.put("identify", doc.getId());
entity.put("version", doc.getCreateDate().getTime());
JSONObject attr = new JSONObject();
attr.put("is_open", "0".equals(doc.getIsOpen()) ? false : true);
entity.put("a_attr", attr);
entitys.add(entity);
JSONArray entitys = new JSONArray(); // 创建 JSON 数组对象
for (int i = 0; i < documentList.size(); i++) { // 遍历文档列表
DocumentEntity doc = documentList.get(i); // 获取当前文档
JSONObject entity = new JSONObject(); // 创建 JSON 对象
entity.put("id", doc.getId()); // 设置文档 ID
entity.put("text", doc.getName()); // 设置文档名称
entity.put("parent", "0".equals(doc.getParentId())? "#" : doc.getParentId()); // 设置文档的父节点
entity.put("identify", doc.getId()); // 设置文档的标识
entity.put("version", doc.getCreateDate().getTime()); // 设置文档的版本
JSONObject attr = new JSONObject(); // 创建属性对象
attr.put("is_open", "0".equals(doc.getIsOpen())? false : true); // 设置文档是否展开
entity.put("a_attr", attr); // 设置文档的属性
entitys.add(entity); // 将文档对象添加到 JSON 数组中
}
return entitys;
return entitys; // 返回 JSON 数组
}
/**
*
* @param id ID
* @return
*/
@RequestMapping(value = "book/{id}.html", method = RequestMethod.GET)
@ResponseBody
public Result book(@PathVariable String id) {
try {
BookEntity book = iBookService.selectById(id);
BookEntity book = iBookService.selectById(id); // 根据图书 ID 获取图书信息
String categoryIds = book.getCategoryId(); // 获取图书的分类 ID 字符串
book.setCategoryIds(Arrays.asList(categoryIds.split(","))); // 将分类 ID 字符串转换为列表
String categoryIds = book.getCategoryId();
book.setCategoryIds(Arrays.asList(categoryIds.split(",")));
// 获取 categoryIds
return Result.result(0, book, "查询成功!");
return Result.result(0, book, "查询成功!"); // 返回查询成功的结果
} catch (Exception e) {
logger.error(e.getMessage() , e);
return Result.result(1, null, "查询失败!");
logger.error(e.getMessage(), e); // 记录错误日志
return Result.result(1, null, "查询失败!"); // 返回查询失败的结果
}
}
}

@ -15,7 +15,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PathPathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@ -35,31 +35,41 @@ import com.tamguo.modules.book.service.IFileEntityService;
import com.tamguo.modules.book.service.IFileUploadService;
import com.tamguo.utils.FileMd5Utils;
/**
* DocumentController
*/
@Controller
@RequestMapping(value = "document")
public class DocumentController {
private Logger logger = LoggerFactory.getLogger(getClass());
private Logger logger = LoggerFactory.getLogger(getClass()); // 创建日志记录器对象
@Autowired
IDocumentService iDocumentService;
IDocumentService iDocumentService; // 自动注入文档服务
@Autowired
IFileEntityService iFileEntityService;
IFileEntityService iFileEntityService; // 自动注入文件实体服务
@Autowired
IFileUploadService iFileUploadService;
IFileUploadService iFileUploadService; // 自动注入文件上传服务
@Value("${file.storage.path}")
private String fileStoragePath;
private String fileStoragePath; // 文件存储路径配置
@Value("${tamguo.domain.name}")
private String domainName;
private String domainName; // 域名配置
@SuppressWarnings("unchecked")
/**
*
* @param id ID
* @return
*/
@RequestMapping(value = "{id}", method = RequestMethod.GET)
@ResponseBody
public Result getDocument(@PathVariable String id) {
DocumentEntity document = null;
DocumentEntity document = null; // 定义文档对象
try {
document = iDocumentService.selectById(id);
document = iDocumentService.selectById(id); // 根据 ID 获取文档信息
// 查询附件
List<FileUploadEntity> fileUploads = iFileUploadService.selectList(Condition.create().eq("biz_key", document.getId()).eq("biz_type", BizTypeEnum.DOCUMENT.getValue()));
if (!CollectionUtils.isEmpty(fileUploads)) {
@ -72,152 +82,172 @@ public class DocumentController {
document.setFileUploads(fileUploads);
}
} catch (Exception e) {
logger.error(e.getMessage() , e );
return Result.failResult("查询失败");
logger.error(e.getMessage(), e); // 记录错误日志
return Result.failResult("查询失败"); // 返回查询失败结果
}
return Result.successResult(document);
return Result.successResult(document); // 返回查询成功结果
}
/**
*
*
* @param document
* @return
*/
@RequestMapping(value = "modify", method = RequestMethod.POST)
@ResponseBody
public Result modify(DocumentEntity document) {
try {
iDocumentService.modify(document);
iDocumentService.modify(document); // 修改文档内容
} catch (Exception e) {
logger.error(e.getMessage() , e );
return Result.failResult("保存失败");
logger.error(e.getMessage(), e); // 记录错误日志
return Result.failResult("保存失败"); // 返回保存失败结果
}
return Result.successResult("保存成功");
return Result.successResult("保存成功"); // 返回保存成功结果
}
/**
*
*
* @param document
* @return
*/
@RequestMapping(value = "create", method = RequestMethod.POST)
@ResponseBody
public Result create(DocumentEntity document) {
try {
iDocumentService.create(document);
iDocumentService.create(document); // 创建文档
} catch (Exception e) {
logger.error(e.getMessage() , e );
return Result.failResult("保存失败");
logger.error(e.getMessage(), e); // 记录错误日志
return Result.failResult("保存失败"); // 返回保存失败结果
}
return Result.successResult(document);
return Result.successResult(document); // 返回保存成功结果
}
@SuppressWarnings("unchecked")
/**
*
* @param file
* @param bookId ID
* @param request HTTP
* @return
*/
@RequestMapping(value = "uploadImage", method = RequestMethod.POST)
@ResponseBody
public Result uploadImage(@RequestParam("editormd-image-file") MultipartFile file, String bookId, HttpServletRequest request) {
try {
String fileMd5 = FileMd5Utils.getMD5((FileInputStream)file.getInputStream());
FileEntity sysFile = iFileEntityService.selectOne(Condition.create().eq("file_md5", fileMd5));
String fileMd5 = FileMd5Utils.getMD5((FileInputStream) file.getInputStream()); // 获取文件的 MD5 值
FileEntity sysFile = iFileEntityService.selectOne(Condition.create().eq("file_md5", fileMd5)); // 根据 MD5 值查询系统文件
if (sysFile!= null) {
sysFile.setFilePath(domainName + "files/" + sysFile.getFilePath());
return Result.successResult(sysFile);
return Result.successResult(sysFile); // 如果文件已存在,直接返回文件信息
}
String filePath = fileStoragePath + "book/" + DateUtil.fomatDate(new Date(), "yyyyMM") + "/" + bookId;
String filePath = fileStoragePath + "book/" + DateUtil.fomatDate(new Date(), "yyyyMM") + "/" + bookId; // 生成文件存储路径
File dest = new File(filePath);
if (!dest.exists()) {
dest.mkdirs();
dest.mkdirs(); // 创建存储目录
}
// save 文件
FileUtils.writeByteArrayToFile(new File(filePath + "/" + file.getOriginalFilename()) , file.getBytes());
FileEntity fileEntity = new FileEntity();
fileEntity.setFileContentType(file.getContentType());
fileEntity.setFileExtension(file.getOriginalFilename());
fileEntity.setFileMd5(FileMd5Utils.getMD5((FileInputStream)file.getInputStream()));
fileEntity.setFileSize(file.getSize());
fileEntity.setFilePath("book/" + DateUtil.fomatDate(new Date(), "yyyyMM") + "/" + bookId + "/" + file.getOriginalFilename());
iFileEntityService.insert(fileEntity);
fileEntity.setFilePath(domainName + "files/" + fileEntity.getFilePath());
return Result.successResult(fileEntity);
FileUtils.writeByteArrayToFile(new File(filePath + "/" + file.getOriginalFilename()), file.getBytes()); // 保存文件
FileEntity fileEntity = new FileEntity(); // 创建文件实体对象
fileEntity.setFileContentType(file.getContentType()); // 设置文件类型
fileEntity.setFileExtension(file.getOriginalFilename()); // 设置文件扩展名
fileEntity.setFileMd5(FileMd5Utils.getMD5((FileInputStream) file.getInputStream())); // 设置文件 MD5 值
fileEntity.setFileSize(file.getSize()); // 设置文件大小
fileEntity.setFilePath("book/" + DateUtil.fomatDate(new Date(), "yyyyMM") + "/" + bookId + "/" + file.getOriginalFilename()); // 设置文件路径
iFileEntityService.insert(fileEntity); // 插入文件实体到数据库
fileEntity.setFilePath(domainName + "files/" + fileEntity.getFilePath()); // 设置文件路径
return Result.successResult(fileEntity); // 返回文件信息
} catch (IOException e) {
e.printStackTrace();
return Result.failResult("上传失败");
return Result.failResult("上传失败"); // 如果上传失败,返回失败结果
}
}
/**
*
*
* @param file
* @param documentId ID
* @param bookId ID
* @param request HTTP
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping(value = "uploadFile", method = RequestMethod.POST)
@ResponseBody
public Result uploadFile(@RequestParam("editormd-file-file") MultipartFile file, String documentId, String bookId, HttpServletRequest request) {
try {
String fileMd5 = FileMd5Utils.getMD5((FileInputStream)file.getInputStream());
FileEntity sysFile = iFileEntityService.selectOne(Condition.create().eq("file_md5", fileMd5));
String fileMd5 = FileMd5Utils.getMD5((FileInputStream) file.getInputStream()); // 获取文件的 MD5 值
FileEntity sysFile = iFileEntityService.selectOne(Condition.create().eq("file_md5", fileMd5)); // 根据 MD5 值查询系统文件
// 文件不存在
if (sysFile == null) {
String filePath = fileStoragePath + "book/" + DateUtil.fomatDate(new Date(), "yyyyMM") + "/" + bookId;
String filePath = fileStoragePath + "book/" + DateUtil.fomatDate(new Date(), "yyyyMM") + "/" + bookId; // 生成文件存储路径
File dest = new File(filePath);
if (!dest.exists()) {
dest.mkdirs();
dest.mkdirs(); // 创建存储目录
}
// save 文件
FileUtils.writeByteArrayToFile(new File(filePath + "/" + file.getOriginalFilename()) , file.getBytes());
sysFile = new FileEntity();
sysFile.setFileContentType(file.getContentType());
sysFile.setFileExtension(file.getOriginalFilename());
sysFile.setFileMd5(FileMd5Utils.getMD5((FileInputStream)file.getInputStream()));
sysFile.setFileSize(file.getSize());
sysFile.setFilePath("book/" + DateUtil.fomatDate(new Date(), "yyyyMM") + "/" + bookId + "/" + file.getOriginalFilename());
iFileEntityService.insert(sysFile);
FileUtils.writeByteArrayToFile(new File(filePath + "/" + file.getOriginalFilename()), file.getBytes()); // 保存文件
sysFile = new FileEntity(); // 创建文件实体对象
sysFile.setFileContentType(file.getContentType()); // 设置文件类型
sysFile.setFileExtension(file.getOriginalFilename()); // 设置文件扩展名
sysFile.setFileMd5(FileMd5Utils.getMD5((FileInputStream) file.getInputStream())); // 设置文件 MD5 值
sysFile.setFileSize(file.getSize()); // 设置文件大小
sysFile.setFilePath("book/" + DateUtil.fomatDate(new Date(), "yyyyMM") + "/" + bookId + "/" + file.getOriginalFilename()); // 设置文件路径
iFileEntityService.insert(sysFile); // 插入文件实体到数据库
}
// 创建上传记录
FileUploadEntity fileUpload = new FileUploadEntity();
fileUpload.setBizKey(documentId);
fileUpload.setBizType(BizTypeEnum.DOCUMENT);
fileUpload.setCreateBy("system");
fileUpload.setCreateDate(new Date());
fileUpload.setFileId(sysFile.getFileId());
fileUpload.setFileName(sysFile.getFileExtension());
fileUpload.setFileType(file.getContentType());
fileUpload.setUpdateBy("system");
fileUpload.setUpdateDate(new Date());
fileUpload.setStatus(FileUploadStatusEnum.NORMAL);
iFileUploadService.insert(fileUpload);
fileUpload.setFilePath(domainName + "files/" + sysFile.getFilePath());
fileUpload.setFileSize(sysFile.getFileSize());
return Result.successResult(fileUpload);
FileUploadEntity fileUpload = new FileUploadEntity(); // 创建文件上传记录对象
fileUpload.setBizKey(documentId); // 设置业务键
fileUpload.setBizType(BizTypeEnum.DOCUMENT); // 设置业务类型
fileUpload.setCreateBy("system"); // 设置创建者
fileUpload.setCreateDate(new Date()); // 设置创建日期
fileUpload.setFileId(sysFile.getFileId()); // 设置文件 ID
fileUpload.setFileName(sysFile.getFileExtension()); // 设置文件名称
fileUpload.setFileType(file.getContentType()); // 设置文件类型
fileUpload.setUpdateBy("system"); // 设置更新者
fileUpload.setUpdateDate(new Date()); // 设置更新日期
fileUpload.setStatus(FileUploadStatusEnum.NORMAL); // 设置状态为正常
iFileUploadService.insert(fileUpload); // 插入文件上传记录到数据库
fileUpload.setFilePath(domainName + "files/" + sysFile.getFilePath()); // 设置文件路径
fileUpload.setFileSize(sysFile.getFileSize()); // 设置文件大小
return Result.successResult(fileUpload); // 返回文件上传记录信息
} catch (IOException e) {
e.printStackTrace();
return Result.failResult("上传失败");
return Result.failResult("上传失败"); // 如果上传失败,返回失败结果
}
}
/**
*
*
* @param id ID
* @return
*/
@RequestMapping(value = "removeFile", method = RequestMethod.POST)
@ResponseBody
public Result removeFile(String id) {
try {
iFileUploadService.deleteById(id);
iFileUploadService.deleteById(id); // 根据 ID 删除文件上传记录
} catch (Exception e) {
return Result.result(1, null, "删除失败");
return Result.result(1, null, "删除失败"); // 如果删除失败,返回失败结果
}
return Result.result(0, null, "删除成功");
return Result.result(0, null, "删除成功"); // 如果删除成功,返回成功结果
}
@SuppressWarnings("unchecked")
/**
*
* @param id ID
* @return
*/
@RequestMapping(value = "delete", method = RequestMethod.POST)
@ResponseBody
public Result delete(String id) {
try {
DocumentEntity document = iDocumentService.selectById(id);
iDocumentService.delete(Condition.create().eq("batch_no", document.getBatchNo()));
DocumentEntity document = iDocumentService.selectById(id); // 根据 ID 获取文档信息
iDocumentService.delete(Condition.create().eq("batch_no", document.getBatchNo())); // 根据批次号删除文档
} catch (Exception e) {
return Result.result(1, null, "删除失败");
return Result.result(1, null, "删除失败"); // 如果删除失败,返回失败结果
}
return Result.result(0, null, "删除成功");
return Result.result(0, null, "删除成功"); // 如果删除成功,返回成功结果
}
}

@ -1,34 +1,45 @@
package com.tamguo.web;
import org.apache.commons.mail.EmailException;
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 org.apache.commons.mail.EmailException; // 导入邮件异常类
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.tamguo.common.utils.Result;
import com.tamguo.common.utils.SystemConstant;
import com.tamguo.modules.sys.service.IEmailService;
import com.tamguo.common.utils.Result; // 通用结果类
import com.tamguo.common.utils.SystemConstant; // 系统常量类
import com.tamguo.modules.sys.service.IEmailService; // 邮件服务接口
/**
* EmailController
*/
@Controller
public class EmailController {
@Autowired
@Autowired // 自动注入邮件服务实例
private IEmailService iEmailService;
/**
*
* @param email
* @return
*/
@RequestMapping(value = {"sendFindPasswordEmail"}, method = RequestMethod.GET)
@ResponseBody
public Result sendFindPasswordEmail(String email) {
try {
// 调用邮件服务发送找回密码邮件,并获取结果
Integer result = iEmailService.sendFindPasswordEmail(email, SystemConstant.ALIYUN_MAIL_SUBJECT_FINDPASSWORD);
if (result == 0) {
// 如果结果为 0返回服务器异常的结果
return Result.result(200, null, "服务器异常");
}
} catch (EmailException e) {
// 捕获邮件异常并打印堆栈信息
e.printStackTrace();
}
// 无论是否发生异常,都返回服务器异常的结果
return Result.result(500, null, "服务器异常");
}
}

@ -1,73 +1,81 @@
package com.tamguo.web;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Date;
import java.io.File; // 文件类
import java.io.FileInputStream; // 文件输入流类
import java.io.IOException; // 输入输出异常类
import java.util.Date; // 日期类
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequest; // HTTP 请求类
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.apache.commons.io.FileUtils; // 文件工具类
import org.springframework.beans.factory.annotation.Autowired; // 自动注入注解
import org.springframework.beans.factory.annotation.Value; // 值注入注解
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.RequestParam; // 请求参数
import org.springframework.web.bind.annotation.ResponseBody; // 返回响应体
import com.baomidou.mybatisplus.mapper.Condition;
import com.tamguo.common.utils.DateUtil;
import com.tamguo.common.utils.Result;
import com.tamguo.modules.book.model.FileEntity;
import com.tamguo.modules.book.service.IFileEntityService;
import com.tamguo.utils.FileMd5Utils;
import com.baomidou.mybatisplus.mapper.Condition; // 条件类
import com.tamguo.common.utils.DateUtil; // 日期工具类
import com.tamguo.common.utils.Result; // 通用结果类
import com.tamguo.modules.book.model.FileEntity; // 文件实体类
import com.tamguo.modules.book.service.IFileEntityService; // 文件服务接口
/**
* FileController
*/
@Controller
public class FileController {
@Value("${file.storage.path}")
@Value("${file.storage.path}") // 获取配置文件中文件存储路径的值
private String fileStoragePath;
@Value("${tamguo.domain.name}")
@Value("${tamguo.domain.name}") // 获取配置文件中域名的值
private String domainName;
@Autowired
@Autowired // 自动注入文件服务实例
private IFileEntityService iFileEntityService;
/**
*
* @param file
* @param request HTTP
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping(value = "uploadImage", method = RequestMethod.POST)
@ResponseBody
public Result uploadImage(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
try {
String fileMd5 = FileMd5Utils.getMD5((FileInputStream)file.getInputStream());
FileEntity sysFile = iFileEntityService.selectOne(Condition.create().eq("file_md5", fileMd5));
if(sysFile != null) {
sysFile.setFilePath(domainName + "files/" + sysFile.getFilePath());
return Result.successResult(sysFile);
String fileMd5 = FileMd5Utils.getMD5((FileInputStream)file.getInputStream()); // 获取文件的 MD5 值
FileEntity sysFile = iFileEntityService.selectOne(Condition.create().eq("file_md5", fileMd5)); // 根据文件 MD5 查找文件实体
if (sysFile!= null) { // 如果找到文件实体
sysFile.setFilePath(domainName + "files/" + sysFile.getFilePath()); // 设置文件路径
return Result.successResult(sysFile); // 返回文件实体
}
String filePath = fileStoragePath + DateUtil.fomatDate(new Date(), "yyyyMM") + "/avatar";
File dest = new File(filePath);
if(!dest.exists()) {
dest.mkdirs();
String filePath = fileStoragePath + DateUtil.fomatDate(new Date(), "yyyyMM") + "/avatar"; // 设置文件存储路径
File dest = new File(filePath); // 创建文件对象
if (!dest.exists()) { // 如果文件不存在
dest.mkdirs(); // 创建文件夹
}
// save 文件
// 保存文件
FileUtils.writeByteArrayToFile(new File(filePath + "/" + file.getOriginalFilename()), file.getBytes());
FileEntity fileEntity = new FileEntity();
fileEntity.setFileContentType(file.getContentType());
fileEntity.setFileExtension(file.getOriginalFilename());
fileEntity.setFileMd5(FileMd5Utils.getMD5((FileInputStream)file.getInputStream()));
fileEntity.setFileSize(file.getSize());
fileEntity.setFilePath(DateUtil.fomatDate(new Date(), "yyyyMM") + "/avatar/" + file.getOriginalFilename());
iFileEntityService.insert(fileEntity);
FileEntity fileEntity = new FileEntity(); // 创建文件实体对象
fileEntity.setFileContentType(file.getContentType()); // 设置文件类型
fileEntity.setFileExtension(file.getOriginalFilename()); // 设置文件扩展名
fileEntity.setFileMd5(FileMd5Utils.getMD5((FileInputStream)file.getInputStream())); // 设置文件 MD5 值
fileEntity.setFileSize(file.getSize()); // 设置文件大小
fileEntity.setFilePath(DateUtil.fomatDate(new Date(), "yyyyMM") + "/avatar/" + file.getOriginalFilename()); // 设置文件路径
iFileEntityService.insert(fileEntity); // 插入文件实体到数据库
fileEntity.setFilePath(domainName + "files/" + fileEntity.getFilePath());
fileEntity.setFilePath(domainName + "files/" + fileEntity.getFilePath()); // 设置文件路径
return Result.successResult(fileEntity);
return Result.successResult(fileEntity); // 返回文件实体
} catch (IOException e) {
e.printStackTrace();
return Result.failResult("上传失败");
e.printStackTrace(); // 打印异常信息
return Result.failResult("上传失败"); // 返回上传失败的结果
}
}
}

@ -18,74 +18,108 @@ import com.tamguo.modules.book.model.DocumentEntity;
import com.tamguo.modules.book.model.enums.DocumentStatusEnum;
import com.tamguo.modules.book.service.IDocumentService;
/**
* HistoryDocController
*/
@Controller
@RequestMapping(value="document")
public class HistoryDocController {
// 日志记录器
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private IDocumentService iDocumentService;
/**
*
*
* @param id ID
* @param model
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping(value = "history", method = RequestMethod.POST)
public ModelAndView history(String id, ModelAndView model) {
model.setViewName("book/history");
model.setViewName("book/history"); // 设置视图名称
// 根据 ID 查询文档实体
DocumentEntity document = iDocumentService.selectById(id);
model.addObject("document", document);
model.addObject("document", document); // 添加文档到模型
// 查询与该批次号且状态为历史的文档列表,并按创建日期降序排序
model.addObject("historyList", iDocumentService.selectList(Condition.create().eq("batch_no", document.getBatchNo()).eq("status", DocumentStatusEnum.HISTORY.getValue()).orderDesc(Arrays.asList("create_date"))));
return model;
}
/**
*
*
* @param id ID
* @return
*/
@RequestMapping(value = "history/delete", method = RequestMethod.POST)
@ResponseBody
public Result delete(String id) {
try {
// 根据 ID 删除文档
iDocumentService.deleteById(id);
} catch (Exception e) {
logger.error(e.getMessage() , e);
return Result.failResult("删除失败!");
logger.error(e.getMessage(), e); // 记录错误日志
return Result.failResult("删除失败!"); // 返回删除失败结果
}
return Result.successResult("删除成功!");
return Result.successResult("删除成功!"); // 返回删除成功结果
}
/**
*
*
* @param id ID
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping(value = "history/restore", method = RequestMethod.POST)
@ResponseBody
public Result restore(String id) {
try {
// 根据 ID 查询历史文档
DocumentEntity history = iDocumentService.selectById(id);
// 获取历史文档的内容和 markdown
String content = history.getContent();
String markdown = history.getMarkdown();
// 查询与该批次号且状态为正常的文档
DocumentEntity document = iDocumentService.selectOne(Condition.create().eq("batch_no", history.getBatchNo()).eq("status", DocumentStatusEnum.NORMAL.getValue()));
// 设置文档的内容和 markdown
document.setContent(content);
document.setMarkdown(markdown);
document.setCover("no");
// 修改文档
iDocumentService.modify(document);
return Result.successResult(document);
return Result.successResult(document); // 返回恢复成功结果和文档
} catch (Exception e) {
logger.error(e.getMessage() , e);
return Result.failResult("恢复失败!");
logger.error(e.getMessage(), e); // 记录错误日志
return Result.failResult("恢复失败!"); // 返回恢复失败结果
}
}
/**
*
* @param id ID
* @param model
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping(value = "history/compare/{id}", method = RequestMethod.POST)
@ResponseBody
public ModelAndView compare(@PathVariable String id, ModelAndView model) {
model.setViewName("book/compare");
model.setViewName("book/compare"); // 设置视图名称
// 根据 ID 查询历史文档
DocumentEntity history = iDocumentService.selectById(id);
model.addObject("history", history);
model.addObject("document", iDocumentService.selectOne(Condition.create().eq("status", DocumentStatusEnum.NORMAL.getValue()).eq("batch_no", history.getBatchNo())));
model.addObject("history", history); // 添加历史文档到模型
// 查询与该批次号且状态为正常的文档
model.addObject("document", iDocumentService.selectOne(Condition.create().eq("batch_no", history.getBatchNo()).eq("status", DocumentStatusEnum.NORMAL.getValue())));
return model;
}
}

@ -1,12 +1,13 @@
package com.tamguo.web;
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.servlet.ModelAndView;
import com.tamguo.modules.member.service.IMemberService;
import com.tamguo.utils.ShiroUtils;
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.servlet.ModelAndView; // 模型和视图
import com.tamguo.modules.member.service.IMemberService; // 会员服务接口
import com.tamguo.utils.ShiroUtils; // Shiro 工具类
/**
* -
@ -17,14 +18,19 @@ import com.tamguo.utils.ShiroUtils;
@Controller
public class IndexController {
@Autowired
@Autowired // 自动注入会员服务实例
IMemberService iMemberService;
/**
* index.html / GET
*
* @param model
* @return
*/
@RequestMapping(value = {"index.html", "/"}, method = RequestMethod.GET)
public ModelAndView index(ModelAndView model) {
model.setViewName("index");
model.addObject("member", iMemberService.selectById(ShiroUtils.getMemberId()));
model.setViewName("index"); // 设置视图名称为 "index"
model.addObject("member", iMemberService.selectById(ShiroUtils.getMemberId())); // 添加会员信息到模型中
return model;
}
}

@ -22,9 +22,23 @@ import com.tamguo.common.utils.Result;
import com.tamguo.common.utils.SystemConstant;
import com.tamguo.utils.ShiroUtils;
/**
*
*
* @author tamguo
*
*/
@Controller
public class LoginController {
/**
*
*
* @param response
* @param session
* @throws ServletException Servlet
* @throws IOException IO
*/
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response, HttpSession session) throws ServletException, IOException {
response.setHeader("Cache-Control", "no-store, no-cache");
@ -34,6 +48,13 @@ public class LoginController {
session.setAttribute(SystemConstant.KAPTCHA_SESSION_KEY, a);
}
/**
* GET
*
* @param redirectUrl URL
* @param model
* @return
*/
@RequestMapping(value = "/login.html", method = RequestMethod.GET)
public ModelAndView login(String redirectUrl, ModelAndView model) {
model.setViewName("login");
@ -42,9 +63,23 @@ public class LoginController {
return model;
}
/**
* POST
*
* @param username
* @param password
* @param verifyCode
* @param redirectUrl URL
* @param model
* @param session
* @param response
* @return null
* @throws IOException IO
*/
@RequestMapping(value = "/submitLogin.html", method = RequestMethod.POST)
public ModelAndView submitLogin(String username, String password, String verifyCode, String redirectUrl, ModelAndView model, HttpSession session, HttpServletResponse response) throws IOException {
Result result = Result.successResult(null);
if (StringUtils.isEmpty(verifyCode)) {
result = Result.result(202, null, "请输入验证码");
} else if (StringUtils.isNotEmpty(verifyCode)) {
@ -73,6 +108,7 @@ public class LoginController {
}
}
}
model.setViewName("login");
model.addObject("code", result.getCode());
model.addObject("msg", result.getMessage());
@ -80,10 +116,21 @@ public class LoginController {
return model;
}
/**
* GET
*
* @param username
* @param password
* @param captcha
* @param model
* @param session
* @return
*/
@RequestMapping(value = "/miniLogin.html", method = RequestMethod.GET)
@ResponseBody
public Result miniLogin(String username, String password, String captcha, ModelAndView model, HttpSession session) {
Result result = null;
if (StringUtils.isEmpty(captcha)) {
result = Result.result(204, null, "请输入验证码");
} else if (StringUtils.isNotEmpty(captcha)) {
@ -109,6 +156,11 @@ public class LoginController {
return result;
}
/**
*
*
* @return
*/
@RequestMapping(value = "/isLogin.html", method = RequestMethod.GET)
@ResponseBody
public Result isLogin() {

@ -1,28 +1,27 @@
package com.tamguo.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest; // 导入 HttpServletRequest 类
import javax.servlet.http.HttpServletResponse; // 导入 HttpServletResponse 类
import javax.servlet.http.HttpSession; // 导入 HttpSession 类
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.stereotype.Controller; // 表示这是一个控制器类
import org.springframework.web.bind.annotation.RequestMapping; // 用于处理请求映射
import org.springframework.web.bind.annotation.RequestMethod; // 用于指定请求方法
import com.tamguo.utils.ShiroUtils;
import com.tamguo.utils.ShiroUtils; // 导入 ShiroUtils 类
@Controller
@Controller // 声明这是一个控制器
public class LogoutController {
/**
*
*
*/
@RequestMapping(value = "logout.html", method = RequestMethod.GET)
public String logout(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
if (session.getAttribute("currMember") != null) {
session.removeAttribute("currMember");
ShiroUtils.logout();
@RequestMapping(value = "logout.html", method = RequestMethod.GET) // 映射到 "logout.html" 且使用 GET 方法的请求
public String logout(HttpServletRequest request, HttpServletResponse response, HttpSession session) { // 接收请求、响应和会话对象
if (session.getAttribute("currMember")!= null) { // 如果会话中当前成员不为空
session.removeAttribute("currMember"); // 从会话中移除当前成员属性
ShiroUtils.logout(); // 执行 ShiroUtils 的注销操作
}
return "redirect:/";
return "redirect:/"; // 重定向到根路径
}
}

@ -1,81 +1,95 @@
package com.tamguo.web;
import javax.servlet.http.HttpSession;
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 org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession; // 导入 HttpSession 类
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 org.springframework.web.servlet.ModelAndView; // 模型和视图类
import com.tamguo.common.utils.Result;
import com.tamguo.common.utils.SystemConstant;
import com.tamguo.modules.member.service.IMemberService;
import com.tamguo.common.utils.Result; // 通用结果类
import com.tamguo.common.utils.SystemConstant; // 系统常量类
import com.tamguo.modules.member.service.IMemberService; // 会员服务接口
@Controller
@Controller // 控制器注解
public class PasswordController {
@Autowired
@Autowired // 自动注入会员服务
private IMemberService iMemberService;
/**
*
*/
@RequestMapping(value = "password/find.html", method = RequestMethod.GET)
public ModelAndView confirmAccount(ModelAndView model){
model.setViewName("password/confirmAccount");
return model;
public ModelAndView confirmAccount(ModelAndView model) { // 处理方法,接收模型和视图对象
model.setViewName("password/confirmAccount"); // 设置视图名称
return model; // 返回模型和视图
}
/**
*
*/
@RequestMapping(value = "password/confirmAccount.html", method = RequestMethod.POST)
public ModelAndView submitConfirmAccount(String username , String veritycode , ModelAndView model , HttpSession session){
Result result = iMemberService.confirmAccount(username, veritycode);
String kaptcha = session.getAttribute(SystemConstant.KAPTCHA_SESSION_KEY).toString();
if (!veritycode.equalsIgnoreCase(kaptcha)) {
result = Result.result(202, null, "验证码错误");
public ModelAndView submitConfirmAccount(String username, String veritycode, ModelAndView model, HttpSession session) { // 处理方法,接收参数、模型和视图对象、会话对象
Result result = iMemberService.confirmAccount(username, veritycode); // 调用会员服务的确认账号方法
String kaptcha = session.getAttribute(SystemConstant.KAPTCHA_SESSION_KEY).toString(); // 获取验证码
if (!veritycode.equalsIgnoreCase(kaptcha)) { // 比较验证码是否正确
result = Result.result(202, null, "验证码错误"); // 设置错误结果
}
if(result.getCode() == 200){
model.setViewName("password/securityCheck");
model.addObject("result", result);
model.addObject("isEmail", username.contains("@") ? "1" : "0");
if (result.getCode() == 200) { // 如果结果码为 200
model.setViewName("password/securityCheck"); // 设置视图名称
model.addObject("result", result); // 添加结果到模型
model.addObject("isEmail", username.contains("@")? "1" : "0"); // 添加是否为邮箱的标识到模型
} else {
model.setViewName("password/confirmAccount");
model.addObject("account", username);
model.addObject("username",username);
model.addObject("veritycode", veritycode);
model.addObject("code", result.getCode());
model.setViewName("password/confirmAccount"); // 设置视图名称
model.addObject("account", username); // 添加账号到模型
model.addObject("username", username); // 添加用户名到模型
model.addObject("veritycode", veritycode); // 添加验证码到模型
model.addObject("code", result.getCode()); // 添加结果码到模型
}
return model;
return model; // 返回模型和视图
}
/**
*
*/
@RequestMapping(value = "password/securityCheck.html", method = RequestMethod.POST)
public ModelAndView securityCheck(String username , String isEmail , String mobileVcode , ModelAndView model){
Result result = iMemberService.securityCheck(username , isEmail , mobileVcode);
if(result.getCode() == 200){
model.addObject("username", username);
model.addObject("resetPasswordKey" , result.getResult());
model.setViewName("password/resetPassword");
public ModelAndView securityCheck(String username, String isEmail, String mobileVcode, ModelAndView model) { // 处理方法,接收参数、模型和视图对象
Result result = iMemberService.securityCheck(username, isEmail, mobileVcode); // 调用会员服务的安全检查方法
if (result.getCode() == 200) { // 如果结果码为 200
model.addObject("username", username); // 添加用户名到模型
model.addObject("resetPasswordKey", result.getResult()); // 添加重置密码键到模型
model.setViewName("password/resetPassword"); // 设置视图名称
} else {
model.addObject("result", result);
model.addObject("isEmail", isEmail);
model.addObject("codeError", "1");
model.setViewName("password/securityCheck");
model.addObject("result", result); // 添加结果到模型
model.addObject("isEmail", isEmail); // 添加是否为邮箱的标识到模型
model.addObject("codeError", "1"); // 添加错误标识到模型
model.setViewName("password/securityCheck"); // 设置视图名称
}
return model;
return model; // 返回模型和视图
}
/**
*
*/
@RequestMapping(value = "password/resetPassword.html", method = RequestMethod.POST)
public ModelAndView resetPassword(String resetPasswordKey , String username , String password , String verifypwd , ModelAndView model){
Result result = iMemberService.resetPassword(resetPasswordKey , username , password , verifypwd);
if(result.getCode() == 200){
model.setViewName("password/resetPwSuccess");
public ModelAndView resetPassword(String resetPasswordKey, String username, String password, String verifypwd, ModelAndView model) { // 处理方法,接收参数、模型和视图对象
Result result = iMemberService.resetPassword(resetPasswordKey, username, password, verifypwd); // 调用会员服务的重置密码方法
if (result.getCode() == 200) { // 如果结果码为 200
model.setViewName("password/resetPwSuccess"); // 设置视图名称
} else {
model.setViewName("password/resetPassword");
model.setViewName("password/resetPassword"); // 设置视图名称
}
return model;
return model; // 返回模型和视图
}
/**
*
*/
@RequestMapping(value = "password/checkAccount.html", method = RequestMethod.GET)
@ResponseBody
public Result checkAccount(String account){
return iMemberService.checkAccount(account);
@ResponseBody // 返回响应体
public Result checkAccount(String account) { // 处理方法,接收账号参数
return iMemberService.checkAccount(account); // 调用会员服务的检查账号方法并返回结果
}
}

@ -19,41 +19,74 @@ import com.tamguo.modules.member.model.MemberEntity;
import com.tamguo.modules.member.service.IMemberService;
import com.tamguo.utils.ShiroUtils;
/**
* RegisterController
*/
@Controller
public class RegisterController {
/**
* IMemberService
*/
@Autowired
private IMemberService iMemberService;
/**
* /register.html GET
* @param model
* @param session HttpSession
* @return
*/
@RequestMapping(value = "/register.html", method = RequestMethod.GET)
public ModelAndView register(ModelAndView model, HttpSession session) {
model.setViewName("register");
return model;
}
/**
* /checkUsername.html GET
* @param username
* @return
*/
@RequestMapping(value = "/checkUsername.html", method = RequestMethod.GET)
@ResponseBody
public Result checkUsername(String username) {
return iMemberService.checkUsername(username);
}
/**
* /checkMobile.html GET
* @param mobile
* @return
*/
@RequestMapping(value = "/checkMobile.html", method = RequestMethod.GET)
@ResponseBody
public Result checkMobile(String mobile) {
return iMemberService.checkMobile(mobile);
}
/**
* /subRegister POST
* @param member
* @param session HttpSession
* @return
*/
@RequestMapping(value = "/subRegister", method = RequestMethod.POST)
@ResponseBody
public Result subRegister(@RequestBody MemberEntity member, HttpSession session) {
Result result = iMemberService.register(member);
if (result.getCode() == 200) {
// 获取 Shiro 主体
Subject subject = ShiroUtils.getSubject();
// 获取注册成功的会员实体对象
MemberEntity memberEntity = (MemberEntity) result.getResult();
// 创建用户名密码令牌
UsernamePasswordToken token = new UsernamePasswordToken(memberEntity.getUsername(), member.getPassword());
try {
// 主体登录
subject.login(token);
// 设置当前会员到会话中
session.setAttribute("currMember", ShiroUtils.getMember());
} catch (UnknownAccountException e) {
return Result.result(201, null, "用户名或密码有误,请重新输入或找回密码");
@ -65,5 +98,4 @@ public class RegisterController {
}
return result;
}
}

@ -10,21 +10,34 @@ import com.aliyuncs.exceptions.ClientException;
import com.tamguo.common.utils.Result;
import com.tamguo.modules.sys.service.ISmsService;
/**
* SmsController
*/
@Controller
public class SmsController {
/**
* ISmsService
*/
@Autowired
ISmsService iSmsService;
private ISmsService iSmsService;
/**
* /sendFindPasswordSms GET
* @param mobile
* @return
*/
@RequestMapping(value = {"sendFindPasswordSms"}, method = RequestMethod.GET)
@ResponseBody
public Result sendFindPasswordSms(String mobile) {
try {
// 调用 ISmsService 发送找回密码短信,并返回结果
return iSmsService.sendFindPasswordSms(mobile);
} catch (ClientException e) {
// 打印异常信息
e.printStackTrace();
}
// 返回错误结果
return Result.result(500, null, "");
}
}

@ -1,55 +1,59 @@
package com.tamguo.web.interceptor;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import java.net.URLEncoder; // 导入用于编码的类
import javax.servlet.http.HttpServletRequest; // 导入 Http 请求类
import javax.servlet.http.HttpServletResponse; // 导入 Http 响应类
import org.springframework.stereotype.Component; // 标记为组件
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; // 继承的拦截器适配器类
/**
* MemberInterceptor
*/
@Component
public class MemberInterceptor extends HandlerInterceptorAdapter{
public class MemberInterceptor extends HandlerInterceptorAdapter { // 继承自拦截器适配器
/** "重定向 URL"参数名称 */
private static final String REDIRECT_URL_PARAMETER_NAME = "redirectUrl";
private static final String REDIRECT_URL_PARAMETER_NAME = "redirectUrl"; // 定义重定向 URL 参数名称
/** 默认登录 URL */
private static final String DEFAULT_LOGIN_URL = "/login.html";
private static final String DEFAULT_LOGIN_URL = "/login.html"; // 定义默认登录 URL
/** 登录 URL */
private String loginUrl = DEFAULT_LOGIN_URL;
private String loginUrl = DEFAULT_LOGIN_URL; // 定义登录 URL
/**
*
*
* @param request
* HttpServletRequest
* @param response
* HttpServletResponse
* @param handler
*
* @param request HttpServletRequest
* @param response HttpServletResponse
* @param handler
* @return
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Object currMember = request.getSession().getAttribute("currMember");
if (currMember != null) {
return true;
} else {
String requestType = request.getHeader("X-Requested-With");
if (requestType != null && requestType.equalsIgnoreCase("XMLHttpRequest")) {
response.addHeader("loginStatus", "accessDenied");
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return false;
} else {
if (request.getMethod().equalsIgnoreCase("GET")) {
String redirectUrl = request.getQueryString() != null ? request.getRequestURI() + "?" + request.getQueryString() : request.getRequestURI();
response.sendRedirect(request.getContextPath() + loginUrl + "?" + REDIRECT_URL_PARAMETER_NAME + "=" + URLEncoder.encode(redirectUrl, "UTF-8"));
} else {
response.sendRedirect(request.getContextPath() + loginUrl);
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { // 重写预处理方法
Object currMember = request.getSession().getAttribute("currMember"); // 获取当前会话中的会员对象
if (currMember!= null) { // 如果会员对象不为空
return true; // 返回 true继续执行
} else { // 否则
String requestType = request.getHeader("X-Requested-With"); // 获取请求头中的"X-Requested-With"
if (requestType!= null && requestType.equalsIgnoreCase("XMLHttpRequest")) { // 如果是 XMLHttpRequest 请求
response.addHeader("loginStatus", "accessDenied"); // 在响应头中添加登录状态
response.sendError(HttpServletResponse.SC_FORBIDDEN); // 发送禁止访问错误
return false; // 返回 false停止执行
} else { // 否则
if (request.getMethod().equalsIgnoreCase("GET")) { // 如果是 GET 请求
String redirectUrl = request.getQueryString()!= null? request.getRequestURI() + "?" + request.getQueryString() : request.getRequestURI(); // 获取重定向 URL
response.sendRedirect(request.getContextPath() + loginUrl + "?" + REDIRECT_URL_PARAMETER_NAME + "=" + URLEncoder.encode(redirectUrl, "UTF-8")); // 发送重定向响应
} else { // 如果是其他请求
response.sendRedirect(request.getContextPath() + loginUrl); // 发送重定向响应
}
return false;
return false; // 返回 false停止执行
}
}
}
}

@ -18,15 +18,19 @@ import redis.clients.jedis.ShardedJedis;
*/
@Service("cacheService")
public class CacheService {
// 定义 Redis 键的前缀
private final static String REDIS_PRE_KEY = "TAMGUO:";
// 创建对象序列化工具
private SerializeTranscoder objectSerialize = new ObjectUtil();
@Autowired
private RedisXMLConfigure redisXMLConfigure;
/**
*
*
* @Title: get @Description: @param @return String @throws
* @param key
* @return
*/
public String get(String key) {
key = getPreKey(key);
@ -40,8 +44,10 @@ public class CacheService {
}
/**
*
*
* @Title: set @Description: @param @return void @throws
* @param key
* @param value
*/
public void set(String key, String value) {
key = getPreKey(key);
@ -55,16 +61,11 @@ public class CacheService {
}
/**
*
*
* set
*
* @param key
* @param value
* @param time
*
* @description
* @exception @since
* 1.0.0
* @param key
* @param value
* @param time
*/
public void set(String key, String value, int time) {
key = getPreKey(key);
@ -79,10 +80,10 @@ public class CacheService {
}
/**
* redis
* Redis
*
* @param key key
* @param value
* @param key
* @param value
*/
public void setObject(String key, Object value) {
key = getPreKey(key);
@ -98,11 +99,11 @@ public class CacheService {
}
/**
*
* Redis
*
* @param key key
* @param value
* @param time
* @param key
* @param value
* @param time
*/
public void setObject(String key, Object value, int time) {
key = getPreKey(key);
@ -118,10 +119,10 @@ public class CacheService {
}
/**
*
* Redis
*
* @param key key
* @return
* @param key
* @return
*/
public Object getObject(String key) {
key = getPreKey(key);
@ -141,10 +142,10 @@ public class CacheService {
}
/**
*
* Redis
*
* @param key key
* @return
* @param key
* @return
*/
public boolean deleteObject(String key) {
key = getPreKey(key);
@ -161,9 +162,10 @@ public class CacheService {
}
/**
*
*
* @Title: isExist @Description: key @param @return boolean
* @throws
* @param key
* @return
*/
public boolean isExist(String key) {
key = getPreKey(key);
@ -179,10 +181,22 @@ public class CacheService {
return false;
}
/**
*
*
* @param key
* @return
*/
public boolean notExist(String key) {
return!isExist(key);
}
/**
*
*
* @param key
* @return
*/
public boolean delete(String key) {
key = getPreKey(key);
ShardedJedis conn = null;
@ -198,11 +212,11 @@ public class CacheService {
}
/**
* redis list value key ()
*
*
* @param key
* @param value
* @return
* @param key
* @param value
* @return
*/
public long putToListEnd(String key, String value) {
key = getPreKey(key);
@ -217,28 +231,25 @@ public class CacheService {
}
/**
* valuekey,
*
*
* @author zhangxin
* @param key
* @param value
* @param seconds
* @param score
* @return long
* @param key
* @param value
* @param seconds
* @param score
* @return
*/
public long addToSortedSetAndExpire(String key, String value, int seconds, double score) {
return addToSortedSet(key, value, seconds, true, score);
}
/**
* valuekey valuescore
*
*
* @author zhangxin
* @param key
* @param value
* @param score
* @return long
* @param key
* @param value
* @param score
* @return
*/
public double addToSortedSetScore(String key, String value, double score) {
key = getPreKey(key);
@ -253,42 +264,23 @@ public class CacheService {
}
/**
* memberScore
* @param key
* @param value
* @return
*/
public Double getMemberScore(String key, String member) {
key = getPreKey(key);
ShardedJedis conn = null;
try {
conn = redisXMLConfigure.getConnection();
Double zscore = conn.zscore(key, member);
return zscore == null ? 0 : zscore;
} finally {
redisXMLConfigure.closeConnection(conn);
}
}
/**
* valuekey,
*
*
* @author zhangxin
* @param key
* @param value
* @param score
* @return long
* @param key
* @param value
* @param score
* @return
*/
public long addToSortedSet(String key, String value, double score) {
return addToSortedSet(key, value, -1, false, score);
}
/**
* member
*
*
* @return isExist true
* @param key
* @param member
* @return
*/
public boolean isExistSortedSet(String key, String member) {
key = getPreKey(key);
@ -303,9 +295,11 @@ public class CacheService {
}
/**
* member
*
*
* @return isExist true
* @param key
* @param member
* @return
*/
public boolean delSortedSetMember(String key, String[] member) {
key = getPreKey(key);
@ -320,9 +314,14 @@ public class CacheService {
}
/**
* valuekey, setExpirefalse, seconds
*
*
* @return
* @param key
* @param value
* @param seconds
* @param setExpire
* @param score
* @return
*/
private long addToSortedSet(String key, String value, int seconds, boolean setExpire, double score) {
key = getPreKey(key);
@ -340,14 +339,12 @@ public class CacheService {
}
/**
* score
*
*
* @author zhangxin
* @param key
* @param pageNo
* 1
* @param pageSize
* @return Set<String>
* @param key
* @param pageNo 1
* @param pageSize
* @return
*/
public Set<String> getSortedSetByPage(String key, int pageNo, int pageSize) {
key = getPreKey(key);
@ -370,6 +367,12 @@ public class CacheService {
return null;
}
/**
*
*
* @param key
* @return
*/
public List<String> getListHead(String key) {
key = getPreKey(key);
ShardedJedis conn = null;
@ -386,12 +389,12 @@ public class CacheService {
}
/**
* map
* Map Redis
*
* @param key
* @param field map field
* @param value map value
* @return if filed exist return 0 else return 1
* @param key
* @param field Map
* @param value Map
* @return 0 1
*/
public Long hset(String key, String field, String value) {
key = getPreKey(key);
@ -404,6 +407,13 @@ public class CacheService {
}
}
/**
* Map Redis
*
* @param key
* @param values Map
* @return
*/
public String hset(String key, Map<String, String> values) {
key = getPreKey(key);
ShardedJedis conn = null;
@ -415,6 +425,14 @@ public class CacheService {
}
}
/**
* Map Redis
*
* @param key
* @param values Map
* @param time
* @return
*/
public String hset(String key, Map<String, String> values, int time) {
key = getPreKey(key);
ShardedJedis conn = null;
@ -429,11 +447,11 @@ public class CacheService {
}
/**
* mapfield
* Map
*
* @param key
* @param field map field
* @return
* @param key
* @param field
* @return
*/
public String hget(String key, String field) {
key = getPreKey(key);
@ -447,10 +465,10 @@ public class CacheService {
}
/**
* keystring1
* key 1
*
* @param key
* @return
* @param key
* @return 1
*/
public Long decr(String key) {
key = getPreKey(key);
@ -464,10 +482,10 @@ public class CacheService {
}
/**
* keystring1
* key 1
*
* @param key
* @return
* @param key
* @return 1
*/
public Long incr(String key) {
key = getPreKey(key);
@ -480,6 +498,12 @@ public class CacheService {
}
}
/**
* 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;
}
}

@ -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 + "]";
}
}

@ -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 + "]";
}
}

@ -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");
}
logger.info("Redis XML config path:" + REDIS_PATH);
if (xmlConfiguration.readConfigFile(stream)) {
document = xmlConfiguration.getDocument();
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)) { // 如果成功读取 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<RedisServerNodeBean> rsnbs = initRedisServerNodeBeans();
//实现shardedJedisPool
initPreKey(); // 初始化 Redis 键的前缀
PoolConfigBean pcb = initPoolConfigBean(); // 初始化连接池配置对象
List<RedisServerNodeBean> rsnbs = initRedisServerNodeBeans(); // 初始化 Redis 服务器节点信息列表
// 创建 JedisPoolConfig 对象
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
//no maxActive config
// 设置最大空闲连接数
jedisPoolConfig.setMaxIdle(pcb.getMax_idle());
// 设置最大等待时间(毫秒)
jedisPoolConfig.setMaxWaitMillis(pcb.getMax_wait());
// 创建 ShardedJedisPool 对象
shardedJedisPool = new ShardedJedisPool(jedisPoolConfig, getJedisShardInfo(rsnbs));
if(shardedJedisPool == null){
throw new RuntimeException("config redis.xml error");
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;
}
/**
* redisserver
* Redis
* @return Redis
*/
private List<RedisServerNodeBean> initRedisServerNodeBeans() {
List<RedisServerNodeBean> redisServers = new ArrayList<RedisServerNodeBean>();
NodeList serverElements = document.getElementsByTagName("server");
int serverLen = serverElements.getLength();
if (serverLen < 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;
}
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
List<RedisServerNodeBean> redisServers = new ArrayList<RedisServerNodeBean>(); // 创建 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++) { // 遍历所有 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; // 身份验证密码
// 需要身份验证
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<JedisShardInfo> getJedisShardInfo(List<RedisServerNodeBean> 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<JedisShardInfo> servers = new ArrayList<JedisShardInfo>(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<JedisShardInfo> servers = new ArrayList<JedisShardInfo>(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;
}
/*
* rediskey
/**
* 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();
}
}

@ -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<BookCategoryEntity> {
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();
}
}

@ -10,31 +10,37 @@ 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<BookEntity> {
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<String> categoryIds;
private List<String> 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();

@ -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<DocumentEntity> {
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;
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;
private DocumentStatusEnum status; // 文档状态
@TableField(value="is_open")
private String isOpen;
private Date createDate;
private Date updateDate;
private String isOpen; // 是否公开
private Date createDate; // 创建日期
private Date updateDate; // 更新日期
private String content;
private String markdown;
// 定义关联字段
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<DocumentEntity> children;
private List<DocumentEntity> children; // 子文档列表
@TableField(exist=false)
private String cover;
private String cover; // 封面
@TableField(exist=false)
private List<FileUploadEntity> fileUploads;
private List<FileUploadEntity> fileUploads; // 文件上传列表
// 重写 pkVal 方法,返回 ID 作为主键值
@Override
protected Serializable pkVal() {
return getId();
}
}

@ -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 {
// 文件 ID
@TableId("file_id")
private String fileId;
// 文件 MD5 值
private String fileMd5;
// 文件路径
private String filePath;
// 文件类型
private String fileContentType;
// 文件扩展名
private String fileExtension;
// 文件大小(字节数)
private Long fileSize;
}

@ -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<FileUploadEntity> {
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 BizTypeEnum bizType;
// 文件上传状态
@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();
}
}

@ -1,30 +1,48 @@
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", "文档");
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;

@ -4,28 +4,51 @@ import java.io.Serializable;
import com.baomidou.mybatisplus.enums.IEnum;
/**
*
*
*/
public enum DocumentStatusEnum implements IEnum {
/**
*
*/
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;

@ -4,28 +4,51 @@ import java.io.Serializable;
import com.baomidou.mybatisplus.enums.IEnum;
/**
*
*
*/
public enum FileUploadStatusEnum implements IEnum {
/**
*
*/
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;

@ -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<BookMapper, BookEntity> 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);
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);
this.updateById(book); // 执行更新操作
}
}
}

@ -12,13 +12,22 @@ 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<DocumentMapper, DocumentEntity> implements IDocumentService {
/**
*
*
* @param document
*/
@Transactional(readOnly = false)
@Override
public void modify(DocumentEntity document) {
DocumentEntity entity = this.selectById(document.getId());
DocumentEntity entity = this.selectById(document.getId()); // 根据 ID 获取文档实体
if ("yes".equals(document.getCover())) {
// 覆盖修改
entity.setContent(document.getContent());
@ -35,28 +44,33 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, DocumentEnt
this.updateById(entity);
// 新增历史
document.setId(null);
document.setContent(content);
document.setMarkdown(markdown);
document.setBookId(entity.getBookId());
document.setCreateDate(new Date());
document.setIsOpen(entity.getIsOpen());
document.setName(entity.getName());
document.setOwner(entity.getOwner());
document.setParentId(entity.getParentId());
document.setUpdateDate(new Date());
document.setStatus(DocumentStatusEnum.HISTORY);
document.setBatchNo(entity.getBatchNo());
Document.setId(null);
Document.setContent(content);
Document.setMarkdown(markdown);
Document.setBookId(entity.getBookId());
Document.setCreateDate(new Date());
Document.setIsOpen(entity.getIsOpen());
Document.setName(entity.getName());
Document.setOwner(entity.getOwner());
Document.setParentId(entity.getParentId());
Document.setUpdateDate(new Date());
Document.setStatus(DocumentStatusEnum.HISTORY);
Document.setBatchNo(entity.getBatchNo());
this.insert(document);
}
}
/**
*
*
* @param document
*/
@SuppressWarnings("static-access")
@Transactional(readOnly = false)
@Override
public void create(DocumentEntity document) {
if (StringUtils.isEmpty(document.getId())) {
// 如果文档 ID 为空
document.setStatus(DocumentStatusEnum.NORMAL);
document.setCreateDate(new Date());
document.setUpdateDate(new Date());
@ -70,5 +84,4 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, DocumentEnt
this.updateById(entity);
}
}
}

@ -9,27 +9,44 @@ import com.baomidou.mybatisplus.annotations.TableName;
import com.tamguo.config.dao.SuperEntity;
import lombok.Data;
/**
* MemberEntity
*/
@Data
@TableName(value="t_member")
public class MemberEntity extends SuperEntity<MemberEntity> 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;
}

@ -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;
}
}

@ -239,10 +239,490 @@ public class MemberService extends ServiceImpl<MemberMapper, MemberEntity> imple
if(!entity.getPassword().equals(new Sha256Hash(member.getPassword()).toHex())) {
return Result.result(501, null, "旧密码错误!");
}
package com.tamguo.modules.member.service.impl;
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;
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<MemberMapper, MemberEntity> 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<MemberEntity> 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<MemberEntity> 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, "修改成功");
}
@ -250,14 +730,18 @@ public class MemberService extends ServiceImpl<MemberMapper, MemberEntity> imple
@Transactional(readOnly=true)
@Override
public Page<MemberEntity> listData(MemberCondition condition) {
// 创建分页对象
Page<MemberEntity> 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());
}
@ -268,13 +752,14 @@ public class MemberService extends ServiceImpl<MemberMapper, MemberEntity> imple
@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 {
@ -283,5 +768,3 @@ public class MemberService extends ServiceImpl<MemberMapper, MemberEntity> imple
e.printStackTrace();
}
}
}

@ -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")
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)
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)
private List<SysAreaEntity> children;
// 获取区域编码
public String getId() {
return areaCode;
}

@ -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")
@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)
private String treeAreaNames;
// 获取公司编码
public String getId() {
return companyCode;
}

@ -13,47 +13,78 @@ import com.baomidou.mybatisplus.enums.FieldFill;
import com.tamguo.modules.sys.model.enums.SysMenuStatusEnum;
import lombok.Data;
/**
* SysMenuEntity
*/
@Data
@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)
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;
}

@ -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")
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();
}
}

@ -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")
public class SysPostEntity extends Model<SysPostEntity> 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)
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();
}
}

@ -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")
public class SysUserEntity extends Model<SysUserEntity> 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)
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")
private String pwdQuestion2;
// 第三个密码问题
@TableField(value = "pwd_question_3")
private String pwdQuestion3;
// 密码问题答案
private String pwdQuestionAnswer;
// 第二个密码问题答案
@TableField(value = "pwd_question_answer_2")
private String pwdQuestionAnswer2;
// 第三个密码问题答案
@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)
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)
private SysUserTypeEnum userType;
// 用户权重
private BigDecimal userWeight;
// 微信 OpenID
private String wxOpenid;
// 英文名
private String userNameEn;
// 员工岗位列表(不存在数据库字段)
@TableField(exist = false)
private List<String> employeePosts;
// 用户角色字符串(不存在数据库字段)
@TableField(exist = false)
private String userRoleString;
// 用户数据范围列表 JSON 字符串(不存在数据库字段)
@TableField(exist = false)
private String userDataScopeListJson;
/**
* pkVal
* @return
*/
@Override
protected Serializable pkVal() {
return getUserCode();
}
}

@ -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;
}
}

@ -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<ChapterEntity> implements Serializable {
private static final long serialVersionUID = 1L;
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<ChapterEntity> childChapterList;
@JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString)
private ChapterStatusEnum status;
@TableName(value = "t_chapter") // 指定表名为 t_chapter
@Data // Lombok 的数据注解,自动生成 getter 和 setter 等方法
public class ChapterEntity extends SuperEntity<ChapterEntity> 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 描述
@TableField(exist = false) // 表示该字段在数据库中不存在
private List<ChapterEntity> childChapterList; // 子章节列表
@JSONField(serialzeFeatures = SerializerFeature.WriteEnumUsingToString) // 指定 JSON 序列化枚举时的特性
private ChapterStatusEnum status; // 章节状态枚举
}

@ -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")
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;
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 的数据注解
private String seoTitle;
private String seoKeywords;
private String seoDescription;
@Data // Lombok 的数据注解,自动生成 getter 和 setter 等方法
@TableName(value = "t_course") // 指定表名为 t_course
public class CourseEntity {
@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; // 图标
@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;
private String seoTitle; // SEO 标题
private String seoKeywords; // SEO 关键字
private String seoDescription; // SEO 描述
@JSONField(serialzeFeatures= SerializerFeature.WriteEnumUsingToString)
private CourseStatusEnum status;
@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; // 课程状态枚举
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -1,28 +1,66 @@
package com.tamguo.modules.tiku.model.enums;
import java.io.Serializable;
/**
* (1.2.; 3.)
*
* (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;
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;
@ -38,17 +76,28 @@ public enum QuestionTypeEnum {
return WENDATI;
}
/**
*
* @return
*/
public Serializable getValue() {
return this.value;
}
/**
*
* @return
*/
public String getDesc() {
return this.desc;
}
/**
*
* @return
*/
@Override
public String toString() {
return this.value;
}
}

@ -1,45 +1,54 @@
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
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<ChapterMapper, ChapterEntity> implements IChapterService {
@Autowired
ChapterMapper chapterMapper;
@Autowired
CourseMapper courseMapper;
@Autowired
KnowPointMapper bookMapper;
@Autowired // 自动注入 ChapterMapper 实例
private ChapterMapper chapterMapper;
@Autowired // 自动注入 CourseMapper 实例
private CourseMapper courseMapper;
@Autowired // 自动注入 KnowPointMapper 实例
private KnowPointMapper bookMapper;
@Transactional(readOnly=false)
@SuppressWarnings("unchecked")
/**
*
*
* @param bookId ID
* @return
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@SuppressWarnings("unchecked") // 抑制unchecked 警告
@Override
public List<ChapterEntity> findChapterTree(String bookId) {
// 根据书籍 ID 查询章节列表
List<ChapterEntity> chapterList = baseMapper.selectList(Condition.create().eq("book_id", bookId));
// 获取根chapter UID
// 获取根章节 UID
String rootUid = StringUtils.EMPTY;
for (int i = 0; i < chapterList.size(); i++) {
ChapterEntity chapter = chapterList.get(i);
@ -47,6 +56,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
rootUid = chapter.getId();
}
}
// 获取第一层结构
List<ChapterEntity> entitys = new ArrayList<>();
for (int i = 0; i < chapterList.size(); i++) {
@ -55,8 +65,10 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
entitys.add(chapter);
}
}
for (int i = 0; i < entitys.size(); i++) {
ChapterEntity entity = entitys.get(i);
// 获取子章节列表
List<ChapterEntity> childs = new ArrayList<>();
for (int k = 0; k < chapterList.size(); k++) {
ChapterEntity chapter = chapterList.get(k);
@ -66,10 +78,12 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
}
entity.setChildChapterList(childs);
}
for (int i = 0; i < entitys.size(); i++) {
List<ChapterEntity> childs = entitys.get(i).getChildChapterList();
for (int k = 0; k < childs.size(); k++) {
ChapterEntity child = childs.get(k);
// 获取子子章节列表
List<ChapterEntity> tmpChilds = new ArrayList<>();
for (int n = 0; n < chapterList.size(); n++) {
ChapterEntity chapter = chapterList.get(n);
@ -83,83 +97,98 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
return entitys;
}
@SuppressWarnings("unchecked")
/**
*
*
* @param condition
* @return
*/
@SuppressWarnings("unchecked") // 抑制 unchecked 警告
@Override
public List<ChapterEntity> listData(ChapterCondition condition) {
Condition query = Condition.create();
Condition query = Condition.create(); // 创建查询条件对象
if (!StringUtils.isEmpty(condition.getParentCode())) {
query.eq("parent_code", condition.getParentCode());
query.eq("parent_code", condition.getParentCode()); // 添加父章节代码条件
} else {
query.eq("tree_level", "0");
query.eq("tree_level", "0"); // 添加树级别为 0 的条件(即根章节)
}
if (!StringUtils.isEmpty(condition.getId())) {
query.eq("id", condition.getId());
query.eq("id", condition.getId()); // 添加章节 ID 条件
}
if (!StringUtils.isEmpty(condition.getName())) {
query.like("name", 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());;
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);
}
@SuppressWarnings("unchecked")
@Override
public JSONArray treeData(String courseId, String excludeId) {
List<ChapterEntity> 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);
return chapterMapper.selectList(query); // 执行查询并返回结果
}
/**
* ZTree JSON
*
* @param chapterList
* @return ZTree JSON
*/
private JSONArray turnZTreeData(List<ChapterEntity> chapterList) {
if (chapterList!= null) {
JSONArray nodes = new JSONArray();
JSONArray nodes = new JSONArray(); // 创建 JSON 数组对象
for (int i = 0; i < chapterList.size(); i++) {
JSONObject node = new JSONObject();
JSONObject node = new JSONObject(); // 创建 JSON 对象
ChapterEntity office = chapterList.get(i);
node.put("name", office.getName());
node.put("id", office.getId());
node.put("pId", office.getParentCode());
node.put("title", office.getName());
nodes.add(node);
ChapterEntity office = chapterList.get(i); // 获取章节实体
node.put("name", office.getName()); // 设置节点名称
node.put("id", office.getId()); // 设置节点 ID
node.put("pId", office.getParentCode()); // 设置父节点 ID
node.put("title", office.getName()); // 设置节点标题
nodes.add(node); // 将节点添加到 JSON 数组中
}
return nodes;
return nodes; // 返回 JSON 数组
}
return null;
return null; // 如果章节列表为空,则返回 null
}
@Transactional(readOnly=false)
/**
*
*
* @param chapter
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void save(ChapterEntity chapter) {
// 更新父章节的叶子节点状态为 false
ChapterEntity parentChapter = chapterMapper.selectById(chapter.getParentCode());
parentChapter.setTreeLeaf(false);
chapterMapper.updateById(parentChapter);
chapter.setStatus(ChapterStatusEnum.NORMAL);
chapter.setTreeLeaf(true);
chapter.setTreeLevel(parentChapter.getTreeLevel() + 1);
chapter.setBookId(parentChapter.getBookId());
chapterMapper.insert(chapter);
chapter.setStatus(ChapterStatusEnum.NORMAL); // 设置章节状态为正常
chapter.setTreeLeaf(true); // 设置章节为叶子节点
chapter.setTreeLevel(parentChapter.getTreeLevel() + 1); // 设置章节树级别
chapter.setBookId(parentChapter.getBookId()); // 设置章节所属书籍 ID
chapterMapper.insert(chapter); // 插入章节记录
// 更新章节的父章节代码列表
chapter.setParentCodes(parentChapter.getParentCodes() + chapter.getId() + ",");
chapterMapper.updateById(chapter);
}
@SuppressWarnings("unchecked")
@Transactional(readOnly=false)
/**
*
*
* @param chapter
*/
@SuppressWarnings("unchecked") // 抑制 unchecked 警告
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public void update(ChapterEntity chapter) {
ChapterEntity entity = chapterMapper.selectById(chapter.getId());
// 更新父章节的叶子节点状态为 false
ChapterEntity parentChapter = chapterMapper.selectById(chapter.getParentCode());
parentChapter.setTreeLeaf(false);
chapterMapper.updateById(parentChapter);
// 更新章节信息
ChapterEntity entity = chapterMapper.selectById(chapter.getId());
entity.setName(chapter.getName());
entity.setParentCode(chapter.getParentCode());
entity.setParentCodes(parentChapter.getParentCodes() + entity.getId() + ",");
@ -168,7 +197,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
entity.setOrders(chapter.getOrders());
entity.setTreeLevel(entity.getParentCodes().split(",").length - 1);
// 更新子集章节
// 更新子集章节的父章节代码列表和树级别
List<ChapterEntity> chapterList = chapterMapper.selectList(Condition.create().like("parent_codes", entity.getId()));
for (int i = 0; i < chapterList.size(); i++) {
ChapterEntity child = chapterList.get(i);
@ -181,13 +210,20 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
chapterMapper.updateById(entity);
}
@Transactional(readOnly=false)
@SuppressWarnings("unchecked")
/**
*
*
* @param id ID
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@SuppressWarnings("unchecked") // 抑制 unchecked 警告
@Override
public void delete(String id) {
// 更新章节状态为已删除
ChapterEntity chapter = chapterMapper.selectById(id);
chapter.setStatus(ChapterStatusEnum.DELETE);
chapterMapper.updateById(chapter);
// 删除子章节
List<ChapterEntity> childs = chapterMapper.selectList(Condition.create().like("parent_codes", id));
for (int i = 0; i < childs.size(); i++) {
@ -197,24 +233,41 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, ChapterEntity
}
}
@Transactional(readOnly=true)
@SuppressWarnings("unchecked")
/**
* ID
*
* @param courseId ID
* @return
*/
@Transactional(readOnly = true) // 开启事务,设置只读为 true
@SuppressWarnings("unchecked") // 抑制 unchecked 警告
@Override
public List<ChapterEntity> findCourseChapter(String courseId) {
// 根据课程 ID 查询知识关键点列表
List<KnowPointEntity> bookList = bookMapper.selectList(Condition.create().eq("course_id", courseId));
if (bookList.size() == 0) {
return null;
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<ChapterEntity> 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);
return chapterMapper.selectNextChapter(parentCode, id); // 查询下一个章节
}
}

@ -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
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<CourseMapper, CourseEntity> implements ICourseService {
@Autowired
public CourseMapper courseMapper;
@Autowired
public SubjectMapper subjectMapper;
@Autowired // 自动注入 CourseMapper 实例
private CourseMapper courseMapper;
@SuppressWarnings("unchecked")
@Transactional(readOnly=true)
@Autowired // 自动注入 SubjectMapper 实例
private SubjectMapper subjectMapper;
/**
*
*
* @param condition
* @return
*/
@SuppressWarnings("unchecked") // 抑制unchecked 警告
@Transactional(readOnly = true) // 开启事务,设置只读为 true
@Override
public Page<CourseEntity> listData(CourseCondition condition) {
Page<CourseEntity> page = new Page<>(condition.getPageNo() , condition.getPageSize());
Condition query = Condition.create();
Page<CourseEntity> page = new Page<>(condition.getPageNo(), condition.getPageSize()); // 创建分页对象
Condition query = Condition.create(); // 创建查询条件对象
if (!StringUtils.isEmpty(condition.getId())) {
query.eq("id", condition.getId());
query.eq("id", condition.getId()); // 添加课程 ID 条件
}
if (!StringUtils.isEmpty(condition.getName())) {
query.like("name", condition.getName());
query.like("name", condition.getName()); // 添加课程名称模糊匹配条件
}
if (!StringUtils.isEmpty(condition.getSubjectId())) {
query.eq("subject_id", condition.getSubjectId());
query.eq("subject_id", condition.getSubjectId()); // 添加科目 ID 条件
}
if (!StringUtils.isEmpty(condition.getStatus())) {
query.eq("status", 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<SubjectEntity> subjectList = subjectMapper.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue()));
List<CourseEntity> courseList = courseMapper.selectList(Condition.create().eq("status", CourseStatusEnum.NORMAL.getValue()));
return transform(subjectList, courseList);
List<SubjectEntity> subjectList = subjectMapper.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue())); // 查询正常状态的科目列表
List<CourseEntity> courseList = courseMapper.selectList(Condition.create().eq("status", CourseStatusEnum.NORMAL.getValue())); // 查询正常状态的课程列表
return transform(subjectList, courseList); // 转换科目和课程数据为 JSON 数组
}
/**
* ZTree JSON
*
* @param subjectList
* @param courseList
* @return ZTree JSON
*/
private JSONArray transform(List<SubjectEntity> subjectList, List<CourseEntity> courseList) {
JSONArray entitys = new JSONArray();
JSONArray entitys = new JSONArray(); // 创建 JSON 数组对象
for (int i = 0; i < subjectList.size(); i++) {
JSONObject entity = new JSONObject();
entity.put("id", subjectList.get(i).getId());
entity.put("name", subjectList.get(i).getName());
entity.put("pId", "0");
entitys.add(entity);
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 < courseList.size(); i++) {
JSONObject entity = new JSONObject();
entity.put("id", courseList.get(i).getId());
entity.put("name", courseList.get(i).getName());
entity.put("pId", courseList.get(i).getSubjectId());
entitys.add(entity);
}
return entitys;
}
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 数组
}
}

@ -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
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<KnowPointMapper, KnowPointEntity> implements IKnowPointService {
@Autowired
KnowPointMapper knowPointMapper;
@Autowired
CourseMapper courseMapper;
@Autowired
SubjectMapper subjectMapper;
@Autowired // 自动注入 KnowPointMapper 实例
private KnowPointMapper knowPointMapper;
@Transactional(readOnly=false)
@Autowired // 自动注入 CourseMapper 实例
private CourseMapper courseMapper;
@Autowired // 自动注入 SubjectMapper 实例
private SubjectMapper subjectMapper;
/**
*
*
* @param condition
* @return
*/
@Transactional(readOnly = false) // 开启事务,设置只读为 false
@Override
public Page<KnowPointEntity> listData(BookCondition condition) {
Page<KnowPointEntity> page = new Page<>(condition.getPageNo() , condition.getPageSize());
return page.setRecords(knowPointMapper.listData(page, condition));
Page<KnowPointEntity> 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());
CourseEntity course = courseMapper.selectById(book.getCourseId()); // 获取课程实体
book.setStatus(BookStatusEnum.NORMAL);
book.setSubjectId(course.getSubjectId());
knowPointMapper.insert(book);
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<SubjectEntity> subjectList = subjectMapper.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue()));
List<CourseEntity> courseList = courseMapper.selectList(Condition.create().eq("status", CourseStatusEnum.NORMAL.getValue()));
List<KnowPointEntity> bookList = knowPointMapper.selectList(Condition.create().eq("status", BookStatusEnum.NORMAL.getValue()));
return transform(subjectList, courseList , bookList);
List<SubjectEntity> subjectList = subjectMapper.selectList(Condition.create().eq("status", SubjectStatusEnum.NORMAL.getValue())); // 查询正常状态的科目列表
List<CourseEntity> courseList = courseMapper.selectList(Condition.create().eq("status", CourseStatusEnum.NORMAL.getValue())); // 查询正常状态的课程列表
List<KnowPointEntity> bookList = knowPointMapper.selectList(Condition.create().eq("status", BookStatusEnum.NORMAL.getValue())); // 查询正常状态的知识点列表
return transform(subjectList, courseList, bookList); // 转换科目、课程和知识点数据为 JSON 数组
}
/**
* ZTree JSON
*
* @param subjectList
* @param courseList
* @param bookList
* @return ZTree JSON
*/
private JSONArray transform(List<SubjectEntity> subjectList, List<CourseEntity> courseList, List<KnowPointEntity> bookList) {
JSONArray entitys = new JSONArray();
JSONArray entitys = new JSONArray(); // 创建 JSON 数组对象
for (int i = 0; i < subjectList.size(); i++) {
JSONObject entity = new JSONObject();
entity.put("id", subjectList.get(i).getId());
entity.put("name", subjectList.get(i).getName());
entity.put("pId", "0");
entitys.add(entity);
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 < courseList.size(); i++) {
JSONObject entity = new JSONObject();
entity.put("id", courseList.get(i).getId());
entity.put("name", courseList.get(i).getName());
entity.put("pId", courseList.get(i).getSubjectId());
entitys.add(entity);
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 数组中
}
for (int i = 0; i < bookList.size(); i++) {
JSONObject entity = new JSONObject();
entity.put("id", bookList.get(i).getId());
entity.put("name", bookList.get(i).getName());
entity.put("pId", bookList.get(i).getCourseId());
entitys.add(entity);
JSONObject entity = new JSONObject(); // 创建 JSON 对象
KnowPointEntity book = bookList.get(i); // 获取知识点实体
entity.put("id", book.getId()); // 设置知识点 ID
entity.put("name", book.getName()); // 设置知识点名称
entity.put("pId", book.getCourseId()); // 设置父节点 ID 为知识点所属课程 ID
entitys.add(entity); // 将知识点对象添加到 JSON 数组中
}
return entitys;
return entitys; // 返回转换后的 JSON 数组
}
}

@ -2,6 +2,7 @@ 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;
@ -13,14 +14,28 @@ import com.tamguo.modules.tiku.dao.MenuMapper;
import com.tamguo.modules.tiku.model.MenuEntity;
import com.tamguo.modules.tiku.service.IMenuService;
/**
* MenuServiceImpl IMenuService
*/
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> implements IMenuService {
/**
* MenuMapper
*/
@Autowired
private MenuMapper menuMapper;
/**
*
*/
@Autowired
private CacheService cacheService;
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findMenus() {
@ -36,6 +51,10 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> impleme
return menuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findAllMenus() {
@ -51,6 +70,10 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> impleme
return allMenuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findLeftMenus() {
@ -66,7 +89,10 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> impleme
return leftMenuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findChapterMenus() {
@ -82,7 +108,10 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> impleme
return chapterMenuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> findFooterMenus() {
@ -98,15 +127,23 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, MenuEntity> impleme
return footerMenuList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<MenuEntity> getMenuTree() {
return menuMapper.selectList(Condition.EMPTY);
}
/**
* ID
* @param uid ID
* @return
*/
@Override
public MenuEntity findById(String uid) {
return menuMapper.selectById(uid);
}
}

@ -27,24 +27,58 @@ 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<PaperMapper, PaperEntity> 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<PaperEntity> findHistoryPaper() {
@ -63,6 +97,10 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
return paperList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<PaperEntity> findSimulationPaper() {
@ -81,6 +119,11 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
return paperList;
}
/**
*
* @param areaId ID
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<PaperEntity> findHotPaper(String areaId) {
@ -99,6 +142,13 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
return paperList;
}
/**
*
* @param paperId ID
* @param title
* @param name
* @param type
*/
@Transactional(readOnly = false)
@Override
public void addPaperQuestionInfo(String paperId, String title, String name, String type) {
@ -117,6 +167,14 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
paperMapper.updateById(paper);
}
/**
*
* @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) {
@ -135,9 +193,15 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
paperMapper.updateById(paper);
}
/**
*
* @param currMemberId ID
* @param paperId ID
* @return
*/
@SuppressWarnings("unchecked")
@Override
public Result deletePaper(String currMemberId , String paperId) {
public Result deletePaper(String CurrMemberId, String paperId) {
PaperEntity paper = paperMapper.selectById(paperId);
if (!currMemberId.equals(paper.getCreaterId())) {
return Result.result(501, null, "不能删除其他人的试卷!");
@ -148,9 +212,16 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
return Result.result(Result.SUCCESS_CODE, null, "删除成功!");
}
/**
*
* @param CurrMemberId ID
* @param paperId ID
* @param cuid ID
* @return
*/
@Transactional(readOnly = false)
@Override
public Result deletePaperQuestionInfoBtn(String currMemberId , String paperId, String cuid) {
public Result deletePaperQuestionInfoBtn(String CurrMemberId, String paperId, String cuid) {
PaperEntity paper = paperMapper.selectById(paperId);
if (!paper.getCreaterId().equals(currMemberId)) {
return Result.failResult("试卷属于当前用户,不能修改!");
@ -167,6 +238,10 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
return Result.result(Result.SUCCESS_CODE, null, "删除子卷成功");
}
/**
*
* @param paper
*/
@Transactional(readOnly = false)
@Override
public void addPaper(PaperEntity paper) {
@ -181,8 +256,14 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
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)) {
return Result.failResult("试卷属于当前用户,不能修改!");
@ -192,6 +273,11 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
return Result.result(Result.SUCCESS_CODE, paper, "修改成功");
}
/**
*
* @param paperId ID
* @return
*/
@Override
public List<QuestionEntity> findQuestionList(String paperId) {
// 查询选项信息
@ -202,5 +288,4 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> impl
});
return questionList;
}
}

@ -15,66 +15,135 @@ 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<QuestionMapper, QuestionEntity> implements IQuestionService {
// 自动注入PaperMapper用于操作试卷Paper相关的数据比如通过试卷ID查询试卷信息等操作在题目相关业务逻辑中可能需要获取试卷的创建者等信息来进行权限判断等操作依赖该Mapper与数据库的试卷表进行交互。
@Autowired
private PaperMapper paperMapper;
// 自动注入QuestionMapper用于操作题目Question相关的数据比如插入题目、根据条件查询题目、更新题目以及删除题目等数据库操作是实现题目业务逻辑中与数据库进行交互的核心依赖对象直接对应数据库中的题目表。
@Autowired
private QuestionMapper questionMapper;
/**
*
* ID
* ID
*
* @param question ID
* @param currMemberId IDID
* @return Result0501
*/
@Override
public Result addQuestion(QuestionEntity question, String currMemberId) {
// 根据题目实体对象中携带的试卷ID通过PaperMapper从数据库中查询对应的试卷实体信息用于后续判断当前用户对该试卷是否有操作权限即是否为试卷创建者
PaperEntity paper = paperMapper.selectById(question.getPaperId().toString());
// 判断当前登录会员的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, "添加成功!");
}
/**
*
* IDIDID
* IDID
* MyBatis Plus
*
* @param questionType
* @param id IDIDID便ID
* @param content LIKE
* @param paperId IDIDIDID
* @param currMemberId IDID访
* @param p 便
* @return Page<QuestionEntity>p.setRecords(null)
*/
@SuppressWarnings("unchecked")
@Override
public Page<QuestionEntity> queryQuestionList(String questionType, String id, String content, String paperId, String currMemberId,
Page<QuestionEntity> p) {
// 根据传入的试卷ID从数据库中查询对应的试卷实体信息然后判断当前登录会员的ID与查询到的试卷创建者的ID是否相等如果不相等表示当前用户无权查询该试卷下的题目直接返回传入的分页对象并将其记录列表设置为空表示无权获取题目数据。
if (!currMemberId.equals(paperMapper.selectById(paperId).getCreaterId())) {
return p.setRecords(null);
}
// 创建一个MyBatis Plus的查询条件对象用于构建后续查询题目时的各种条件通过该对象可以方便地添加等于、大于、小于、模糊匹配等各种条件来精确筛选题目数据符合MyBatis Plus的条件查询规范。
Condition condition = new Condition();
// 判断题目类型是否不为空字符串如果不为空则添加一个等于eq条件到查询条件对象中使得查询时只会获取指定题目类型的题目与数据库题目表中的题目类型字段进行精确匹配查询。
if (!StringUtils.isEmpty(questionType)) {
condition.eq("question_type", questionType);
}
// 判断题目ID是否不为空字符串如果不为空则添加一个等于eq条件到查询条件对象中使得查询时只会获取指定ID的题目与数据库题目表中的题目ID字段进行精确匹配查询用于精确查找特定题目。
if (!StringUtils.isEmpty(id)) {
condition.eq("id", id);
}
// 判断题目内容是否不为空字符串如果不为空则添加一个模糊匹配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));
}
/**
*
* ID
* QuestionMapperID
* 使
*
* @param question ID
* @param currMemberId IDID
* @return Result0501
*/
@Transactional(readOnly = false)
@Override
public Result updateQuestion(QuestionEntity question, String currMemberId) {
// 根据题目实体对象中携带的试卷ID通过PaperMapper从数据库中查询对应的试卷实体信息用于后续判断当前用户对该试卷是否有操作权限即是否为试卷创建者
PaperEntity paper = paperMapper.selectById(question.getPaperId().toString());
// 判断当前登录会员的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, "修改成功!");
}
/**
*
* IDID
* QuestionMapperID
* 使
*
* @param uid IDID
* @param currMemberId IDID
* @return Result0501
*/
@Transactional(readOnly = false)
@Override
public Result delete(String uid, String currMemberId) {
// 根据传入的题目ID通过QuestionMapper从数据库中查询对应的题目实体信息用于获取该题目所属试卷的ID以便后续判断当前用户对该试卷是否有操作权限即是否为试卷创建者
QuestionEntity question = questionMapper.selectById(uid);
// 根据题目所属试卷的ID通过PaperMapper从数据库中查询对应的试卷实体信息用于后续判断当前用户对该试卷是否有操作权限即是否为试卷创建者
PaperEntity paper = paperMapper.selectById(question.getPaperId().toString());
// 判断当前登录会员的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, "删除成功!");
}

@ -19,16 +19,35 @@ 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<SchoolMapper, SchoolEntity> implements ISchoolService {
public class SchoolServiceImpl extends ServiceImpl<SchoolMapper, SchoolEntity> 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<SchoolEntity> findEliteSchoolPaper(String shcoolId) {
@ -47,6 +66,10 @@ public class SchoolService extends ServiceImpl<SchoolMapper, SchoolEntity> imple
return schoolList;
}
/**
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<SchoolEntity> findEliteSchool() {
@ -59,11 +82,15 @@ public class SchoolService extends ServiceImpl<SchoolMapper, SchoolEntity> imple
return schoolList;
}
/**
* ID
* @param areaId ID
* @return
*/
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
@Override
public List<SchoolEntity> findSchoolByAreaId(String areaId) {
return schoolMapper.selectList(Condition.create().in("area_id", Arrays.asList(areaId.split(","))));
}
}

@ -19,14 +19,29 @@ 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<SubjectMapper, SubjectEntity> implements ISubjectService {
/**
* SubjectMapper
*/
@Autowired
private SubjectMapper subjectMapper;
/**
* CourseMapper
*/
@Autowired
private CourseMapper courseMapper;
/**
*
* @param condition
* @return
*/
@Transactional(readOnly = false)
@SuppressWarnings("unchecked")
@Override
@ -44,6 +59,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
return page.setRecords(subjectMapper.selectPage(page, query));
}
/**
*
* @param subject
*/
@Transactional(readOnly = false)
@Override
public void save(SubjectEntity subject) {
@ -51,6 +70,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.insert(subject);
}
/**
*
* @param subject
*/
@Transactional(readOnly = false)
@Override
public void update(SubjectEntity subject) {
@ -64,6 +87,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.updateById(entity);
}
/**
*
* @param uid
*/
@Transactional(readOnly = false)
@Override
public void enable(String uid) {
@ -72,6 +99,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.updateById(entity);
}
/**
*
* @param uid
*/
@Transactional(readOnly = false)
@Override
public void disabled(String uid) {
@ -80,6 +111,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.updateById(entity);
}
/**
*
* @param uid
*/
@Transactional(readOnly = false)
@Override
public void delete(String uid) {
@ -88,6 +123,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
subjectMapper.updateById(entity);
}
/**
*
* @return JSON
*/
@SuppressWarnings("unchecked")
@Override
public JSONArray getCourseCascaderTree() {
@ -115,6 +154,10 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
return courseTree;
}
/**
*
* @return JSON
*/
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
@Override
@ -130,5 +173,4 @@ public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, SubjectEntity
}
return courseTree;
}
}
Loading…
Cancel
Save