Compare commits

...

19 Commits

Author SHA1 Message Date
pxwi83ejl e31d3c3fc7 Merge pull request '小组汇总' (#16) from develop into main
1 year ago
pxwi83ejl 46133e2648 Merge pull request '叶黎海谊注释' (#15) from edu/Manger into develop
1 year ago
张展望 72ff8ffe11 Merge branch 'edu/Manger' of bdgit.educoder.net:pfi6fjnhr/Onlineeducation into edu/Manger
1 year ago
张展望 41ff19df74 Merge remote-tracking branch 'origin/edu/Manger' into edu/Manger
1 year ago
pfi6fjnhr 11fda2e241 张展望注释 (#11)
1 year ago
pxwi83ejl 1202871465 Merge pull request '顾士鑫注释' (#10) from edu/User into develop
1 year ago
张展望 2d5a05cc81 Merge remote-tracking branch 'origin/edu/Manger' into edu/Manger
1 year ago
pxwi83ejl 792ccd9525 测试 (#9)
1 year ago
张展望 698ebe7269 Merge remote-tracking branch 'origin/edu/Manger' into edu/Manger
1 year ago
pxwi83ejl 7cc388f0d6 11 (#8)
1 year ago
taeyeon fff2717c3f Merge remote-tracking branch 'origin/edu/Manger' into edu/Manger
1 year ago
pxwi83ejl a2004fefc5 Merge pull request '11' (#7) from edu/Manger into develop
1 year ago
taeyeon 2e48f623bb Merge remote-tracking branch 'origin/edu/Manger' into edu/Manger
1 year ago
taeyeon 78bfcdf4f8 Merge remote-tracking branch 'origin/edu/Manger' into edu/Manger
1 year ago
pfi6fjnhr 61ec272eb4 pull request (#6)
1 year ago
taeyeon 0542e1438d Merge remote-tracking branch 'origin/edu/Manger' into edu/Manger
1 year ago
taeyeon 775c6c3e4d adadad
1 year ago
pxwi83ejl 8f5df73b1d Merge pull request 'pull request' (#5) from develop into main
1 year ago
pxwi83ejl 64160ce765 Merge pull request 'pull request' (#4) from edu/Manger into develop
1 year ago

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012 - 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,91 +13,128 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// 导入 java.net 包中的类,用于处理网络相关操作
import java.net.*;
// 导入 java.io 包中的类,用于输入输出操作
import java.io.*;
// 导入 java.nio.channels 包中的类,用于使用 NIO 通道进行高效的 I/O 操作
import java.nio.channels.*;
// 导入 java.util.Properties 类,用于处理属性文件
import java.util.Properties;
// 定义 MavenWrapperDownloader 类,用于下载 Maven 包装器 JAR 文件
public class MavenWrapperDownloader {
// 定义 Maven 包装器的版本号
private static final String WRAPPER_VERSION = "0.5.5";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
* 'downloadUrl' URL maven-wrapper.jar
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
* maven-wrapper.properties downloadUrl URL
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
* maven-wrapper.jar
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
* URL
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
// 程序的入口点
public static void main(String args[]) {
// 打印下载器启动信息
System.out.println("- Downloader started");
// 根据命令行参数创建基础目录文件对象
File baseDirectory = new File(args[0]);
// 打印使用的基础目录的绝对路径
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
// 如果 maven-wrapper.properties 文件存在,读取它并检查是否包含自定义的 wrapperUrl 参数
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
// 初始化下载 URL 为默认值
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
// 用于读取 maven-wrapper.properties 文件的输入流
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
// 打开 maven-wrapper.properties 文件的输入流
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
// 创建 Properties 对象用于存储属性文件中的键值对
Properties mavenWrapperProperties = new Properties();
// 从输入流中加载属性文件内容
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
// 获取自定义的下载 URL如果不存在则使用默认值
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
// 打印加载 maven-wrapper.properties 文件出错信息
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
// 关闭输入流
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
// 忽略关闭输入流时可能出现的异常
}
}
}
// 打印下载的 URL
System.out.println("- Downloading from: " + url);
// 创建要保存 maven-wrapper.jar 的文件对象
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
// 如果输出文件的父目录不存在,则创建它
if(!outputFile.getParentFile().exists()) {
// 如果创建父目录失败,打印错误信息
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
// 打印下载文件的保存路径
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
// 调用下载文件的方法
downloadFileFromURL(url, outputFile);
// 打印下载完成信息
System.out.println("Done");
// 正常退出程序
System.exit(0);
} catch (Throwable e) {
// 打印下载出错信息
System.out.println("- Error downloading");
// 打印异常堆栈信息
e.printStackTrace();
// 异常退出程序
System.exit(1);
}
}
// 从指定 URL 下载文件到指定目标文件的方法
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
// 如果环境变量中设置了 MVNW_USERNAME 和 MVNW_PASSWORD
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
// 获取用户名
String username = System.getenv("MVNW_USERNAME");
// 获取密码并转换为字符数组
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
// 设置认证器
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
@ -105,13 +142,20 @@ public class MavenWrapperDownloader {
}
});
}
// 创建 URL 对象
URL website = new URL(urlString);
// 用于读取网络数据的通道
ReadableByteChannel rbc;
// 打开 URL 连接并创建通道
rbc = Channels.newChannel(website.openStream());
// 创建用于写入文件的输出流
FileOutputStream fos = new FileOutputStream(destination);
// 将通道中的数据传输到文件输出流的通道中
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
// 关闭输出流
fos.close();
// 关闭通道
rbc.close();
}
}
}

File diff suppressed because it is too large Load Diff

973
mvnw vendored

File diff suppressed because it is too large Load Diff

106
mvnw.cmd vendored

@ -1,133 +1,217 @@
@REM ----------------------------------------------------------------------------
@REM 此注释块表明该文件遵循 Apache 软件基金会的许可协议
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM 可能有一个或多个贡献者与 ASF 签订了许可协议
@REM or more contributor license agreements. See the NOTICE file
@REM 查看随此项目一同分发的 NOTICE 文件,获取更多版权信息
@REM distributed with this work for additional information
@REM 关于版权归属的详细信息
@REM regarding copyright ownership. The ASF licenses this file
@REM ASF 根据 Apache 许可证 2.0 版本将此文件授权给你
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM 除非你遵守该许可协议,否则不能使用此文件
@REM with the License. You may obtain a copy of the License at
@REM
@REM 你可以在下面的链接获取许可协议副本
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM 除非适用法律要求或书面同意
@REM software distributed under the License is distributed on an
@REM 根据许可协议分发的软件按“原样”分发
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM 不附带任何形式的明示或暗示保证和条件
@REM KIND, either express or implied. See the License for the
@REM 查看许可协议以了解相关权限和限制的具体条款
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM 此注释块介绍了这是一个 Maven2 的启动批处理脚本
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM 必需的环境变量
@REM JAVA_HOME - location of a JDK home dir
@REM JAVA_HOME 环境变量,指向 JDK 的安装目录
@REM
@REM Optional ENV vars
@REM 可选的环境变量
@REM M2_HOME - location of maven2's installed home dir
@REM M2_HOME 环境变量,指向 Maven2 的安装目录
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_ECHO 环境变量,设置为 'on' 可启用批处理命令的回显
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_BATCH_PAUSE 环境变量,设置为 'on' 可在脚本结束前等待按键
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM MAVEN_OPTS 环境变量,用于在运行 Maven 时传递给 Java 虚拟机的参数
@REM e.g. to debug Maven itself, use
@REM 例如,要调试 Maven 本身,可使用以下设置
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM MAVEN_SKIP_RC 环境变量,用于禁用加载 mavenrc 文件的标志
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@REM 以 '@' 开头的 REM 行,防止在 MAVEN_BATCH_ECHO 为 'on' 时回显注释
@echo off
@REM 关闭命令回显,避免在执行脚本时显示命令本身
@REM set title of command window
@REM 设置命令窗口的标题
title %0
@REM 将命令窗口的标题设置为当前脚本的名称
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@REM 通过将 MAVEN_BATCH_ECHO 设置为 'on' 来启用命令回显
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM 如果 MAVEN_BATCH_ECHO 环境变量的值为 'on',则开启命令回显
@REM set %HOME% to equivalent of $HOME
@REM 将 %HOME% 环境变量设置为与 $HOME 等效的值
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM 如果 %HOME% 环境变量未设置,则将其设置为当前用户的主目录
@REM Execute a user defined script before this one
@REM 在执行此脚本之前执行用户定义的脚本
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM 如果 MAVEN_SKIP_RC 环境变量不为空,则跳过执行用户定义的前置脚本
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
@REM 检查是否存在前置脚本,分别检查以 .bat 和 .cmd 结尾的文件
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
@REM 如果存在 %HOME%\mavenrc_pre.bat 文件,则调用该脚本
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
@REM 如果存在 %HOME%\mavenrc_pre.cmd 文件,则调用该脚本
:skipRcPre
@REM 跳过执行用户定义的前置脚本的标签
@setlocal
@REM 开启本地环境变量作用域,确保后续设置的变量只在当前脚本块内有效
set ERROR_CODE=0
@REM 初始化错误代码为 0表示脚本执行正常
@REM To isolate internal variables from possible post scripts, we use another setlocal
@REM 为了将内部变量与可能的后置脚本隔离开,我们再次使用 setlocal
@setlocal
@REM ==== START VALIDATION ====
@REM 开始验证环境变量
if not "%JAVA_HOME%" == "" goto OkJHome
@REM 如果 JAVA_HOME 环境变量已设置,则跳转到 OkJHome 标签
echo.
echo Error: JAVA_HOME not found in your environment. >&2
@REM 输出错误信息,提示 JAVA_HOME 环境变量未找到
echo Please set the JAVA_HOME variable in your environment to match the >&2
@REM 提示用户设置 JAVA_HOME 环境变量
echo location of your Java installation. >&2
@REM 提示用户将 JAVA_HOME 设置为 Java 安装目录
echo.
goto error
@REM 跳转到 error 标签,处理错误情况
:OkJHome
@REM JAVA_HOME 环境变量已设置的标签
if exist "%JAVA_HOME%\bin\java.exe" goto init
@REM 如果 JAVA_HOME\bin\java.exe 文件存在,则跳转到 init 标签
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
@REM 输出错误信息,提示 JAVA_HOME 设置为无效目录
echo JAVA_HOME = "%JAVA_HOME%" >&2
@REM 显示当前 JAVA_HOME 的值
echo Please set the JAVA_HOME variable in your environment to match the >&2
@REM 提示用户设置正确的 JAVA_HOME 环境变量
echo location of your Java installation. >&2
@REM 提示用户将 JAVA_HOME 设置为 Java 安装目录
echo.
goto error
@REM 跳转到 error 标签,处理错误情况
@REM ==== END VALIDATION ====
@REM 结束环境变量验证
:init
@REM 初始化标签
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM 查找项目的基础目录,即包含 .mvn 文件夹的目录
@REM Fallback to current working directory if not found.
@REM 如果未找到,则使用当前工作目录作为基础目录
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
@REM 将 MAVEN_PROJECTBASEDIR 环境变量设置为 MAVEN_BASEDIR 的值
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
@REM 如果 MAVEN_PROJECTBASEDIR 环境变量不为空,则跳转到 endDetectBaseDir 标签
set EXEC_DIR=%CD%
@REM 将 EXEC_DIR 环境变量设置为当前工作目录
set WDIR=%EXEC_DIR%
@REM 将 WDIR 环境变量设置为当前工作目录
:findBaseDir
@REM 查找基础目录的标签
IF EXIST "%WDIR%"\.mvn goto baseDirFound
@REM 如果当前目录下存在 .mvn 文件夹,则跳转到 baseDirFound 标签
cd ..
@REM 切换到上一级目录
IF "%WDIR%"=="%CD%" goto baseDirNotFound
@REM 如果已经到达根目录,则跳转到 baseDirNotFound 标签
set WDIR=%CD%
@REM 更新 WDIR 环境变量为当前目录
goto findBaseDir
@REM 继续查找基础目录
:baseDirFound
@REM 找到基础目录的标签
set MAVEN_PROJECTBASEDIR=%WDIR%
@REM 将 MAVEN_PROJECTBASEDIR 环境变量设置为找到的基础目录
cd "%EXEC_DIR%"
@REM 切换回原来的工作目录
goto endDetectBaseDir
@REM 跳转到 endDetectBaseDir 标签
:baseDirNotFound
@REM 未找到基础目录的标签
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
@REM 将 MAVEN_PROJECTBASEDIR 环境变量设置为当前工作目录
cd "%EXEC_DIR%"
@REM 切换回原来的工作目录
:endDetectBaseDir
@REM 结束基础目录检测的标签
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@REM 如果 %MAVEN_PROJECTBASEDIR%\.mvn\jvm.config 文件不存在,则跳转到 endReadAdditionalConfig 标签
@setlocal EnableExtensions EnableDelayedExpansion
@REM 开启扩展和延迟环境变量扩展
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@REM 读取 %MAVEN_PROJECTBASEDIR%\.mvn\jvm.config 文件的内容,并将其添加到 JVM_CONFIG_MAVEN_PROPS 环境变量中
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
@REM 结束本地环境变量作用域,并将 JVM_CONFIG_MAVEN_PROPS 环境变量传递到外部
:endReadAdditionalConfig
@REM 结束读取额外配置文件的标签
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
@REM 设置 MAVEN_JAVA_EXE 环境变量为 Java 可执行文件的路径
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
@REM 设置 WRAPPER_JAR 环境变量为 Maven 包装器 JAR 文件的路径
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
@REM 设置 WRAPPER_LAUNCHER 环境变量为 Maven 包装器的主类名
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
@REM 设置 DOWNLOAD_URL 环境变量为 Maven 包装器 JAR 文件的下载地址
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM 读取 %MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties 文件,查找 wrapperUrl 属性,并更新 DOWNLOAD_URL 环境变量
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM 扩展功能,允许自动从 Maven 中央仓库下载 maven-wrapper.jar 文件
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
@REM 这允许在禁止提交二进制数据的项目中使用 Maven 包装器
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
@ -153,30 +237,50 @@ if exist %WRAPPER_JAR% (
)
)
@REM End of extension
@REM 扩展功能结束
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM 提供一种“标准化”的方式来获取命令行参数
@REM work with both Windows and non-Windows executions.
@REM 适用于 Windows 和非 Windows 系统的执行环境
set MAVEN_CMD_LINE_ARGS=%*
@REM 将 MAVEN_CMD_LINE_ARGS 环境变量设置为所有命令行参数
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
@REM 执行 Java 命令,启动 Maven 包装器
if ERRORLEVEL 1 goto error
@REM 如果执行 Java 命令返回错误码,则跳转到 error 标签
goto end
@REM 跳转到 end 标签
:error
@REM 错误处理标签
set ERROR_CODE=1
@REM 设置错误代码为 1表示脚本执行出错
:end
@REM 结束标签
@endlocal & set ERROR_CODE=%ERROR_CODE%
@REM 结束本地环境变量作用域,并将错误代码传递到外部
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM 如果 MAVEN_SKIP_RC 环境变量不为空,则跳过执行用户定义的后置脚本
@REM check for post script, once with legacy .bat ending and once with .cmd ending
@REM 检查是否存在后置脚本,分别检查以 .bat 和 .cmd 结尾的文件
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
@REM 如果存在 %HOME%\mavenrc_post.bat 文件,则调用该脚本
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
@REM 如果存在 %HOME%\mavenrc_post.cmd 文件,则调用该脚本
:skipRcPost
@REM 跳过执行用户定义的后置脚本的标签
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
@REM 如果 MAVEN_BATCH_PAUSE 环境变量设置为 'on',则暂停脚本执行
if "%MAVEN_BATCH_PAUSE%" == "on" pause
@REM 等待用户按键
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
@REM 如果 MAVEN_TERMINATE_CMD 环境变量设置为 'on',则退出命令提示符并返回错误代码
exit /B %ERROR_CODE%
@REM 退出当前批处理脚本并返回错误代码

@ -1,116 +1,138 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- 定义项目的根元素,使用 Maven POM 4.0.0 架构 -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- 指定 POM 模型的版本,固定为 4.0.0 -->
<modelVersion>4.0.0</modelVersion>
<!-- 定义项目的父 POM继承父项目的配置 -->
<parent>
<!-- 父项目的组 ID -->
<groupId>org.springframework.boot</groupId>
<!-- 父项目的项目 ID -->
<artifactId>spring-boot-starter-parent</artifactId>
<!-- 父项目的版本 -->
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
<!-- 查找父项目的相对路径,为空表示从仓库中查找 -->
<relativePath/>
</parent>
<!-- 项目的组 ID通常是公司或组织的域名倒序 -->
<groupId>com.jlwl</groupId>
<!-- 导入项目的名称 -->
<artifactId>springbootus5uu</artifactId>
<!-- 项目的版本SNAPSHOT 表示快照版本 -->
<version>0.0.1-SNAPSHOT</version>
<!-- 项目的名称 -->
<name>springboot-schema</name>
<!-- 项目的描述信息,说明是 springboot 学习框架,以及打 war 包的命令 -->
<description>springboot学习框架(war包对应的pom打war包执行【mvn clean package -f pom-war.xml】)</description>
<!-- 项目的打包方式,这里指定为 war 包 -->
<packaging>war</packaging>
<!-- 定义项目的属性 -->
<properties>
<!-- Java 版本 -->
<java.version>1.8</java.version>
<!-- FastJson 版本 -->
<fastjson.version>1.2.8</fastjson.version>
<!-- Maven JAR 插件版本 -->
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>
<!-- 定义项目的依赖 -->
<dependencies>
<!-- Spring Boot Web 启动器依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- MyBatis Spring Boot 启动器依赖 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
<!-- Spring Boot JDBC 启动器依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- Spring Boot Tomcat 启动器依赖scope 为 provided 表示运行时由容器提供 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- MySQL 数据库连接驱动依赖 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- Apache Shiro Spring 集成依赖 -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.3.2</version>
</dependency>
<!-- MyBatis-Plus 依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>2.3</version>
</dependency>
<!-- MyBatis-Plus Spring Boot 启动器依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatisplus-spring-boot-starter</artifactId>
<version>1.0.5</version>
</dependency>
<!-- Google Protobuf Java 依赖 -->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.10.0</version>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.10.0</version>
</dependency>
<!-- Apache Commons Lang3 依赖 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<!-- Java 验证 API 依赖 -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<!-- Apache Commons IO 依赖 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<!-- Hutool 工具集依赖 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.0.12</version>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.0.12</version>
</dependency>
<!-- FastJson -->
<!-- FastJson 依赖,版本使用属性中定义的值 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- 百度人工智能 -->
<!-- 百度人工智能 Java SDK 依赖 -->
<dependency>
<groupId>com.baidu.aip</groupId>
<artifactId>java-sdk</artifactId>
<version>4.4.1</version>
<groupId>com.baidu.aip</groupId>
<artifactId>java-sdk</artifactId>
<version>4.4.1</version>
</dependency>
<!-- Spring Boot 测试启动器依赖scope 为 test 表示只在测试时使用 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<!-- 排除 JUnit Vintage 引擎依赖 -->
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
@ -120,23 +142,27 @@
</dependency>
</dependencies>
<!-- 定义项目的构建配置 -->
<build>
<!-- 最终生成的 WAR 包名称 -->
<finalName>springbootus5uu</finalName>
<!-- 定义构建插件 -->
<plugins>
<!-- Spring Boot Maven 插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- 跳过单元测试 -->
<!-- 跳过单元测试的插件配置 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- 设置为 true 表示跳过单元测试 -->
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
</project>

@ -1,143 +1,219 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- 声明 XML 文档的版本为 1.0,字符编码为 UTF-8 -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- 定义项目的根元素,指定 Maven POM 的命名空间和 XML 模式实例命名空间,并设置模式位置 -->
<modelVersion>4.0.0</modelVersion>
<!-- 指定项目的模型版本为 4.0.0 -->
<parent>
<!-- 定义项目的父项目配置 -->
<groupId>org.springframework.boot</groupId>
<!-- 父项目的组 ID这里是 Spring Boot 项目的组 ID -->
<artifactId>spring-boot-starter-parent</artifactId>
<!-- 父项目的工件 IDspring-boot-starter-parent 是 Spring Boot 的起始父项目 -->
<version>2.2.2.RELEASE</version>
<!-- 父项目的版本号 -->
<relativePath/> <!-- lookup parent from repository -->
<!-- 不指定父项目的相对路径,从仓库中查找父项目 -->
</parent>
<groupId>com.jlwl</groupId>
<!-- 项目的组 ID标识项目所属的组织或组 -->
<!-- 导入项目的名称 -->
<artifactId>springbootus5uu</artifactId>
<!-- 项目的工件 ID唯一标识项目 -->
<version>0.0.1-SNAPSHOT</version>
<!-- 项目的版本号,这里是一个快照版本 -->
<name>springboot-schema</name>
<description>springboot学习框架</description>
<!-- 项目的名称,用于展示等用途 -->
<description>springboot学习框架(war包对应的pom打war包执行【mvn clean package -f pom-war.xml】)</description>
<!-- 项目的描述信息,说明项目用途以及打 war 包的相关指令 -->
<packaging>war</packaging>
<!-- 指定项目打包的类型为 war 包 -->
<properties>
<!-- 定义项目的属性 -->
<java.version>1.8</java.version>
<!-- 指定项目使用的 Java 版本为 1.8 -->
<fastjson.version>1.2.8</fastjson.version>
<!-- 定义 fastjson 依赖的版本号为 1.2.8 -->
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
<!-- 定义 maven-jar-plugin 插件的版本号为 3.1.1 -->
</properties>
<dependencies>
<!-- 定义项目的依赖关系 -->
<dependency>
<!-- 单个依赖项的配置 -->
<groupId>org.springframework.boot</groupId>
<!-- 依赖的组 ID这里是 Spring Boot 的组 ID -->
<artifactId>spring-boot-starter-web</artifactId>
<!-- 依赖的工件 IDspring-boot-starter-web 是 Spring Boot 的 Web 启动器依赖 -->
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<!-- MyBatis Spring Boot 集成依赖的组 ID -->
<artifactId>mybatis-spring-boot-starter</artifactId>
<!-- MyBatis Spring Boot 启动器依赖的工件 ID -->
<version>2.1.1</version>
<!-- 依赖的版本号为 2.1.1 -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<groupId>org.springframework.boot</groupId>
<!-- Spring Boot 组 ID -->
<artifactId>spring-boot-starter-jdbc</artifactId>
<!-- Spring Boot 的 JDBC 启动器依赖的工件 ID -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<!-- Spring Boot 组 ID -->
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- Spring Boot 的 Tomcat 启动器依赖的工件 ID -->
<scope>provided</scope>
<!-- 依赖的作用域为 provided表示在编译和测试阶段可用但在运行时由容器提供不会被打包进最终的 war 包 -->
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<groupId>mysql</groupId>
<!-- MySQL 数据库驱动的组 ID -->
<artifactId>mysql-connector-java</artifactId>
<!-- MySQL 数据库驱动的工件 ID -->
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<!-- Apache Shiro 框架的组 ID -->
<artifactId>shiro-spring</artifactId>
<!-- Shiro 与 Spring 集成的依赖的工件 ID -->
<version>1.3.2</version>
<!-- 依赖的版本号为 1.3.2 -->
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<!-- 项目组 ID这里是 Baomidou -->
<artifactId>mybatis-plus</artifactId>
<!-- MyBatis-Plus 框架的工件 ID -->
<version>2.3</version>
<!-- 依赖的版本号为 2.3 -->
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<!-- Baomidou 组 ID -->
<artifactId>mybatisplus-spring-boot-starter</artifactId>
<!-- MyBatis-Plus 与 Spring Boot 集成的启动器依赖的工件 ID -->
<version>1.0.5</version>
<!-- 依赖的版本号为 1.0.5 -->
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.10.0</version>
<groupId>com.google.protobuf</groupId>
<!-- Google Protocol Buffers 的组 ID -->
<artifactId>protobuf-java</artifactId>
<!-- Google Protocol Buffers Java 库的工件 ID -->
<version>3.10.0</version>
<!-- 依赖的版本号为 3.10.0 -->
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
<groupId>org.apache.commons</groupId>
<!-- Apache Commons 项目的组 ID -->
<artifactId>commons-lang3</artifactId>
<!-- Apache Commons Lang 3 库的工件 ID -->
<version>3.0</version>
<!-- 依赖的版本号为 3.0 -->
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
<groupId>javax.validation</groupId>
<!-- Java 验证 API 的组 ID -->
<artifactId>validation-api</artifactId>
<!-- 验证 API 的工件 ID -->
<version>2.0.1.Final</version>
<!-- 依赖的版本号为 2.0.1.Final -->
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<groupId>commons-io</groupId>
<!-- Apache Commons IO 项目的组 ID -->
<artifactId>commons-io</artifactId>
<!-- Apache Commons IO 库的工件 ID -->
<version>2.5</version>
<!-- 依赖的版本号为 2.5 -->
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.0.12</version>
<groupId>cn.hutool</groupId>
<!-- Hutool 工具库的组 ID -->
<artifactId>hutool-all</artifactId>
<!-- Hutool 全功能工具库的工件 ID -->
<version>4.0.12</version>
<!-- 依赖的版本号为 4.0.12 -->
</dependency>
<!-- FastJson -->
<dependency>
<groupId>com.alibaba</groupId>
<!-- 阿里巴巴的组 ID -->
<artifactId>fastjson</artifactId>
<!-- FastJson 库的工件 ID -->
<version>${fastjson.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.microsoft.sqlserver</groupId>-->
<!-- <artifactId>sqljdbc4</artifactId>-->
<!-- <scope>4.0</scope>-->
<!-- <version>4.0</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.2.0.jre8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.2.0.jre8</version>
<scope>runtime</scope>
<!-- 使用之前定义的 fastjson.version 属性作为版本号 -->
</dependency>
<!-- 百度人工智能 -->
<dependency>
<groupId>com.baidu.aip</groupId>
<artifactId>java-sdk</artifactId>
<version>4.4.1</version>
<groupId>com.baidu.aip</groupId>
<!-- 百度 AI 组 ID -->
<artifactId>java-sdk</artifactId>
<!-- 百度 AI Java SDK 的工件 ID -->
<version>4.4.1</version>
<!-- 依赖的版本号为 4.4.1 -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<!-- Spring Boot 组 ID -->
<artifactId>spring-boot-starter-test</artifactId>
<!-- Spring Boot 测试启动器依赖的工件 ID -->
<scope>test</scope>
<!-- 依赖的作用域为测试 -->
<exclusions>
<!-- 排除不需要的依赖 -->
<exclusion>
<groupId>org.junit.vintage</groupId>
<!-- 要排除的依赖的组 ID -->
<artifactId>junit-vintage-engine</artifactId>
<!-- 要排除的依赖的工件 ID -->
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<!-- 定义项目的构建配置 -->
<finalName>springbootus5uu</finalName>
<!-- 设置最终生成的 war 包的名称为 springbootus5uu -->
<plugins>
<!-- 定义项目使用的插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<!-- Spring Boot 组 ID -->
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- Spring Boot Maven 插件的工件 ID -->
</plugin>
<!-- 跳过单元测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<!-- Apache Maven 插件组 ID -->
<artifactId>maven-surefire-plugin</artifactId>
<!-- Maven Surefire 插件的工件 ID用于运行单元测试 -->
<configuration>
<!-- 插件的配置 -->
<skipTests>true</skipTests>
<!-- 设置为 true 表示在构建过程中跳过单元测试 -->
</configuration>
</plugin>
</plugins>
</build>
</project>
</project>

@ -28,11 +28,11 @@ public class InterceptorConfig extends WebMvcConfigurationSupport{
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/resources/")
.addResourceLocations("classpath:/static/")
.addResourceLocations("classpath:/admin/")
.addResourceLocations("classpath:/resources/")//测试
.addResourceLocations("classpath:/static/")//测试
.addResourceLocations("classpath:/admin/")//测试
.addResourceLocations("classpath:/front/")
.addResourceLocations("classpath:/public/");
super.addResourceHandlers(registry);
super.addResourceHandlers(registry);//测试
}
}

@ -1,231 +1,346 @@
package com.controller;
// 导入用于格式化日期的类
import java.text.SimpleDateFormat;
// 导入ArrayList类用于创建动态数组
import java.util.ArrayList;
// 导入Arrays类提供操作数组的静态方法
import java.util.Arrays;
// 导入Calendar类用于处理日期和时间
import java.util.Calendar;
// 导入Map接口用于存储键值对
import java.util.Map;
// 导入HashMap类实现了Map接口
import java.util.HashMap;
// 导入Iterator接口用于遍历集合
import java.util.Iterator;
// 导入Date类用于表示特定的瞬间
import java.util.Date;
// 导入List接口用于存储有序的元素集合
import java.util.List;
// 导入HttpServletRequest类用于获取客户端请求信息
import javax.servlet.http.HttpServletRequest;
// 导入自定义的验证工具类
import com.utils.ValidatorUtils;
// 导入Apache Commons Lang库中的StringUtils类用于处理字符串
import org.apache.commons.lang3.StringUtils;
// 导入Spring框架的自动装配注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入Spring框架的日期格式化注解
import org.springframework.format.annotation.DateTimeFormat;
// 导入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;
// 导入MyBatis-Plus的实体包装器类
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入MyBatis-Plus的包装器接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解
import com.annotation.IgnoreAuth;
// 导入Chat实体类
import com.entity.ChatEntity;
// 导入Chat视图类
import com.entity.view.ChatView;
// 导入Chat服务类
import com.service.ChatService;
// 导入Token服务类
import com.service.TokenService;
// 导入自定义的分页工具类
import com.utils.PageUtils;
// 导入自定义的响应结果类
import com.utils.R;
// 导入自定义的MD5工具类
import com.utils.MD5Util;
// 导入自定义的MyBatis-Plus工具类
import com.utils.MPUtil;
// 导入自定义的通用工具类
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:15
*/
// 声明为RESTful风格的控制器
@RestController
// 定义请求的基础路径
@RequestMapping("/chat")
public class ChatController {
@Autowired
private ChatService chatService;
/**
*
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ChatEntity chat,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
chat.setUserid((Long)request.getSession().getAttribute("userId"));
}
EntityWrapper<ChatEntity> ew = new EntityWrapper<ChatEntity>();
// 自动装配ChatService实例
@Autowired
private ChatService chatService;
/**
*
*/
// 处理/page请求
@RequestMapping("/page")
// 方法接收请求参数、Chat实体和HttpServletRequest对象
public R page(@RequestParam Map<String, Object> params, ChatEntity chat,
HttpServletRequest request) {
// 如果当前用户不是管理员
if (!request.getSession().getAttribute("role").toString().equals("管理员")) {
// 设置Chat实体的用户ID为当前用户ID
chat.setUserid((Long) request.getSession().getAttribute("userId"));
}
// 创建MyBatis-Plus的实体包装器
EntityWrapper<ChatEntity> ew = new EntityWrapper<ChatEntity>();
// 调用ChatService的queryPage方法进行分页查询
PageUtils page = chatService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, chat), params), params));
// 返回成功响应,并将分页数据放入响应中
return R.ok().put("data", page);
}
return R.ok().put("data", page);
}
/**
*
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ChatEntity chat,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
chat.setUserid((Long)request.getSession().getAttribute("userId"));
}
EntityWrapper<ChatEntity> ew = new EntityWrapper<ChatEntity>();
/**
*
*/
// 处理/list请求
@RequestMapping("/list")
// 方法接收请求参数、Chat实体和HttpServletRequest对象
public R list(@RequestParam Map<String, Object> params, ChatEntity chat,
HttpServletRequest request) {
// 如果当前用户不是管理员
if (!request.getSession().getAttribute("role").toString().equals("管理员")) {
// 设置Chat实体的用户ID为当前用户ID
chat.setUserid((Long) request.getSession().getAttribute("userId"));
}
// 创建MyBatis-Plus的实体包装器
EntityWrapper<ChatEntity> ew = new EntityWrapper<ChatEntity>();
// 调用ChatService的queryPage方法进行分页查询
PageUtils page = chatService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, chat), params), params));
return R.ok().put("data", page);
}
// 返回成功响应,并将分页数据放入响应中
return R.ok().put("data", page);
}
/**
*
*/
// 处理/lists请求
@RequestMapping("/lists")
// 方法接收Chat实体
public R list(ChatEntity chat) {
// 创建MyBatis-Plus的实体包装器
EntityWrapper<ChatEntity> ew = new EntityWrapper<ChatEntity>();
// 设置查询条件将Chat实体的属性作为查询条件
ew.allEq(MPUtil.allEQMapPre(chat, "chat"));
// 调用ChatService的selectListView方法查询列表数据
return R.ok().put("data", chatService.selectListView(ew));
}
/**
*
*/
@RequestMapping("/lists")
public R list( ChatEntity chat){
EntityWrapper<ChatEntity> ew = new EntityWrapper<ChatEntity>();
ew.allEq(MPUtil.allEQMapPre( chat, "chat"));
return R.ok().put("data", chatService.selectListView(ew));
}
/**
*
*/
@RequestMapping("/query")
public R query(ChatEntity chat){
EntityWrapper< ChatEntity> ew = new EntityWrapper< ChatEntity>();
ew.allEq(MPUtil.allEQMapPre( chat, "chat"));
ChatView chatView = chatService.selectView(ew);
*
*/
// 处理/query请求
@RequestMapping("/query")
// 方法接收Chat实体
public R query(ChatEntity chat) {
// 创建MyBatis-Plus的实体包装器
EntityWrapper<ChatEntity> ew = new EntityWrapper<ChatEntity>();
// 设置查询条件将Chat实体的属性作为查询条件
ew.allEq(MPUtil.allEQMapPre(chat, "chat"));
// 调用ChatService的selectView方法查询单个视图数据
ChatView chatView = chatService.selectView(ew);
// 返回成功响应,并将查询结果放入响应中
return R.ok("查询客户服务成功").put("data", chatView);
}
/**
*
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
ChatEntity chat = chatService.selectById(id);
return R.ok().put("data", chat);
}
/**
*
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
ChatEntity chat = chatService.selectById(id);
return R.ok().put("data", chat);
}
/**
*
*/
@RequestMapping("/save")
public R save(@RequestBody ChatEntity chat, HttpServletRequest request){
chat.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(chat);
if(StringUtils.isNotBlank(chat.getAsk())) {
}
/**
*
*/
// 处理/info/{id}请求接收路径变量id
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id) {
// 根据ID查询Chat实体
ChatEntity chat = chatService.selectById(id);
// 返回成功响应,并将查询结果放入响应中
return R.ok().put("data", chat);
}
/**
*
*/
// 处理/detail/{id}请求接收路径变量id
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id) {
// 根据ID查询Chat实体
ChatEntity chat = chatService.selectById(id);
// 返回成功响应,并将查询结果放入响应中
return R.ok().put("data", chat);
}
/**
*
*/
// 处理/save请求接收请求体中的Chat实体和HttpServletRequest对象
@RequestMapping("/save")
public R save(@RequestBody ChatEntity chat, HttpServletRequest request) {
// 生成唯一的ID使用当前时间戳加上随机数
chat.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释掉的验证代码
//ValidatorUtils.validateEntity(chat);
// 如果询问内容不为空
if (StringUtils.isNotBlank(chat.getAsk())) {
// 将该用户的所有聊天记录的isreply字段置为0
chatService.updateForSet("isreply=0", new EntityWrapper<ChatEntity>().eq("userid", request.getSession().getAttribute("userId")));
chat.setUserid((Long)request.getSession().getAttribute("userId"));
chat.setIsreply(1);
}
if(StringUtils.isNotBlank(chat.getReply())) {
chatService.updateForSet("isreply=0", new EntityWrapper<ChatEntity>().eq("userid", chat.getUserid()));
chat.setAdminid((Long)request.getSession().getAttribute("userId"));
}
chatService.insert(chat);
return R.ok();
}
/**
*
*/
@RequestMapping("/add")
public R add(@RequestBody ChatEntity chat, HttpServletRequest request){
chat.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(chat);
chat.setUserid((Long)request.getSession().getAttribute("userId"));
if(StringUtils.isNotBlank(chat.getAsk())) {
// 设置Chat实体的用户ID为当前用户ID
chat.setUserid((Long) request.getSession().getAttribute("userId"));
// 设置isreply字段为1
chat.setIsreply(1);
}
// 如果回复内容不为空
if (StringUtils.isNotBlank(chat.getReply())) {
// 将该用户的所有聊天记录的isreply字段置为0
chatService.updateForSet("isreply=0", new EntityWrapper<ChatEntity>().eq("userid", chat.getUserid()));
// 设置Chat实体的管理员ID为当前用户ID
chat.setAdminid((Long) request.getSession().getAttribute("userId"));
}
// 插入Chat实体到数据库
chatService.insert(chat);
// 返回成功响应
return R.ok();
}
/**
*
*/
// 处理/add请求接收请求体中的Chat实体和HttpServletRequest对象
@RequestMapping("/add")
public R add(@RequestBody ChatEntity chat, HttpServletRequest request) {
// 生成唯一的ID使用当前时间戳加上随机数
chat.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释掉的验证代码
//ValidatorUtils.validateEntity(chat);
// 设置Chat实体的用户ID为当前用户ID
chat.setUserid((Long) request.getSession().getAttribute("userId"));
// 如果询问内容不为空
if (StringUtils.isNotBlank(chat.getAsk())) {
// 将该用户的所有聊天记录的isreply字段置为0
chatService.updateForSet("isreply=0", new EntityWrapper<ChatEntity>().eq("userid", request.getSession().getAttribute("userId")));
chat.setUserid((Long)request.getSession().getAttribute("userId"));
chat.setIsreply(1);
}
if(StringUtils.isNotBlank(chat.getReply())) {
chatService.updateForSet("isreply=0", new EntityWrapper<ChatEntity>().eq("userid", chat.getUserid()));
chat.setAdminid((Long)request.getSession().getAttribute("userId"));
}
chatService.insert(chat);
return R.ok();
}
/**
*
*/
@RequestMapping("/update")
public R update(@RequestBody ChatEntity chat, HttpServletRequest request){
//ValidatorUtils.validateEntity(chat);
chatService.updateById(chat);//全部更新
return R.ok();
}
/**
*
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
chatService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
*
*/
// 设置Chat实体的用户ID为当前用户ID
chat.setUserid((Long) request.getSession().getAttribute("userId"));
// 设置isreply字段为1
chat.setIsreply(1);
}
// 如果回复内容不为空
if (StringUtils.isNotBlank(chat.getReply())) {
// 将该用户的所有聊天记录的isreply字段置为0
chatService.updateForSet("isreply=0", new EntityWrapper<ChatEntity>().eq("userid", chat.getUserid()));
// 设置Chat实体的管理员ID为当前用户ID
chat.setAdminid((Long) request.getSession().getAttribute("userId"));
}
// 插入Chat实体到数据库
chatService.insert(chat);
// 返回成功响应
return R.ok();
}
/**
*
*/
// 处理/update请求接收请求体中的Chat实体和HttpServletRequest对象
@RequestMapping("/update")
public R update(@RequestBody ChatEntity chat, HttpServletRequest request) {
// 注释掉的验证代码
//ValidatorUtils.validateEntity(chat);
// 根据ID更新Chat实体的所有字段
chatService.updateById(chat);
// 返回成功响应
return R.ok();
}
/**
*
*/
// 处理/delete请求接收请求体中的ID数组
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids) {
// 根据ID数组批量删除Chat实体
chatService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*/
// 处理/remind/{columnName}/{type}请求接收路径变量columnName和type以及请求参数map
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 将列名和类型放入请求参数map中
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
// 如果类型为2
if (type.equals("2")) {
// 创建日期格式化对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建Calendar对象
Calendar c = Calendar.getInstance();
// 提醒开始日期
Date remindStartDate = null;
// 提醒结束日期
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
// 如果提醒开始时间不为空
if (map.get("remindstart") != null) {
// 将提醒开始时间转换为整数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
// 设置Calendar的时间为当前时间
c.setTime(new Date());
// 增加指定天数
c.add(Calendar.DAY_OF_MONTH, remindStart);
// 获取提醒开始日期
remindStartDate = c.getTime();
// 将提醒开始日期格式化后放入请求参数map中
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
// 如果提醒结束时间不为空
if (map.get("remindend") != null) {
// 将提醒结束时间转换为整数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置Calendar的时间为当前时间
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
// 增加指定天数
c.add(Calendar.DAY_OF_MONTH, remindEnd);
// 获取提醒结束日期
remindEndDate = c.getTime();
// 将提醒结束日期格式化后放入请求参数map中
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建MyBatis-Plus的包装器
Wrapper<ChatEntity> wrapper = new EntityWrapper<ChatEntity>();
if(map.get("remindstart")!=null) {
// 如果提醒开始时间不为空
if (map.get("remindstart") != null) {
// 设置查询条件,列名大于等于提醒开始时间
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
// 如果提醒结束时间不为空
if (map.get("remindend") != null) {
// 设置查询条件,列名小于等于提醒结束时间
wrapper.le(columnName, map.get("remindend"));
}
// 统计符合条件的记录数
int count = chatService.selectCount(wrapper);
// 返回成功响应,并将统计结果放入响应中
return R.ok().put("count", count);
}
}
}

@ -1,256 +1,405 @@
package com.controller;
// 导入文件操作相关类
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
// 导入日期格式化类
import java.text.SimpleDateFormat;
// 导入动态数组类
import java.util.ArrayList;
// 导入日历类
import java.util.Calendar;
// 导入日期类
import java.util.Date;
// 导入哈希映射类
import java.util.HashMap;
// 导入列表接口
import java.util.List;
// 导入映射接口
import java.util.Map;
// 导入Apache Commons Lang工具类
import org.apache.commons.lang3.StringUtils;
// 导入JSON对象类
import org.json.JSONObject;
// 导入Spring的自动装配注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入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;
// 导入自定义的忽略认证注解
import com.annotation.IgnoreAuth;
// 导入百度人脸识别客户端类
import com.baidu.aip.face.AipFace;
// 导入百度人脸匹配请求类
import com.baidu.aip.face.MatchRequest;
// 导入百度的Base64工具类
import com.baidu.aip.util.Base64Util;
// 导入MyBatis-Plus的实体包装器类
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入MyBatis-Plus的包装器接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入配置实体类
import com.entity.ConfigEntity;
// 导入通用服务类
import com.service.CommonService;
// 导入配置服务类
import com.service.ConfigService;
// 导入自定义的百度工具类
import com.utils.BaiduUtil;
// 导入自定义的文件工具类
import com.utils.FileUtil;
// 导入自定义的响应结果类
import com.utils.R;
/**
*
*/
// 声明为RESTful控制器
@RestController
public class CommonController{
public class CommonController {
// 自动装配通用服务类实例
@Autowired
private CommonService commonService;
// 自动装配配置服务类实例
@Autowired
private ConfigService configService;
// 定义一个未使用的整型变量
private int aaaa;
// 定义百度人脸识别客户端静态变量
private static AipFace client = null;
// 定义百度地图AK静态变量
private static String BAIDU_DITU_AK = null;
/**
*
* @param lng
* @param lat
* @return
*/
@RequestMapping("/location")
public R location(String lng,String lat) {
if(BAIDU_DITU_AK==null) {
public R location(String lng, String lat) {
// 如果百度地图AK为空
if (BAIDU_DITU_AK == null) {
// 从配置表中获取百度地图AK
BAIDU_DITU_AK = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "baidu_ditu_ak")).getValue();
if(BAIDU_DITU_AK==null) {
// 如果获取失败
if (BAIDU_DITU_AK == null) {
// 返回错误信息
return R.error("请在配置管理中正确配置baidu_ditu_ak");
}
}
// 调用百度工具类的方法获取城市信息
Map<String, String> map = BaiduUtil.getCityByLonLat(BAIDU_DITU_AK, lng, lat);
// 返回成功响应并携带城市信息
return R.ok().put("data", map);
}
/**
*
*
* @param face1 1
* @param face2 2
* @return
* @param face1 1
* @param face2 2
* @return
*/
@RequestMapping("/matchFace")
public R matchFace(String face1, String face2) {
if(client==null) {
/*String AppID = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "AppID")).getValue();*/
// 如果百度人脸识别客户端未初始化
if (client == null) {
// 从配置表中获取API Key
String APIKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "APIKey")).getValue();
// 从配置表中获取Secret Key
String SecretKey = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "SecretKey")).getValue();
// 获取百度认证令牌
String token = BaiduUtil.getAuth(APIKey, SecretKey);
if(token==null) {
// 如果获取失败
if (token == null) {
// 返回错误信息
return R.error("请在配置管理中正确配置APIKey和SecretKey");
}
// 初始化百度人脸识别客户端
client = new AipFace(null, APIKey, SecretKey);
// 设置连接超时时间
client.setConnectionTimeoutInMillis(2000);
// 设置套接字超时时间
client.setSocketTimeoutInMillis(60000);
}
// 定义JSON对象用于存储比对结果
JSONObject res = null;
try {
File file1 = new File(ResourceUtils.getFile("classpath:static/upload").getAbsolutePath()+"/"+face1);
File file2 = new File(ResourceUtils.getFile("classpath:static/upload").getAbsolutePath()+"/"+face2);
// 获取人脸1的文件对象
File file1 = new File(ResourceUtils.getFile("classpath:static/upload").getAbsolutePath() + "/" + face1);
// 获取人脸2的文件对象
File file2 = new File(ResourceUtils.getFile("classpath:static/upload").getAbsolutePath() + "/" + face2);
// 将人脸1的文件转换为Base64编码字符串
String img1 = Base64Util.encode(FileUtil.FileToByte(file1));
// 将人脸2的文件转换为Base64编码字符串
String img2 = Base64Util.encode(FileUtil.FileToByte(file2));
// 创建人脸1的匹配请求对象
MatchRequest req1 = new MatchRequest(img1, "BASE64");
// 创建人脸2的匹配请求对象
MatchRequest req2 = new MatchRequest(img2, "BASE64");
// 创建匹配请求列表
ArrayList<MatchRequest> requests = new ArrayList<MatchRequest>();
// 将人脸1的匹配请求添加到列表中
requests.add(req1);
// 将人脸2的匹配请求添加到列表中
requests.add(req2);
// 调用百度人脸识别客户端的匹配方法进行人脸比对
res = client.match(requests);
// 打印比对结果
System.out.println(res.get("result"));
} catch (FileNotFoundException e) {
// 打印文件未找到异常信息
e.printStackTrace();
// 返回文件不存在的错误信息
return R.error("文件不存在");
} catch (IOException e) {
// 打印IO异常信息
e.printStackTrace();
}
}
// 返回成功响应并携带比对结果
return R.ok().put("data", com.alibaba.fastjson.JSONObject.parse(res.get("result").toString()));
}
/**
* tablecolumn()
* @param table
* @param column
* @return
* @param tableName
* @param columnName
* @param level
* @param parent
* @return
*/
@IgnoreAuth
@RequestMapping("/option/{tableName}/{columnName}")
public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,String level,String parent) {
public R getOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, String level, String parent) {
// 创建参数映射
Map<String, Object> params = new HashMap<String, Object>();
// 将表名放入参数映射中
params.put("table", tableName);
// 将列名放入参数映射中
params.put("column", columnName);
if(StringUtils.isNotBlank(level)) {
// 如果层级信息不为空
if (StringUtils.isNotBlank(level)) {
// 将层级信息放入参数映射中
params.put("level", level);
}
if(StringUtils.isNotBlank(parent)) {
// 如果父级信息不为空
if (StringUtils.isNotBlank(parent)) {
// 将父级信息放入参数映射中
params.put("parent", parent);
}
// 调用通用服务类的方法获取列列表
List<String> data = commonService.getOption(params);
// 返回成功响应并携带列列表
return R.ok().put("data", data);
}
/**
* tablecolumn
* @param table
* @param column
* @return
* @param tableName
* @param columnName
* @param columnValue
* @return
*/
@IgnoreAuth
@RequestMapping("/follow/{tableName}/{columnName}")
public R getFollowByOption(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName, @RequestParam String columnValue) {
// 创建参数映射
Map<String, Object> params = new HashMap<String, Object>();
// 将表名放入参数映射中
params.put("table", tableName);
// 将列名放入参数映射中
params.put("column", columnName);
// 将列值放入参数映射中
params.put("columnValue", columnValue);
// 调用通用服务类的方法获取单条记录
Map<String, Object> result = commonService.getFollowByOption(params);
// 返回成功响应并携带单条记录
return R.ok().put("data", result);
}
/**
* tablesfsh
* @param table
* @param map
* @return
* @param tableName
* @param map
* @return
*/
@RequestMapping("/sh/{tableName}")
public R sh(@PathVariable("tableName") String tableName, @RequestBody Map<String, Object> map) {
// 将表名放入映射中
map.put("table", tableName);
// 调用通用服务类的方法修改状态
commonService.sh(map);
// 返回成功响应
return R.ok();
}
/**
*
* @param tableName
* @param columnName
* @param tableName
* @param columnName
* @param type 1: 2:
* @param map
* @return
* @param map
* @return
*/
@IgnoreAuth
@RequestMapping("/remind/{tableName}/{columnName}/{type}")
public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
public R remindCount(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 将表名放入映射中
map.put("table", tableName);
// 将列名放入映射中
map.put("column", columnName);
// 将类型放入映射中
map.put("type", type);
if(type.equals("2")) {
// 如果类型为日期
if (type.equals("2")) {
// 创建日期格式化对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建日历对象
Calendar c = Calendar.getInstance();
// 提醒开始日期
Date remindStartDate = null;
// 提醒结束日期
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
// 如果提醒开始时间不为空
if (map.get("remindstart") != null) {
// 将提醒开始时间转换为整数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
// 设置日历时间为当前时间
c.setTime(new Date());
// 增加指定天数
c.add(Calendar.DAY_OF_MONTH, remindStart);
// 获取提醒开始日期
remindStartDate = c.getTime();
// 将提醒开始日期格式化后放入映射中
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
// 如果提醒结束时间不为空
if (map.get("remindend") != null) {
// 将提醒结束时间转换为整数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置日历时间为当前时间
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
// 增加指定天数
c.add(Calendar.DAY_OF_MONTH, remindEnd);
// 获取提醒结束日期
remindEndDate = c.getTime();
// 将提醒结束日期格式化后放入映射中
map.put("remindend", sdf.format(remindEndDate));
}
}
// 调用通用服务类的方法统计提醒记录数
int count = commonService.remindCount(map);
// 返回成功响应并携带提醒记录数
return R.ok().put("count", count);
}
/**
*
* @param tableName
* @param columnName
* @return
*/
@IgnoreAuth
@RequestMapping("/cal/{tableName}/{columnName}")
public R cal(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
// 创建参数映射
Map<String, Object> params = new HashMap<String, Object>();
// 将表名放入参数映射中
params.put("table", tableName);
// 将列名放入参数映射中
params.put("column", columnName);
// 调用通用服务类的方法进行单列求和
Map<String, Object> result = commonService.selectCal(params);
// 返回成功响应并携带求和结果
return R.ok().put("data", result);
}
/**
*
* @param tableName
* @param columnName
* @return
*/
@IgnoreAuth
@RequestMapping("/group/{tableName}/{columnName}")
public R group(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) {
// 创建参数映射
Map<String, Object> params = new HashMap<String, Object>();
// 将表名放入参数映射中
params.put("table", tableName);
// 将列名放入参数映射中
params.put("column", columnName);
// 调用通用服务类的方法进行分组统计
List<Map<String, Object>> result = commonService.selectGroup(params);
// 创建日期格式化对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
for(Map<String, Object> m : result) {
for(String k : m.keySet()) {
if(m.get(k) instanceof Date) {
m.put(k, sdf.format((Date)m.get(k)));
// 遍历统计结果
for (Map<String, Object> m : result) {
// 遍历结果中的键
for (String k : m.keySet()) {
// 如果值为日期类型
if (m.get(k) instanceof Date) {
// 将日期格式化后重新放入结果中
m.put(k, sdf.format((Date) m.get(k)));
}
}
}
// 返回成功响应并携带分组统计结果
return R.ok().put("data", result);
}
/**
*
* @param tableName
* @param yColumnName y
* @param xColumnName x
* @return
*/
@IgnoreAuth
@RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}")
public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName) {
// 创建参数映射
Map<String, Object> params = new HashMap<String, Object>();
// 将表名放入参数映射中
params.put("table", tableName);
// 将x列名放入参数映射中
params.put("xColumn", xColumnName);
// 将y列名放入参数映射中
params.put("yColumn", yColumnName);
// 调用通用服务类的方法进行按值统计
List<Map<String, Object>> result = commonService.selectValue(params);
// 创建日期格式化对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
for(Map<String, Object> m : result) {
for(String k : m.keySet()) {
if(m.get(k) instanceof Date) {
m.put(k, sdf.format((Date)m.get(k)));
// 遍历统计结果
for (Map<String, Object> m : result) {
// 遍历结果中的键
for (String k : m.keySet()) {
// 如果值为日期类型
if (m.get(k) instanceof Date) {
// 将日期格式化后重新放入结果中
m.put(k, sdf.format((Date) m.get(k)));
}
}
}
// 返回成功响应并携带按值统计结果
return R.ok().put("data", result);
}
}
}

@ -1,111 +1,156 @@
// 声明该类所在的包
package com.controller;
// 导入Arrays类用于操作数组这里主要用于处理批量删除时的ID数组
import java.util.Arrays;
// 导入Map接口用于存储键值对通常用于接收请求参数
import java.util.Map;
// 导入Spring框架的自动装配注解用于将ConfigService注入到当前类中
import org.springframework.beans.factory.annotation.Autowired;
// 导入Spring框架的路径变量注解用于从URL路径中获取参数
import org.springframework.web.bind.annotation.PathVariable;
// 导入Spring框架的Post请求映射注解用于处理HTTP POST请求
import org.springframework.web.bind.annotation.PostMapping;
// 导入Spring框架的请求体注解用于将请求体中的数据绑定到方法参数上
import org.springframework.web.bind.annotation.RequestBody;
// 导入Spring框架的请求映射注解用于将HTTP请求映射到处理方法上
import org.springframework.web.bind.annotation.RequestMapping;
// 导入Spring框架的请求参数注解用于从请求中获取参数
import org.springframework.web.bind.annotation.RequestParam;
// 导入Spring框架的REST控制器注解表明该类是一个RESTful风格的控制器
import org.springframework.web.bind.annotation.RestController;
// 导入自定义的忽略认证注解,用于标记某些接口不需要进行认证
import com.annotation.IgnoreAuth;
// 导入MyBatis-Plus的实体包装器类用于构建查询条件
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入配置实体类,用于表示配置信息
import com.entity.ConfigEntity;
// 导入配置服务类,用于处理配置信息的业务逻辑
import com.service.ConfigService;
// 导入自定义的分页工具类,用于处理分页查询结果
import com.utils.PageUtils;
// 导入自定义的响应结果类,用于封装接口的返回数据
import com.utils.R;
// 导入自定义的验证工具类,用于验证实体对象的合法性
import com.utils.ValidatorUtils;
/**
*
*/
// 定义该控制器处理的请求路径前缀为"config"
@RequestMapping("config")
// 声明该类为RESTful控制器
@RestController
public class ConfigController{
@Autowired
private ConfigService configService;
public class ConfigController {
// 使用自动装配将ConfigService实例注入到当前类中
@Autowired
private ConfigService configService;
/**
/**
*
*
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ConfigEntity config){
public R page(@RequestParam Map<String, Object> params, ConfigEntity config) {
// 创建一个EntityWrapper对象用于构建查询条件
EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>();
PageUtils page = configService.queryPage(params);
// 调用ConfigService的queryPage方法进行分页查询
PageUtils page = configService.queryPage(params);
// 返回成功响应,并将分页查询结果放入响应数据中
return R.ok().put("data", page);
}
/**
/**
*
*
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ConfigEntity config){
public R list(@RequestParam Map<String, Object> params, ConfigEntity config) {
// 创建一个EntityWrapper对象用于构建查询条件
EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>();
PageUtils page = configService.queryPage(params);
// 调用ConfigService的queryPage方法进行分页查询
PageUtils page = configService.queryPage(params);
// 返回成功响应,并将分页查询结果放入响应数据中
return R.ok().put("data", page);
}
/**
*
* ID
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") String id){
public R info(@PathVariable("id") String id) {
// 调用ConfigService的selectById方法根据ID查询配置信息
ConfigEntity config = configService.selectById(id);
// 返回成功响应,并将查询到的配置信息放入响应数据中
return R.ok().put("data", config);
}
/**
*
* ID
*/
@IgnoreAuth
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") String id){
public R detail(@PathVariable("id") String id) {
// 调用ConfigService的selectById方法根据ID查询配置信息
ConfigEntity config = configService.selectById(id);
// 返回成功响应,并将查询到的配置信息放入响应数据中
return R.ok().put("data", config);
}
/**
* name
*
*/
@RequestMapping("/info")
public R infoByName(@RequestParam String name){
public R infoByName(@RequestParam String name) {
// 调用ConfigService的selectOne方法根据名称查询配置信息这里写死了查询"faceFile"
ConfigEntity config = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
// 返回成功响应,并将查询到的配置信息放入响应数据中
return R.ok().put("data", config);
}
/**
*
* 使HTTP POST
*/
@PostMapping("/save")
public R save(@RequestBody ConfigEntity config){
public R save(@RequestBody ConfigEntity config) {
// 注释掉的代码,原本用于验证实体对象的合法性
// ValidatorUtils.validateEntity(config);
configService.insert(config);
// 调用ConfigService的insert方法将配置信息插入到数据库中
configService.insert(config);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/update")
public R update(@RequestBody ConfigEntity config){
public R update(@RequestBody ConfigEntity config) {
// 注释掉的代码,原本用于验证实体对象的合法性
// ValidatorUtils.validateEntity(config);
configService.updateById(config);//全部更新
// 调用ConfigService的updateById方法根据ID更新配置信息的所有字段
configService.updateById(config);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
configService.deleteBatchIds(Arrays.asList(ids));
public R delete(@RequestBody Long[] ids) {
// 调用ConfigService的deleteBatchIds方法根据ID数组批量删除配置信息
configService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
}
}

@ -1,207 +1,297 @@
// 声明该类所在的包
package com.controller;
// 导入用于格式化日期的类,可将日期对象按照指定格式转换为字符串
import java.text.SimpleDateFormat;
// 导入动态数组类,可动态调整大小,用于存储多个元素
import java.util.ArrayList;
// 导入用于操作数组的工具类,提供了如排序、查找等操作数组的方法
import java.util.Arrays;
// 导入日历类,用于处理日期和时间,可进行日期的计算和转换
import java.util.Calendar;
// 导入映射接口,用于存储键值对,方便通过键快速查找对应的值
import java.util.Map;
// 导入哈希映射类是Map接口的一个实现类使用哈希表存储键值对
import java.util.HashMap;
// 导入迭代器接口,用于遍历集合中的元素
import java.util.Iterator;
// 导入日期类,用于表示特定的瞬间
import java.util.Date;
// 导入列表接口,是有序集合,可存储重复元素
import java.util.List;
// 导入用于处理HTTP请求的类可获取请求的各种信息如参数、头信息等
import javax.servlet.http.HttpServletRequest;
// 导入自定义的验证工具类,可用于验证实体对象的属性是否符合要求
import com.utils.ValidatorUtils;
// 导入Apache Commons Lang库中的字符串工具类提供了丰富的字符串处理方法
import org.apache.commons.lang3.StringUtils;
// 导入Spring框架的自动装配注解用于将依赖的对象自动注入到当前类中
import org.springframework.beans.factory.annotation.Autowired;
// 导入Spring框架的日期格式化注解可将请求参数中的日期字符串按照指定格式转换为日期对象
import org.springframework.format.annotation.DateTimeFormat;
// 导入Spring框架的路径变量注解用于从URL路径中提取参数
import org.springframework.web.bind.annotation.PathVariable;
// 导入Spring框架的请求体注解用于将请求体中的数据绑定到方法参数上
import org.springframework.web.bind.annotation.RequestBody;
// 导入Spring框架的请求映射注解用于将HTTP请求映射到对应的处理方法上
import org.springframework.web.bind.annotation.RequestMapping;
// 导入Spring框架的请求参数注解用于从请求中获取参数
import org.springframework.web.bind.annotation.RequestParam;
// 导入Spring框架的REST控制器注解表明该类是一个RESTful风格的控制器
import org.springframework.web.bind.annotation.RestController;
// 导入MyBatis-Plus的实体包装器类用于构建查询条件
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入MyBatis-Plus的包装器接口是EntityWrapper的父接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解,用于标记某些接口不需要进行认证
import com.annotation.IgnoreAuth;
// 导入课程信息评论实体类,用于表示课程信息评论的数据结构
import com.entity.DiscusskechengxinxiEntity;
// 导入课程信息评论视图类,可能用于展示课程信息评论的特定视图
import com.entity.view.DiscusskechengxinxiView;
// 导入课程信息评论服务类,用于处理课程信息评论的业务逻辑
import com.service.DiscusskechengxinxiService;
// 导入令牌服务类,可能用于处理用户认证和授权相关的令牌
import com.service.TokenService;
// 导入自定义的分页工具类,用于处理分页查询的结果
import com.utils.PageUtils;
// 导入自定义的响应结果类,用于封装接口的返回数据,统一返回格式
import com.utils.R;
// 导入自定义的MD5工具类用于进行MD5加密操作
import com.utils.MD5Util;
// 导入自定义的MyBatis-Plus工具类提供了一些方便使用MyBatis-Plus的方法
import com.utils.MPUtil;
// 导入自定义的通用工具类,包含一些通用的工具方法
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:15
*/
// 声明该类为RESTful风格的控制器
@RestController
// 定义该控制器处理的请求路径前缀
@RequestMapping("/discusskechengxinxi")
public class DiscusskechengxinxiController {
// 使用自动装配将DiscusskechengxinxiService注入到当前类中
@Autowired
private DiscusskechengxinxiService discusskechengxinxiService;
/**
*
*
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,DiscusskechengxinxiEntity discusskechengxinxi,
HttpServletRequest request){
public R page(@RequestParam Map<String, Object> params, DiscusskechengxinxiEntity discusskechengxinxi,
HttpServletRequest request) {
// 创建一个EntityWrapper对象用于构建查询条件
EntityWrapper<DiscusskechengxinxiEntity> ew = new EntityWrapper<DiscusskechengxinxiEntity>();
PageUtils page = discusskechengxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, discusskechengxinxi), params), params));
// 调用DiscusskechengxinxiService的queryPage方法进行分页查询
PageUtils page = discusskechengxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, discusskechengxinxi), params), params));
// 返回成功响应,并将分页查询结果放入响应数据中
return R.ok().put("data", page);
}
/**
*
*
*/
@IgnoreAuth
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,DiscusskechengxinxiEntity discusskechengxinxi,
HttpServletRequest request){
public R list(@RequestParam Map<String, Object> params, DiscusskechengxinxiEntity discusskechengxinxi,
HttpServletRequest request) {
// 创建一个EntityWrapper对象用于构建查询条件
EntityWrapper<DiscusskechengxinxiEntity> ew = new EntityWrapper<DiscusskechengxinxiEntity>();
PageUtils page = discusskechengxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, discusskechengxinxi), params), params));
// 调用DiscusskechengxinxiService的queryPage方法进行分页查询
PageUtils page = discusskechengxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, discusskechengxinxi), params), params));
// 返回成功响应,并将分页查询结果放入响应数据中
return R.ok().put("data", page);
}
/**
/**
*
*
*/
@RequestMapping("/lists")
public R list( DiscusskechengxinxiEntity discusskechengxinxi){
EntityWrapper<DiscusskechengxinxiEntity> ew = new EntityWrapper<DiscusskechengxinxiEntity>();
ew.allEq(MPUtil.allEQMapPre( discusskechengxinxi, "discusskechengxinxi"));
public R list(DiscusskechengxinxiEntity discusskechengxinxi) {
// 创建一个EntityWrapper对象用于构建查询条件
EntityWrapper<DiscusskechengxinxiEntity> ew = new EntityWrapper<DiscusskechengxinxiEntity>();
// 设置查询条件,将实体对象的属性作为查询条件
ew.allEq(MPUtil.allEQMapPre(discusskechengxinxi, "discusskechengxinxi"));
// 调用DiscusskechengxinxiService的selectListView方法查询列表数据
return R.ok().put("data", discusskechengxinxiService.selectListView(ew));
}
/**
/**
*
*
*/
@RequestMapping("/query")
public R query(DiscusskechengxinxiEntity discusskechengxinxi){
EntityWrapper< DiscusskechengxinxiEntity> ew = new EntityWrapper< DiscusskechengxinxiEntity>();
ew.allEq(MPUtil.allEQMapPre( discusskechengxinxi, "discusskechengxinxi"));
DiscusskechengxinxiView discusskechengxinxiView = discusskechengxinxiService.selectView(ew);
return R.ok("查询课程信息评论表成功").put("data", discusskechengxinxiView);
public R query(DiscusskechengxinxiEntity discusskechengxinxi) {
// 创建一个EntityWrapper对象用于构建查询条件
EntityWrapper<DiscusskechengxinxiEntity> ew = new EntityWrapper<DiscusskechengxinxiEntity>();
// 设置查询条件,将实体对象的属性作为查询条件
ew.allEq(MPUtil.allEQMapPre(discusskechengxinxi, "discusskechengxinxi"));
// 调用DiscusskechengxinxiService的selectView方法查询单个视图数据
DiscusskechengxinxiView discusskechengxinxiView = discusskechengxinxiService.selectView(ew);
// 返回成功响应,并将查询结果放入响应数据中
return R.ok("查询课程信息评论表成功").put("data", discusskechengxinxiView);
}
/**
*
* ID
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
public R info(@PathVariable("id") Long id) {
// 调用DiscusskechengxinxiService的selectById方法根据ID查询课程信息评论
DiscusskechengxinxiEntity discusskechengxinxi = discusskechengxinxiService.selectById(id);
// 返回成功响应,并将查询结果放入响应数据中
return R.ok().put("data", discusskechengxinxi);
}
/**
*
* ID
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
public R detail(@PathVariable("id") Long id) {
// 调用DiscusskechengxinxiService的selectById方法根据ID查询课程信息评论
DiscusskechengxinxiEntity discusskechengxinxi = discusskechengxinxiService.selectById(id);
// 返回成功响应,并将查询结果放入响应数据中
return R.ok().put("data", discusskechengxinxi);
}
/**
*
*
*/
@RequestMapping("/save")
public R save(@RequestBody DiscusskechengxinxiEntity discusskechengxinxi, HttpServletRequest request){
discusskechengxinxi.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(discusskechengxinxi);
public R save(@RequestBody DiscusskechengxinxiEntity discusskechengxinxi, HttpServletRequest request) {
// 为课程信息评论生成一个唯一的ID使用当前时间戳加上一个随机数
discusskechengxinxi.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释掉的代码,原本用于验证实体对象的合法性
//ValidatorUtils.validateEntity(discusskechengxinxi);
// 调用DiscusskechengxinxiService的insert方法将课程信息评论插入到数据库中
discusskechengxinxiService.insert(discusskechengxinxi);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/add")
public R add(@RequestBody DiscusskechengxinxiEntity discusskechengxinxi, HttpServletRequest request){
discusskechengxinxi.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(discusskechengxinxi);
public R add(@RequestBody DiscusskechengxinxiEntity discusskechengxinxi, HttpServletRequest request) {
// 为课程信息评论生成一个唯一的ID使用当前时间戳加上一个随机数
discusskechengxinxi.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释掉的代码,原本用于验证实体对象的合法性
//ValidatorUtils.validateEntity(discusskechengxinxi);
// 调用DiscusskechengxinxiService的insert方法将课程信息评论插入到数据库中
discusskechengxinxiService.insert(discusskechengxinxi);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/update")
public R update(@RequestBody DiscusskechengxinxiEntity discusskechengxinxi, HttpServletRequest request){
public R update(@RequestBody DiscusskechengxinxiEntity discusskechengxinxi, HttpServletRequest request) {
// 注释掉的代码,原本用于验证实体对象的合法性
//ValidatorUtils.validateEntity(discusskechengxinxi);
discusskechengxinxiService.updateById(discusskechengxinxi);//全部更新
// 调用DiscusskechengxinxiService的updateById方法根据ID更新课程信息评论的所有字段
discusskechengxinxiService.updateById(discusskechengxinxi);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
public R delete(@RequestBody Long[] ids) {
// 调用DiscusskechengxinxiService的deleteBatchIds方法根据ID数组批量删除课程信息评论
discusskechengxinxiService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<DiscusskechengxinxiEntity> wrapper = new EntityWrapper<DiscusskechengxinxiEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = discusskechengxinxiService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 将列名和类型放入请求参数映射中
map.put("column", columnName);
map.put("type", type);
// 如果类型为2表示日期类型的提醒
if (type.equals("2")) {
// 创建一个日期格式化对象,用于将日期对象格式化为指定格式的字符串
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建一个日历对象,用于进行日期的计算和操作
Calendar c = Calendar.getInstance();
// 提醒开始日期
Date remindStartDate = null;
// 提醒结束日期
Date remindEndDate = null;
// 如果请求参数中包含提醒开始时间
if (map.get("remindstart") != null) {
// 将提醒开始时间转换为整数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
// 设置日历对象的时间为当前时间
c.setTime(new Date());
// 在当前时间基础上增加指定的天数
c.add(Calendar.DAY_OF_MONTH, remindStart);
// 获取增加天数后的日期
remindStartDate = c.getTime();
// 将提醒开始日期格式化为字符串并放入请求参数映射中
map.put("remindstart", sdf.format(remindStartDate));
}
// 如果请求参数中包含提醒结束时间
if (map.get("remindend") != null) {
// 将提醒结束时间转换为整数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置日历对象的时间为当前时间
c.setTime(new Date());
// 在当前时间基础上增加指定的天数
c.add(Calendar.DAY_OF_MONTH, remindEnd);
// 获取增加天数后的日期
remindEndDate = c.getTime();
// 将提醒结束日期格式化为字符串并放入请求参数映射中
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建一个EntityWrapper对象用于构建查询条件
Wrapper<DiscusskechengxinxiEntity> wrapper = new EntityWrapper<DiscusskechengxinxiEntity>();
// 如果请求参数中包含提醒开始时间
if (map.get("remindstart") != null) {
// 设置查询条件,列名大于等于提醒开始时间
wrapper.ge(columnName, map.get("remindstart"));
}
// 如果请求参数中包含提醒结束时间
if (map.get("remindend") != null) {
// 设置查询条件,列名小于等于提醒结束时间
wrapper.le(columnName, map.get("remindend"));
}
// 调用DiscusskechengxinxiService的selectCount方法统计符合条件的记录数量
int count = discusskechengxinxiService.selectCount(wrapper);
// 返回成功响应,并将统计结果放入响应数据中
return R.ok().put("count", count);
}
}

@ -1,206 +1,295 @@
// 声明该类所在的包
package com.controller;
// 导入用于格式化日期的类,可将日期对象按指定格式转换为字符串
import java.text.SimpleDateFormat;
// 导入动态数组类,可动态调整大小来存储多个元素
import java.util.ArrayList;
// 导入用于操作数组的工具类,提供排序、查找等数组操作方法
import java.util.Arrays;
// 导入日历类,用于处理日期和时间,可进行日期计算和转换
import java.util.Calendar;
// 导入映射接口,用于存储键值对,方便通过键快速查找对应值
import java.util.Map;
// 导入哈希映射类是Map接口的实现类使用哈希表存储键值对
import java.util.HashMap;
// 导入迭代器接口,用于遍历集合中的元素
import java.util.Iterator;
// 导入日期类,用于表示特定的瞬间
import java.util.Date;
// 导入列表接口,是有序集合,可存储重复元素
import java.util.List;
// 导入用于处理HTTP请求的类可获取请求的参数、头信息等
import javax.servlet.http.HttpServletRequest;
// 导入自定义的验证工具类,用于验证实体对象属性是否符合要求
import com.utils.ValidatorUtils;
// 导入Apache Commons Lang库中的字符串工具类提供丰富的字符串处理方法
import org.apache.commons.lang3.StringUtils;
// 导入Spring框架的自动装配注解用于将依赖对象自动注入当前类
import org.springframework.beans.factory.annotation.Autowired;
// 导入Spring框架的日期格式化注解可将请求参数中的日期字符串按指定格式转换为日期对象
import org.springframework.format.annotation.DateTimeFormat;
// 导入Spring框架的路径变量注解用于从URL路径中提取参数
import org.springframework.web.bind.annotation.PathVariable;
// 导入Spring框架的请求体注解用于将请求体中的数据绑定到方法参数上
import org.springframework.web.bind.annotation.RequestBody;
// 导入Spring框架的请求映射注解用于将HTTP请求映射到对应的处理方法
import org.springframework.web.bind.annotation.RequestMapping;
// 导入Spring框架的请求参数注解用于从请求中获取参数
import org.springframework.web.bind.annotation.RequestParam;
// 导入Spring框架的REST控制器注解表明该类是RESTful风格的控制器
import org.springframework.web.bind.annotation.RestController;
// 导入MyBatis-Plus的实体包装器类用于构建查询条件
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入MyBatis-Plus的包装器接口是EntityWrapper的父接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解,用于标记某些接口不需要认证
import com.annotation.IgnoreAuth;
// 导入试卷实体类,用于表示试卷的数据结构
import com.entity.ExampaperEntity;
// 导入试卷视图类,可能用于展示试卷的特定视图
import com.entity.view.ExampaperView;
// 导入试卷服务类,用于处理试卷的业务逻辑
import com.service.ExampaperService;
// 导入令牌服务类,可能用于处理用户认证和授权相关的令牌
import com.service.TokenService;
// 导入自定义的分页工具类,用于处理分页查询结果
import com.utils.PageUtils;
// 导入自定义的响应结果类,用于封装接口的返回数据,统一返回格式
import com.utils.R;
// 导入自定义的MD5工具类用于进行MD5加密操作
import com.utils.MD5Util;
// 导入自定义的MyBatis-Plus工具类提供方便使用MyBatis-Plus的方法
import com.utils.MPUtil;
// 导入自定义的通用工具类,包含一些通用的工具方法
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:15
*/
// 声明该类为RESTful风格的控制器
@RestController
// 定义该控制器处理的请求路径前缀
@RequestMapping("/exampaper")
public class ExampaperController {
// 使用自动装配将ExampaperService注入到当前类中
@Autowired
private ExampaperService exampaperService;
/**
*
*
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ExampaperEntity exampaper,
HttpServletRequest request){
public R page(@RequestParam Map<String, Object> params, ExampaperEntity exampaper,
HttpServletRequest request) {
// 创建一个EntityWrapper对象用于构建查询条件
EntityWrapper<ExampaperEntity> ew = new EntityWrapper<ExampaperEntity>();
PageUtils page = exampaperService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, exampaper), params), params));
// 调用ExampaperService的queryPage方法进行分页查询同时对查询条件进行排序、范围和模糊查询等处理
PageUtils page = exampaperService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, exampaper), params), params));
// 返回成功响应,并将分页查询结果放入响应数据中
return R.ok().put("data", page);
}
/**
*
*
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ExampaperEntity exampaper,
HttpServletRequest request){
public R list(@RequestParam Map<String, Object> params, ExampaperEntity exampaper,
HttpServletRequest request) {
// 创建一个EntityWrapper对象用于构建查询条件
EntityWrapper<ExampaperEntity> ew = new EntityWrapper<ExampaperEntity>();
PageUtils page = exampaperService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, exampaper), params), params));
// 调用ExampaperService的queryPage方法进行分页查询同时对查询条件进行排序、范围和模糊查询等处理
PageUtils page = exampaperService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, exampaper), params), params));
// 返回成功响应,并将分页查询结果放入响应数据中
return R.ok().put("data", page);
}
/**
/**
*
*
*/
@RequestMapping("/lists")
public R list( ExampaperEntity exampaper){
EntityWrapper<ExampaperEntity> ew = new EntityWrapper<ExampaperEntity>();
ew.allEq(MPUtil.allEQMapPre( exampaper, "exampaper"));
public R list(ExampaperEntity exampaper) {
// 创建一个EntityWrapper对象用于构建查询条件
EntityWrapper<ExampaperEntity> ew = new EntityWrapper<ExampaperEntity>();
// 设置查询条件,将实体对象的属性作为查询条件
ew.allEq(MPUtil.allEQMapPre(exampaper, "exampaper"));
// 调用ExampaperService的selectListView方法查询列表数据
return R.ok().put("data", exampaperService.selectListView(ew));
}
/**
/**
*
*
*/
@RequestMapping("/query")
public R query(ExampaperEntity exampaper){
EntityWrapper< ExampaperEntity> ew = new EntityWrapper< ExampaperEntity>();
ew.allEq(MPUtil.allEQMapPre( exampaper, "exampaper"));
ExampaperView exampaperView = exampaperService.selectView(ew);
return R.ok("查询试卷表成功").put("data", exampaperView);
public R query(ExampaperEntity exampaper) {
// 创建一个EntityWrapper对象用于构建查询条件
EntityWrapper<ExampaperEntity> ew = new EntityWrapper<ExampaperEntity>();
// 设置查询条件,将实体对象的属性作为查询条件
ew.allEq(MPUtil.allEQMapPre(exampaper, "exampaper"));
// 调用ExampaperService的selectView方法查询单个视图数据
ExampaperView exampaperView = exampaperService.selectView(ew);
// 返回成功响应,并将查询结果放入响应数据中
return R.ok("查询试卷表成功").put("data", exampaperView);
}
/**
*
* ID
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
public R info(@PathVariable("id") Long id) {
// 调用ExampaperService的selectById方法根据ID查询试卷信息
ExampaperEntity exampaper = exampaperService.selectById(id);
// 返回成功响应,并将查询结果放入响应数据中
return R.ok().put("data", exampaper);
}
/**
*
* ID
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
public R detail(@PathVariable("id") Long id) {
// 调用ExampaperService的selectById方法根据ID查询试卷信息
ExampaperEntity exampaper = exampaperService.selectById(id);
// 返回成功响应,并将查询结果放入响应数据中
return R.ok().put("data", exampaper);
}
/**
*
*
*/
@RequestMapping("/save")
public R save(@RequestBody ExampaperEntity exampaper, HttpServletRequest request){
exampaper.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(exampaper);
public R save(@RequestBody ExampaperEntity exampaper, HttpServletRequest request) {
// 为试卷生成一个唯一的ID使用当前时间戳加上一个随机数
exampaper.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释掉的代码,原本用于验证实体对象的合法性
//ValidatorUtils.validateEntity(exampaper);
// 调用ExampaperService的insert方法将试卷信息插入到数据库中
exampaperService.insert(exampaper);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/add")
public R add(@RequestBody ExampaperEntity exampaper, HttpServletRequest request){
exampaper.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(exampaper);
public R add(@RequestBody ExampaperEntity exampaper, HttpServletRequest request) {
// 为试卷生成一个唯一的ID使用当前时间戳加上一个随机数
exampaper.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释掉的代码,原本用于验证实体对象的合法性
//ValidatorUtils.validateEntity(exampaper);
// 调用ExampaperService的insert方法将试卷信息插入到数据库中
exampaperService.insert(exampaper);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/update")
public R update(@RequestBody ExampaperEntity exampaper, HttpServletRequest request){
public R update(@RequestBody ExampaperEntity exampaper, HttpServletRequest request) {
// 注释掉的代码,原本用于验证实体对象的合法性
//ValidatorUtils.validateEntity(exampaper);
exampaperService.updateById(exampaper);//全部更新
// 调用ExampaperService的updateById方法根据ID更新试卷信息的所有字段
exampaperService.updateById(exampaper);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
public R delete(@RequestBody Long[] ids) {
// 调用ExampaperService的deleteBatchIds方法根据ID数组批量删除试卷信息
exampaperService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<ExampaperEntity> wrapper = new EntityWrapper<ExampaperEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = exampaperService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 将列名和类型放入请求参数映射中
map.put("column", columnName);
map.put("type", type);
// 如果类型为2表示日期类型的提醒
if (type.equals("2")) {
// 创建一个日期格式化对象,用于将日期对象格式化为指定格式的字符串
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建一个日历对象,用于进行日期的计算和操作
Calendar c = Calendar.getInstance();
// 提醒开始日期
Date remindStartDate = null;
// 提醒结束日期
Date remindEndDate = null;
// 如果请求参数中包含提醒开始时间
if (map.get("remindstart") != null) {
// 将提醒开始时间转换为整数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
// 设置日历对象的时间为当前时间
c.setTime(new Date());
// 在当前时间基础上增加指定的天数
c.add(Calendar.DAY_OF_MONTH, remindStart);
// 获取增加天数后的日期
remindStartDate = c.getTime();
// 将提醒开始日期格式化为字符串并放入请求参数映射中
map.put("remindstart", sdf.format(remindStartDate));
}
// 如果请求参数中包含提醒结束时间
if (map.get("remindend") != null) {
// 将提醒结束时间转换为整数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置日历对象的时间为当前时间
c.setTime(new Date());
// 在当前时间基础上增加指定的天数
c.add(Calendar.DAY_OF_MONTH, remindEnd);
// 获取增加天数后的日期
remindEndDate = c.getTime();
// 将提醒结束日期格式化为字符串并放入请求参数映射中
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建一个EntityWrapper对象用于构建查询条件
Wrapper<ExampaperEntity> wrapper = new EntityWrapper<ExampaperEntity>();
// 如果请求参数中包含提醒开始时间
if (map.get("remindstart") != null) {
// 设置查询条件,列名大于等于提醒开始时间
wrapper.ge(columnName, map.get("remindstart"));
}
// 如果请求参数中包含提醒结束时间
if (map.get("remindend") != null) {
// 设置查询条件,列名小于等于提醒结束时间
wrapper.le(columnName, map.get("remindend"));
}
// 调用ExampaperService的selectCount方法统计符合条件的记录数量
int count = exampaperService.selectCount(wrapper);
// 返回成功响应,并将统计结果放入响应数据中
return R.ok().put("count", count);
}
}

@ -1,206 +1,315 @@
package com.controller;
// 导入用于格式化日期的类
import java.text.SimpleDateFormat;
// 导入用于创建和操作动态数组的类
import java.util.ArrayList;
// 导入用于操作数组的工具类
import java.util.Arrays;
// 导入用于处理日期和时间的类
import java.util.Calendar;
// 导入用于表示键值对映射的接口
import java.util.Map;
// 导入用于实现 Map 接口的类
import java.util.HashMap;
// 导入用于遍历集合的迭代器接口
import java.util.Iterator;
// 导入用于表示日期的类
import java.util.Date;
// 导入用于表示列表的接口
import java.util.List;
// 导入用于处理 HTTP 请求的类
import javax.servlet.http.HttpServletRequest;
// 导入自定义的验证工具类
import com.utils.ValidatorUtils;
// 导入 Apache Commons Lang 库中的字符串处理工具类
import org.apache.commons.lang3.StringUtils;
// 导入 Spring 框架中的自动注入注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入 Spring 框架中用于日期格式化的注解
import org.springframework.format.annotation.DateTimeFormat;
// 导入 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 框架中用于将类标记为 RESTful 控制器的注解
import org.springframework.web.bind.annotation.RestController;
// 导入 MyBatis-Plus 框架中用于构建查询条件的实体包装器类
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入 MyBatis-Plus 框架中用于构建查询条件的包装器接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解
import com.annotation.IgnoreAuth;
// 导入试题实体类
import com.entity.ExamquestionEntity;
// 导入试题视图类
import com.entity.view.ExamquestionView;
// 导入试题服务类
import com.service.ExamquestionService;
// 导入令牌服务类
import com.service.TokenService;
// 导入自定义的分页工具类
import com.utils.PageUtils;
// 导入自定义的返回结果工具类
import com.utils.R;
// 导入自定义的 MD5 加密工具类
import com.utils.MD5Util;
// 导入自定义的 MyBatis-Plus 工具类
import com.utils.MPUtil;
// 导入自定义的通用工具类
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:15
*/
// 将该类标记为 RESTful 控制器,用于处理 HTTP 请求
@RestController
// 定义该控制器处理的请求路径前缀
@RequestMapping("/examquestion")
public class ExamquestionController {
// 自动注入试题服务类的实例
@Autowired
private ExamquestionService examquestionService;
/**
*
*/
// 处理 /examquestion/page 路径的请求
@RequestMapping("/page")
// 该方法用于获取试题的分页列表
public R page(@RequestParam Map<String, Object> params,ExamquestionEntity examquestion,
HttpServletRequest request){
HttpServletRequest request){
// 创建一个用于构建查询条件的实体包装器
EntityWrapper<ExamquestionEntity> ew = new EntityWrapper<ExamquestionEntity>();
PageUtils page = examquestionService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, examquestion), params), params));
// 调用试题服务类的 queryPage 方法进行分页查询
PageUtils page = examquestionService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, examquestion), params), params));
return R.ok().put("data", page);
// 返回成功响应,并将分页数据放入响应结果中
return R.ok().put("data", page);//测试
}
/**
*
*/
// 处理 /examquestion/list 路径的请求
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ExamquestionEntity examquestion,
HttpServletRequest request){
// 该方法用于获取试题的分页列表(前端使用)
public R list(@RequestParam Map<String, Object> params,ExamquestionEntity examquestion,
HttpServletRequest request){
// 创建一个用于构建查询条件的实体包装器
EntityWrapper<ExamquestionEntity> ew = new EntityWrapper<ExamquestionEntity>();
PageUtils page = examquestionService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, examquestion), params), params));
// 调用试题服务类的 queryPage 方法进行分页查询
PageUtils page = examquestionService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, examquestion), params), params));
// 返回成功响应,并将分页数据放入响应结果中
return R.ok().put("data", page);
}
/**
/**
*
*/
// 处理 /examquestion/lists 路径的请求
@RequestMapping("/lists")
// 该方法用于获取试题列表
public R list( ExamquestionEntity examquestion){
EntityWrapper<ExamquestionEntity> ew = new EntityWrapper<ExamquestionEntity>();
ew.allEq(MPUtil.allEQMapPre( examquestion, "examquestion"));
// 创建一个用于构建查询条件的实体包装器
EntityWrapper<ExamquestionEntity> ew = new EntityWrapper<ExamquestionEntity>();
// 设置查询条件为所有字段相等
ew.allEq(MPUtil.allEQMapPre( examquestion, "examquestion"));
// 返回成功响应,并将查询到的试题列表放入响应结果中
return R.ok().put("data", examquestionService.selectListView(ew));
}
/**
/**
*
*/
// 处理 /examquestion/query 路径的请求
@RequestMapping("/query")
// 该方法用于查询单个试题信息
public R query(ExamquestionEntity examquestion){
// 创建一个用于构建查询条件的实体包装器
EntityWrapper< ExamquestionEntity> ew = new EntityWrapper< ExamquestionEntity>();
ew.allEq(MPUtil.allEQMapPre( examquestion, "examquestion"));
ExamquestionView examquestionView = examquestionService.selectView(ew);
return R.ok("查询试题表成功").put("data", examquestionView);
// 设置查询条件为所有字段相等
ew.allEq(MPUtil.allEQMapPre( examquestion, "examquestion"));
// 调用试题服务类的 selectView 方法查询单个试题信息
ExamquestionView examquestionView = examquestionService.selectView(ew);
// 返回成功响应,并将查询到的试题信息放入响应结果中
return R.ok("查询试题表成功").put("data", examquestionView);
}
/**
*
*/
// 处理 /examquestion/info/{id} 路径的请求,{id} 为路径变量
@RequestMapping("/info/{id}")
// 该方法用于获取单个试题的详细信息
public R info(@PathVariable("id") Long id){
// 调用试题服务类的 selectById 方法根据 ID 查询试题信息
ExamquestionEntity examquestion = examquestionService.selectById(id);
// 返回成功响应,并将查询到的试题信息放入响应结果中
return R.ok().put("data", examquestion);
}
/**
*
*/
// 处理 /examquestion/detail/{id} 路径的请求,{id} 为路径变量
@RequestMapping("/detail/{id}")
// 该方法用于获取单个试题的详细信息(前端使用)
public R detail(@PathVariable("id") Long id){
// 调用试题服务类的 selectById 方法根据 ID 查询试题信息
ExamquestionEntity examquestion = examquestionService.selectById(id);
// 返回成功响应,并将查询到的试题信息放入响应结果中
return R.ok().put("data", examquestion);
}
/**
*
*/
// 处理 /examquestion/save 路径的 POST 请求
@RequestMapping("/save")
// 该方法用于保存新的试题信息
public R save(@RequestBody ExamquestionEntity examquestion, HttpServletRequest request){
examquestion.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(examquestion);
// 为试题设置一个唯一的 ID由当前时间戳加上一个随机数组成
examquestion.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
// 暂时注释掉实体验证逻辑
//ValidatorUtils.validateEntity(examquestion);
// 调用试题服务类的 insert 方法将试题信息插入数据库
examquestionService.insert(examquestion);
// 返回成功响应
return R.ok();
}
/**
*
*/
// 处理 /examquestion/add 路径的 POST 请求
@RequestMapping("/add")
// 该方法用于保存新的试题信息(前端使用)
public R add(@RequestBody ExamquestionEntity examquestion, HttpServletRequest request){
examquestion.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(examquestion);
// 为试题设置一个唯一的 ID由当前时间戳加上一个随机数组成
examquestion.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
// 暂时注释掉实体验证逻辑
//ValidatorUtils.validateEntity(examquestion);
// 调用试题服务类的 insert 方法将试题信息插入数据库
examquestionService.insert(examquestion);
// 返回成功响应
return R.ok();
}
/**
*
*/
// 处理 /examquestion/update 路径的 POST 请求
@RequestMapping("/update")
// 该方法用于更新试题信息
public R update(@RequestBody ExamquestionEntity examquestion, HttpServletRequest request){
// 暂时注释掉实体验证逻辑
//ValidatorUtils.validateEntity(examquestion);
// 调用试题服务类的 updateById 方法根据 ID 更新试题信息
examquestionService.updateById(examquestion);//全部更新
// 返回成功响应
return R.ok();
}
/**
*
*/
// 处理 /examquestion/delete 路径的 POST 请求
@RequestMapping("/delete")
// 该方法用于批量删除试题信息
public R delete(@RequestBody Long[] ids){
// 调用试题服务类的 deleteBatchIds 方法根据 ID 批量删除试题信息
examquestionService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<ExamquestionEntity> wrapper = new EntityWrapper<ExamquestionEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = examquestionService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
// 处理 /examquestion/remind/{columnName}/{type} 路径的请求,{columnName} 和 {type} 为路径变量
@RequestMapping("/remind/{columnName}/{type}")
// 该方法用于统计符合提醒条件的试题数量
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
// 将列名和提醒类型放入请求参数中
map.put("column", columnName);
map.put("type", type);
// 如果提醒类型为 2
if(type.equals("2")) {
// 创建一个用于格式化日期的对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建一个 Calendar 实例用于处理日期
Calendar c = Calendar.getInstance();
// 定义提醒开始日期和结束日期
Date remindStartDate = null;
Date remindEndDate = null;
// 如果请求参数中包含提醒开始时间
if(map.get("remindstart")!=null) {
// 将提醒开始时间转换为整数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
// 设置 Calendar 的时间为当前时间
c.setTime(new Date());
// 在当前时间基础上加上提醒开始时间的天数
c.add(Calendar.DAY_OF_MONTH,remindStart);
// 获取提醒开始日期
remindStartDate = c.getTime();
// 将格式化后的提醒开始日期放入请求参数中
map.put("remindstart", sdf.format(remindStartDate));
}
// 如果请求参数中包含提醒结束时间
if(map.get("remindend")!=null) {
// 将提醒结束时间转换为整数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置 Calendar 的时间为当前时间
c.setTime(new Date());
// 在当前时间基础上加上提醒结束时间的天数
c.add(Calendar.DAY_OF_MONTH,remindEnd);
// 获取提醒结束日期
remindEndDate = c.getTime();
// 将格式化后的提醒结束日期放入请求参数中
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建一个用于构建查询条件的包装器
Wrapper<ExamquestionEntity> wrapper = new EntityWrapper<ExamquestionEntity>();
// 如果请求参数中包含提醒开始时间
if(map.get("remindstart")!=null) {
// 设置查询条件为列值大于等于提醒开始时间
wrapper.ge(columnName, map.get("remindstart"));
}
// 如果请求参数中包含提醒结束时间
if(map.get("remindend")!=null) {
// 设置查询条件为列值小于等于提醒结束时间
wrapper.le(columnName, map.get("remindend"));
}
// 调用试题服务类的 selectCount 方法统计符合条件的试题数量
int count = examquestionService.selectCount(wrapper);
// 返回成功响应,并将统计结果放入响应结果中
return R.ok().put("count", count);
}
}

@ -1,238 +1,369 @@
package com.controller;
// 导入用于格式化日期的类
import java.text.SimpleDateFormat;
// 导入 ArrayList 类,用于创建动态数组
import java.util.ArrayList;
// 导入 Arrays 类,用于操作数组
import java.util.Arrays;
// 导入 Calendar 类,用于处理日期和时间
import java.util.Calendar;
// 导入 Map 接口,用于存储键值对
import java.util.Map;
// 导入 HashMap 类,实现了 Map 接口
import java.util.HashMap;
// 导入 Iterator 接口,用于遍历集合
import java.util.Iterator;
// 导入 Date 类,用于表示日期和时间
import java.util.Date;
// 导入 List 接口,用于创建列表
import java.util.List;
// 导入 HttpServletRequest 类,用于处理 HTTP 请求
import javax.servlet.http.HttpServletRequest;
// 导入验证工具类
import com.utils.ValidatorUtils;
// 导入 Apache Commons Lang 库中的 StringUtils 类,用于处理字符串
import org.apache.commons.lang3.StringUtils;
// 导入 Spring 框架的自动注入注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入 Spring 框架的日期格式化注解
import org.springframework.format.annotation.DateTimeFormat;
// 导入 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;
// 导入 MyBatis-Plus 的实体包装器类
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入 MyBatis-Plus 的包装器接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解
import com.annotation.IgnoreAuth;
// 导入考试记录实体类
import com.entity.ExamrecordEntity;
// 导入考试记录视图类
import com.entity.view.ExamrecordView;
// 导入考试记录服务类
import com.service.ExamrecordService;
// 导入令牌服务类
import com.service.TokenService;
// 导入分页工具类
import com.utils.PageUtils;
// 导入自定义的响应类
import com.utils.R;
// 导入 MD5 加密工具类
import com.utils.MD5Util;
// 导入 MyBatis-Plus 工具类
import com.utils.MPUtil;
// 导入通用工具类
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:15
*/
// 声明为 REST 控制器,用于处理 HTTP 请求
@RestController
// 映射请求路径,所有以 /examrecord 开头的请求都会被该控制器处理
@RequestMapping("/examrecord")
public class ExamrecordController {
// 自动注入考试记录服务类的实例
@Autowired
private ExamrecordService examrecordService;
/**
/**
*
*/
// 映射请求路径 /examrecord/groupby
@RequestMapping("/groupby")
// 处理分组查询请求
public R page2(@RequestParam Map<String, Object> params,ExamrecordEntity examrecord, HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
examrecord.setUserid((Long)request.getSession().getAttribute("userId"));
}
// 如果当前用户不是管理员
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
// 设置考试记录的用户 ID 为当前用户的 ID
examrecord.setUserid((Long)request.getSession().getAttribute("userId"));
}
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<ExamrecordEntity> ew = new EntityWrapper<ExamrecordEntity>();
PageUtils page = examrecordService.queryPageGroupBy(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, examrecord), params), params));
// 调用考试记录服务类的查询分页分组方法
PageUtils page = examrecordService.queryPageGroupBy(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, examrecord), params), params));
// 返回成功响应,并将分页数据放入响应中
return R.ok().put("data", page);
}
/**
*
*/
// 映射请求路径 /examrecord/page
@RequestMapping("/page")
// 处理后端分页查询请求
public R page(@RequestParam Map<String, Object> params,ExamrecordEntity examrecord,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
examrecord.setUserid((Long)request.getSession().getAttribute("userId"));
}
HttpServletRequest request){
// 如果当前用户不是管理员
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
// 设置考试记录的用户 ID 为当前用户的 ID
examrecord.setUserid((Long)request.getSession().getAttribute("userId"));
}
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<ExamrecordEntity> ew = new EntityWrapper<ExamrecordEntity>();
PageUtils page = examrecordService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, examrecord), params), params));
// 调用考试记录服务类的查询分页方法
PageUtils page = examrecordService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, examrecord), params), params));
// 返回成功响应,并将分页数据放入响应中
return R.ok().put("data", page);
}
/**
*
*/
// 映射请求路径 /examrecord/list
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ExamrecordEntity examrecord,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
examrecord.setUserid((Long)request.getSession().getAttribute("userId"));
}
// 处理前端分页查询请求
public R list(@RequestParam Map<String, Object> params,ExamrecordEntity examrecord,
HttpServletRequest request){
// 如果当前用户不是管理员
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
// 设置考试记录的用户 ID 为当前用户的 ID
examrecord.setUserid((Long)request.getSession().getAttribute("userId"));
}
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<ExamrecordEntity> ew = new EntityWrapper<ExamrecordEntity>();
PageUtils page = examrecordService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, examrecord), params), params));
// 调用考试记录服务类的查询分页方法
PageUtils page = examrecordService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, examrecord), params), params));
// 返回成功响应,并将分页数据放入响应中
return R.ok().put("data", page);
}
/**
/**
*
*/
// 映射请求路径 /examrecord/lists
@RequestMapping("/lists")
// 处理列表查询请求
public R list( ExamrecordEntity examrecord){
EntityWrapper<ExamrecordEntity> ew = new EntityWrapper<ExamrecordEntity>();
ew.allEq(MPUtil.allEQMapPre( examrecord, "examrecord"));
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<ExamrecordEntity> ew = new EntityWrapper<ExamrecordEntity>();
// 设置查询条件,所有字段相等
ew.allEq(MPUtil.allEQMapPre( examrecord, "examrecord"));
// 返回成功响应,并将查询结果放入响应中
return R.ok().put("data", examrecordService.selectListView(ew));
}
/**
/**
*
*/
// 映射请求路径 /examrecord/query
@RequestMapping("/query")
// 处理查询请求
public R query(ExamrecordEntity examrecord){
// 创建一个实体包装器,用于构建查询条件
EntityWrapper< ExamrecordEntity> ew = new EntityWrapper< ExamrecordEntity>();
ew.allEq(MPUtil.allEQMapPre( examrecord, "examrecord"));
ExamrecordView examrecordView = examrecordService.selectView(ew);
return R.ok("查询考试记录表成功").put("data", examrecordView);
// 设置查询条件,所有字段相等
ew.allEq(MPUtil.allEQMapPre( examrecord, "examrecord"));
// 调用考试记录服务类的查询视图方法
ExamrecordView examrecordView = examrecordService.selectView(ew);
// 返回成功响应,并将查询结果放入响应中
return R.ok("查询考试记录表成功").put("data", examrecordView);
}
/**
*
*/
// 映射请求路径 /examrecord/info/{id}
@RequestMapping("/info/{id}")
// 处理后端详情查询请求
public R info(@PathVariable("id") Long id){
// 根据 ID 查询考试记录实体
ExamrecordEntity examrecord = examrecordService.selectById(id);
// 返回成功响应,并将查询结果放入响应中
return R.ok().put("data", examrecord);
}
/**
*
*/
// 映射请求路径 /examrecord/detail/{id}
@RequestMapping("/detail/{id}")
// 处理前端详情查询请求
public R detail(@PathVariable("id") Long id){
// 根据 ID 查询考试记录实体
ExamrecordEntity examrecord = examrecordService.selectById(id);
// 返回成功响应,并将查询结果放入响应中
return R.ok().put("data", examrecord);
}
/**
*
*/
// 映射请求路径 /examrecord/save
@RequestMapping("/save")
// 处理后端保存请求
public R save(@RequestBody ExamrecordEntity examrecord, HttpServletRequest request){
examrecord.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(examrecord);
examrecord.setUserid((Long)request.getSession().getAttribute("userId"));
// 生成一个唯一的 ID
examrecord.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
// 验证实体(注释掉,未启用)
//ValidatorUtils.validateEntity(examrecord);
// 设置考试记录的用户 ID 为当前用户的 ID
examrecord.setUserid((Long)request.getSession().getAttribute("userId"));
// 调用考试记录服务类的插入方法
examrecordService.insert(examrecord);
// 返回成功响应
return R.ok();
}
/**
*
*/
// 映射请求路径 /examrecord/add
@RequestMapping("/add")
// 处理前端保存请求
public R add(@RequestBody ExamrecordEntity examrecord, HttpServletRequest request){
examrecord.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(examrecord);
examrecord.setUserid((Long)request.getSession().getAttribute("userId"));
// 生成一个唯一的 ID
examrecord.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
// 验证实体(注释掉,未启用)
//ValidatorUtils.validateEntity(examrecord);
// 设置考试记录的用户 ID 为当前用户的 ID
examrecord.setUserid((Long)request.getSession().getAttribute("userId"));
// 调用考试记录服务类的插入方法
examrecordService.insert(examrecord);
// 返回成功响应
return R.ok();
}
/**
*
*/
// 映射请求路径 /examrecord/update
@RequestMapping("/update")
// 处理修改请求
public R update(@RequestBody ExamrecordEntity examrecord, HttpServletRequest request){
// 验证实体(注释掉,未启用)
//ValidatorUtils.validateEntity(examrecord);
// 调用考试记录服务类的更新方法,更新所有字段
examrecordService.updateById(examrecord);//全部更新
// 返回成功响应
return R.ok();
}
/**
*
*/
// 映射请求路径 /examrecord/delete
@RequestMapping("/delete")
// 处理删除请求
public R delete(@RequestBody Long[] ids){
// 调用考试记录服务类的批量删除方法
examrecordService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<ExamrecordEntity> wrapper = new EntityWrapper<ExamrecordEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
wrapper.eq("userid", (Long)request.getSession().getAttribute("userId"));
}
int count = examrecordService.selectCount(wrapper);
return R.ok().put("count", count);
}
// 映射请求路径 /examrecord/remind/{columnName}/{type}
@RequestMapping("/remind/{columnName}/{type}")
// 处理提醒统计请求
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
// 将列名放入参数映射中
map.put("column", columnName);
// 将类型放入参数映射中
map.put("type", type);
// 如果类型为 2
if(type.equals("2")) {
// 创建一个日期格式化对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建一个日历对象
Calendar c = Calendar.getInstance();
// 提醒开始日期
Date remindStartDate = null;
// 提醒结束日期
Date remindEndDate = null;
// 如果提醒开始参数不为空
if(map.get("remindstart")!=null) {
// 将提醒开始参数转换为整数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
// 设置日历时间为当前时间
c.setTime(new Date());
// 在当前日期上加上提醒开始天数
c.add(Calendar.DAY_OF_MONTH,remindStart);
// 获取提醒开始日期
remindStartDate = c.getTime();
// 将提醒开始日期格式化后放入参数映射中
map.put("remindstart", sdf.format(remindStartDate));
}
// 如果提醒结束参数不为空
if(map.get("remindend")!=null) {
// 将提醒结束参数转换为整数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置日历时间为当前时间
c.setTime(new Date());
// 在当前日期上加上提醒结束天数
c.add(Calendar.DAY_OF_MONTH,remindEnd);
// 获取提醒结束日期
remindEndDate = c.getTime();
// 将提醒结束日期格式化后放入参数映射中
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建一个实体包装器,用于构建查询条件
Wrapper<ExamrecordEntity> wrapper = new EntityWrapper<ExamrecordEntity>();
// 如果提醒开始参数不为空
if(map.get("remindstart")!=null) {
// 设置查询条件,列名大于等于提醒开始日期
wrapper.ge(columnName, map.get("remindstart"));
}
// 如果提醒结束参数不为空
if(map.get("remindend")!=null) {
// 设置查询条件,列名小于等于提醒结束日期
wrapper.le(columnName, map.get("remindend"));
}
// 如果当前用户不是管理员
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
// 设置查询条件,用户 ID 等于当前用户的 ID
wrapper.eq("userid", (Long)request.getSession().getAttribute("userId"));
}
// 调用考试记录服务类的统计方法,统计符合条件的记录数
int count = examrecordService.selectCount(wrapper);
// 返回成功响应,并将统计结果放入响应中
return R.ok().put("count", count);
}
/**
*
*/
// 映射请求路径 /examrecord/deleteRecords
@RequestMapping("/deleteRecords")
// 处理删除指定考生指定试卷的所有考试记录请求
public R deleteRecords(@RequestParam Long userid,@RequestParam Long paperid){
examrecordService.delete(new EntityWrapper<ExamrecordEntity>().eq("paperid", paperid).eq("userid", userid));
// 调用考试记录服务类的删除方法,根据用户 ID 和试卷 ID 删除记录
examrecordService.delete(new EntityWrapper<ExamrecordEntity>().eq("paperid", paperid).eq("userid", userid));
// 返回成功响应
return R.ok();
}
}
}

