Compare commits
No commits in common. 'main' and '8c8cf7a8681e2f96b698a83a3a3b9eb8f37dc88b' have entirely different histories.
main
...
8c8cf7a868
@ -1,6 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<profile version="1.0">
|
|
||||||
<option name="myName" value="Project Default" />
|
|
||||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
||||||
</profile>
|
|
||||||
</component>
|
|
@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$" />
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module version="4">
|
||||||
|
<component name="FacetManager">
|
||||||
|
<facet type="Spring" name="Spring">
|
||||||
|
<configuration />
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,187 @@
|
|||||||
|
<?xml version="1.0" encoding="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">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>2.2.2.RELEASE</version>
|
||||||
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
|
</parent>
|
||||||
|
<groupId>com.jlwl</groupId>
|
||||||
|
<!-- 导入项目的名称 -->
|
||||||
|
<artifactId>jianshenfanggl</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>jianshenfanggl</name>
|
||||||
|
<description>健身房管理系统</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<fastjson.version>1.2.8</fastjson.version>
|
||||||
|
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>2.1.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--访问静态资源-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--热部署-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.shiro</groupId>
|
||||||
|
<artifactId>shiro-spring</artifactId>
|
||||||
|
<version>1.3.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus</artifactId>
|
||||||
|
<version>2.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatisplus-spring-boot-starter</artifactId>
|
||||||
|
<version>1.0.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.protobuf</groupId>
|
||||||
|
<artifactId>protobuf-java</artifactId>
|
||||||
|
<version>3.10.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>3.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.validation</groupId>
|
||||||
|
<artifactId>validation-api</artifactId>
|
||||||
|
<version>2.0.1.Final</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>2.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>4.0.12</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- FastJson -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<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.baidu.aip</groupId>
|
||||||
|
<artifactId>java-sdk</artifactId>
|
||||||
|
<version>4.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- poi高版本额外包 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-examples</artifactId>
|
||||||
|
<version>3.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-excelant</artifactId>
|
||||||
|
<version>3.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml</artifactId>
|
||||||
|
<version>3.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml-schemas</artifactId>
|
||||||
|
<version>3.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-scratchpad</artifactId>
|
||||||
|
<version>3.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alipay.sdk</groupId>
|
||||||
|
<artifactId>alipay-sdk-java</artifactId>
|
||||||
|
<version>4.10.170.ALL</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.junit.vintage</groupId>
|
||||||
|
<artifactId>junit-vintage-engine</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -1,20 +1,13 @@
|
|||||||
|
|
||||||
// 定义该文件所在的包路径
|
|
||||||
package com.annotation;
|
package com.annotation;
|
||||||
|
|
||||||
// 导入注解相关的包
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
// 忽略Token验证的注解
|
/**
|
||||||
// 被此注解标记的方法将跳过Token验证检查
|
* 忽略Token验证
|
||||||
|
*/
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
// 指定该注解只能用于方法上
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
// 指定该注解在运行时保留,可以通过反射读取
|
|
||||||
@Documented
|
@Documented
|
||||||
// 表示该注解应该被包含在JavaDoc中
|
|
||||||
public @interface IgnoreAuth {
|
public @interface IgnoreAuth {
|
||||||
// 这是一个标记注解,不包含任何属性
|
|
||||||
// 仅用于标识需要跳过Token验证的方法
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,159 +1,110 @@
|
|||||||
package com.controller; // 定义包路径
|
package com.controller;
|
||||||
|
|
||||||
// 文件操作相关类
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
// 文件未找到异常
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
// IO异常
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
// 数组工具类
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
// 日期类
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
// 哈希Map
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
// 列表接口
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
// Map接口
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
// 随机数类
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
// UUID类
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
// Apache Commons IO工具类
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
// Apache Commons字符串工具
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
// Spring自动注入注解
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
// HTTP头定义
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
// HTTP状态码
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
// 媒体类型定义
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
// ResponseEntity响应实体
|
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
// Spring资源工具
|
|
||||||
import org.springframework.util.ResourceUtils;
|
import org.springframework.util.ResourceUtils;
|
||||||
// Spring路径变量注解
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
// Spring请求体注解
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
// Spring请求映射注解
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
// Spring请求参数注解
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
// Spring REST控制器注解
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
// Spring文件上传类
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
// 自定义忽略鉴权注解
|
|
||||||
import com.annotation.IgnoreAuth;
|
import com.annotation.IgnoreAuth;
|
||||||
// MyBatis Plus实体包装器
|
|
||||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||||
// 配置实体类
|
|
||||||
import com.entity.ConfigEntity;
|
import com.entity.ConfigEntity;
|
||||||
// 自定义异常类
|
|
||||||
import com.entity.EIException;
|
import com.entity.EIException;
|
||||||
// 配置服务接口
|
|
||||||
import com.service.ConfigService;
|
import com.service.ConfigService;
|
||||||
// 自定义返回结果类
|
|
||||||
import com.utils.R;
|
import com.utils.R;
|
||||||
|
|
||||||
|
/**
|
||||||
//上传文件映射表
|
* 上传文件映射表
|
||||||
//文件上传下载控制器
|
*/
|
||||||
@RestController // 声明为RESTful控制器
|
@RestController
|
||||||
@RequestMapping("file") // 基础请求路径映射
|
@RequestMapping("file")
|
||||||
@SuppressWarnings({"unchecked","rawtypes"}) // 抑制警告
|
@SuppressWarnings({"unchecked","rawtypes"})
|
||||||
public class FileController{
|
public class FileController{
|
||||||
@Autowired // 自动注入配置服务
|
@Autowired
|
||||||
private ConfigService configService;
|
private ConfigService configService;
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
//上传文件
|
*/
|
||||||
//@param file 上传的文件对象
|
@RequestMapping("/upload")
|
||||||
//@param type 文件类型标识
|
|
||||||
//@return 上传结果
|
|
||||||
//* @throws Exception 可能抛出的异常
|
|
||||||
|
|
||||||
@RequestMapping("/upload") // 文件上传请求映射
|
|
||||||
public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {
|
public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {
|
||||||
if (file.isEmpty()) { // 检查文件是否为空
|
if (file.isEmpty()) {
|
||||||
throw new EIException("上传文件不能为空"); // 抛出文件为空异常
|
throw new EIException("上传文件不能为空");
|
||||||
}
|
}
|
||||||
// 获取文件扩展名
|
|
||||||
String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
|
String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
|
||||||
// 获取静态资源路径
|
|
||||||
File path = new File(ResourceUtils.getURL("classpath:static").getPath());
|
File path = new File(ResourceUtils.getURL("classpath:static").getPath());
|
||||||
if(!path.exists()) { // 如果路径不存在
|
if(!path.exists()) {
|
||||||
path = new File(""); // 使用当前路径
|
path = new File("");
|
||||||
}
|
}
|
||||||
// 创建上传目录
|
|
||||||
File upload = new File(path.getAbsolutePath(),"/upload/");
|
File upload = new File(path.getAbsolutePath(),"/upload/");
|
||||||
if(!upload.exists()) { // 如果目录不存在
|
if(!upload.exists()) {
|
||||||
upload.mkdirs(); // 创建目录
|
upload.mkdirs();
|
||||||
}
|
}
|
||||||
// 生成唯一文件名(时间戳+扩展名)
|
|
||||||
String fileName = new Date().getTime()+"."+fileExt;
|
String fileName = new Date().getTime()+"."+fileExt;
|
||||||
// 创建目标文件
|
|
||||||
File dest = new File(upload.getAbsolutePath()+"/"+fileName);
|
File dest = new File(upload.getAbsolutePath()+"/"+fileName);
|
||||||
// 传输文件到目标位置
|
|
||||||
file.transferTo(dest);
|
file.transferTo(dest);
|
||||||
// 如果是类型1的文件(如头像文件)
|
|
||||||
if(StringUtils.isNotBlank(type) && type.equals("1")) {
|
if(StringUtils.isNotBlank(type) && type.equals("1")) {
|
||||||
// 查询配置表中faceFile配置
|
|
||||||
ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
|
ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
|
||||||
if(configEntity==null) { // 如果配置不存在
|
if(configEntity==null) {
|
||||||
configEntity = new ConfigEntity(); // 创建新配置
|
configEntity = new ConfigEntity();
|
||||||
configEntity.setName("faceFile"); // 设置配置名
|
configEntity.setName("faceFile");
|
||||||
configEntity.setValue(fileName); // 设置文件名
|
configEntity.setValue(fileName);
|
||||||
} else {
|
} else {
|
||||||
configEntity.setValue(fileName); // 更新文件名
|
configEntity.setValue(fileName);
|
||||||
}
|
}
|
||||||
// 保存或更新配置
|
|
||||||
configService.insertOrUpdate(configEntity);
|
configService.insertOrUpdate(configEntity);
|
||||||
}
|
}
|
||||||
// 返回成功结果和文件名
|
|
||||||
return R.ok().put("file", fileName);
|
return R.ok().put("file", fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
//下载文件
|
* 下载文件
|
||||||
//@param fileName 要下载的文件名
|
*/
|
||||||
// @return 文件下载响应
|
@IgnoreAuth
|
||||||
|
@RequestMapping("/download")
|
||||||
@IgnoreAuth // 忽略权限验证
|
|
||||||
@RequestMapping("/download") // 文件下载请求映射
|
|
||||||
public ResponseEntity<byte[]> download(@RequestParam String fileName) {
|
public ResponseEntity<byte[]> download(@RequestParam String fileName) {
|
||||||
try {
|
try {
|
||||||
// 获取静态资源路径
|
|
||||||
File path = new File(ResourceUtils.getURL("classpath:static").getPath());
|
File path = new File(ResourceUtils.getURL("classpath:static").getPath());
|
||||||
if(!path.exists()) { // 如果路径不存在
|
if(!path.exists()) {
|
||||||
path = new File(""); // 使用当前路径
|
path = new File("");
|
||||||
}
|
}
|
||||||
// 获取上传目录
|
|
||||||
File upload = new File(path.getAbsolutePath(),"/upload/");
|
File upload = new File(path.getAbsolutePath(),"/upload/");
|
||||||
if(!upload.exists()) { // 如果目录不存在
|
if(!upload.exists()) {
|
||||||
upload.mkdirs(); // 创建目录
|
upload.mkdirs();
|
||||||
}
|
}
|
||||||
// 构建文件对象
|
|
||||||
File file = new File(upload.getAbsolutePath()+"/"+fileName);
|
File file = new File(upload.getAbsolutePath()+"/"+fileName);
|
||||||
if(file.exists()){ // 如果文件存在
|
if(file.exists()){
|
||||||
// 设置HTTP响应头
|
/*if(!fileService.canRead(file, SessionManager.getSessionUser())){
|
||||||
|
getResponse().sendError(403);
|
||||||
|
}*/
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); // 设置内容类型为二进制流
|
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||||
headers.setContentDispositionFormData("attachment", fileName); // 设置内容处置为附件
|
headers.setContentDispositionFormData("attachment", fileName);
|
||||||
// 返回文件内容和响应头
|
|
||||||
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
|
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
} catch (IOException e) { // 捕获IO异常
|
} catch (IOException e) {
|
||||||
e.printStackTrace(); // 打印异常堆栈
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
// 返回服务器错误响应
|
|
||||||
return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
|
return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,297 +1,300 @@
|
|||||||
// 声明当前文件所在的包路径
|
|
||||||
package com.controller;
|
package com.controller;
|
||||||
|
|
||||||
// 导入所需的Java类库
|
import java.io.File;
|
||||||
import java.io.File; // 文件操作类
|
import java.math.BigDecimal;
|
||||||
import java.math.BigDecimal; // 高精度数字计算类
|
import java.net.URL;
|
||||||
import java.net.URL; // 统一资源定位符类
|
import java.text.SimpleDateFormat;
|
||||||
import java.text.SimpleDateFormat; // 日期格式化类
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.alibaba.fastjson.JSONObject; // FastJSON的JSON对象类
|
import java.util.*;
|
||||||
import java.util.*; // 通用工具类集合
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.BeanUtils; // Spring Bean工具类
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletRequest; // HTTP请求类
|
import org.springframework.web.context.ContextLoader;
|
||||||
import org.springframework.web.context.ContextLoader; // Spring上下文加载器
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContext; // Servlet上下文接口
|
import com.service.TokenService;
|
||||||
import com.service.TokenService; // 自定义Token服务类
|
import com.utils.*;
|
||||||
import com.utils.*; // 自定义工具类包
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.InvocationTargetException; // 反射异常类
|
|
||||||
|
import com.service.DictionaryService;
|
||||||
// 导入自定义服务类
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import com.service.DictionaryService; // 字典服务类
|
import com.annotation.IgnoreAuth;
|
||||||
import org.apache.commons.lang3.StringUtils; // Apache字符串工具类
|
import org.slf4j.Logger;
|
||||||
import com.annotation.IgnoreAuth; // 自定义忽略认证注解
|
import org.slf4j.LoggerFactory;
|
||||||
import org.slf4j.Logger; // 日志接口
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.slf4j.LoggerFactory; // 日志工厂类
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.beans.factory.annotation.Autowired; // Spring自动注入注解
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.stereotype.Controller; // Spring控制器注解
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||||
import org.springframework.web.bind.annotation.*; // Spring Web注解集合
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||||
import com.baomidou.mybatisplus.mapper.EntityWrapper; // MyBatis Plus实体包装类
|
import com.entity.*;
|
||||||
import com.baomidou.mybatisplus.mapper.Wrapper; // MyBatis Plus包装接口
|
import com.entity.view.*;
|
||||||
import com.entity.*; // 实体类包
|
import com.service.*;
|
||||||
import com.entity.view.*; // 实体视图类包
|
import com.utils.PageUtils;
|
||||||
import com.service.*; // 服务接口包
|
import com.utils.R;
|
||||||
import com.utils.PageUtils; // 分页工具类
|
import com.alibaba.fastjson.*;
|
||||||
import com.utils.R; // 通用返回结果类
|
|
||||||
import com.alibaba.fastjson.*; // FastJSON工具包
|
/**
|
||||||
|
* 单页数据
|
||||||
|
* 后端接口
|
||||||
//单页数据
|
* @author
|
||||||
//后端接口控制器
|
* @email
|
||||||
//@author
|
*/
|
||||||
//@email
|
@RestController
|
||||||
|
@Controller
|
||||||
@RestController // 标识这是一个RESTful风格的控制器
|
@RequestMapping("/singleSeach")
|
||||||
@Controller // 标识这是一个Spring MVC控制器
|
|
||||||
@RequestMapping("/singleSeach") // 定义基础请求路径
|
|
||||||
public class SingleSeachController {
|
public class SingleSeachController {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SingleSeachController.class); // 日志记录器
|
private static final Logger logger = LoggerFactory.getLogger(SingleSeachController.class);
|
||||||
|
|
||||||
private static final String TABLE_NAME = "singleSeach"; // 数据库表名常量
|
private static final String TABLE_NAME = "singleSeach";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SingleSeachService singleSeachService; // 注入单页数据服务
|
private SingleSeachService singleSeachService;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TokenService tokenService; // 注入token服务
|
private TokenService tokenService;
|
||||||
|
|
||||||
// 注入其他相关服务
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DictionaryService dictionaryService; // 字典服务
|
private DictionaryService dictionaryService;//字典
|
||||||
@Autowired
|
@Autowired
|
||||||
private ForumService forumService; // 健身论坛服务
|
private ForumService forumService;//健身论坛
|
||||||
@Autowired
|
@Autowired
|
||||||
private JianshenkechengService jianshenkechengService; // 健身课程服务
|
private JianshenkechengService jianshenkechengService;//健身课程
|
||||||
@Autowired
|
@Autowired
|
||||||
private JianshenkechengCollectionService jianshenkechengCollectionService; // 课程收藏服务
|
private JianshenkechengCollectionService jianshenkechengCollectionService;//课程收藏
|
||||||
@Autowired
|
@Autowired
|
||||||
private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 课程留言服务
|
private JianshenkechengLiuyanService jianshenkechengLiuyanService;//课程留言
|
||||||
@Autowired
|
@Autowired
|
||||||
private JiaolianService jiaolianService; // 教练服务
|
private JiaolianService jiaolianService;//教练
|
||||||
@Autowired
|
@Autowired
|
||||||
private JiaolianYuyueService jiaolianYuyueService; // 教练预约申请服务
|
private JiaolianYuyueService jiaolianYuyueService;//教练预约申请
|
||||||
@Autowired
|
@Autowired
|
||||||
private NewsService newsService; // 健身资讯服务
|
private NewsService newsService;//健身资讯
|
||||||
@Autowired
|
@Autowired
|
||||||
private YonghuService yonghuService; // 用户服务
|
private YonghuService yonghuService;//用户
|
||||||
@Autowired
|
@Autowired
|
||||||
private UsersService usersService; // 管理员服务
|
private UsersService usersService;//管理员
|
||||||
|
|
||||||
|
|
||||||
//后端列表
|
|
||||||
//分页查询单页数据
|
|
||||||
//@param params 请求参数Map
|
|
||||||
//@param request HTTP请求对象
|
|
||||||
//@return 返回分页数据结果
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后端列表
|
||||||
|
*/
|
||||||
@RequestMapping("/page")
|
@RequestMapping("/page")
|
||||||
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||||
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录日志
|
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||||
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||||
if(false) // 条件判断
|
if(false)
|
||||||
return R.error(511,"永不会进入"); // 返回错误信息
|
return R.error(511,"永不会进入");
|
||||||
else if("用户".equals(role)) // 如果是用户角色
|
else if("用户".equals(role))
|
||||||
params.put("yonghuId",request.getSession().getAttribute("userId")); // 添加用户ID参数
|
params.put("yonghuId",request.getSession().getAttribute("userId"));
|
||||||
else if("教练".equals(role)) // 如果是教练角色
|
else if("教练".equals(role))
|
||||||
params.put("jiaolianId",request.getSession().getAttribute("userId")); // 添加教练ID参数
|
params.put("jiaolianId",request.getSession().getAttribute("userId"));
|
||||||
CommonUtil.checkMap(params); // 检查参数
|
CommonUtil.checkMap(params);
|
||||||
PageUtils page = singleSeachService.queryPage(params); // 调用服务层分页查询
|
PageUtils page = singleSeachService.queryPage(params);
|
||||||
|
|
||||||
// 字典表数据转换
|
//字典表数据转换
|
||||||
List<SingleSeachView> list =(List<SingleSeachView>)page.getList(); // 获取分页数据列表
|
List<SingleSeachView> list =(List<SingleSeachView>)page.getList();
|
||||||
for(SingleSeachView c:list){ // 遍历列表
|
for(SingleSeachView c:list){
|
||||||
dictionaryService.dictionaryConvert(c, request); // 转换字典表字段
|
//修改对应字典表字段
|
||||||
|
dictionaryService.dictionaryConvert(c, request);
|
||||||
}
|
}
|
||||||
return R.ok().put("data", page); // 返回成功结果和数据
|
return R.ok().put("data", page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
//后端详情
|
* 后端详情
|
||||||
//根据ID查询单条单页数据详情
|
*/
|
||||||
//@param id 数据ID
|
|
||||||
//@param request HTTP请求对象
|
|
||||||
//@return 返回查询结果
|
|
||||||
@RequestMapping("/info/{id}")
|
@RequestMapping("/info/{id}")
|
||||||
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
||||||
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录日志
|
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||||
SingleSeachEntity singleSeach = singleSeachService.selectById(id); // 根据ID查询数据
|
SingleSeachEntity singleSeach = singleSeachService.selectById(id);
|
||||||
if(singleSeach !=null){ // 如果查询到数据
|
if(singleSeach !=null){
|
||||||
SingleSeachView view = new SingleSeachView(); // 创建视图对象
|
//entity转view
|
||||||
BeanUtils.copyProperties(singleSeach, view); // 复制属性到视图对象
|
SingleSeachView view = new SingleSeachView();
|
||||||
dictionaryService.dictionaryConvert(view, request); // 转换字典表字段
|
BeanUtils.copyProperties( singleSeach , view );//把实体数据重构到view中
|
||||||
return R.ok().put("data", view); // 返回成功结果和数据
|
//修改对应字典表字段
|
||||||
|
dictionaryService.dictionaryConvert(view, request);
|
||||||
|
return R.ok().put("data", view);
|
||||||
}else {
|
}else {
|
||||||
return R.error(511,"查不到数据"); // 返回错误信息
|
return R.error(511,"查不到数据");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//后端保存
|
/**
|
||||||
//新增单页数据
|
* 后端保存
|
||||||
//@param singleSeach 单页数据实体
|
*/
|
||||||
//@param request HTTP请求对象
|
@RequestMapping("/save")
|
||||||
//@return 返回操作结果
|
|
||||||
//@RequestMapping("/save")
|
|
||||||
public R save(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request){
|
public R save(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request){
|
||||||
logger.debug("save方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString()); // 记录日志
|
logger.debug("save方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString());
|
||||||
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
|
||||||
if(false) // 条件判断
|
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||||
return R.error(511,"永远不会进入"); // 返回错误信息
|
if(false)
|
||||||
|
return R.error(511,"永远不会进入");
|
||||||
|
|
||||||
// 构建查询条件
|
|
||||||
Wrapper<SingleSeachEntity> queryWrapper = new EntityWrapper<SingleSeachEntity>()
|
Wrapper<SingleSeachEntity> queryWrapper = new EntityWrapper<SingleSeachEntity>()
|
||||||
.eq("single_seach_types",singleSeach.getSingleSeachTypes()); // 按类型查询
|
.eq("single_seach_types",singleSeach.getSingleSeachTypes())
|
||||||
|
;
|
||||||
logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句
|
|
||||||
SingleSeachEntity singleSeachEntity = singleSeachService.selectOne(queryWrapper); // 查询是否存在
|
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||||
if(singleSeachEntity==null){ // 如果不存在
|
SingleSeachEntity singleSeachEntity = singleSeachService.selectOne(queryWrapper);
|
||||||
singleSeach.setCreateTime(new Date()); // 设置创建时间
|
if(singleSeachEntity==null){
|
||||||
singleSeachService.insert(singleSeach); // 插入新数据
|
singleSeach.setCreateTime(new Date());
|
||||||
return R.ok(); // 返回成功结果
|
singleSeachService.insert(singleSeach);
|
||||||
|
return R.ok();
|
||||||
}else {
|
}else {
|
||||||
return R.error(511,"该类型已经有存在的,请删除后重新新增"); // 返回错误信息
|
return R.error(511,"该类型已经有存在的,请删除后重新新增");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//后端修改
|
/**
|
||||||
//更新单页数据
|
* 后端修改
|
||||||
//@param singleSeach 单页数据实体
|
*/
|
||||||
//@param request HTTP请求对象
|
|
||||||
//@return 返回操作结果
|
|
||||||
@RequestMapping("/update")
|
@RequestMapping("/update")
|
||||||
public R update(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
|
public R update(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
|
||||||
logger.debug("update方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString()); // 记录日志
|
logger.debug("update方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString());
|
||||||
SingleSeachEntity oldSingleSeachEntity = singleSeachService.selectById(singleSeach.getId()); // 查询原数据
|
SingleSeachEntity oldSingleSeachEntity = singleSeachService.selectById(singleSeach.getId());//查询原先数据
|
||||||
|
|
||||||
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||||
if("".equals(singleSeach.getSingleSeachPhoto()) || "null".equals(singleSeach.getSingleSeachPhoto())){ // 如果图片为空
|
// if(false)
|
||||||
singleSeach.setSingleSeachPhoto(null); // 设置为null
|
// return R.error(511,"永远不会进入");
|
||||||
|
if("".equals(singleSeach.getSingleSeachPhoto()) || "null".equals(singleSeach.getSingleSeachPhoto())){
|
||||||
|
singleSeach.setSingleSeachPhoto(null);
|
||||||
}
|
}
|
||||||
if("".equals(singleSeach.getSingleSeachContent()) || "null".equals(singleSeach.getSingleSeachContent())){ // 如果内容为空
|
if("".equals(singleSeach.getSingleSeachContent()) || "null".equals(singleSeach.getSingleSeachContent())){
|
||||||
singleSeach.setSingleSeachContent(null); // 设置为null
|
singleSeach.setSingleSeachContent(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
singleSeachService.updateById(singleSeach); // 更新数据
|
singleSeachService.updateById(singleSeach);//根据id更新
|
||||||
return R.ok(); // 返回成功结果
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//删除
|
|
||||||
//批量删除单页数据
|
/**
|
||||||
//@param ids 要删除的ID数组
|
* 删除
|
||||||
//@param request HTTP请求对象
|
*/
|
||||||
//@return 返回操作结果
|
|
||||||
@RequestMapping("/delete")
|
@RequestMapping("/delete")
|
||||||
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
|
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
|
||||||
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); // 记录日志
|
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
|
||||||
List<SingleSeachEntity> oldSingleSeachList = singleSeachService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据
|
List<SingleSeachEntity> oldSingleSeachList =singleSeachService.selectBatchIds(Arrays.asList(ids));//要删除的数据
|
||||||
singleSeachService.deleteBatchIds(Arrays.asList(ids)); // 批量删除
|
singleSeachService.deleteBatchIds(Arrays.asList(ids));
|
||||||
return R.ok(); // 返回成功结果
|
|
||||||
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//批量上传/
|
/**
|
||||||
//通过Excel批量导入数据
|
* 批量上传
|
||||||
//@param fileName Excel文件名
|
*/
|
||||||
//@param request HTTP请求对象
|
|
||||||
//@return 返回操作结果
|
|
||||||
@RequestMapping("/batchInsert")
|
@RequestMapping("/batchInsert")
|
||||||
public R save(String fileName, HttpServletRequest request){
|
public R save( String fileName, HttpServletRequest request){
|
||||||
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); // 记录日志
|
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
|
||||||
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取用户ID
|
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 创建日期格式化对象
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
//.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
|
||||||
try {
|
try {
|
||||||
List<SingleSeachEntity> singleSeachList = new ArrayList<>(); // 创建数据列表
|
List<SingleSeachEntity> singleSeachList = new ArrayList<>();//上传的东西
|
||||||
Map<String, List<String>> seachFields = new HashMap<>(); // 创建查询字段Map
|
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
|
||||||
Date date = new Date(); // 当前时间
|
Date date = new Date();
|
||||||
int lastIndexOf = fileName.lastIndexOf("."); // 获取文件后缀位置
|
int lastIndexOf = fileName.lastIndexOf(".");
|
||||||
if(lastIndexOf == -1){ // 如果没有后缀
|
if(lastIndexOf == -1){
|
||||||
return R.error(511,"该文件没有后缀"); // 返回错误信息
|
return R.error(511,"该文件没有后缀");
|
||||||
}else{
|
}else{
|
||||||
String suffix = fileName.substring(lastIndexOf); // 获取文件后缀
|
String suffix = fileName.substring(lastIndexOf);
|
||||||
if(!".xls".equals(suffix)){ // 如果不是xls文件
|
if(!".xls".equals(suffix)){
|
||||||
return R.error(511,"只支持后缀为xls的excel文件"); // 返回错误信息
|
return R.error(511,"只支持后缀为xls的excel文件");
|
||||||
}else{
|
}else{
|
||||||
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 获取文件路径
|
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
|
||||||
File file = new File(resource.getFile()); // 创建文件对象
|
File file = new File(resource.getFile());
|
||||||
if(!file.exists()){ // 如果文件不存在
|
if(!file.exists()){
|
||||||
return R.error(511,"找不到上传文件,请联系管理员"); // 返回错误信息
|
return R.error(511,"找不到上传文件,请联系管理员");
|
||||||
}else{
|
}else{
|
||||||
List<List<String>> dataList = PoiUtil.poiImport(file.getPath()); // 读取Excel文件
|
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
|
||||||
dataList.remove(0); // 删除标题行
|
dataList.remove(0);//删除第一行,因为第一行是提示
|
||||||
for(List<String> data:dataList){ // 遍历数据行
|
for(List<String> data:dataList){
|
||||||
SingleSeachEntity singleSeachEntity = new SingleSeachEntity(); // 创建实体对象
|
//循环
|
||||||
// 可以在此处设置实体属性,示例中被注释掉了
|
SingleSeachEntity singleSeachEntity = new SingleSeachEntity();
|
||||||
singleSeachList.add(singleSeachEntity); // 添加到列表
|
// singleSeachEntity.setSingleSeachName(data.get(0)); //名字 要改的
|
||||||
|
// singleSeachEntity.setSingleSeachTypes(Integer.valueOf(data.get(0))); //数据类型 要改的
|
||||||
|
// singleSeachEntity.setSingleSeachPhoto("");//详情和图片
|
||||||
|
// singleSeachEntity.setSingleSeachContent("");//详情和图片
|
||||||
|
// singleSeachEntity.setCreateTime(date);//时间
|
||||||
|
singleSeachList.add(singleSeachEntity);
|
||||||
|
|
||||||
|
|
||||||
|
//把要查询是否重复的字段放入map中
|
||||||
}
|
}
|
||||||
singleSeachService.insertBatch(singleSeachList); // 批量插入
|
|
||||||
return R.ok(); // 返回成功结果
|
//查询是否重复
|
||||||
|
singleSeachService.insertBatch(singleSeachList);
|
||||||
|
return R.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (Exception e){ // 捕获异常
|
}catch (Exception e){
|
||||||
e.printStackTrace(); // 打印异常堆栈
|
e.printStackTrace();
|
||||||
return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息
|
return R.error(511,"批量插入数据异常,请联系管理员");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//前端列表
|
|
||||||
//无需认证的分页查询
|
|
||||||
//@param params 请求参数Map
|
/**
|
||||||
//@param request HTTP请求对象
|
* 前端列表
|
||||||
//@return 返回分页数据结果
|
*/
|
||||||
@IgnoreAuth // 忽略认证
|
@IgnoreAuth
|
||||||
@RequestMapping("/list")
|
@RequestMapping("/list")
|
||||||
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||||
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录日志
|
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||||
CommonUtil.checkMap(params); // 检查参数
|
|
||||||
PageUtils page = singleSeachService.queryPage(params); // 分页查询
|
|
||||||
|
|
||||||
List<SingleSeachView> list = (List<SingleSeachView>)page.getList(); // 获取数据列表
|
CommonUtil.checkMap(params);
|
||||||
for(SingleSeachView c:list) // 遍历列表
|
PageUtils page = singleSeachService.queryPage(params);
|
||||||
dictionaryService.dictionaryConvert(c, request); // 转换字典表字段
|
|
||||||
|
|
||||||
return R.ok().put("data", page); // 返回成功结果和数据
|
//字典表数据转换
|
||||||
}
|
List<SingleSeachView> list =(List<SingleSeachView>)page.getList();
|
||||||
|
for(SingleSeachView c:list)
|
||||||
|
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
|
||||||
|
|
||||||
|
return R.ok().put("data", page);
|
||||||
|
}
|
||||||
|
|
||||||
//前端详情
|
/**
|
||||||
//根据类型查询单条数据
|
* 前端详情
|
||||||
//@param id 数据类型ID
|
*/
|
||||||
//@param request HTTP请求对象
|
|
||||||
//@return 返回查询结果
|
|
||||||
@RequestMapping("/detail/{id}")
|
@RequestMapping("/detail/{id}")
|
||||||
public R detail(@PathVariable("id") Integer id, HttpServletRequest request){
|
public R detail(@PathVariable("id") Integer id, HttpServletRequest request){
|
||||||
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录日志
|
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||||
// 根据类型查询单条数据
|
|
||||||
SingleSeachEntity singleSeach = singleSeachService.selectOne(new EntityWrapper<SingleSeachEntity>().eq("single_seach_types", id));
|
SingleSeachEntity singleSeach = singleSeachService.selectOne(new EntityWrapper<SingleSeachEntity>().eq("single_seach_types", id));
|
||||||
if(singleSeach != null) // 如果查询到数据
|
if(singleSeach != null)
|
||||||
return R.ok().put("data", singleSeach); // 返回成功结果和数据
|
return R.ok().put("data", singleSeach);
|
||||||
else
|
else
|
||||||
return R.error(511,"查不到数据"); // 返回错误信息
|
return R.error(511,"查不到数据");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//前端保存
|
/**
|
||||||
//新增单页数据
|
* 前端保存
|
||||||
//@param singleSeach 单页数据实体
|
*/
|
||||||
//@param request HTTP请求对象
|
|
||||||
//@return 返回操作结果
|
|
||||||
@RequestMapping("/add")
|
@RequestMapping("/add")
|
||||||
public R add(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request){
|
public R add(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request){
|
||||||
logger.debug("add方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString()); // 记录日志
|
logger.debug("add方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString());
|
||||||
// 构建查询条件
|
|
||||||
Wrapper<SingleSeachEntity> queryWrapper = new EntityWrapper<SingleSeachEntity>()
|
Wrapper<SingleSeachEntity> queryWrapper = new EntityWrapper<SingleSeachEntity>()
|
||||||
.eq("single_seach_types",singleSeach.getSingleSeachTypes()); // 按类型查询
|
.eq("single_seach_types",singleSeach.getSingleSeachTypes())
|
||||||
|
// .notIn("single_seach_types", new Integer[]{102})
|
||||||
logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句
|
;
|
||||||
SingleSeachEntity singleSeachEntity = singleSeachService.selectOne(queryWrapper); // 查询是否已存在
|
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||||
if(singleSeachEntity==null){ // 如果不存在
|
SingleSeachEntity singleSeachEntity = singleSeachService.selectOne(queryWrapper);
|
||||||
singleSeach.setCreateTime(new Date()); // 设置创建时间
|
if(singleSeachEntity==null){
|
||||||
singleSeachService.insert(singleSeach); // 插入新数据
|
singleSeach.setCreateTime(new Date());
|
||||||
return R.ok(); // 返回成功结果
|
singleSeachService.insert(singleSeach);
|
||||||
|
|
||||||
|
return R.ok();
|
||||||
}else {
|
}else {
|
||||||
return R.error(511,"该类型已经有存在的,请删除后重新新增"); // 返回错误信息
|
return R.error(511,"该类型已经有存在的,请删除后重新新增");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,532 +1,521 @@
|
|||||||
package com.controller; // 声明当前类所在的包路径
|
|
||||||
|
package com.controller;
|
||||||
// 导入Java IO类
|
|
||||||
import java.io.File; // 文件操作类
|
import java.io.File;
|
||||||
// 导入数学类
|
import java.math.BigDecimal;
|
||||||
import java.math.BigDecimal; // 高精度数字计算类
|
import java.net.URL;
|
||||||
// 导入网络类
|
import java.text.SimpleDateFormat;
|
||||||
import java.net.URL; // 统一资源定位符类
|
import com.alibaba.fastjson.JSONObject;
|
||||||
// 导入文本处理类
|
import java.util.*;
|
||||||
import java.text.SimpleDateFormat; // 日期格式化类
|
import org.springframework.beans.BeanUtils;
|
||||||
// 导入JSON处理类
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import com.alibaba.fastjson.JSONObject; // FastJSON对象类
|
import org.springframework.web.context.ContextLoader;
|
||||||
// 导入集合类
|
import javax.servlet.ServletContext;
|
||||||
import java.util.*; // 通用集合工具类
|
import com.service.TokenService;
|
||||||
// 导入Spring Bean工具类
|
import com.utils.*;
|
||||||
import org.springframework.beans.BeanUtils; // Bean属性复制工具类
|
import java.lang.reflect.InvocationTargetException;
|
||||||
// 导入Servlet类
|
|
||||||
import javax.servlet.http.HttpServletRequest; // HTTP请求对象
|
import com.service.DictionaryService;
|
||||||
// 导入Spring上下文类
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.web.context.ContextLoader; // Web应用上下文加载器
|
import com.annotation.IgnoreAuth;
|
||||||
// 导入Servlet上下文类
|
import org.slf4j.Logger;
|
||||||
import javax.servlet.ServletContext; // Servlet上下文对象
|
import org.slf4j.LoggerFactory;
|
||||||
// 导入自定义服务类
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import com.service.TokenService; // Token服务接口
|
import org.springframework.stereotype.Controller;
|
||||||
// 导入自定义工具类
|
import org.springframework.web.bind.annotation.*;
|
||||||
import com.utils.*; // 自定义工具类集合
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||||
// 导入反射异常类
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
||||||
import java.lang.reflect.InvocationTargetException; // 反射调用异常类
|
import com.entity.*;
|
||||||
|
import com.entity.view.*;
|
||||||
// 导入字典服务类
|
import com.service.*;
|
||||||
import com.service.DictionaryService; // 字典数据服务接口
|
import com.utils.PageUtils;
|
||||||
// 导入Apache Commons工具类
|
import com.utils.R;
|
||||||
import org.apache.commons.lang3.StringUtils; // 字符串处理工具类
|
import com.alibaba.fastjson.*;
|
||||||
// 导入自定义注解
|
|
||||||
import com.annotation.IgnoreAuth; // 忽略认证注解
|
/**
|
||||||
// 导入日志类
|
* 用户
|
||||||
import org.slf4j.Logger; // 日志接口
|
* 后端接口
|
||||||
import org.slf4j.LoggerFactory; // 日志工厂类
|
* @author
|
||||||
// 导入Spring注解
|
* @email
|
||||||
import org.springframework.beans.factory.annotation.Autowired; // 自动注入注解
|
*/
|
||||||
import org.springframework.stereotype.Controller; // 控制器注解
|
@RestController
|
||||||
import org.springframework.web.bind.annotation.*; // Web请求相关注解
|
@Controller
|
||||||
// 导入MyBatis Plus类
|
@RequestMapping("/yonghu")
|
||||||
import com.baomidou.mybatisplus.mapper.EntityWrapper; // 条件构造器
|
|
||||||
import com.baomidou.mybatisplus.mapper.Wrapper; // 条件构造器接口
|
|
||||||
// 导入实体类
|
|
||||||
import com.entity.*; // 实体类集合
|
|
||||||
import com.entity.view.*; // 视图实体类集合
|
|
||||||
// 导入服务接口
|
|
||||||
import com.service.*; // 服务接口集合
|
|
||||||
// 导入分页工具类
|
|
||||||
import com.utils.PageUtils; // 分页工具类
|
|
||||||
// 导入返回结果类
|
|
||||||
import com.utils.R; // 统一返回结果类
|
|
||||||
// 导入FastJSON类
|
|
||||||
import com.alibaba.fastjson.*; // FastJSON工具类
|
|
||||||
|
|
||||||
|
|
||||||
//用户控制器
|
|
||||||
// 处理用户相关操作的RESTful接口
|
|
||||||
|
|
||||||
@RestController // 标识为RESTful控制器
|
|
||||||
@Controller // 标识为Spring MVC控制器
|
|
||||||
@RequestMapping("/yonghu") // 基础请求路径
|
|
||||||
public class YonghuController {
|
public class YonghuController {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(YonghuController.class); // 日志记录器
|
private static final Logger logger = LoggerFactory.getLogger(YonghuController.class);
|
||||||
|
|
||||||
private static final String TABLE_NAME = "yonghu"; // 数据库表名常量
|
private static final String TABLE_NAME = "yonghu";
|
||||||
|
|
||||||
@Autowired // 自动注入用户服务
|
@Autowired
|
||||||
private YonghuService yonghuService;
|
private YonghuService yonghuService;
|
||||||
|
|
||||||
@Autowired // 自动注入Token服务
|
|
||||||
|
@Autowired
|
||||||
private TokenService tokenService;
|
private TokenService tokenService;
|
||||||
|
|
||||||
// 注入其他相关服务
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DictionaryService dictionaryService; // 字典服务
|
private DictionaryService dictionaryService;//字典
|
||||||
@Autowired
|
@Autowired
|
||||||
private ForumService forumService; // 健身论坛服务
|
private ForumService forumService;//健身论坛
|
||||||
@Autowired
|
@Autowired
|
||||||
private JianshenkechengService jianshenkechengService; // 健身课程服务
|
private JianshenkechengService jianshenkechengService;//健身课程
|
||||||
@Autowired
|
@Autowired
|
||||||
private JianshenkechengCollectionService jianshenkechengCollectionService; // 课程收藏服务
|
private JianshenkechengCollectionService jianshenkechengCollectionService;//课程收藏
|
||||||
@Autowired
|
@Autowired
|
||||||
private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 课程留言服务
|
private JianshenkechengLiuyanService jianshenkechengLiuyanService;//课程留言
|
||||||
@Autowired
|
@Autowired
|
||||||
private JiaolianService jiaolianService; // 教练服务
|
private JiaolianService jiaolianService;//教练
|
||||||
@Autowired
|
@Autowired
|
||||||
private JiaolianYuyueService jiaolianYuyueService; // 教练预约服务
|
private JiaolianYuyueService jiaolianYuyueService;//教练预约申请
|
||||||
@Autowired
|
@Autowired
|
||||||
private NewsService newsService; // 健身资讯服务
|
private NewsService newsService;//健身资讯
|
||||||
@Autowired
|
@Autowired
|
||||||
private SingleSeachService singleSeachService; // 单页数据服务
|
private SingleSeachService singleSeachService;//单页数据
|
||||||
@Autowired
|
@Autowired
|
||||||
private UsersService usersService; // 管理员服务
|
private UsersService usersService;//管理员
|
||||||
|
|
||||||
//后端分页列表
|
|
||||||
//@param params 请求参数Map
|
/**
|
||||||
//@param request HTTP请求对象
|
* 后端列表
|
||||||
//@return 分页结果
|
*/
|
||||||
@RequestMapping("/page")
|
@RequestMapping("/page")
|
||||||
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||||
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||||
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||||
if(false) // 条件判断
|
if(false)
|
||||||
return R.error(511,"永不会进入"); // 返回错误信息
|
return R.error(511,"永不会进入");
|
||||||
else if("用户".equals(role)) // 如果是用户角色
|
else if("用户".equals(role))
|
||||||
params.put("yonghuId",request.getSession().getAttribute("userId")); // 添加用户ID参数
|
params.put("yonghuId",request.getSession().getAttribute("userId"));
|
||||||
else if("教练".equals(role)) // 如果是教练角色
|
else if("教练".equals(role))
|
||||||
params.put("jiaolianId",request.getSession().getAttribute("userId")); // 添加教练ID参数
|
params.put("jiaolianId",request.getSession().getAttribute("userId"));
|
||||||
params.put("dataDeleteStart",1);params.put("dataDeleteEnd",1); // 设置逻辑删除条件
|
params.put("dataDeleteStart",1);params.put("dataDeleteEnd",1);
|
||||||
CommonUtil.checkMap(params); // 检查参数
|
CommonUtil.checkMap(params);
|
||||||
PageUtils page = yonghuService.queryPage(params); // 分页查询
|
PageUtils page = yonghuService.queryPage(params);
|
||||||
|
|
||||||
// 字典表数据转换
|
//字典表数据转换
|
||||||
List<YonghuView> list =(List<YonghuView>)page.getList(); // 获取分页数据
|
List<YonghuView> list =(List<YonghuView>)page.getList();
|
||||||
for(YonghuView c:list){ // 遍历数据
|
for(YonghuView c:list){
|
||||||
dictionaryService.dictionaryConvert(c, request); // 转换字典表字段
|
//修改对应字典表字段
|
||||||
}
|
dictionaryService.dictionaryConvert(c, request);
|
||||||
return R.ok().put("data", page); // 返回分页结果
|
}
|
||||||
}
|
return R.ok().put("data", page);
|
||||||
|
}
|
||||||
|
|
||||||
//后端详情
|
/**
|
||||||
//@param id 用户ID
|
* 后端详情
|
||||||
//@param request HTTP请求对象
|
*/
|
||||||
//@return 用户详情
|
|
||||||
@RequestMapping("/info/{id}")
|
@RequestMapping("/info/{id}")
|
||||||
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
||||||
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||||
YonghuEntity yonghu = yonghuService.selectById(id); // 根据ID查询用户
|
YonghuEntity yonghu = yonghuService.selectById(id);
|
||||||
if(yonghu !=null){ // 如果查询到数据
|
if(yonghu !=null){
|
||||||
YonghuView view = new YonghuView(); // 创建视图对象
|
//entity转view
|
||||||
BeanUtils.copyProperties(yonghu, view); // 复制属性到视图对象
|
YonghuView view = new YonghuView();
|
||||||
dictionaryService.dictionaryConvert(view, request); // 转换字典表字段
|
BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中
|
||||||
return R.ok().put("data", view); // 返回成功结果
|
//修改对应字典表字段
|
||||||
|
dictionaryService.dictionaryConvert(view, request);
|
||||||
|
return R.ok().put("data", view);
|
||||||
}else {
|
}else {
|
||||||
return R.error(511,"查不到数据"); // 返回错误信息
|
return R.error(511,"查不到数据");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//后端保存用户
|
/**
|
||||||
//@param yonghu 用户实体
|
* 后端保存
|
||||||
//@param request HTTP请求对象
|
*/
|
||||||
//@return 操作结果
|
|
||||||
@RequestMapping("/save")
|
@RequestMapping("/save")
|
||||||
public R save(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
|
public R save(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
|
||||||
logger.debug("save方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
|
logger.debug("save方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
|
||||||
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
|
||||||
if(false) // 条件判断
|
|
||||||
return R.error(511,"永远不会进入"); // 返回错误信息
|
|
||||||
|
|
||||||
// 构建查询条件:检查用户名、手机号、身份证号是否已存在
|
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||||
|
if(false)
|
||||||
|
return R.error(511,"永远不会进入");
|
||||||
|
|
||||||
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
|
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
|
||||||
.eq("username", yonghu.getUsername()) // 用户名条件
|
.eq("username", yonghu.getUsername())
|
||||||
.or() // 或条件
|
.or()
|
||||||
.eq("yonghu_phone", yonghu.getYonghuPhone()) // 手机号条件
|
.eq("yonghu_phone", yonghu.getYonghuPhone())
|
||||||
.or() // 或条件
|
.or()
|
||||||
.eq("yonghu_id_number", yonghu.getYonghuIdNumber()) // 身份证号条件
|
.eq("yonghu_id_number", yonghu.getYonghuIdNumber())
|
||||||
.eq("data_delete", 1) // 未删除条件
|
.eq("data_delete", 1)
|
||||||
;
|
;
|
||||||
|
|
||||||
logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句
|
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||||
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper); // 查询是否存在
|
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
|
||||||
if(yonghuEntity==null){ // 如果不存在
|
if(yonghuEntity==null){
|
||||||
yonghu.setDataDelete(1); // 设置未删除状态
|
yonghu.setDataDelete(1);
|
||||||
yonghu.setInsertTime(new Date()); // 设置插入时间
|
yonghu.setInsertTime(new Date());
|
||||||
yonghu.setCreateTime(new Date()); // 设置创建时间
|
yonghu.setCreateTime(new Date());
|
||||||
yonghu.setPassword("123456"); // 设置默认密码
|
yonghu.setPassword("123456");
|
||||||
yonghuService.insert(yonghu); // 插入新用户
|
yonghuService.insert(yonghu);
|
||||||
return R.ok(); // 返回成功结果
|
return R.ok();
|
||||||
}else {
|
}else {
|
||||||
return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用"); // 返回错误信息
|
return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
//后端修改用户
|
* 后端修改
|
||||||
//@param yonghu 用户实体
|
*/
|
||||||
//@param request HTTP请求对象
|
|
||||||
//@return 操作结果
|
|
||||||
@RequestMapping("/update")
|
@RequestMapping("/update")
|
||||||
public R update(@RequestBody YonghuEntity yonghu, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
|
public R update(@RequestBody YonghuEntity yonghu, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
|
||||||
logger.debug("update方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
|
logger.debug("update方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
|
||||||
YonghuEntity oldYonghuEntity = yonghuService.selectById(yonghu.getId()); // 查询原数据
|
YonghuEntity oldYonghuEntity = yonghuService.selectById(yonghu.getId());//查询原先数据
|
||||||
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
|
||||||
|
|
||||||
if("".equals(yonghu.getYonghuPhoto()) || "null".equals(yonghu.getYonghuPhoto())){ // 如果图片为空
|
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||||
yonghu.setYonghuPhoto(null); // 设置为null
|
// if(false)
|
||||||
|
// return R.error(511,"永远不会进入");
|
||||||
|
if("".equals(yonghu.getYonghuPhoto()) || "null".equals(yonghu.getYonghuPhoto())){
|
||||||
|
yonghu.setYonghuPhoto(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
yonghuService.updateById(yonghu); // 更新用户信息
|
yonghuService.updateById(yonghu);//根据id更新
|
||||||
return R.ok(); // 返回成功结果
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//删除用户(逻辑删除)
|
|
||||||
//@param ids 用户ID数组
|
/**
|
||||||
//@param request HTTP请求对象
|
* 删除
|
||||||
//@return 操作结果
|
*/
|
||||||
@RequestMapping("/delete")
|
@RequestMapping("/delete")
|
||||||
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
|
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
|
||||||
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
|
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
|
||||||
List<YonghuEntity> oldYonghuList = yonghuService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据
|
List<YonghuEntity> oldYonghuList =yonghuService.selectBatchIds(Arrays.asList(ids));//要删除的数据
|
||||||
ArrayList<YonghuEntity> list = new ArrayList<>(); // 创建更新列表
|
ArrayList<YonghuEntity> list = new ArrayList<>();
|
||||||
for(Integer id:ids){ // 遍历ID数组
|
for(Integer id:ids){
|
||||||
YonghuEntity yonghuEntity = new YonghuEntity(); // 创建用户实体
|
YonghuEntity yonghuEntity = new YonghuEntity();
|
||||||
yonghuEntity.setId(id); // 设置ID
|
yonghuEntity.setId(id);
|
||||||
yonghuEntity.setDataDelete(2); // 设置删除状态
|
yonghuEntity.setDataDelete(2);
|
||||||
list.add(yonghuEntity); // 添加到列表
|
list.add(yonghuEntity);
|
||||||
}
|
}
|
||||||
if(list != null && list.size() >0){ // 如果有数据需要更新
|
if(list != null && list.size() >0){
|
||||||
yonghuService.updateBatchById(list); // 批量更新
|
yonghuService.updateBatchById(list);
|
||||||
}
|
}
|
||||||
return R.ok(); // 返回成功结果
|
|
||||||
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//批量导入用户数据
|
/**
|
||||||
//@param fileName Excel文件名
|
* 批量上传
|
||||||
//@param request HTTP请求对象
|
*/
|
||||||
//@return 导入结果
|
|
||||||
@RequestMapping("/batchInsert")
|
@RequestMapping("/batchInsert")
|
||||||
public R save(String fileName, HttpServletRequest request){
|
public R save( String fileName, HttpServletRequest request){
|
||||||
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
|
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
|
||||||
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取当前用户ID
|
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 创建日期格式化对象
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
//.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
|
||||||
try {
|
try {
|
||||||
List<YonghuEntity> yonghuList = new ArrayList<>(); // 创建用户列表
|
List<YonghuEntity> yonghuList = new ArrayList<>();//上传的东西
|
||||||
Map<String, List<String>> seachFields = new HashMap<>(); // 创建查重字段Map
|
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
|
||||||
Date date = new Date(); // 当前时间
|
Date date = new Date();
|
||||||
int lastIndexOf = fileName.lastIndexOf("."); // 获取文件后缀位置
|
int lastIndexOf = fileName.lastIndexOf(".");
|
||||||
if(lastIndexOf == -1){ // 如果没有后缀
|
if(lastIndexOf == -1){
|
||||||
return R.error(511,"该文件没有后缀"); // 返回错误信息
|
return R.error(511,"该文件没有后缀");
|
||||||
}else{
|
}else{
|
||||||
String suffix = fileName.substring(lastIndexOf); // 获取文件后缀
|
String suffix = fileName.substring(lastIndexOf);
|
||||||
if(!".xls".equals(suffix)){ // 如果不是xls文件
|
if(!".xls".equals(suffix)){
|
||||||
return R.error(511,"只支持后缀为xls的excel文件"); // 返回错误信息
|
return R.error(511,"只支持后缀为xls的excel文件");
|
||||||
}else{
|
}else{
|
||||||
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 获取文件路径
|
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
|
||||||
File file = new File(resource.getFile()); // 创建文件对象
|
File file = new File(resource.getFile());
|
||||||
if(!file.exists()){ // 如果文件不存在
|
if(!file.exists()){
|
||||||
return R.error(511,"找不到上传文件,请联系管理员"); // 返回错误信息
|
return R.error(511,"找不到上传文件,请联系管理员");
|
||||||
}else{
|
}else{
|
||||||
List<List<String>> dataList = PoiUtil.poiImport(file.getPath()); // 读取Excel文件
|
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
|
||||||
dataList.remove(0); // 删除标题行
|
dataList.remove(0);//删除第一行,因为第一行是提示
|
||||||
for(List<String> data:dataList){ // 遍历数据行
|
for(List<String> data:dataList){
|
||||||
YonghuEntity yonghuEntity = new YonghuEntity(); // 创建用户实体
|
//循环
|
||||||
// 可以在此处设置实体属性,示例中被注释掉了
|
YonghuEntity yonghuEntity = new YonghuEntity();
|
||||||
yonghuList.add(yonghuEntity); // 添加到列表
|
// yonghuEntity.setUsername(data.get(0)); //账户 要改的
|
||||||
|
// yonghuEntity.setPassword("123456");//密码
|
||||||
// 构建查重字段Map
|
// yonghuEntity.setYonghuName(data.get(0)); //用户名称 要改的
|
||||||
// 账户查重
|
// yonghuEntity.setYonghuPhone(data.get(0)); //用户手机号 要改的
|
||||||
|
// yonghuEntity.setYonghuIdNumber(data.get(0)); //用户身份证号 要改的
|
||||||
|
// yonghuEntity.setYonghuPhoto("");//详情和图片
|
||||||
|
// yonghuEntity.setSexTypes(Integer.valueOf(data.get(0))); //性别 要改的
|
||||||
|
// yonghuEntity.setYonghuEmail(data.get(0)); //用户邮箱 要改的
|
||||||
|
// yonghuEntity.setNewMoney(data.get(0)); //现有余额 要改的
|
||||||
|
// yonghuEntity.setDataDelete(1);//逻辑删除字段
|
||||||
|
// yonghuEntity.setInsertTime(date);//时间
|
||||||
|
// yonghuEntity.setCreateTime(date);//时间
|
||||||
|
yonghuList.add(yonghuEntity);
|
||||||
|
|
||||||
|
|
||||||
|
//把要查询是否重复的字段放入map中
|
||||||
|
//账户
|
||||||
if(seachFields.containsKey("username")){
|
if(seachFields.containsKey("username")){
|
||||||
List<String> username = seachFields.get("username");
|
List<String> username = seachFields.get("username");
|
||||||
username.add(data.get(0)); // 添加用户名
|
username.add(data.get(0));//要改的
|
||||||
}else{
|
}else{
|
||||||
List<String> username = new ArrayList<>();
|
List<String> username = new ArrayList<>();
|
||||||
username.add(data.get(0)); // 添加用户名
|
username.add(data.get(0));//要改的
|
||||||
seachFields.put("username",username); // 放入Map
|
seachFields.put("username",username);
|
||||||
}
|
}
|
||||||
// 手机号查重
|
//用户手机号
|
||||||
if(seachFields.containsKey("yonghuPhone")){
|
if(seachFields.containsKey("yonghuPhone")){
|
||||||
List<String> yonghuPhone = seachFields.get("yonghuPhone");
|
List<String> yonghuPhone = seachFields.get("yonghuPhone");
|
||||||
yonghuPhone.add(data.get(0)); // 添加手机号
|
yonghuPhone.add(data.get(0));//要改的
|
||||||
}else{
|
}else{
|
||||||
List<String> yonghuPhone = new ArrayList<>();
|
List<String> yonghuPhone = new ArrayList<>();
|
||||||
yonghuPhone.add(data.get(0)); // 添加手机号
|
yonghuPhone.add(data.get(0));//要改的
|
||||||
seachFields.put("yonghuPhone",yonghuPhone); // 放入Map
|
seachFields.put("yonghuPhone",yonghuPhone);
|
||||||
}
|
}
|
||||||
// 身份证号查重
|
//用户身份证号
|
||||||
if(seachFields.containsKey("yonghuIdNumber")){
|
if(seachFields.containsKey("yonghuIdNumber")){
|
||||||
List<String> yonghuIdNumber = seachFields.get("yonghuIdNumber");
|
List<String> yonghuIdNumber = seachFields.get("yonghuIdNumber");
|
||||||
yonghuIdNumber.add(data.get(0)); // 添加身份证号
|
yonghuIdNumber.add(data.get(0));//要改的
|
||||||
}else{
|
}else{
|
||||||
List<String> yonghuIdNumber = new ArrayList<>();
|
List<String> yonghuIdNumber = new ArrayList<>();
|
||||||
yonghuIdNumber.add(data.get(0)); // 添加身份证号
|
yonghuIdNumber.add(data.get(0));//要改的
|
||||||
seachFields.put("yonghuIdNumber",yonghuIdNumber); // 放入Map
|
seachFields.put("yonghuIdNumber",yonghuIdNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查重验证
|
//查询是否重复
|
||||||
// 验证用户名是否重复
|
//账户
|
||||||
List<YonghuEntity> yonghuEntities_username = yonghuService.selectList(
|
List<YonghuEntity> yonghuEntities_username = yonghuService.selectList(new EntityWrapper<YonghuEntity>().in("username", seachFields.get("username")).eq("data_delete", 1));
|
||||||
new EntityWrapper<YonghuEntity>().in("username", seachFields.get("username")).eq("data_delete", 1));
|
if(yonghuEntities_username.size() >0 ){
|
||||||
if(yonghuEntities_username.size() >0 ){ // 如果有重复
|
ArrayList<String> repeatFields = new ArrayList<>();
|
||||||
ArrayList<String> repeatFields = new ArrayList<>(); // 创建重复字段列表
|
for(YonghuEntity s:yonghuEntities_username){
|
||||||
for(YonghuEntity s:yonghuEntities_username){ // 遍历重复数据
|
repeatFields.add(s.getUsername());
|
||||||
repeatFields.add(s.getUsername()); // 添加重复用户名
|
|
||||||
}
|
}
|
||||||
return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString()); // 返回错误信息
|
return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString());
|
||||||
}
|
}
|
||||||
// 验证手机号是否重复
|
//用户手机号
|
||||||
List<YonghuEntity> yonghuEntities_yonghuPhone = yonghuService.selectList(
|
List<YonghuEntity> yonghuEntities_yonghuPhone = yonghuService.selectList(new EntityWrapper<YonghuEntity>().in("yonghu_phone", seachFields.get("yonghuPhone")).eq("data_delete", 1));
|
||||||
new EntityWrapper<YonghuEntity>().in("yonghu_phone", seachFields.get("yonghuPhone")).eq("data_delete", 1));
|
if(yonghuEntities_yonghuPhone.size() >0 ){
|
||||||
if(yonghuEntities_yonghuPhone.size() >0 ){ // 如果有重复
|
ArrayList<String> repeatFields = new ArrayList<>();
|
||||||
ArrayList<String> repeatFields = new ArrayList<>(); // 创建重复字段列表
|
for(YonghuEntity s:yonghuEntities_yonghuPhone){
|
||||||
for(YonghuEntity s:yonghuEntities_yonghuPhone){ // 遍历重复数据
|
repeatFields.add(s.getYonghuPhone());
|
||||||
repeatFields.add(s.getYonghuPhone()); // 添加重复手机号
|
|
||||||
}
|
}
|
||||||
return R.error(511,"数据库的该表中的 [用户手机号] 字段已经存在 存在数据为:"+repeatFields.toString()); // 返回错误信息
|
return R.error(511,"数据库的该表中的 [用户手机号] 字段已经存在 存在数据为:"+repeatFields.toString());
|
||||||
}
|
}
|
||||||
// 验证身份证号是否重复
|
//用户身份证号
|
||||||
List<YonghuEntity> yonghuEntities_yonghuIdNumber = yonghuService.selectList(
|
List<YonghuEntity> yonghuEntities_yonghuIdNumber = yonghuService.selectList(new EntityWrapper<YonghuEntity>().in("yonghu_id_number", seachFields.get("yonghuIdNumber")).eq("data_delete", 1));
|
||||||
new EntityWrapper<YonghuEntity>().in("yonghu_id_number", seachFields.get("yonghuIdNumber")).eq("data_delete", 1));
|
if(yonghuEntities_yonghuIdNumber.size() >0 ){
|
||||||
if(yonghuEntities_yonghuIdNumber.size() >0 ){ // 如果有重复
|
ArrayList<String> repeatFields = new ArrayList<>();
|
||||||
ArrayList<String> repeatFields = new ArrayList<>(); // 创建重复字段列表
|
for(YonghuEntity s:yonghuEntities_yonghuIdNumber){
|
||||||
for(YonghuEntity s:yonghuEntities_yonghuIdNumber){ // 遍历重复数据
|
repeatFields.add(s.getYonghuIdNumber());
|
||||||
repeatFields.add(s.getYonghuIdNumber()); // 添加重复身份证号
|
|
||||||
}
|
}
|
||||||
return R.error(511,"数据库的该表中的 [用户身份证号] 字段已经存在 存在数据为:"+repeatFields.toString()); // 返回错误信息
|
return R.error(511,"数据库的该表中的 [用户身份证号] 字段已经存在 存在数据为:"+repeatFields.toString());
|
||||||
}
|
}
|
||||||
yonghuService.insertBatch(yonghuList); // 批量插入数据
|
yonghuService.insertBatch(yonghuList);
|
||||||
return R.ok(); // 返回成功结果
|
return R.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (Exception e){ // 捕获异常
|
}catch (Exception e){
|
||||||
e.printStackTrace(); // 打印异常堆栈
|
e.printStackTrace();
|
||||||
return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息
|
return R.error(511,"批量插入数据异常,请联系管理员");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
//用户登录
|
* 登录
|
||||||
//@param username 用户名
|
*/
|
||||||
//@param password 密码
|
@IgnoreAuth
|
||||||
//@param captcha 验证码
|
|
||||||
//@param request HTTP请求对象
|
|
||||||
//@return 登录结果
|
|
||||||
@IgnoreAuth // 忽略认证
|
|
||||||
@RequestMapping(value = "/login")
|
@RequestMapping(value = "/login")
|
||||||
public R login(String username, String password, String captcha, HttpServletRequest request) {
|
public R login(String username, String password, String captcha, HttpServletRequest request) {
|
||||||
YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("username", username)); // 根据用户名查询用户
|
YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("username", username));
|
||||||
if(yonghu==null || !yonghu.getPassword().equals(password)) // 验证用户名和密码
|
if(yonghu==null || !yonghu.getPassword().equals(password))
|
||||||
return R.error("账号或密码不正确"); // 返回错误信息
|
return R.error("账号或密码不正确");
|
||||||
else if(yonghu.getDataDelete() != 1) // 检查是否被删除
|
else if(yonghu.getDataDelete() != 1)
|
||||||
return R.error("账户已被删除"); // 返回错误信息
|
return R.error("账户已被删除");
|
||||||
String token = tokenService.generateToken(yonghu.getId(),username, "yonghu", "用户"); // 生成Token
|
String token = tokenService.generateToken(yonghu.getId(),username, "yonghu", "用户");
|
||||||
R r = R.ok(); // 创建返回结果
|
R r = R.ok();
|
||||||
r.put("token", token); // 添加Token
|
r.put("token", token);
|
||||||
r.put("role","用户"); // 添加角色
|
r.put("role","用户");
|
||||||
r.put("username",yonghu.getYonghuName()); // 添加用户名
|
r.put("username",yonghu.getYonghuName());
|
||||||
r.put("tableName","yonghu"); // 添加表名
|
r.put("tableName","yonghu");
|
||||||
r.put("userId",yonghu.getId()); // 添加用户ID
|
r.put("userId",yonghu.getId());
|
||||||
return r; // 返回结果
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
//用户注册
|
* 注册
|
||||||
//@param yonghu 用户实体
|
*/
|
||||||
// @param request HTTP请求对象
|
@IgnoreAuth
|
||||||
//@return 注册结果
|
|
||||||
|
|
||||||
@IgnoreAuth // 忽略认证
|
|
||||||
@PostMapping(value = "/register")
|
@PostMapping(value = "/register")
|
||||||
public R register(@RequestBody YonghuEntity yonghu, HttpServletRequest request) {
|
public R register(@RequestBody YonghuEntity yonghu, HttpServletRequest request) {
|
||||||
// 构建查询条件:检查用户名、手机号、身份证号是否已存在
|
// ValidatorUtils.validateEntity(user);
|
||||||
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
|
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
|
||||||
.eq("username", yonghu.getUsername()) // 用户名条件
|
.eq("username", yonghu.getUsername())
|
||||||
.or() // 或条件
|
.or()
|
||||||
.eq("yonghu_phone", yonghu.getYonghuPhone()) // 手机号条件
|
.eq("yonghu_phone", yonghu.getYonghuPhone())
|
||||||
.or() // 或条件
|
.or()
|
||||||
.eq("yonghu_id_number", yonghu.getYonghuIdNumber()) // 身份证号条件
|
.eq("yonghu_id_number", yonghu.getYonghuIdNumber())
|
||||||
.andNew() // 新条件组
|
.andNew()
|
||||||
.eq("data_delete", 1) // 未删除条件
|
.eq("data_delete", 1)
|
||||||
;
|
;
|
||||||
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper); // 查询是否存在
|
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
|
||||||
if(yonghuEntity != null) // 如果已存在
|
if(yonghuEntity != null)
|
||||||
return R.error("账户或者用户手机号或者用户身份证号已经被使用"); // 返回错误信息
|
return R.error("账户或者用户手机号或者用户身份证号已经被使用");
|
||||||
yonghu.setNewMoney(0.0); // 设置初始余额
|
yonghu.setNewMoney(0.0);
|
||||||
yonghu.setDataDelete(1); // 设置未删除状态
|
yonghu.setDataDelete(1);
|
||||||
yonghu.setInsertTime(new Date()); // 设置插入时间
|
yonghu.setInsertTime(new Date());
|
||||||
yonghu.setCreateTime(new Date()); // 设置创建时间
|
yonghu.setCreateTime(new Date());
|
||||||
yonghuService.insert(yonghu); // 插入新用户
|
yonghuService.insert(yonghu);
|
||||||
return R.ok(); // 返回成功结果
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//重置密码为默认值
|
return R.ok();
|
||||||
//@param id 用户ID
|
}
|
||||||
//@param request HTTP请求对象
|
|
||||||
// @return 操作结果
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置密码
|
||||||
|
*/
|
||||||
@GetMapping(value = "/resetPassword")
|
@GetMapping(value = "/resetPassword")
|
||||||
public R resetPassword(Integer id, HttpServletRequest request) {
|
public R resetPassword(Integer id, HttpServletRequest request) {
|
||||||
YonghuEntity yonghu = yonghuService.selectById(id); // 根据ID查询用户
|
YonghuEntity yonghu = yonghuService.selectById(id);
|
||||||
yonghu.setPassword("123456"); // 重置密码
|
yonghu.setPassword("123456");
|
||||||
yonghuService.updateById(yonghu); // 更新用户
|
yonghuService.updateById(yonghu);
|
||||||
return R.ok(); // 返回成功结果
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
//修改密码
|
/**
|
||||||
//@param oldPassword 旧密码
|
* 修改密码
|
||||||
//@param newPassword 新密码
|
*/
|
||||||
//@param request HTTP请求对象
|
|
||||||
// @return 操作结果
|
|
||||||
|
|
||||||
@GetMapping(value = "/updatePassword")
|
@GetMapping(value = "/updatePassword")
|
||||||
public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) {
|
public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) {
|
||||||
YonghuEntity yonghu = yonghuService.selectById((Integer)request.getSession().getAttribute("userId")); // 获取当前用户
|
YonghuEntity yonghu = yonghuService.selectById((Integer)request.getSession().getAttribute("userId"));
|
||||||
if(newPassword == null){ // 检查新密码是否为空
|
if(newPassword == null){
|
||||||
return R.error("新密码不能为空") ; // 返回错误信息
|
return R.error("新密码不能为空") ;
|
||||||
}
|
}
|
||||||
if(!oldPassword.equals(yonghu.getPassword())){ // 检查旧密码是否正确
|
if(!oldPassword.equals(yonghu.getPassword())){
|
||||||
return R.error("原密码输入错误"); // 返回错误信息
|
return R.error("原密码输入错误");
|
||||||
}
|
}
|
||||||
if(newPassword.equals(yonghu.getPassword())){ // 检查新旧密码是否相同
|
if(newPassword.equals(yonghu.getPassword())){
|
||||||
return R.error("新密码不能和原密码一致") ; // 返回错误信息
|
return R.error("新密码不能和原密码一致") ;
|
||||||
}
|
}
|
||||||
yonghu.setPassword(newPassword); // 设置新密码
|
yonghu.setPassword(newPassword);
|
||||||
yonghuService.updateById(yonghu); // 更新用户
|
yonghuService.updateById(yonghu);
|
||||||
return R.ok(); // 返回成功结果
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
//忘记密码(重置为默认密码)
|
|
||||||
//@param username 用户名
|
|
||||||
//@param request HTTP请求对象
|
/**
|
||||||
//@return 操作结果
|
* 忘记密码
|
||||||
@IgnoreAuth // 忽略认证
|
*/
|
||||||
|
@IgnoreAuth
|
||||||
@RequestMapping(value = "/resetPass")
|
@RequestMapping(value = "/resetPass")
|
||||||
public R resetPass(String username, HttpServletRequest request) {
|
public R resetPass(String username, HttpServletRequest request) {
|
||||||
YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("username", username)); // 根据用户名查询用户
|
YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("username", username));
|
||||||
if(yonghu!=null){ // 如果用户存在
|
if(yonghu!=null){
|
||||||
yonghu.setPassword("123456"); // 重置密码
|
yonghu.setPassword("123456");
|
||||||
yonghuService.updateById(yonghu); // 更新用户
|
yonghuService.updateById(yonghu);
|
||||||
return R.ok(); // 返回成功结果
|
return R.ok();
|
||||||
}else{ // 如果用户不存在
|
}else{
|
||||||
return R.error("账号不存在"); // 返回错误信息
|
return R.error("账号不存在");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//获取当前会话用户信息
|
/**
|
||||||
//@param request HTTP请求对象
|
* 获取用户的session用户信息
|
||||||
//@return 用户信息
|
*/
|
||||||
@RequestMapping("/session")
|
@RequestMapping("/session")
|
||||||
public R getCurrYonghu(HttpServletRequest request){
|
public R getCurrYonghu(HttpServletRequest request){
|
||||||
Integer id = (Integer)request.getSession().getAttribute("userId"); // 获取当前用户ID
|
Integer id = (Integer)request.getSession().getAttribute("userId");
|
||||||
YonghuEntity yonghu = yonghuService.selectById(id); // 查询用户信息
|
YonghuEntity yonghu = yonghuService.selectById(id);
|
||||||
if(yonghu !=null){ // 如果用户存在
|
if(yonghu !=null){
|
||||||
YonghuView view = new YonghuView(); // 创建视图对象
|
//entity转view
|
||||||
BeanUtils.copyProperties(yonghu, view); // 复制属性
|
YonghuView view = new YonghuView();
|
||||||
dictionaryService.dictionaryConvert(view, request); // 转换字典字段
|
BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中
|
||||||
return R.ok().put("data", view); // 返回用户信息
|
|
||||||
|
//修改对应字典表字段
|
||||||
|
dictionaryService.dictionaryConvert(view, request);
|
||||||
|
return R.ok().put("data", view);
|
||||||
}else {
|
}else {
|
||||||
return R.error(511,"查不到数据"); // 返回错误信息
|
return R.error(511,"查不到数据");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//用户退出
|
/**
|
||||||
//@param request HTTP请求对象
|
* 退出
|
||||||
//@return 操作结果
|
*/
|
||||||
@GetMapping(value = "logout")
|
@GetMapping(value = "logout")
|
||||||
public R logout(HttpServletRequest request) {
|
public R logout(HttpServletRequest request) {
|
||||||
request.getSession().invalidate(); // 使会话失效
|
request.getSession().invalidate();
|
||||||
return R.ok("退出成功"); // 返回成功信息
|
return R.ok("退出成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//前端分页列表
|
|
||||||
//@param params 请求参数
|
/**
|
||||||
//@param request HTTP请求对象
|
* 前端列表
|
||||||
//@return 分页结果
|
*/
|
||||||
@IgnoreAuth // 忽略认证
|
@IgnoreAuth
|
||||||
@RequestMapping("/list")
|
@RequestMapping("/list")
|
||||||
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||||
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||||
CommonUtil.checkMap(params); // 检查参数
|
|
||||||
PageUtils page = yonghuService.queryPage(params); // 分页查询
|
|
||||||
|
|
||||||
// 字典表数据转换
|
CommonUtil.checkMap(params);
|
||||||
List<YonghuView> list =(List<YonghuView>)page.getList(); // 获取分页数据
|
PageUtils page = yonghuService.queryPage(params);
|
||||||
for(YonghuView c:list) // 遍历数据
|
|
||||||
dictionaryService.dictionaryConvert(c, request); // 转换字典字段
|
|
||||||
|
|
||||||
return R.ok().put("data", page); // 返回分页结果
|
//字典表数据转换
|
||||||
}
|
List<YonghuView> list =(List<YonghuView>)page.getList();
|
||||||
|
for(YonghuView c:list)
|
||||||
|
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
|
||||||
|
|
||||||
|
return R.ok().put("data", page);
|
||||||
|
}
|
||||||
|
|
||||||
//前端详情
|
/**
|
||||||
//@param id 用户ID
|
* 前端详情
|
||||||
//@param request HTTP请求对象
|
*/
|
||||||
//@return 用户详情
|
|
||||||
@RequestMapping("/detail/{id}")
|
@RequestMapping("/detail/{id}")
|
||||||
public R detail(@PathVariable("id") Integer id, HttpServletRequest request){
|
public R detail(@PathVariable("id") Integer id, HttpServletRequest request){
|
||||||
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||||
YonghuEntity yonghu = yonghuService.selectById(id); // 根据ID查询用户
|
YonghuEntity yonghu = yonghuService.selectById(id);
|
||||||
if(yonghu !=null){ // 如果用户存在
|
if(yonghu !=null){
|
||||||
YonghuView view = new YonghuView(); // 创建视图对象
|
|
||||||
BeanUtils.copyProperties(yonghu, view); // 复制属性
|
|
||||||
dictionaryService.dictionaryConvert(view, request); // 转换字典字段
|
//entity转view
|
||||||
return R.ok().put("data", view); // 返回用户信息
|
YonghuView view = new YonghuView();
|
||||||
|
BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中
|
||||||
|
|
||||||
|
//修改对应字典表字段
|
||||||
|
dictionaryService.dictionaryConvert(view, request);
|
||||||
|
return R.ok().put("data", view);
|
||||||
}else {
|
}else {
|
||||||
return R.error(511,"查不到数据"); // 返回错误信息
|
return R.error(511,"查不到数据");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//前端保存用户
|
/**
|
||||||
//@param yonghu 用户实体
|
* 前端保存
|
||||||
//@param request HTTP请求对象
|
*/
|
||||||
//@return 操作结果
|
|
||||||
@RequestMapping("/add")
|
@RequestMapping("/add")
|
||||||
public R add(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
|
public R add(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
|
||||||
logger.debug("add方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
|
logger.debug("add方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
|
||||||
// 构建查询条件:检查用户名、手机号、身份证号是否已存在
|
|
||||||
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
|
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
|
||||||
.eq("username", yonghu.getUsername()) // 用户名条件
|
.eq("username", yonghu.getUsername())
|
||||||
.or() // 或条件
|
.or()
|
||||||
.eq("yonghu_phone", yonghu.getYonghuPhone()) // 手机号条件
|
.eq("yonghu_phone", yonghu.getYonghuPhone())
|
||||||
.or() // 或条件
|
.or()
|
||||||
.eq("yonghu_id_number", yonghu.getYonghuIdNumber()) // 身份证号条件
|
.eq("yonghu_id_number", yonghu.getYonghuIdNumber())
|
||||||
.andNew() // 新条件组
|
.andNew()
|
||||||
.eq("data_delete", 1) // 未删除条件
|
.eq("data_delete", 1)
|
||||||
|
// .notIn("yonghu_types", new Integer[]{102})
|
||||||
;
|
;
|
||||||
logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句
|
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||||
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper); // 查询是否存在
|
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
|
||||||
if(yonghuEntity==null){ // 如果不存在
|
if(yonghuEntity==null){
|
||||||
yonghu.setDataDelete(1); // 设置未删除状态
|
yonghu.setDataDelete(1);
|
||||||
yonghu.setInsertTime(new Date()); // 设置插入时间
|
yonghu.setInsertTime(new Date());
|
||||||
yonghu.setCreateTime(new Date()); // 设置创建时间
|
yonghu.setCreateTime(new Date());
|
||||||
yonghu.setPassword("123456"); // 设置默认密码
|
yonghu.setPassword("123456");
|
||||||
yonghuService.insert(yonghu); // 插入新用户
|
yonghuService.insert(yonghu);
|
||||||
return R.ok(); // 返回成功结果
|
|
||||||
|
return R.ok();
|
||||||
}else {
|
}else {
|
||||||
return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用"); // 返回错误信息
|
return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in new issue