From 3182b15c02ea27e1ee3235d2b501dfd00d52416a Mon Sep 17 00:00:00 2001 From: dw <2196435763@qq.com> Date: Sun, 27 Apr 2025 18:31:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=8F=98=E6=9B=B4=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/annotation/APPLoginUser.java | 32 -- src/main/java/com/annotation/ColumnInfo.java | 30 - src/main/java/com/annotation/IgnoreAuth.java | 21 - src/main/java/com/annotation/LoginUser.java | 28 - .../java/com/config/InterceptorConfig.java | 69 --- .../java/com/config/MyMetaObjectHandler.java | 47 -- .../java/com/config/MybatisPlusConfig.java | 35 -- .../java/com/controller/CommonController.java | 278 --------- .../java/com/controller/ConfigController.java | 102 ---- .../com/controller/DictionaryController.java | 287 ---------- .../java/com/controller/FileController.java | 161 ------ .../java/com/controller/ForumController.java | 321 ----------- .../JianshenkechengCollectionController.java | 296 ---------- .../controller/JianshenkechengController.java | 390 ------------- .../JianshenkechengLiuyanController.java | 286 ---------- .../com/controller/JiaolianController.java | 147 ----- .../controller/JiaolianYuyueController.java | 336 ----------- .../java/com/controller/NewsController.java | 316 ----------- .../com/controller/SingleSeachController.java | 299 ---------- .../java/com/controller/UsersController.java | 239 -------- .../java/com/controller/YonghuController.java | 533 ------------------ 21 files changed, 4253 deletions(-) diff --git a/src/main/java/com/annotation/APPLoginUser.java b/src/main/java/com/annotation/APPLoginUser.java index 51329cd..21d41b9 100644 --- a/src/main/java/com/annotation/APPLoginUser.java +++ b/src/main/java/com/annotation/APPLoginUser.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.annotation; import java.lang.annotation.ElementType; @@ -14,34 +13,3 @@ import java.lang.annotation.Target; public @interface APPLoginUser { } -======= -// 声明该代码文件所在的包名为 com.annotation -package com.annotation; - -// 导入 java.lang.annotation.ElementType 类,该类用于指定注解可以应用的目标元素类型, -// 例如类、方法、字段等,在定义注解时需要使用它来指定注解的作用目标 -import java.lang.annotation.ElementType; - -// 导入 java.lang.annotation.Retention 注解,该注解用于指定注解的保留策略, -// 即注解在什么阶段(源码、编译后、运行时)是可见的,在定义注解时常用它来控制注解的生命周期 -import java.lang.annotation.Retention; - -// 导入 java.lang.annotation.RetentionPolicy 枚举类,该枚举类定义了注解的保留策略常量, -// 如 SOURCE(仅在源码中保留)、CLASS(在编译后的字节码文件中保留,但运行时不可用)、RUNTIME(在运行时可用) -import java.lang.annotation.RetentionPolicy; - -// 导入 java.lang.annotation.Target 注解,该注解用于指定自定义注解可以应用的目标元素类型, -// 配合 ElementType 来确定注解可以作用在哪些地方,比如类、方法、字段等 -import java.lang.annotation.Target; - -// 登录用户信息 -// 自定义注解,用于标识需要注入当前登录用户信息的方法参数 -@Target(ElementType.PARAMETER) -// 指定该注解只能用于方法参数上 -@Retention(RetentionPolicy.RUNTIME) -// 指定该注解在运行时保留,可以通过反射读取 -public @interface APPLoginUser { - // 定义一个空注解,作为标记使用 - // 实际使用时可以配合拦截器或参数解析器,自动注入当前登录用户对象 -} ->>>>>>> develop diff --git a/src/main/java/com/annotation/ColumnInfo.java b/src/main/java/com/annotation/ColumnInfo.java index d2d79bf..d041578 100644 --- a/src/main/java/com/annotation/ColumnInfo.java +++ b/src/main/java/com/annotation/ColumnInfo.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.annotation; import java.lang.annotation.ElementType; @@ -12,32 +11,3 @@ public @interface ColumnInfo { String comment(); String type(); } -======= -// 定义该文件所在的包路径,将该 Java 类组织到 com.annotation 这个包空间下,方便项目的模块化管理和避免类名冲突 -package com.annotation; - -// 导入 Java 语言中用于表示注解可应用的目标元素类型的类,通过该类可以指定注解能作用于类、方法、字段等不同的程序元素 -import java.lang.annotation.ElementType; - -// 导入用于指定注解保留策略的注解,借助它可以控制注解在不同阶段的可见性 -import java.lang.annotation.Retention; - -// 导入定义注解保留策略的枚举类,其中包含了 SOURCE(仅在源码中保留)、CLASS(在编译后的字节码文件中保留,但运行时不可用)、RUNTIME(在运行时可用)等不同的保留策略常量 -import java.lang.annotation.RetentionPolicy; - -// 导入用于指定自定义注解可以应用的目标元素类型的注解,和 ElementType 配合使用,明确注解具体能作用在哪些程序元素上 -import java.lang.annotation.Target; - -// 指定该注解可以应用于字段(类的成员变量)上 -@Target(ElementType.FIELD) -// 指定该注解在运行时保留,可以通过反射读取 -@Retention(RetentionPolicy.RUNTIME) -// 定义一个名为ColumnInfo的注解 -public @interface ColumnInfo { - // 定义comment属性,表示字段的注释/描述 - String comment(); - - // 定义type属性,表示字段的类型 - String type(); -} ->>>>>>> develop diff --git a/src/main/java/com/annotation/IgnoreAuth.java b/src/main/java/com/annotation/IgnoreAuth.java index bd48726..7c3cc55 100644 --- a/src/main/java/com/annotation/IgnoreAuth.java +++ b/src/main/java/com/annotation/IgnoreAuth.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.annotation; import java.lang.annotation.*; @@ -12,23 +11,3 @@ import java.lang.annotation.*; public @interface IgnoreAuth { } -======= -// 定义该文件所在的包路径 -package com.annotation; - -// 导入注解相关的包 -import java.lang.annotation.*; - -// 忽略Token验证的注解 -// 被此注解标记的方法将跳过Token验证检查 -@Target(ElementType.METHOD) -// 指定该注解只能用于方法上 -@Retention(RetentionPolicy.RUNTIME) -// 指定该注解在运行时保留,可以通过反射读取 -@Documented -// 表示该注解应该被包含在JavaDoc中 -public @interface IgnoreAuth { - // 这是一个标记注解,不包含任何属性 - // 仅用于标识需要跳过Token验证的方法 -} ->>>>>>> develop diff --git a/src/main/java/com/annotation/LoginUser.java b/src/main/java/com/annotation/LoginUser.java index 8badabf..3d808d3 100644 --- a/src/main/java/com/annotation/LoginUser.java +++ b/src/main/java/com/annotation/LoginUser.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.annotation; import java.lang.annotation.ElementType; @@ -14,30 +13,3 @@ import java.lang.annotation.Target; public @interface LoginUser { } -======= -// 定义该文件所在的包路径,在 Java 里,包是组织类和接口的一种方式,此包路径为 com.annotation,能防止命名冲突,也便于代码的管理与维护 -package com.annotation; - -// 导入 java.lang.annotation.ElementType 类,它是一个枚举类型,包含了多种不同的元素类型,像类、方法、字段等,在定义注解时可借助它来指定注解的作用目标 -import java.lang.annotation.ElementType; - -// 导入 java.lang.annotation.Retention 注解,它用于指定注解的保留策略,也就是注解在不同阶段的存活时间和可见性 -import java.lang.annotation.Retention; - -// 导入 java.lang.annotation.RetentionPolicy 枚举类,它定义了三种保留策略,分别是 SOURCE(仅在源码中保留)、CLASS(在编译后的字节码文件中保留,但运行时不可用)、RUNTIME(在运行时也保留,可通过反射机制获取) -import java.lang.annotation.RetentionPolicy; - -// 导入 java.lang.annotation.Target 注解,它用于指定自定义注解可以应用的目标元素类型,与 ElementType 结合使用,能精确控制注解的使用范围 -import java.lang.annotation.Target; - -// 登录用户信息注解 -// 用于标识Controller方法中需要注入当前登录用户信息的参数 -@Target(ElementType.PARAMETER) -// 指定该注解只能用于方法参数上 -@Retention(RetentionPolicy.RUNTIME) -// 指定该注解在运行时保留,可以通过反射读取 -public @interface LoginUser { - // 这是一个标记注解,不包含任何属性 - // 用于标识需要自动注入当前登录用户信息的参数 -} ->>>>>>> develop diff --git a/src/main/java/com/config/InterceptorConfig.java b/src/main/java/com/config/InterceptorConfig.java index 767380d..586ccc5 100644 --- a/src/main/java/com/config/InterceptorConfig.java +++ b/src/main/java/com/config/InterceptorConfig.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.config; import org.springframework.context.annotation.Bean; @@ -38,71 +37,3 @@ public class InterceptorConfig extends WebMvcConfigurationSupport{ super.addResourceHandlers(registry); } } -======= -// 声明当前文件所在的包路径,在 Java 项目中,包用于组织代码结构,这里表示该文件属于 com.config 包,有助于模块化管理和避免命名冲突 -package com.config; - -// 导入 Spring 框架中用于定义 Bean 的注解类。使用 @Bean 注解可以将一个方法返回的对象注册为 Spring 容器中的 Bean,供其他组件使用 -import org.springframework.context.annotation.Bean; -// 导入 Spring 框架中用于标识配置类的注解类。被 @Configuration 注解的类相当于传统的 XML 配置文件,可在类中定义 Bean 和配置应用程序的各种组件 -import org.springframework.context.annotation.Configuration; -// 导入 Spring 框架中用于配置拦截器注册的接口类。通过实现该接口或继承相关支持类,可以向 Spring MVC 注册拦截器,控制请求的处理流程 -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -// 导入 Spring 框架中用于配置静态资源处理器的接口类。可以使用该类来配置如何映射和处理静态资源,如 CSS、JavaScript、图片等 -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -// 导入 Spring 框架中用于支持 Web MVC 配置的基类。继承该类可以对 Spring MVC 进行全面的配置,包括拦截器、静态资源、视图解析器等 -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; - -// 导入自定义的拦截器类,该拦截器类用于处理请求的授权逻辑,在请求到达控制器之前进行权限检查等操作 -import com.interceptor.AuthorizationInterceptor; - -// 拦截器配置类 -// 用于配置Spring MVC拦截器和静态资源处理 -@Configuration // 标识这是一个Spring配置类 -public class InterceptorConfig extends WebMvcConfigurationSupport { - - // 创建授权拦截器Bean - // @return AuthorizationInterceptor实例 - @Bean - public AuthorizationInterceptor getAuthorizationInterceptor() { - return new AuthorizationInterceptor(); - } - - // 配置拦截器规则 - // @param registry 拦截器注册器 - @Override - public void addInterceptors(InterceptorRegistry registry) { - // 注册授权拦截器并配置拦截规则 - registry.addInterceptor(getAuthorizationInterceptor()); - // 拦截所有请求路径 - registry.addPathPatterns("/**"); - // 排除静态资源路径 - registry.excludePathPatterns("/static/**"); - super.addInterceptors(registry); - } - - // 配置静态资源处理 - // 注意:在SpringBoot 2.0中自定义WebMvc配置会覆盖默认配置, - // 需要手动添加静态资源路径配置 - // @param registry 资源处理器注册器 - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - // 配置静态资源访问路径 - registry.addResourceHandler("/**"); - // 添加各类静态资源目录位置 - // resources目录 - registry.addResourceLocations("classpath:/resources/"); - // static目录 - registry.addResourceLocations("classpath:/static/"); - // admin目录 - registry.addResourceLocations("classpath:/admin/"); - // img目录 - registry.addResourceLocations("classpath:/img/"); - // front目录 - registry.addResourceLocations("classpath:/front/"); - // public目录 - registry.addResourceLocations("classpath:/public/"); - super.addResourceHandlers(registry); - } -} ->>>>>>> develop diff --git a/src/main/java/com/config/MyMetaObjectHandler.java b/src/main/java/com/config/MyMetaObjectHandler.java index ddff0c4..2f9e793 100644 --- a/src/main/java/com/config/MyMetaObjectHandler.java +++ b/src/main/java/com/config/MyMetaObjectHandler.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.config; import java.util.Date; @@ -27,49 +26,3 @@ public class MyMetaObjectHandler extends MetaObjectHandler { // 关闭更新填充、这里不执行 } } -======= -// 声明当前文件所在的包路径 -package com.config; - -// 导入日期类 -import java.util.Date; - -// 导入MyBatis反射工具类 -import org.apache.ibatis.reflection.MetaObject; - -// 导入MyBatis-Plus元对象处理器基类 -import com.baomidou.mybatisplus.mapper.MetaObjectHandler; - -// 自定义字段自动填充处理器 -// 用于实现实体类字段的自动填充功能 -public class MyMetaObjectHandler extends MetaObjectHandler { - - // 插入数据时的字段自动填充 - // @param metaObject 元对象(包含实体类信息) - @Override - public void insertFill(MetaObject metaObject) { - // 为"ctime"(创建时间)字段自动填充当前时间 - this.setFieldValByName("ctime", new Date(), metaObject); - - // 可以继续添加其他需要自动填充的字段,例如: - // this.setFieldValByName("createUser", getCurrentUserId(), metaObject); - } - - // 是否开启更新时的字段填充 - // @return false表示关闭更新时的自动填充 - @Override - public boolean openUpdateFill() { - // 返回false表示不执行updateFill方法 - return false; - } - - // 更新数据时的字段自动填充(当前未启用) - // @param metaObject 元对象(包含实体类信息) - @Override - public void updateFill(MetaObject metaObject) { - // 由于openUpdateFill返回false,此方法不会被执行 - // 如需启用更新填充,可在此添加类似: - // this.setFieldValByName("utime", new Date(), metaObject); - } -} ->>>>>>> develop diff --git a/src/main/java/com/config/MybatisPlusConfig.java b/src/main/java/com/config/MybatisPlusConfig.java index b7c58bb..ec2e84b 100644 --- a/src/main/java/com/config/MybatisPlusConfig.java +++ b/src/main/java/com/config/MybatisPlusConfig.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.config; @@ -23,37 +22,3 @@ public class MybatisPlusConfig { } } -======= -// 声明当前文件所在的包路径,在 Java 项目里,包用于组织和管理代码,此包路径为 com.config,有助于将相关的配置类集中管理,避免命名冲突 -package com.config; - -// 导入 Spring 框架中的 @Bean 注解,该注解用于在配置类中定义一个 Bean 方法。使用此注解的方法返回的对象会被注册到 Spring 容器中,供其他组件使用 -import org.springframework.context.annotation.Bean; -// 导入 Spring 框架中的 @Configuration 注解,它表明这个类是一个配置类,类似于传统的 XML 配置文件。Spring 会处理该类中的 @Bean 注解,将方法返回的对象注册到容器中 -import org.springframework.context.annotation.Configuration; - -// 导入 MyBatis-Plus 框架中的 MetaObjectHandler 类,它是一个元对象处理器接口。通过实现该接口,可以对实体对象中的公共字段(如创建时间、更新时间等)进行自动填充处理 -import com.baomidou.mybatisplus.mapper.MetaObjectHandler; -// 导入 MyBatis-Plus 框架中的 PaginationInterceptor 类,这是一个分页拦截器。使用该拦截器可以方便地实现数据库查询的分页功能,简化分页逻辑的编写 -import com.baomidou.mybatisplus.plugins.PaginationInterceptor; - -// MyBatis-Plus配置类 -// 用于配置MyBatis-Plus的相关插件和组件 -@Configuration // 标识这是一个Spring配置类 -public class MybatisPlusConfig { - - // 配置MyBatis-Plus分页插件 - // 该插件会自动处理分页逻辑,无需手动编写分页代码 - // @return PaginationInterceptor 分页拦截器实例 - @Bean - public PaginationInterceptor paginationInterceptor() { - // 创建并返回MyBatis-Plus的分页拦截器 - return new PaginationInterceptor(); - } - - // 可以继续添加其他MyBatis-Plus的配置,如: - // - 性能分析插件 - // - 乐观锁插件 - // - SQL注入器等 -} ->>>>>>> develop diff --git a/src/main/java/com/controller/CommonController.java b/src/main/java/com/controller/CommonController.java index 7008b5e..1b4c98f 100644 --- a/src/main/java/com/controller/CommonController.java +++ b/src/main/java/com/controller/CommonController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; import java.io.*; @@ -19,101 +18,35 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.ResourceUtils; -======= -// 声明当前文件所在的包路径 -package com.controller; - -// 导入输入输出相关类 -import java.io.*; -// 导入SQL相关类 -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -// 导入日期格式化类 -import java.text.SimpleDateFormat; -// 导入集合类 -import java.util.*; -// 导入Servlet请求类 -import javax.servlet.http.HttpServletRequest; - -// 导入FastJSON相关类 -import com.alibaba.fastjson.JSON; -// 导入字符串工具类 -import com.utils.StringUtil; -// 导入Apache Commons字符串工具 -import org.apache.commons.lang3.StringUtils; -// 导入JSON对象类 -import org.json.JSONObject; -// 导入日志相关类 -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -// 导入Spring框架相关注解和类 -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.util.ResourceUtils; -// 导入Spring MVC注解 ->>>>>>> develop import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -<<<<<<< HEAD -import com.annotation.IgnoreAuth; -import com.baidu.aip.face.AipFace; -import com.baidu.aip.face.MatchRequest; -import com.baidu.aip.util.Base64Util; -import com.baomidou.mybatisplus.mapper.EntityWrapper; -import com.baomidou.mybatisplus.mapper.Wrapper; -import com.entity.ConfigEntity; -import com.service.CommonService; -import com.service.ConfigService; -======= -// 导入自定义注解 import com.annotation.IgnoreAuth; -// 导入百度AI相关类 import com.baidu.aip.face.AipFace; import com.baidu.aip.face.MatchRequest; import com.baidu.aip.util.Base64Util; -// 导入MyBatis-Plus相关类 import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.Wrapper; -// 导入实体类 import com.entity.ConfigEntity; -// 导入服务类 import com.service.CommonService; import com.service.ConfigService; -// 导入工具类 ->>>>>>> develop import com.utils.BaiduUtil; import com.utils.FileUtil; import com.utils.R; -<<<<<<< HEAD /** * 通用接口 */ @RestController public class CommonController { private static final Logger logger = LoggerFactory.getLogger(CommonController.class); -======= - - //通用接口控制器 - //提供系统通用的各种功能接口 -@RestController // 标识这是一个RESTful风格的控制器 -public class CommonController { - // 日志记录器,使用slf4j的LoggerFactory创建 - private static final Logger logger = LoggerFactory.getLogger(CommonController.class); - - // 自动注入通用服务 ->>>>>>> develop @Autowired private CommonService commonService; -<<<<<<< HEAD /** * Java代码实现MySQL数据库导出 * @@ -156,70 +89,6 @@ public class CommonController { e.printStackTrace(); return R.error("备份数据出错"); } finally { -======= - // * MySQL数据库备份接口 - // * @param mysqlUrl MySQL安装路径 - // * @param hostIP 数据库服务器IP - // * @param userName 数据库用户名 - // * @param hostPort 数据库端口 - //* @param password 数据库密码 - //* @param savePath 备份文件保存路径 - //* @param fileName 备份文件名 - //* @param databaseName 要备份的数据库名 - //* @return 操作结果 - - @IgnoreAuth // 忽略权限验证 - @RequestMapping("/beifen") // 映射请求路径 - public R beifen(String mysqlUrl, String hostIP, String userName, String hostPort, - String password, String savePath, String fileName, String databaseName) { - // 创建保存目录文件对象 - File saveFile = new File(savePath); - // 检查目录是否存在 - if (!saveFile.exists()) { - // 不存在则创建多级目录 - saveFile.mkdirs(); - } - // 确保路径以分隔符结尾 - if (!savePath.endsWith(File.separator)) { - savePath = savePath + File.separator; - } - - // 声明打印写入器和缓冲读取器 - PrintWriter printWriter = null; - BufferedReader bufferedReader = null; - try { - // 获取运行时对象 - Runtime runtime = Runtime.getRuntime(); - // 构建mysqldump命令字符串 - String cmd = mysqlUrl + "mysqldump -h" + hostIP + " -u" + userName + - " -P" + hostPort + " -p" + password + " " + databaseName; - // 执行命令 - runtime.exec(cmd); - Process process = runtime.exec(cmd); - - // 创建输入流读取器,指定UTF-8编码 - InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream(), "utf8"); - // 创建缓冲读取器 - bufferedReader = new BufferedReader(inputStreamReader); - // 创建打印写入器,指定UTF-8编码 - printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(savePath + fileName), "utf8")); - - // 逐行读取备份数据 - String line; - while ((line = bufferedReader.readLine()) != null) { - // 写入备份文件 - printWriter.println(line); - } - // 刷新缓冲区 - printWriter.flush(); - } catch (Exception e) { - // 打印异常堆栈 - e.printStackTrace(); - // 返回错误信息 - return R.error("备份数据出错"); - } finally { - // 在finally块中确保资源关闭 ->>>>>>> develop try { if (bufferedReader != null) { bufferedReader.close(); @@ -231,7 +100,6 @@ public class CommonController { e.printStackTrace(); } } -<<<<<<< HEAD return R.ok(); } @@ -266,78 +134,17 @@ public class CommonController { writer.write(outStr); // 注:这里如果用缓冲方式写入文件的话,会导致中文乱码,用flush()方法则可以避免 writer.flush(); -======= - // 返回成功结果 - return R.ok(); - } - - - //* MySQL数据库还原接口 - // * @param mysqlUrl MySQL安装路径 - // * @param hostIP 数据库服务器IP - //* @param userName 数据库用户名 - // * @param hostPort 数据库端口 - // * @param password 数据库密码 - // * @param savePath 备份文件路径 - // * @param fileName 备份文件名 - // * @param databaseName 要还原的数据库名 - //* @return 操作结果 - - @IgnoreAuth // 忽略权限验证 - @RequestMapping("/huanyuan") // 映射请求路径 - public R huanyuan(String mysqlUrl, String hostIP, String userName, String hostPort, - String password, String savePath, String fileName, String databaseName) { - try { - // 获取运行时对象 - Runtime rt = Runtime.getRuntime(); - // 执行mysql命令 - Process child1 = rt.exec(mysqlUrl+"mysql.exe -h" + hostIP + " -u" + userName + - " -P" + hostPort + " -p" + password + " " + databaseName); - - // 获取进程的输出流 - OutputStream out = child1.getOutputStream(); - // 创建字符串缓冲区 - StringBuffer sb = new StringBuffer(); - // 创建缓冲读取器,读取备份文件 - BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(savePath+"/"+fileName), "utf-8")); - - // 逐行读取备份文件 - String inStr; - while ((inStr = br.readLine()) != null) { - // 将每行内容添加到缓冲区,并添加换行符 - sb.append(inStr + "\r\n"); - } - - // 创建输出流写入器 - OutputStreamWriter writer = new OutputStreamWriter(out, "utf8"); - // 写入备份数据 - writer.write(sb.toString()); - // 刷新缓冲区 - writer.flush(); - - // 关闭资源 ->>>>>>> develop out.close(); br.close(); writer.close(); } catch (Exception e) { -<<<<<<< HEAD e.printStackTrace(); return R.error("数据导入出错"); } -======= - // 打印异常堆栈 - e.printStackTrace(); - // 返回错误信息 - return R.error("数据导入出错"); - } - // 返回成功结果 ->>>>>>> develop return R.ok(); } -<<<<<<< HEAD /** * 饼状图求和 * @return @@ -409,72 +216,10 @@ public class CommonController { xAxis.add(oneValue); yAxis0.add(value); } -======= - // * 饼状图求和接口 - //* @param params 请求参数Map - // * @return 包含求和结果的响应 - - @RequestMapping("/pieSum") // 映射请求路径 - public R pieSum(@RequestParam Map params) { - // 记录调试日志 - logger.debug("饼状图求和:,,Controller:{},,params:{}",this.getClass().getName(),params); - // 调用服务层获取求和结果 - List> result = commonService.pieSum(params); - // 返回成功结果和数据 - return R.ok().put("data", result); - } - - - // * 饼状图统计接口 - // * @param params 请求参数Map - //* @return 包含统计结果的响应 - - @RequestMapping("/pieCount") // 映射请求路径 - public R pieCount(@RequestParam Map params) { - // 记录调试日志 - logger.debug("饼状图统计:,,Controller:{},,params:{}",this.getClass().getName(),params); - // 调用服务层获取统计结果 - List> result = commonService.pieCount(params); - // 返回成功结果和数据 - return R.ok().put("data", result); - } - - // * 单列柱状图求和接口 - // * @param params 请求参数Map - //* @return 包含图表数据的响应 - - @RequestMapping("/barSumOne") // 映射请求路径 - public R barSumOne(@RequestParam Map params) { - // 记录调试日志 - logger.debug("柱状图求和单列:,,Controller:{},,params:{}",this.getClass().getName(),params); - // 调用服务层获取数据 - List> result = commonService.barSumOne(params); - - // 准备图表数据 - List xAxis = new ArrayList<>(); // x轴数据 - List> yAxis = new ArrayList<>(); // y轴数据 - List legend = new ArrayList<>(); // 图例 - List yAxis0 = new ArrayList<>(); // 第一个y轴数据系列 - yAxis.add(yAxis0); // 添加到y轴集合 - legend.add(""); // 添加空图例 - - // 遍历结果集 - for(Map map : result){ - // 获取名称和值 - String oneValue = String.valueOf(map.get("name")); - String value = String.valueOf(map.get("value")); - // 添加到对应集合 - xAxis.add(oneValue); - yAxis0.add(value); - } - - // 构建结果Map ->>>>>>> develop Map resultMap = new HashMap<>(); resultMap.put("xAxis",xAxis); resultMap.put("yAxis",yAxis); resultMap.put("legend",legend); -<<<<<<< HEAD return R.ok().put("data", resultMap); } @@ -938,26 +683,3 @@ public class CommonController { return R.ok().put("data", resultMap); } } -======= - // 返回成功结果和数据 - return R.ok().put("data", resultMap); - } - - // 其他方法的行注释类似,遵循相同的模式... - // 每个方法都包含: - // 1. 方法功能说明 - // 2. 参数说明 - // 3. 返回值说明 - // 4. 关键代码行的详细注释 - - // 由于篇幅限制,这里省略了部分方法的详细行注释 - // 但每个方法都应按照上述模式进行注释 - - // 所有方法的注释都应包括: - // - 方法用途 - // - 参数说明 - // - 返回值说明 - // - 关键处理逻辑说明 - // - 异常处理说明 -} ->>>>>>> develop diff --git a/src/main/java/com/controller/ConfigController.java b/src/main/java/com/controller/ConfigController.java index 97a65cd..6e9f123 100644 --- a/src/main/java/com/controller/ConfigController.java +++ b/src/main/java/com/controller/ConfigController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; @@ -110,104 +109,3 @@ public class ConfigController{ return R.ok(); } } -======= -package com.controller; - -import java.util.Arrays; // 导入Java的Arrays类,用于操作数组 -import java.util.Map; // 导入Java的Map接口,用于存储键值对 - -import org.springframework.beans.factory.annotation.Autowired; // 导入Spring框架的@Autowired注解,用于自动注入依赖 -import org.springframework.web.bind.annotation.PathVariable; // 导入Spring MVC的@PathVariable注解,用于从URL路径中获取变量 -import org.springframework.web.bind.annotation.PostMapping; // 导入Spring MVC的@PostMapping注解,用于映射HTTP POST请求到特定的处理方法 -import org.springframework.web.bind.annotation.RequestBody; // 导入Spring MVC的@RequestBody注解,用于将HTTP请求体绑定到方法参数上 -import org.springframework.web.bind.annotation.RequestMapping; // 导入Spring MVC的@RequestMapping注解,用于映射HTTP请求到控制器的方法 -import org.springframework.web.bind.annotation.RequestParam; // 导入Spring MVC的@RequestParam注解,用于从HTTP请求中获取查询参数 -import org.springframework.web.bind.annotation.RestController; // 导入Spring MVC的@RestController注解,用于定义RESTful Web服务的控制器 - -import com.annotation.IgnoreAuth; // 导入自定义的IgnoreAuth注解,可能用于忽略某些认证逻辑 -import com.baomidou.mybatisplus.mapper.EntityWrapper; // 导入MyBatis-Plus的EntityWrapper类,用于构建查询条件 -import com.entity.ConfigEntity; // 导入ConfigEntity实体类,表示配置信息的数据模型 -import com.service.ConfigService; // 导入ConfigService服务接口,提供配置相关的业务逻辑 -import com.utils.PageUtils; // 导入PageUtils工具类,用于分页处理 -import com.utils.R; // 导入R工具类,用于封装统一的响应结果 -import com.utils.ValidatorUtils; // 导入ValidatorUtils工具类,用于数据验证 - - -//登录相关 -@RequestMapping("config") // 映射请求路径为 "config" -@RestController // 声明这是一个控制器,并且返回的数据直接写入 HTTP 响应体中 -public class ConfigController { - - @Autowired // 自动注入 ConfigService 实例 - private ConfigService configService; - - /**列表*/ - @RequestMapping("/page") // 映射请求路径为 "/page" - public R page(@RequestParam Map params, ConfigEntity config) { - EntityWrapper ew = new EntityWrapper(); // 创建查询条件包装器 - PageUtils page = configService.queryPage(params); // 调用服务层方法获取分页数据 - return R.ok().put("data", page); // 返回封装好的分页数据 - } - - /**列表*/ - @IgnoreAuth // 忽略认证注解 - @RequestMapping("/list") // 映射请求路径为 "/list" - public R list(@RequestParam Map params, ConfigEntity config) { - EntityWrapper ew = new EntityWrapper(); // 创建查询条件包装器 - PageUtils page = configService.queryPage(params); // 调用服务层方法获取分页数据 - return R.ok().put("data", page); // 返回封装好的分页数据 - } - - //信息 - @RequestMapping("/info/{id}") // 映射请求路径为 "/info/{id}" - public R info(@PathVariable("id") String id) { // 从路径变量中获取 id 参数 - ConfigEntity config = configService.selectById(id); // 根据 id 查询配置实体 - return R.ok().put("data", config); // 返回查询到的配置实体 - } - - - // 详情 - @IgnoreAuth // 忽略认证注解 - @RequestMapping("/detail/{id}") // 映射请求路径为 "/detail/{id}" - public R detail(@PathVariable("id") String id) { // 从路径变量中获取 id 参数 - ConfigEntity config = configService.selectById(id); // 根据 id 查询配置实体 - return R.ok().put("data", config); // 返回查询到的配置实体 - } - - - // 根据name获取信息 - - @RequestMapping("/info") // 映射请求路径为 "/info" - public R infoByName(@RequestParam String name) { // 从请求参数中获取 name 参数 - ConfigEntity config = configService.selectOne(new EntityWrapper().eq("name", "faceFile")); // 根据 name 查询配置实体 - return R.ok().put("data", config); // 返回查询到的配置实体 - } - - - // 保存 - @PostMapping("/save") // 映射请求路径为 "/save",并指定请求方法为 POST - public R save(@RequestBody ConfigEntity config) { // 从请求体中获取配置实体对象 -// ValidatorUtils.validateEntity(config); // 验证实体(注释掉) - configService.insert(config); // 插入新的配置实体 - return R.ok(); // 返回成功响应 - } - - - //修改 - - @RequestMapping("/update") // 映射请求路径为 "/update" - public R update(@RequestBody ConfigEntity config) { // 从请求体中获取配置实体对象 -// ValidatorUtils.validateEntity(config); // 验证实体(注释掉) - configService.updateById(config); // 更新配置实体(全部字段) - return R.ok(); // 返回成功响应 - } - - //删除/ - @RequestMapping("/delete") // 映射请求路径为 "/delete" - public R delete(@RequestBody Long[] ids) { // 从请求体中获取要删除的 ID 数组 - configService.deleteBatchIds(Arrays.asList(ids)); // 批量删除配置实体 - return R.ok(); // 返回成功响应 - } -} - ->>>>>>> develop diff --git a/src/main/java/com/controller/DictionaryController.java b/src/main/java/com/controller/DictionaryController.java index 5b97e81..e0a8887 100644 --- a/src/main/java/com/controller/DictionaryController.java +++ b/src/main/java/com/controller/DictionaryController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; @@ -268,289 +267,10 @@ public class DictionaryController { //查询是否重复 dictionaryService.insertBatch(dictionaryList); return R.ok(); -======= -package com.controller; -// 文件操作相关类 -import java.io.File; -// 高精度数学计算类 -import java.math.BigDecimal; -// 网络URL处理类 -import java.net.URL; -// 日期格式化类 -import java.text.SimpleDateFormat; -// FastJSON的JSON对象处理类 -import com.alibaba.fastjson.JSONObject; -// Java集合框架类 -import java.util.*; -// Spring Bean属性复制工具类 -import org.springframework.beans.BeanUtils; -// HTTP请求处理类 -import javax.servlet.http.HttpServletRequest; -// Spring Web上下文加载器 -import org.springframework.web.context.ContextLoader; -// Servlet上下文接口 -import javax.servlet.ServletContext; -// 自定义Token服务接口 -import com.service.TokenService; -// 自定义工具类包 -import com.utils.*; -// Java反射异常类 -import java.lang.reflect.InvocationTargetException; - -// 自定义字典服务接口 -import com.service.DictionaryService; -// Apache Commons字符串处理工具 -import org.apache.commons.lang3.StringUtils; -// 自定义忽略鉴权注解 -import com.annotation.IgnoreAuth; -// 日志接口 -import org.slf4j.Logger; -// 日志工厂类 -import org.slf4j.LoggerFactory; -// Spring自动注入注解 -import org.springframework.beans.factory.annotation.Autowired; -// Spring控制器注解 -import org.springframework.stereotype.Controller; -// Spring Web映射注解包 -import org.springframework.web.bind.annotation.*; -// MyBatis Plus实体包装器 -import com.baomidou.mybatisplus.mapper.EntityWrapper; -// MyBatis Plus包装器接口 -import com.baomidou.mybatisplus.mapper.Wrapper; -// 自定义实体类包 -import com.entity.*; -// 自定义视图实体类包 -import com.entity.view.*; -// 自定义服务接口包 -import com.service.*; -// 自定义分页工具类 -import com.utils.PageUtils; -// 自定义返回结果类 -import com.utils.R; -// FastJSON包 -import com.alibaba.fastjson.*; - - //字典 - //后端接口 - //@author - // @email - -@RestController // 声明这是一个RESTful风格的控制器 -@Controller // 声明这是一个Spring MVC控制器 -@RequestMapping("/dictionary") // 定义请求的基础路径 -public class DictionaryController { - private static final Logger logger = LoggerFactory.getLogger(DictionaryController.class); // 日志记录器 - - private static final String TABLE_NAME = "dictionary"; // 表名常量 - - @Autowired - private DictionaryService dictionaryService; // 注入字典服务 - - @Autowired - private TokenService tokenService; // 注入Token服务 - - @Autowired - private ForumService forumService; // 注入健身论坛服务 - @Autowired - private JianshenkechengService jianshenkechengService; // 注入健身课程服务 - @Autowired - private JianshenkechengCollectionService jianshenkechengCollectionService; // 注入课程收藏服务 - @Autowired - private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 注入课程留言服务 - @Autowired - private JiaolianService jiaolianService; // 注入教练服务 - @Autowired - private JiaolianYuyueService jiaolianYuyueService; // 注入教练预约申请服务 - @Autowired - private NewsService newsService; // 注入健身资讯服务 - @Autowired - private SingleSeachService singleSeachService; // 注入单页数据服务 - @Autowired - private YonghuService yonghuService; // 注入用户服务 - @Autowired - private UsersService usersService; // 注入管理员服务 - - - //后端列表 - @RequestMapping("/page") // 处理分页请求 - @IgnoreAuth // 忽略鉴权 - public R page(@RequestParam Map params, HttpServletRequest request){ - logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录日志 - CommonUtil.checkMap(params); // 检查参数 - PageUtils page = dictionaryService.queryPage(params); // 调用服务查询分页数据 - - // 字典表数据转换 - List list =(List)page.getList(); // 获取分页数据列表 - for(DictionaryView c:list){ - // 修改对应字典表字段 - dictionaryService.dictionaryConvert(c, request); // 转换字典数据 - } - return R.ok().put("data", page); // 返回成功响应和数据 - } - - - //后端详情 - @RequestMapping("/info/{id}") // 处理详情请求 - public R info(@PathVariable("id") Long id, HttpServletRequest request){ - logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录日志 - DictionaryEntity dictionary = dictionaryService.selectById(id); // 根据ID查询字典数据 - if(dictionary !=null){ - // entity转view - DictionaryView view = new DictionaryView(); // 创建视图对象 - BeanUtils.copyProperties(dictionary, view); // 复制属性到视图对象 - // 修改对应字典表字段 - dictionaryService.dictionaryConvert(view, request); // 转换字典数据 - return R.ok().put("data", view); // 返回成功响应和数据 - }else { - return R.error(511,"查不到数据"); // 返回错误响应 - } - } - - - //后端保存 - @RequestMapping("/save") // 处理保存请求 - public R save(@RequestBody DictionaryEntity dictionary, HttpServletRequest request){ - logger.debug("save方法:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString()); // 记录日志 - - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) - return R.error(511,"永远不会进入"); // 模拟条件判断 - - Wrapper queryWrapper = new EntityWrapper() - .eq("dic_code", dictionary.getDicCode()) // 构建查询条件 - .eq("index_name", dictionary.getIndexName()); - if(dictionary.getDicCode().contains("_erji_types")){ - queryWrapper.eq("super_id",dictionary.getSuperId()); // 如果是二级类型,添加父ID条件 - } - - logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句 - DictionaryEntity dictionaryEntity = dictionaryService.selectOne(queryWrapper); // 查询是否已存在相同数据 - if(dictionaryEntity==null){ - dictionary.setCreateTime(new Date()); // 设置创建时间 - dictionaryService.insert(dictionary); // 插入新数据 - // 字典表新增数据,把数据再重新查出,放入监听器中 - List dictionaryEntities = dictionaryService.selectList(new EntityWrapper()); // 查询所有字典数据 - ServletContext servletContext = request.getServletContext(); // 获取ServletContext - Map> map = new HashMap<>(); // 创建字典映射 - for(DictionaryEntity d :dictionaryEntities){ - Map m = map.get(d.getDicCode()); // 获取当前字典代码的映射 - if(m ==null || m.isEmpty()){ - m = new HashMap<>(); // 如果不存在则创建新映射 - } - m.put(d.getCodeIndex(),d.getIndexName()); // 添加编码和名称到映射 - map.put(d.getDicCode(),m); // 将映射放入字典映射中 - } - servletContext.setAttribute("dictionaryMap",map); // 将字典映射存入ServletContext - return R.ok(); // 返回成功响应 - }else { - return R.error(511,"表中有相同数据"); // 返回错误响应 - } - } - - - //后端修改 - @RequestMapping("/update") // 处理更新请求 - public R update(@RequestBody DictionaryEntity dictionary, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { - logger.debug("update方法:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString()); // 记录日志 - DictionaryEntity oldDictionaryEntity = dictionaryService.selectById(dictionary.getId()); // 查询原数据 - - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 -// if(false) -// return R.error(511,"永远不会进入"); - - dictionaryService.updateById(dictionary); // 根据ID更新数据 - // 如果字典表修改数据的话,把数据再重新查出,放入监听器中 - List dictionaryEntities = dictionaryService.selectList(new EntityWrapper()); // 查询所有字典数据 - ServletContext servletContext = request.getServletContext(); // 获取ServletContext - Map> map = new HashMap<>(); // 创建字典映射 - for(DictionaryEntity d :dictionaryEntities){ - Map m = map.get(d.getDicCode()); // 获取当前字典代码的映射 - if(m ==null || m.isEmpty()){ - m = new HashMap<>(); // 如果不存在则创建新映射 - } - m.put(d.getCodeIndex(),d.getIndexName()); // 添加编码和名称到映射 - map.put(d.getDicCode(),m); // 将映射放入字典映射中 - } - servletContext.setAttribute("dictionaryMap",map); // 将字典映射存入ServletContext - return R.ok(); // 返回成功响应 - } - - - //删除 - @RequestMapping("/delete") // 处理删除请求 - public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ - logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); // 记录日志 - List oldDictionaryList =dictionaryService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据 - dictionaryService.deleteBatchIds(Arrays.asList(ids)); // 批量删除数据 - - return R.ok(); // 返回成功响应 - } - - - //最大值 - @RequestMapping("/maxCodeIndex") // 处理获取最大编码请求 - public R maxCodeIndex(@RequestBody DictionaryEntity dictionary){ - logger.debug("maxCodeIndex:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString()); // 记录日志 - List descs = new ArrayList<>(); // 创建排序字段列表 - descs.add("code_index"); // 添加排序字段 - Wrapper queryWrapper = new EntityWrapper() - .eq("dic_code", dictionary.getDicCode()) // 构建查询条件 - .orderDesc(descs); // 添加排序条件 - logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句 - List dictionaryEntityList = dictionaryService.selectList(queryWrapper); // 查询数据 - if(dictionaryEntityList.size()>0 ){ - return R.ok().put("maxCodeIndex",dictionaryEntityList.get(0).getCodeIndex()+1); // 返回最大编码加1 - }else{ - return R.ok().put("maxCodeIndex",1); // 返回默认值1 - } - } - - - //批量上传 - @RequestMapping("/batchInsert") // 处理批量上传请求 - public R save(String fileName, HttpServletRequest request){ - logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); // 记录日志 - Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取用户ID - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 创建日期格式化对象 - try { - List dictionaryList = new ArrayList<>(); // 创建字典数据列表 - Map> seachFields= new HashMap<>(); // 创建查询字段映射 - Date date = new Date(); // 获取当前时间 - int lastIndexOf = fileName.lastIndexOf("."); // 获取文件后缀名位置 - if(lastIndexOf == -1){ - return R.error(511,"该文件没有后缀"); // 返回错误响应 - }else{ - String suffix = fileName.substring(lastIndexOf); // 获取文件后缀名 - if(!".xls".equals(suffix)){ - return R.error(511,"只支持后缀为xls的excel文件"); // 返回错误响应 - }else{ - URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 获取文件路径 - File file = new File(resource.getFile()); // 创建文件对象 - if(!file.exists()){ - return R.error(511,"找不到上传文件,请联系管理员"); // 返回错误响应 - }else{ - List> dataList = PoiUtil.poiImport(file.getPath()); // 读取Excel文件 - dataList.remove(0); // 删除第一行标题 - for(List data:dataList){ - // 循环处理每一行数据 - DictionaryEntity dictionaryEntity = new DictionaryEntity(); // 创建字典实体 -// dictionaryEntity.setDicCode(data.get(0)); // 设置字段代码(示例) -// dictionaryEntity.setDicName(data.get(0)); // 设置字段名(示例) -// dictionaryEntity.setCodeIndex(Integer.valueOf(data.get(0))); // 设置编码(示例) -// dictionaryEntity.setIndexName(data.get(0)); // 设置编码名(示例) -// dictionaryEntity.setSuperId(Integer.valueOf(data.get(0))); // 设置父ID(示例) -// dictionaryEntity.setBeizhu(data.get(0)); // 设置备注(示例) -// dictionaryEntity.setCreateTime(date); // 设置创建时间(示例) - dictionaryList.add(dictionaryEntity); // 添加到列表 - } - dictionaryService.insertBatch(dictionaryList); // 批量插入数据 - return R.ok(); // 返回成功响应 ->>>>>>> develop } } } }catch (Exception e){ -<<<<<<< HEAD e.printStackTrace(); return R.error(511,"批量插入数据异常,请联系管理员"); } @@ -561,10 +281,3 @@ public class DictionaryController { } -======= - e.printStackTrace(); // 打印异常堆栈 - return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误响应 - } - } -} ->>>>>>> develop diff --git a/src/main/java/com/controller/FileController.java b/src/main/java/com/controller/FileController.java index 70c3d57..7bd4f8e 100644 --- a/src/main/java/com/controller/FileController.java +++ b/src/main/java/com/controller/FileController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; import java.io.File; @@ -108,164 +107,4 @@ public class FileController{ return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); } -======= -package com.controller; // 定义包路径 - -// 文件操作相关类 -import java.io.File; -// 文件未找到异常 -import java.io.FileNotFoundException; -// IO异常 -import java.io.IOException; -// 数组工具类 -import java.util.Arrays; -// 日期类 -import java.util.Date; -// 哈希Map -import java.util.HashMap; -// 列表接口 -import java.util.List; -// Map接口 -import java.util.Map; -// 随机数类 -import java.util.Random; -// UUID类 -import java.util.UUID; - -// Apache Commons IO工具类 -import org.apache.commons.io.FileUtils; -// Apache Commons字符串工具 -import org.apache.commons.lang3.StringUtils; -// Spring自动注入注解 -import org.springframework.beans.factory.annotation.Autowired; -// HTTP头定义 -import org.springframework.http.HttpHeaders; -// HTTP状态码 -import org.springframework.http.HttpStatus; -// 媒体类型定义 -import org.springframework.http.MediaType; -// ResponseEntity响应实体 -import org.springframework.http.ResponseEntity; -// Spring资源工具 -import org.springframework.util.ResourceUtils; -// Spring路径变量注解 -import org.springframework.web.bind.annotation.PathVariable; -// Spring请求体注解 -import org.springframework.web.bind.annotation.RequestBody; -// Spring请求映射注解 -import org.springframework.web.bind.annotation.RequestMapping; -// Spring请求参数注解 -import org.springframework.web.bind.annotation.RequestParam; -// Spring REST控制器注解 -import org.springframework.web.bind.annotation.RestController; -// Spring文件上传类 -import org.springframework.web.multipart.MultipartFile; - -// 自定义忽略鉴权注解 -import com.annotation.IgnoreAuth; -// MyBatis Plus实体包装器 -import com.baomidou.mybatisplus.mapper.EntityWrapper; -// 配置实体类 -import com.entity.ConfigEntity; -// 自定义异常类 -import com.entity.EIException; -// 配置服务接口 -import com.service.ConfigService; -// 自定义返回结果类 -import com.utils.R; - - - //上传文件映射表 - //文件上传下载控制器 -@RestController // 声明为RESTful控制器 -@RequestMapping("file") // 基础请求路径映射 -@SuppressWarnings({"unchecked","rawtypes"}) // 抑制警告 -public class FileController{ - @Autowired // 自动注入配置服务 - private ConfigService configService; - - - //上传文件 - //@param file 上传的文件对象 - //@param type 文件类型标识 - //@return 上传结果 - //* @throws Exception 可能抛出的异常 - - @RequestMapping("/upload") // 文件上传请求映射 - public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception { - if (file.isEmpty()) { // 检查文件是否为空 - throw new EIException("上传文件不能为空"); // 抛出文件为空异常 - } - // 获取文件扩展名 - String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1); - // 获取静态资源路径 - File path = new File(ResourceUtils.getURL("classpath:static").getPath()); - if(!path.exists()) { // 如果路径不存在 - path = new File(""); // 使用当前路径 - } - // 创建上传目录 - File upload = new File(path.getAbsolutePath(),"/upload/"); - if(!upload.exists()) { // 如果目录不存在 - upload.mkdirs(); // 创建目录 - } - // 生成唯一文件名(时间戳+扩展名) - String fileName = new Date().getTime()+"."+fileExt; - // 创建目标文件 - File dest = new File(upload.getAbsolutePath()+"/"+fileName); - // 传输文件到目标位置 - file.transferTo(dest); - // 如果是类型1的文件(如头像文件) - if(StringUtils.isNotBlank(type) && type.equals("1")) { - // 查询配置表中faceFile配置 - ConfigEntity configEntity = configService.selectOne(new EntityWrapper().eq("name", "faceFile")); - if(configEntity==null) { // 如果配置不存在 - configEntity = new ConfigEntity(); // 创建新配置 - configEntity.setName("faceFile"); // 设置配置名 - configEntity.setValue(fileName); // 设置文件名 - } else { - configEntity.setValue(fileName); // 更新文件名 - } - // 保存或更新配置 - configService.insertOrUpdate(configEntity); - } - // 返回成功结果和文件名 - return R.ok().put("file", fileName); - } - - - //下载文件 - //@param fileName 要下载的文件名 - // @return 文件下载响应 - - @IgnoreAuth // 忽略权限验证 - @RequestMapping("/download") // 文件下载请求映射 - public ResponseEntity download(@RequestParam String fileName) { - try { - // 获取静态资源路径 - File path = new File(ResourceUtils.getURL("classpath:static").getPath()); - if(!path.exists()) { // 如果路径不存在 - path = new File(""); // 使用当前路径 - } - // 获取上传目录 - File upload = new File(path.getAbsolutePath(),"/upload/"); - if(!upload.exists()) { // 如果目录不存在 - upload.mkdirs(); // 创建目录 - } - // 构建文件对象 - File file = new File(upload.getAbsolutePath()+"/"+fileName); - if(file.exists()){ // 如果文件存在 - // 设置HTTP响应头 - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); // 设置内容类型为二进制流 - headers.setContentDispositionFormData("attachment", fileName); // 设置内容处置为附件 - // 返回文件内容和响应头 - return new ResponseEntity(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED); - } - } catch (IOException e) { // 捕获IO异常 - e.printStackTrace(); // 打印异常堆栈 - } - // 返回服务器错误响应 - return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); - } ->>>>>>> develop } diff --git a/src/main/java/com/controller/ForumController.java b/src/main/java/com/controller/ForumController.java index a795ef1..bed9f99 100644 --- a/src/main/java/com/controller/ForumController.java +++ b/src/main/java/com/controller/ForumController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; @@ -39,54 +38,12 @@ import com.alibaba.fastjson.*; * @author * @email */ -======= -package com.controller;// 定义包路径,表示该文件位于com.controller包下 - -import java.io.File; // 导入文件操作类 -import java.math.BigDecimal; // 导入高精度数学计算类 -import java.net.URL; // 导入网络URL处理类 -import java.text.SimpleDateFormat; // 导入日期格式化类 -import com.alibaba.fastjson.JSONObject; // 导入FastJSON的JSON对象类 -import java.util.*; // 导入Java常用工具类(集合、日期等) -import org.springframework.beans.BeanUtils; // 导入Spring Bean属性复制工具类 -import javax.servlet.http.HttpServletRequest; // 导入HTTP请求处理类 -import org.springframework.web.context.ContextLoader; // 导入Spring上下文加载器 -import javax.servlet.ServletContext; // 导入Servlet上下文接口 -import com.service.TokenService; // 导入自定义的Token服务类 -import com.utils.*; // 导入自定义工具类 -import java.lang.reflect.InvocationTargetException; // 导入反射异常类 - -import com.service.DictionaryService; // 导入自定义的字典服务类 -import org.apache.commons.lang3.StringUtils; // 导入Apache字符串工具类 -import com.annotation.IgnoreAuth; // 导入自定义的忽略认证注解 -import org.slf4j.Logger; // 导入日志接口 -import org.slf4j.LoggerFactory; // 导入日志工厂类 -import org.springframework.beans.factory.annotation.Autowired; // 导入Spring自动注入注解 -import org.springframework.stereotype.Controller; // 导入Spring控制器注解 -import org.springframework.web.bind.annotation.*; // 导入Spring Web注解 -import com.baomidou.mybatisplus.mapper.EntityWrapper; // 导入MyBatis Plus查询条件构造器 -import com.baomidou.mybatisplus.mapper.Wrapper; // 导入MyBatis Plus包装器接口 -import com.entity.*; // 导入实体类 -import com.entity.view.*; // 导入视图实体类 -import com.service.*; // 导入服务类 -import com.utils.PageUtils; // 导入分页工具类 -import com.utils.R; // 导入统一返回结果类 -import com.alibaba.fastjson.*; // 导入FastJSON相关类 - - - //健身论坛 - //后端接口 - //@author - //@email - ->>>>>>> develop @RestController @Controller @RequestMapping("/forum") public class ForumController { private static final Logger logger = LoggerFactory.getLogger(ForumController.class); -<<<<<<< HEAD private static final String TABLE_NAME = "forum"; @Autowired @@ -187,104 +144,10 @@ public class ForumController { /** * 后端保存 */ -======= - private static final String TABLE_NAME = "forum"; // 数据库表名 - - @Autowired - private ForumService forumService; // 论坛服务 - - @Autowired - private TokenService tokenService; // token服务 - - @Autowired - private DictionaryService dictionaryService; // 字典服务 - @Autowired - private JianshenkechengService jianshenkechengService; // 健身课程服务 - @Autowired - private JianshenkechengCollectionService jianshenkechengCollectionService; // 课程收藏服务 - @Autowired - private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 课程留言服务 - @Autowired - private JiaolianService jiaolianService; // 教练服务 - @Autowired - private JiaolianYuyueService jiaolianYuyueService; // 教练预约申请服务 - @Autowired - private NewsService newsService; // 健身资讯服务 - @Autowired - private SingleSeachService singleSeachService; // 单页数据服务 - @Autowired - private YonghuService yonghuService; // 用户服务 - @Autowired - private UsersService usersService; // 管理员服务 - - - //后端列表 - @RequestMapping("/page") - public R page(@RequestParam Map params, HttpServletRequest request){ - logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); - CommonUtil.checkMap(params); // 检查参数 - PageUtils page = forumService.queryPage(params); // 查询分页数据 - - // 字典表数据转换 - List list =(List)page.getList(); - for(ForumView c:list){ - // 修改对应字典表字段 - dictionaryService.dictionaryConvert(c, request); - } - return R.ok().put("data", page); // 返回分页数据 - } - - - //后端详情 - @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id, HttpServletRequest request){ - logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); - ForumEntity forum = forumService.selectById(id); // 根据ID查询论坛帖子 - if(forum !=null){ - // entity转view - ForumView view = new ForumView(); - BeanUtils.copyProperties( forum , view ); // 把实体数据重构到view中 - // 级联表 用户 - YonghuEntity yonghu = yonghuService.selectById(forum.getYonghuId()); - if(yonghu != null){ - BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId" - , "jiaolianId" - , "usersId"}); // 把级联的数据添加到view中,并排除id和创建时间字段 - view.setYonghuId(yonghu.getId()); - } - // 级联表 教练 - JiaolianEntity jiaolian = jiaolianService.selectById(forum.getJiaolianId()); - if(jiaolian != null){ - BeanUtils.copyProperties( jiaolian , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId" - , "jiaolianId" - , "usersId"}); // 把级联的数据添加到view中,并排除id和创建时间字段 - view.setJiaolianId(jiaolian.getId()); - } - // 级联表 管理员 - UsersEntity users = usersService.selectById(forum.getUsersId()); - if(users != null){ - view.setUsersId(users.getId()); // 设置管理员ID - view.setUusername(users.getUsername()); // 设置管理员用户名 - view.setUpassword(users.getPassword()); // 设置管理员密码 - view.setUrole(users.getRole()); // 设置管理员角色 - view.setUaddtime(users.getAddtime()); // 设置管理员添加时间 - } - // 修改对应字典表字段 - dictionaryService.dictionaryConvert(view, request); - return R.ok().put("data", view); // 返回帖子详情 - }else { - return R.error(511,"查不到数据"); // 查询不到数据返回错误 - } - } - - - //后端保存 ->>>>>>> develop @RequestMapping("/save") public R save(@RequestBody ForumEntity forum, HttpServletRequest request){ logger.debug("save方法:,,Controller:{},,forum:{}",this.getClass().getName(),forum.toString()); -<<<<<<< HEAD String role = String.valueOf(request.getSession().getAttribute("role")); if(false) return R.error(511,"永远不会进入"); @@ -352,69 +215,11 @@ public class ForumController { logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); List oldForumList =forumService.selectBatchIds(Arrays.asList(ids));//要删除的数据 forumService.deleteBatchIds(Arrays.asList(ids)); -======= - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) - return R.error(511,"永远不会进入"); - else if("用户".equals(role)) - forum.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); // 设置用户ID - else if("教练".equals(role)) - forum.setJiaolianId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); // 设置教练ID - else if("管理员".equals(role)) - forum.setUsersId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); // 设置管理员ID - - Wrapper queryWrapper = new EntityWrapper() - .eq("forum_name", forum.getForumName()) // 帖子标题 - .eq("yonghu_id", forum.getYonghuId()) // 用户ID - .eq("jiaolian_id", forum.getJiaolianId()) // 教练ID - .eq("users_id", forum.getUsersId()) // 管理员ID - .eq("super_ids", forum.getSuperIds()) // 父ID - .eq("forum_state_types", forum.getForumStateTypes()) // 帖子状态 - ; - - logger.info("sql语句:"+queryWrapper.getSqlSegment()); - ForumEntity forumEntity = forumService.selectOne(queryWrapper); // 查询是否已存在相同数据 - if(forumEntity==null){ - forum.setInsertTime(new Date()); // 设置插入时间 - forum.setCreateTime(new Date()); // 设置创建时间 - forumService.insert(forum); // 插入新数据 - return R.ok(); - }else { - return R.error(511,"表中有相同数据"); // 数据已存在返回错误 - } - } - - - //后端修改 - @RequestMapping("/update") - public R update(@RequestBody ForumEntity forum, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { - logger.debug("update方法:,,Controller:{},,forum:{}",this.getClass().getName(),forum.toString()); - ForumEntity oldForumEntity = forumService.selectById(forum.getId()); // 查询原先数据 - - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if("".equals(forum.getForumContent()) || "null".equals(forum.getForumContent())){ - forum.setForumContent(null); // 处理空内容 - } - forum.setUpdateTime(new Date()); // 设置更新时间 - forumService.updateById(forum); // 根据ID更新数据 return R.ok(); } - //删除 - @RequestMapping("/delete") - public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ - logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); - List oldForumList =forumService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据 - forumService.deleteBatchIds(Arrays.asList(ids)); // 批量删除 ->>>>>>> develop - - return R.ok(); - } - - -<<<<<<< HEAD /** * 批量上传 */ @@ -463,39 +268,6 @@ public class ForumController { } //查询是否重复 -======= - //批量上传 - @RequestMapping("/batchInsert") - public R save( String fileName, HttpServletRequest request){ - logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); - Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取用户ID - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - try { - List forumList = new ArrayList<>(); // 存储上传的数据 - Map> seachFields= new HashMap<>(); // 要查询的字段 - Date date = new Date(); - int lastIndexOf = fileName.lastIndexOf("."); - if(lastIndexOf == -1){ - return R.error(511,"该文件没有后缀"); // 文件无后缀返回错误 - }else{ - String suffix = fileName.substring(lastIndexOf); - if(!".xls".equals(suffix)){ - return R.error(511,"只支持后缀为xls的excel文件"); // 文件格式不正确返回错误 - }else{ - URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 获取文件路径 - File file = new File(resource.getFile()); - if(!file.exists()){ - return R.error(511,"找不到上传文件,请联系管理员"); // 文件不存在返回错误 - }else{ - List> dataList = PoiUtil.poiImport(file.getPath()); // 读取xls文件 - dataList.remove(0); // 删除第一行提示信息 - for(List data:dataList){ - // 循环处理每行数据 - ForumEntity forumEntity = new ForumEntity(); - forumList.add(forumEntity); // 添加到列表 - } - // 批量插入数据 ->>>>>>> develop forumService.insertBatch(forumList); return R.ok(); } @@ -503,7 +275,6 @@ public class ForumController { } }catch (Exception e){ e.printStackTrace(); -<<<<<<< HEAD return R.error(511,"批量插入数据异常,请联系管理员"); } } @@ -515,20 +286,10 @@ public class ForumController { * 前端列表 */ @IgnoreAuth -======= - return R.error(511,"批量插入数据异常,请联系管理员"); // 异常处理 - } - } - - // 前端列表 - - @IgnoreAuth // 忽略认证 ->>>>>>> develop @RequestMapping("/list") public R list(@RequestParam Map params, HttpServletRequest request){ logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); -<<<<<<< HEAD CommonUtil.checkMap(params); PageUtils page = forumService.queryPage(params); @@ -590,70 +351,10 @@ public class ForumController { /** * 前端保存 */ -======= - CommonUtil.checkMap(params); // 检查参数 - PageUtils page = forumService.queryPage(params); // 查询分页数据 - - // 字典表数据转换 - List list =(List)page.getList(); - for(ForumView c:list) - dictionaryService.dictionaryConvert(c, request); // 修改对应字典表字段 - - return R.ok().put("data", page); // 返回分页数据 - } - - - //前端详情 - @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ - logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); - ForumEntity forum = forumService.selectById(id); // 根据ID查询帖子 - if(forum !=null){ - // entity转view - ForumView view = new ForumView(); - BeanUtils.copyProperties( forum , view ); // 把实体数据重构到view中 - - // 级联表用户 - YonghuEntity yonghu = yonghuService.selectById(forum.getYonghuId()); - if(yonghu != null){ - BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId" - , "jiaolianId" - , "usersId"}); // 把级联的数据添加到view中,并排除id和创建时间字段 - view.setYonghuId(yonghu.getId()); - } - // 级联表教练 - JiaolianEntity jiaolian = jiaolianService.selectById(forum.getJiaolianId()); - if(jiaolian != null){ - BeanUtils.copyProperties( jiaolian , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId" - , "jiaolianId" - , "usersId"}); // 把级联的数据添加到view中,并排除id和创建时间字段 - view.setJiaolianId(jiaolian.getId()); - } - // 级联表管理员 - UsersEntity users = usersService.selectById(forum.getUsersId()); - if(users != null){ - view.setUsersId(users.getId()); // 设置管理员ID - view.setUusername(users.getUsername()); // 设置管理员用户名 - view.setUpassword(users.getPassword()); // 设置管理员密码 - view.setUrole(users.getRole()); // 设置管理员角色 - view.setUaddtime(users.getAddtime()); // 设置管理员添加时间 - } - // 修改对应字典表字段 - dictionaryService.dictionaryConvert(view, request); - return R.ok().put("data", view); // 返回帖子详情 - }else { - return R.error(511,"查不到数据"); // 查询不到数据返回错误 - } - } - - - //前端保存 ->>>>>>> develop @RequestMapping("/add") public R add(@RequestBody ForumEntity forum, HttpServletRequest request){ logger.debug("add方法:,,Controller:{},,forum:{}",this.getClass().getName(),forum.toString()); Wrapper queryWrapper = new EntityWrapper() -<<<<<<< HEAD .eq("forum_name", forum.getForumName()) .eq("yonghu_id", forum.getYonghuId()) .eq("jiaolian_id", forum.getJiaolianId()) @@ -677,25 +378,3 @@ public class ForumController { } -======= - .eq("forum_name", forum.getForumName()) // 帖子标题 - .eq("yonghu_id", forum.getYonghuId()) // 用户ID - .eq("jiaolian_id", forum.getJiaolianId()) // 教练ID - .eq("users_id", forum.getUsersId()) // 管理员ID - .eq("super_ids", forum.getSuperIds()) // 父ID - .eq("forum_state_types", forum.getForumStateTypes()) // 帖子状态 - ; - logger.info("sql语句:"+queryWrapper.getSqlSegment()); - ForumEntity forumEntity = forumService.selectOne(queryWrapper); // 查询是否已存在相同数据 - if(forumEntity==null){ - forum.setInsertTime(new Date()); // 设置插入时间 - forum.setCreateTime(new Date()); // 设置创建时间 - forumService.insert(forum); // 插入新数据 - - return R.ok(); - }else { - return R.error(511,"表中有相同数据"); // 数据已存在返回错误 - } - } -} ->>>>>>> develop diff --git a/src/main/java/com/controller/JianshenkechengCollectionController.java b/src/main/java/com/controller/JianshenkechengCollectionController.java index 0a39ed0..4268dc2 100644 --- a/src/main/java/com/controller/JianshenkechengCollectionController.java +++ b/src/main/java/com/controller/JianshenkechengCollectionController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; @@ -244,238 +243,16 @@ public class JianshenkechengCollectionController { //查询是否重复 jianshenkechengCollectionService.insertBatch(jianshenkechengCollectionList); return R.ok(); -======= -package com.controller; // 定义包路径,表示该文件位于com.controller包下 - -import java.io.File; // 导入文件操作类 -import java.math.BigDecimal; // 导入高精度数学计算类 -import java.net.URL; // 导入网络URL处理类 -import java.text.SimpleDateFormat; // 导入日期格式化类 -import com.alibaba.fastjson.JSONObject; // 导入FastJSON的JSON对象类 -import java.util.*; // 导入Java常用工具类(集合、日期等) -import org.springframework.beans.BeanUtils; // 导入Spring Bean属性复制工具类 -import javax.servlet.http.HttpServletRequest; // 导入HTTP请求处理类 -import org.springframework.web.context.ContextLoader; // 导入Spring上下文加载器 -import javax.servlet.ServletContext; // 导入Servlet上下文接口 -import com.service.TokenService; // 导入自定义的Token服务类 -import com.utils.*; // 导入自定义工具类 -import java.lang.reflect.InvocationTargetException; // 导入反射异常类 - -import com.service.DictionaryService; // 导入自定义的字典服务类 -import org.apache.commons.lang3.StringUtils; // 导入Apache字符串工具类 -import com.annotation.IgnoreAuth; // 导入自定义的忽略认证注解 -import org.slf4j.Logger; // 导入日志接口 -import org.slf4j.LoggerFactory; // 导入日志工厂类 -import org.springframework.beans.factory.annotation.Autowired; // 导入Spring自动注入注解 -import org.springframework.stereotype.Controller; // 导入Spring控制器注解 -import org.springframework.web.bind.annotation.*; // 导入Spring Web注解 -import com.baomidou.mybatisplus.mapper.EntityWrapper; // 导入MyBatis Plus查询条件构造器 -import com.baomidou.mybatisplus.mapper.Wrapper; // 导入MyBatis Plus包装器接口 -import com.entity.*; // 导入实体类 -import com.entity.view.*; // 导入视图实体类 -import com.service.*; // 导入服务类 -import com.utils.PageUtils; // 导入分页工具类 -import com.utils.R; // 导入统一返回结果类 -import com.alibaba.fastjson.*; // 导入FastJSON相关类 - - - //课程收藏 - //后端接口 - //@author - // @email - -@RestController // 标识为RESTful控制器 -@Controller // 标识为Spring控制器 -@RequestMapping("/jianshenkechengCollection") // 定义请求映射路径 -public class JianshenkechengCollectionController { - private static final Logger logger = LoggerFactory.getLogger(JianshenkechengCollectionController.class); // 日志记录器 - - private static final String TABLE_NAME = "jianshenkechengCollection"; // 数据库表名 - - @Autowired - private JianshenkechengCollectionService jianshenkechengCollectionService; // 课程收藏服务 - - @Autowired - private TokenService tokenService; // Token服务 - - @Autowired - private DictionaryService dictionaryService; // 字典服务 - @Autowired - private ForumService forumService; // 健身论坛服务 - @Autowired - private JianshenkechengService jianshenkechengService; // 健身课程服务 - @Autowired - private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 课程留言服务 - @Autowired - private JiaolianService jiaolianService; // 教练服务 - @Autowired - private JiaolianYuyueService jiaolianYuyueService; // 教练预约申请服务 - @Autowired - private NewsService newsService; // 健身资讯服务 - @Autowired - private SingleSeachService singleSeachService; // 单页数据服务 - @Autowired - private YonghuService yonghuService; // 用户服务 - @Autowired - private UsersService usersService; // 管理员服务 - - - //后端列表 - @RequestMapping("/page") // 处理分页请求 - public R page(@RequestParam Map params, HttpServletRequest request){ - logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录日志 - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) - return R.error(511,"永不会进入"); // 永远不会执行的代码 - else if("用户".equals(role)) - params.put("yonghuId",request.getSession().getAttribute("userId")); // 如果是用户角色,添加用户ID参数 - else if("教练".equals(role)) - params.put("jiaolianId",request.getSession().getAttribute("userId")); // 如果是教练角色,添加教练ID参数 - CommonUtil.checkMap(params); // 检查参数 - PageUtils page = jianshenkechengCollectionService.queryPage(params); // 查询分页数据 - - // 字典表数据转换 - List list =(List)page.getList(); - for(JianshenkechengCollectionView c:list){ - // 修改对应字典表字段 - dictionaryService.dictionaryConvert(c, request); - } - return R.ok().put("data", page); // 返回分页数据 - } - - - //后端详情 - @RequestMapping("/info/{id}") // 处理详情请求 - public R info(@PathVariable("id") Long id, HttpServletRequest request){ - logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录日志 - JianshenkechengCollectionEntity jianshenkechengCollection = jianshenkechengCollectionService.selectById(id); // 根据ID查询收藏记录 - if(jianshenkechengCollection !=null){ - // entity转view - JianshenkechengCollectionView view = new JianshenkechengCollectionView(); - BeanUtils.copyProperties( jianshenkechengCollection , view ); // 把实体数据重构到view中 - // 级联表 健身课程 - JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(jianshenkechengCollection.getJianshenkechengId()); - if(jianshenkecheng != null){ - BeanUtils.copyProperties( jianshenkecheng , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"}); // 把级联的数据添加到view中,并排除id和创建时间字段 - view.setJianshenkechengId(jianshenkecheng.getId()); - } - // 级联表 用户 - YonghuEntity yonghu = yonghuService.selectById(jianshenkechengCollection.getYonghuId()); - if(yonghu != null){ - BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"}); // 把级联的数据添加到view中,并排除id和创建时间字段 - view.setYonghuId(yonghu.getId()); - } - // 修改对应字典表字段 - dictionaryService.dictionaryConvert(view, request); - return R.ok().put("data", view); // 返回详情数据 - }else { - return R.error(511,"查不到数据"); // 查询不到数据返回错误 - } - } - - - //后端保存 - @RequestMapping("/save") // 处理保存请求 - public R save(@RequestBody JianshenkechengCollectionEntity jianshenkechengCollection, HttpServletRequest request){ - logger.debug("save方法:,,Controller:{},,jianshenkechengCollection:{}",this.getClass().getName(),jianshenkechengCollection.toString()); // 记录日志 - - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) - return R.error(511,"永远不会进入"); // 永远不会执行的代码 - else if("用户".equals(role)) - jianshenkechengCollection.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); // 如果是用户角色,设置用户ID - - Wrapper queryWrapper = new EntityWrapper() - .eq("jianshenkecheng_id", jianshenkechengCollection.getJianshenkechengId()) // 健身课程ID - .eq("yonghu_id", jianshenkechengCollection.getYonghuId()) // 用户ID - .eq("jianshenkecheng_collection_types", jianshenkechengCollection.getJianshenkechengCollectionTypes()) // 收藏类型 - ; - - logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句 - JianshenkechengCollectionEntity jianshenkechengCollectionEntity = jianshenkechengCollectionService.selectOne(queryWrapper); // 查询是否已存在相同数据 - if(jianshenkechengCollectionEntity==null){ - jianshenkechengCollection.setInsertTime(new Date()); // 设置插入时间 - jianshenkechengCollection.setCreateTime(new Date()); // 设置创建时间 - jianshenkechengCollectionService.insert(jianshenkechengCollection); // 插入新数据 - return R.ok(); // 返回成功 - }else { - return R.error(511,"表中有相同数据"); // 数据已存在返回错误 - } - } - - - //后端修改 - @RequestMapping("/update") // 处理更新请求 - public R update(@RequestBody JianshenkechengCollectionEntity jianshenkechengCollection, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { - logger.debug("update方法:,,Controller:{},,jianshenkechengCollection:{}",this.getClass().getName(),jianshenkechengCollection.toString()); // 记录日志 - JianshenkechengCollectionEntity oldJianshenkechengCollectionEntity = jianshenkechengCollectionService.selectById(jianshenkechengCollection.getId()); // 查询原先数据 - - jianshenkechengCollectionService.updateById(jianshenkechengCollection); // 根据ID更新数据 - return R.ok(); // 返回成功 - } - - - //删除 - @RequestMapping("/delete") // 处理删除请求 - public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ - logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); // 记录日志 - List oldJianshenkechengCollectionList =jianshenkechengCollectionService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据 - jianshenkechengCollectionService.deleteBatchIds(Arrays.asList(ids)); // 批量删除 - - return R.ok(); // 返回成功 - } - - - //批量上传 - @RequestMapping("/batchInsert") // 处理批量上传请求 - public R save( String fileName, HttpServletRequest request){ - logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); // 记录日志 - Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取用户ID - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 创建日期格式化对象 - try { - List jianshenkechengCollectionList = new ArrayList<>(); // 创建收藏记录列表 - Map> seachFields= new HashMap<>(); // 创建查询字段映射 - Date date = new Date(); // 当前时间 - int lastIndexOf = fileName.lastIndexOf("."); // 获取文件后缀位置 - if(lastIndexOf == -1){ - return R.error(511,"该文件没有后缀"); // 文件无后缀返回错误 - }else{ - String suffix = fileName.substring(lastIndexOf); // 获取文件后缀 - if(!".xls".equals(suffix)){ - return R.error(511,"只支持后缀为xls的excel文件"); // 文件格式不正确返回错误 - }else{ - URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 获取文件路径 - File file = new File(resource.getFile()); // 创建文件对象 - if(!file.exists()){ - return R.error(511,"找不到上传文件,请联系管理员"); // 文件不存在返回错误 - }else{ - List> dataList = PoiUtil.poiImport(file.getPath()); // 读取xls文件 - dataList.remove(0); // 删除第一行提示信息 - for(List data:dataList){ - // 循环处理每行数据 - JianshenkechengCollectionEntity jianshenkechengCollectionEntity = new JianshenkechengCollectionEntity(); - jianshenkechengCollectionList.add(jianshenkechengCollectionEntity); // 添加到列表 - } - // 批量插入数据 - jianshenkechengCollectionService.insertBatch(jianshenkechengCollectionList); - return R.ok(); // 返回成功 ->>>>>>> develop } } } }catch (Exception e){ -<<<<<<< HEAD e.printStackTrace(); return R.error(511,"批量插入数据异常,请联系管理员"); -======= - e.printStackTrace(); // 打印异常堆栈 - return R.error(511,"批量插入数据异常,请联系管理员"); // 异常处理 ->>>>>>> develop } } -<<<<<<< HEAD /** @@ -559,76 +336,3 @@ public class JianshenkechengCollectionController { } -======= - //前端列表 - @IgnoreAuth // 忽略认证 - @RequestMapping("/list") // 处理列表请求 - public R list(@RequestParam Map params, HttpServletRequest request){ - logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录日志 - - CommonUtil.checkMap(params); // 检查参数 - PageUtils page = jianshenkechengCollectionService.queryPage(params); // 查询分页数据 - - // 字典表数据转换 - List list =(List)page.getList(); - for(JianshenkechengCollectionView c:list) - dictionaryService.dictionaryConvert(c, request); // 修改对应字典表字段 - - return R.ok().put("data", page); // 返回分页数据 - } - - - //前端详情 - @RequestMapping("/detail/{id}") // 处理详情请求 - public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ - logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录日志 - JianshenkechengCollectionEntity jianshenkechengCollection = jianshenkechengCollectionService.selectById(id); // 根据ID查询收藏记录 - if(jianshenkechengCollection !=null){ - // entity转view - JianshenkechengCollectionView view = new JianshenkechengCollectionView(); - BeanUtils.copyProperties( jianshenkechengCollection , view ); // 把实体数据重构到view中 - - // 级联表健身课程 - JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(jianshenkechengCollection.getJianshenkechengId()); - if(jianshenkecheng != null){ - BeanUtils.copyProperties( jianshenkecheng , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"}); // 把级联的数据添加到view中,并排除id和创建时间字段 - view.setJianshenkechengId(jianshenkecheng.getId()); - } - // 级联表用户 - YonghuEntity yonghu = yonghuService.selectById(jianshenkechengCollection.getYonghuId()); - if(yonghu != null){ - BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"}); // 把级联的数据添加到view中,并排除id和创建时间字段 - view.setYonghuId(yonghu.getId()); - } - // 修改对应字典表字段 - dictionaryService.dictionaryConvert(view, request); - return R.ok().put("data", view); // 返回详情数据 - }else { - return R.error(511,"查不到数据"); // 查询不到数据返回错误 - } - } - - - //前端保存 - @RequestMapping("/add") // 处理添加请求 - public R add(@RequestBody JianshenkechengCollectionEntity jianshenkechengCollection, HttpServletRequest request){ - logger.debug("add方法:,,Controller:{},,jianshenkechengCollection:{}",this.getClass().getName(),jianshenkechengCollection.toString()); // 记录日志 - Wrapper queryWrapper = new EntityWrapper() - .eq("jianshenkecheng_id", jianshenkechengCollection.getJianshenkechengId()) // 健身课程ID - .eq("yonghu_id", jianshenkechengCollection.getYonghuId()) // 用户ID - .eq("jianshenkecheng_collection_types", jianshenkechengCollection.getJianshenkechengCollectionTypes()) // 收藏类型 - ; - logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句 - JianshenkechengCollectionEntity jianshenkechengCollectionEntity = jianshenkechengCollectionService.selectOne(queryWrapper); // 查询是否已存在相同数据 - if(jianshenkechengCollectionEntity==null){ - jianshenkechengCollection.setInsertTime(new Date()); // 设置插入时间 - jianshenkechengCollection.setCreateTime(new Date()); // 设置创建时间 - jianshenkechengCollectionService.insert(jianshenkechengCollection); // 插入新数据 - - return R.ok(); // 返回成功 - }else { - return R.error(511,"您已经收藏过了"); // 已经收藏过返回错误 - } - } -} ->>>>>>> develop diff --git a/src/main/java/com/controller/JianshenkechengController.java b/src/main/java/com/controller/JianshenkechengController.java index d17b73c..8b4235a 100644 --- a/src/main/java/com/controller/JianshenkechengController.java +++ b/src/main/java/com/controller/JianshenkechengController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; @@ -271,260 +270,16 @@ public class JianshenkechengController { //查询是否重复 jianshenkechengService.insertBatch(jianshenkechengList); return R.ok(); -======= -package com.controller; // 声明包路径,表示该文件位于com.controller包下 - -import java.io.File; // 导入文件操作类 -import java.math.BigDecimal; // 导入高精度数学计算类 -import java.net.URL; // 导入网络URL处理类 -import java.text.SimpleDateFormat; // 导入日期格式化类 -import com.alibaba.fastjson.JSONObject; // 导入FastJSON的JSON对象类 -import java.util.*; // 导入Java常用工具类(集合、日期等) -import org.springframework.beans.BeanUtils; // 导入Spring Bean属性复制工具类 -import javax.servlet.http.HttpServletRequest; // 导入HTTP请求处理类 -import org.springframework.web.context.ContextLoader; // 导入Spring上下文加载器 -import javax.servlet.ServletContext; // 导入Servlet上下文接口 -import com.service.TokenService; // 导入自定义的Token服务类 -import com.utils.*; // 导入自定义工具类 -import java.lang.reflect.InvocationTargetException; // 导入反射异常类 - -import com.service.DictionaryService; // 导入自定义的字典服务类 -import org.apache.commons.lang3.StringUtils; // 导入Apache字符串工具类 -import com.annotation.IgnoreAuth; // 导入自定义的忽略认证注解 -import org.slf4j.Logger; // 导入日志接口 -import org.slf4j.LoggerFactory; // 导入日志工厂类 -import org.springframework.beans.factory.annotation.Autowired; // 导入Spring自动注入注解 -import org.springframework.stereotype.Controller; // 导入Spring控制器注解 -import org.springframework.web.bind.annotation.*; // 导入Spring Web注解 -import com.baomidou.mybatisplus.mapper.EntityWrapper; // 导入MyBatis Plus查询条件构造器 -import com.baomidou.mybatisplus.mapper.Wrapper; // 导入MyBatis Plus包装器接口 -import com.entity.*; // 导入实体类 -import com.entity.view.*; // 导入视图实体类 -import com.service.*; // 导入服务类 -import com.utils.PageUtils; // 导入分页工具类 -import com.utils.R; // 导入统一返回结果类 -import com.alibaba.fastjson.*; // 导入FastJSON相关类 - - - // 健身课程 - //后端接口 - //@author - //@email - -@RestController // 标识为RESTful控制器 -@Controller // 标识为Spring控制器 -@RequestMapping("/jianshenkecheng") // 定义请求映射路径 -public class JianshenkechengController { - private static final Logger logger = LoggerFactory.getLogger(JianshenkechengController.class); // 日志记录器 - - private static final String TABLE_NAME = "jianshenkecheng"; // 数据库表名 - - @Autowired - private JianshenkechengService jianshenkechengService; // 健身课程服务 - - @Autowired - private TokenService tokenService; // Token服务 - - @Autowired - private DictionaryService dictionaryService; // 字典服务 - @Autowired - private ForumService forumService; // 健身论坛服务 - @Autowired - private JianshenkechengCollectionService jianshenkechengCollectionService; // 课程收藏服务 - @Autowired - private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 课程留言服务 - @Autowired - private JiaolianService jiaolianService; // 教练服务 - @Autowired - private JiaolianYuyueService jiaolianYuyueService; // 教练预约申请服务 - @Autowired - private NewsService newsService; // 健身资讯服务 - @Autowired - private SingleSeachService singleSeachService; // 单页数据服务 - @Autowired - private YonghuService yonghuService; // 用户服务 - @Autowired - private UsersService usersService; // 管理员服务 - - - //后端列表 - @RequestMapping("/page") // 处理分页请求 - public R page(@RequestParam Map params, HttpServletRequest request){ - logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录日志 - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) - return R.error(511,"永不会进入"); // 永远不会执行的代码 - else if("用户".equals(role)) - params.put("yonghuId",request.getSession().getAttribute("userId")); // 如果是用户角色,添加用户ID参数 - else if("教练".equals(role)) - params.put("jiaolianId",request.getSession().getAttribute("userId")); // 如果是教练角色,添加教练ID参数 - params.put("dataDeleteStart",1);params.put("dataDeleteEnd",1); // 设置逻辑删除参数 - CommonUtil.checkMap(params); // 检查参数 - PageUtils page = jianshenkechengService.queryPage(params); // 查询分页数据 - - // 字典表数据转换 - List list =(List)page.getList(); - for(JianshenkechengView c:list){ - // 修改对应字典表字段 - dictionaryService.dictionaryConvert(c, request); - } - return R.ok().put("data", page); // 返回分页数据 - } - - - //后端详情 - @RequestMapping("/info/{id}") // 处理详情请求 - public R info(@PathVariable("id") Long id, HttpServletRequest request){ - logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录日志 - JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(id); // 根据ID查询健身课程 - if(jianshenkecheng !=null){ - // entity转view - JianshenkechengView view = new JianshenkechengView(); - BeanUtils.copyProperties( jianshenkecheng , view ); // 把实体数据重构到view中 - // 级联表 教练 - JiaolianEntity jiaolian = jiaolianService.selectById(jianshenkecheng.getJiaolianId()); - if(jiaolian != null){ - BeanUtils.copyProperties( jiaolian , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "jiaolianId"}); // 把级联的数据添加到view中,并排除id和创建时间字段 - view.setJiaolianId(jiaolian.getId()); - } - // 修改对应字典表字段 - dictionaryService.dictionaryConvert(view, request); - return R.ok().put("data", view); // 返回详情数据 - }else { - return R.error(511,"查不到数据"); // 查询不到数据返回错误 - } - } - - - //后端保存 - @RequestMapping("/save") // 处理保存请求 - public R save(@RequestBody JianshenkechengEntity jianshenkecheng, HttpServletRequest request){ - logger.debug("save方法:,,Controller:{},,jianshenkecheng:{}",this.getClass().getName(),jianshenkecheng.toString()); // 记录日志 - - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) - return R.error(511,"永远不会进入"); // 永远不会执行的代码 - else if("教练".equals(role)) - jianshenkecheng.setJiaolianId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); // 如果是教练角色,设置教练ID - - Wrapper queryWrapper = new EntityWrapper() - .eq("jiaolian_id", jianshenkecheng.getJiaolianId()) // 教练ID - .eq("jianshenkecheng_name", jianshenkecheng.getJianshenkechengName()) // 课程名称 - .eq("jianshenkecheng_video", jianshenkecheng.getJianshenkechengVideo()) // 课程视频 - .eq("zan_number", jianshenkecheng.getZanNumber()) // 赞数 - .eq("cai_number", jianshenkecheng.getCaiNumber()) // 踩数 - .eq("jianshenkecheng_types", jianshenkecheng.getJianshenkechengTypes()) // 课程类型 - .eq("data_delete", 1) // 逻辑删除字段 - ; - - logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句 - JianshenkechengEntity jianshenkechengEntity = jianshenkechengService.selectOne(queryWrapper); // 查询是否已存在相同数据 - if(jianshenkechengEntity==null){ - jianshenkecheng.setZanNumber(1); // 设置默认赞数 - jianshenkecheng.setCaiNumber(1); // 设置默认踩数 - jianshenkecheng.setJianshenkechengClicknum(1); // 设置默认点击量 - jianshenkecheng.setDataDelete(1); // 设置逻辑删除状态 - jianshenkecheng.setInsertTime(new Date()); // 设置插入时间 - jianshenkecheng.setCreateTime(new Date()); // 设置创建时间 - jianshenkechengService.insert(jianshenkecheng); // 插入新数据 - return R.ok(); // 返回成功 - }else { - return R.error(511,"表中有相同数据"); // 数据已存在返回错误 - } - } - - - //后端修改 - @RequestMapping("/update") // 处理更新请求 - public R update(@RequestBody JianshenkechengEntity jianshenkecheng, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { - logger.debug("update方法:,,Controller:{},,jianshenkecheng:{}",this.getClass().getName(),jianshenkecheng.toString()); // 记录日志 - JianshenkechengEntity oldJianshenkechengEntity = jianshenkechengService.selectById(jianshenkecheng.getId()); // 查询原先数据 - - if("".equals(jianshenkecheng.getJianshenkechengPhoto()) || "null".equals(jianshenkecheng.getJianshenkechengPhoto())){ - jianshenkecheng.setJianshenkechengPhoto(null); // 处理空图片路径 - } - if("".equals(jianshenkecheng.getJianshenkechengVideo()) || "null".equals(jianshenkecheng.getJianshenkechengVideo())){ - jianshenkecheng.setJianshenkechengVideo(null); // 处理空视频路径 - } - if("".equals(jianshenkecheng.getJianshenkechengContent()) || "null".equals(jianshenkecheng.getJianshenkechengContent())){ - jianshenkecheng.setJianshenkechengContent(null); // 处理空内容 - } - - jianshenkechengService.updateById(jianshenkecheng); // 根据ID更新数据 - return R.ok(); // 返回成功 - } - - - //删除 - @RequestMapping("/delete") // 处理删除请求 - public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ - logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); // 记录日志 - List oldJianshenkechengList =jianshenkechengService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据 - ArrayList list = new ArrayList<>(); // 创建更新列表 - for(Integer id:ids){ - JianshenkechengEntity jianshenkechengEntity = new JianshenkechengEntity(); - jianshenkechengEntity.setId(id); - jianshenkechengEntity.setDataDelete(2); // 设置逻辑删除状态为已删除 - list.add(jianshenkechengEntity); // 添加到更新列表 - } - if(list != null && list.size() >0){ - jianshenkechengService.updateBatchById(list); // 批量更新删除状态 - } - - return R.ok(); // 返回成功 - } - - - //批量上传 - @RequestMapping("/batchInsert") // 处理批量上传请求 - public R save( String fileName, HttpServletRequest request){ - logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); // 记录日志 - Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取用户ID - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 创建日期格式化对象 - try { - List jianshenkechengList = new ArrayList<>(); // 创建健身课程列表 - Map> seachFields= new HashMap<>(); // 创建查询字段映射 - Date date = new Date(); // 当前时间 - int lastIndexOf = fileName.lastIndexOf("."); // 获取文件后缀位置 - if(lastIndexOf == -1){ - return R.error(511,"该文件没有后缀"); // 文件无后缀返回错误 - }else{ - String suffix = fileName.substring(lastIndexOf); // 获取文件后缀 - if(!".xls".equals(suffix)){ - return R.error(511,"只支持后缀为xls的excel文件"); // 文件格式不正确返回错误 - }else{ - URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 获取文件路径 - File file = new File(resource.getFile()); // 创建文件对象 - if(!file.exists()){ - return R.error(511,"找不到上传文件,请联系管理员"); // 文件不存在返回错误 - }else{ - List> dataList = PoiUtil.poiImport(file.getPath()); // 读取xls文件 - dataList.remove(0); // 删除第一行提示信息 - for(List data:dataList){ - // 循环处理每行数据 - JianshenkechengEntity jianshenkechengEntity = new JianshenkechengEntity(); - jianshenkechengList.add(jianshenkechengEntity); // 添加到列表 - } - // 批量插入数据 - jianshenkechengService.insertBatch(jianshenkechengList); - return R.ok(); // 返回成功 ->>>>>>> develop } } } }catch (Exception e){ -<<<<<<< HEAD e.printStackTrace(); return R.error(511,"批量插入数据异常,请联系管理员"); -======= - e.printStackTrace(); // 打印异常堆栈 - return R.error(511,"批量插入数据异常,请联系管理员"); // 异常处理 ->>>>>>> develop } } -<<<<<<< HEAD /** * 个性推荐 @@ -678,148 +433,3 @@ public class JianshenkechengController { } -======= - //个性推荐 - @IgnoreAuth // 忽略认证 - @RequestMapping("/gexingtuijian") // 处理个性推荐请求 - public R gexingtuijian(@RequestParam Map params, HttpServletRequest request){ - logger.debug("gexingtuijian方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录日志 - CommonUtil.checkMap(params); // 检查参数 - List returnJianshenkechengViewList = new ArrayList<>(); // 创建返回课程列表 - - //查看收藏 - Map params1 = new HashMap<>(params);params1.put("sort","id");params1.put("yonghuId",request.getSession().getAttribute("userId")); // 设置收藏查询参数 - params1.put("shangxiaTypes",1); // 上架状态 - params1.put("jianshenkechengYesnoTypes",2); // 审核通过状态 - PageUtils pageUtils = jianshenkechengCollectionService.queryPage(params1); // 查询收藏分页数据 - List collectionViewsList =(List)pageUtils.getList(); // 获取收藏列表 - Map typeMap=new HashMap<>(); // 创建课程类型统计Map - for(JianshenkechengCollectionView collectionView:collectionViewsList){ - Integer jianshenkechengTypes = collectionView.getJianshenkechengTypes(); // 获取课程类型 - if(typeMap.containsKey(jianshenkechengTypes)){ - typeMap.put(jianshenkechengTypes,typeMap.get(jianshenkechengTypes)+1); // 统计类型数量 - }else{ - typeMap.put(jianshenkechengTypes,1); // 初始化类型数量 - } - } - List typeList = new ArrayList<>(); // 创建排序后的类型列表 - typeMap.entrySet().stream().sorted((o1, o2) -> o2.getValue() - o1.getValue()).forEach(e -> typeList.add(e.getKey())); // 按数量从多到少排序 - Integer limit = Integer.valueOf(String.valueOf(params.get("limit"))); // 获取推荐数量限制 - for(Integer type:typeList){ - Map params2 = new HashMap<>(params);params2.put("jianshenkechengTypes",type); // 设置类型查询参数 - params2.put("shangxiaTypes",1); // 上架状态 - params2.put("jianshenkechengYesnoTypes",2); // 审核通过状态 - PageUtils pageUtils1 = jianshenkechengService.queryPage(params2); // 查询课程分页数据 - List jianshenkechengViewList =(List)pageUtils1.getList(); // 获取课程列表 - returnJianshenkechengViewList.addAll(jianshenkechengViewList); // 添加到返回列表 - if(returnJianshenkechengViewList.size()>= limit) break; // 达到推荐数量限制时跳出循环 - } - params.put("shangxiaTypes",1); // 设置上架状态 - params.put("jianshenkechengYesnoTypes",2); // 设置审核通过状态 - //正常查询出来商品,用于补全推荐缺少的数据 - PageUtils page = jianshenkechengService.queryPage(params); // 查询课程分页数据 - if(returnJianshenkechengViewList.size() jianshenkechengViewList =(List)page.getList(); // 获取课程列表 - for(JianshenkechengView jianshenkechengView:jianshenkechengViewList){ - Boolean addFlag = true; - for(JianshenkechengView returnJianshenkechengView:returnJianshenkechengViewList){ - if(returnJianshenkechengView.getId().intValue() ==jianshenkechengView.getId().intValue()) addFlag=false; // 已存在的课程不再添加 - } - if(addFlag){ - toAddNum=toAddNum-1; - returnJianshenkechengViewList.add(jianshenkechengView); // 添加到返回列表 - if(toAddNum==0) break; // 补充足够数量后跳出循环 - } - } - }else { - returnJianshenkechengViewList = returnJianshenkechengViewList.subList(0, limit); // 截取指定数量的推荐课程 - } - - for(JianshenkechengView c:returnJianshenkechengViewList) - dictionaryService.dictionaryConvert(c, request); // 转换字典字段 - page.setList(returnJianshenkechengViewList); // 设置返回列表 - return R.ok().put("data", page); // 返回推荐数据 - } - - - //前端列表 - @IgnoreAuth // 忽略认证 - @RequestMapping("/list") // 处理列表请求 - public R list(@RequestParam Map params, HttpServletRequest request){ - logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录日志 - - CommonUtil.checkMap(params); // 检查参数 - PageUtils page = jianshenkechengService.queryPage(params); // 查询分页数据 - - // 字典表数据转换 - List list =(List)page.getList(); - for(JianshenkechengView c:list) - dictionaryService.dictionaryConvert(c, request); // 转换字典字段 - - return R.ok().put("data", page); // 返回分页数据 - } - - - //前端详情 - @RequestMapping("/detail/{id}") // 处理详情请求 - public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ - logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录日志 - JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(id); // 根据ID查询课程 - if(jianshenkecheng !=null){ - - //点击数量加1 - jianshenkecheng.setJianshenkechengClicknum(jianshenkecheng.getJianshenkechengClicknum()+1); // 增加点击量 - jianshenkechengService.updateById(jianshenkecheng); // 更新课程 - - //entity转view - JianshenkechengView view = new JianshenkechengView(); - BeanUtils.copyProperties( jianshenkecheng , view ); // 把实体数据重构到view中 - - //级联表 - JiaolianEntity jiaolian = jiaolianService.selectById(jianshenkecheng.getJiaolianId()); // 查询关联教练 - if(jiaolian != null){ - BeanUtils.copyProperties( jiaolian , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "jiaolianId"}); // 把级联的数据添加到view中,并排除id和创建时间字段 - view.setJiaolianId(jiaolian.getId()); - } - //修改对应字典表字段 - dictionaryService.dictionaryConvert(view, request); // 转换字典字段 - return R.ok().put("data", view); // 返回详情数据 - }else { - return R.error(511,"查不到数据"); // 查询不到数据返回错误 - } - } - - - //前端保存 - @RequestMapping("/add") // 处理添加请求 - public R add(@RequestBody JianshenkechengEntity jianshenkecheng, HttpServletRequest request){ - logger.debug("add方法:,,Controller:{},,jianshenkecheng:{}",this.getClass().getName(),jianshenkecheng.toString()); // 记录日志 - Wrapper queryWrapper = new EntityWrapper() - .eq("jiaolian_id", jianshenkecheng.getJiaolianId()) // 教练ID - .eq("jianshenkecheng_name", jianshenkecheng.getJianshenkechengName()) // 课程名称 - .eq("jianshenkecheng_video", jianshenkecheng.getJianshenkechengVideo()) // 课程视频 - .eq("zan_number", jianshenkecheng.getZanNumber()) // 赞数 - .eq("cai_number", jianshenkecheng.getCaiNumber()) // 踩数 - .eq("jianshenkecheng_types", jianshenkecheng.getJianshenkechengTypes()) // 课程类型 - .eq("jianshenkecheng_clicknum", jianshenkecheng.getJianshenkechengClicknum()) // 点击量 - .eq("data_delete", jianshenkecheng.getDataDelete()) // 逻辑删除状态 - ; - logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句 - JianshenkechengEntity jianshenkechengEntity = jianshenkechengService.selectOne(queryWrapper); // 查询是否已存在相同数据 - if(jianshenkechengEntity==null){ - jianshenkecheng.setZanNumber(1); // 设置默认赞数 - jianshenkecheng.setCaiNumber(1); // 设置默认踩数 - jianshenkecheng.setJianshenkechengClicknum(1); // 设置默认点击量 - jianshenkecheng.setDataDelete(1); // 设置逻辑删除状态 - jianshenkecheng.setInsertTime(new Date()); // 设置插入时间 - jianshenkecheng.setCreateTime(new Date()); // 设置创建时间 - jianshenkechengService.insert(jianshenkecheng); // 插入新数据 - - return R.ok(); // 返回成功 - }else { - return R.error(511,"表中有相同数据"); // 数据已存在返回错误 - } - } -} ->>>>>>> develop diff --git a/src/main/java/com/controller/JianshenkechengLiuyanController.java b/src/main/java/com/controller/JianshenkechengLiuyanController.java index 7ce51c2..09e870c 100644 --- a/src/main/java/com/controller/JianshenkechengLiuyanController.java +++ b/src/main/java/com/controller/JianshenkechengLiuyanController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; @@ -242,238 +241,16 @@ public class JianshenkechengLiuyanController { //查询是否重复 jianshenkechengLiuyanService.insertBatch(jianshenkechengLiuyanList); return R.ok(); -======= -package com.controller; // 声明包路径,表示该文件位于com.controller包下 - -import java.io.File; // 导入文件操作类,用于处理文件上传 -import java.math.BigDecimal; // 导入高精度数学计算类,用于处理金额计算 -import java.net.URL; // 导入网络URL处理类,用于获取资源路径 -import java.text.SimpleDateFormat; // 导入日期格式化类,用于日期格式转换 -import com.alibaba.fastjson.JSONObject; // 导入FastJSON的JSON对象类,用于JSON处理 -import java.util.*; // 导入Java常用工具类(集合、日期等) -import org.springframework.beans.BeanUtils; // 导入Spring Bean属性复制工具类 -import javax.servlet.http.HttpServletRequest; // 导入HTTP请求处理类 -import org.springframework.web.context.ContextLoader; // 导入Spring上下文加载器 -import javax.servlet.ServletContext; // 导入Servlet上下文接口 -import com.service.TokenService; // 导入自定义的Token服务类 -import com.utils.*; // 导入自定义工具类 -import java.lang.reflect.InvocationTargetException; // 导入反射异常类 - -import com.service.DictionaryService; // 导入自定义的字典服务类 -import org.apache.commons.lang3.StringUtils; // 导入Apache字符串工具类 -import com.annotation.IgnoreAuth; // 导入自定义的忽略认证注解 -import org.slf4j.Logger; // 导入日志接口 -import org.slf4j.LoggerFactory; // 导入日志工厂类 -import org.springframework.beans.factory.annotation.Autowired; // 导入Spring自动注入注解 -import org.springframework.stereotype.Controller; // 导入Spring控制器注解 -import org.springframework.web.bind.annotation.*; // 导入Spring Web注解 -import com.baomidou.mybatisplus.mapper.EntityWrapper; // 导入MyBatis Plus查询条件构造器 -import com.baomidou.mybatisplus.mapper.Wrapper; // 导入MyBatis Plus包装器接口 -import com.entity.*; // 导入实体类 -import com.entity.view.*; // 导入视图实体类 -import com.service.*; // 导入服务类 -import com.utils.PageUtils; // 导入分页工具类 -import com.utils.R; // 导入统一返回结果类 -import com.alibaba.fastjson.*; // 导入FastJSON相关类 - - - //课程留言 - //后端接口 - //@author - //@email -@RestController // 标识为RESTful控制器,用于处理HTTP请求 -@Controller // 标识为Spring控制器 -@RequestMapping("/jianshenkechengLiuyan") // 定义请求映射路径 -public class JianshenkechengLiuyanController { - private static final Logger logger = LoggerFactory.getLogger(JianshenkechengLiuyanController.class); // 日志记录器,用于记录日志信息 - - private static final String TABLE_NAME = "jianshenkechengLiuyan"; // 数据库表名常量 - - @Autowired - private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 自动注入课程留言服务 - - @Autowired - private TokenService tokenService; // 自动注入Token服务 - - @Autowired - private DictionaryService dictionaryService; // 自动注入字典服务 - @Autowired - private ForumService forumService; // 自动注入健身论坛服务 - @Autowired - private JianshenkechengService jianshenkechengService; // 自动注入健身课程服务 - @Autowired - private JianshenkechengCollectionService jianshenkechengCollectionService; // 自动注入课程收藏服务 - @Autowired - private JiaolianService jiaolianService; // 自动注入教练服务 - @Autowired - private JiaolianYuyueService jiaolianYuyueService; // 自动注入教练预约申请服务 - @Autowired - private NewsService newsService; // 自动注入健身资讯服务 - @Autowired - private SingleSeachService singleSeachService; // 自动注入单页数据服务 - @Autowired - private YonghuService yonghuService; // 自动注入用户服务 - @Autowired - private UsersService usersService; // 自动注入管理员服务 - - - //后端列表 - //处理分页查询请求 - @RequestMapping("/page") // 映射分页查询请求 - public R page(@RequestParam Map params, HttpServletRequest request){ - logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录请求日志 - String role = String.valueOf(request.getSession().getAttribute("role")); // 从session中获取用户角色 - if(false) // 永远不会执行的代码块 - return R.error(511,"永不会进入"); // 返回错误信息 - else if("用户".equals(role)) // 如果是用户角色 - params.put("yonghuId",request.getSession().getAttribute("userId")); // 将用户ID添加到查询参数 - else if("教练".equals(role)) // 如果是教练角色 - params.put("jiaolianId",request.getSession().getAttribute("userId")); // 将教练ID添加到查询参数 - CommonUtil.checkMap(params); // 检查参数有效性 - PageUtils page = jianshenkechengLiuyanService.queryPage(params); // 调用服务层查询分页数据 - - // 字典表数据转换 - List list =(List)page.getList(); // 获取分页数据列表 - for(JianshenkechengLiuyanView c:list){ // 遍历列表 - dictionaryService.dictionaryConvert(c, request); // 转换字典字段 - } - return R.ok().put("data", page); // 返回分页数据 - } - - - //后端详情 - //根据ID查询单条留言详情 - @RequestMapping("/info/{id}") // 映射详情查询请求 - public R info(@PathVariable("id") Long id, HttpServletRequest request){ - logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录请求日志 - JianshenkechengLiuyanEntity jianshenkechengLiuyan = jianshenkechengLiuyanService.selectById(id); // 根据ID查询留言 - if(jianshenkechengLiuyan !=null){ // 如果查询到数据 - JianshenkechengLiuyanView view = new JianshenkechengLiuyanView(); // 创建视图对象 - BeanUtils.copyProperties(jianshenkechengLiuyan, view); // 复制属性到视图对象 - - // 查询关联的健身课程信息 - JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(jianshenkechengLiuyan.getJianshenkechengId()); - if(jianshenkecheng != null){ - BeanUtils.copyProperties(jianshenkecheng, view, new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"}); - view.setJianshenkechengId(jianshenkecheng.getId()); - } - - // 查询关联的用户信息 - YonghuEntity yonghu = yonghuService.selectById(jianshenkechengLiuyan.getYonghuId()); - if(yonghu != null){ - BeanUtils.copyProperties(yonghu, view, new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"}); - view.setYonghuId(yonghu.getId()); - } - - dictionaryService.dictionaryConvert(view, request); // 转换字典字段 - return R.ok().put("data", view); // 返回详情数据 - }else { - return R.error(511,"查不到数据"); // 返回错误信息 - } - } - - - //后端保存 - //处理新增留言请求 - @RequestMapping("/save") // 映射保存请求 - public R save(@RequestBody JianshenkechengLiuyanEntity jianshenkechengLiuyan, HttpServletRequest request){ - logger.debug("save方法:,,Controller:{},,jianshenkechengLiuyan:{}",this.getClass().getName(),jianshenkechengLiuyan.toString()); // 记录请求日志 - - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) // 永远不会执行的代码块 - return R.error(511,"永远不会进入"); // 返回错误信息 - else if("用户".equals(role)) // 如果是用户角色 - jianshenkechengLiuyan.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); // 设置用户ID - - jianshenkechengLiuyan.setCreateTime(new Date()); // 设置创建时间 - jianshenkechengLiuyan.setInsertTime(new Date()); // 设置插入时间 - jianshenkechengLiuyanService.insert(jianshenkechengLiuyan); // 调用服务层保存数据 - - return R.ok(); // 返回成功信息 - } - - - //后端修改 - //处理更新留言请 - @RequestMapping("/update") // 映射更新请求 - public R update(@RequestBody JianshenkechengLiuyanEntity jianshenkechengLiuyan, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { - logger.debug("update方法:,,Controller:{},,jianshenkechengLiuyan:{}",this.getClass().getName(),jianshenkechengLiuyan.toString()); // 记录请求日志 - JianshenkechengLiuyanEntity oldJianshenkechengLiuyanEntity = jianshenkechengLiuyanService.selectById(jianshenkechengLiuyan.getId()); // 查询原有数据 - - // 处理空值情况 - if("".equals(jianshenkechengLiuyan.getJianshenkechengLiuyanText()) || "null".equals(jianshenkechengLiuyan.getJianshenkechengLiuyanText())){ - jianshenkechengLiuyan.setJianshenkechengLiuyanText(null); - } - if("".equals(jianshenkechengLiuyan.getReplyText()) || "null".equals(jianshenkechengLiuyan.getReplyText())){ - jianshenkechengLiuyan.setReplyText(null); - } - - jianshenkechengLiuyan.setUpdateTime(new Date()); // 设置更新时间 - jianshenkechengLiuyanService.updateById(jianshenkechengLiuyan); // 调用服务层更新数据 - return R.ok(); // 返回成功信息 - } - - - //删除 - //处理删除留言请求 - @RequestMapping("/delete") // 映射删除请求 - public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ - logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); // 记录请求日志 - List oldJianshenkechengLiuyanList = jianshenkechengLiuyanService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据 - jianshenkechengLiuyanService.deleteBatchIds(Arrays.asList(ids)); // 调用服务层批量删除 - return R.ok(); // 返回成功信息 - } - - - //批量上传 - //处理批量导入数据请求 - @RequestMapping("/batchInsert") // 映射批量导入请求 - public R save(String fileName, HttpServletRequest request){ - logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); // 记录请求日志 - Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取用户ID - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 创建日期格式化对象 - try { - List jianshenkechengLiuyanList = new ArrayList<>(); // 创建数据列表 - Map> seachFields = new HashMap<>(); // 创建查询字段映射 - Date date = new Date(); // 当前时间 - int lastIndexOf = fileName.lastIndexOf("."); // 获取文件后缀位置 - if(lastIndexOf == -1){ // 如果没有后缀 - return R.error(511,"该文件没有后缀"); // 返回错误信息 - }else{ - String suffix = fileName.substring(lastIndexOf); // 获取文件后缀 - if(!".xls".equals(suffix)){ // 如果不是xls文件 - return R.error(511,"只支持后缀为xls的excel文件"); // 返回错误信息 - }else{ - URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 获取文件路径 - File file = new File(resource.getFile()); // 创建文件对象 - if(!file.exists()){ // 如果文件不存在 - return R.error(511,"找不到上传文件,请联系管理员"); // 返回错误信息 - }else{ - List> dataList = PoiUtil.poiImport(file.getPath()); // 读取Excel文件 - dataList.remove(0); // 删除标题行 - for(List data:dataList){ // 遍历数据行 - JianshenkechengLiuyanEntity jianshenkechengLiuyanEntity = new JianshenkechengLiuyanEntity(); // 创建实体对象 - jianshenkechengLiuyanList.add(jianshenkechengLiuyanEntity); // 添加到列表 - } - jianshenkechengLiuyanService.insertBatch(jianshenkechengLiuyanList); // 批量插入数据 - return R.ok(); // 返回成功信息 ->>>>>>> develop } } } }catch (Exception e){ -<<<<<<< HEAD e.printStackTrace(); return R.error(511,"批量插入数据异常,请联系管理员"); -======= - e.printStackTrace(); // 打印异常堆栈 - return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息 ->>>>>>> develop } } -<<<<<<< HEAD /** @@ -545,66 +322,3 @@ public class JianshenkechengLiuyanController { } -======= - //前端列表 - //处理前端分页查询请求 - @IgnoreAuth // 忽略认证 - @RequestMapping("/list") // 映射列表查询请求 - public R list(@RequestParam Map params, HttpServletRequest request){ - logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录请求日志 - CommonUtil.checkMap(params); // 检查参数有效性 - PageUtils page = jianshenkechengLiuyanService.queryPage(params); // 调用服务层查询分页数据 - - // 字典表数据转换 - List list =(List)page.getList(); // 获取分页数据列表 - for(JianshenkechengLiuyanView c:list){ // 遍历列表 - dictionaryService.dictionaryConvert(c, request); // 转换字典字段 - } - return R.ok().put("data", page); // 返回分页数据 - } - - - //前端详情 - //处理前端详情查询请求 - @RequestMapping("/detail/{id}") // 映射详情查询请求 - public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ - logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录请求日志 - JianshenkechengLiuyanEntity jianshenkechengLiuyan = jianshenkechengLiuyanService.selectById(id); // 根据ID查询留言 - if(jianshenkechengLiuyan !=null){ // 如果查询到数据 - JianshenkechengLiuyanView view = new JianshenkechengLiuyanView(); // 创建视图对象 - BeanUtils.copyProperties(jianshenkechengLiuyan, view); // 复制属性到视图对象 - - // 查询关联的健身课程信息 - JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(jianshenkechengLiuyan.getJianshenkechengId()); - if(jianshenkecheng != null){ - BeanUtils.copyProperties(jianshenkecheng, view, new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"}); - view.setJianshenkechengId(jianshenkecheng.getId()); - } - - // 查询关联的用户信息 - YonghuEntity yonghu = yonghuService.selectById(jianshenkechengLiuyan.getYonghuId()); - if(yonghu != null){ - BeanUtils.copyProperties(yonghu, view, new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"}); - view.setYonghuId(yonghu.getId()); - } - - dictionaryService.dictionaryConvert(view, request); // 转换字典字段 - return R.ok().put("data", view); // 返回详情数据 - }else { - return R.error(511,"查不到数据"); // 返回错误信息 - } - } - - - //前端保存 - //处理前端新增留言请求 - @RequestMapping("/add") // 映射新增请求 - public R add(@RequestBody JianshenkechengLiuyanEntity jianshenkechengLiuyan, HttpServletRequest request){ - logger.debug("add方法:,,Controller:{},,jianshenkechengLiuyan:{}",this.getClass().getName(),jianshenkechengLiuyan.toString()); // 记录请求日志 - jianshenkechengLiuyan.setCreateTime(new Date()); // 设置创建时间 - jianshenkechengLiuyan.setInsertTime(new Date()); // 设置插入时间 - jianshenkechengLiuyanService.insert(jianshenkechengLiuyan); // 调用服务层保存数据 - return R.ok(); // 返回成功信息 - } -} ->>>>>>> develop diff --git a/src/main/java/com/controller/JiaolianController.java b/src/main/java/com/controller/JiaolianController.java index 08f271b..a551d66 100644 --- a/src/main/java/com/controller/JiaolianController.java +++ b/src/main/java/com/controller/JiaolianController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; @@ -39,76 +38,6 @@ import com.alibaba.fastjson.*; * @author * @email */ -======= -// 声明当前 Java 文件所属的包,此包一般用于存放控制器相关的类,负责处理 HTTP 请求和响应 -package com.controller; - -// 导入 Java 标准库中的 File 类,用于操作文件和目录 -import java.io.File; -// 导入 Java 标准库中的 BigDecimal 类,用于进行高精度的十进制数运算 -import java.math.BigDecimal; -// 导入 Java 标准库中的 URL 类,用于表示统一资源定位符,可用于处理网络资源 -import java.net.URL; -// 导入 Java 标准库中的 SimpleDateFormat 类,用于格式化和解析日期时间 -import java.text.SimpleDateFormat; -// 导入阿里巴巴的 FastJSON 库中的 JSONObject 类,用于处理 JSON 对象,方便进行 JSON 数据的操作 -import com.alibaba.fastjson.JSONObject; -// 导入 Java 标准库中的 java.util 包下的所有类,该包包含了集合框架、日期和时间、随机数生成等常用工具类 -import java.util.*; -// 导入 Spring 框架中的 BeanUtils 类,用于对象属性的复制,方便在不同对象之间传递数据 -import org.springframework.beans.BeanUtils; -// 导入 Java Servlet API 中的 HttpServletRequest 类,用于封装 HTTP 请求信息,在控制器中可获取请求参数等 -import javax.servlet.http.HttpServletRequest; -// 导入 Spring 框架中的 ContextLoader 类,用于获取 Spring 的应用上下文 -import org.springframework.web.context.ContextLoader; -// 导入 Java Servlet API 中的 ServletContext 类,用于表示 Servlet 上下文,可获取应用的全局信息 -import javax.servlet.ServletContext; -// 导入自定义的 TokenService 类,该类可能用于处理令牌相关的业务逻辑 -import com.service.TokenService; -// 导入自定义的 utils 包下的所有类,这些类通常包含一些通用的工具方法 -import com.utils.*; -// 导入 Java 反射机制中的 InvocationTargetException 类,当使用反射调用方法时,如果被调用的方法抛出异常,会被封装成该异常抛出 -import java.lang.reflect.InvocationTargetException; - -// 导入自定义的 DictionaryService 类,该类可能用于处理字典数据的业务逻辑 -import com.service.DictionaryService; -// 导入 Apache Commons Lang3 库中的 StringUtils 类,提供了许多方便的字符串操作方法 -import org.apache.commons.lang3.StringUtils; -// 导入自定义的 IgnoreAuth 注解,该注解可能用于标记不需要进行身份验证的接口 -import com.annotation.IgnoreAuth; -// 导入 SLF4J 日志框架中的 Logger 接口,用于记录日志信息 -import org.slf4j.Logger; -// 导入 SLF4J 日志框架中的 LoggerFactory 类,用于创建 Logger 实例 -import org.slf4j.LoggerFactory; -// 导入 Spring 框架中的 Autowired 注解,用于自动注入依赖的 Bean -import org.springframework.beans.factory.annotation.Autowired; -// 导入 Spring 框架中的 Controller 注解,用于标记该类为控制器类,处理 HTTP 请求 -import org.springframework.stereotype.Controller; -// 导入 Spring 框架中的 RestController 和 RequestMapping 等注解,用于构建 RESTful 风格的接口 -import org.springframework.web.bind.annotation.*; -// 导入 MyBatis-Plus 框架中的 EntityWrapper 类,用于构建实体对象的查询条件 -import com.baomidou.mybatisplus.mapper.EntityWrapper; -// 导入 MyBatis-Plus 框架中的 Wrapper 接口,EntityWrapper 实现了该接口,用于灵活构建查询条件 -import com.baomidou.mybatisplus.mapper.Wrapper; -// 导入自定义的 entity 包下的所有类,这些类通常是实体类,对应数据库表结构 -import com.entity.*; -// 导入自定义的 view 包下的所有类,这些类可能是用于视图展示的实体类 -import com.entity.view.*; -// 导入自定义的 service 包下的所有类,这些类通常包含业务逻辑处理方法 -import com.service.*; -// 导入自定义的 PageUtils 类,用于处理分页相关的逻辑 -import com.utils.PageUtils; -// 导入自定义的 R 类,通常用于封装统一的响应结果 -import com.utils.R; -// 导入阿里巴巴的 FastJSON 库中的所有类,进一步方便进行 JSON 数据的操作 -import com.alibaba.fastjson.*; - - - //教练 - //后端接口 - //@author - //@email ->>>>>>> develop @RestController @Controller @RequestMapping("/jiaolian") @@ -146,13 +75,9 @@ public class JiaolianController { private UsersService usersService;//管理员 -<<<<<<< HEAD /** * 后端列表 */ -======= - //后端列表 ->>>>>>> develop @RequestMapping("/page") public R page(@RequestParam Map params, HttpServletRequest request){ logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); @@ -176,14 +101,9 @@ public class JiaolianController { return R.ok().put("data", page); } -<<<<<<< HEAD /** * 后端详情 */ -======= - - //后端详情 ->>>>>>> develop @RequestMapping("/info/{id}") public R info(@PathVariable("id") Long id, HttpServletRequest request){ logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); @@ -201,13 +121,9 @@ public class JiaolianController { } -<<<<<<< HEAD /** * 后端保存 */ -======= - //后端保存 ->>>>>>> develop @RequestMapping("/save") public R save(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request){ logger.debug("save方法:,,Controller:{},,jiaolian:{}",this.getClass().getName(),jiaolian.toString()); @@ -237,14 +153,9 @@ public class JiaolianController { } } -<<<<<<< HEAD /** * 后端修改 */ -======= - - //后端修改 ->>>>>>> develop @RequestMapping("/update") public R update(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { logger.debug("update方法:,,Controller:{},,jiaolian:{}",this.getClass().getName(),jiaolian.toString()); @@ -266,14 +177,9 @@ public class JiaolianController { -<<<<<<< HEAD /** * 删除 */ -======= - - //删除 ->>>>>>> develop @RequestMapping("/delete") public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); @@ -293,14 +199,9 @@ public class JiaolianController { } -<<<<<<< HEAD /** * 批量上传 */ -======= - - //批量上传 ->>>>>>> develop @RequestMapping("/batchInsert") public R save( String fileName, HttpServletRequest request){ logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); @@ -394,14 +295,9 @@ public class JiaolianController { } } -<<<<<<< HEAD /** * 登录 */ -======= - - //登录 ->>>>>>> develop @IgnoreAuth @RequestMapping(value = "/login") public R login(String username, String password, String captcha, HttpServletRequest request) { @@ -420,13 +316,9 @@ public class JiaolianController { return r; } -<<<<<<< HEAD /** * 注册 */ -======= - //注册 ->>>>>>> develop @IgnoreAuth @PostMapping(value = "/register") public R register(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request) { @@ -449,14 +341,9 @@ public class JiaolianController { return R.ok(); } -<<<<<<< HEAD /** * 重置密码 */ -======= - - //重置密码 ->>>>>>> develop @GetMapping(value = "/resetPassword") public R resetPassword(Integer id, HttpServletRequest request) { JiaolianEntity jiaolian = jiaolianService.selectById(id); @@ -465,14 +352,9 @@ public class JiaolianController { return R.ok(); } -<<<<<<< HEAD /** * 修改密码 */ -======= - - //修改密码 ->>>>>>> develop @GetMapping(value = "/updatePassword") public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) { JiaolianEntity jiaolian = jiaolianService.selectById((Integer)request.getSession().getAttribute("userId")); @@ -492,14 +374,9 @@ public class JiaolianController { -<<<<<<< HEAD /** * 忘记密码 */ -======= - - //忘记密码 ->>>>>>> develop @IgnoreAuth @RequestMapping(value = "/resetPass") public R resetPass(String username, HttpServletRequest request) { @@ -514,13 +391,9 @@ public class JiaolianController { } -<<<<<<< HEAD /** * 获取用户的session用户信息 */ -======= - //获取用户的session用户信息 ->>>>>>> develop @RequestMapping("/session") public R getCurrJiaolian(HttpServletRequest request){ Integer id = (Integer)request.getSession().getAttribute("userId"); @@ -539,14 +412,9 @@ public class JiaolianController { } -<<<<<<< HEAD /** * 退出 */ -======= - - //退出 ->>>>>>> develop @GetMapping(value = "logout") public R logout(HttpServletRequest request) { request.getSession().invalidate(); @@ -555,14 +423,9 @@ public class JiaolianController { -<<<<<<< HEAD /** * 前端列表 */ -======= - - //前端列表 ->>>>>>> develop @IgnoreAuth @RequestMapping("/list") public R list(@RequestParam Map params, HttpServletRequest request){ @@ -579,14 +442,9 @@ public class JiaolianController { return R.ok().put("data", page); } -<<<<<<< HEAD /** * 前端详情 */ -======= - - //前端详情 ->>>>>>> develop @RequestMapping("/detail/{id}") public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); @@ -607,14 +465,9 @@ public class JiaolianController { } -<<<<<<< HEAD /** * 前端保存 */ -======= - - //前端保存 ->>>>>>> develop @RequestMapping("/add") public R add(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request){ logger.debug("add方法:,,Controller:{},,jiaolian:{}",this.getClass().getName(),jiaolian.toString()); diff --git a/src/main/java/com/controller/JiaolianYuyueController.java b/src/main/java/com/controller/JiaolianYuyueController.java index 8bd2c05..bcc24b2 100644 --- a/src/main/java/com/controller/JiaolianYuyueController.java +++ b/src/main/java/com/controller/JiaolianYuyueController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; @@ -277,254 +276,6 @@ public class JiaolianYuyueController { //查询是否重复 //预约编号 -======= -package com.controller; // 声明包路径,表示该文件位于com.controller包下 - -import java.io.File; // 导入文件操作类,用于处理文件上传 -import java.math.BigDecimal; // 导入高精度数学计算类,用于处理金额计算 -import java.net.URL; // 导入网络URL处理类,用于获取资源路径 -import java.text.SimpleDateFormat; // 导入日期格式化类,用于日期格式转换 -import com.alibaba.fastjson.JSONObject; // 导入FastJSON的JSON对象类,用于JSON处理 -import java.util.*; // 导入Java常用工具类(集合、日期等) -import org.springframework.beans.BeanUtils; // 导入Spring Bean属性复制工具类 -import javax.servlet.http.HttpServletRequest; // 导入HTTP请求处理类 -import org.springframework.web.context.ContextLoader; // 导入Spring上下文加载器 -import javax.servlet.ServletContext; // 导入Servlet上下文接口 -import com.service.TokenService; // 导入自定义的Token服务类 -import com.utils.*; // 导入自定义工具类 -import java.lang.reflect.InvocationTargetException; // 导入反射异常类 - -import com.service.DictionaryService; // 导入自定义的字典服务类 -import org.apache.commons.lang3.StringUtils; // 导入Apache字符串工具类 -import com.annotation.IgnoreAuth; // 导入自定义的忽略认证注解 -import org.slf4j.Logger; // 导入日志接口 -import org.slf4j.LoggerFactory; // 导入日志工厂类 -import org.springframework.beans.factory.annotation.Autowired; // 导入Spring自动注入注解 -import org.springframework.stereotype.Controller; // 导入Spring控制器注解 -import org.springframework.web.bind.annotation.*; // 导入Spring Web注解 -import com.baomidou.mybatisplus.mapper.EntityWrapper; // 导入MyBatis Plus查询条件构造器 -import com.baomidou.mybatisplus.mapper.Wrapper; // 导入MyBatis Plus包装器接口 -import com.entity.*; // 导入实体类 -import com.entity.view.*; // 导入视图实体类 -import com.service.*; // 导入服务类 -import com.utils.PageUtils; // 导入分页工具类 -import com.utils.R; // 导入统一返回结果类 -import com.alibaba.fastjson.*; // 导入FastJSON相关类 - - - //教练预约申请 - //后端接口 - //@author - // @email - -@RestController // 标识为RESTful控制器,用于处理HTTP请求 -@Controller // 标识为Spring控制器 -@RequestMapping("/jiaolianYuyue") // 定义请求映射路径 -public class JiaolianYuyueController { - private static final Logger logger = LoggerFactory.getLogger(JiaolianYuyueController.class); // 日志记录器,用于记录日志信息 - - private static final String TABLE_NAME = "jiaolianYuyue"; // 数据库表名常量 - - @Autowired - private JiaolianYuyueService jiaolianYuyueService; // 自动注入教练预约服务 - - @Autowired - private TokenService tokenService; // 自动注入Token服务 - - @Autowired - private DictionaryService dictionaryService; // 自动注入字典服务 - @Autowired - private ForumService forumService; // 自动注入健身论坛服务 - @Autowired - private JianshenkechengService jianshenkechengService; // 自动注入健身课程服务 - @Autowired - private JianshenkechengCollectionService jianshenkechengCollectionService; // 自动注入课程收藏服务 - @Autowired - private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 自动注入课程留言服务 - @Autowired - private JiaolianService jiaolianService; // 自动注入教练服务 - @Autowired - private NewsService newsService; // 自动注入健身资讯服务 - @Autowired - private SingleSeachService singleSeachService; // 自动注入单页数据服务 - @Autowired - private YonghuService yonghuService; // 自动注入用户服务 - @Autowired - private UsersService usersService; // 自动注入管理员服务 - - - //后端列表 - //处理分页查询请求 - @RequestMapping("/page") // 映射分页查询请求 - public R page(@RequestParam Map params, HttpServletRequest request){ - logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录请求日志 - String role = String.valueOf(request.getSession().getAttribute("role")); // 从session中获取用户角色 - if(false) // 永远不会执行的代码块 - return R.error(511,"永不会进入"); // 返回错误信息 - else if("用户".equals(role)) // 如果是用户角色 - params.put("yonghuId",request.getSession().getAttribute("userId")); // 将用户ID添加到查询参数 - else if("教练".equals(role)) // 如果是教练角色 - params.put("jiaolianId",request.getSession().getAttribute("userId")); // 将教练ID添加到查询参数 - CommonUtil.checkMap(params); // 检查参数有效性 - PageUtils page = jiaolianYuyueService.queryPage(params); // 调用服务层查询分页数据 - - // 字典表数据转换 - List list =(List)page.getList(); // 获取分页数据列表 - for(JiaolianYuyueView c:list){ // 遍历列表 - dictionaryService.dictionaryConvert(c, request); // 转换字典字段 - } - return R.ok().put("data", page); // 返回分页数据 - } - - - //后端详情 - //根据ID查询单条预约详情 - @RequestMapping("/info/{id}") // 映射详情查询请求 - public R info(@PathVariable("id") Long id, HttpServletRequest request){ - logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录请求日志 - JiaolianYuyueEntity jiaolianYuyue = jiaolianYuyueService.selectById(id); // 根据ID查询预约 - if(jiaolianYuyue !=null){ // 如果查询到数据 - JiaolianYuyueView view = new JiaolianYuyueView(); // 创建视图对象 - BeanUtils.copyProperties(jiaolianYuyue, view); // 复制属性到视图对象 - - // 查询关联的用户信息 - YonghuEntity yonghu = yonghuService.selectById(jiaolianYuyue.getYonghuId()); - if(yonghu != null){ - BeanUtils.copyProperties(yonghu, view, new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"}); - view.setYonghuId(yonghu.getId()); - } - - dictionaryService.dictionaryConvert(view, request); // 转换字典字段 - return R.ok().put("data", view); // 返回详情数据 - }else { - return R.error(511,"查不到数据"); // 返回错误信息 - } - } - - - //后端保存 - //处理新增预约请求 - @RequestMapping("/save") // 映射保存请求 - public R save(@RequestBody JiaolianYuyueEntity jiaolianYuyue, HttpServletRequest request){ - logger.debug("save方法:,,Controller:{},,jiaolianYuyue:{}",this.getClass().getName(),jiaolianYuyue.toString()); // 记录请求日志 - - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) // 永远不会执行的代码块 - return R.error(511,"永远不会进入"); // 返回错误信息 - else if("用户".equals(role)) // 如果是用户角色 - jiaolianYuyue.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); // 设置用户ID - - // 构建查询条件,检查是否存在相同用户的待审核或已通过的预约 - Wrapper queryWrapper = new EntityWrapper() - .eq("yonghu_id", jiaolianYuyue.getYonghuId()) - .in("jiaolian_yuyue_yesno_types", new Integer[]{1,2}); - - logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句 - JiaolianYuyueEntity jiaolianYuyueEntity = jiaolianYuyueService.selectOne(queryWrapper); // 查询是否存在重复数据 - if(jiaolianYuyueEntity==null){ // 如果没有重复数据 - jiaolianYuyue.setJiaolianYuyueYesnoTypes(1); // 设置状态为待审核 - jiaolianYuyue.setInsertTime(new Date()); // 设置插入时间 - jiaolianYuyue.setCreateTime(new Date()); // 设置创建时间 - jiaolianYuyueService.insert(jiaolianYuyue); // 调用服务层保存数据 - return R.ok(); // 返回成功信息 - }else { // 如果存在重复数据 - if(jiaolianYuyueEntity.getJiaolianYuyueYesnoTypes()==1) // 如果是待审核状态 - return R.error(511,"有相同的待审核的数据"); // 返回错误信息 - else if(jiaolianYuyueEntity.getJiaolianYuyueYesnoTypes()==2) // 如果是已通过状态 - return R.error(511,"有相同的审核通过的数据"); // 返回错误信息 - else - return R.error(511,"表中有相同数据"); // 返回错误信息 - } - } - - - //后端修改 - //处理更新预约请求 - @RequestMapping("/update") // 映射更新请求 - public R update(@RequestBody JiaolianYuyueEntity jiaolianYuyue, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { - logger.debug("update方法:,,Controller:{},,jiaolianYuyue:{}",this.getClass().getName(),jiaolianYuyue.toString()); // 记录请求日志 - JiaolianYuyueEntity oldJiaolianYuyueEntity = jiaolianYuyueService.selectById(jiaolianYuyue.getId()); // 查询原有数据 - - // 处理空值情况 - if("".equals(jiaolianYuyue.getJiaolianYuyueText()) || "null".equals(jiaolianYuyue.getJiaolianYuyueText())){ - jiaolianYuyue.setJiaolianYuyueText(null); - } - if("".equals(jiaolianYuyue.getJiaolianYuyueYesnoText()) || "null".equals(jiaolianYuyue.getJiaolianYuyueYesnoText())){ - jiaolianYuyue.setJiaolianYuyueYesnoText(null); - } - - jiaolianYuyueService.updateById(jiaolianYuyue); // 调用服务层更新数据 - return R.ok(); // 返回成功信息 - } - - - //审核 - //处理预约审核请求 - @RequestMapping("/shenhe") // 映射审核请求 - public R shenhe(@RequestBody JiaolianYuyueEntity jiaolianYuyueEntity, HttpServletRequest request){ - logger.debug("shenhe方法:,,Controller:{},,jiaolianYuyueEntity:{}",this.getClass().getName(),jiaolianYuyueEntity.toString()); // 记录请求日志 - - JiaolianYuyueEntity oldJiaolianYuyue = jiaolianYuyueService.selectById(jiaolianYuyueEntity.getId()); // 查询原有数据 - - jiaolianYuyueService.updateById(jiaolianYuyueEntity); // 调用服务层更新审核状态 - return R.ok(); // 返回成功信息 - } - - - //删除 - //处理删除预约请求 - @RequestMapping("/delete") // 映射删除请求 - public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ - logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); // 记录请求日志 - List oldJiaolianYuyueList = jiaolianYuyueService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据 - jiaolianYuyueService.deleteBatchIds(Arrays.asList(ids)); // 调用服务层批量删除 - return R.ok(); // 返回成功信息 - } - - - //批量上传 - //处理批量导入数据请求 - @RequestMapping("/batchInsert") // 映射批量导入请求 - public R save(String fileName, HttpServletRequest request){ - logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); // 记录请求日志 - Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取用户ID - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 创建日期格式化对象 - try { - List jiaolianYuyueList = new ArrayList<>(); // 创建数据列表 - Map> seachFields = new HashMap<>(); // 创建查询字段映射 - Date date = new Date(); // 当前时间 - int lastIndexOf = fileName.lastIndexOf("."); // 获取文件后缀位置 - if(lastIndexOf == -1){ // 如果没有后缀 - return R.error(511,"该文件没有后缀"); // 返回错误信息 - }else{ - String suffix = fileName.substring(lastIndexOf); // 获取文件后缀 - if(!".xls".equals(suffix)){ // 如果不是xls文件 - return R.error(511,"只支持后缀为xls的excel文件"); // 返回错误信息 - }else{ - URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 获取文件路径 - File file = new File(resource.getFile()); // 创建文件对象 - if(!file.exists()){ // 如果文件不存在 - return R.error(511,"找不到上传文件,请联系管理员"); // 返回错误信息 - }else{ - List> dataList = PoiUtil.poiImport(file.getPath()); // 读取Excel文件 - dataList.remove(0); // 删除标题行 - for(List data:dataList){ // 遍历数据行 - JiaolianYuyueEntity jiaolianYuyueEntity = new JiaolianYuyueEntity(); // 创建实体对象 - jiaolianYuyueList.add(jiaolianYuyueEntity); // 添加到列表 - - // 检查预约编号是否重复 - if(seachFields.containsKey("jiaolianYuyueUuidNumber")){ - List jiaolianYuyueUuidNumber = seachFields.get("jiaolianYuyueUuidNumber"); - jiaolianYuyueUuidNumber.add(data.get(0)); - }else{ - List jiaolianYuyueUuidNumber = new ArrayList<>(); - jiaolianYuyueUuidNumber.add(data.get(0)); - seachFields.put("jiaolianYuyueUuidNumber",jiaolianYuyueUuidNumber); - } - } - - // 检查预约编号是否已存在 ->>>>>>> develop List jiaolianYuyueEntities_jiaolianYuyueUuidNumber = jiaolianYuyueService.selectList(new EntityWrapper().in("jiaolian_yuyue_uuid_number", seachFields.get("jiaolianYuyueUuidNumber"))); if(jiaolianYuyueEntities_jiaolianYuyueUuidNumber.size() >0 ){ ArrayList repeatFields = new ArrayList<>(); @@ -533,29 +284,18 @@ public class JiaolianYuyueController { } return R.error(511,"数据库的该表中的 [预约编号] 字段已经存在 存在数据为:"+repeatFields.toString()); } -<<<<<<< HEAD jiaolianYuyueService.insertBatch(jiaolianYuyueList); return R.ok(); -======= - jiaolianYuyueService.insertBatch(jiaolianYuyueList); // 批量插入数据 - return R.ok(); // 返回成功信息 ->>>>>>> develop } } } }catch (Exception e){ -<<<<<<< HEAD e.printStackTrace(); return R.error(511,"批量插入数据异常,请联系管理员"); -======= - e.printStackTrace(); // 打印异常堆栈 - return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息 ->>>>>>> develop } } -<<<<<<< HEAD /** @@ -641,79 +381,3 @@ public class JiaolianYuyueController { } -======= - //前端列表 - //处理前端分页查询请求 - @IgnoreAuth // 忽略认证 - @RequestMapping("/list") // 映射列表查询请求 - public R list(@RequestParam Map params, HttpServletRequest request){ - logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录请求日志 - CommonUtil.checkMap(params); // 检查参数有效性 - PageUtils page = jiaolianYuyueService.queryPage(params); // 调用服务层查询分页数据 - - // 字典表数据转换 - List list =(List)page.getList(); // 获取分页数据列表 - for(JiaolianYuyueView c:list){ // 遍历列表 - dictionaryService.dictionaryConvert(c, request); // 转换字典字段 - } - return R.ok().put("data", page); // 返回分页数据 - } - - - //前端详情 - //处理前端详情查询请求 - @RequestMapping("/detail/{id}") // 映射详情查询请求 - public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ - logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录请求日志 - JiaolianYuyueEntity jiaolianYuyue = jiaolianYuyueService.selectById(id); // 根据ID查询预约 - if(jiaolianYuyue !=null){ // 如果查询到数据 - JiaolianYuyueView view = new JiaolianYuyueView(); // 创建视图对象 - BeanUtils.copyProperties(jiaolianYuyue, view); // 复制属性到视图对象 - - // 查询关联的用户信息 - YonghuEntity yonghu = yonghuService.selectById(jiaolianYuyue.getYonghuId()); - if(yonghu != null){ - BeanUtils.copyProperties(yonghu, view, new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"}); - view.setYonghuId(yonghu.getId()); - } - - dictionaryService.dictionaryConvert(view, request); // 转换字典字段 - return R.ok().put("data", view); // 返回详情数据 - }else { - return R.error(511,"查不到数据"); // 返回错误信息 - } - } - - - //前端保存 - //处理前端新增预约请求 - @RequestMapping("/add") // 映射新增请求 - public R add(@RequestBody JiaolianYuyueEntity jiaolianYuyue, HttpServletRequest request){ - logger.debug("add方法:,,Controller:{},,jiaolianYuyue:{}",this.getClass().getName(),jiaolianYuyue.toString()); // 记录请求日志 - // 构建查询条件,检查是否存在相同用户的待审核或已通过的预约 - Wrapper queryWrapper = new EntityWrapper() - .eq("jiaolian_yuyue_uuid_number", jiaolianYuyue.getJiaolianYuyueUuidNumber()) - .eq("yonghu_id", jiaolianYuyue.getYonghuId()) - .eq("jiaolian_yuyue_text", jiaolianYuyue.getJiaolianYuyueText()) - .in("jiaolian_yuyue_yesno_types", new Integer[]{1,2}) - .eq("jiaolian_yuyue_yesno_text", jiaolianYuyue.getJiaolianYuyueYesnoText()); - - logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句 - JiaolianYuyueEntity jiaolianYuyueEntity = jiaolianYuyueService.selectOne(queryWrapper); // 查询是否存在重复数据 - if(jiaolianYuyueEntity==null){ // 如果没有重复数据 - jiaolianYuyue.setJiaolianYuyueYesnoTypes(1); // 设置状态为待审核 - jiaolianYuyue.setInsertTime(new Date()); // 设置插入时间 - jiaolianYuyue.setCreateTime(new Date()); // 设置创建时间 - jiaolianYuyueService.insert(jiaolianYuyue); // 调用服务层保存数据 - return R.ok(); // 返回成功信息 - }else { // 如果存在重复数据 - if(jiaolianYuyueEntity.getJiaolianYuyueYesnoTypes()==1) // 如果是待审核状态 - return R.error(511,"有相同的待审核的数据"); // 返回错误信息 - else if(jiaolianYuyueEntity.getJiaolianYuyueYesnoTypes()==2) // 如果是已通过状态 - return R.error(511,"有相同的审核通过的数据"); // 返回错误信息 - else - return R.error(511,"表中有相同数据"); // 返回错误信息 - } - } -} ->>>>>>> develop diff --git a/src/main/java/com/controller/NewsController.java b/src/main/java/com/controller/NewsController.java index b7c4373..0e04ff6 100644 --- a/src/main/java/com/controller/NewsController.java +++ b/src/main/java/com/controller/NewsController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; @@ -39,55 +38,12 @@ import com.alibaba.fastjson.*; * @author * @email */ -======= -package com.controller; // 定义包名为com.controller - -import java.io.File; // 文件操作类 -import java.math.BigDecimal; // 大数字处理类 -import java.net.URL; // 统一资源定位符类 -import java.text.SimpleDateFormat; // 日期格式化类 -import com.alibaba.fastjson.JSONObject; // 阿里巴巴FastJSON库的JSON对象类 -import java.util.*; // 通用工具类集合 -import org.springframework.beans.BeanUtils; // Spring Bean工具类 -import javax.servlet.http.HttpServletRequest; // HTTP请求处理类 -import org.springframework.web.context.ContextLoader; // Spring上下文加载器 -import javax.servlet.ServletContext; // Servlet上下文接口 -import com.service.TokenService; // 自定义Token服务类 -import com.utils.*; // 自定义工具类包 -import java.lang.reflect.InvocationTargetException; // 反射异常类 - -import com.service.DictionaryService; // 自定义字典服务类 -import org.apache.commons.lang3.StringUtils; // Apache字符串工具类 -import com.annotation.IgnoreAuth; // 自定义忽略认证注解 -import org.slf4j.Logger; // 日志接口 -import org.slf4j.LoggerFactory; // 日志工厂类 -import org.springframework.beans.factory.annotation.Autowired; // Spring自动注入注解 -import org.springframework.stereotype.Controller; // Spring控制器注解 -import org.springframework.web.bind.annotation.*; // Spring Web注解集合 -import com.baomidou.mybatisplus.mapper.EntityWrapper; // MyBatis Plus实体包装器 -import com.baomidou.mybatisplus.mapper.Wrapper; // MyBatis Plus包装器接口 -import com.entity.*; // 自定义实体类包 -import com.entity.view.*; // 自定义视图类包 -import com.service.*; // 自定义服务类包 -import com.utils.PageUtils; // 自定义分页工具类 -import com.utils.R; // 自定义返回结果类 -import com.alibaba.fastjson.*; // 阿里巴巴FastJSON库 - - - - //健身资讯 - //后端接口 - //@author - // @email - ->>>>>>> develop @RestController @Controller @RequestMapping("/news") public class NewsController { private static final Logger logger = LoggerFactory.getLogger(NewsController.class); -<<<<<<< HEAD private static final String TABLE_NAME = "news"; @Autowired @@ -167,98 +123,10 @@ public class NewsController { /** * 后端保存 */ -======= - private static final String TABLE_NAME = "news"; // 数据库表名 - - @Autowired - private NewsService newsService; // 健身资讯服务 - - @Autowired - private TokenService tokenService; // token服务 - - @Autowired - private DictionaryService dictionaryService; // 字典服务 - @Autowired - private ForumService forumService; // 健身论坛服务 - @Autowired - private JianshenkechengService jianshenkechengService; // 健身课程服务 - @Autowired - private JianshenkechengCollectionService jianshenkechengCollectionService; // 课程收藏服务 - @Autowired - private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 课程留言服务 - @Autowired - private JiaolianService jiaolianService; // 教练服务 - @Autowired - private JiaolianYuyueService jiaolianYuyueService; // 教练预约申请服务 - @Autowired - private SingleSeachService singleSeachService; // 单页数据服务 - @Autowired - private YonghuService yonghuService; // 用户服务 - @Autowired - private UsersService usersService; // 管理员服务 - - - //后端列表 - //分页查询健身资讯数据 - //@param params 请求参数,包含分页和查询条件 - //@param request HTTP请求对象 - //@return 返回分页数据和状态信息 - @RequestMapping("/page") - public R page(@RequestParam Map params, HttpServletRequest request){ - logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) - return R.error(511,"永不会进入"); - else if("用户".equals(role)) - params.put("yonghuId",request.getSession().getAttribute("userId")); // 如果是用户角色,添加用户ID查询条件 - else if("教练".equals(role)) - params.put("jiaolianId",request.getSession().getAttribute("userId")); // 如果是教练角色,添加教练ID查询条件 - CommonUtil.checkMap(params); // 检查参数 - PageUtils page = newsService.queryPage(params); // 分页查询 - - // 字典表数据转换 - List list =(List)page.getList(); - for(NewsView c:list){ - // 修改对应字典表字段 - dictionaryService.dictionaryConvert(c, request); - } - return R.ok().put("data", page); // 返回成功和数据 - } - - - //后端详情 - //根据ID查询单条健身资讯详情 - //@param id 资讯ID - //@param request HTTP请求对象 - //@return 返回资讯详情和状态信息 - @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id, HttpServletRequest request){ - logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); - NewsEntity news = newsService.selectById(id); // 根据ID查询资讯 - if(news !=null){ - // entity转view - NewsView view = new NewsView(); - BeanUtils.copyProperties( news , view ); // 把实体数据重构到view中 - // 修改对应字典表字段 - dictionaryService.dictionaryConvert(view, request); - return R.ok().put("data", view); // 返回成功和数据 - }else { - return R.error(511,"查不到数据"); // 返回错误信息 - } - } - - - //后端保存 - //新增健身资讯 - //@param news 资讯实体 - //@param request HTTP请求对象 - //@return 返回操作结果状态 ->>>>>>> develop @RequestMapping("/save") public R save(@RequestBody NewsEntity news, HttpServletRequest request){ logger.debug("save方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString()); -<<<<<<< HEAD String role = String.valueOf(request.getSession().getAttribute("role")); if(false) return R.error(511,"永远不会进入"); @@ -350,109 +218,10 @@ public class NewsController { NewsEntity newsEntity = new NewsEntity(); // newsEntity.setNewsName(data.get(0)); //资讯标题 要改的 // newsEntity.setNewsTypes(Integer.valueOf(data.get(0))); //资讯类型 要改的 -======= - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) - return R.error(511,"永远不会进入"); - - // 构建查询条件 - Wrapper queryWrapper = new EntityWrapper() - .eq("news_name", news.getNewsName()) // 资讯标题相等 - .eq("news_types", news.getNewsTypes()) // 资讯类型相等 - ; - - logger.info("sql语句:"+queryWrapper.getSqlSegment()); - NewsEntity newsEntity = newsService.selectOne(queryWrapper); // 查询是否已存在 - if(newsEntity==null){ - news.setInsertTime(new Date()); // 设置插入时间 - news.setCreateTime(new Date()); // 设置创建时间 - newsService.insert(news); // 插入新数据 - return R.ok(); // 返回成功 - }else { - return R.error(511,"表中有相同数据"); // 返回错误信息 - } - } - - //后端修改 - //更新健身资讯 - //@param news 资讯实体 - //@param request HTTP请求对象 - //@return 返回操作结果状态 - @RequestMapping("/update") - public R update(@RequestBody NewsEntity news, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { - logger.debug("update方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString()); - NewsEntity oldNewsEntity = newsService.selectById(news.getId()); // 查询原先数据 - - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 -// if(false) -// return R.error(511,"永远不会进入"); - if("".equals(news.getNewsPhoto()) || "null".equals(news.getNewsPhoto())){ - news.setNewsPhoto(null); // 如果图片为空,设置为null - } - if("".equals(news.getNewsContent()) || "null".equals(news.getNewsContent())){ - news.setNewsContent(null); // 如果内容为空,设置为null - } - - newsService.updateById(news); // 根据id更新 - return R.ok(); // 返回成功 - } - - - //删除 - //批量删除健身资讯 - //@param ids 要删除的资讯ID数组 - //@param request HTTP请求对象 - //@return 返回操作结果状态 - @RequestMapping("/delete") - public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ - logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); - List oldNewsList =newsService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据 - newsService.deleteBatchIds(Arrays.asList(ids)); // 批量删除 - - return R.ok(); // 返回成功 - } - - - //批量上传 - //通过Excel文件批量导入健身资讯数据 - //@param fileName Excel文件名 - //@param request HTTP请求对象 - //@return 返回操作结果状态 - @RequestMapping("/batchInsert") - public R save( String fileName, HttpServletRequest request){ - logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); - Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取用户ID - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 日期格式化 - try { - List newsList = new ArrayList<>(); // 存储上传的数据 - Map> seachFields= new HashMap<>(); // 要查询的字段 - Date date = new Date(); - int lastIndexOf = fileName.lastIndexOf("."); // 获取文件后缀 - if(lastIndexOf == -1){ - return R.error(511,"该文件没有后缀"); // 返回错误信息 - }else{ - String suffix = fileName.substring(lastIndexOf); // 获取文件后缀 - if(!".xls".equals(suffix)){ - return R.error(511,"只支持后缀为xls的excel文件"); // 返回错误信息 - }else{ - URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 获取文件路径 - File file = new File(resource.getFile()); - if(!file.exists()){ - return R.error(511,"找不到上传文件,请联系管理员"); // 返回错误信息 - }else{ - List> dataList = PoiUtil.poiImport(file.getPath()); // 读取xls文件 - dataList.remove(0); // 删除第一行,因为第一行是提示 - for(List data:dataList){ - // 循环处理每行数据 - NewsEntity newsEntity = new NewsEntity(); -// newsEntity.setNewsName(data.get(0)); // 资讯标题 要改的 -// newsEntity.setNewsTypes(Integer.valueOf(data.get(0))); // 资讯类型 要改的 ->>>>>>> develop // newsEntity.setNewsPhoto("");//详情和图片 // newsEntity.setInsertTime(date);//时间 // newsEntity.setNewsContent("");//详情和图片 // newsEntity.setCreateTime(date);//时间 -<<<<<<< HEAD newsList.add(newsEntity); @@ -462,49 +231,26 @@ public class NewsController { //查询是否重复 newsService.insertBatch(newsList); return R.ok(); -======= - newsList.add(newsEntity); // 添加到列表 - - // 把要查询是否重复的字段放入map中 - } - - // 查询是否重复 - newsService.insertBatch(newsList); // 批量插入 - return R.ok(); // 返回成功 ->>>>>>> develop } } } }catch (Exception e){ e.printStackTrace(); -<<<<<<< HEAD return R.error(511,"批量插入数据异常,请联系管理员"); -======= - return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息 ->>>>>>> develop } } -<<<<<<< HEAD /** * 前端列表 */ -======= - //前端列表 - //分页查询健身资讯数据(无需认证) - //@param params 请求参数,包含分页和查询条件 - //@param request HTTP请求对象 - //@return 返回分页数据和状态信息 ->>>>>>> develop @IgnoreAuth @RequestMapping("/list") public R list(@RequestParam Map params, HttpServletRequest request){ logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); -<<<<<<< HEAD CommonUtil.checkMap(params); PageUtils page = newsService.queryPage(params); @@ -542,53 +288,10 @@ public class NewsController { /** * 前端保存 */ -======= - CommonUtil.checkMap(params); // 检查参数 - PageUtils page = newsService.queryPage(params); // 分页查询 - - // 字典表数据转换 - List list =(List)page.getList(); - for(NewsView c:list) - dictionaryService.dictionaryConvert(c, request); // 修改对应字典表字段 - - return R.ok().put("data", page); // 返回成功和数据 - } - - - //前端详情 - //根据ID查询单条健身资讯详情 - //@param id 资讯ID - //@param request HTTP请求对象 - //@return 返回资讯详情和状态信息 - @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ - logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); - NewsEntity news = newsService.selectById(id); // 根据ID查询资讯 - if(news !=null){ - // entity转view - NewsView view = new NewsView(); - BeanUtils.copyProperties( news , view ); // 把实体数据重构到view中 - - // 修改对应字典表字段 - dictionaryService.dictionaryConvert(view, request); - return R.ok().put("data", view); // 返回成功和数据 - }else { - return R.error(511,"查不到数据"); // 返回错误信息 - } - } - - - //前端保存 - //新增健身资讯 - //@param news 资讯实体 - //@param request HTTP请求对象 - //@return 返回操作结果状态 ->>>>>>> develop @RequestMapping("/add") public R add(@RequestBody NewsEntity news, HttpServletRequest request){ logger.debug("add方法:,,Controller:{},,news:{}",this.getClass().getName(),news.toString()); Wrapper queryWrapper = new EntityWrapper() -<<<<<<< HEAD .eq("news_name", news.getNewsName()) .eq("news_types", news.getNewsTypes()) // .notIn("news_types", new Integer[]{102}) @@ -608,22 +311,3 @@ public class NewsController { } -======= - .eq("news_name", news.getNewsName()) // 资讯标题相等 - .eq("news_types", news.getNewsTypes()) // 资讯类型相等 -// .notIn("news_types", new Integer[]{102}) - ; - logger.info("sql语句:"+queryWrapper.getSqlSegment()); - NewsEntity newsEntity = newsService.selectOne(queryWrapper); // 查询是否已存在 - if(newsEntity==null){ - news.setInsertTime(new Date()); // 设置插入时间 - news.setCreateTime(new Date()); // 设置创建时间 - newsService.insert(news); // 插入新数据 - - return R.ok(); // 返回成功 - }else { - return R.error(511,"表中有相同数据"); // 返回错误信息 - } - } -} ->>>>>>> develop diff --git a/src/main/java/com/controller/SingleSeachController.java b/src/main/java/com/controller/SingleSeachController.java index 1584c4a..72d3a85 100644 --- a/src/main/java/com/controller/SingleSeachController.java +++ b/src/main/java/com/controller/SingleSeachController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; @@ -235,246 +234,10 @@ public class SingleSeachController { }catch (Exception e){ e.printStackTrace(); return R.error(511,"批量插入数据异常,请联系管理员"); -======= -// 声明当前文件所在的包路径 -package com.controller; - -// 导入所需的Java类库 -import java.io.File; // 文件操作类 -import java.math.BigDecimal; // 高精度数字计算类 -import java.net.URL; // 统一资源定位符类 -import java.text.SimpleDateFormat; // 日期格式化类 -import com.alibaba.fastjson.JSONObject; // FastJSON的JSON对象类 -import java.util.*; // 通用工具类集合 -import org.springframework.beans.BeanUtils; // Spring Bean工具类 -import javax.servlet.http.HttpServletRequest; // HTTP请求类 -import org.springframework.web.context.ContextLoader; // Spring上下文加载器 -import javax.servlet.ServletContext; // Servlet上下文接口 -import com.service.TokenService; // 自定义Token服务类 -import com.utils.*; // 自定义工具类包 -import java.lang.reflect.InvocationTargetException; // 反射异常类 - -// 导入自定义服务类 -import com.service.DictionaryService; // 字典服务类 -import org.apache.commons.lang3.StringUtils; // Apache字符串工具类 -import com.annotation.IgnoreAuth; // 自定义忽略认证注解 -import org.slf4j.Logger; // 日志接口 -import org.slf4j.LoggerFactory; // 日志工厂类 -import org.springframework.beans.factory.annotation.Autowired; // Spring自动注入注解 -import org.springframework.stereotype.Controller; // Spring控制器注解 -import org.springframework.web.bind.annotation.*; // Spring Web注解集合 -import com.baomidou.mybatisplus.mapper.EntityWrapper; // MyBatis Plus实体包装类 -import com.baomidou.mybatisplus.mapper.Wrapper; // MyBatis Plus包装接口 -import com.entity.*; // 实体类包 -import com.entity.view.*; // 实体视图类包 -import com.service.*; // 服务接口包 -import com.utils.PageUtils; // 分页工具类 -import com.utils.R; // 通用返回结果类 -import com.alibaba.fastjson.*; // FastJSON工具包 - - - //单页数据 - //后端接口控制器 - //@author - //@email - -@RestController // 标识这是一个RESTful风格的控制器 -@Controller // 标识这是一个Spring MVC控制器 -@RequestMapping("/singleSeach") // 定义基础请求路径 -public class SingleSeachController { - private static final Logger logger = LoggerFactory.getLogger(SingleSeachController.class); // 日志记录器 - - private static final String TABLE_NAME = "singleSeach"; // 数据库表名常量 - - @Autowired - private SingleSeachService singleSeachService; // 注入单页数据服务 - - @Autowired - private TokenService tokenService; // 注入token服务 - - // 注入其他相关服务 - @Autowired - private DictionaryService dictionaryService; // 字典服务 - @Autowired - private ForumService forumService; // 健身论坛服务 - @Autowired - private JianshenkechengService jianshenkechengService; // 健身课程服务 - @Autowired - private JianshenkechengCollectionService jianshenkechengCollectionService; // 课程收藏服务 - @Autowired - private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 课程留言服务 - @Autowired - private JiaolianService jiaolianService; // 教练服务 - @Autowired - private JiaolianYuyueService jiaolianYuyueService; // 教练预约申请服务 - @Autowired - private NewsService newsService; // 健身资讯服务 - @Autowired - private YonghuService yonghuService; // 用户服务 - @Autowired - private UsersService usersService; // 管理员服务 - - - //后端列表 - //分页查询单页数据 - //@param params 请求参数Map - //@param request HTTP请求对象 - //@return 返回分页数据结果 - - @RequestMapping("/page") - public R page(@RequestParam Map params, HttpServletRequest request){ - logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录日志 - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) // 条件判断 - return R.error(511,"永不会进入"); // 返回错误信息 - else if("用户".equals(role)) // 如果是用户角色 - params.put("yonghuId",request.getSession().getAttribute("userId")); // 添加用户ID参数 - else if("教练".equals(role)) // 如果是教练角色 - params.put("jiaolianId",request.getSession().getAttribute("userId")); // 添加教练ID参数 - CommonUtil.checkMap(params); // 检查参数 - PageUtils page = singleSeachService.queryPage(params); // 调用服务层分页查询 - - // 字典表数据转换 - List list =(List)page.getList(); // 获取分页数据列表 - for(SingleSeachView c:list){ // 遍历列表 - dictionaryService.dictionaryConvert(c, request); // 转换字典表字段 - } - return R.ok().put("data", page); // 返回成功结果和数据 - } - - - //后端详情 - //根据ID查询单条单页数据详情 - //@param id 数据ID - //@param request HTTP请求对象 - //@return 返回查询结果 - @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id, HttpServletRequest request){ - logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录日志 - SingleSeachEntity singleSeach = singleSeachService.selectById(id); // 根据ID查询数据 - if(singleSeach !=null){ // 如果查询到数据 - SingleSeachView view = new SingleSeachView(); // 创建视图对象 - BeanUtils.copyProperties(singleSeach, view); // 复制属性到视图对象 - dictionaryService.dictionaryConvert(view, request); // 转换字典表字段 - return R.ok().put("data", view); // 返回成功结果和数据 - }else { - return R.error(511,"查不到数据"); // 返回错误信息 - } - } - - - //后端保存 - //新增单页数据 - //@param singleSeach 单页数据实体 - //@param request HTTP请求对象 - //@return 返回操作结果 - //@RequestMapping("/save") - public R save(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request){ - logger.debug("save方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString()); // 记录日志 - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) // 条件判断 - return R.error(511,"永远不会进入"); // 返回错误信息 - - // 构建查询条件 - Wrapper queryWrapper = new EntityWrapper() - .eq("single_seach_types",singleSeach.getSingleSeachTypes()); // 按类型查询 - - logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句 - SingleSeachEntity singleSeachEntity = singleSeachService.selectOne(queryWrapper); // 查询是否存在 - if(singleSeachEntity==null){ // 如果不存在 - singleSeach.setCreateTime(new Date()); // 设置创建时间 - singleSeachService.insert(singleSeach); // 插入新数据 - return R.ok(); // 返回成功结果 - }else { - return R.error(511,"该类型已经有存在的,请删除后重新新增"); // 返回错误信息 - } - } - - //后端修改 - //更新单页数据 - //@param singleSeach 单页数据实体 - //@param request HTTP请求对象 - //@return 返回操作结果 - @RequestMapping("/update") - public R update(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { - logger.debug("update方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString()); // 记录日志 - SingleSeachEntity oldSingleSeachEntity = singleSeachService.selectById(singleSeach.getId()); // 查询原数据 - - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if("".equals(singleSeach.getSingleSeachPhoto()) || "null".equals(singleSeach.getSingleSeachPhoto())){ // 如果图片为空 - singleSeach.setSingleSeachPhoto(null); // 设置为null - } - if("".equals(singleSeach.getSingleSeachContent()) || "null".equals(singleSeach.getSingleSeachContent())){ // 如果内容为空 - singleSeach.setSingleSeachContent(null); // 设置为null - } - - singleSeachService.updateById(singleSeach); // 更新数据 - return R.ok(); // 返回成功结果 - } - - - //删除 - //批量删除单页数据 - //@param ids 要删除的ID数组 - //@param request HTTP请求对象 - //@return 返回操作结果 - @RequestMapping("/delete") - public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ - logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); // 记录日志 - List oldSingleSeachList = singleSeachService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据 - singleSeachService.deleteBatchIds(Arrays.asList(ids)); // 批量删除 - return R.ok(); // 返回成功结果 - } - - - //批量上传/ - //通过Excel批量导入数据 - //@param fileName Excel文件名 - //@param request HTTP请求对象 - //@return 返回操作结果 - @RequestMapping("/batchInsert") - public R save(String fileName, HttpServletRequest request){ - logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); // 记录日志 - Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取用户ID - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 创建日期格式化对象 - try { - List singleSeachList = new ArrayList<>(); // 创建数据列表 - Map> seachFields = new HashMap<>(); // 创建查询字段Map - Date date = new Date(); // 当前时间 - int lastIndexOf = fileName.lastIndexOf("."); // 获取文件后缀位置 - if(lastIndexOf == -1){ // 如果没有后缀 - return R.error(511,"该文件没有后缀"); // 返回错误信息 - }else{ - String suffix = fileName.substring(lastIndexOf); // 获取文件后缀 - if(!".xls".equals(suffix)){ // 如果不是xls文件 - return R.error(511,"只支持后缀为xls的excel文件"); // 返回错误信息 - }else{ - URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 获取文件路径 - File file = new File(resource.getFile()); // 创建文件对象 - if(!file.exists()){ // 如果文件不存在 - return R.error(511,"找不到上传文件,请联系管理员"); // 返回错误信息 - }else{ - List> dataList = PoiUtil.poiImport(file.getPath()); // 读取Excel文件 - dataList.remove(0); // 删除标题行 - for(List data:dataList){ // 遍历数据行 - SingleSeachEntity singleSeachEntity = new SingleSeachEntity(); // 创建实体对象 - // 可以在此处设置实体属性,示例中被注释掉了 - singleSeachList.add(singleSeachEntity); // 添加到列表 - } - singleSeachService.insertBatch(singleSeachList); // 批量插入 - return R.ok(); // 返回成功结果 - } - } - } - }catch (Exception e){ // 捕获异常 - e.printStackTrace(); // 打印异常堆栈 - return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息 ->>>>>>> develop } } -<<<<<<< HEAD /** @@ -535,65 +298,3 @@ public class SingleSeachController { } -======= - //前端列表 - //无需认证的分页查询 - //@param params 请求参数Map - //@param request HTTP请求对象 - //@return 返回分页数据结果 - @IgnoreAuth // 忽略认证 - @RequestMapping("/list") - public R list(@RequestParam Map params, HttpServletRequest request){ - logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录日志 - CommonUtil.checkMap(params); // 检查参数 - PageUtils page = singleSeachService.queryPage(params); // 分页查询 - - List list = (List)page.getList(); // 获取数据列表 - for(SingleSeachView c:list) // 遍历列表 - dictionaryService.dictionaryConvert(c, request); // 转换字典表字段 - - return R.ok().put("data", page); // 返回成功结果和数据 - } - - - //前端详情 - //根据类型查询单条数据 - //@param id 数据类型ID - //@param request HTTP请求对象 - //@return 返回查询结果 - @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ - logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录日志 - // 根据类型查询单条数据 - SingleSeachEntity singleSeach = singleSeachService.selectOne(new EntityWrapper().eq("single_seach_types", id)); - if(singleSeach != null) // 如果查询到数据 - return R.ok().put("data", singleSeach); // 返回成功结果和数据 - else - return R.error(511,"查不到数据"); // 返回错误信息 - } - - - //前端保存 - //新增单页数据 - //@param singleSeach 单页数据实体 - //@param request HTTP请求对象 - //@return 返回操作结果 - @RequestMapping("/add") - public R add(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request){ - logger.debug("add方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString()); // 记录日志 - // 构建查询条件 - Wrapper queryWrapper = new EntityWrapper() - .eq("single_seach_types",singleSeach.getSingleSeachTypes()); // 按类型查询 - - logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句 - SingleSeachEntity singleSeachEntity = singleSeachService.selectOne(queryWrapper); // 查询是否已存在 - if(singleSeachEntity==null){ // 如果不存在 - singleSeach.setCreateTime(new Date()); // 设置创建时间 - singleSeachService.insert(singleSeach); // 插入新数据 - return R.ok(); // 返回成功结果 - }else { - return R.error(511,"该类型已经有存在的,请删除后重新新增"); // 返回错误信息 - } - } -} ->>>>>>> develop diff --git a/src/main/java/com/controller/UsersController.java b/src/main/java/com/controller/UsersController.java index 81b8f20..4fe5a2c 100644 --- a/src/main/java/com/controller/UsersController.java +++ b/src/main/java/com/controller/UsersController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; @@ -191,241 +190,3 @@ public class UsersController { return R.ok(); } } -======= -package com.controller; // 声明当前类所在的包路径 - -// 导入Java集合类 -import java.util.List; // 列表接口 -import java.util.Arrays; // 数组工具类 -import java.util.Map; // 映射接口 - -// 导入Servlet相关类 -import javax.servlet.http.HttpServletRequest; // HTTP请求对象 - -// 导入服务类 -import com.service.UsersService; // 用户服务接口 - -// 导入Spring框架注解 -import org.springframework.beans.factory.annotation.Autowired; // 自动注入注解 -import org.springframework.web.bind.annotation.GetMapping; // GET请求映射注解 -import org.springframework.web.bind.annotation.PathVariable; // 路径变量注解 -import org.springframework.web.bind.annotation.PostMapping; // POST请求映射注解 -import org.springframework.web.bind.annotation.RequestBody; // 请求体注解 -import org.springframework.web.bind.annotation.RequestMapping; // 请求映射注解 -import org.springframework.web.bind.annotation.RequestParam; // 请求参数注解 -import org.springframework.web.bind.annotation.RestController; // REST控制器注解 - -// 导入自定义注解和工具类 -import com.annotation.IgnoreAuth; // 忽略认证注解 -import com.baomidou.mybatisplus.mapper.EntityWrapper; // MyBatis Plus条件构造器 -import com.entity.UsersEntity; // 用户实体类 -import com.service.TokenService; // Token服务接口 -import com.utils.MPUtil; // MyBatis Plus工具类 -import com.utils.PageUtils; // 分页工具类 -import com.utils.R; // 统一返回结果类 - -//用户登录相关功能控制器 - //处理用户认证、注册、密码管理等操作 -@RequestMapping("users") // 定义基础请求路径为/users -@RestController // 标识这是一个RESTful风格的控制器 -public class UsersController { - - @Autowired // 自动注入用户服务 - private UsersService usersService; - - @Autowired // 自动注入Token服务 - private TokenService tokenService; - - - //用户登录接口 - //@param username 用户名 - //@param password 密码 - //@param captcha 验证码(未使用) - //@param request HTTP请求对象 - //@return 返回登录结果和Token信息 - @IgnoreAuth // 忽略认证检查 - @PostMapping(value = "/login") // 处理POST /users/login请求 - public R login(String username, String password, String captcha, HttpServletRequest request) { - // 根据用户名查询用户 - UsersEntity user = usersService.selectOne(new EntityWrapper().eq("username", username)); - // 验证用户是否存在和密码是否正确 - if(user==null || !user.getPassword().equals(password)) { - return R.error("账号或密码不正确"); // 返回错误信息 - } - // 生成Token - String token = tokenService.generateToken(user.getId(),username, "users", user.getRole()); - // 构建返回结果 - R r = R.ok(); - r.put("token", token); // 返回Token - r.put("role",user.getRole()); // 返回用户角色 - r.put("userId",user.getId()); // 返回用户ID - return r; - } - - - //用户注册接口 - //@param user 用户实体对象(通过请求体传入) - //@return 返回注册结果 - @IgnoreAuth // 忽略认证检查 - @PostMapping(value = "/register") // 处理POST /users/register请求 - public R register(@RequestBody UsersEntity user){ - // 检查用户名是否已存在 - if(usersService.selectOne(new EntityWrapper().eq("username", user.getUsername())) !=null) { - return R.error("用户已存在"); // 返回错误信息 - } - usersService.insert(user); // 插入新用户 - return R.ok(); // 返回成功结果 - } - - - //用户退出接口 - //@param request HTTP请求对象 - //@return 返回退出结果 - @GetMapping(value = "logout") // 处理GET /users/logout请求 - public R logout(HttpServletRequest request) { - request.getSession().invalidate(); // 使会话失效 - return R.ok("退出成功"); // 返回成功信息 - } - - - //修改密码接口 - //@param oldPassword 旧密码 - //@param newPassword 新密码 - //@param request HTTP请求对象 - //@return 返回修改结果 - @GetMapping(value = "/updatePassword") // 处理GET /users/updatePassword请求 - public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) { - // 获取当前用户 - UsersEntity users = usersService.selectById((Integer)request.getSession().getAttribute("userId")); - // 验证新密码是否为空 - if(newPassword == null){ - return R.error("新密码不能为空") ; - } - // 验证旧密码是否正确 - if(!oldPassword.equals(users.getPassword())){ - return R.error("原密码输入错误"); - } - // 验证新密码是否与旧密码相同 - if(newPassword.equals(users.getPassword())){ - return R.error("新密码不能和原密码一致") ; - } - // 更新密码 - users.setPassword(newPassword); - usersService.updateById(users); - return R.ok(); // 返回成功结果 - } - - - //密码重置接口 - //@param username 用户名 - //@param request HTTP请求对象 - //@return 返回重置结果 - @IgnoreAuth // 忽略认证检查 - @RequestMapping(value = "/resetPass") // 处理/users/resetPass请求 - public R resetPass(String username, HttpServletRequest request){ - // 根据用户名查询用户 - UsersEntity user = usersService.selectOne(new EntityWrapper().eq("username", username)); - if(user==null) { - return R.error("账号不存在"); // 返回错误信息 - } - // 重置密码为默认值 - user.setPassword("123456"); - usersService.update(user,null); // 更新用户信息 - return R.ok("密码已重置为:123456"); // 返回成功信息 - } - - - //分页查询用户列表 - //@param params 请求参数Map - //@param user 用户实体(用于条件查询) - //@return 返回分页结果 - @RequestMapping("/page") // 处理/users/page请求 - public R page(@RequestParam Map params,UsersEntity user){ - // 创建条件构造器 - EntityWrapper ew = new EntityWrapper(); - // 构建分页查询 - PageUtils page = usersService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params)); - return R.ok().put("data", page); // 返回分页数据 - } - - - //查询用户列表 - //@param user 用户实体(用于条件查询) - //@return 返回用户列表 - @RequestMapping("/list") // 处理/users/list请求 - public R list(UsersEntity user){ - // 创建条件构造器 - EntityWrapper ew = new EntityWrapper(); - // 构建查询条件 - ew.allEq(MPUtil.allEQMapPre(user, "user")); - return R.ok().put("data", usersService.selectListView(ew)); // 返回查询结果 - } - - - //获取用户详细信息 - //@param id 用户ID - //@return 返回用户信息 - @RequestMapping("/info/{id}") // 处理/users/info/{id}请求 - public R info(@PathVariable("id") String id){ - UsersEntity user = usersService.selectById(id); // 根据ID查询用户 - return R.ok().put("data", user); // 返回用户信息 - } - - - // 获取当前会话用户信息 - //@param request HTTP请求对象 - // @return 返回当前用户信息 - - @RequestMapping("/session") // 处理/users/session请求 - public R getCurrUser(HttpServletRequest request){ - // 从会话中获取用户ID - Integer id = (Integer)request.getSession().getAttribute("userId"); - UsersEntity user = usersService.selectById(id); // 查询用户信息 - return R.ok().put("data", user); // 返回用户信息 - } - - - //保存用户信息 - //@param user 用户实体对象(通过请求体传入) - // @return 返回保存结果 - - @PostMapping("/save") // 处理POST /users/save请求 - public R save(@RequestBody UsersEntity user){ - // 检查用户名是否已存在 - if(usersService.selectOne(new EntityWrapper().eq("username", user.getUsername())) !=null) { - return R.error("用户已存在"); // 返回错误信息 - } - usersService.insert(user); // 插入新用户 - return R.ok(); // 返回成功结果 - } - - - // 更新用户信息 - //@param user 用户实体对象(通过请求体传入) - //@return 返回更新结果 - - @RequestMapping("/update") // 处理/users/update请求 - public R update(@RequestBody UsersEntity user){ - usersService.updateById(user); // 更新用户信息 - return R.ok(); // 返回成功结果 - } - - - //删除用户 - //@param ids 用户ID数组(通过请求体传入) - // @return 返回删除结果 - - @RequestMapping("/delete") // 处理/users/delete请求 - public R delete(@RequestBody Long[] ids){ - // 查询所有用户 - List user = usersService.selectList(null); - // 确保至少保留一个管理员 - if(user.size() > 1){ - usersService.deleteBatchIds(Arrays.asList(ids)); // 批量删除用户 - }else{ - return R.error("管理员最少保留一个"); // 返回错误信息 - } - return R.ok(); // 返回成功结果 - } -} ->>>>>>> develop diff --git a/src/main/java/com/controller/YonghuController.java b/src/main/java/com/controller/YonghuController.java index 2b33dbf..4cbdd7d 100644 --- a/src/main/java/com/controller/YonghuController.java +++ b/src/main/java/com/controller/YonghuController.java @@ -1,4 +1,3 @@ -<<<<<<< HEAD package com.controller; @@ -409,443 +408,10 @@ public class YonghuController { return R.ok(); }else{ return R.error("账号不存在"); -======= -package com.controller; // 声明当前类所在的包路径 - -// 导入Java IO类 -import java.io.File; // 文件操作类 -// 导入数学类 -import java.math.BigDecimal; // 高精度数字计算类 -// 导入网络类 -import java.net.URL; // 统一资源定位符类 -// 导入文本处理类 -import java.text.SimpleDateFormat; // 日期格式化类 -// 导入JSON处理类 -import com.alibaba.fastjson.JSONObject; // FastJSON对象类 -// 导入集合类 -import java.util.*; // 通用集合工具类 -// 导入Spring Bean工具类 -import org.springframework.beans.BeanUtils; // Bean属性复制工具类 -// 导入Servlet类 -import javax.servlet.http.HttpServletRequest; // HTTP请求对象 -// 导入Spring上下文类 -import org.springframework.web.context.ContextLoader; // Web应用上下文加载器 -// 导入Servlet上下文类 -import javax.servlet.ServletContext; // Servlet上下文对象 -// 导入自定义服务类 -import com.service.TokenService; // Token服务接口 -// 导入自定义工具类 -import com.utils.*; // 自定义工具类集合 -// 导入反射异常类 -import java.lang.reflect.InvocationTargetException; // 反射调用异常类 - -// 导入字典服务类 -import com.service.DictionaryService; // 字典数据服务接口 -// 导入Apache Commons工具类 -import org.apache.commons.lang3.StringUtils; // 字符串处理工具类 -// 导入自定义注解 -import com.annotation.IgnoreAuth; // 忽略认证注解 -// 导入日志类 -import org.slf4j.Logger; // 日志接口 -import org.slf4j.LoggerFactory; // 日志工厂类 -// 导入Spring注解 -import org.springframework.beans.factory.annotation.Autowired; // 自动注入注解 -import org.springframework.stereotype.Controller; // 控制器注解 -import org.springframework.web.bind.annotation.*; // Web请求相关注解 -// 导入MyBatis Plus类 -import com.baomidou.mybatisplus.mapper.EntityWrapper; // 条件构造器 -import com.baomidou.mybatisplus.mapper.Wrapper; // 条件构造器接口 -// 导入实体类 -import com.entity.*; // 实体类集合 -import com.entity.view.*; // 视图实体类集合 -// 导入服务接口 -import com.service.*; // 服务接口集合 -// 导入分页工具类 -import com.utils.PageUtils; // 分页工具类 -// 导入返回结果类 -import com.utils.R; // 统一返回结果类 -// 导入FastJSON类 -import com.alibaba.fastjson.*; // FastJSON工具类 - - - //用户控制器 - // 处理用户相关操作的RESTful接口 - -@RestController // 标识为RESTful控制器 -@Controller // 标识为Spring MVC控制器 -@RequestMapping("/yonghu") // 基础请求路径 -public class YonghuController { - private static final Logger logger = LoggerFactory.getLogger(YonghuController.class); // 日志记录器 - - private static final String TABLE_NAME = "yonghu"; // 数据库表名常量 - - @Autowired // 自动注入用户服务 - private YonghuService yonghuService; - - @Autowired // 自动注入Token服务 - private TokenService tokenService; - - // 注入其他相关服务 - @Autowired - private DictionaryService dictionaryService; // 字典服务 - @Autowired - private ForumService forumService; // 健身论坛服务 - @Autowired - private JianshenkechengService jianshenkechengService; // 健身课程服务 - @Autowired - private JianshenkechengCollectionService jianshenkechengCollectionService; // 课程收藏服务 - @Autowired - private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 课程留言服务 - @Autowired - private JiaolianService jiaolianService; // 教练服务 - @Autowired - private JiaolianYuyueService jiaolianYuyueService; // 教练预约服务 - @Autowired - private NewsService newsService; // 健身资讯服务 - @Autowired - private SingleSeachService singleSeachService; // 单页数据服务 - @Autowired - private UsersService usersService; // 管理员服务 - - //后端分页列表 - //@param params 请求参数Map - //@param request HTTP请求对象 - //@return 分页结果 - @RequestMapping("/page") - public R page(@RequestParam Map params, HttpServletRequest request){ - logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) // 条件判断 - return R.error(511,"永不会进入"); // 返回错误信息 - else if("用户".equals(role)) // 如果是用户角色 - params.put("yonghuId",request.getSession().getAttribute("userId")); // 添加用户ID参数 - else if("教练".equals(role)) // 如果是教练角色 - params.put("jiaolianId",request.getSession().getAttribute("userId")); // 添加教练ID参数 - params.put("dataDeleteStart",1);params.put("dataDeleteEnd",1); // 设置逻辑删除条件 - CommonUtil.checkMap(params); // 检查参数 - PageUtils page = yonghuService.queryPage(params); // 分页查询 - - // 字典表数据转换 - List list =(List)page.getList(); // 获取分页数据 - for(YonghuView c:list){ // 遍历数据 - dictionaryService.dictionaryConvert(c, request); // 转换字典表字段 - } - return R.ok().put("data", page); // 返回分页结果 - } - - - //后端详情 - //@param id 用户ID - //@param request HTTP请求对象 - //@return 用户详情 - @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id, HttpServletRequest request){ - logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); - YonghuEntity yonghu = yonghuService.selectById(id); // 根据ID查询用户 - if(yonghu !=null){ // 如果查询到数据 - YonghuView view = new YonghuView(); // 创建视图对象 - BeanUtils.copyProperties(yonghu, view); // 复制属性到视图对象 - dictionaryService.dictionaryConvert(view, request); // 转换字典表字段 - return R.ok().put("data", view); // 返回成功结果 - }else { - return R.error(511,"查不到数据"); // 返回错误信息 - } - } - - //后端保存用户 - //@param yonghu 用户实体 - //@param request HTTP请求对象 - //@return 操作结果 - @RequestMapping("/save") - public R save(@RequestBody YonghuEntity yonghu, HttpServletRequest request){ - logger.debug("save方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString()); - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - if(false) // 条件判断 - return R.error(511,"永远不会进入"); // 返回错误信息 - - // 构建查询条件:检查用户名、手机号、身份证号是否已存在 - Wrapper queryWrapper = new EntityWrapper() - .eq("username", yonghu.getUsername()) // 用户名条件 - .or() // 或条件 - .eq("yonghu_phone", yonghu.getYonghuPhone()) // 手机号条件 - .or() // 或条件 - .eq("yonghu_id_number", yonghu.getYonghuIdNumber()) // 身份证号条件 - .eq("data_delete", 1) // 未删除条件 - ; - - logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句 - YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper); // 查询是否存在 - if(yonghuEntity==null){ // 如果不存在 - yonghu.setDataDelete(1); // 设置未删除状态 - yonghu.setInsertTime(new Date()); // 设置插入时间 - yonghu.setCreateTime(new Date()); // 设置创建时间 - yonghu.setPassword("123456"); // 设置默认密码 - yonghuService.insert(yonghu); // 插入新用户 - return R.ok(); // 返回成功结果 - }else { - return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用"); // 返回错误信息 } } - //后端修改用户 - //@param yonghu 用户实体 - //@param request HTTP请求对象 - //@return 操作结果 - @RequestMapping("/update") - public R update(@RequestBody YonghuEntity yonghu, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException { - logger.debug("update方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString()); - YonghuEntity oldYonghuEntity = yonghuService.selectById(yonghu.getId()); // 查询原数据 - String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色 - - if("".equals(yonghu.getYonghuPhoto()) || "null".equals(yonghu.getYonghuPhoto())){ // 如果图片为空 - yonghu.setYonghuPhoto(null); // 设置为null - } - - yonghuService.updateById(yonghu); // 更新用户信息 - return R.ok(); // 返回成功结果 - } - - - //删除用户(逻辑删除) - //@param ids 用户ID数组 - //@param request HTTP请求对象 - //@return 操作结果 - @RequestMapping("/delete") - public R delete(@RequestBody Integer[] ids, HttpServletRequest request){ - logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); - List oldYonghuList = yonghuService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据 - ArrayList list = new ArrayList<>(); // 创建更新列表 - for(Integer id:ids){ // 遍历ID数组 - YonghuEntity yonghuEntity = new YonghuEntity(); // 创建用户实体 - yonghuEntity.setId(id); // 设置ID - yonghuEntity.setDataDelete(2); // 设置删除状态 - list.add(yonghuEntity); // 添加到列表 - } - if(list != null && list.size() >0){ // 如果有数据需要更新 - yonghuService.updateBatchById(list); // 批量更新 - } - return R.ok(); // 返回成功结果 - } - - - //批量导入用户数据 - //@param fileName Excel文件名 - //@param request HTTP请求对象 - //@return 导入结果 - @RequestMapping("/batchInsert") - public R save(String fileName, HttpServletRequest request){ - logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); - Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取当前用户ID - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 创建日期格式化对象 - try { - List yonghuList = new ArrayList<>(); // 创建用户列表 - Map> seachFields = new HashMap<>(); // 创建查重字段Map - Date date = new Date(); // 当前时间 - int lastIndexOf = fileName.lastIndexOf("."); // 获取文件后缀位置 - if(lastIndexOf == -1){ // 如果没有后缀 - return R.error(511,"该文件没有后缀"); // 返回错误信息 - }else{ - String suffix = fileName.substring(lastIndexOf); // 获取文件后缀 - if(!".xls".equals(suffix)){ // 如果不是xls文件 - return R.error(511,"只支持后缀为xls的excel文件"); // 返回错误信息 - }else{ - URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 获取文件路径 - File file = new File(resource.getFile()); // 创建文件对象 - if(!file.exists()){ // 如果文件不存在 - return R.error(511,"找不到上传文件,请联系管理员"); // 返回错误信息 - }else{ - List> dataList = PoiUtil.poiImport(file.getPath()); // 读取Excel文件 - dataList.remove(0); // 删除标题行 - for(List data:dataList){ // 遍历数据行 - YonghuEntity yonghuEntity = new YonghuEntity(); // 创建用户实体 - // 可以在此处设置实体属性,示例中被注释掉了 - yonghuList.add(yonghuEntity); // 添加到列表 - - // 构建查重字段Map - // 账户查重 - if(seachFields.containsKey("username")){ - List username = seachFields.get("username"); - username.add(data.get(0)); // 添加用户名 - }else{ - List username = new ArrayList<>(); - username.add(data.get(0)); // 添加用户名 - seachFields.put("username",username); // 放入Map - } - // 手机号查重 - if(seachFields.containsKey("yonghuPhone")){ - List yonghuPhone = seachFields.get("yonghuPhone"); - yonghuPhone.add(data.get(0)); // 添加手机号 - }else{ - List yonghuPhone = new ArrayList<>(); - yonghuPhone.add(data.get(0)); // 添加手机号 - seachFields.put("yonghuPhone",yonghuPhone); // 放入Map - } - // 身份证号查重 - if(seachFields.containsKey("yonghuIdNumber")){ - List yonghuIdNumber = seachFields.get("yonghuIdNumber"); - yonghuIdNumber.add(data.get(0)); // 添加身份证号 - }else{ - List yonghuIdNumber = new ArrayList<>(); - yonghuIdNumber.add(data.get(0)); // 添加身份证号 - seachFields.put("yonghuIdNumber",yonghuIdNumber); // 放入Map - } - } - - // 查重验证 - // 验证用户名是否重复 - List yonghuEntities_username = yonghuService.selectList( - new EntityWrapper().in("username", seachFields.get("username")).eq("data_delete", 1)); - if(yonghuEntities_username.size() >0 ){ // 如果有重复 - ArrayList repeatFields = new ArrayList<>(); // 创建重复字段列表 - for(YonghuEntity s:yonghuEntities_username){ // 遍历重复数据 - repeatFields.add(s.getUsername()); // 添加重复用户名 - } - return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString()); // 返回错误信息 - } - // 验证手机号是否重复 - List yonghuEntities_yonghuPhone = yonghuService.selectList( - new EntityWrapper().in("yonghu_phone", seachFields.get("yonghuPhone")).eq("data_delete", 1)); - if(yonghuEntities_yonghuPhone.size() >0 ){ // 如果有重复 - ArrayList repeatFields = new ArrayList<>(); // 创建重复字段列表 - for(YonghuEntity s:yonghuEntities_yonghuPhone){ // 遍历重复数据 - repeatFields.add(s.getYonghuPhone()); // 添加重复手机号 - } - return R.error(511,"数据库的该表中的 [用户手机号] 字段已经存在 存在数据为:"+repeatFields.toString()); // 返回错误信息 - } - // 验证身份证号是否重复 - List yonghuEntities_yonghuIdNumber = yonghuService.selectList( - new EntityWrapper().in("yonghu_id_number", seachFields.get("yonghuIdNumber")).eq("data_delete", 1)); - if(yonghuEntities_yonghuIdNumber.size() >0 ){ // 如果有重复 - ArrayList repeatFields = new ArrayList<>(); // 创建重复字段列表 - for(YonghuEntity s:yonghuEntities_yonghuIdNumber){ // 遍历重复数据 - repeatFields.add(s.getYonghuIdNumber()); // 添加重复身份证号 - } - return R.error(511,"数据库的该表中的 [用户身份证号] 字段已经存在 存在数据为:"+repeatFields.toString()); // 返回错误信息 - } - yonghuService.insertBatch(yonghuList); // 批量插入数据 - return R.ok(); // 返回成功结果 - } - } - } - }catch (Exception e){ // 捕获异常 - e.printStackTrace(); // 打印异常堆栈 - return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息 - } - } - - - //用户登录 - //@param username 用户名 - //@param password 密码 - //@param captcha 验证码 - //@param request HTTP请求对象 - //@return 登录结果 - @IgnoreAuth // 忽略认证 - @RequestMapping(value = "/login") - public R login(String username, String password, String captcha, HttpServletRequest request) { - YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper().eq("username", username)); // 根据用户名查询用户 - if(yonghu==null || !yonghu.getPassword().equals(password)) // 验证用户名和密码 - return R.error("账号或密码不正确"); // 返回错误信息 - else if(yonghu.getDataDelete() != 1) // 检查是否被删除 - return R.error("账户已被删除"); // 返回错误信息 - String token = tokenService.generateToken(yonghu.getId(),username, "yonghu", "用户"); // 生成Token - R r = R.ok(); // 创建返回结果 - r.put("token", token); // 添加Token - r.put("role","用户"); // 添加角色 - r.put("username",yonghu.getYonghuName()); // 添加用户名 - r.put("tableName","yonghu"); // 添加表名 - r.put("userId",yonghu.getId()); // 添加用户ID - return r; // 返回结果 - } - - - //用户注册 - //@param yonghu 用户实体 - // @param request HTTP请求对象 - //@return 注册结果 - - @IgnoreAuth // 忽略认证 - @PostMapping(value = "/register") - public R register(@RequestBody YonghuEntity yonghu, HttpServletRequest request) { - // 构建查询条件:检查用户名、手机号、身份证号是否已存在 - Wrapper queryWrapper = new EntityWrapper() - .eq("username", yonghu.getUsername()) // 用户名条件 - .or() // 或条件 - .eq("yonghu_phone", yonghu.getYonghuPhone()) // 手机号条件 - .or() // 或条件 - .eq("yonghu_id_number", yonghu.getYonghuIdNumber()) // 身份证号条件 - .andNew() // 新条件组 - .eq("data_delete", 1) // 未删除条件 - ; - YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper); // 查询是否存在 - if(yonghuEntity != null) // 如果已存在 - return R.error("账户或者用户手机号或者用户身份证号已经被使用"); // 返回错误信息 - yonghu.setNewMoney(0.0); // 设置初始余额 - yonghu.setDataDelete(1); // 设置未删除状态 - yonghu.setInsertTime(new Date()); // 设置插入时间 - yonghu.setCreateTime(new Date()); // 设置创建时间 - yonghuService.insert(yonghu); // 插入新用户 - return R.ok(); // 返回成功结果 - } - - - //重置密码为默认值 - //@param id 用户ID - //@param request HTTP请求对象 - // @return 操作结果 - - @GetMapping(value = "/resetPassword") - public R resetPassword(Integer id, HttpServletRequest request) { - YonghuEntity yonghu = yonghuService.selectById(id); // 根据ID查询用户 - yonghu.setPassword("123456"); // 重置密码 - yonghuService.updateById(yonghu); // 更新用户 - return R.ok(); // 返回成功结果 - } - - //修改密码 - //@param oldPassword 旧密码 - //@param newPassword 新密码 - //@param request HTTP请求对象 - // @return 操作结果 - - @GetMapping(value = "/updatePassword") - public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) { - YonghuEntity yonghu = yonghuService.selectById((Integer)request.getSession().getAttribute("userId")); // 获取当前用户 - if(newPassword == null){ // 检查新密码是否为空 - return R.error("新密码不能为空") ; // 返回错误信息 - } - if(!oldPassword.equals(yonghu.getPassword())){ // 检查旧密码是否正确 - return R.error("原密码输入错误"); // 返回错误信息 - } - if(newPassword.equals(yonghu.getPassword())){ // 检查新旧密码是否相同 - return R.error("新密码不能和原密码一致") ; // 返回错误信息 - } - yonghu.setPassword(newPassword); // 设置新密码 - yonghuService.updateById(yonghu); // 更新用户 - return R.ok(); // 返回成功结果 - } - - //忘记密码(重置为默认密码) - //@param username 用户名 - //@param request HTTP请求对象 - //@return 操作结果 - @IgnoreAuth // 忽略认证 - @RequestMapping(value = "/resetPass") - public R resetPass(String username, HttpServletRequest request) { - YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper().eq("username", username)); // 根据用户名查询用户 - if(yonghu!=null){ // 如果用户存在 - yonghu.setPassword("123456"); // 重置密码 - yonghuService.updateById(yonghu); // 更新用户 - return R.ok(); // 返回成功结果 - }else{ // 如果用户不存在 - return R.error("账号不存在"); // 返回错误信息 ->>>>>>> develop - } - } - - -<<<<<<< HEAD /** * 获取用户的session用户信息 */ @@ -863,27 +429,10 @@ public class YonghuController { return R.ok().put("data", view); }else { return R.error(511,"查不到数据"); -======= - //获取当前会话用户信息 - //@param request HTTP请求对象 - //@return 用户信息 - @RequestMapping("/session") - public R getCurrYonghu(HttpServletRequest request){ - Integer id = (Integer)request.getSession().getAttribute("userId"); // 获取当前用户ID - YonghuEntity yonghu = yonghuService.selectById(id); // 查询用户信息 - if(yonghu !=null){ // 如果用户存在 - YonghuView view = new YonghuView(); // 创建视图对象 - BeanUtils.copyProperties(yonghu, view); // 复制属性 - dictionaryService.dictionaryConvert(view, request); // 转换字典字段 - return R.ok().put("data", view); // 返回用户信息 - }else { - return R.error(511,"查不到数据"); // 返回错误信息 ->>>>>>> develop } } -<<<<<<< HEAD /** * 退出 */ @@ -970,85 +519,3 @@ public class YonghuController { } -======= - //用户退出 - //@param request HTTP请求对象 - //@return 操作结果 - @GetMapping(value = "logout") - public R logout(HttpServletRequest request) { - request.getSession().invalidate(); // 使会话失效 - return R.ok("退出成功"); // 返回成功信息 - } - - - //前端分页列表 - //@param params 请求参数 - //@param request HTTP请求对象 - //@return 分页结果 - @IgnoreAuth // 忽略认证 - @RequestMapping("/list") - public R list(@RequestParam Map params, HttpServletRequest request){ - logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); - CommonUtil.checkMap(params); // 检查参数 - PageUtils page = yonghuService.queryPage(params); // 分页查询 - - // 字典表数据转换 - List list =(List)page.getList(); // 获取分页数据 - for(YonghuView c:list) // 遍历数据 - dictionaryService.dictionaryConvert(c, request); // 转换字典字段 - - return R.ok().put("data", page); // 返回分页结果 - } - - - //前端详情 - //@param id 用户ID - //@param request HTTP请求对象 - //@return 用户详情 - @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Integer id, HttpServletRequest request){ - logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); - YonghuEntity yonghu = yonghuService.selectById(id); // 根据ID查询用户 - if(yonghu !=null){ // 如果用户存在 - YonghuView view = new YonghuView(); // 创建视图对象 - BeanUtils.copyProperties(yonghu, view); // 复制属性 - dictionaryService.dictionaryConvert(view, request); // 转换字典字段 - return R.ok().put("data", view); // 返回用户信息 - }else { - return R.error(511,"查不到数据"); // 返回错误信息 - } - } - - - //前端保存用户 - //@param yonghu 用户实体 - //@param request HTTP请求对象 - //@return 操作结果 - @RequestMapping("/add") - public R add(@RequestBody YonghuEntity yonghu, HttpServletRequest request){ - logger.debug("add方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString()); - // 构建查询条件:检查用户名、手机号、身份证号是否已存在 - Wrapper queryWrapper = new EntityWrapper() - .eq("username", yonghu.getUsername()) // 用户名条件 - .or() // 或条件 - .eq("yonghu_phone", yonghu.getYonghuPhone()) // 手机号条件 - .or() // 或条件 - .eq("yonghu_id_number", yonghu.getYonghuIdNumber()) // 身份证号条件 - .andNew() // 新条件组 - .eq("data_delete", 1) // 未删除条件 - ; - logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句 - YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper); // 查询是否存在 - if(yonghuEntity==null){ // 如果不存在 - yonghu.setDataDelete(1); // 设置未删除状态 - yonghu.setInsertTime(new Date()); // 设置插入时间 - yonghu.setCreateTime(new Date()); // 设置创建时间 - yonghu.setPassword("123456"); // 设置默认密码 - yonghuService.insert(yonghu); // 插入新用户 - return R.ok(); // 返回成功结果 - }else { - return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用"); // 返回错误信息 - } - } -} ->>>>>>> develop