@ -1,110 +1,187 @@
// 声明该类所在的包
package com.controller;
// 导入用于处理文件的类
import java.io.File;
// 导入文件未找到异常类
import java.io.FileNotFoundException;
// 导入输入输出异常类
import java.io.IOException;
// 导入数组操作工具类
import java.util.Arrays;
// 导入日期类
import java.util.Date;
// 导入哈希表实现类
import java.util.HashMap;
// 导入列表接口
import java.util.List;
// 导入映射接口
import java.util.Map;
// 导入随机数生成类
import java.util.Random;
// 导入通用唯一识别码类
import java.util.UUID;
// 导入 Apache Commons IO 库的文件工具类
import org.apache.commons.io.FileUtils;
// 导入 Apache Commons Lang 库的字符串工具类
import org.apache.commons.lang3.StringUtils;
// 导入 Spring 框架的自动注入注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入 Spring 框架的 HTTP 头类
import org.springframework.http.HttpHeaders;
// 导入 Spring 框架的 HTTP 状态码类
import org.springframework.http.HttpStatus;
// 导入 Spring 框架的媒体类型类
import org.springframework.http.MediaType;
// 导入 Spring 框架的响应实体类
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;
/**
*
*/
// 声明为 REST 控制器,用于处理 HTTP 请求
@RestController
// 映射请求路径,所有以 /file 开头的请求都会被该控制器处理
@RequestMapping("file")
// 抑制未经检查的类型转换警告
@SuppressWarnings({"unchecked","rawtypes"})
// 文件控制器类,处理文件上传和下载请求
public class FileController{
// 自动注入配置服务类的实例
@Autowired
private ConfigService configService;
private ConfigService configService;
/**
*
*/
// 映射请求路径 /file/upload
@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);
// 获取类路径下 static 目录的文件对象
File path = new File(ResourceUtils.getURL("classpath:static").getPath());
// 检查该目录是否存在
if(!path.exists()) {
path = new File("");
// 若不存在,创建一个空文件对象
path = new File("");
}
// 创建上传目录的文件对象
File upload = new File(path.getAbsolutePath(),"/upload/");
// 检查上传目录是否存在
if(!upload.exists()) {
upload.mkdirs();
// 若不存在,创建该目录及其父目录
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")) {
// 根据配置名称查询配置实体
ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().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);
}
/**
*
*/
// 该接口忽略认证
@IgnoreAuth
// 映射请求路径 /file/download
@RequestMapping("/download")
// 处理文件下载请求
public ResponseEntity<byte[]> download(@RequestParam String fileName) {
try {
// 获取类路径下 static 目录的文件对象
File path = new File(ResourceUtils.getURL("classpath:static").getPath());
// 检查该目录是否存在
if(!path.exists()) {
path = new File("");
// 若不存在,创建一个空文件对象
path = new File("");
}
// 创建上传目录的文件对象
File upload = new File(path.getAbsolutePath(),"/upload/");
// 检查上传目录是否存在
if(!upload.exists()) {
upload.mkdirs();
// 若不存在,创建该目录及其父目录
upload.mkdirs();
}
// 创建要下载的文件对象
File file = new File(upload.getAbsolutePath()+"/"+fileName);
// 检查文件是否存在
if(file.exists()){
/*if(!fileService.canRead(file, SessionManager.getSessionUser())){
getResponse().sendError(403);
}*/
// 这里注释掉的代码是检查用户是否有读取文件的权限
/*if(!fileService.canRead(file, SessionManager.getSessionUser())){
getResponse().sendError(403);
}*/
// 创建 HTTP 头对象
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
// 设置内容类型为二进制流
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
// 设置内容处置为附件,指定文件名
headers.setContentDispositionFormData("attachment", fileName);
// 返回响应实体包含文件内容、HTTP 头和 HTTP 状态码
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
}
} catch (IOException e) {
// 捕获输入输出异常并打印堆栈跟踪信息
e.printStackTrace();
}
// 若出现异常或文件不存在,返回内部服务器错误响应
return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

@ -1,238 +1,363 @@
// 声明该类所在的包
package com.controller;
// 导入用于格式化日期的类
import java.text.SimpleDateFormat;
// 导入用于创建动态数组的类
import java.util.ArrayList;
// 导入用于操作数组的工具类
import java.util.Arrays;
// 导入用于处理日期和时间的类
import java.util.Calendar;
// 导入用于存储键值对的接口
import java.util.Map;
// 导入 HashMap 类,用于实现 Map 接口
import java.util.HashMap;
// 导入用于遍历集合的接口
import java.util.Iterator;
// 导入用于表示日期和时间的类
import java.util.Date;
// 导入用于创建列表的接口
import java.util.List;
// 导入用于处理 HTTP 请求的类
import javax.servlet.http.HttpServletRequest;
// 导入自定义的验证工具类
import com.utils.ValidatorUtils;
// 导入 Apache Commons Lang 库中的字符串处理工具类
import org.apache.commons.lang3.StringUtils;
// 导入 Spring 框架的自动注入注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入 Spring 框架的日期格式化注解
import org.springframework.format.annotation.DateTimeFormat;
// 导入 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;
// 导入 MyBatis-Plus 的实体包装器类
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入 MyBatis-Plus 的包装器接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解
import com.annotation.IgnoreAuth;
// 导入学习交流实体类
import com.entity.ForumEntity;
// 导入学习交流视图类
import com.entity.view.ForumView;
// 导入学习交流服务类
import com.service.ForumService;
// 导入令牌服务类
import com.service.TokenService;
// 导入分页工具类
import com.utils.PageUtils;
// 导入自定义的响应类
import com.utils.R;
// 导入 MD5 加密工具类
import com.utils.MD5Util;
// 导入 MyBatis-Plus 工具类
import com.utils.MPUtil;
// 导入通用工具类
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:15
*/
// 声明该类为 REST 控制器,用于处理 HTTP 请求
@RestController
// 映射请求路径,所有以 /forum 开头的请求都会由该控制器处理
@RequestMapping("/forum")
public class ForumController {
// 自动注入学习交流服务类的实例
@Autowired
private ForumService forumService;
/**
*
*/
// 映射请求路径 /forum/page
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ForumEntity forum,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
forum.setUserid((Long)request.getSession().getAttribute("userId"));
}
// 处理后端分页查询学习交流列表的请求
public R page(@RequestParam Map<String, Object> params, ForumEntity forum,
HttpServletRequest request) {
// 如果当前用户不是管理员
if (!request.getSession().getAttribute("role").toString().equals("管理员")) {
// 设置学习交流的用户 ID 为当前用户的 ID
forum.setUserid((Long) request.getSession().getAttribute("userId"));
}
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>();
PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params));
// 调用学习交流服务类的查询分页方法,进行排序、范围和模糊查询
PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params));
// 返回成功响应,并将分页数据放入响应中
return R.ok().put("data", page);
}
/**
*
*/
// 映射请求路径 /forum/list
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ForumEntity forum,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
forum.setUserid((Long)request.getSession().getAttribute("userId"));
}
// 处理前端分页查询学习交流列表的请求
public R list(@RequestParam Map<String, Object> params, ForumEntity forum,
HttpServletRequest request) {
// 如果当前用户不是管理员
if (!request.getSession().getAttribute("role").toString().equals("管理员")) {
// 设置学习交流的用户 ID 为当前用户的 ID
forum.setUserid((Long) request.getSession().getAttribute("userId"));
}
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>();
PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params));
// 调用学习交流服务类的查询分页方法,进行排序、范围和模糊查询
PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params));
// 返回成功响应,并将分页数据放入响应中
return R.ok().put("data", page);
}
/**
/**
*
*/
// 该接口忽略认证
@IgnoreAuth
// 映射请求路径 /forum/flist
@RequestMapping("/flist")
public R flist(@RequestParam Map<String, Object> params,ForumEntity forum, HttpServletRequest request){
// 处理查询学习交流列表的请求
public R flist(@RequestParam Map<String, Object> params, ForumEntity forum, HttpServletRequest request) {
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>();
PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allEq(ew, forum), params), params));
// 调用学习交流服务类的查询分页方法,进行排序、范围和全量相等查询
PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allEq(ew, forum), params), params));
// 返回成功响应,并将分页数据放入响应中
return R.ok().put("data", page);
}
/**
/**
*
*/
// 映射请求路径 /forum/query
@RequestMapping("/query")
public R query(ForumEntity forum){
EntityWrapper< ForumEntity> ew = new EntityWrapper< ForumEntity>();
ew.allEq(MPUtil.allEQMapPre( forum, "forum"));
ForumView forumView = forumService.selectView(ew);
return R.ok("查询学习交流成功").put("data", forumView);
// 处理查询学习交流信息的请求
public R query(ForumEntity forum) {
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>();
// 设置查询条件,所有字段相等
ew.allEq(MPUtil.allEQMapPre(forum, "forum"));
// 调用学习交流服务类的查询视图方法
ForumView forumView = forumService.selectView(ew);
// 返回成功响应,并将查询结果放入响应中
return R.ok("查询学习交流成功").put("data", forumView);
}
/**
*
*/
// 映射请求路径 /forum/info/{id}
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
// 处理后端查询学习交流详情的请求
public R info(@PathVariable("id") Long id) {
// 根据 ID 查询学习交流实体
ForumEntity forum = forumService.selectById(id);
// 返回成功响应,并将查询结果放入响应中
return R.ok().put("data", forum);
}
/**
*
*/
// 映射请求路径 /forum/detail/{id}
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
// 处理前端查询学习交流详情的请求
public R detail(@PathVariable("id") Long id) {
// 根据 ID 查询学习交流实体
ForumEntity forum = forumService.selectById(id);
// 返回成功响应,并将查询结果放入响应中
return R.ok().put("data", forum);
}
/**
/**
*
*/
@IgnoreAuth
// 该接口忽略认证
@IgnoreAuth
// 映射请求路径 /forum/list/{id}
@RequestMapping("/list/{id}")
public R list(@PathVariable("id") String id){
// 处理查询论坛详情的请求
public R list(@PathVariable("id") String id) {
// 根据 ID 查询学习交流实体
ForumEntity forum = forumService.selectById(id);
// 递归获取子论坛信息
getChilds(forum);
// 返回成功响应,并将查询结果放入响应中
return R.ok().put("data", forum);
}
private ForumEntity getChilds(ForumEntity forum) {
List<ForumEntity> childs = new ArrayList<ForumEntity>();
childs = forumService.selectList(new EntityWrapper<ForumEntity>().eq("parentid", forum.getId()));
if(childs == null || childs.size()==0) {
return null;
}
forum.setChilds(childs);
for(ForumEntity forumEntity : childs) {
getChilds(forumEntity);
}
return forum;
}
// 递归获取子论坛信息的方法
private ForumEntity getChilds(ForumEntity forum) {
// 创建一个存储子论坛的列表
List<ForumEntity> childs = new ArrayList<ForumEntity>();
// 查询该论坛的所有子论坛
childs = forumService.selectList(new EntityWrapper<ForumEntity>().eq("parentid", forum.getId()));
// 如果没有子论坛
if (childs == null || childs.size() == 0) {
// 返回 null
return null;
}
// 设置该论坛的子论坛列表
forum.setChilds(childs);
// 递归处理每个子论坛
for (ForumEntity forumEntity : childs) {
getChilds(forumEntity);
}
// 返回该论坛
return forum;
}
/**
*
*/
// 映射请求路径 /forum/save
@RequestMapping("/save")
public R save(@RequestBody ForumEntity forum, HttpServletRequest request){
forum.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(forum);
forum.setUserid((Long)request.getSession().getAttribute("userId"));
// 处理后端保存学习交流信息的请求
public R save(@RequestBody ForumEntity forum, HttpServletRequest request) {
// 生成一个唯一的 ID
forum.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 验证实体(注释掉,未启用)
//ValidatorUtils.validateEntity(forum);
// 设置学习交流的用户 ID 为当前用户的 ID
forum.setUserid((Long) request.getSession().getAttribute("userId"));
// 调用学习交流服务类的插入方法
forumService.insert(forum);
// 返回成功响应
return R.ok();
}
/**
*
*/
// 映射请求路径 /forum/add
@RequestMapping("/add")
public R add(@RequestBody ForumEntity forum, HttpServletRequest request){
forum.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(forum);
forum.setUserid((Long)request.getSession().getAttribute("userId"));
// 处理前端保存学习交流信息的请求
public R add(@RequestBody ForumEntity forum, HttpServletRequest request) {
// 生成一个唯一的 ID
forum.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 验证实体(注释掉,未启用)
//ValidatorUtils.validateEntity(forum);
// 设置学习交流的用户 ID 为当前用户的 ID
forum.setUserid((Long) request.getSession().getAttribute("userId"));
// 调用学习交流服务类的插入方法
forumService.insert(forum);
// 返回成功响应
return R.ok();
}
/**
*
*/
// 映射请求路径 /forum/update
@RequestMapping("/update")
public R update(@RequestBody ForumEntity forum, HttpServletRequest request){
// 处理修改学习交流信息的请求
public R update(@RequestBody ForumEntity forum, HttpServletRequest request) {
// 验证实体(注释掉,未启用)
//ValidatorUtils.validateEntity(forum);
forumService.updateById(forum);//全部更新
// 调用学习交流服务类的更新方法,更新所有字段
forumService.updateById(forum); // 全部更新
// 返回成功响应
return R.ok();
}
/**
*
*/
// 映射请求路径 /forum/delete
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
// 处理删除学习交流信息的请求
public R delete(@RequestBody Long[] ids) {
// 调用学习交流服务类的批量删除方法
forumService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<ForumEntity> wrapper = new EntityWrapper<ForumEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = forumService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
// 映射请求路径 /forum/remind/{columnName}/{type}
@RequestMapping("/remind/{columnName}/{type}")
// 处理提醒统计的请求
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 将列名放入参数映射中
map.put("column", columnName);
// 将类型放入参数映射中
map.put("type", type);
// 如果类型为 2
if (type.equals("2")) {
// 创建一个日期格式化对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建一个日历对象
Calendar c = Calendar.getInstance();
// 提醒开始日期
Date remindStartDate = null;
// 提醒结束日期
Date remindEndDate = null;
// 如果提醒开始参数不为空
if (map.get("remindstart") != null) {
// 将提醒开始参数转换为整数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
// 设置日历时间为当前时间
c.setTime(new Date());
// 在当前日期上加上提醒开始天数
c.add(Calendar.DAY_OF_MONTH, remindStart);
// 获取提醒开始日期
remindStartDate = c.getTime();
// 将提醒开始日期格式化后放入参数映射中
map.put("remindstart", sdf.format(remindStartDate));
}
// 如果提醒结束参数不为空
if (map.get("remindend") != null) {
// 将提醒结束参数转换为整数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置日历时间为当前时间
c.setTime(new Date());
// 在当前日期上加上提醒结束天数
c.add(Calendar.DAY_OF_MONTH, remindEnd);
// 获取提醒结束日期
remindEndDate = c.getTime();
// 将提醒结束日期格式化后放入参数映射中
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建一个实体包装器,用于构建查询条件
Wrapper<ForumEntity> wrapper = new EntityWrapper<ForumEntity>();
// 如果提醒开始参数不为空
if (map.get("remindstart") != null) {
// 设置查询条件,列名大于等于提醒开始日期
wrapper.ge(columnName, map.get("remindstart"));
}
// 如果提醒结束参数不为空
if (map.get("remindend") != null) {
// 设置查询条件,列名小于等于提醒结束日期
wrapper.le(columnName, map.get("remindend"));
}
// 调用学习交流服务类的统计方法,统计符合条件的记录数
int count = forumService.selectCount(wrapper);
// 返回成功响应,并将统计结果放入响应中
return R.ok().put("count", count);
}
}

@ -1,214 +1,317 @@
package com.controller;
// 导入用于格式化日期的类
import java.text.SimpleDateFormat;
// 导入用于创建动态数组的类
import java.util.ArrayList;
// 导入用于操作数组的工具类
import java.util.Arrays;
// 导入用于处理日期和时间的类
import java.util.Calendar;
// 导入用于存储键值对的接口
import java.util.Map;
// 导入 HashMap 类,用于实现 Map 接口
import java.util.HashMap;
// 导入用于遍历集合的接口
import java.util.Iterator;
// 导入用于表示日期和时间的类
import java.util.Date;
// 导入用于创建列表的接口
import java.util.List;
// 导入用于处理 HTTP 请求的类
import javax.servlet.http.HttpServletRequest;
// 导入自定义的验证工具类
import com.utils.ValidatorUtils;
// 导入 Apache Commons Lang 库中的字符串处理工具类
import org.apache.commons.lang3.StringUtils;
// 导入 Spring 框架的自动注入注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入 Spring 框架的日期格式化注解
import org.springframework.format.annotation.DateTimeFormat;
// 导入 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;
// 导入 MyBatis-Plus 的实体包装器类
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入 MyBatis-Plus 的包装器接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解
import com.annotation.IgnoreAuth;
// 导入购买的课程实体类
import com.entity.GoumaidekechengEntity;
// 导入购买的课程视图类
import com.entity.view.GoumaidekechengView;
// 导入购买的课程服务类
import com.service.GoumaidekechengService;
// 导入令牌服务类
import com.service.TokenService;
// 导入分页工具类
import com.utils.PageUtils;
// 导入自定义的响应类
import com.utils.R;
// 导入 MD5 加密工具类
import com.utils.MD5Util;
// 导入 MyBatis-Plus 工具类
import com.utils.MPUtil;
// 导入通用工具类
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:14
*/
// 声明为 REST 控制器,用于处理 HTTP 请求
@RestController
// 映射请求路径,所有以 /goumaidekecheng 开头的请求由该控制器处理
@RequestMapping("/goumaidekecheng")
public class GoumaidekechengController {
// 自动注入购买的课程服务类实例
@Autowired
private GoumaidekechengService goumaidekechengService;
/**
*
*
*/
// 映射请求路径 /goumaidekecheng/page
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,GoumaidekechengEntity goumaidekecheng,
HttpServletRequest request){
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yonghu")) {
goumaidekecheng.setYonghuzhanghao((String)request.getSession().getAttribute("username"));
}
// 处理后端分页查询请求参数包括查询条件、实体对象、HTTP 请求
public R page(@RequestParam Map<String, Object> params, GoumaidekechengEntity goumaidekecheng,
HttpServletRequest request) {
// 从会话中获取表名(判断用户类型)
String tableName = request.getSession().getAttribute("tableName").toString();
// 如果表名是 "yonghu"(用户表)
if (tableName.equals("yonghu")) {
// 设置查询条件:用户账号为当前登录用户的用户名
goumaidekecheng.setYonghuzhanghao((String) request.getSession().getAttribute("username"));
}
// 创建实体包装器,用于构建查询条件
EntityWrapper<GoumaidekechengEntity> ew = new EntityWrapper<GoumaidekechengEntity>();
PageUtils page = goumaidekechengService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, goumaidekecheng), params), params));
// 调用服务类的分页查询方法,包含排序、范围查询、模糊查询处理
PageUtils page = goumaidekechengService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, goumaidekecheng), params), params));
// 返回成功响应,携带分页数据
return R.ok().put("data", page);
}
/**
*
*
*/
// 映射请求路径 /goumaidekecheng/list
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,GoumaidekechengEntity goumaidekecheng,
HttpServletRequest request){
// 处理前端分页查询请求参数包括查询条件、实体对象、HTTP 请求
public R list(@RequestParam Map<String, Object> params, GoumaidekechengEntity goumaidekecheng,
HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<GoumaidekechengEntity> ew = new EntityWrapper<GoumaidekechengEntity>();
PageUtils page = goumaidekechengService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, goumaidekecheng), params), params));
// 调用服务类的分页查询方法,包含排序、范围查询、模糊查询处理
PageUtils page = goumaidekechengService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, goumaidekecheng), params), params));
// 返回成功响应,携带分页数据
return R.ok().put("data", page);
}
/**
*
/**
*
*/
// 映射请求路径 /goumaidekecheng/lists
@RequestMapping("/lists")
public R list( GoumaidekechengEntity goumaidekecheng){
EntityWrapper<GoumaidekechengEntity> ew = new EntityWrapper<GoumaidekechengEntity>();
ew.allEq(MPUtil.allEQMapPre( goumaidekecheng, "goumaidekecheng"));
// 处理全量查询请求,参数为实体对象
public R list(GoumaidekechengEntity goumaidekecheng) {
// 创建实体包装器
EntityWrapper<GoumaidekechengEntity> ew = new EntityWrapper<GoumaidekechengEntity>();
// 设置查询条件:所有字段与实体对象相等(前缀为 "goumaidekecheng"
ew.allEq(MPUtil.allEQMapPre(goumaidekecheng, "goumaidekecheng"));
// 返回成功响应,携带查询结果(视图列表)
return R.ok().put("data", goumaidekechengService.selectListView(ew));
}
/**
*
/**
*
*/
// 映射请求路径 /goumaidekecheng/query
@RequestMapping("/query")
public R query(GoumaidekechengEntity goumaidekecheng){
EntityWrapper< GoumaidekechengEntity> ew = new EntityWrapper< GoumaidekechengEntity>();
ew.allEq(MPUtil.allEQMapPre( goumaidekecheng, "goumaidekecheng"));
GoumaidekechengView goumaidekechengView = goumaidekechengService.selectView(ew);
return R.ok("查询购买的课程成功").put("data", goumaidekechengView);
// 处理单个对象查询请求,参数为实体对象
public R query(GoumaidekechengEntity goumaidekecheng) {
// 创建实体包装器
EntityWrapper<GoumaidekechengEntity> ew = new EntityWrapper<GoumaidekechengEntity>();
// 设置查询条件:所有字段与实体对象相等(前缀为 "goumaidekecheng"
ew.allEq(MPUtil.allEQMapPre(goumaidekecheng, "goumaidekecheng"));
// 调用服务类的视图查询方法
GoumaidekechengView goumaidekechengView = goumaidekechengService.selectView(ew);
// 返回成功响应,携带查询结果和提示信息
return R.ok("查询购买的课程成功").put("data", goumaidekechengView);
}
/**
*
* ID
*/
// 映射请求路径 /goumaidekecheng/info/{id}
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
// 处理详情查询请求,参数为路径中的 ID
public R info(@PathVariable("id") Long id) {
// 根据 ID 直接查询实体对象
GoumaidekechengEntity goumaidekecheng = goumaidekechengService.selectById(id);
// 返回成功响应,携带查询到的实体数据
return R.ok().put("data", goumaidekecheng);
}
/**
*
* ID
*/
// 映射请求路径 /goumaidekecheng/detail/{id}
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
// 处理详情查询请求,参数为路径中的 ID前端调用
public R detail(@PathVariable("id") Long id) {
// 根据 ID 直接查询实体对象
GoumaidekechengEntity goumaidekecheng = goumaidekechengService.selectById(id);
// 返回成功响应,携带查询到的实体数据
return R.ok().put("data", goumaidekecheng);
}
/**
*
*
*/
// 映射请求路径 /goumaidekecheng/save
@RequestMapping("/save")
public R save(@RequestBody GoumaidekechengEntity goumaidekecheng, HttpServletRequest request){
goumaidekecheng.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(goumaidekecheng);
// 处理后端新增请求,请求体为实体对象,携带 HTTP 请求
public R save(@RequestBody GoumaidekechengEntity goumaidekecheng, HttpServletRequest request) {
// 生成唯一 ID时间戳 + 随机数)
goumaidekecheng.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 实体验证(注释,未启用)
//ValidatorUtils.validateEntity(goumaidekecheng);
// 调用服务类的插入方法
goumaidekechengService.insert(goumaidekecheng);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射请求路径 /goumaidekecheng/add
@RequestMapping("/add")
public R add(@RequestBody GoumaidekechengEntity goumaidekecheng, HttpServletRequest request){
goumaidekecheng.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(goumaidekecheng);
// 处理前端新增请求,请求体为实体对象,携带 HTTP 请求
public R add(@RequestBody GoumaidekechengEntity goumaidekecheng, HttpServletRequest request) {
// 生成唯一 ID时间戳 + 随机数)
goumaidekecheng.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 实体验证(注释,未启用)
//ValidatorUtils.validateEntity(goumaidekecheng);
// 调用服务类的插入方法
goumaidekechengService.insert(goumaidekecheng);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射请求路径 /goumaidekecheng/update
@RequestMapping("/update")
public R update(@RequestBody GoumaidekechengEntity goumaidekecheng, HttpServletRequest request){
// 处理修改请求,请求体为实体对象,携带 HTTP 请求
public R update(@RequestBody GoumaidekechengEntity goumaidekecheng, HttpServletRequest request) {
// 实体验证(注释,未启用)
//ValidatorUtils.validateEntity(goumaidekecheng);
goumaidekechengService.updateById(goumaidekecheng);//全部更新
// 调用服务类的更新方法(根据 ID 全量更新)
goumaidekechengService.updateById(goumaidekecheng); // 全部更新
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射请求路径 /goumaidekecheng/delete
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
// 处理删除请求,请求体为 ID 数组
public R delete(@RequestBody Long[] ids) {
// 调用服务类的批量删除方法(根据 ID 列表)
goumaidekechengService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<GoumaidekechengEntity> wrapper = new EntityWrapper<GoumaidekechengEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yonghu")) {
wrapper.eq("yonghuzhanghao", (String)request.getSession().getAttribute("username"));
}
int count = goumaidekechengService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
// 映射请求路径 /goumaidekecheng/remind/{columnName}/{type}
@RequestMapping("/remind/{columnName}/{type}")
// 处理提醒统计请求,参数包括列名、类型、查询条件映射
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 向查询条件中添加列名和类型
map.put("column", columnName);
map.put("type", type);
// 如果类型为 2处理日期范围提醒
if (type.equals("2")) {
// 创建日期格式化对象yyyy-MM-dd 格式)
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建日历对象
Calendar c = Calendar.getInstance();
// 提醒开始日期和结束日期变量
Date remindStartDate = null;
Date remindEndDate = null;
// 处理提醒开始时间(相对当前日期偏移)
if (map.get("remindstart") != null) {
// 解析偏移天数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
// 设置日历为当前时间并添加偏移天数
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindStart);
// 获取格式化后的提醒开始日期
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
// 处理提醒结束时间(相对当前日期偏移)
if (map.get("remindend") != null) {
// 解析偏移天数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置日历为当前时间并添加偏移天数
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindEnd);
// 获取格式化后的提醒结束日期
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建包装器用于构建查询条件
Wrapper<GoumaidekechengEntity> wrapper = new EntityWrapper<GoumaidekechengEntity>();
// 添加提醒开始时间的大于等于条件
if (map.get("remindstart") != null) {
wrapper.ge(columnName, map.get("remindstart"));
}
// 添加提醒结束时间的小于等于条件
if (map.get("remindend") != null) {
wrapper.le(columnName, map.get("remindend"));
}
// 根据表名判断是否添加用户账号条件(用户表场景)
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
wrapper.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类统计符合条件的记录数
int count = goumaidekechengService.selectCount(wrapper);
// 返回成功响应,携带统计结果
return R.ok().put("count", count);
}
}

@ -1,206 +1,304 @@
package com.controller;
// 导入用于格式化日期的类
import java.text.SimpleDateFormat;
// 导入用于创建动态数组的类
import java.util.ArrayList;
// 导入用于操作数组的工具类
import java.util.Arrays;
// 导入用于处理日期和时间的类
import java.util.Calendar;
// 导入用于存储键值对的接口
import java.util.Map;
// 导入HashMap类用于实现Map接口
import java.util.HashMap;
// 导入用于遍历集合的接口
import java.util.Iterator;
// 导入用于表示日期和时间的类
import java.util.Date;
// 导入用于创建列表的接口
import java.util.List;
// 导入用于处理HTTP请求的类
import javax.servlet.http.HttpServletRequest;
// 导入自定义的验证工具类
import com.utils.ValidatorUtils;
// 导入Apache Commons Lang库中的字符串处理工具类
import org.apache.commons.lang3.StringUtils;
// 导入Spring框架的自动注入注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入Spring框架的日期格式化注解
import org.springframework.format.annotation.DateTimeFormat;
// 导入Spring框架的路径变量注解
import org.springframework.web.bind.annotation.PathVariable;
// 导入Spring框架的请求体注解
import org.springframework.web.bind.annotation.RequestBody;
// 导入Spring框架的请求映射注解
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
// 导入Spring框架的REST控制器注解
import org.springframework.web.bind.annotation.RestController;
// 导入MyBatis-Plus的实体包装器类
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入MyBatis-Plus的包装器接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解
import com.annotation.IgnoreAuth;
// 导入课程类型实体类
import com.entity.KechengleixingEntity;
// 导入课程类型视图类
import com.entity.view.KechengleixingView;
// 导入课程类型服务类
import com.service.KechengleixingService;
// 导入令牌服务类
import com.service.TokenService;
// 导入分页工具类
import com.utils.PageUtils;
// 导入自定义的响应类
import com.utils.R;
// 导入MD5加密工具类
import com.utils.MD5Util;
// 导入MyBatis-Plus工具类
import com.utils.MPUtil;
// 导入通用工具类
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:14
*/
// 声明为REST控制器用于处理HTTP请求
@RestController
// 映射请求路径,所有以/kechengleixing开头的请求由该控制器处理
@RequestMapping("/kechengleixing")
public class KechengleixingController {
// 自动注入课程类型服务类实例
@Autowired
private KechengleixingService kechengleixingService;
/**
*
*
*/
// 映射请求路径/kechengleixing/page
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,KechengleixingEntity kechengleixing,
HttpServletRequest request){
// 处理后端分页查询请求参数包括查询条件、实体对象、HTTP请求
public R page(@RequestParam Map<String, Object> params, KechengleixingEntity kechengleixing,
HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<KechengleixingEntity> ew = new EntityWrapper<KechengleixingEntity>();
PageUtils page = kechengleixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, kechengleixing), params), params));
// 调用服务类的分页查询方法,包含排序、范围查询、模糊查询处理
PageUtils page = kechengleixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, kechengleixing), params), params));
// 返回成功响应,携带分页数据
return R.ok().put("data", page);
}
/**
*
*
*/
// 映射请求路径/kechengleixing/list
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,KechengleixingEntity kechengleixing,
HttpServletRequest request){
// 处理前端分页查询请求参数包括查询条件、实体对象、HTTP请求
public R list(@RequestParam Map<String, Object> params, KechengleixingEntity kechengleixing,
HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<KechengleixingEntity> ew = new EntityWrapper<KechengleixingEntity>();
PageUtils page = kechengleixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, kechengleixing), params), params));
// 调用服务类的分页查询方法,包含排序、范围查询、模糊查询处理
PageUtils page = kechengleixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, kechengleixing), params), params));
// 返回成功响应,携带分页数据
return R.ok().put("data", page);
}
/**
*
/**
*
*/
// 映射请求路径/kechengleixing/lists测试用接口
@RequestMapping("/lists")
public R list( KechengleixingEntity kechengleixing){
EntityWrapper<KechengleixingEntity> ew = new EntityWrapper<KechengleixingEntity>();
ew.allEq(MPUtil.allEQMapPre( kechengleixing, "kechengleixing"));
// 处理全量查询请求,参数为实体对象
public R list(KechengleixingEntity kechengleixing) {
// 创建实体包装器
EntityWrapper<KechengleixingEntity> ew = new EntityWrapper<KechengleixingEntity>();
// 设置查询条件:所有字段与实体对象相等(前缀为"kechengleixing"
ew.allEq(MPUtil.allEQMapPre(kechengleixing, "kechengleixing"));
// 返回成功响应,携带查询结果(视图列表)
return R.ok().put("data", kechengleixingService.selectListView(ew));
}
/**
*
/**
*
*/
// 映射请求路径/kechengleixing/query
@RequestMapping("/query")
public R query(KechengleixingEntity kechengleixing){
EntityWrapper< KechengleixingEntity> ew = new EntityWrapper< KechengleixingEntity>();
ew.allEq(MPUtil.allEQMapPre( kechengleixing, "kechengleixing"));
KechengleixingView kechengleixingView = kechengleixingService.selectView(ew);
return R.ok("查询课程类型成功").put("data", kechengleixingView);
// 处理单个对象查询请求,参数为实体对象
public R query(KechengleixingEntity kechengleixing) {
// 创建实体包装器
EntityWrapper<KechengleixingEntity> ew = new EntityWrapper<KechengleixingEntity>();
// 设置查询条件:所有字段与实体对象相等(前缀为"kechengleixing"
ew.allEq(MPUtil.allEQMapPre(kechengleixing, "kechengleixing"));
// 调用服务类的视图查询方法
KechengleixingView kechengleixingView = kechengleixingService.selectView(ew);
// 返回成功响应,携带查询结果和提示信息
return R.ok("查询课程类型成功").put("data", kechengleixingView);
}
/**
*
* ID
*/
// 映射请求路径/kechengleixing/info/{id}
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
// 处理详情查询请求参数为路径中的ID
public R info(@PathVariable("id") Long id) {
// 根据ID直接查询实体对象
KechengleixingEntity kechengleixing = kechengleixingService.selectById(id);
// 返回成功响应,携带查询到的实体数据
return R.ok().put("data", kechengleixing);
}
/**
*
* ID
*/
// 映射请求路径/kechengleixing/detail/{id}
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
// 处理详情查询请求参数为路径中的ID前端调用
public R detail(@PathVariable("id") Long id) {
// 根据ID直接查询实体对象
KechengleixingEntity kechengleixing = kechengleixingService.selectById(id);
// 返回成功响应,携带查询到的实体数据
return R.ok().put("data", kechengleixing);
}
/**
*
*
*/
// 映射请求路径/kechengleixing/save
@RequestMapping("/save")
public R save(@RequestBody KechengleixingEntity kechengleixing, HttpServletRequest request){
kechengleixing.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(kechengleixing);
// 处理后端新增请求请求体为实体对象携带HTTP请求
public R save(@RequestBody KechengleixingEntity kechengleixing, HttpServletRequest request) {
// 生成唯一ID时间戳 + 随机数)
kechengleixing.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 实体验证(注释,未启用)
//ValidatorUtils.validateEntity(kechengleixing);
// 调用服务类的插入方法
kechengleixingService.insert(kechengleixing);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射请求路径/kechengleixing/add
@RequestMapping("/add")
public R add(@RequestBody KechengleixingEntity kechengleixing, HttpServletRequest request){
kechengleixing.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(kechengleixing);
// 处理前端新增请求请求体为实体对象携带HTTP请求
public R add(@RequestBody KechengleixingEntity kechengleixing, HttpServletRequest request) {
// 生成唯一ID时间戳 + 随机数)
kechengleixing.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 实体验证(注释,未启用)
//ValidatorUtils.validateEntity(kechengleixing);
// 调用服务类的插入方法
kechengleixingService.insert(kechengleixing);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射请求路径/kechengleixing/update
@RequestMapping("/update")
public R update(@RequestBody KechengleixingEntity kechengleixing, HttpServletRequest request){
// 处理修改请求请求体为实体对象携带HTTP请求
public R update(@RequestBody KechengleixingEntity kechengleixing, HttpServletRequest request) {
// 实体验证(注释,未启用)
//ValidatorUtils.validateEntity(kechengleixing);
kechengleixingService.updateById(kechengleixing);//全部更新
// 调用服务类的更新方法根据ID全量更新
kechengleixingService.updateById(kechengleixing); // 全部更新
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射请求路径/kechengleixing/delete
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
// 处理删除请求请求体为ID数组
public R delete(@RequestBody Long[] ids) {
// 调用服务类的批量删除方法根据ID列表
kechengleixingService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<KechengleixingEntity> wrapper = new EntityWrapper<KechengleixingEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = kechengleixingService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
// 映射请求路径/kechengleixing/remind/{columnName}/{type}
@RequestMapping("/remind/{columnName}/{type}")
// 处理提醒统计请求,参数包括列名、类型、查询条件映射
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 向查询条件中添加列名和类型
map.put("column", columnName);
map.put("type", type);
// 如果类型为2处理日期范围提醒
if (type.equals("2")) {
// 创建日期格式化对象yyyy-MM-dd格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建日历对象
Calendar c = Calendar.getInstance();
// 提醒开始日期和结束日期变量
Date remindStartDate = null;
Date remindEndDate = null;
// 处理提醒开始时间(相对当前日期偏移)
if (map.get("remindstart") != null) {
// 解析偏移天数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
// 设置日历为当前时间并添加偏移天数
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindStart);
// 获取格式化后的提醒开始日期
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
// 处理提醒结束时间(相对当前日期偏移)
if (map.get("remindend") != null) {
// 解析偏移天数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置日历为当前时间并添加偏移天数
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindEnd);
// 获取格式化后的提醒结束日期
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建包装器用于构建查询条件
Wrapper<KechengleixingEntity> wrapper = new EntityWrapper<KechengleixingEntity>();
// 添加提醒开始时间的大于等于条件
if (map.get("remindstart") != null) {
wrapper.ge(columnName, map.get("remindstart"));
}
// 添加提醒结束时间的小于等于条件
if (map.get("remindend") != null) {
wrapper.le(columnName, map.get("remindend"));
}
// 调用服务类统计符合条件的记录数
int count = kechengleixingService.selectCount(wrapper);
// 返回成功响应,携带统计结果
return R.ok().put("count", count);
}
}

@ -1,208 +1,313 @@
// 声明该类所在的包
package com.controller;
// 导入用于格式化日期的类
import java.text.SimpleDateFormat;
// 导入用于创建动态数组的类
import java.util.ArrayList;
// 导入用于操作数组的工具类
import java.util.Arrays;
// 导入用于处理日期和时间的类
import java.util.Calendar;
// 导入用于存储键值对的接口
import java.util.Map;
// 导入用于实现 Map 接口的 HashMap 类
import java.util.HashMap;
// 导入用于遍历集合的接口
import java.util.Iterator;
// 导入用于表示日期和时间的类
import java.util.Date;
// 导入用于创建列表的接口
import java.util.List;
// 导入用于处理 HTTP 请求的类
import javax.servlet.http.HttpServletRequest;
// 导入自定义的验证工具类
import com.utils.ValidatorUtils;
// 导入 Apache Commons Lang 库中的字符串处理工具类
import org.apache.commons.lang3.StringUtils;
// 导入 Spring 框架的自动注入注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入 Spring 框架的日期格式化注解
import org.springframework.format.annotation.DateTimeFormat;
// 导入 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;
// 导入 MyBatis-Plus 的实体包装器类
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入 MyBatis-Plus 的包装器接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解
import com.annotation.IgnoreAuth;
// 导入课程信息实体类
import com.entity.KechengxinxiEntity;
// 导入课程信息视图类
import com.entity.view.KechengxinxiView;
// 导入课程信息服务类
import com.service.KechengxinxiService;
// 导入令牌服务类
import com.service.TokenService;
// 导入分页工具类
import com.utils.PageUtils;
// 导入自定义的响应类
import com.utils.R;
// 导入 MD5 加密工具类
import com.utils.MD5Util;
// 导入 MyBatis-Plus 工具类
import com.utils.MPUtil;
// 导入通用工具类
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:14
*/
// 声明该类为 REST 控制器,用于处理 HTTP 请求
@RestController
// 映射请求路径,所有以 /kechengxinxi 开头的请求都会由该控制器处理
@RequestMapping("/kechengxinxi")
public class KechengxinxiController {
// 自动注入课程信息服务类的实例
@Autowired
private KechengxinxiService kechengxinxiService;
/**
*
*/
// 映射请求路径 /kechengxinxi/page
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,KechengxinxiEntity kechengxinxi,
HttpServletRequest request){
// 处理后端分页查询课程信息列表的请求
public R page(@RequestParam Map<String, Object> params, KechengxinxiEntity kechengxinxi,
HttpServletRequest request) {
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<KechengxinxiEntity> ew = new EntityWrapper<KechengxinxiEntity>();
PageUtils page = kechengxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, kechengxinxi), params), params));
// 调用课程信息服务类的查询分页方法,进行排序、范围和模糊查询
PageUtils page = kechengxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, kechengxinxi), params), params));
// 返回成功响应,并将分页数据放入响应中
return R.ok().put("data", page);
}
/**
*
*/
@IgnoreAuth
// 该接口忽略认证
@IgnoreAuth
// 映射请求路径 /kechengxinxi/list
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,KechengxinxiEntity kechengxinxi,
HttpServletRequest request){
// 处理前端分页查询课程信息列表的请求
public R list(@RequestParam Map<String, Object> params, KechengxinxiEntity kechengxinxi,
HttpServletRequest request) {
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<KechengxinxiEntity> ew = new EntityWrapper<KechengxinxiEntity>();
PageUtils page = kechengxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, kechengxinxi), params), params));
// 调用课程信息服务类的查询分页方法,进行排序、范围和模糊查询
PageUtils page = kechengxinxiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, kechengxinxi), params), params));
// 返回成功响应,并将分页数据放入响应中
return R.ok().put("data", page);
}
/**
/**
*
*/
// 映射请求路径 /kechengxinxi/lists
@RequestMapping("/lists")
public R list( KechengxinxiEntity kechengxinxi){
EntityWrapper<KechengxinxiEntity> ew = new EntityWrapper<KechengxinxiEntity>();
ew.allEq(MPUtil.allEQMapPre( kechengxinxi, "kechengxinxi"));
// 处理查询课程信息列表的请求
public R list(KechengxinxiEntity kechengxinxi) {
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<KechengxinxiEntity> ew = new EntityWrapper<KechengxinxiEntity>();
// 设置查询条件,所有字段相等
ew.allEq(MPUtil.allEQMapPre(kechengxinxi, "kechengxinxi"));
// 返回成功响应,并将查询结果(视图列表)放入响应中
return R.ok().put("data", kechengxinxiService.selectListView(ew));
}
/**
/**
*
*/
// 映射请求路径 /kechengxinxi/query
@RequestMapping("/query")
public R query(KechengxinxiEntity kechengxinxi){
EntityWrapper< KechengxinxiEntity> ew = new EntityWrapper< KechengxinxiEntity>();
ew.allEq(MPUtil.allEQMapPre( kechengxinxi, "kechengxinxi"));
KechengxinxiView kechengxinxiView = kechengxinxiService.selectView(ew);
return R.ok("查询课程信息成功").put("data", kechengxinxiView);
// 处理查询课程信息的请求
public R query(KechengxinxiEntity kechengxinxi) {
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<KechengxinxiEntity> ew = new EntityWrapper<KechengxinxiEntity>();
// 设置查询条件,所有字段相等
ew.allEq(MPUtil.allEQMapPre(kechengxinxi, "kechengxinxi"));
// 调用课程信息服务类的查询视图方法
KechengxinxiView kechengxinxiView = kechengxinxiService.selectView(ew);
// 返回成功响应,并将查询结果放入响应中,附带成功提示信息
return R.ok("查询课程信息成功").put("data", kechengxinxiView);
}
/**
*
*/
// 映射请求路径 /kechengxinxi/info/{id}
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
// 处理后端查询课程信息详情的请求
public R info(@PathVariable("id") Long id) {
// 根据 ID 查询课程信息实体
KechengxinxiEntity kechengxinxi = kechengxinxiService.selectById(id);
// 返回成功响应,并将查询结果放入响应中
return R.ok().put("data", kechengxinxi);
}
/**
*
*/
// 映射请求路径 /kechengxinxi/detail/{id}
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
// 处理前端查询课程信息详情的请求
public R detail(@PathVariable("id") Long id) {
// 根据 ID 查询课程信息实体
KechengxinxiEntity kechengxinxi = kechengxinxiService.selectById(id);
// 返回成功响应,并将查询结果放入响应中
return R.ok().put("data", kechengxinxi);
}
/**
*
*/
// 映射请求路径 /kechengxinxi/save
@RequestMapping("/save")
public R save(@RequestBody KechengxinxiEntity kechengxinxi, HttpServletRequest request){
kechengxinxi.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(kechengxinxi);
// 处理后端保存课程信息的请求
public R save(@RequestBody KechengxinxiEntity kechengxinxi, HttpServletRequest request) {
// 生成一个唯一的 ID
kechengxinxi.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 验证实体(注释掉,未启用)
//ValidatorUtils.validateEntity(kechengxinxi);
// 调用课程信息服务类的插入方法
kechengxinxiService.insert(kechengxinxi);
// 返回成功响应
return R.ok();
}
/**
*
*/
@IgnoreAuth
// 该接口忽略认证
@IgnoreAuth
// 映射请求路径 /kechengxinxi/add
@RequestMapping("/add")
public R add(@RequestBody KechengxinxiEntity kechengxinxi, HttpServletRequest request){
kechengxinxi.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(kechengxinxi);
// 处理前端保存课程信息的请求
public R add(@RequestBody KechengxinxiEntity kechengxinxi, HttpServletRequest request) {
// 生成一个唯一的 ID
kechengxinxi.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 验证实体(注释掉,未启用)
//ValidatorUtils.validateEntity(kechengxinxi);
// 调用课程信息服务类的插入方法
kechengxinxiService.insert(kechengxinxi);
// 返回成功响应
return R.ok();
}
/**
*
*/
// 映射请求路径 /kechengxinxi/update
@RequestMapping("/update")
public R update(@RequestBody KechengxinxiEntity kechengxinxi, HttpServletRequest request){
// 处理修改课程信息的请求
public R update(@RequestBody KechengxinxiEntity kechengxinxi, HttpServletRequest request) {
// 验证实体(注释掉,未启用)
//ValidatorUtils.validateEntity(kechengxinxi);
kechengxinxiService.updateById(kechengxinxi);//全部更新
// 调用课程信息服务类的更新方法,更新所有字段
kechengxinxiService.updateById(kechengxinxi); // 全部更新
// 返回成功响应
return R.ok();
}
/**
*
*/
// 映射请求路径 /kechengxinxi/delete
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
// 处理删除课程信息的请求
public R delete(@RequestBody Long[] ids) {
// 调用课程信息服务类的批量删除方法
kechengxinxiService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<KechengxinxiEntity> wrapper = new EntityWrapper<KechengxinxiEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = kechengxinxiService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
// 映射请求路径 /kechengxinxi/remind/{columnName}/{type}
@RequestMapping("/remind/{columnName}/{type}")
// 处理提醒统计的请求
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 将列名放入参数映射中
map.put("column", columnName);
// 将类型放入参数映射中
map.put("type", type);
// 如果类型为 2
if (type.equals("2")) {
// 创建一个日期格式化对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建一个日历对象
Calendar c = Calendar.getInstance();
// 提醒开始日期
Date remindStartDate = null;
// 提醒结束日期
Date remindEndDate = null;
// 如果提醒开始参数不为空
if (map.get("remindstart") != null) {
// 将提醒开始参数转换为整数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
// 设置日历时间为当前时间
c.setTime(new Date());
// 在当前日期上加上提醒开始天数
c.add(Calendar.DAY_OF_MONTH, remindStart);
// 获取提醒开始日期
remindStartDate = c.getTime();
// 将提醒开始日期格式化后放入参数映射中
map.put("remindstart", sdf.format(remindStartDate));
}
// 如果提醒结束参数不为空
if (map.get("remindend") != null) {
// 将提醒结束参数转换为整数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置日历时间为当前时间
c.setTime(new Date());
// 在当前日期上加上提醒结束天数
c.add(Calendar.DAY_OF_MONTH, remindEnd);
// 获取提醒结束日期
remindEndDate = c.getTime();
// 将提醒结束日期格式化后放入参数映射中
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建一个实体包装器,用于构建查询条件
Wrapper<KechengxinxiEntity> wrapper = new EntityWrapper<KechengxinxiEntity>();
// 如果提醒开始参数不为空
if (map.get("remindstart") != null) {
// 设置查询条件,列名大于等于提醒开始日期
wrapper.ge(columnName, map.get("remindstart"));
}
// 如果提醒结束参数不为空
if (map.get("remindend") != null) {
// 设置查询条件,列名小于等于提醒结束日期
wrapper.le(columnName, map.get("remindend"));
}
// 调用课程信息服务类的统计方法,统计符合条件的记录数
int count = kechengxinxiService.selectCount(wrapper);
// 返回成功响应,并将统计结果放入响应中
return R.ok().put("count", count);
}
}

@ -1,213 +1,316 @@
package com.controller;
// 导入用于格式化日期的类
import java.text.SimpleDateFormat;
// 导入用于创建动态数组的类
import java.util.ArrayList;
// 导入用于操作数组的工具类
import java.util.Arrays;
// 导入用于处理日期和时间的类
import java.util.Calendar;
// 导入用于存储键值对的接口
import java.util.Map;
// 导入用于实现Map接口的HashMap类
import java.util.HashMap;
// 导入用于遍历集合的接口
import java.util.Iterator;
// 导入用于表示日期和时间的类
import java.util.Date;
// 导入用于创建列表的接口
import java.util.List;
// 导入用于处理HTTP请求的类
import javax.servlet.http.HttpServletRequest;
// 导入自定义的验证工具类
import com.utils.ValidatorUtils;
// 导入Apache Commons Lang库中的字符串处理工具类
import org.apache.commons.lang3.StringUtils;
// 导入Spring框架的自动注入注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入Spring框架的日期格式化注解
import org.springframework.format.annotation.DateTimeFormat;
// 导入Spring框架的路径变量注解
import org.springframework.web.bind.annotation.PathVariable;
// 导入Spring框架的请求体注解
import org.springframework.web.bind.annotation.RequestBody;
// 导入Spring框架的请求映射注解
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
// 导入Spring框架的REST控制器注解
import org.springframework.web.bind.annotation.RestController;
// 导入MyBatis-Plus的实体包装器类
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入MyBatis-Plus的包装器接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解
import com.annotation.IgnoreAuth;
// 导入留言板实体类
import com.entity.MessagesEntity;
// 导入留言板视图类
import com.entity.view.MessagesView;
// 导入留言板服务类
import com.service.MessagesService;
// 导入令牌服务类
import com.service.TokenService;
// 导入分页工具类
import com.utils.PageUtils;
// 导入自定义的响应类
import com.utils.R;
// 导入MD5加密工具类
import com.utils.MD5Util;
// 导入MyBatis-Plus工具类
import com.utils.MPUtil;
// 导入通用工具类
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:15
*/
// 声明为REST控制器用于处理HTTP请求
@RestController
// 映射请求路径,所有以/messages开头的请求由该控制器处理
@RequestMapping("/messages")
public class MessagesController {
// 自动注入留言板服务类实例
@Autowired
private MessagesService messagesService;
/**
*
*
*/
// 映射请求路径/messages/page
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,MessagesEntity messages,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
messages.setUserid((Long)request.getSession().getAttribute("userId"));
}
// 处理后端分页查询请求参数包括查询条件、实体对象、HTTP请求
public R page(@RequestParam Map<String, Object> params, MessagesEntity messages,
HttpServletRequest request) {
// 如果当前用户不是管理员
if (!request.getSession().getAttribute("role").toString().equals("管理员")) {
// 设置留言的用户ID为当前登录用户的ID
messages.setUserid((Long) request.getSession().getAttribute("userId"));
}
// 创建实体包装器,用于构建查询条件
EntityWrapper<MessagesEntity> ew = new EntityWrapper<MessagesEntity>();
PageUtils page = messagesService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, messages), params), params));
// 调用服务类的分页查询方法,包含排序、范围查询、模糊查询处理
PageUtils page = messagesService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, messages), params), params));
// 返回成功响应,携带分页数据
return R.ok().put("data", page);
}
/**
*
*
*/
// 映射请求路径/messages/list
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,MessagesEntity messages,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
messages.setUserid((Long)request.getSession().getAttribute("userId"));
}
// 处理前端分页查询请求参数包括查询条件、实体对象、HTTP请求
public R list(@RequestParam Map<String, Object> params, MessagesEntity messages,
HttpServletRequest request) {
// 如果当前用户不是管理员
if (!request.getSession().getAttribute("role").toString().equals("管理员")) {
// 设置留言的用户ID为当前登录用户的ID
messages.setUserid((Long) request.getSession().getAttribute("userId"));
}
// 创建实体包装器,用于构建查询条件
EntityWrapper<MessagesEntity> ew = new EntityWrapper<MessagesEntity>();
PageUtils page = messagesService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, messages), params), params));
// 调用服务类的分页查询方法,包含排序、范围查询、模糊查询处理
PageUtils page = messagesService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, messages), params), params));
// 返回成功响应,携带分页数据
return R.ok().put("data", page);
}
/**
*
/**
*
*/
// 映射请求路径/messages/lists
@RequestMapping("/lists")
public R list( MessagesEntity messages){
EntityWrapper<MessagesEntity> ew = new EntityWrapper<MessagesEntity>();
ew.allEq(MPUtil.allEQMapPre( messages, "messages"));
// 处理全量查询请求,参数为实体对象
public R list(MessagesEntity messages) {
// 创建实体包装器
EntityWrapper<MessagesEntity> ew = new EntityWrapper<MessagesEntity>();
// 设置查询条件:所有字段与实体对象相等(前缀为"messages"
ew.allEq(MPUtil.allEQMapPre(messages, "messages"));
// 返回成功响应,携带查询结果(视图列表)
return R.ok().put("data", messagesService.selectListView(ew));
}
/**
*
/**
*
*/
// 映射请求路径/messages/query
@RequestMapping("/query")
public R query(MessagesEntity messages){
EntityWrapper< MessagesEntity> ew = new EntityWrapper< MessagesEntity>();
ew.allEq(MPUtil.allEQMapPre( messages, "messages"));
MessagesView messagesView = messagesService.selectView(ew);
return R.ok("查询留言板成功").put("data", messagesView);
// 处理单个对象查询请求,参数为实体对象
public R query(MessagesEntity messages) {
// 创建实体包装器
EntityWrapper<MessagesEntity> ew = new EntityWrapper<MessagesEntity>();
// 设置查询条件:所有字段与实体对象相等(前缀为"messages"
ew.allEq(MPUtil.allEQMapPre(messages, "messages"));
// 调用服务类的视图查询方法
MessagesView messagesView = messagesService.selectView(ew);
// 返回成功响应,携带查询结果和提示信息
return R.ok("查询留言板成功").put("data", messagesView);
}
/**
*
* ID
*/
// 映射请求路径/messages/info/{id}
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
// 处理详情查询请求参数为路径中的ID
public R info(@PathVariable("id") Long id) {
// 根据ID直接查询实体对象
MessagesEntity messages = messagesService.selectById(id);
// 返回成功响应,携带查询到的实体数据
return R.ok().put("data", messages);
}
/**
*
* ID
*/
// 映射请求路径/messages/detail/{id}
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
// 处理详情查询请求参数为路径中的ID前端调用
public R detail(@PathVariable("id") Long id) {
// 根据ID直接查询实体对象
MessagesEntity messages = messagesService.selectById(id);
// 返回成功响应,携带查询到的实体数据
return R.ok().put("data", messages);
}
/**
*
*
*/
// 映射请求路径/messages/save
@RequestMapping("/save")
public R save(@RequestBody MessagesEntity messages, HttpServletRequest request){
messages.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(messages);
// 处理后端新增请求请求体为实体对象携带HTTP请求
public R save(@RequestBody MessagesEntity messages, HttpServletRequest request) {
// 生成唯一ID时间戳 + 随机数)
messages.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 实体验证(注释,未启用)
//ValidatorUtils.validateEntity(messages);
// 调用服务类的插入方法
messagesService.insert(messages);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射请求路径/messages/add
@RequestMapping("/add")
public R add(@RequestBody MessagesEntity messages, HttpServletRequest request){
messages.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(messages);
messages.setUserid((Long)request.getSession().getAttribute("userId"));
// 处理前端新增请求请求体为实体对象携带HTTP请求
public R add(@RequestBody MessagesEntity messages, HttpServletRequest request) {
// 生成唯一ID时间戳 + 随机数)
messages.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 实体验证(注释,未启用)
//ValidatorUtils.validateEntity(messages);
// 设置留言的用户ID为当前登录用户的ID
messages.setUserid((Long) request.getSession().getAttribute("userId"));
// 调用服务类的插入方法
messagesService.insert(messages);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射请求路径/messages/update
@RequestMapping("/update")
public R update(@RequestBody MessagesEntity messages, HttpServletRequest request){
// 处理修改请求请求体为实体对象携带HTTP请求
public R update(@RequestBody MessagesEntity messages, HttpServletRequest request) {
// 实体验证(注释,未启用)
//ValidatorUtils.validateEntity(messages);
messagesService.updateById(messages);//全部更新
// 调用服务类的更新方法根据ID全量更新
messagesService.updateById(messages); // 全部更新
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射请求路径/messages/delete
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
// 处理删除请求请求体为ID数组
public R delete(@RequestBody Long[] ids) {
// 调用服务类的批量删除方法根据ID列表
messagesService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<MessagesEntity> wrapper = new EntityWrapper<MessagesEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = messagesService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
// 映射请求路径/messages/remind/{columnName}/{type}
@RequestMapping("/remind/{columnName}/{type}")
// 处理提醒统计请求,参数包括列名、类型、查询条件映射
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 向查询条件中添加列名和类型
map.put("column", columnName);
map.put("type", type);
// 如果类型为2处理日期范围提醒
if (type.equals("2")) {
// 创建日期格式化对象yyyy-MM-dd格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建日历对象
Calendar c = Calendar.getInstance();
// 提醒开始日期和结束日期变量
Date remindStartDate = null;
Date remindEndDate = null;
// 处理提醒开始时间(相对当前日期偏移)
if (map.get("remindstart") != null) {
// 解析偏移天数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
// 设置日历为当前时间并添加偏移天数
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindStart);
// 获取格式化后的提醒开始日期
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
// 处理提醒结束时间(相对当前日期偏移)
if (map.get("remindend") != null) {
// 解析偏移天数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置日历为当前时间并添加偏移天数
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindEnd);
// 获取格式化后的提醒结束日期
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建包装器用于构建查询条件
Wrapper<MessagesEntity> wrapper = new EntityWrapper<MessagesEntity>();
// 添加提醒开始时间的大于等于条件
if (map.get("remindstart") != null) {
wrapper.ge(columnName, map.get("remindstart"));
}
// 添加提醒结束时间的小于等于条件
if (map.get("remindend") != null) {
wrapper.le(columnName, map.get("remindend"));
}
// 调用服务类统计符合条件的记录数
int count = messagesService.selectCount(wrapper);
// 返回成功响应,携带统计结果
return R.ok().put("count", count);
}
}

@ -1,208 +1,308 @@
package com.controller;
// 导入用于格式化日期的类
import java.text.SimpleDateFormat;
// 导入用于创建动态数组的类
import java.util.ArrayList;
// 导入用于操作数组的工具类
import java.util.Arrays;
// 导入用于处理日期和时间的类
import java.util.Calendar;
// 导入用于存储键值对的接口
import java.util.Map;
// 导入用于实现Map接口的HashMap类
import java.util.HashMap;
// 导入用于遍历集合的接口
import java.util.Iterator;
// 导入用于表示日期和时间的类
import java.util.Date;
// 导入用于创建列表的接口
import java.util.List;
// 导入用于处理HTTP请求的类
import javax.servlet.http.HttpServletRequest;
// 导入自定义的验证工具类
import com.utils.ValidatorUtils;
// 导入Apache Commons Lang库中的字符串处理工具类
import org.apache.commons.lang3.StringUtils;
// 导入Spring框架的自动注入注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入Spring框架的日期格式化注解
import org.springframework.format.annotation.DateTimeFormat;
// 导入Spring框架的路径变量注解
import org.springframework.web.bind.annotation.PathVariable;
// 导入Spring框架的请求体注解
import org.springframework.web.bind.annotation.RequestBody;
// 导入Spring框架的请求映射注解
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
// 导入Spring框架的REST控制器注解
import org.springframework.web.bind.annotation.RestController;
// 导入MyBatis-Plus的实体包装器类
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入MyBatis-Plus的包装器接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解
import com.annotation.IgnoreAuth;
// 导入教育资讯实体类
import com.entity.NewsEntity;
// 导入教育资讯视图类
import com.entity.view.NewsView;
// 导入教育资讯服务类
import com.service.NewsService;
// 导入令牌服务类
import com.service.TokenService;
// 导入分页工具类
import com.utils.PageUtils;
// 导入自定义的响应类
import com.utils.R;
// 导入MD5加密工具类
import com.utils.MD5Util;
// 导入MyBatis-Plus工具类
import com.utils.MPUtil;
// 导入通用工具类
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:15
*/
// 声明为REST控制器用于处理HTTP请求
@RestController
// 映射请求路径,所有以/news开头的请求由该控制器处理
@RequestMapping("/news")
public class NewsController {
// 自动注入教育资讯服务类实例
@Autowired
private NewsService newsService;
/**
*
*
*/
// 映射请求路径/news/page
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,NewsEntity news,
HttpServletRequest request){
// 处理后端分页查询请求参数包括查询条件、实体对象、HTTP请求
public R page(@RequestParam Map<String, Object> params, NewsEntity news,
HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<NewsEntity> ew = new EntityWrapper<NewsEntity>();
PageUtils page = newsService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, news), params), params));
// 调用服务类的分页查询方法,包含排序、范围查询、模糊查询处理
PageUtils page = newsService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, news), params), params));
// 返回成功响应,携带分页数据
return R.ok().put("data", page);
}
/**
*
*
*/
@IgnoreAuth
// 该接口忽略认证
@IgnoreAuth
// 映射请求路径/news/list
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,NewsEntity news,
HttpServletRequest request){
// 处理前端分页查询请求参数包括查询条件、实体对象、HTTP请求
public R list(@RequestParam Map<String, Object> params, NewsEntity news,
HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<NewsEntity> ew = new EntityWrapper<NewsEntity>();
PageUtils page = newsService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, news), params), params));
// 调用服务类的分页查询方法,包含排序、范围查询、模糊查询处理
PageUtils page = newsService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, news), params), params));
// 返回成功响应,携带分页数据
return R.ok().put("data", page);
}
/**
*
/**
*
*/
// 映射请求路径/news/lists
@RequestMapping("/lists")
public R list( NewsEntity news){
EntityWrapper<NewsEntity> ew = new EntityWrapper<NewsEntity>();
ew.allEq(MPUtil.allEQMapPre( news, "news"));
// 处理全量查询请求,参数为实体对象
public R list(NewsEntity news) {
// 创建实体包装器
EntityWrapper<NewsEntity> ew = new EntityWrapper<NewsEntity>();
// 设置查询条件:所有字段与实体对象相等(前缀为"news"
ew.allEq(MPUtil.allEQMapPre(news, "news"));
// 返回成功响应,携带查询结果(视图列表)
return R.ok().put("data", newsService.selectListView(ew));
}
/**
*
/**
*
*/
// 映射请求路径/news/query
@RequestMapping("/query")
public R query(NewsEntity news){
EntityWrapper< NewsEntity> ew = new EntityWrapper< NewsEntity>();
ew.allEq(MPUtil.allEQMapPre( news, "news"));
NewsView newsView = newsService.selectView(ew);
return R.ok("查询教育资讯成功").put("data", newsView);
// 处理单个对象查询请求,参数为实体对象
public R query(NewsEntity news) {
// 创建实体包装器
EntityWrapper<NewsEntity> ew = new EntityWrapper<NewsEntity>();
// 设置查询条件:所有字段与实体对象相等(前缀为"news"
ew.allEq(MPUtil.allEQMapPre(news, "news"));
// 调用服务类的视图查询方法
NewsView newsView = newsService.selectView(ew);
// 返回成功响应,携带查询结果和提示信息
return R.ok("查询教育资讯成功").put("data", newsView);
}
/**
*
* ID
*/
// 映射请求路径/news/info/{id}
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
// 处理详情查询请求参数为路径中的ID
public R info(@PathVariable("id") Long id) {
// 根据ID直接查询实体对象
NewsEntity news = newsService.selectById(id);
// 返回成功响应,携带查询到的实体数据
return R.ok().put("data", news);
}
/**
*
* ID
*/
@IgnoreAuth
// 该接口忽略认证
@IgnoreAuth
// 映射请求路径/news/detail/{id}
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
// 处理详情查询请求参数为路径中的ID前端调用
public R detail(@PathVariable("id") Long id) {
// 根据ID直接查询实体对象
NewsEntity news = newsService.selectById(id);
// 返回成功响应,携带查询到的实体数据
return R.ok().put("data", news);
}
/**
*
*
*/
// 映射请求路径/news/save
@RequestMapping("/save")
public R save(@RequestBody NewsEntity news, HttpServletRequest request){
news.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(news);
// 处理后端新增请求请求体为实体对象携带HTTP请求
public R save(@RequestBody NewsEntity news, HttpServletRequest request) {
// 生成唯一ID时间戳 + 随机数)
news.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 实体验证(注释,未启用)
//ValidatorUtils.validateEntity(news);
// 调用服务类的插入方法
newsService.insert(news);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射请求路径/news/add
@RequestMapping("/add")
public R add(@RequestBody NewsEntity news, HttpServletRequest request){
news.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(news);
// 处理前端新增请求请求体为实体对象携带HTTP请求
public R add(@RequestBody NewsEntity news, HttpServletRequest request) {
// 生成唯一ID时间戳 + 随机数)
news.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 实体验证(注释,未启用)
//ValidatorUtils.validateEntity(news);
// 调用服务类的插入方法
newsService.insert(news);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射请求路径/news/update
@RequestMapping("/update")
public R update(@RequestBody NewsEntity news, HttpServletRequest request){
// 处理修改请求请求体为实体对象携带HTTP请求
public R update(@RequestBody NewsEntity news, HttpServletRequest request) {
// 实体验证(注释,未启用)
//ValidatorUtils.validateEntity(news);
newsService.updateById(news);//全部更新
// 调用服务类的更新方法根据ID全量更新
newsService.updateById(news); // 全部更新
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射请求路径/news/delete
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
// 处理删除请求请求体为ID数组
public R delete(@RequestBody Long[] ids) {
// 调用服务类的批量删除方法根据ID列表
newsService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<NewsEntity> wrapper = new EntityWrapper<NewsEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = newsService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
// 映射请求路径/news/remind/{columnName}/{type}
@RequestMapping("/remind/{columnName}/{type}")
// 处理提醒统计请求,参数包括列名、类型、查询条件映射
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 向查询条件中添加列名和类型
map.put("column", columnName);
map.put("type", type);
// 如果类型为2处理日期范围提醒
if (type.equals("2")) {
// 创建日期格式化对象yyyy-MM-dd格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建日历对象
Calendar c = Calendar.getInstance();
// 提醒开始日期和结束日期变量
Date remindStartDate = null;
Date remindEndDate = null;
// 处理提醒开始时间(相对当前日期偏移)
if (map.get("remindstart") != null) {
// 解析偏移天数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
// 设置日历为当前时间并添加偏移天数
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindStart);
// 获取格式化后的提醒开始日期
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
// 处理提醒结束时间(相对当前日期偏移)
if (map.get("remindend") != null) {
// 解析偏移天数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置日历为当前时间并添加偏移天数
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindEnd);
// 获取格式化后的提醒结束日期
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建包装器用于构建查询条件
Wrapper<NewsEntity> wrapper = new EntityWrapper<NewsEntity>();
// 添加提醒开始时间的大于等于条件
if (map.get("remindstart") != null) {
wrapper.ge(columnName, map.get("remindstart"));
}
// 添加提醒结束时间的小于等于条件
if (map.get("remindend") != null) {
wrapper.le(columnName, map.get("remindend"));
}
// 调用服务类统计符合条件的记录数
int count = newsService.selectCount(wrapper);
// 返回成功响应,携带统计结果
return R.ok().put("count", count);
}
}

@ -1,219 +1,333 @@
// 声明该类所在的包
package com.controller;
// 导入用于格式化日期的类,可将日期对象按照指定格式转换为字符串
import java.text.SimpleDateFormat;
// 导入用于创建动态数组的类,可根据需要动态调整数组大小
import java.util.ArrayList;
// 导入用于操作数组的工具类,提供了如排序、查找等方法
import java.util.Arrays;
// 导入用于处理日期和时间的类,可进行日期的计算、格式化等操作
import java.util.Calendar;
// 导入用于存储键值对的接口,可通过键快速查找对应的值
import java.util.Map;
// 导入用于实现 Map 接口的 HashMap 类,基于哈希表实现,存储键值对
import java.util.HashMap;
// 导入用于遍历集合的接口,可依次访问集合中的元素
import java.util.Iterator;
// 导入用于表示日期和时间的类,用于处理日期和时间相关操作
import java.util.Date;
// 导入用于创建列表的接口,可存储多个元素并进行操作
import java.util.List;
// 导入用于处理 HTTP 请求的类,封装了 HTTP 请求的相关信息
import javax.servlet.http.HttpServletRequest;
// 导入自定义的验证工具类,用于对实体对象进行验证
import com.utils.ValidatorUtils;
// 导入 Apache Commons Lang 库中的字符串处理工具类,提供了丰富的字符串操作方法
import org.apache.commons.lang3.StringUtils;
// 导入 Spring 框架的自动注入注解,可自动将依赖的对象注入到类中
import org.springframework.beans.factory.annotation.Autowired;
// 导入 Spring 框架的日期格式化注解,用于指定日期参数的格式
import org.springframework.format.annotation.DateTimeFormat;
// 导入 Spring 框架的路径变量注解,用于获取 URL 路径中的变量值
import org.springframework.web.bind.annotation.PathVariable;
// 导入 Spring 框架的请求体注解,用于将请求体中的数据绑定到方法参数上
import org.springframework.web.bind.annotation.RequestBody;
// 导入 Spring 框架的请求映射注解,用于将 HTTP 请求映射到控制器的方法上
import org.springframework.web.bind.annotation.RequestMapping;
// 导入 Spring 框架的请求参数注解,用于获取请求参数的值
import org.springframework.web.bind.annotation.RequestParam;
// 导入 Spring 框架的 REST 控制器注解,表明该类是一个 RESTful 风格的控制器
import org.springframework.web.bind.annotation.RestController;
// 导入 MyBatis-Plus 的实体包装器类,用于构建查询条件
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入 MyBatis-Plus 的包装器接口,是实体包装器的接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解,用于标记某些接口不需要进行认证
import com.annotation.IgnoreAuth;
// 导入视频点播实体类,包含视频点播的相关属性
import com.entity.ShipindianboEntity;
// 导入视频点播视图类,可能用于展示视频点播的相关信息
import com.entity.view.ShipindianboView;
// 导入视频点播服务类,处理视频点播的业务逻辑
import com.service.ShipindianboService;
// 导入令牌服务类,可能用于处理令牌相关业务
import com.service.TokenService;
// 导入分页工具类,用于处理分页查询相关操作
import com.utils.PageUtils;
// 导入自定义的响应类,用于封装接口的返回结果
import com.utils.R;
// 导入 MD5 加密工具类,用于对数据进行 MD5 加密
import com.utils.MD5Util;
// 导入 MyBatis-Plus 工具类,提供一些便捷的操作方法
import com.utils.MPUtil;
// 导入通用工具类,包含一些通用的工具方法
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:14
*/
// 声明该类为 REST 控制器,处理 HTTP 请求并返回 JSON 数据
@RestController
// 映射请求路径,所有以 /shipindianbo 开头的请求都会由该控制器处理
@RequestMapping("/shipindianbo")
public class ShipindianboController {
@Autowired
private ShipindianboService shipindianboService;
// 自动注入视频点播服务类的实例,用于调用服务层的方法
@Autowired
private ShipindianboService shipindianboService;
/**
*
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ShipindianboEntity shipindianbo,
HttpServletRequest request){
/**
*
*/
// 映射请求路径 /shipindianbo/page
@RequestMapping("/page")
// 处理后端分页查询视频点播列表的请求
public R page(@RequestParam Map<String, Object> params, ShipindianboEntity shipindianbo,
HttpServletRequest request) {
// 从会话中获取表名
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yonghu")) {
shipindianbo.setYonghuzhanghao((String)request.getSession().getAttribute("username"));
// 如果表名是 "yonghu"
if (tableName.equals("yonghu")) {
// 设置视频点播实体的用户账号为会话中的用户名
shipindianbo.setYonghuzhanghao((String) request.getSession().getAttribute("username"));
}
EntityWrapper<ShipindianboEntity> ew = new EntityWrapper<ShipindianboEntity>();
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<ShipindianboEntity> ew = new EntityWrapper<ShipindianboEntity>();
// 调用视频点播服务类的查询分页方法,进行排序、范围和模糊查询
PageUtils page = shipindianboService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shipindianbo), params), params));
// 返回成功响应,并将分页数据放入响应中
return R.ok().put("data", page);
}
return R.ok().put("data", page);
}
/**
*
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ShipindianboEntity shipindianbo,
HttpServletRequest request){
/**
*
*/
// 映射请求路径 /shipindianbo/list
@RequestMapping("/list")
// 处理前端分页查询视频点播列表的请求
public R list(@RequestParam Map<String, Object> params, ShipindianboEntity shipindianbo,
HttpServletRequest request) {
// 从会话中获取表名
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yonghu")) {
shipindianbo.setYonghuzhanghao((String)request.getSession().getAttribute("username"));
// 如果表名是 "yonghu"
if (tableName.equals("yonghu")) {
// 设置视频点播实体的用户账号为会话中的用户名
shipindianbo.setYonghuzhanghao((String) request.getSession().getAttribute("username"));
}
EntityWrapper<ShipindianboEntity> ew = new EntityWrapper<ShipindianboEntity>();
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<ShipindianboEntity> ew = new EntityWrapper<ShipindianboEntity>();
// 调用视频点播服务类的查询分页方法,进行排序、范围和模糊查询
PageUtils page = shipindianboService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, shipindianbo), params), params));
return R.ok().put("data", page);
}
// 返回成功响应,并将分页数据放入响应中
return R.ok().put("data", page);
}
/**
*
*/
@RequestMapping("/lists")
public R list( ShipindianboEntity shipindianbo){
EntityWrapper<ShipindianboEntity> ew = new EntityWrapper<ShipindianboEntity>();
ew.allEq(MPUtil.allEQMapPre( shipindianbo, "shipindianbo"));
return R.ok().put("data", shipindianboService.selectListView(ew));
}
/**
*
*/
@RequestMapping("/query")
public R query(ShipindianboEntity shipindianbo){
EntityWrapper< ShipindianboEntity> ew = new EntityWrapper< ShipindianboEntity>();
ew.allEq(MPUtil.allEQMapPre( shipindianbo, "shipindianbo"));
ShipindianboView shipindianboView = shipindianboService.selectView(ew);
*
*/
// 映射请求路径 /shipindianbo/lists
@RequestMapping("/lists")
// 处理查询视频点播列表的请求
public R list(ShipindianboEntity shipindianbo) {
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<ShipindianboEntity> ew = new EntityWrapper<ShipindianboEntity>();
// 设置查询条件,所有字段相等
ew.allEq(MPUtil.allEQMapPre(shipindianbo, "shipindianbo"));
// 返回成功响应,并将查询结果(视图列表)放入响应中
return R.ok().put("data", shipindianboService.selectListView(ew));
}
/**
*
*/
// 映射请求路径 /shipindianbo/query
@RequestMapping("/query")
// 处理查询视频点播的请求
public R query(ShipindianboEntity shipindianbo) {
// 创建一个实体包装器,用于构建查询条件
EntityWrapper<ShipindianboEntity> ew = new EntityWrapper<ShipindianboEntity>();
// 设置查询条件,所有字段相等
ew.allEq(MPUtil.allEQMapPre(shipindianbo, "shipindianbo"));
// 调用视频点播服务类的查询视图方法
ShipindianboView shipindianboView = shipindianboService.selectView(ew);
// 返回成功响应,并将查询结果放入响应中,附带成功提示信息
return R.ok("查询视频点播成功").put("data", shipindianboView);
}
/**
*
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
ShipindianboEntity shipindianbo = shipindianboService.selectById(id);
return R.ok().put("data", shipindianbo);
}
/**
*
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
ShipindianboEntity shipindianbo = shipindianboService.selectById(id);
return R.ok().put("data", shipindianbo);
}
/**
*
*/
@RequestMapping("/save")
public R save(@RequestBody ShipindianboEntity shipindianbo, HttpServletRequest request){
shipindianbo.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(shipindianbo);
shipindianboService.insert(shipindianbo);
return R.ok();
}
/**
*
*/
@RequestMapping("/add")
public R add(@RequestBody ShipindianboEntity shipindianbo, HttpServletRequest request){
shipindianbo.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(shipindianbo);
shipindianbo.setUserid((Long)request.getSession().getAttribute("userId"));
shipindianboService.insert(shipindianbo);
return R.ok();
}
/**
*
*/
@RequestMapping("/update")
public R update(@RequestBody ShipindianboEntity shipindianbo, HttpServletRequest request){
//ValidatorUtils.validateEntity(shipindianbo);
shipindianboService.updateById(shipindianbo);//全部更新
return R.ok();
}
/**
*
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
shipindianboService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
*
*/
}
/**
*
*/
// 映射请求路径 /shipindianbo/info/{id}
@RequestMapping("/info/{id}")
// 处理后端查询视频点播详情的请求
public R info(@PathVariable("id") Long id) {
// 根据 ID 查询视频点播实体
ShipindianboEntity shipindianbo = shipindianboService.selectById(id);
// 返回成功响应,并将查询结果放入响应中
return R.ok().put("data", shipindianbo);
}
/**
*
*/
// 映射请求路径 /shipindianbo/detail/{id}
@RequestMapping("/detail/{id}")
// 处理前端查询视频点播详情的请求
public R detail(@PathVariable("id") Long id) {
// 根据 ID 查询视频点播实体
ShipindianboEntity shipindianbo = shipindianboService.selectById(id);
// 返回成功响应,并将查询结果放入响应中
return R.ok().put("data", shipindianbo);
}
/**
*
*/
// 映射请求路径 /shipindianbo/save
@RequestMapping("/save")
// 处理后端保存视频点播的请求
public R save(@RequestBody ShipindianboEntity shipindianbo, HttpServletRequest request) {
// 生成一个唯一的 ID
shipindianbo.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 验证实体(注释掉,未启用)
//ValidatorUtils.validateEntity(shipindianbo);
// 调用视频点播服务类的插入方法
shipindianboService.insert(shipindianbo);
// 返回成功响应
return R.ok();
}
/**
*
*/
// 映射请求路径 /shipindianbo/add
@RequestMapping("/add")
// 处理前端保存视频点播的请求
public R add(@RequestBody ShipindianboEntity shipindianbo, HttpServletRequest request) {
// 生成一个唯一的 ID
shipindianbo.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 验证实体(注释掉,未启用)
//ValidatorUtils.validateEntity(shipindianbo);
// 设置视频点播实体的用户 ID 为会话中的用户 ID
shipindianbo.setUserid((Long) request.getSession().getAttribute("userId"));
// 调用视频点播服务类的插入方法
shipindianboService.insert(shipindianbo);
// 返回成功响应
return R.ok();
}
/**
*
*/
// 映射请求路径 /shipindianbo/update
@RequestMapping("/update")
// 处理修改视频点播的请求
public R update(@RequestBody ShipindianboEntity shipindianbo, HttpServletRequest request) {
// 验证实体(注释掉,未启用)
//ValidatorUtils.validateEntity(shipindianbo);
// 调用视频点播服务类的更新方法,更新所有字段
shipindianboService.updateById(shipindianbo); // 全部更新
// 返回成功响应
return R.ok();
}
/**
*
*/
// 映射请求路径 /shipindianbo/delete
@RequestMapping("/delete")
// 处理删除视频点播的请求
public R delete(@RequestBody Long[] ids) {
// 调用视频点播服务类的批量删除方法
shipindianboService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*/
// 映射请求路径 /shipindianbo/remind/{columnName}/{type}
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
// 处理提醒统计的请求
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 将列名放入参数映射中
map.put("column", columnName);
// 将类型放入参数映射中
map.put("type", type);
if(type.equals("2")) {
// 如果类型为 2
if (type.equals("2")) {
// 创建一个日期格式化对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建一个日历对象
Calendar c = Calendar.getInstance();
// 提醒开始日期
Date remindStartDate = null;
// 提醒结束日期
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
// 如果提醒开始参数不为空
if (map.get("remindstart") != null) {
// 将提醒开始参数转换为整数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
// 设置日历时间为当前时间
c.setTime(new Date());
// 在当前日期上加上提醒开始天数
c.add(Calendar.DAY_OF_MONTH, remindStart);
// 获取提醒开始日期
remindStartDate = c.getTime();
// 将提醒开始日期格式化后放入参数映射中
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
// 如果提醒结束参数不为空
if (map.get("remindend") != null) {
// 将提醒结束参数转换为整数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置日历时间为当前时间
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
// 在当前日期上加上提醒结束天数
c.add(Calendar.DAY_OF_MONTH, remindEnd);
// 获取提醒结束日期
remindEndDate = c.getTime();
// 将提醒结束日期格式化后放入参数映射中
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建一个实体包装器,用于构建查询条件
Wrapper<ShipindianboEntity> wrapper = new EntityWrapper<ShipindianboEntity>();
if(map.get("remindstart")!=null) {
// 如果提醒开始参数不为空
if (map.get("remindstart") != null) {
// 设置查询条件,列名大于等于提醒开始日期
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
// 如果提醒结束参数不为空
if (map.get("remindend") != null) {
// 设置查询条件,列名小于等于提醒结束日期
wrapper.le(columnName, map.get("remindend"));
}
// 从会话中获取表名
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yonghu")) {
wrapper.eq("yonghuzhanghao", (String)request.getSession().getAttribute("username"));
// 如果表名是 "yonghu"
if (tableName.equals("yonghu")) {
// 设置查询条件,用户账号等于会话中的用户名
wrapper.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用视频点播服务类的统计方法,统计符合条件的记录数
int count = shipindianboService.selectCount(wrapper);
// 返回成功响应,并将统计结果放入响应中
return R.ok().put("count", count);
}
}
}

@ -1,217 +1,300 @@
package com.controller;
// 导入用于格式化日期的类,用于处理日期格式转换
import java.text.SimpleDateFormat;
// 导入动态数组类,用于创建和操作动态数组
import java.util.ArrayList;
// 导入数组工具类,提供数组相关操作方法
import java.util.Arrays;
// 导入日历类,用于处理日期和时间计算
import java.util.Calendar;
// 导入映射接口,用于存储键值对数据
import java.util.Map;
// 导入哈希表类实现Map接口的哈希表数据结构
import java.util.HashMap;
// 导入迭代器接口,用于遍历集合元素
import java.util.Iterator;
// 导入日期类,用于处理日期和时间对象
import java.util.Date;
// 导入列表接口,用于创建有序集合
import java.util.List;
// 导入HTTP请求类用于获取HTTP请求信息
import javax.servlet.http.HttpServletRequest;
// 导入自定义验证工具类,用于实体对象验证
import com.utils.ValidatorUtils;
// 导入字符串工具类,提供丰富的字符串操作方法
import org.apache.commons.lang3.StringUtils;
// 导入Spring自动注入注解自动装配依赖对象
import org.springframework.beans.factory.annotation.Autowired;
// 导入日期格式注解,用于指定日期参数的格式
import org.springframework.format.annotation.DateTimeFormat;
// 导入路径变量注解用于获取URL路径中的参数
import org.springframework.web.bind.annotation.PathVariable;
// 导入请求体注解,用于接收请求体中的数据
import org.springframework.web.bind.annotation.RequestBody;
// 导入请求映射注解用于映射HTTP请求到方法
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.annotation.IgnoreAuth;
import org.springframework.web.bind.annotation.RequestParam; // 导入请求参数注解,用于获取请求参数
import org.springframework.web.bind.annotation.RestController; // 导入REST控制器注解标记为RESTful控制器
import com.baomidou.mybatisplus.mapper.EntityWrapper; // 导入MyBatis-Plus实体包装器用于构建查询条件
import com.baomidou.mybatisplus.mapper.Wrapper; // 导入MyBatis-Plus包装器接口
import com.annotation.IgnoreAuth; // 导入自定义忽略认证注解
// 导入收藏表实体类,对应数据库表结构
import com.entity.StoreupEntity;
// 导入收藏表视图类,用于展示扩展数据
import com.entity.view.StoreupView;
// 导入收藏表服务类,处理业务逻辑
import com.service.StoreupService;
// 导入令牌服务类,处理令牌相关逻辑(未在代码中使用,保留注释)
import com.service.TokenService;
// 导入分页工具类,处理分页查询
import com.utils.PageUtils;
// 导入自定义响应类,封装接口返回数据
import com.utils.R;
// 导入MD5加密工具类用于数据加密未在代码中使用保留注释
import com.utils.MD5Util;
// 导入MyBatis-Plus工具类提供通用操作方法
import com.utils.MPUtil;
// 导入通用工具类,包含常用工具方法
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:15
*/
// 声明为REST控制器处理HTTP请求并返回JSON响应
@RestController
// 映射请求路径,所有以/storeup开头的请求由该控制器处理
@RequestMapping("/storeup")
public class StoreupController {
// 自动注入收藏表服务类实例,用于调用业务方法
@Autowired
private StoreupService storeupService;
/**
*
*
*/
// 映射请求路径/storeup/page
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,StoreupEntity storeup,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
storeup.setUserid((Long)request.getSession().getAttribute("userId"));
}
// 处理后端分页查询请求参数包括查询条件、实体对象、HTTP请求
public R page(@RequestParam Map<String, Object> params, StoreupEntity storeup,
HttpServletRequest request) {
// 如果当前用户不是管理员
if (!request.getSession().getAttribute("role").toString().equals("管理员")) {
// 设置收藏表的用户ID为当前登录用户的ID非管理员只能查看自己的数据
storeup.setUserid((Long) request.getSession().getAttribute("userId"));
}
// 创建实体包装器,用于构建查询条件
EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>();
PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params));
// 调用服务类的分页查询方法,包含排序、范围查询、模糊查询处理
PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params));
// 返回成功响应,携带分页数据
return R.ok().put("data", page);
}
/**
*
*
*/
// 映射请求路径/storeup/list
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,StoreupEntity storeup,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
storeup.setUserid((Long)request.getSession().getAttribute("userId"));
}
// 处理前端分页查询请求逻辑与后端类似非管理员限制用户ID
public R list(@RequestParam Map<String, Object> params, StoreupEntity storeup,
HttpServletRequest request) {
// 如果当前用户不是管理员
if (!request.getSession().getAttribute("role").toString().equals("管理员")) {
// 设置收藏表的用户ID为当前登录用户的ID
storeup.setUserid((Long) request.getSession().getAttribute("userId"));
}
// 创建实体包装器
EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>();
PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params));
// 调用分页查询方法
PageUtils page = storeupService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, storeup), params), params));
// 返回分页数据
return R.ok().put("data", page);
}
/**
*
/**
*
*/
// 映射请求路径/storeup/lists
@RequestMapping("/lists")
public R list( StoreupEntity storeup){
EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>();
ew.allEq(MPUtil.allEQMapPre( storeup, "storeup"));
// 处理全量查询请求,根据实体对象的属性构建查询条件
public R list(StoreupEntity storeup) {
// 创建实体包装器
EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>();
// 设置查询条件:所有字段与实体对象相等(前缀为"storeup"
ew.allEq(MPUtil.allEQMapPre(storeup, "storeup"));
// 返回查询结果(视图列表)
return R.ok().put("data", storeupService.selectListView(ew));
}
/**
*
/**
*
*/
// 映射请求路径/storeup/query
@RequestMapping("/query")
public R query(StoreupEntity storeup){
EntityWrapper< StoreupEntity> ew = new EntityWrapper< StoreupEntity>();
ew.allEq(MPUtil.allEQMapPre( storeup, "storeup"));
StoreupView storeupView = storeupService.selectView(ew);
return R.ok("查询收藏表成功").put("data", storeupView);
// 根据实体对象的属性查询单个收藏记录(通常用于精确查询)
public R query(StoreupEntity storeup) {
// 创建实体包装器
EntityWrapper<StoreupEntity> ew = new EntityWrapper<StoreupEntity>();
// 设置全字段相等查询条件
ew.allEq(MPUtil.allEQMapPre(storeup, "storeup"));
// 调用服务类的视图查询方法,获取包含关联数据的视图对象
StoreupView storeupView = storeupService.selectView(ew);
// 返回成功响应及查询结果
return R.ok("查询收藏表成功").put("data", storeupView);
}
/**
*
* ID
*/
// 映射路径参数/{id}获取记录ID
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
// 根据ID查询收藏记录详情后端使用
public R info(@PathVariable("id") Long id) {
// 通过ID直接查询实体对象
StoreupEntity storeup = storeupService.selectById(id);
// 返回实体数据
return R.ok().put("data", storeup);
}
/**
*
* ID
*/
// 映射路径参数/{id},前端调用的详情接口
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
// 逻辑与后端详情一致,返回实体数据
public R detail(@PathVariable("id") Long id) {
StoreupEntity storeup = storeupService.selectById(id);
return R.ok().put("data", storeup);
}
/**
*
*
*/
// 处理POST请求接收请求体中的实体对象
@RequestMapping("/save")
public R save(@RequestBody StoreupEntity storeup, HttpServletRequest request){
storeup.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(storeup);
storeup.setUserid((Long)request.getSession().getAttribute("userId"));
public R save(@RequestBody StoreupEntity storeup, HttpServletRequest request) {
// 生成唯一ID时间戳+随机数,确保唯一性)
storeup.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 实体验证(注释:未启用,如需验证可取消注释)
//ValidatorUtils.validateEntity(storeup);
// 设置用户ID为当前登录用户的ID后端保存时自动填充
storeup.setUserid((Long) request.getSession().getAttribute("userId"));
// 调用服务类的插入方法
storeupService.insert(storeup);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 前端调用的新增接口,逻辑与后端保存一致
@RequestMapping("/add")
public R add(@RequestBody StoreupEntity storeup, HttpServletRequest request){
storeup.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(storeup);
storeup.setUserid((Long)request.getSession().getAttribute("userId"));
public R add(@RequestBody StoreupEntity storeup, HttpServletRequest request) {
// 生成唯一ID
storeup.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 实体验证(未启用)
//ValidatorUtils.validateEntity(storeup);
// 设置用户ID前端请求时自动关联当前用户
storeup.setUserid((Long) request.getSession().getAttribute("userId"));
// 插入数据库
storeupService.insert(storeup);
return R.ok();
}
/**
*
*
*/
// 处理PUT请求更新已有记录
@RequestMapping("/update")
public R update(@RequestBody StoreupEntity storeup, HttpServletRequest request){
public R update(@RequestBody StoreupEntity storeup, HttpServletRequest request) {
// 实体验证(未启用)
//ValidatorUtils.validateEntity(storeup);
storeupService.updateById(storeup);//全部更新
// 根据ID更新实体对象全字段更新
storeupService.updateById(storeup); // 注释:标记为全部更新
return R.ok();
}
/**
*
*
*/
// 处理DELETE请求接收ID数组
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
public R delete(@RequestBody Long[] ids) {
// 将ID数组转换为列表批量删除
storeupService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
*
*
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<StoreupEntity> wrapper = new EntityWrapper<StoreupEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
wrapper.eq("userid", (Long)request.getSession().getAttribute("userId"));
}
int count = storeupService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
// 映射路径参数{columnName}/{type},处理提醒相关统计
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 向参数映射中添加列名和类型,用于后续处理
map.put("column", columnName);
map.put("type", type);
// 如果是日期范围提醒type=2相对当前日期计算提醒时间
if (type.equals("2")) {
// 创建日期格式化对象格式yyyy-MM-dd
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 获取日历实例,用于日期计算
Calendar c = Calendar.getInstance();
Date remindStartDate = null; // 提醒开始日期
Date remindEndDate = null; // 提醒结束日期
// 处理提醒开始时间(偏移天数转日期)
if (map.get("remindstart") != null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date()); // 设置为当前时间
c.add(Calendar.DAY_OF_MONTH, remindStart); // 添加偏移天数
remindStartDate = c.getTime(); // 获取计算后的日期
map.put("remindstart", sdf.format(remindStartDate)); // 格式化后存入参数
}
// 处理提醒结束时间(逻辑同上)
if (map.get("remindend") != null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建包装器构建查询条件
Wrapper<StoreupEntity> wrapper = new EntityWrapper<StoreupEntity>();
// 添加提醒开始时间的大于等于条件
if (map.get("remindstart") != null) {
wrapper.ge(columnName, map.get("remindstart"));
}
// 添加提醒结束时间的小于等于条件
if (map.get("remindend") != null) {
wrapper.le(columnName, map.get("remindend"));
}
// 非管理员用户限制只能查询自己的数据
if (!request.getSession().getAttribute("role").toString().equals("管理员")) {
wrapper.eq("userid", (Long) request.getSession().getAttribute("userId"));
}
// 统计符合条件的记录数
int count = storeupService.selectCount(wrapper);
// 返回统计结果
return R.ok().put("count", count);
}
}

@ -1,174 +1,855 @@
package com.controller;
// 导入数组操作工具类,提供数组相关操作方法(如排序、查找等)
import java.util.Arrays;
// 导入日历类,用于处理日期和时间(如日期计算、格式化等)
import java.util.Calendar;
// 导入日期类,用于表示具体的日期和时间
import java.util.Date;
// 导入映射接口,用于存储键值对数据(如参数映射、结果集等)
import java.util.Map;
// 导入列表接口,用于存储有序的元素集合
import java.util.List;
// 导入链表实现类,提供高效的列表操作(如插入、删除)
import java.util.LinkedList;
// 导入哈希表实现类,提供键值对的快速存储和查找
import java.util.HashMap;
// 导入迭代器接口,用于遍历集合中的元素
import java.util.Iterator;
// 导入HTTP请求处理类用于获取请求参数、会话等信息
import javax.servlet.http.HttpServletRequest;
// 导入Spring自动注入注解自动装配依赖的服务类
import org.springframework.beans.factory.annotation.Autowired;
// 导入Spring控制器注解冗余导入实际使用@RestController保留注释说明
import org.springframework.stereotype.Controller;
// 导入Spring GET请求映射注解处理GET方法的请求
import org.springframework.web.bind.annotation.GetMapping;
// 导入Spring路径变量注解获取URL路径中的参数值
import org.springframework.web.bind.annotation.PathVariable;
// 导入Spring POST请求映射注解处理POST方法的请求
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
// 导入Spring请求映射注解定义URL路径与方法的映射关系
import org.springframework.web.bind.annotation.RequestMapping;
// 导入Spring请求参数注解获取请求参数的值
import org.springframework.web.bind.annotation.RequestParam;
// 导入Spring响应体注解冗余导入@RestController已包含保留注释说明
import org.springframework.web.bind.annotation.ResponseBody;
// 导入Spring REST控制器注解标记为RESTful风格控制器并自动返回JSON响应
import org.springframework.web.bind.annotation.RestController;
// 导入自定义忽略认证注解,标记无需认证的接口
import com.annotation.IgnoreAuth;
// 导入MyBatis-Plus实体包装器类用于构建数据库查询条件
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入用户实体类,对应数据库用户表
import com.entity.TokenEntity;
import com.entity.UserEntity;
// 导入角色实体类,对应数据库角色表
import com.entity.RoleEntity;
// 导入权限实体类,对应数据库权限表
import com.entity.PermissionEntity;
// 导入用户服务类,处理用户相关业务逻辑
import com.service.TokenService;
import com.service.UserService;
// 导入角色服务类,处理角色相关业务逻辑
import com.service.RoleService;
// 导入权限服务类,处理权限相关业务逻辑
import com.service.PermissionService;
// 导入通用工具类,包含常用辅助方法
import com.utils.CommonUtil;
// 导入MyBatis-Plus工具类提供通用数据库操作工具
import com.utils.MPUtil;
// 导入分页工具类,处理分页查询结果
import com.utils.PageUtils;
// 导入自定义响应类,封装统一的响应格式
import com.utils.R;
// 导入验证工具类,用于实体对象的参数验证
import com.utils.ValidatorUtils;
/**
*
*
*
*/
// 定义请求路径前缀为"/users",所有接口路径均以此开头
@RequestMapping("users")
// 声明为REST控制器处理HTTP请求并返回JSON数据
@RestController
public class UserController{
public class UserController {
// 自动注入用户服务类实例,用于调用用户相关数据库操作
@Autowired
private UserService userService;
// 自动注入令牌服务类实例,用于生成和管理用户令牌
@Autowired
private TokenService tokenService;
// 自动注入角色服务类实例,用于处理角色相关业务
@Autowired
private RoleService roleService;
// 自动注入权限服务类实例,用于处理权限相关业务
@Autowired
private PermissionService permissionService;
/**
*
*
* 访
*/
// 标记该接口无需认证
@IgnoreAuth
// 映射POST请求路径"/login"
@PostMapping(value = "/login")
// 定义登录方法接收用户名、密码、验证码和HTTP请求
public R login(String username, String password, String captcha, HttpServletRequest request) {
// 根据用户名查询用户实体(从数据库中查找匹配的用户)
UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
if(user==null || !user.getPassword().equals(password)) {
// 验证用户是否存在且密码是否正确
if (user == null || !user.getPassword().equals(password)) {
// 返回错误响应,提示账号或密码不正确
return R.error("账号或密码不正确");
}
String token = tokenService.generateToken(user.getId(),username, "users", user.getRole());
// 生成用户令牌参数用户ID、用户名、表名、用户角色
String token = tokenService.generateToken(user.getId(), username, "users", user.getRole());
// 返回成功响应,携带生成的令牌
return R.ok().put("token", token);
}
/**
*
*
* 访
*/
// 标记该接口无需认证
@IgnoreAuth
// 映射POST请求路径"/register",接收请求体中的用户实体
@PostMapping(value = "/register")
public R register(@RequestBody UserEntity user){
public R register(@RequestBody UserEntity user) {
// 注释:实体验证(此处代码被注释,未启用参数验证)
// ValidatorUtils.validateEntity(user);
if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
return R.error("用户已存在");
}
userService.insert(user);
return R.ok();
}
// 检查用户名是否已存在(数据库中是否有相同用户名的记录)
if (userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) != null) {
// 返回错误响应,提示用户已存在
return R.error("用户已存在");
}
// 插入新用户到数据库
userService.insert(user);
// 返回成功响应
return R.ok();
}
/**
* 退
* 退
* 退使
*/
// 映射GET请求路径"logout"
@GetMapping(value = "logout")
public R logout(HttpServletRequest request) {
// 使当前HTTP会话失效清除用户登录状态
request.getSession().invalidate();
// 返回成功响应,提示退出成功
return R.ok("退出成功");
}
/**
*
*/
@IgnoreAuth
*
* 访
*/
// 标记该接口无需认证
@IgnoreAuth
// 映射任意请求方法路径"/resetPass"
@RequestMapping(value = "/resetPass")
public R resetPass(String username, HttpServletRequest request){
UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
if(user==null) {
return R.error("账号不存在");
}
user.setPassword("123456");
userService.update(user,null);
return R.ok("密码已重置为123456");
}
/**
*
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,UserEntity user){
EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));
return R.ok().put("data", page);
}
/**
*
*/
@RequestMapping("/list")
public R list( UserEntity user){
EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
ew.allEq(MPUtil.allEQMapPre( user, "user"));
return R.ok().put("data", userService.selectListView(ew));
}
/**
*
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") String id){
UserEntity user = userService.selectById(id);
return R.ok().put("data", user);
}
/**
* session
*/
@RequestMapping("/session")
public R getCurrUser(HttpServletRequest request){
Long id = (Long)request.getSession().getAttribute("userId");
UserEntity user = userService.selectById(id);
return R.ok().put("data", user);
}
/**
*
*/
@PostMapping("/save")
public R save(@RequestBody UserEntity user){
public R resetPass(String username, HttpServletRequest request) {
// 根据用户名查询用户实体
UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
// 检查用户是否存在
if (user == null) {
// 返回错误响应,提示账号不存在
return R.error("账号不存在");
}
// 将用户密码重置为默认值"123456"
user.setPassword("123456");
// 更新用户信息第二个参数为null表示更新所有匹配记录此处按ID更新
userService.update(user, null);
// 返回成功响应,提示密码重置结果
return R.ok("密码已重置为123456");
}
/**
*
*
*/
// 映射任意请求方法路径"/page"
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params, UserEntity user) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
// 调用用户服务的分页查询方法(包含排序、范围查询、模糊查询处理)
PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));
// 返回成功响应,携带分页数据
return R.ok().put("data", page);
}
/**
*
*
*/
// 映射任意请求方法路径"/list"
@RequestMapping("/list")
public R list(UserEntity user) {
// 创建实体包装器
EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
// 设置查询条件:所有字段与实体对象相等(前缀为"user",避免字段名冲突)
ew.allEq(MPUtil.allEQMapPre(user, "user"));
// 返回成功响应,携带查询结果(视图列表,可能包含关联数据)
return R.ok().put("data", userService.selectListView(ew));
}
/**
*
* ID
*/
// 映射任意请求方法路径"/info/{id}"{id}为路径参数
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") String id) {
// 根据用户ID查询用户实体从数据库中获取用户详情
UserEntity user = userService.selectById(id);
// 返回成功响应,携带用户数据
return R.ok().put("data", user);
}
/**
*
*
*/
// 映射任意请求方法路径"/session"
@RequestMapping("/session")
public R getCurrUser(HttpServletRequest request) {
// 从会话中获取用户ID登录时存储的用户标识
Long id = (Long) request.getSession().getAttribute("userId");
// 根据用户ID查询用户实体
UserEntity user = userService.selectById(id);
// 返回成功响应,携带当前用户数据
return R.ok().put("data", user);
}
/**
*
*
*/
// 映射POST请求路径"/save",接收请求体中的用户实体
@PostMapping("/save")
public R save(@RequestBody UserEntity user) {
// 注释:实体验证(此处代码被注释,未启用参数验证)
// ValidatorUtils.validateEntity(user);
if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
return R.error("用户已存在");
}
userService.insert(user);
return R.ok();
}
/**
*
*/
@RequestMapping("/update")
public R update(@RequestBody UserEntity user){
// 检查用户名是否已存在(除当前用户外,避免更新时冲突)
if (userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) != null) {
// 返回错误响应,提示用户已存在
return R.error("用户已存在");
}
// 插入新用户到数据库
userService.insert(user);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射任意请求方法路径"/update",接收请求体中的用户实体
@RequestMapping("/update")
public R update(@RequestBody UserEntity user) {
// 注释:实体验证(此处代码被注释,未启用参数验证)
// ValidatorUtils.validateEntity(user);
UserEntity u = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername()));
if(u!=null && u.getId()!=user.getId() && u.getUsername().equals(user.getUsername())) {
return R.error("用户名已存在。");
}
userService.updateById(user);//全部更新
return R.ok();
}
/**
*
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
userService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
}
// 根据用户名查询用户实体(检查用户名是否被其他用户占用)
UserEntity u = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername()));
// 检查用户名是否已被其他用户使用ID不同但用户名相同
if (u != null && u.getId() != user.getId() && u.getUsername().equals(user.getUsername())) {
// 返回错误响应,提示用户名已存在
return R.error("用户名已存在。");
}
// 根据用户ID更新用户信息全字段更新覆盖数据库中现有记录
userService.updateById(user); // 注释:标记为全部更新,非部分更新
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射任意请求方法路径"/delete"接收请求体中的用户ID数组
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids) {
// 将用户ID数组转换为列表批量删除对应的用户记录
userService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
* ID
*/
// 映射任意请求方法路径"/roles/{userId}"{userId}为用户ID
@RequestMapping("/roles/{userId}")
public R getUserRoles(@PathVariable("userId") Long userId) {
// 根据用户ID查询用户实体
UserEntity user = userService.selectById(userId);
// 检查用户是否存在
if (user == null) {
// 返回错误响应,提示用户不存在
return R.error("用户不存在");
}
// 根据用户角色ID查询角色信息用户实体中存储角色ID关联角色表
RoleEntity role = roleService.selectById(user.getRole());
// 返回成功响应,携带角色数据
return R.ok().put("role", role);
}
/**
*
* ID
*/
// 映射任意请求方法路径"/permissions/{roleId}"{roleId}为角色ID
@RequestMapping("/permissions/{roleId}")
public R getRolePermissions(@PathVariable("roleId") Long roleId) {
// 根据角色ID查询角色实体
RoleEntity role = roleService.selectById(roleId);
// 检查角色是否存在
if (role == null) {
// 返回错误响应,提示角色不存在
return R.error("角色不存在");
}
// 根据角色ID查询权限信息权限表中存储角色ID关联查询
List<PermissionEntity> permissions = permissionService.selectList(new EntityWrapper<PermissionEntity>().eq("role_id", roleId));
// 返回成功响应,携带权限列表
return R.ok().put("permissions", permissions);
}
/**
*
*
*/
// 映射POST请求路径"/roles/add",接收请求体中的角色实体
@PostMapping("/roles/add")
public R addRole(@RequestBody RoleEntity role) {
// 检查角色名是否已存在(避免重复角色名)
if (roleService.selectOne(new EntityWrapper<RoleEntity>().eq("role_name", role.getRoleName())) != null) {
// 返回错误响应,提示角色名已存在
return R.error("角色名已存在");
}
// 插入新角色到数据库
roleService.insert(role);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射任意请求方法路径"/roles/update",接收请求体中的角色实体
@RequestMapping("/roles/update")
public R updateRole(@RequestBody RoleEntity role) {
// 检查角色名是否已被其他角色使用更新时排除自身ID
RoleEntity existingRole = roleService.selectOne(new EntityWrapper<RoleEntity>().eq("role_name", role.getRoleName()));
if (existingRole != null && existingRole.getId() != role.getId()) {
// 返回错误响应,提示角色名已存在
return R.error("角色名已存在");
}
// 更新角色信息到数据库
roleService.updateById(role);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射任意请求方法路径"/roles/delete/{roleId}"{roleId}为角色ID
@RequestMapping("/roles/delete/{roleId}")
public R deleteRole(@PathVariable("roleId") Long roleId) {
// 检查该角色是否有用户关联(查询所有拥有该角色的用户)
List<UserEntity> users = userService.selectList(new EntityWrapper<UserEntity>().eq("role", roleId));
if (!users.isEmpty()) {
// 返回错误响应,提示角色下存在用户,无法删除
return R.error("该角色下存在用户,无法删除");
}
// 删除角色记录
roleService.deleteById(roleId);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射POST请求路径"/permissions/add",接收请求体中的权限实体
@PostMapping("/permissions/add")
public R addPermission(@RequestBody PermissionEntity permission) {
// 检查权限名是否已存在(避免重复权限名)
if (permissionService.selectOne(new EntityWrapper<PermissionEntity>().eq("permission_name", permission.getPermissionName())) != null) {
// 返回错误响应,提示权限名已存在
return R.error("权限名已存在");
}
// 插入新权限到数据库
permissionService.insert(permission);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射任意请求方法路径"/permissions/update",接收请求体中的权限实体
@RequestMapping("/permissions/update")
public R updatePermission(@RequestBody PermissionEntity permission) {
// 检查权限名是否已被其他权限使用更新时排除自身ID
PermissionEntity existingPermission = permissionService.selectOne(new EntityWrapper<PermissionEntity>().eq("permission_name", permission.getPermissionName()));
if (existingPermission != null && existingPermission.getId() != permission.getId()) {
// 返回错误响应,提示权限名已存在
return R.error("权限名已存在");
}
// 更新权限信息到数据库
permissionService.updateById(permission);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射任意请求方法路径"/permissions/delete/{permissionId}"{permissionId}为权限ID
@RequestMapping("/permissions/delete/{permissionId}")
public R deletePermission(@PathVariable("permissionId") Long permissionId) {
// 删除指定ID的权限记录
permissionService.deleteById(permissionId);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射POST请求路径"/users/{userId}/assignRole/{roleId}"路径参数为用户ID和角色ID
@PostMapping("/users/{userId}/assignRole/{roleId}")
public R assignRoleToUser(@PathVariable("userId") Long userId, @PathVariable("roleId") Long roleId) {
// 检查用户是否存在
UserEntity user = userService.selectById(userId);
if (user == null) {
// 返回错误响应,提示用户不存在
return R.error("用户不存在");
}
// 检查角色是否存在
RoleEntity role = roleService.selectById(roleId);
if (role == null) {
// 返回错误响应,提示角色不存在
return R.error("角色不存在");
}
// 更新用户的角色ID为指定角色ID
user.setRole(roleId);
userService.updateById(user);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射POST请求路径"/roles/{roleId}/assignPermission/{permissionId}"路径参数为角色ID和权限ID
@PostMapping("/roles/{roleId}/assignPermission/{permissionId}")
public R assignPermissionToRole(@PathVariable("roleId") Long roleId, @PathVariable("permissionId") Long permissionId) {
// 检查角色是否存在
RoleEntity role = roleService.selectById(roleId);
if (role == null) {
// 返回错误响应,提示角色不存在
return R.error("角色不存在");
}
// 检查权限是否存在
PermissionEntity permission = permissionService.selectById(permissionId);
if (permission == null) {
// 返回错误响应,提示权限不存在
return R.error("权限不存在");
}
// 更新权限的角色ID为指定角色ID假设权限表中直接存储角色ID
permission.setRoleId(roleId);
permissionService.updateById(permission);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射任意请求方法路径"/users/count"
@RequestMapping("/users/count")
public R countUsers() {
// 统计用户表中的记录数
Integer userCount = userService.selectCount(new EntityWrapper<UserEntity>());
// 返回成功响应,携带用户数量
return R.ok().put("userCount", userCount);
}
/**
*
*
*/
// 映射任意请求方法路径"/roles/count"
@RequestMapping("/roles/count")
public R countRoles() {
// 统计角色表中的记录数
Integer roleCount = roleService.selectCount(new EntityWrapper<RoleEntity>());
// 返回成功响应,携带角色数量
return R.ok().put("roleCount", roleCount);
}
/**
*
*
*/
// 映射任意请求方法路径"/permissions/count"
@RequestMapping("/permissions/count")
public R countPermissions() {
// 统计权限表中的记录数
Integer permissionCount = permissionService.selectCount(new EntityWrapper<PermissionEntity>());
// 返回成功响应,携带权限数量
return R.ok().put("permissionCount", permissionCount);
}
/**
*
*
*/
// 映射任意请求方法路径"/users/search/{keyword}"{keyword}为搜索关键词
@RequestMapping("/users/search/{keyword}")
public R searchUsers(@PathVariable("keyword") String keyword) {
// 创建实体包装器,设置用户名模糊查询条件(包含关键词)
EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>().like("username", keyword);
// 查询符合条件的用户列表
List<UserEntity> users = userService.selectList(ew);
// 返回成功响应,携带查询结果
return R.ok().put("users", users);
}
/**
*
*
*/
// 映射任意请求方法路径"/roles/search/{keyword}"{keyword}为搜索关键词
@RequestMapping("/roles/search/{keyword}")
public R searchRoles(@PathVariable("keyword") String keyword) {
// 创建实体包装器,设置角色名模糊查询条件(包含关键词)
EntityWrapper<RoleEntity> ew = new EntityWrapper<RoleEntity>().like("role_name", keyword);
// 查询符合条件的角色列表
List<RoleEntity> roles = roleService.selectList(ew);
// 返回成功响应,携带查询结果
return R.ok().put("roles", roles);
}
/**
*
*
*/
// 映射任意请求方法路径"/permissions/search/{keyword}"{keyword}为搜索关键词
@RequestMapping("/permissions/search/{keyword}")
public R searchPermissions(@PathVariable("keyword") String keyword) {
// 创建实体包装器,设置权限名模糊查询条件(包含关键词)
EntityWrapper<PermissionEntity> ew = new EntityWrapper<PermissionEntity>().like("permission_name", keyword);
// 查询符合条件的权限列表
List<PermissionEntity> permissions = permissionService.selectList(ew);
// 返回成功响应,携带查询结果
return R.ok().put("permissions", permissions);
}
/**
*
*
*/
// 映射任意请求方法路径"/users/allWithRoles"
@RequestMapping("/users/allWithRoles")
public R getAllUsersWithRoles() {
// 查询所有用户记录
List<UserEntity> users = userService.selectList(new EntityWrapper<UserEntity>());
// 创建映射表存储用户ID到用户及角色信息的映射
Map<Long, Map<String, Object>> userRoleMap = new HashMap<>();
// 遍历用户列表,填充角色信息
for (UserEntity user : users) {
// 根据用户角色ID查询角色实体
RoleEntity role = roleService.selectById(user.getRole());
// 创建用户信息映射,包含用户和角色数据
Map<String, Object> userInfo = new HashMap<>();
userInfo.put("user", user);
userInfo.put("role", role);
// 将用户信息存入映射表
userRoleMap.put(user.getId(), userInfo);
}
// 返回成功响应,携带用户及其角色信息
return R.ok().put("userRoleMap", userRoleMap);
}
/**
*
*
*/
// 映射任意请求方法路径"/roles/allWithPermissions"
@RequestMapping("/roles/allWithPermissions")
public R getAllRolesWithPermissions() {
// 查询所有角色记录
List<RoleEntity> roles = roleService.selectList(new EntityWrapper<RoleEntity>());
// 创建映射表存储角色ID到角色及权限信息的映射
Map<Long, Map<String, Object>> rolePermissionMap = new HashMap<>();
// 遍历角色列表,填充权限信息
for (RoleEntity role : roles) {
// 根据角色ID查询权限列表
List<PermissionEntity> permissions = permissionService.selectList(new EntityWrapper<PermissionEntity>().eq("role_id", role.getId()));
// 创建角色信息映射,包含角色和权限数据
Map<String, Object> roleInfo = new HashMap<>();
roleInfo.put("role", role);
roleInfo.put("permissions", permissions);
// 将角色信息存入映射表
rolePermissionMap.put(role.getId(), roleInfo);
}
// 返回成功响应,携带角色及其权限信息
return R.ok().put("rolePermissionMap", rolePermissionMap);
}
/**
*
*
*/
// 映射POST请求路径"/users/batchAssignRole"接收包含用户ID列表和角色ID的请求体
@PostMapping("/users/batchAssignRole")
public R batchAssignRole(@RequestBody Map<String, Object> params) {
// 从请求体中获取用户ID列表
List<Long> userIds = (List<Long>) params.get("userIds");
// 从请求体中获取角色ID
Long roleId = (Long) params.get("roleId");
// 检查角色是否存在
RoleEntity role = roleService.selectById(roleId);
if (role == null) {
// 返回错误响应,提示角色不存在
return R.error("角色不存在");
}
// 遍历用户ID列表逐个分配角色
for (Long userId : userIds) {
// 根据用户ID查询用户实体
UserEntity user = userService.selectById(userId);
if (user != null) {
// 更新用户的角色ID为目标角色ID
user.setRole(roleId);
userService.updateById(user);
}
}
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射POST请求路径"/roles/batchAssignPermission"接收包含角色ID和权限ID列表的请求体
@PostMapping("/roles/batchAssignPermission")
public R batchAssignPermission(@RequestBody Map<String, Object> params) {
// 从请求体中获取角色ID
Long roleId = (Long) params.get("roleId");
// 从请求体中获取权限ID列表
List<Long> permissionIds = (List<Long>) params.get("permissionIds");
// 检查角色是否存在
RoleEntity role = roleService.selectById(roleId);
if (role == null) {
// 返回错误响应,提示角色不存在
return R.error("角色不存在");
}
// 遍历权限ID列表逐个分配权限
for (Long permissionId : permissionIds) {
// 根据权限ID查询权限实体
PermissionEntity permission = permissionService.selectById(permissionId);
if (permission != null) {
// 更新权限的角色ID为目标角色ID
permission.setRoleId(roleId);
permissionService.updateById(permission);
}
}
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射任意请求方法路径"/users/{userId}/hasPermission/{permissionName}"路径参数为用户ID和权限名
@RequestMapping("/users/{userId}/hasPermission/{permissionName}")
public R checkUserPermission(@PathVariable("userId") Long userId, @PathVariable("permissionName") String permissionName) {
// 根据用户ID查询用户实体
UserEntity user = userService.selectById(userId);
if (user == null) {
// 返回错误响应,提示用户不存在
return R.error("用户不存在");
}
// 根据用户角色ID查询角色实体
RoleEntity role = roleService.selectById(user.getRole());
if (role == null) {
// 返回错误响应,提示角色不存在(用户角色异常)
return R.error("角色不存在");
}
// 根据角色ID和权限名查询权限实体检查角色是否拥有该权限
PermissionEntity permission = permissionService.selectOne(new EntityWrapper<PermissionEntity>()
.eq("role_id", role.getId())
.eq("permission_name", permissionName));
// 判断用户是否具有该权限(存在即有权限)
boolean hasPermission = permission != null;
// 返回成功响应,携带权限检查结果
return R.ok().put("hasPermission", hasPermission);
}
/**
*
*
*/
// 映射任意请求方法路径"/users/{userId}/allPermissions"路径参数为用户ID
@RequestMapping("/users/{userId}/allPermissions")
public R getUserAllPermissions(@PathVariable("userId") Long userId) {
// 根据用户ID查询用户实体
UserEntity user = userService.selectById(userId);
if (user == null) {
// 返回错误响应,提示用户不存在
return R.error("用户不存在");
}
// 根据用户角色ID查询角色实体
RoleEntity role = roleService.selectById(user.getRole());
if (role == null) {
// 返回错误响应,提示角色不存在(用户角色异常)
return R.error("角色不存在");
}
// 根据角色ID查询所有权限该角色拥有的所有权限
List<PermissionEntity> permissions = permissionService.selectList(new EntityWrapper<PermissionEntity>().eq("role_id", role.getId()));
// 返回成功响应,携带权限列表
return R.ok().put("permissions", permissions);
}
/**
*
* 0
*/
// 映射任意请求方法路径"/users/{userId}/disable"路径参数为用户ID
@RequestMapping("/users/{userId}/disable")
public R disableUser(@PathVariable("userId") Long userId) {
// 根据用户ID查询用户实体
UserEntity user = userService.selectById(userId);
if (user == null) {
// 返回错误响应,提示用户不存在
return R.error("用户不存在");
}
// 设置用户状态为禁用假设0表示禁用1表示启用
user.setStatus(0);
// 更新用户状态到数据库
userService.updateById(user);
// 返回成功响应
return R.ok();
}
/**
*
* 1
*/
// 映射任意请求方法路径"/users/{userId}/enable"路径参数为用户ID
@RequestMapping("/users/{userId}/enable")
public R enableUser(@PathVariable("userId") Long userId) {
// 根据用户ID查询用户实体
UserEntity user = userService.selectById(userId);
if (user == null) {
// 返回错误响应,提示用户不存在
return R.error("用户不存在");
}
// 设置用户状态为启用假设1表示启用0表示禁用
user.setStatus(1);
// 更新用户状态到数据库
userService.updateById(user);
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射POST请求路径"/users/batchDisable"接收请求体中的用户ID列表
@PostMapping("/users/batchDisable")
public R batchDisableUsers(@RequestBody List<Long> userIds) {
// 遍历用户ID列表逐个禁用用户
for (Long userId : userIds) {
// 根据用户ID查询用户实体
UserEntity user = userService.selectById(userId);
if (user != null) {
// 设置用户状态为禁用
user.setStatus(0);
userService.updateById(user);
}
}
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射POST请求路径"/users/batchEnable"接收请求体中的用户ID列表
@PostMapping("/users/batchEnable")
public R batchEnableUsers(@RequestBody List<Long> userIds) {
// 遍历用户ID列表逐个启用用户
for (Long userId : userIds) {
// 根据用户ID查询用户实体
UserEntity user = userService.selectById(userId);
if (user != null) {
// 设置用户状态为启用
user.setStatus(1);
userService.updateById(user);
}
}
// 返回成功响应
return R.ok();
}
/**
*
*
*/
// 映射任意请求方法路径"/users/disabled"
@RequestMapping("/users/disabled")
public R getDisabledUsers() {
// 创建实体包装器设置状态为禁用的查询条件假设0为禁用
EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>().eq("status", 0);
// 查询所有禁用用户记录
List<UserEntity> disabledUsers = userService.selectList(ew);
// 返回成功响应,携带禁用用户列表
return R.ok().put("disabledUsers", disabledUsers);
}
/**
*
*
*/
// 映射任意请求方法路径"/users/enabled"
@RequestMapping("/users/enabled")
public R getEnabledUsers() {
// 创建实体包装器设置状态为启用的查询条件假设1为启用
EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>().eq("status", 1);
// 查询所有启用用户记录
List<UserEntity> enabledUsers = userService.selectList(ew);
// 返回成功响应,携带启用用户列表
return R.ok().put("enabledUsers", enabledUsers);
}
}

@ -1,110 +1,482 @@
package com.controller;
// 导入SimpleDateFormat类用于格式化日期和时间
import java.text.SimpleDateFormat;
// 导入ArrayList类用于创建动态数组
import java.util.ArrayList;
// 导入Arrays类提供了操作数组的静态方法
import java.util.Arrays;
// 导入Calendar类用于处理日期和时间
import java.util.Calendar;
// 导入Map接口用于存储键值对
import java.util.Map;
// 导入HashMap类实现了Map接口用于存储键值对
import java.util.HashMap;
// 导入Iterator接口用于遍历集合
import java.util.Iterator;
// 导入Date类用于表示特定的瞬间
import java.util.Date;
// 导入List接口用于存储有序的元素集合
import java.util.List;
// 导入HttpServletRequest类用于封装HTTP请求信息
import javax.servlet.http.HttpServletRequest;
// 导入验证工具类,用于验证实体对象的合法性
import com.utils.ValidatorUtils;
// 导入Apache Commons Lang库中的StringUtils类提供了字符串操作的实用方法
import org.apache.commons.lang3.StringUtils;
// 导入Spring框架的自动注入注解用于自动装配依赖
import org.springframework.beans.factory.annotation.Autowired;
// 导入Spring框架的日期格式化注解用于将请求参数转换为日期类型
import org.springframework.format.annotation.DateTimeFormat;
// 导入Spring框架的路径变量注解用于获取URL中的路径变量
import org.springframework.web.bind.annotation.PathVariable;
// 导入Spring框架的请求体注解用于将请求体中的数据绑定到方法参数上
import org.springframework.web.bind.annotation.RequestBody;
// 导入Spring框架的请求映射注解用于将HTTP请求映射到处理方法上
import org.springframework.web.bind.annotation.RequestMapping;
// 导入Spring框架的请求参数注解用于获取请求参数的值
import org.springframework.web.bind.annotation.RequestParam;
// 导入Spring框架的REST控制器注解用于将该类标记为RESTful风格的控制器
import org.springframework.web.bind.annotation.RestController;
// 导入MyBatis-Plus的实体包装器类用于构建查询条件
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入MyBatis-Plus的包装器接口是EntityWrapper的父接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解,用于标记不需要进行认证的接口
import com.annotation.IgnoreAuth;
// 导入我的笔记实体类,对应数据库中的我的笔记表
import com.entity.WodebijiEntity;
// 导入我的笔记视图类,用于展示我的笔记信息
import com.entity.view.WodebijiView;
// 导入我的笔记服务类,用于处理我的笔记相关的业务逻辑
import com.service.WodebijiService;
// 导入令牌服务类,用于处理令牌相关的业务逻辑
import com.service.TokenService;
// 导入分页工具类,用于处理分页查询结果
import com.utils.PageUtils;
// 导入自定义的响应类,用于封装统一的响应格式
import com.utils.R;
// 导入MD5工具类用于对数据进行MD5加密
import com.utils.MD5Util;
// 导入MyBatis-Plus工具类提供了一些常用的工具方法
import com.utils.MPUtil;
// 导入通用工具类,提供了一些通用的工具方法
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:15
*/
// 将该类标记为RESTful风格的控制器处理HTTP请求并返回JSON数据
@RestController
// 定义请求映射路径,所有以/wodebiji开头的请求都会被该控制器处理
@RequestMapping("/wodebiji")
public class WodebijiController {
// 使用@Autowired注解自动注入我的笔记服务类的实例
@Autowired
private WodebijiService wodebijiService;
// 以下是新添加的功能:根据笔记标题进行模糊查询
/**
*
* @param params
* @param title
* @param request HTTP
* @return
*/
@RequestMapping("/searchByTitle")
public R searchByTitle(@RequestParam Map<String, Object> params, @RequestParam String title, HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodebijiEntity> ew = new EntityWrapper<WodebijiEntity>();
// 添加模糊查询条件,查询笔记标题包含指定关键词的记录
ew.like("title", title);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodebijiService.queryPage(params, MPUtil.sort(ew, params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
// 以下是新添加的功能:根据笔记创建时间范围进行查询
/**
*
* @param params
* @param startDate
* @param endDate
* @param request HTTP
* @return
*/
@RequestMapping("/searchByCreateTime")
public R searchByCreateTime(@RequestParam Map<String, Object> params,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodebijiEntity> ew = new EntityWrapper<WodebijiEntity>();
// 添加时间范围查询条件,查询创建时间在指定范围内的笔记
ew.between("create_time", startDate, endDate);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodebijiService.queryPage(params, MPUtil.sort(ew, params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
// 以下是新添加的功能:根据笔记重要程度进行查询
/**
*
* @param params
* @param importance
* @param request HTTP
* @return
*/
@RequestMapping("/searchByImportance")
public R searchByImportance(@RequestParam Map<String, Object> params, @RequestParam int importance, HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodebijiEntity> ew = new EntityWrapper<WodebijiEntity>();
// 添加重要程度查询条件,查询指定重要程度的笔记
ew.eq("importance", importance);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodebijiService.queryPage(params, MPUtil.sort(ew, params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
// 以下是新添加的功能:批量更新笔记的重要程度
/**
*
* @param ids ID
* @param importance
* @return
*/
@RequestMapping("/batchUpdateImportance")
public R batchUpdateImportance(@RequestBody Long[] ids, @RequestParam int importance) {
// 遍历ID数组
for (Long id : ids) {
// 根据ID查询笔记实体
WodebijiEntity wodebiji = wodebijiService.selectById(id);
if (wodebiji != null) {
// 如果笔记存在,则更新其重要程度
wodebiji.setImportance(importance);
// 调用服务类的更新方法,更新笔记信息
wodebijiService.updateById(wodebiji);
}
}
// 返回成功响应
return R.ok();
}
// 以下是新添加的功能:统计不同重要程度的笔记数量
/**
*
* @param request HTTP
* @return
*/
@RequestMapping("/countByImportance")
public R countByImportance(HttpServletRequest request) {
// 创建一个Map对象用于存储不同重要程度的笔记数量
Map<Integer, Integer> importanceCountMap = new HashMap<>();
// 假设重要程度范围是1到5
for (int i = 1; i <= 5; i++) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodebijiEntity> ew = new EntityWrapper<WodebijiEntity>();
// 添加重要程度查询条件,查询指定重要程度的笔记
ew.eq("importance", i);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的统计方法,统计指定重要程度的笔记数量
int count = wodebijiService.selectCount(ew);
// 将统计结果存入Map对象中
importanceCountMap.put(i, count);
}
// 返回成功响应,并将统计结果放入响应对象中
return R.ok().put("importanceCountMap", importanceCountMap);
}
// 以下是新添加的功能:获取最近创建的笔记
/**
*
* @param count
* @param request HTTP
* @return
*/
@RequestMapping("/getRecentNotes")
public R getRecentNotes(@RequestParam int count, HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodebijiEntity> ew = new EntityWrapper<WodebijiEntity>();
// 添加排序条件,按创建时间降序排序
ew.orderBy("create_time", false);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的查询方法,查询最近创建的笔记
List<WodebijiEntity> recentNotes = wodebijiService.selectList(ew.last("LIMIT " + count));
// 返回成功响应,并将最近创建的笔记列表放入响应对象中
return R.ok().put("recentNotes", recentNotes);
}
// 以下是新添加的功能:根据笔记标签进行查询
/**
*
* @param params
* @param tag
* @param request HTTP
* @return
*/
@RequestMapping("/searchByTag")
public R searchByTag(@RequestParam Map<String, Object> params, @RequestParam String tag, HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodebijiEntity> ew = new EntityWrapper<WodebijiEntity>();
// 添加模糊查询条件,查询笔记标签包含指定标签的记录
ew.like("tags", tag);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodebijiService.queryPage(params, MPUtil.sort(ew, params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
// 以下是新添加的功能:批量添加笔记标签
/**
*
* @param ids ID
* @param tag
* @return
*/
@RequestMapping("/batchAddTag")
public R batchAddTag(@RequestBody Long[] ids, @RequestParam String tag) {
// 遍历ID数组
for (Long id : ids) {
// 根据ID查询笔记实体
WodebijiEntity wodebiji = wodebijiService.selectById(id);
if (wodebiji != null) {
// 如果笔记存在,则获取其原有的标签
String tags = wodebiji.getTags();
if (StringUtils.isBlank(tags)) {
// 如果原标签为空,则直接设置为新标签
wodebiji.setTags(tag);
} else {
// 如果原标签不为空,则将新标签添加到原标签后面,用逗号分隔
wodebiji.setTags(tags + "," + tag);
}
// 调用服务类的更新方法,更新笔记信息
wodebijiService.updateById(wodebiji);
}
}
// 返回成功响应
return R.ok();
}
// 以下是新添加的功能:批量删除笔记标签
/**
*
* @param ids ID
* @param tag
* @return
*/
@RequestMapping("/batchRemoveTag")
public R batchRemoveTag(@RequestBody Long[] ids, @RequestParam String tag) {
// 遍历ID数组
for (Long id : ids) {
// 根据ID查询笔记实体
WodebijiEntity wodebiji = wodebijiService.selectById(id);
if (wodebiji != null) {
// 如果笔记存在,则获取其原有的标签
String tags = wodebiji.getTags();
if (StringUtils.isNotBlank(tags)) {
// 如果原标签不为空,则将指定标签从原标签中移除
String newTags = tags.replace(tag, "").replaceAll(",+", ",").replaceAll("^,|,$", "");
wodebiji.setTags(newTags);
// 调用服务类的更新方法,更新笔记信息
wodebijiService.updateById(wodebiji);
}
}
}
// 返回成功响应
return R.ok();
}
// 以下是新添加的功能:根据笔记状态进行查询
/**
*
* @param params
* @param status
* @param request HTTP
* @return
*/
@RequestMapping("/searchByStatus")
public R searchByStatus(@RequestParam Map<String, Object> params, @RequestParam String status, HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodebijiEntity> ew = new EntityWrapper<WodebijiEntity>();
// 添加状态查询条件,查询指定状态的笔记
ew.eq("status", status);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodebijiService.queryPage(params, MPUtil.sort(ew, params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
// 以下是新添加的功能:批量更新笔记状态
/**
*
* @param ids ID
* @param status
* @return
*/
@RequestMapping("/batchUpdateStatus")
public R batchUpdateStatus(@RequestBody Long[] ids, @RequestParam String status) {
// 遍历ID数组
for (Long id : ids) {
// 根据ID查询笔记实体
WodebijiEntity wodebiji = wodebijiService.selectById(id);
if (wodebiji != null) {
// 如果笔记存在,则更新其状态
wodebiji.setStatus(status);
// 调用服务类的更新方法,更新笔记信息
wodebijiService.updateById(wodebiji);
}
}
// 返回成功响应
return R.ok();
}
/**
*
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,WodebijiEntity wodebiji,
HttpServletRequest request){
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yonghu")) {
wodebiji.setYonghuzhanghao((String)request.getSession().getAttribute("username"));
}
public R page(@RequestParam Map<String, Object> params, WodebijiEntity wodebiji,
HttpServletRequest request) {
// 从会话中获取表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是yonghu则设置用户账号为会话中的用户名
wodebiji.setYonghuzhanghao((String) request.getSession().getAttribute("username"));
}
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodebijiEntity> ew = new EntityWrapper<WodebijiEntity>();
PageUtils page = wodebijiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wodebiji), params), params));
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodebijiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wodebiji), params), params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
/**
*
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,WodebijiEntity wodebiji,
HttpServletRequest request){
public R list(@RequestParam Map<String, Object> params, WodebijiEntity wodebiji,
HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodebijiEntity> ew = new EntityWrapper<WodebijiEntity>();
PageUtils page = wodebijiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wodebiji), params), params));
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodebijiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wodebiji), params), params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
/**
/**
*
*/
@RequestMapping("/lists")
public R list( WodebijiEntity wodebiji){
EntityWrapper<WodebijiEntity> ew = new EntityWrapper<WodebijiEntity>();
ew.allEq(MPUtil.allEQMapPre( wodebiji, "wodebiji"));
public R list(WodebijiEntity wodebiji) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodebijiEntity> ew = new EntityWrapper<WodebijiEntity>();
// 设置查询条件,使所有字段与传入的实体对象相等
ew.allEq(MPUtil.allEQMapPre(wodebiji, "wodebiji"));
// 调用服务类的查询视图列表方法,获取查询结果
return R.ok().put("data", wodebijiService.selectListView(ew));
}
/**
/**
*
*/
@RequestMapping("/query")
public R query(WodebijiEntity wodebiji){
EntityWrapper< WodebijiEntity> ew = new EntityWrapper< WodebijiEntity>();
ew.allEq(MPUtil.allEQMapPre( wodebiji, "wodebiji"));
WodebijiView wodebijiView = wodebijiService.selectView(ew);
return R.ok("查询我的笔记成功").put("data", wodebijiView);
public R query(WodebijiEntity wodebiji) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodebijiEntity> ew = new EntityWrapper<WodebijiEntity>();
// 设置查询条件,使所有字段与传入的实体对象相等
ew.allEq(MPUtil.allEQMapPre(wodebiji, "wodebiji"));
// 调用服务类的查询视图方法,获取查询结果
WodebijiView wodebijiView = wodebijiService.selectView(ew);
// 返回成功响应,并将查询结果放入响应对象中
return R.ok("查询我的笔记成功").put("data", wodebijiView);
}
/**
*
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
public R info(@PathVariable("id") Long id) {
// 根据ID查询笔记实体
WodebijiEntity wodebiji = wodebijiService.selectById(id);
// 返回成功响应,并将查询结果放入响应对象中
return R.ok().put("data", wodebiji);
}
@ -112,33 +484,40 @@ public class WodebijiController {
*
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
public R detail(@PathVariable("id") Long id) {
// 根据ID查询笔记实体
WodebijiEntity wodebiji = wodebijiService.selectById(id);
// 返回成功响应,并将查询结果放入响应对象中
return R.ok().put("data", wodebiji);
}
/**
*
*/
@RequestMapping("/save")
public R save(@RequestBody WodebijiEntity wodebiji, HttpServletRequest request){
wodebiji.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(wodebiji);
public R save(@RequestBody WodebijiEntity wodebiji, HttpServletRequest request) {
// 生成一个唯一的ID由当前时间戳和一个随机数组成
wodebiji.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释:此处可进行实体对象的验证,但当前代码未启用
// ValidatorUtils.validateEntity(wodebiji);
// 调用服务类的插入方法,将笔记实体插入数据库
wodebijiService.insert(wodebiji);
// 返回成功响应
return R.ok();
}
/**
*
*/
@RequestMapping("/add")
public R add(@RequestBody WodebijiEntity wodebiji, HttpServletRequest request){
wodebiji.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(wodebiji);
public R add(@RequestBody WodebijiEntity wodebiji, HttpServletRequest request) {
// 生成一个唯一的ID由当前时间戳和一个随机数组成
wodebiji.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释:此处可进行实体对象的验证,但当前代码未启用
// ValidatorUtils.validateEntity(wodebiji);
// 调用服务类的插入方法,将笔记实体插入数据库
wodebijiService.insert(wodebiji);
// 返回成功响应
return R.ok();
}
@ -146,69 +525,85 @@ public class WodebijiController {
*
*/
@RequestMapping("/update")
public R update(@RequestBody WodebijiEntity wodebiji, HttpServletRequest request){
//ValidatorUtils.validateEntity(wodebiji);
wodebijiService.updateById(wodebiji);//全部更新
public R update(@RequestBody WodebijiEntity wodebiji, HttpServletRequest request) {
// 注释:此处可进行实体对象的验证,但当前代码未启用
// ValidatorUtils.validateEntity(wodebiji);
// 调用服务类的更新方法根据ID更新笔记实体的所有字段
wodebijiService.updateById(wodebiji); // 全部更新
// 返回成功响应
return R.ok();
}
/**
*
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
public R delete(@RequestBody Long[] ids) {
// 将ID数组转换为列表调用服务类的批量删除方法删除指定ID的笔记记录
wodebijiService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<WodebijiEntity> wrapper = new EntityWrapper<WodebijiEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yonghu")) {
wrapper.eq("yonghuzhanghao", (String)request.getSession().getAttribute("username"));
}
int count = wodebijiService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 将列名和类型放入请求参数Map中
map.put("column", columnName);
map.put("type", type);
if (type.equals("2")) {
// 创建SimpleDateFormat对象用于格式化日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 获取Calendar实例用于处理日期和时间
Calendar c = Calendar.getInstance();
// 定义提醒开始日期和结束日期
Date remindStartDate = null;
Date remindEndDate = null;
if (map.get("remindstart") != null) {
// 如果请求参数中包含提醒开始日期的偏移量,则计算提醒开始日期
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindStart);
remindStartDate = c.getTime();
// 将格式化后的提醒开始日期放入请求参数Map中
map.put("remindstart", sdf.format(remindStartDate));
}
if (map.get("remindend") != null) {
// 如果请求参数中包含提醒结束日期的偏移量,则计算提醒结束日期
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindEnd);
remindEndDate = c.getTime();
// 将格式化后的提醒结束日期放入请求参数Map中
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建MyBatis-Plus的包装器用于构建查询条件
Wrapper<WodebijiEntity> wrapper = new EntityWrapper<WodebijiEntity>();
if (map.get("remindstart") != null) {
// 如果请求参数中包含提醒开始日期,则添加大于等于该日期的查询条件
wrapper.ge(columnName, map.get("remindstart"));
}
if (map.get("remindend") != null) {
// 如果请求参数中包含提醒结束日期,则添加小于等于该日期的查询条件
wrapper.le(columnName, map.get("remindend"));
}
// 从会话中获取表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是yonghu则添加用户账号的查询条件
wrapper.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的统计方法,统计符合查询条件的笔记数量
int count = wodebijiService.selectCount(wrapper);
// 返回成功响应,并将统计结果放入响应对象中
return R.ok().put("count", count);
}
}

@ -1,110 +1,440 @@
package com.controller;
// 导入 SimpleDateFormat 类,用于格式化日期和时间
import java.text.SimpleDateFormat;
// 导入 ArrayList 类,用于创建动态数组
import java.util.ArrayList;
// 导入 Arrays 类,提供了操作数组的静态方法
import java.util.Arrays;
// 导入 Calendar 类,用于处理日期和时间
import java.util.Calendar;
// 导入 Map 接口,用于存储键值对
import java.util.Map;
// 导入 HashMap 类,实现了 Map 接口,用于存储键值对
import java.util.HashMap;
// 导入 Iterator 接口,用于遍历集合
import java.util.Iterator;
// 导入 Date 类,用于表示特定的瞬间
import java.util.Date;
// 导入 List 接口,用于存储有序的元素集合
import java.util.List;
// 导入 HttpServletRequest 类,用于封装 HTTP 请求信息
import javax.servlet.http.HttpServletRequest;
// 导入验证工具类,用于验证实体对象的合法性
import com.utils.ValidatorUtils;
// 导入 Apache Commons Lang 库中的 StringUtils 类,提供了字符串操作的实用方法
import org.apache.commons.lang3.StringUtils;
// 导入 Spring 框架的自动注入注解,用于自动装配依赖
import org.springframework.beans.factory.annotation.Autowired;
// 导入 Spring 框架的日期格式化注解,用于将请求参数转换为日期类型
import org.springframework.format.annotation.DateTimeFormat;
// 导入 Spring 框架的路径变量注解,用于获取 URL 中的路径变量
import org.springframework.web.bind.annotation.PathVariable;
// 导入 Spring 框架的请求体注解,用于将请求体中的数据绑定到方法参数上
import org.springframework.web.bind.annotation.RequestBody;
// 导入 Spring 框架的请求映射注解,用于将 HTTP 请求映射到处理方法上
import org.springframework.web.bind.annotation.RequestMapping;
// 导入 Spring 框架的请求参数注解,用于获取请求参数的值
import org.springframework.web.bind.annotation.RequestParam;
// 导入 Spring 框架的 REST 控制器注解,用于将该类标记为 RESTful 风格的控制器
import org.springframework.web.bind.annotation.RestController;
// 导入 MyBatis-Plus 的实体包装器类,用于构建查询条件
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入 MyBatis-Plus 的包装器接口,是 EntityWrapper 的父接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解,用于标记不需要进行认证的接口
import com.annotation.IgnoreAuth;
// 导入我的课程实体类,对应数据库中的我的课程表
import com.entity.WodekechengEntity;
// 导入我的课程视图类,用于展示我的课程信息
import com.entity.view.WodekechengView;
// 导入我的课程服务类,用于处理我的课程相关的业务逻辑
import com.service.WodekechengService;
// 导入令牌服务类,用于处理令牌相关的业务逻辑
import com.service.TokenService;
// 导入分页工具类,用于处理分页查询结果
import com.utils.PageUtils;
// 导入自定义的响应类,用于封装统一的响应格式
import com.utils.R;
// 导入 MD5 工具类,用于对数据进行 MD5 加密
import com.utils.MD5Util;
// 导入 MyBatis-Plus 工具类,提供了一些常用的工具方法
import com.utils.MPUtil;
// 导入通用工具类,提供了一些通用的工具方法
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:15
*/
// 将该类标记为 RESTful 风格的控制器,处理 HTTP 请求并返回 JSON 数据
@RestController
// 定义请求映射路径,所有以 /wodekecheng 开头的请求都会被该控制器处理
@RequestMapping("/wodekecheng")
public class WodekechengController {
// 使用 @Autowired 注解自动注入我的课程服务类的实例
@Autowired
private WodekechengService wodekechengService;
// 以下是新添加的功能:根据课程名称进行模糊查询
/**
*
* @param params
* @param courseName
* @param request HTTP
* @return
*/
@RequestMapping("/searchByCourseName")
public R searchByCourseName(@RequestParam Map<String, Object> params, @RequestParam String courseName, HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodekechengEntity> ew = new EntityWrapper<WodekechengEntity>();
// 添加模糊查询条件,查询课程名称包含指定关键词的记录
ew.like("course_name", courseName);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是 yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodekechengService.queryPage(params, MPUtil.sort(ew, params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
// 以下是新添加的功能:根据课程分类进行查询
/**
*
* @param params
* @param courseCategory
* @param request HTTP
* @return
*/
@RequestMapping("/searchByCourseCategory")
public R searchByCourseCategory(@RequestParam Map<String, Object> params, @RequestParam String courseCategory, HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodekechengEntity> ew = new EntityWrapper<WodekechengEntity>();
// 添加课程分类查询条件,查询指定分类的课程
ew.eq("course_category", courseCategory);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是 yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodekechengService.queryPage(params, MPUtil.sort(ew, params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
// 以下是新添加的功能:根据课程难度进行查询
/**
*
* @param params
* @param courseDifficulty
* @param request HTTP
* @return
*/
@RequestMapping("/searchByCourseDifficulty")
public R searchByCourseDifficulty(@RequestParam Map<String, Object> params, @RequestParam String courseDifficulty, HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodekechengEntity> ew = new EntityWrapper<WodekechengEntity>();
// 添加课程难度查询条件,查询指定难度的课程
ew.eq("course_difficulty", courseDifficulty);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是 yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodekechengService.queryPage(params, MPUtil.sort(ew, params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
// 以下是新添加的功能:批量更新课程状态
/**
*
* @param ids ID
* @param courseStatus
* @return
*/
@RequestMapping("/batchUpdateCourseStatus")
public R batchUpdateCourseStatus(@RequestBody Long[] ids, @RequestParam String courseStatus) {
// 遍历 ID 数组
for (Long id : ids) {
// 根据 ID 查询课程实体
WodekechengEntity wodekecheng = wodekechengService.selectById(id);
if (wodekecheng != null) {
// 如果课程存在,则更新其状态
wodekecheng.setCourseStatus(courseStatus);
// 调用服务类的更新方法,更新课程信息
wodekechengService.updateById(wodekecheng);
}
}
// 返回成功响应
return R.ok();
}
// 以下是新添加的功能:统计不同课程分类的课程数量
/**
*
* @param request HTTP
* @return
*/
@RequestMapping("/countByCourseCategory")
public R countByCourseCategory(HttpServletRequest request) {
// 创建一个 Map 对象,用于存储不同课程分类的课程数量
Map<String, Integer> courseCategoryCountMap = new HashMap<>();
// 假设课程分类有以下几种,可根据实际情况修改
List<String> courseCategories = Arrays.asList("编程", "设计", "数学", "物理", "化学");
for (String category : courseCategories) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodekechengEntity> ew = new EntityWrapper<WodekechengEntity>();
// 添加课程分类查询条件,查询指定分类的课程
ew.eq("course_category", category);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是 yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的统计方法,统计指定分类的课程数量
int count = wodekechengService.selectCount(ew);
// 将统计结果存入 Map 对象中
courseCategoryCountMap.put(category, count);
}
// 返回成功响应,并将统计结果放入响应对象中
return R.ok().put("courseCategoryCountMap", courseCategoryCountMap);
}
// 以下是新添加的功能:获取最近添加的课程
/**
*
* @param count
* @param request HTTP
* @return
*/
@RequestMapping("/getRecentCourses")
public R getRecentCourses(@RequestParam int count, HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodekechengEntity> ew = new EntityWrapper<WodekechengEntity>();
// 添加排序条件,按创建时间降序排序
ew.orderBy("create_time", false);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是 yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的查询方法,查询最近添加的课程
List<WodekechengEntity> recentCourses = wodekechengService.selectList(ew.last("LIMIT " + count));
// 返回成功响应,并将最近添加的课程列表放入响应对象中
return R.ok().put("recentCourses", recentCourses);
}
// 以下是新添加的功能:根据课程开始时间范围进行查询
/**
*
* @param params
* @param startDate
* @param endDate
* @param request HTTP
* @return
*/
@RequestMapping("/searchByCourseStartTime")
public R searchByCourseStartTime(@RequestParam Map<String, Object> params,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodekechengEntity> ew = new EntityWrapper<WodekechengEntity>();
// 添加时间范围查询条件,查询开始时间在指定范围内的课程
ew.between("course_start_time", startDate, endDate);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是 yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodekechengService.queryPage(params, MPUtil.sort(ew, params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
// 以下是新添加的功能:批量更新课程开始时间
/**
*
* @param ids ID
* @param newStartTime
* @return
*/
@RequestMapping("/batchUpdateCourseStartTime")
public R batchUpdateCourseStartTime(@RequestBody Long[] ids, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date newStartTime) {
// 遍历 ID 数组
for (Long id : ids) {
// 根据 ID 查询课程实体
WodekechengEntity wodekecheng = wodekechengService.selectById(id);
if (wodekecheng != null) {
// 如果课程存在,则更新其开始时间
wodekecheng.setCourseStartTime(newStartTime);
// 调用服务类的更新方法,更新课程信息
wodekechengService.updateById(wodekecheng);
}
}
// 返回成功响应
return R.ok();
}
// 以下是新添加的功能:根据课程结束时间范围进行查询
/**
*
* @param params
* @param startDate
* @param endDate
* @param request HTTP
* @return
*/
@RequestMapping("/searchByCourseEndTime")
public R searchByCourseEndTime(@RequestParam Map<String, Object> params,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodekechengEntity> ew = new EntityWrapper<WodekechengEntity>();
// 添加时间范围查询条件,查询结束时间在指定范围内的课程
ew.between("course_end_time", startDate, endDate);
// 获取会话中的表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是 yonghu则添加用户账号的查询条件
ew.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodekechengService.queryPage(params, MPUtil.sort(ew, params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
// 以下是新添加的功能:批量更新课程结束时间
/**
*
* @param ids ID
* @param newEndTime
* @return
*/
@RequestMapping("/batchUpdateCourseEndTime")
public R batchUpdateCourseEndTime(@RequestBody Long[] ids, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date newEndTime) {
// 遍历 ID 数组
for (Long id : ids) {
// 根据 ID 查询课程实体
WodekechengEntity wodekecheng = wodekechengService.selectById(id);
if (wodekecheng != null) {
// 如果课程存在,则更新其结束时间
wodekecheng.setCourseEndTime(newEndTime);
// 调用服务类的更新方法,更新课程信息
wodekechengService.updateById(wodekecheng);
}
}
// 返回成功响应
return R.ok();
}
/**
*
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,WodekechengEntity wodekecheng,
HttpServletRequest request){
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yonghu")) {
wodekecheng.setYonghuzhanghao((String)request.getSession().getAttribute("username"));
}
public R page(@RequestParam Map<String, Object> params, WodekechengEntity wodekecheng,
HttpServletRequest request) {
// 从会话中获取表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是 yonghu则设置用户账号为会话中的用户名
wodekecheng.setYonghuzhanghao((String) request.getSession().getAttribute("username"));
}
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodekechengEntity> ew = new EntityWrapper<WodekechengEntity>();
PageUtils page = wodekechengService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wodekecheng), params), params));
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodekechengService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wodekecheng), params), params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
/**
*
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,WodekechengEntity wodekecheng,
HttpServletRequest request){
public R list(@RequestParam Map<String, Object> params, WodekechengEntity wodekecheng,
HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodekechengEntity> ew = new EntityWrapper<WodekechengEntity>();
PageUtils page = wodekechengService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wodekecheng), params), params));
// 调用服务类的分页查询方法,传入请求参数和排序后的查询条件
PageUtils page = wodekechengService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wodekecheng), params), params));
// 返回成功响应,并将查询结果的分页信息放入响应对象中
return R.ok().put("data", page);
}
/**
/**
*
*/
@RequestMapping("/lists")
public R list( WodekechengEntity wodekecheng){
EntityWrapper<WodekechengEntity> ew = new EntityWrapper<WodekechengEntity>();
ew.allEq(MPUtil.allEQMapPre( wodekecheng, "wodekecheng"));
public R list(WodekechengEntity wodekecheng) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodekechengEntity> ew = new EntityWrapper<WodekechengEntity>();
// 设置查询条件,使所有字段与传入的实体对象相等
ew.allEq(MPUtil.allEQMapPre(wodekecheng, "wodekecheng"));
// 调用服务类的查询视图列表方法,获取查询结果
return R.ok().put("data", wodekechengService.selectListView(ew));
}
/**
/**
*
*/
@RequestMapping("/query")
public R query(WodekechengEntity wodekecheng){
EntityWrapper< WodekechengEntity> ew = new EntityWrapper< WodekechengEntity>();
ew.allEq(MPUtil.allEQMapPre( wodekecheng, "wodekecheng"));
WodekechengView wodekechengView = wodekechengService.selectView(ew);
return R.ok("查询我的课程成功").put("data", wodekechengView);
public R query(WodekechengEntity wodekecheng) {
// 创建实体包装器,用于构建查询条件
EntityWrapper<WodekechengEntity> ew = new EntityWrapper<WodekechengEntity>();
// 设置查询条件,使所有字段与传入的实体对象相等
ew.allEq(MPUtil.allEQMapPre(wodekecheng, "wodekecheng"));
// 调用服务类的查询视图方法,获取查询结果
WodekechengView wodekechengView = wodekechengService.selectView(ew);
// 返回成功响应,并将查询结果放入响应对象中
return R.ok("查询我的课程成功").put("data", wodekechengView);
}
/**
*
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
public R info(@PathVariable("id") Long id) {
// 根据 ID 查询课程实体
WodekechengEntity wodekecheng = wodekechengService.selectById(id);
// 返回成功响应,并将查询结果放入响应对象中
return R.ok().put("data", wodekecheng);
}
@ -112,33 +442,40 @@ public class WodekechengController {
*
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
public R detail(@PathVariable("id") Long id) {
// 根据 ID 查询课程实体
WodekechengEntity wodekecheng = wodekechengService.selectById(id);
// 返回成功响应,并将查询结果放入响应对象中
return R.ok().put("data", wodekecheng);
}
/**
*
*/
@RequestMapping("/save")
public R save(@RequestBody WodekechengEntity wodekecheng, HttpServletRequest request){
wodekecheng.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(wodekecheng);
public R save(@RequestBody WodekechengEntity wodekecheng, HttpServletRequest request) {
// 生成一个唯一的 ID由当前时间戳和一个随机数组成
wodekecheng.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释:此处可进行实体对象的验证,但当前代码未启用
// ValidatorUtils.validateEntity(wodekecheng);
// 调用服务类的插入方法,将课程实体插入数据库
wodekechengService.insert(wodekecheng);
// 返回成功响应
return R.ok();
}
/**
*
*/
@RequestMapping("/add")
public R add(@RequestBody WodekechengEntity wodekecheng, HttpServletRequest request){
wodekecheng.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(wodekecheng);
public R add(@RequestBody WodekechengEntity wodekecheng, HttpServletRequest request) {
// 生成一个唯一的 ID由当前时间戳和一个随机数组成
wodekecheng.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释:此处可进行实体对象的验证,但当前代码未启用
// ValidatorUtils.validateEntity(wodekecheng);
// 调用服务类的插入方法,将课程实体插入数据库
wodekechengService.insert(wodekecheng);
// 返回成功响应
return R.ok();
}
@ -146,69 +483,85 @@ public class WodekechengController {
*
*/
@RequestMapping("/update")
public R update(@RequestBody WodekechengEntity wodekecheng, HttpServletRequest request){
//ValidatorUtils.validateEntity(wodekecheng);
wodekechengService.updateById(wodekecheng);//全部更新
public R update(@RequestBody WodekechengEntity wodekecheng, HttpServletRequest request) {
// 注释:此处可进行实体对象的验证,但当前代码未启用
// ValidatorUtils.validateEntity(wodekecheng);
// 调用服务类的更新方法,根据 ID 更新课程实体的所有字段
wodekechengService.updateById(wodekecheng); // 全部更新
// 返回成功响应
return R.ok();
}
/**
*
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
public R delete(@RequestBody Long[] ids) {
// 将 ID 数组转换为列表,调用服务类的批量删除方法,删除指定 ID 的课程记录
wodekechengService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<WodekechengEntity> wrapper = new EntityWrapper<WodekechengEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yonghu")) {
wrapper.eq("yonghuzhanghao", (String)request.getSession().getAttribute("username"));
}
int count = wodekechengService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 将列名和类型放入请求参数 Map 中
map.put("column", columnName);
map.put("type", type);
if (type.equals("2")) {
// 创建 SimpleDateFormat 对象,用于格式化日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 获取 Calendar 实例,用于处理日期和时间
Calendar c = Calendar.getInstance();
// 定义提醒开始日期和结束日期
Date remindStartDate = null;
Date remindEndDate = null;
if (map.get("remindstart") != null) {
// 如果请求参数中包含提醒开始日期的偏移量,则计算提醒开始日期
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindStart);
remindStartDate = c.getTime();
// 将格式化后的提醒开始日期放入请求参数 Map 中
map.put("remindstart", sdf.format(remindStartDate));
}
if (map.get("remindend") != null) {
// 如果请求参数中包含提醒结束日期的偏移量,则计算提醒结束日期
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindEnd);
remindEndDate = c.getTime();
// 将格式化后的提醒结束日期放入请求参数 Map 中
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建 MyBatis-Plus 的包装器,用于构建查询条件
Wrapper<WodekechengEntity> wrapper = new EntityWrapper<WodekechengEntity>();
if (map.get("remindstart") != null) {
// 如果请求参数中包含提醒开始日期,则添加大于等于该日期的查询条件
wrapper.ge(columnName, map.get("remindstart"));
}
if (map.get("remindend") != null) {
// 如果请求参数中包含提醒结束日期,则添加小于等于该日期的查询条件
wrapper.le(columnName, map.get("remindend"));
}
// 从会话中获取表名
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
// 如果表名是 yonghu则添加用户账号的查询条件
wrapper.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 调用服务类的统计方法,统计符合查询条件的课程数量
int count = wodekechengService.selectCount(wrapper);
// 返回成功响应,并将统计结果放入响应对象中
return R.ok().put("count", count);
}
}

@ -1,214 +1,314 @@
package com.controller;
// 导入SimpleDateFormat类用于格式化日期和时间如将Date对象转为指定格式的字符串
import java.text.SimpleDateFormat;
// 导入ArrayList类用于创建动态数组可自动扩容的有序集合
import java.util.ArrayList;
// 导入Arrays类提供操作数组的静态方法如排序、查找、复制等
import java.util.Arrays;
// 导入Calendar类用于处理日期和时间如日期计算、设置日期字段等
import java.util.Calendar;
// 导入Map接口用于存储键值对如请求参数、响应数据等
import java.util.Map;
// 导入HashMap类实现Map接口的哈希表键值对存储允许null键值
import java.util.HashMap;
// 导入Iterator接口用于遍历集合元素如遍历List、Set等
import java.util.Iterator;
// 导入Date类用于表示特定的瞬间精确到毫秒
import java.util.Date;
// 导入List接口用于存储有序的元素集合可重复有索引
import java.util.List;
// 导入HttpServletRequest类封装HTTP请求信息如参数、头信息、会话等
import javax.servlet.http.HttpServletRequest;
// 导入自定义验证工具类(用于验证实体对象的合法性)
import com.utils.ValidatorUtils;
// 导入Apache Commons Lang的StringUtils类提供丰富的字符串操作方法
import org.apache.commons.lang3.StringUtils;
// 导入Spring的自动注入注解用于自动装配Bean如服务类
import org.springframework.beans.factory.annotation.Autowired;
// 导入Spring的日期格式化注解用于将请求参数转换为Date对象
import org.springframework.format.annotation.DateTimeFormat;
// 导入Spring的路径变量注解用于获取URL路径中的参数如/{id}
import org.springframework.web.bind.annotation.PathVariable;
// 导入Spring的请求体注解用于接收请求体中的JSON数据并绑定到实体
import org.springframework.web.bind.annotation.RequestBody;
// 导入Spring的请求映射注解用于映射URL路径到处理方法
import org.springframework.web.bind.annotation.RequestMapping;
// 导入Spring的请求参数注解用于获取请求参数的值
import org.springframework.web.bind.annotation.RequestParam;
// 导入Spring的REST控制器注解标记类为RESTful控制器返回JSON响应
import org.springframework.web.bind.annotation.RestController;
// 导入MyBatis-Plus的实体包装器类用于构建数据库查询条件
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入MyBatis-Plus的包装器接口实体包装器的父接口通用查询条件构建
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解(标记无需登录认证的接口)
import com.annotation.IgnoreAuth;
// 导入消息通知实体类(对应数据库表的实体对象)
import com.entity.XiaoxitongzhiEntity;
// 导入消息通知视图类(用于展示包含关联数据的视图对象)
import com.entity.view.XiaoxitongzhiView;
// 导入消息通知服务类(处理业务逻辑,如增删改查)
import com.service.XiaoxitongzhiService;
// 导入令牌服务类(处理用户令牌生成与验证,此处未使用,保留导入)
import com.service.TokenService;
// 导入分页工具类(封装分页查询结果,包含总页数、数据列表等)
import com.utils.PageUtils;
// 导入自定义响应类封装统一的响应格式如R.ok()、R.error()
import com.utils.R;
// 导入MD5工具类用于数据加密如密码加密此处未使用
import com.utils.MD5Util;
// 导入MyBatis-Plus工具类提供通用数据库操作工具方法
import com.utils.MPUtil;
// 导入通用工具类(包含常用辅助方法,如生成随机数、数据转换等)
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:15
*/
// 标记为RESTful控制器处理所有以/xiaoxitongzhi开头的请求
@RestController
@RequestMapping("/xiaoxitongzhi")
public class XiaoxitongzhiController {
// 自动注入消息通知服务类实例,用于调用数据库操作方法
@Autowired
private XiaoxitongzhiService xiaoxitongzhiService;
/**
*
*
* @param params
* @param xiaoxitongzhi
* @param request HTTP
* @return
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,XiaoxitongzhiEntity xiaoxitongzhi,
HttpServletRequest request){
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yonghu")) {
xiaoxitongzhi.setYonghuzhanghao((String)request.getSession().getAttribute("username"));
}
public R page(@RequestParam Map<String, Object> params, XiaoxitongzhiEntity xiaoxitongzhi,
HttpServletRequest request) {
// 从会话中获取当前用户的表名(用于权限控制,如区分普通用户和管理员)
String tableName = request.getSession().getAttribute("tableName").toString();
// 如果是普通用户表名为yonghu则添加用户账号查询条件仅查询当前用户的消息
if (tableName.equals("yonghu")) {
xiaoxitongzhi.setYonghuzhanghao((String) request.getSession().getAttribute("username"));
}
// 创建实体包装器,用于构建数据库查询条件
EntityWrapper<XiaoxitongzhiEntity> ew = new EntityWrapper<XiaoxitongzhiEntity>();
PageUtils page = xiaoxitongzhiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, xiaoxitongzhi), params), params));
// 调用服务类的分页查询方法,包含模糊查询、范围查询和排序处理
PageUtils page = xiaoxitongzhiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, xiaoxitongzhi), params), params));
// 返回成功响应,携带分页数据
return R.ok().put("data", page);
}
/**
*
*
* @param params
* @param xiaoxitongzhi
* @param request HTTP
* @return 使
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,XiaoxitongzhiEntity xiaoxitongzhi,
HttpServletRequest request){
public R list(@RequestParam Map<String, Object> params, XiaoxitongzhiEntity xiaoxitongzhi,
HttpServletRequest request) {
// 创建实体包装器(前端列表可能不需要权限过滤,直接构建查询条件)
EntityWrapper<XiaoxitongzhiEntity> ew = new EntityWrapper<XiaoxitongzhiEntity>();
PageUtils page = xiaoxitongzhiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, xiaoxitongzhi), params), params));
// 调用服务类的分页查询方法(逻辑与后端列表类似,可能权限控制不同)
PageUtils page = xiaoxitongzhiService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, xiaoxitongzhi), params), params));
// 返回成功响应,携带分页数据
return R.ok().put("data", page);
}
/**
*
/**
*
* @param xiaoxitongzhi
* @return
*/
@RequestMapping("/lists")
public R list( XiaoxitongzhiEntity xiaoxitongzhi){
EntityWrapper<XiaoxitongzhiEntity> ew = new EntityWrapper<XiaoxitongzhiEntity>();
ew.allEq(MPUtil.allEQMapPre( xiaoxitongzhi, "xiaoxitongzhi"));
public R list(XiaoxitongzhiEntity xiaoxitongzhi) {
// 创建实体包装器,设置所有字段相等的查询条件(前缀为"xiaoxitongzhi_"
EntityWrapper<XiaoxitongzhiEntity> ew = new EntityWrapper<XiaoxitongzhiEntity>();
ew.allEq(MPUtil.allEQMapPre(xiaoxitongzhi, "xiaoxitongzhi"));
// 调用服务类的查询视图列表方法(可能返回包含关联数据的视图)
return R.ok().put("data", xiaoxitongzhiService.selectListView(ew));
}
/**
*
/**
*
* @param xiaoxitongzhi
* @return
*/
@RequestMapping("/query")
public R query(XiaoxitongzhiEntity xiaoxitongzhi){
EntityWrapper< XiaoxitongzhiEntity> ew = new EntityWrapper< XiaoxitongzhiEntity>();
ew.allEq(MPUtil.allEQMapPre( xiaoxitongzhi, "xiaoxitongzhi"));
XiaoxitongzhiView xiaoxitongzhiView = xiaoxitongzhiService.selectView(ew);
return R.ok("查询消息通知成功").put("data", xiaoxitongzhiView);
public R query(XiaoxitongzhiEntity xiaoxitongzhi) {
// 创建实体包装器,设置全字段相等的查询条件
EntityWrapper<XiaoxitongzhiEntity> ew = new EntityWrapper<XiaoxitongzhiEntity>();
ew.allEq(MPUtil.allEQMapPre(xiaoxitongzhi, "xiaoxitongzhi"));
// 调用服务类的查询视图方法(返回包含关联数据的视图对象)
XiaoxitongzhiView xiaoxitongzhiView = xiaoxitongzhiService.selectView(ew);
// 返回成功响应,携带查询结果和提示信息
return R.ok("查询消息通知成功").put("data", xiaoxitongzhiView);
}
/**
*
* ID
* @param id ID
* @return 使
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
public R info(@PathVariable("id") Long id) {
// 根据ID直接查询实体对象主键查询性能较高
XiaoxitongzhiEntity xiaoxitongzhi = xiaoxitongzhiService.selectById(id);
// 返回成功响应,携带实体数据
return R.ok().put("data", xiaoxitongzhi);
}
/**
*
* ID
* @param id ID
* @return 使
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
public R detail(@PathVariable("id") Long id) {
// 根据ID查询实体对象与后端详情逻辑相同
XiaoxitongzhiEntity xiaoxitongzhi = xiaoxitongzhiService.selectById(id);
// 返回成功响应,携带实体数据
return R.ok().put("data", xiaoxitongzhi);
}
/**
*
*
* @param xiaoxitongzhi
* @param request HTTP
* @return
*/
@RequestMapping("/save")
public R save(@RequestBody XiaoxitongzhiEntity xiaoxitongzhi, HttpServletRequest request){
xiaoxitongzhi.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(xiaoxitongzhi);
public R save(@RequestBody XiaoxitongzhiEntity xiaoxitongzhi, HttpServletRequest request) {
// 生成唯一ID时间戳+随机数,确保主键唯一)
xiaoxitongzhi.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释:实体验证(此处未启用,可取消注释进行参数校验)
//ValidatorUtils.validateEntity(xiaoxitongzhi);
// 调用服务类的插入方法,将实体保存到数据库
xiaoxitongzhiService.insert(xiaoxitongzhi);
// 返回成功响应
return R.ok();
}
/**
*
*
* @param xiaoxitongzhi
* @param request HTTPID
* @return
*/
@RequestMapping("/add")
public R add(@RequestBody XiaoxitongzhiEntity xiaoxitongzhi, HttpServletRequest request){
xiaoxitongzhi.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(xiaoxitongzhi);
public R add(@RequestBody XiaoxitongzhiEntity xiaoxitongzhi, HttpServletRequest request) {
// 生成唯一ID与后端保存逻辑相同
xiaoxitongzhi.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释:实体验证(未启用)
//ValidatorUtils.validateEntity(xiaoxitongzhi);
// 调用服务类的插入方法(前端保存可能自动关联当前用户,此处代码未体现)
xiaoxitongzhiService.insert(xiaoxitongzhi);
// 返回成功响应
return R.ok();
}
/**
*
*
* @param xiaoxitongzhi
* @return
*/
@RequestMapping("/update")
public R update(@RequestBody XiaoxitongzhiEntity xiaoxitongzhi, HttpServletRequest request){
public R update(@RequestBody XiaoxitongzhiEntity xiaoxitongzhi, HttpServletRequest request) {
// 注释:实体验证(未启用)
//ValidatorUtils.validateEntity(xiaoxitongzhi);
xiaoxitongzhiService.updateById(xiaoxitongzhi);//全部更新
// 调用服务类的更新方法根据ID更新所有字段全量更新
xiaoxitongzhiService.updateById(xiaoxitongzhi); // 注释:标记为全部更新,非部分更新
// 返回成功响应
return R.ok();
}
/**
*
*
* @param ids ID
* @return
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
public R delete(@RequestBody Long[] ids) {
// 将ID数组转换为列表调用批量删除方法高效删除多条记录
xiaoxitongzhiService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*
* @param columnName
* @param type
* @param map
* @return
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<XiaoxitongzhiEntity> wrapper = new EntityWrapper<XiaoxitongzhiEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("yonghu")) {
wrapper.eq("yonghuzhanghao", (String)request.getSession().getAttribute("username"));
}
int count = xiaoxitongzhiService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 向参数Map中添加列名和类型用于后续处理
map.put("column", columnName);
map.put("type", type);
// 如果是日期范围提醒type=2基于当前日期计算提醒时间
if (type.equals("2")) {
// 创建日期格式化对象格式yyyy-MM-dd
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 获取日历实例,用于日期计算
Calendar c = Calendar.getInstance();
Date remindStartDate = null; // 提醒开始日期
Date remindEndDate = null; // 提醒结束日期
// 处理提醒开始时间(偏移天数转具体日期)
if (map.get("remindstart") != null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date()); // 设置为当前时间
c.add(Calendar.DAY_OF_MONTH, remindStart); // 添加偏移天数
remindStartDate = c.getTime(); // 获取计算后的日期
map.put("remindstart", sdf.format(remindStartDate)); // 格式化后存入参数
}
// 处理提醒结束时间(逻辑同上)
if (map.get("remindend") != null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建包装器构建查询条件
Wrapper<XiaoxitongzhiEntity> wrapper = new EntityWrapper<XiaoxitongzhiEntity>();
// 添加提醒开始时间的大于等于条件
if (map.get("remindstart") != null) {
wrapper.ge(columnName, map.get("remindstart"));
}
// 添加提醒结束时间的小于等于条件
if (map.get("remindend") != null) {
wrapper.le(columnName, map.get("remindend"));
}
// 权限控制:普通用户只能查询自己的消息
String tableName = request.getSession().getAttribute("tableName").toString();
if (tableName.equals("yonghu")) {
wrapper.eq("yonghuzhanghao", (String) request.getSession().getAttribute("username"));
}
// 统计符合条件的记录数
int count = xiaoxitongzhiService.selectCount(wrapper);
// 返回统计结果
return R.ok().put("count", count);
}
}

@ -1,206 +1,307 @@
package com.controller;
// 导入SimpleDateFormat类用于格式化日期和时间如将日期转换为指定格式的字符串
import java.text.SimpleDateFormat;
// 导入ArrayList类用于创建动态数组可动态增加或删除元素的有序集合
import java.util.ArrayList;
// 导入Arrays类提供操作数组的工具方法如排序、查找、复制数组等
import java.util.Arrays;
// 导入Calendar类用于处理日期和时间如日期计算、获取日期字段等
import java.util.Calendar;
// 导入Map接口用于存储键值对数据如请求参数、响应数据等
import java.util.Map;
// 导入HashMap类实现Map接口的哈希表支持快速查找和插入
import java.util.HashMap;
// 导入Iterator接口用于遍历集合中的元素如遍历List、Set等
import java.util.Iterator;
// 导入Date类用于表示特定的日期和时间精确到毫秒
import java.util.Date;
// 导入List接口用于存储有序的元素集合允许重复元素
import java.util.List;
// 导入HttpServletRequest类封装HTTP请求信息如请求参数、会话、头信息等
import javax.servlet.http.HttpServletRequest;
// 导入自定义验证工具类(用于验证实体对象的字段合法性)
import com.utils.ValidatorUtils;
// 导入Apache Commons Lang的StringUtils类提供字符串操作的实用方法
import org.apache.commons.lang3.StringUtils;
// 导入Spring框架的自动注入注解用于自动装配Bean如服务类
import org.springframework.beans.factory.annotation.Autowired;
// 导入Spring框架的日期格式化注解用于将请求参数转换为Date对象
import org.springframework.format.annotation.DateTimeFormat;
// 导入Spring框架的路径变量注解用于获取URL路径中的参数如/info/{id}中的id
import org.springframework.web.bind.annotation.PathVariable;
// 导入Spring框架的请求体注解用于接收请求体中的JSON数据并绑定到实体类
import org.springframework.web.bind.annotation.RequestBody;
// 导入Spring框架的请求映射注解用于将HTTP请求映射到控制器方法
import org.springframework.web.bind.annotation.RequestMapping;
// 导入Spring框架的请求参数注解用于获取请求参数的值
import org.springframework.web.bind.annotation.RequestParam;
// 导入Spring框架的REST控制器注解标记类为RESTful控制器返回JSON响应
import org.springframework.web.bind.annotation.RestController;
// 导入MyBatis-Plus的实体包装器类用于构建数据库查询条件
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入MyBatis-Plus的包装器接口实体包装器的父接口通用查询条件构建
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解(标记无需登录认证的接口)
import com.annotation.IgnoreAuth;
// 导入学科实体类(对应数据库中的学科表)
import com.entity.XuekeEntity;
// 导入学科视图类(用于展示包含关联数据的学科信息)
import com.entity.view.XuekeView;
// 导入学科服务类(处理学科相关的业务逻辑,如增删改查)
import com.service.XuekeService;
// 导入令牌服务类(处理用户认证令牌,此处未使用,保留导入)
import com.service.TokenService;
// 导入分页工具类(封装分页查询结果,包含数据列表、总页数等)
import com.utils.PageUtils;
// 导入自定义响应类(封装统一的响应格式,如成功/错误响应)
import com.utils.R;
// 导入MD5工具类用于数据加密如密码加密此处未使用
import com.utils.MD5Util;
// 导入MyBatis-Plus工具类提供通用数据库操作工具方法
import com.utils.MPUtil;
// 导入通用工具类(包含常用辅助方法,如生成随机数、数据转换等)
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:14
*/
// 标记为RESTful控制器处理所有以/xueke开头的HTTP请求
@RestController
// 定义请求映射路径,该控制器的所有接口路径均以/xueke开头
@RequestMapping("/xueke")
public class XuekeController {
// 自动注入学科服务类实例,用于调用学科相关的数据库操作方法
@Autowired
private XuekeService xuekeService;
/**
*
*
* @param params
* @param xueke
* @param request HTTP
* @return {data: }
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,XuekeEntity xueke,
HttpServletRequest request){
public R page(@RequestParam Map<String, Object> params, XuekeEntity xueke,
HttpServletRequest request) {
// 创建MyBatis-Plus实体包装器用于构建数据库查询条件
EntityWrapper<XuekeEntity> ew = new EntityWrapper<XuekeEntity>();
PageUtils page = xuekeService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, xueke), params), params));
// 调用学科服务类的分页查询方法,包含模糊查询、范围查询和排序处理
// MPUtil.likeOrEq(ew, xueke):对实体中的字段进行模糊或等于查询
// MPUtil.between(...):处理日期范围等条件
// MPUtil.sort(...):根据参数进行排序
PageUtils page = xuekeService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, xueke), params), params));
// 返回成功响应,并将分页数据放入响应体的"data"字段
return R.ok().put("data", page);
}
/**
*
*
* @param params
* @param xueke
* @param request HTTP
* @return
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,XuekeEntity xueke,
HttpServletRequest request){
public R list(@RequestParam Map<String, Object> params, XuekeEntity xueke,
HttpServletRequest request) {
// 创建实体包装器,用于构建查询条件(前端列表可能无需额外权限过滤)
EntityWrapper<XuekeEntity> ew = new EntityWrapper<XuekeEntity>();
PageUtils page = xuekeService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, xueke), params), params));
// 调用分页查询方法(逻辑与后端列表一致,复用服务类方法)
PageUtils page = xuekeService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, xueke), params), params));
// 返回分页数据响应
return R.ok().put("data", page);
}
/**
*
/**
*
* @param xueke
* @return
*/
@RequestMapping("/lists")
public R list( XuekeEntity xueke){
EntityWrapper<XuekeEntity> ew = new EntityWrapper<XuekeEntity>();
ew.allEq(MPUtil.allEQMapPre( xueke, "xueke"));
public R list(XuekeEntity xueke) {
// 创建实体包装器,设置所有字段等于实体对象的对应字段(前缀为"xueke_"避免字段冲突)
EntityWrapper<XuekeEntity> ew = new EntityWrapper<XuekeEntity>();
ew.allEq(MPUtil.allEQMapPre(xueke, "xueke"));
// 调用服务类的查询视图列表方法,返回包含关联数据的视图对象列表
return R.ok().put("data", xuekeService.selectListView(ew));
}
/**
*
/**
*
* @param xueke ID
* @return
*/
@RequestMapping("/query")
public R query(XuekeEntity xueke){
EntityWrapper< XuekeEntity> ew = new EntityWrapper< XuekeEntity>();
ew.allEq(MPUtil.allEQMapPre( xueke, "xueke"));
XuekeView xuekeView = xuekeService.selectView(ew);
return R.ok("查询学科成功").put("data", xuekeView);
public R query(XuekeEntity xueke) {
// 创建实体包装器,设置全字段相等的查询条件
EntityWrapper<XuekeEntity> ew = new EntityWrapper<XuekeEntity>();
ew.allEq(MPUtil.allEQMapPre(xueke, "xueke"));
// 调用服务类的查询视图方法,获取包含关联数据的单个视图对象
XuekeView xuekeView = xuekeService.selectView(ew);
// 返回成功响应,携带查询结果和提示信息
return R.ok("查询学科成功").put("data", xuekeView);
}
/**
*
* ID
* @param id ID/info/123
* @return
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
public R info(@PathVariable("id") Long id) {
// 根据ID直接查询学科实体主键查询性能高效
XuekeEntity xueke = xuekeService.selectById(id);
// 返回成功响应,携带学科实体数据
return R.ok().put("data", xueke);
}
/**
*
* ID
* @param id ID
* @return
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
public R detail(@PathVariable("id") Long id) {
// 根据ID查询学科实体
XuekeEntity xueke = xuekeService.selectById(id);
// 返回学科实体数据
return R.ok().put("data", xueke);
}
/**
*
*
* @param xueke
* @param request HTTP使
* @return
*/
@RequestMapping("/save")
public R save(@RequestBody XuekeEntity xueke, HttpServletRequest request){
xueke.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(xueke);
public R save(@RequestBody XuekeEntity xueke, HttpServletRequest request) {
// 生成唯一ID时间戳+随机数,确保主键唯一,避免冲突)
xueke.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释:实体验证(此处未启用,可取消注释进行字段校验)
//ValidatorUtils.validateEntity(xueke);
// 调用服务类的插入方法,将学科实体保存到数据库
xuekeService.insert(xueke);
// 返回成功响应
return R.ok();
}
/**
*
*
* @param xueke
* @param request HTTP使
* @return
*/
@RequestMapping("/add")
public R add(@RequestBody XuekeEntity xueke, HttpServletRequest request){
xueke.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(xueke);
public R add(@RequestBody XuekeEntity xueke, HttpServletRequest request) {
// 生成唯一ID与后端保存逻辑相同
xueke.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
// 注释:实体验证(未启用)
//ValidatorUtils.validateEntity(xueke);
// 插入学科数据到数据库
xuekeService.insert(xueke);
// 返回成功响应
return R.ok();
}
/**
*
*
* @param xueke
* @return
*/
@RequestMapping("/update")
public R update(@RequestBody XuekeEntity xueke, HttpServletRequest request){
public R update(@RequestBody XuekeEntity xueke, HttpServletRequest request) {
// 注释:实体验证(未启用,可根据需求添加字段校验)
//ValidatorUtils.validateEntity(xueke);
xuekeService.updateById(xueke);//全部更新
// 调用服务类的更新方法根据ID更新学科实体的所有字段全量更新
xuekeService.updateById(xueke); // 注释:标记为全部更新,非部分字段更新
// 返回成功响应
return R.ok();
}
/**
*
*
* @param ids ID[1,2,3]
* @return
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
public R delete(@RequestBody Long[] ids) {
// 将ID数组转换为列表调用批量删除方法高效删除多条记录
xuekeService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应
return R.ok();
}
/**
*
*
* @param columnName
* @param type 2
* @param map remindstart=33
* @return
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<XuekeEntity> wrapper = new EntityWrapper<XuekeEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = xuekeService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
// 向参数Map中添加列名和类型用于后续查询条件构建
map.put("column", columnName);
map.put("type", type);
// 如果是相对日期提醒type=2例如"3天后提醒"
if (type.equals("2")) {
// 创建日期格式化对象(格式:年-月-日)
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 获取日历实例,用于日期计算
Calendar c = Calendar.getInstance();
Date remindStartDate = null; // 提醒开始日期(计算后的日期)
Date remindEndDate = null; // 提醒结束日期(计算后的日期)
// 处理提醒开始时间如果有remindstart参数计算绝对日期
if (map.get("remindstart") != null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date()); // 设置为当前时间
c.add(Calendar.DAY_OF_MONTH, remindStart); // 增加指定天数
remindStartDate = c.getTime(); // 获取计算后的日期
map.put("remindstart", sdf.format(remindStartDate)); // 格式化后存入参数
}
// 处理提醒结束时间(逻辑与开始时间类似)
if (map.get("remindend") != null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建MyBatis-Plus包装器用于构建查询条件
Wrapper<XuekeEntity> wrapper = new EntityWrapper<XuekeEntity>();
// 添加提醒开始时间的大于等于条件(如提醒开始时间≥指定日期)
if (map.get("remindstart") != null) {
wrapper.ge(columnName, map.get("remindstart")); // ge: greater than or equal
}
// 添加提醒结束时间的小于等于条件(如提醒结束时间≤指定日期)
if (map.get("remindend") != null) {
wrapper.le(columnName, map.get("remindend")); // le: less than or equal
}
// 此处未添加权限控制(学科可能为公共数据,无需区分用户)
// 直接统计符合条件的记录数
int count = xuekeService.selectCount(wrapper);
// 返回成功响应,携带统计结果
return R.ok().put("count", count);
}
}

@ -1,284 +1,442 @@
// 定义包名为 com.controller
package com.controller;
// 导入用于格式化日期的 SimpleDateFormat 类
import java.text.SimpleDateFormat;
// 导入 ArrayList 类,用于创建动态数组
import java.util.ArrayList;
// 导入 Arrays 类,用于操作数组
import java.util.Arrays;
// 导入 Calendar 类,用于处理日期和时间
import java.util.Calendar;
// 导入 Map 接口,用于存储键值对
import java.util.Map;
// 导入 HashMap 类,实现 Map 接口
import java.util.HashMap;
// 导入 Iterator 接口,用于遍历集合
import java.util.Iterator;
// 导入 Date 类,用于表示日期和时间
import java.util.Date;
// 导入 List 接口,用于创建列表
import java.util.List;
// 导入 HttpServletRequest 类,用于封装 HTTP 请求信息
import javax.servlet.http.HttpServletRequest;
// 导入自定义的验证工具类
import com.utils.ValidatorUtils;
// 导入 Apache Commons Lang3 库中的 StringUtils 类,用于处理字符串
import org.apache.commons.lang3.StringUtils;
// 导入 Spring 框架的自动注入注解
import org.springframework.beans.factory.annotation.Autowired;
// 导入 Spring 框架的日期格式化注解
import org.springframework.format.annotation.DateTimeFormat;
// 导入 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;
// 导入 MyBatis-Plus 框架的实体包装器类
import com.baomidou.mybatisplus.mapper.EntityWrapper;
// 导入 MyBatis-Plus 框架的包装器接口
import com.baomidou.mybatisplus.mapper.Wrapper;
// 导入自定义的忽略认证注解
import com.annotation.IgnoreAuth;
// 导入用户实体类
import com.entity.YonghuEntity;
// 导入用户视图类
import com.entity.view.YonghuView;
// 导入用户服务类
import com.service.YonghuService;
// 导入令牌服务类
import com.service.TokenService;
// 导入自定义的分页工具类
import com.utils.PageUtils;
// 导入自定义的响应结果类
import com.utils.R;
// 导入自定义的 MD5 工具类
import com.utils.MD5Util;
// 导入自定义的 MyBatis-Plus 工具类
import com.utils.MPUtil;
// 导入自定义的通用工具类
import com.utils.CommonUtil;
/**
*
*
* @author
* @email
* @author
* @email
* @date 2021-05-09 15:46:14
*/
// 声明该类为 REST 控制器
@RestController
// 定义该控制器的请求映射路径
@RequestMapping("/yonghu")
public class YonghuController {
@Autowired
private YonghuService yonghuService;
// 自动注入用户服务类的实例
@Autowired
private YonghuService yonghuService;
// 自动注入令牌服务类的实例
@Autowired
private TokenService tokenService;
/**
*
*/
// 忽略认证注解,允许未认证用户访问该接口
@IgnoreAuth
// 定义登录接口的请求映射路径
@RequestMapping(value = "/login")
// 登录方法,接收用户名、密码、验证码和 HTTP 请求作为参数
public R login(String username, String password, String captcha, HttpServletRequest request) {
// 根据用户名查询用户实体
YonghuEntity user = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", username));
// 如果用户不存在或密码不正确
if(user==null || !user.getMima().equals(password)) {
// 返回错误信息
return R.error("账号或密码不正确");
}
// 生成用户令牌
String token = tokenService.generateToken(user.getId(), username,"yonghu", "用户" );
// 返回成功信息并携带令牌
return R.ok().put("token", token);
}
/**
*
*/
*
*/
// 忽略认证注解,允许未认证用户访问该接口
@IgnoreAuth
@RequestMapping("/register")
public R register(@RequestBody YonghuEntity yonghu){
//ValidatorUtils.validateEntity(yonghu);
YonghuEntity user = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", yonghu.getYonghuzhanghao()));
// 定义注册接口的请求映射路径
@RequestMapping("/register")
// 注册方法,接收用户实体作为请求体
public R register(@RequestBody YonghuEntity yonghu){
// 验证用户实体(注释掉,可能后续需要启用)
//ValidatorUtils.validateEntity(yonghu);
// 根据用户名查询用户实体
YonghuEntity user = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", yonghu.getYonghuzhanghao()));
// 如果用户已存在
if(user!=null) {
// 返回错误信息
return R.error("注册用户已存在");
}
// 生成用户 ID使用当前时间戳
Long uId = new Date().getTime();
// 设置用户 ID
yonghu.setId(uId);
yonghuService.insert(yonghu);
return R.ok();
}
// 插入用户实体到数据库
yonghuService.insert(yonghu);
// 返回成功信息
return R.ok();
}
/**
* 退
*/
// 定义退出接口的请求映射路径
@RequestMapping("/logout")
// 退出方法,接收 HTTP 请求作为参数
public R logout(HttpServletRequest request) {
// 使当前会话无效
request.getSession().invalidate();
// 返回退出成功信息
return R.ok("退出成功");
}
/**
* session
*/
@RequestMapping("/session")
public R getCurrUser(HttpServletRequest request){
Long id = (Long)request.getSession().getAttribute("userId");
YonghuEntity user = yonghuService.selectById(id);
return R.ok().put("data", user);
}
/**
*
*/
@IgnoreAuth
* session
*/
// 定义获取用户会话信息接口的请求映射路径
@RequestMapping("/session")
// 获取用户会话信息方法,接收 HTTP 请求作为参数
public R getCurrUser(HttpServletRequest request){
// 从会话中获取用户 ID
Long id = (Long)request.getSession().getAttribute("userId");
// 根据用户 ID 查询用户实体
YonghuEntity user = yonghuService.selectById(id);
// 返回成功信息并携带用户实体
return R.ok().put("data", user);
}
/**
*
*/
// 忽略认证注解,允许未认证用户访问该接口
@IgnoreAuth
// 定义密码重置接口的请求映射路径
@RequestMapping(value = "/resetPass")
public R resetPass(String username, HttpServletRequest request){
YonghuEntity user = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", username));
if(user==null) {
return R.error("账号不存在");
}
user.setMima("123456");
yonghuService.updateById(user);
return R.ok("密码已重置为123456");
}
/**
*
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,YonghuEntity yonghu,
HttpServletRequest request){
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
// 密码重置方法,接收用户名和 HTTP 请求作为参数
public R resetPass(String username, HttpServletRequest request){
// 根据用户名查询用户实体
YonghuEntity user = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", username));
// 如果用户不存在
if(user==null) {
// 返回错误信息
return R.error("账号不存在");
}
// 将用户密码重置为 123456
user.setMima("123456");
// 更新用户实体到数据库
yonghuService.updateById(user);
// 返回密码重置成功信息
return R.ok("密码已重置为123456");
}
/**
*
*/
// 定义后端列表接口的请求映射路径
@RequestMapping("/page")
// 后端列表方法,接收请求参数、用户实体和 HTTP 请求作为参数
public R page(@RequestParam Map<String, Object> params,YonghuEntity yonghu,
HttpServletRequest request){
// 创建用户实体的包装器
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
// 调用用户服务类的查询分页方法
PageUtils page = yonghuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yonghu), params), params));
return R.ok().put("data", page);
}
/**
*
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,YonghuEntity yonghu,
HttpServletRequest request){
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
// 返回成功信息并携带分页数据
return R.ok().put("data", page);
}
/**
*
*/
// 定义前端列表接口的请求映射路径
@RequestMapping("/list")
// 前端列表方法,接收请求参数、用户实体和 HTTP 请求作为参数
public R list(@RequestParam Map<String, Object> params,YonghuEntity yonghu,
HttpServletRequest request){
// 创建用户实体的包装器
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
// 调用用户服务类的查询分页方法
PageUtils page = yonghuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yonghu), params), params));
return R.ok().put("data", page);
}
// 返回成功信息并携带分页数据
return R.ok().put("data", page);
}
/**
*
*/
// 定义列表接口的请求映射路径
@RequestMapping("/lists")
// 列表方法,接收用户实体作为参数
public R list( YonghuEntity yonghu){
// 创建用户实体的包装器
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
// 设置包装器的查询条件
ew.allEq(MPUtil.allEQMapPre( yonghu, "yonghu"));
// 返回成功信息并携带用户视图列表
return R.ok().put("data", yonghuService.selectListView(ew));
}
/**
*
*/
@RequestMapping("/lists")
public R list( YonghuEntity yonghu){
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
ew.allEq(MPUtil.allEQMapPre( yonghu, "yonghu"));
return R.ok().put("data", yonghuService.selectListView(ew));
}
/**
*
*/
@RequestMapping("/query")
public R query(YonghuEntity yonghu){
EntityWrapper< YonghuEntity> ew = new EntityWrapper< YonghuEntity>();
ew.allEq(MPUtil.allEQMapPre( yonghu, "yonghu"));
*
*/
// 定义查询接口的请求映射路径
@RequestMapping("/query")
// 查询方法,接收用户实体作为参数
public R query(YonghuEntity yonghu){
// 创建用户实体的包装器
EntityWrapper< YonghuEntity> ew = new EntityWrapper< YonghuEntity>();
// 设置包装器的查询条件
ew.allEq(MPUtil.allEQMapPre( yonghu, "yonghu"));
// 调用用户服务类的查询视图方法
YonghuView yonghuView = yonghuService.selectView(ew);
// 返回查询成功信息并携带用户视图
return R.ok("查询用户成功").put("data", yonghuView);
}
/**
*
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
YonghuEntity yonghu = yonghuService.selectById(id);
return R.ok().put("data", yonghu);
}
/**
*
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
YonghuEntity yonghu = yonghuService.selectById(id);
return R.ok().put("data", yonghu);
}
/**
*
*/
@RequestMapping("/save")
public R save(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
yonghu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(yonghu);
YonghuEntity user = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", yonghu.getYonghuzhanghao()));
}
/**
*
*/
// 定义后端详情接口的请求映射路径
@RequestMapping("/info/{id}")
// 后端详情方法,接收用户 ID 作为路径变量
public R info(@PathVariable("id") Long id){
// 根据用户 ID 查询用户实体
YonghuEntity yonghu = yonghuService.selectById(id);
// 返回成功信息并携带用户实体
return R.ok().put("data", yonghu);
}
/**
*
*/
// 定义前端详情接口的请求映射路径
@RequestMapping("/detail/{id}")
// 前端详情方法,接收用户 ID 作为路径变量
public R detail(@PathVariable("id") Long id){
// 根据用户 ID 查询用户实体
YonghuEntity yonghu = yonghuService.selectById(id);
// 返回成功信息并携带用户实体
return R.ok().put("data", yonghu);
}
/**
*
*/
// 定义后端保存接口的请求映射路径
@RequestMapping("/save")
// 后端保存方法,接收用户实体作为请求体和 HTTP 请求作为参数
public R save(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
// 生成用户 ID使用当前时间戳加上随机数
yonghu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
// 验证用户实体(注释掉,可能后续需要启用)
//ValidatorUtils.validateEntity(yonghu);
// 根据用户名查询用户实体
YonghuEntity user = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", yonghu.getYonghuzhanghao()));
// 如果用户已存在
if(user!=null) {
// 返回错误信息
return R.error("用户已存在");
}
// 重新设置用户 ID使用当前时间戳
yonghu.setId(new Date().getTime());
yonghuService.insert(yonghu);
return R.ok();
}
/**
*
*/
@RequestMapping("/add")
public R add(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
yonghu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(yonghu);
YonghuEntity user = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", yonghu.getYonghuzhanghao()));
// 插入用户实体到数据库
yonghuService.insert(yonghu);
// 返回成功信息
return R.ok();
}
/**
*
*/
// 定义前端保存接口的请求映射路径
@RequestMapping("/add")
// 前端保存方法,接收用户实体作为请求体和 HTTP 请求作为参数
public R add(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
// 生成用户 ID使用当前时间戳加上随机数
yonghu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
// 验证用户实体(注释掉,可能后续需要启用)
//ValidatorUtils.validateEntity(yonghu);
// 根据用户名查询用户实体
YonghuEntity user = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", yonghu.getYonghuzhanghao()));
// 如果用户已存在
if(user!=null) {
// 返回错误信息
return R.error("用户已存在");
}
// 重新设置用户 ID使用当前时间戳
yonghu.setId(new Date().getTime());
yonghuService.insert(yonghu);
return R.ok();
}
/**
*
*/
@RequestMapping("/update")
public R update(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
//ValidatorUtils.validateEntity(yonghu);
yonghuService.updateById(yonghu);//全部更新
return R.ok();
}
/**
*
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
yonghuService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
*
*/
// 插入用户实体到数据库
yonghuService.insert(yonghu);
// 返回成功信息
return R.ok();
}
/**
*
*/
// 定义修改接口的请求映射路径
@RequestMapping("/update")
// 修改方法,接收用户实体作为请求体和 HTTP 请求作为参数
public R update(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
// 验证用户实体(注释掉,可能后续需要启用)
//ValidatorUtils.validateEntity(yonghu);
// 更新用户实体到数据库
yonghuService.updateById(yonghu);//全部更新
// 返回成功信息
return R.ok();
}
/**
*
*/
// 定义删除接口的请求映射路径
@RequestMapping("/delete")
// 删除方法,接收用户 ID 数组作为请求体
public R delete(@RequestBody Long[] ids){
// 批量删除用户实体
yonghuService.deleteBatchIds(Arrays.asList(ids));
// 返回成功信息
return R.ok();
}
/**
*
*/
// 定义提醒接口的请求映射路径
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
// 提醒方法接收列名、HTTP 请求、类型和请求参数作为参数
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
// 将列名放入请求参数中
map.put("column", columnName);
// 将类型放入请求参数中
map.put("type", type);
// 如果类型为 2
if(type.equals("2")) {
// 创建日期格式化对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// 创建日历对象
Calendar c = Calendar.getInstance();
// 提醒开始日期
Date remindStartDate = null;
// 提醒结束日期
Date remindEndDate = null;
// 如果请求参数中包含提醒开始时间
if(map.get("remindstart")!=null) {
// 获取提醒开始时间并转换为整数
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
// 设置日历时间为当前时间
c.setTime(new Date());
// 增加指定天数
c.add(Calendar.DAY_OF_MONTH,remindStart);
// 获取提醒开始日期
remindStartDate = c.getTime();
// 将提醒开始日期格式化后放入请求参数中
map.put("remindstart", sdf.format(remindStartDate));
}
// 如果请求参数中包含提醒结束时间
if(map.get("remindend")!=null) {
// 获取提醒结束时间并转换为整数
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
// 设置日历时间为当前时间
c.setTime(new Date());
// 增加指定天数
c.add(Calendar.DAY_OF_MONTH,remindEnd);
// 获取提醒结束日期
remindEndDate = c.getTime();
// 将提醒结束日期格式化后放入请求参数中
map.put("remindend", sdf.format(remindEndDate));
}
}
// 创建用户实体的包装器
Wrapper<YonghuEntity> wrapper = new EntityWrapper<YonghuEntity>();
// 如果请求参数中包含提醒开始时间
if(map.get("remindstart")!=null) {
// 设置包装器的大于等于查询条件
wrapper.ge(columnName, map.get("remindstart"));
}
// 如果请求参数中包含提醒结束时间
if(map.get("remindend")!=null) {
// 设置包装器的小于等于查询条件
wrapper.le(columnName, map.get("remindend"));
}
// 统计符合条件的用户数量
int count = yonghuService.selectCount(wrapper);
// 返回成功信息并携带统计数量
return R.ok().put("count", count);
}
}
}

@ -1,7 +1,11 @@
// 声明该类所属的包这里包名为com.controller
package com.controller;
// 定义一个公共类hello
public class hello {
// 主方法,程序执行的入口点
public static void main(String[] args) {
// 声明一个整数类型的变量a未初始化
int a;
}
}
}
Loading…
Cancel
Save