parent
279e3f2480
commit
07c72295a9
@ -1,110 +1,159 @@
|
||||
package com.controller;
|
||||
package com.controller; // 定义包路径
|
||||
|
||||
// 文件操作相关类
|
||||
import java.io.File;
|
||||
// 文件未找到异常
|
||||
import java.io.FileNotFoundException;
|
||||
// IO异常
|
||||
import java.io.IOException;
|
||||
// 数组工具类
|
||||
import java.util.Arrays;
|
||||
// 日期类
|
||||
import java.util.Date;
|
||||
// 哈希Map
|
||||
import java.util.HashMap;
|
||||
// 列表接口
|
||||
import java.util.List;
|
||||
// Map接口
|
||||
import java.util.Map;
|
||||
// 随机数类
|
||||
import java.util.Random;
|
||||
// UUID类
|
||||
import java.util.UUID;
|
||||
|
||||
// Apache Commons IO工具类
|
||||
import org.apache.commons.io.FileUtils;
|
||||
// Apache Commons字符串工具
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
// Spring自动注入注解
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
// HTTP头定义
|
||||
import org.springframework.http.HttpHeaders;
|
||||
// HTTP状态码
|
||||
import org.springframework.http.HttpStatus;
|
||||
// 媒体类型定义
|
||||
import org.springframework.http.MediaType;
|
||||
// ResponseEntity响应实体
|
||||
import org.springframework.http.ResponseEntity;
|
||||
// Spring资源工具
|
||||
import org.springframework.util.ResourceUtils;
|
||||
// Spring路径变量注解
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
// Spring请求体注解
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
// Spring请求映射注解
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
// Spring请求参数注解
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
// Spring REST控制器注解
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
// Spring文件上传类
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
// 自定义忽略鉴权注解
|
||||
import com.annotation.IgnoreAuth;
|
||||
// MyBatis Plus实体包装器
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
// 配置实体类
|
||||
import com.entity.ConfigEntity;
|
||||
// 自定义异常类
|
||||
import com.entity.EIException;
|
||||
// 配置服务接口
|
||||
import com.service.ConfigService;
|
||||
// 自定义返回结果类
|
||||
import com.utils.R;
|
||||
|
||||
/**
|
||||
* 上传文件映射表
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("file")
|
||||
@SuppressWarnings({"unchecked","rawtypes"})
|
||||
|
||||
//上传文件映射表
|
||||
//文件上传下载控制器
|
||||
@RestController // 声明为RESTful控制器
|
||||
@RequestMapping("file") // 基础请求路径映射
|
||||
@SuppressWarnings({"unchecked","rawtypes"}) // 抑制警告
|
||||
public class FileController{
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
/**
|
||||
* 上传文件
|
||||
*/
|
||||
@RequestMapping("/upload")
|
||||
@Autowired // 自动注入配置服务
|
||||
private ConfigService configService;
|
||||
|
||||
|
||||
//上传文件
|
||||
//@param file 上传的文件对象
|
||||
//@param type 文件类型标识
|
||||
//@return 上传结果
|
||||
//* @throws Exception 可能抛出的异常
|
||||
|
||||
@RequestMapping("/upload") // 文件上传请求映射
|
||||
public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {
|
||||
if (file.isEmpty()) {
|
||||
throw new EIException("上传文件不能为空");
|
||||
if (file.isEmpty()) { // 检查文件是否为空
|
||||
throw new EIException("上传文件不能为空"); // 抛出文件为空异常
|
||||
}
|
||||
// 获取文件扩展名
|
||||
String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
|
||||
// 获取静态资源路径
|
||||
File path = new File(ResourceUtils.getURL("classpath:static").getPath());
|
||||
if(!path.exists()) {
|
||||
path = new File("");
|
||||
if(!path.exists()) { // 如果路径不存在
|
||||
path = new File(""); // 使用当前路径
|
||||
}
|
||||
// 创建上传目录
|
||||
File upload = new File(path.getAbsolutePath(),"/upload/");
|
||||
if(!upload.exists()) {
|
||||
upload.mkdirs();
|
||||
if(!upload.exists()) { // 如果目录不存在
|
||||
upload.mkdirs(); // 创建目录
|
||||
}
|
||||
// 生成唯一文件名(时间戳+扩展名)
|
||||
String fileName = new Date().getTime()+"."+fileExt;
|
||||
// 创建目标文件
|
||||
File dest = new File(upload.getAbsolutePath()+"/"+fileName);
|
||||
// 传输文件到目标位置
|
||||
file.transferTo(dest);
|
||||
// 如果是类型1的文件(如头像文件)
|
||||
if(StringUtils.isNotBlank(type) && type.equals("1")) {
|
||||
// 查询配置表中faceFile配置
|
||||
ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
|
||||
if(configEntity==null) {
|
||||
configEntity = new ConfigEntity();
|
||||
configEntity.setName("faceFile");
|
||||
configEntity.setValue(fileName);
|
||||
if(configEntity==null) { // 如果配置不存在
|
||||
configEntity = new ConfigEntity(); // 创建新配置
|
||||
configEntity.setName("faceFile"); // 设置配置名
|
||||
configEntity.setValue(fileName); // 设置文件名
|
||||
} else {
|
||||
configEntity.setValue(fileName);
|
||||
configEntity.setValue(fileName); // 更新文件名
|
||||
}
|
||||
// 保存或更新配置
|
||||
configService.insertOrUpdate(configEntity);
|
||||
}
|
||||
// 返回成功结果和文件名
|
||||
return R.ok().put("file", fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*/
|
||||
@IgnoreAuth
|
||||
@RequestMapping("/download")
|
||||
|
||||
|
||||
//下载文件
|
||||
//@param fileName 要下载的文件名
|
||||
// @return 文件下载响应
|
||||
|
||||
@IgnoreAuth // 忽略权限验证
|
||||
@RequestMapping("/download") // 文件下载请求映射
|
||||
public ResponseEntity<byte[]> download(@RequestParam String fileName) {
|
||||
try {
|
||||
// 获取静态资源路径
|
||||
File path = new File(ResourceUtils.getURL("classpath:static").getPath());
|
||||
if(!path.exists()) {
|
||||
path = new File("");
|
||||
if(!path.exists()) { // 如果路径不存在
|
||||
path = new File(""); // 使用当前路径
|
||||
}
|
||||
// 获取上传目录
|
||||
File upload = new File(path.getAbsolutePath(),"/upload/");
|
||||
if(!upload.exists()) {
|
||||
upload.mkdirs();
|
||||
if(!upload.exists()) { // 如果目录不存在
|
||||
upload.mkdirs(); // 创建目录
|
||||
}
|
||||
// 构建文件对象
|
||||
File file = new File(upload.getAbsolutePath()+"/"+fileName);
|
||||
if(file.exists()){
|
||||
/*if(!fileService.canRead(file, SessionManager.getSessionUser())){
|
||||
getResponse().sendError(403);
|
||||
}*/
|
||||
if(file.exists()){ // 如果文件存在
|
||||
// 设置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); // 设置内容处置为附件
|
||||
// 返回文件内容和响应头
|
||||
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) { // 捕获IO异常
|
||||
e.printStackTrace(); // 打印异常堆栈
|
||||
}
|
||||
// 返回服务器错误响应
|
||||
return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,300 +1,297 @@
|
||||
|
||||
// 声明当前文件所在的包路径
|
||||
package com.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import com.service.TokenService;
|
||||
import com.utils.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import com.service.DictionaryService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.annotation.IgnoreAuth;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
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;
|
||||
import com.alibaba.fastjson.*;
|
||||
|
||||
/**
|
||||
* 单页数据
|
||||
* 后端接口
|
||||
* @author
|
||||
* @email
|
||||
*/
|
||||
@RestController
|
||||
@Controller
|
||||
@RequestMapping("/singleSeach")
|
||||
// 导入所需的Java类库
|
||||
import java.io.File; // 文件操作类
|
||||
import java.math.BigDecimal; // 高精度数字计算类
|
||||
import java.net.URL; // 统一资源定位符类
|
||||
import java.text.SimpleDateFormat; // 日期格式化类
|
||||
import com.alibaba.fastjson.JSONObject; // FastJSON的JSON对象类
|
||||
import java.util.*; // 通用工具类集合
|
||||
import org.springframework.beans.BeanUtils; // Spring Bean工具类
|
||||
import javax.servlet.http.HttpServletRequest; // HTTP请求类
|
||||
import org.springframework.web.context.ContextLoader; // Spring上下文加载器
|
||||
import javax.servlet.ServletContext; // Servlet上下文接口
|
||||
import com.service.TokenService; // 自定义Token服务类
|
||||
import com.utils.*; // 自定义工具类包
|
||||
import java.lang.reflect.InvocationTargetException; // 反射异常类
|
||||
|
||||
// 导入自定义服务类
|
||||
import com.service.DictionaryService; // 字典服务类
|
||||
import org.apache.commons.lang3.StringUtils; // Apache字符串工具类
|
||||
import com.annotation.IgnoreAuth; // 自定义忽略认证注解
|
||||
import org.slf4j.Logger; // 日志接口
|
||||
import org.slf4j.LoggerFactory; // 日志工厂类
|
||||
import org.springframework.beans.factory.annotation.Autowired; // Spring自动注入注解
|
||||
import org.springframework.stereotype.Controller; // Spring控制器注解
|
||||
import org.springframework.web.bind.annotation.*; // Spring Web注解集合
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper; // MyBatis Plus实体包装类
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper; // MyBatis Plus包装接口
|
||||
import com.entity.*; // 实体类包
|
||||
import com.entity.view.*; // 实体视图类包
|
||||
import com.service.*; // 服务接口包
|
||||
import com.utils.PageUtils; // 分页工具类
|
||||
import com.utils.R; // 通用返回结果类
|
||||
import com.alibaba.fastjson.*; // FastJSON工具包
|
||||
|
||||
|
||||
//单页数据
|
||||
//后端接口控制器
|
||||
//@author
|
||||
//@email
|
||||
|
||||
@RestController // 标识这是一个RESTful风格的控制器
|
||||
@Controller // 标识这是一个Spring MVC控制器
|
||||
@RequestMapping("/singleSeach") // 定义基础请求路径
|
||||
public class SingleSeachController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SingleSeachController.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(SingleSeachController.class); // 日志记录器
|
||||
|
||||
private static final String TABLE_NAME = "singleSeach";
|
||||
private static final String TABLE_NAME = "singleSeach"; // 数据库表名常量
|
||||
|
||||
@Autowired
|
||||
private SingleSeachService singleSeachService;
|
||||
|
||||
private SingleSeachService singleSeachService; // 注入单页数据服务
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
private TokenService tokenService; // 注入token服务
|
||||
|
||||
// 注入其他相关服务
|
||||
@Autowired
|
||||
private DictionaryService dictionaryService;//字典
|
||||
private DictionaryService dictionaryService; // 字典服务
|
||||
@Autowired
|
||||
private ForumService forumService;//健身论坛
|
||||
private ForumService forumService; // 健身论坛服务
|
||||
@Autowired
|
||||
private JianshenkechengService jianshenkechengService;//健身课程
|
||||
private JianshenkechengService jianshenkechengService; // 健身课程服务
|
||||
@Autowired
|
||||
private JianshenkechengCollectionService jianshenkechengCollectionService;//课程收藏
|
||||
private JianshenkechengCollectionService jianshenkechengCollectionService; // 课程收藏服务
|
||||
@Autowired
|
||||
private JianshenkechengLiuyanService jianshenkechengLiuyanService;//课程留言
|
||||
private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 课程留言服务
|
||||
@Autowired
|
||||
private JiaolianService jiaolianService;//教练
|
||||
private JiaolianService jiaolianService; // 教练服务
|
||||
@Autowired
|
||||
private JiaolianYuyueService jiaolianYuyueService;//教练预约申请
|
||||
private JiaolianYuyueService jiaolianYuyueService; // 教练预约申请服务
|
||||
@Autowired
|
||||
private NewsService newsService;//健身资讯
|
||||
private NewsService newsService; // 健身资讯服务
|
||||
@Autowired
|
||||
private YonghuService yonghuService;//用户
|
||||
private YonghuService yonghuService; // 用户服务
|
||||
@Autowired
|
||||
private UsersService usersService;//管理员
|
||||
private UsersService usersService; // 管理员服务
|
||||
|
||||
|
||||
//后端列表
|
||||
//分页查询单页数据
|
||||
//@param params 请求参数Map
|
||||
//@param request HTTP请求对象
|
||||
//@return 返回分页数据结果
|
||||
|
||||
/**
|
||||
* 后端列表
|
||||
*/
|
||||
@RequestMapping("/page")
|
||||
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永不会进入");
|
||||
else if("用户".equals(role))
|
||||
params.put("yonghuId",request.getSession().getAttribute("userId"));
|
||||
else if("教练".equals(role))
|
||||
params.put("jiaolianId",request.getSession().getAttribute("userId"));
|
||||
CommonUtil.checkMap(params);
|
||||
PageUtils page = singleSeachService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<SingleSeachView> list =(List<SingleSeachView>)page.getList();
|
||||
for(SingleSeachView c:list){
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(c, request);
|
||||
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录日志
|
||||
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
||||
if(false) // 条件判断
|
||||
return R.error(511,"永不会进入"); // 返回错误信息
|
||||
else if("用户".equals(role)) // 如果是用户角色
|
||||
params.put("yonghuId",request.getSession().getAttribute("userId")); // 添加用户ID参数
|
||||
else if("教练".equals(role)) // 如果是教练角色
|
||||
params.put("jiaolianId",request.getSession().getAttribute("userId")); // 添加教练ID参数
|
||||
CommonUtil.checkMap(params); // 检查参数
|
||||
PageUtils page = singleSeachService.queryPage(params); // 调用服务层分页查询
|
||||
|
||||
// 字典表数据转换
|
||||
List<SingleSeachView> list =(List<SingleSeachView>)page.getList(); // 获取分页数据列表
|
||||
for(SingleSeachView c:list){ // 遍历列表
|
||||
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}")
|
||||
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
SingleSeachEntity singleSeach = singleSeachService.selectById(id);
|
||||
if(singleSeach !=null){
|
||||
//entity转view
|
||||
SingleSeachView view = new SingleSeachView();
|
||||
BeanUtils.copyProperties( singleSeach , view );//把实体数据重构到view中
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录日志
|
||||
SingleSeachEntity singleSeach = singleSeachService.selectById(id); // 根据ID查询数据
|
||||
if(singleSeach !=null){ // 如果查询到数据
|
||||
SingleSeachView view = new SingleSeachView(); // 创建视图对象
|
||||
BeanUtils.copyProperties(singleSeach, view); // 复制属性到视图对象
|
||||
dictionaryService.dictionaryConvert(view, request); // 转换字典表字段
|
||||
return R.ok().put("data", view); // 返回成功结果和数据
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
return R.error(511,"查不到数据"); // 返回错误信息
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
public R save(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request){
|
||||
logger.debug("save方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString());
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永远不会进入");
|
||||
//后端保存
|
||||
//新增单页数据
|
||||
//@param singleSeach 单页数据实体
|
||||
//@param request HTTP请求对象
|
||||
//@return 返回操作结果
|
||||
//@RequestMapping("/save")
|
||||
public R save(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request){
|
||||
logger.debug("save方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString()); // 记录日志
|
||||
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
||||
if(false) // 条件判断
|
||||
return R.error(511,"永远不会进入"); // 返回错误信息
|
||||
|
||||
// 构建查询条件
|
||||
Wrapper<SingleSeachEntity> queryWrapper = new EntityWrapper<SingleSeachEntity>()
|
||||
.eq("single_seach_types",singleSeach.getSingleSeachTypes())
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
SingleSeachEntity singleSeachEntity = singleSeachService.selectOne(queryWrapper);
|
||||
if(singleSeachEntity==null){
|
||||
singleSeach.setCreateTime(new Date());
|
||||
singleSeachService.insert(singleSeach);
|
||||
return R.ok();
|
||||
.eq("single_seach_types",singleSeach.getSingleSeachTypes()); // 按类型查询
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句
|
||||
SingleSeachEntity singleSeachEntity = singleSeachService.selectOne(queryWrapper); // 查询是否存在
|
||||
if(singleSeachEntity==null){ // 如果不存在
|
||||
singleSeach.setCreateTime(new Date()); // 设置创建时间
|
||||
singleSeachService.insert(singleSeach); // 插入新数据
|
||||
return R.ok(); // 返回成功结果
|
||||
}else {
|
||||
return R.error(511,"该类型已经有存在的,请删除后重新新增");
|
||||
return R.error(511,"该类型已经有存在的,请删除后重新新增"); // 返回错误信息
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端修改
|
||||
*/
|
||||
//后端修改
|
||||
//更新单页数据
|
||||
//@param singleSeach 单页数据实体
|
||||
//@param request HTTP请求对象
|
||||
//@return 返回操作结果
|
||||
@RequestMapping("/update")
|
||||
public R update(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
|
||||
logger.debug("update方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString());
|
||||
SingleSeachEntity oldSingleSeachEntity = singleSeachService.selectById(singleSeach.getId());//查询原先数据
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
// if(false)
|
||||
// return R.error(511,"永远不会进入");
|
||||
if("".equals(singleSeach.getSingleSeachPhoto()) || "null".equals(singleSeach.getSingleSeachPhoto())){
|
||||
singleSeach.setSingleSeachPhoto(null);
|
||||
logger.debug("update方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString()); // 记录日志
|
||||
SingleSeachEntity oldSingleSeachEntity = singleSeachService.selectById(singleSeach.getId()); // 查询原数据
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
||||
if("".equals(singleSeach.getSingleSeachPhoto()) || "null".equals(singleSeach.getSingleSeachPhoto())){ // 如果图片为空
|
||||
singleSeach.setSingleSeachPhoto(null); // 设置为null
|
||||
}
|
||||
if("".equals(singleSeach.getSingleSeachContent()) || "null".equals(singleSeach.getSingleSeachContent())){
|
||||
singleSeach.setSingleSeachContent(null);
|
||||
if("".equals(singleSeach.getSingleSeachContent()) || "null".equals(singleSeach.getSingleSeachContent())){ // 如果内容为空
|
||||
singleSeach.setSingleSeachContent(null); // 设置为null
|
||||
}
|
||||
|
||||
singleSeachService.updateById(singleSeach);//根据id更新
|
||||
return R.ok();
|
||||
singleSeachService.updateById(singleSeach); // 更新数据
|
||||
return R.ok(); // 返回成功结果
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
//删除
|
||||
//批量删除单页数据
|
||||
//@param ids 要删除的ID数组
|
||||
//@param request HTTP请求对象
|
||||
//@return 返回操作结果
|
||||
@RequestMapping("/delete")
|
||||
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
|
||||
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
|
||||
List<SingleSeachEntity> oldSingleSeachList =singleSeachService.selectBatchIds(Arrays.asList(ids));//要删除的数据
|
||||
singleSeachService.deleteBatchIds(Arrays.asList(ids));
|
||||
|
||||
return R.ok();
|
||||
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); // 记录日志
|
||||
List<SingleSeachEntity> oldSingleSeachList = singleSeachService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据
|
||||
singleSeachService.deleteBatchIds(Arrays.asList(ids)); // 批量删除
|
||||
return R.ok(); // 返回成功结果
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量上传
|
||||
*/
|
||||
//批量上传/
|
||||
//通过Excel批量导入数据
|
||||
//@param fileName Excel文件名
|
||||
//@param request HTTP请求对象
|
||||
//@return 返回操作结果
|
||||
@RequestMapping("/batchInsert")
|
||||
public R save( String fileName, HttpServletRequest request){
|
||||
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
|
||||
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
//.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
|
||||
public R save(String fileName, HttpServletRequest request){
|
||||
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); // 记录日志
|
||||
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取用户ID
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 创建日期格式化对象
|
||||
try {
|
||||
List<SingleSeachEntity> singleSeachList = new ArrayList<>();//上传的东西
|
||||
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
|
||||
Date date = new Date();
|
||||
int lastIndexOf = fileName.lastIndexOf(".");
|
||||
if(lastIndexOf == -1){
|
||||
return R.error(511,"该文件没有后缀");
|
||||
List<SingleSeachEntity> singleSeachList = new ArrayList<>(); // 创建数据列表
|
||||
Map<String, List<String>> seachFields = new HashMap<>(); // 创建查询字段Map
|
||||
Date date = new Date(); // 当前时间
|
||||
int lastIndexOf = fileName.lastIndexOf("."); // 获取文件后缀位置
|
||||
if(lastIndexOf == -1){ // 如果没有后缀
|
||||
return R.error(511,"该文件没有后缀"); // 返回错误信息
|
||||
}else{
|
||||
String suffix = fileName.substring(lastIndexOf);
|
||||
if(!".xls".equals(suffix)){
|
||||
return R.error(511,"只支持后缀为xls的excel文件");
|
||||
String suffix = fileName.substring(lastIndexOf); // 获取文件后缀
|
||||
if(!".xls".equals(suffix)){ // 如果不是xls文件
|
||||
return R.error(511,"只支持后缀为xls的excel文件"); // 返回错误信息
|
||||
}else{
|
||||
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
|
||||
File file = new File(resource.getFile());
|
||||
if(!file.exists()){
|
||||
return R.error(511,"找不到上传文件,请联系管理员");
|
||||
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 获取文件路径
|
||||
File file = new File(resource.getFile()); // 创建文件对象
|
||||
if(!file.exists()){ // 如果文件不存在
|
||||
return R.error(511,"找不到上传文件,请联系管理员"); // 返回错误信息
|
||||
}else{
|
||||
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
|
||||
dataList.remove(0);//删除第一行,因为第一行是提示
|
||||
for(List<String> data:dataList){
|
||||
//循环
|
||||
SingleSeachEntity singleSeachEntity = new SingleSeachEntity();
|
||||
// singleSeachEntity.setSingleSeachName(data.get(0)); //名字 要改的
|
||||
// singleSeachEntity.setSingleSeachTypes(Integer.valueOf(data.get(0))); //数据类型 要改的
|
||||
// singleSeachEntity.setSingleSeachPhoto("");//详情和图片
|
||||
// singleSeachEntity.setSingleSeachContent("");//详情和图片
|
||||
// singleSeachEntity.setCreateTime(date);//时间
|
||||
singleSeachList.add(singleSeachEntity);
|
||||
|
||||
|
||||
//把要查询是否重复的字段放入map中
|
||||
List<List<String>> dataList = PoiUtil.poiImport(file.getPath()); // 读取Excel文件
|
||||
dataList.remove(0); // 删除标题行
|
||||
for(List<String> data:dataList){ // 遍历数据行
|
||||
SingleSeachEntity singleSeachEntity = new SingleSeachEntity(); // 创建实体对象
|
||||
// 可以在此处设置实体属性,示例中被注释掉了
|
||||
singleSeachList.add(singleSeachEntity); // 添加到列表
|
||||
}
|
||||
|
||||
//查询是否重复
|
||||
singleSeachService.insertBatch(singleSeachList);
|
||||
return R.ok();
|
||||
singleSeachService.insertBatch(singleSeachList); // 批量插入
|
||||
return R.ok(); // 返回成功结果
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return R.error(511,"批量插入数据异常,请联系管理员");
|
||||
}catch (Exception e){ // 捕获异常
|
||||
e.printStackTrace(); // 打印异常堆栈
|
||||
return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 前端列表
|
||||
*/
|
||||
@IgnoreAuth
|
||||
//前端列表
|
||||
//无需认证的分页查询
|
||||
//@param params 请求参数Map
|
||||
//@param request HTTP请求对象
|
||||
//@return 返回分页数据结果
|
||||
@IgnoreAuth // 忽略认证
|
||||
@RequestMapping("/list")
|
||||
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
|
||||
CommonUtil.checkMap(params);
|
||||
PageUtils page = singleSeachService.queryPage(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();
|
||||
for(SingleSeachView c:list)
|
||||
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
|
||||
List<SingleSeachView> list = (List<SingleSeachView>)page.getList(); // 获取数据列表
|
||||
for(SingleSeachView c:list) // 遍历列表
|
||||
dictionaryService.dictionaryConvert(c, request); // 转换字典表字段
|
||||
|
||||
return R.ok().put("data", page);
|
||||
return R.ok().put("data", page); // 返回成功结果和数据
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端详情
|
||||
*/
|
||||
|
||||
//前端详情
|
||||
//根据类型查询单条数据
|
||||
//@param id 数据类型ID
|
||||
//@param request HTTP请求对象
|
||||
//@return 返回查询结果
|
||||
@RequestMapping("/detail/{id}")
|
||||
public R detail(@PathVariable("id") Integer id, HttpServletRequest request){
|
||||
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录日志
|
||||
// 根据类型查询单条数据
|
||||
SingleSeachEntity singleSeach = singleSeachService.selectOne(new EntityWrapper<SingleSeachEntity>().eq("single_seach_types", id));
|
||||
if(singleSeach != null)
|
||||
return R.ok().put("data", singleSeach);
|
||||
if(singleSeach != null) // 如果查询到数据
|
||||
return R.ok().put("data", singleSeach); // 返回成功结果和数据
|
||||
else
|
||||
return R.error(511,"查不到数据");
|
||||
|
||||
return R.error(511,"查不到数据"); // 返回错误信息
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 前端保存
|
||||
*/
|
||||
//前端保存
|
||||
//新增单页数据
|
||||
//@param singleSeach 单页数据实体
|
||||
//@param request HTTP请求对象
|
||||
//@return 返回操作结果
|
||||
@RequestMapping("/add")
|
||||
public R add(@RequestBody SingleSeachEntity singleSeach, HttpServletRequest request){
|
||||
logger.debug("add方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString());
|
||||
logger.debug("add方法:,,Controller:{},,singleSeach:{}",this.getClass().getName(),singleSeach.toString()); // 记录日志
|
||||
// 构建查询条件
|
||||
Wrapper<SingleSeachEntity> queryWrapper = new EntityWrapper<SingleSeachEntity>()
|
||||
.eq("single_seach_types",singleSeach.getSingleSeachTypes())
|
||||
// .notIn("single_seach_types", new Integer[]{102})
|
||||
;
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
SingleSeachEntity singleSeachEntity = singleSeachService.selectOne(queryWrapper);
|
||||
if(singleSeachEntity==null){
|
||||
singleSeach.setCreateTime(new Date());
|
||||
singleSeachService.insert(singleSeach);
|
||||
|
||||
return R.ok();
|
||||
.eq("single_seach_types",singleSeach.getSingleSeachTypes()); // 按类型查询
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句
|
||||
SingleSeachEntity singleSeachEntity = singleSeachService.selectOne(queryWrapper); // 查询是否已存在
|
||||
if(singleSeachEntity==null){ // 如果不存在
|
||||
singleSeach.setCreateTime(new Date()); // 设置创建时间
|
||||
singleSeachService.insert(singleSeach); // 插入新数据
|
||||
return R.ok(); // 返回成功结果
|
||||
}else {
|
||||
return R.error(511,"该类型已经有存在的,请删除后重新新增");
|
||||
return R.error(511,"该类型已经有存在的,请删除后重新新增"); // 返回错误信息
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,521 +1,532 @@
|
||||
|
||||
package com.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import javax.servlet.ServletContext;
|
||||
import com.service.TokenService;
|
||||
import com.utils.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import com.service.DictionaryService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.annotation.IgnoreAuth;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
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;
|
||||
import com.alibaba.fastjson.*;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
* 后端接口
|
||||
* @author
|
||||
* @email
|
||||
*/
|
||||
@RestController
|
||||
@Controller
|
||||
@RequestMapping("/yonghu")
|
||||
package com.controller; // 声明当前类所在的包路径
|
||||
|
||||
// 导入Java IO类
|
||||
import java.io.File; // 文件操作类
|
||||
// 导入数学类
|
||||
import java.math.BigDecimal; // 高精度数字计算类
|
||||
// 导入网络类
|
||||
import java.net.URL; // 统一资源定位符类
|
||||
// 导入文本处理类
|
||||
import java.text.SimpleDateFormat; // 日期格式化类
|
||||
// 导入JSON处理类
|
||||
import com.alibaba.fastjson.JSONObject; // FastJSON对象类
|
||||
// 导入集合类
|
||||
import java.util.*; // 通用集合工具类
|
||||
// 导入Spring Bean工具类
|
||||
import org.springframework.beans.BeanUtils; // Bean属性复制工具类
|
||||
// 导入Servlet类
|
||||
import javax.servlet.http.HttpServletRequest; // HTTP请求对象
|
||||
// 导入Spring上下文类
|
||||
import org.springframework.web.context.ContextLoader; // Web应用上下文加载器
|
||||
// 导入Servlet上下文类
|
||||
import javax.servlet.ServletContext; // Servlet上下文对象
|
||||
// 导入自定义服务类
|
||||
import com.service.TokenService; // Token服务接口
|
||||
// 导入自定义工具类
|
||||
import com.utils.*; // 自定义工具类集合
|
||||
// 导入反射异常类
|
||||
import java.lang.reflect.InvocationTargetException; // 反射调用异常类
|
||||
|
||||
// 导入字典服务类
|
||||
import com.service.DictionaryService; // 字典数据服务接口
|
||||
// 导入Apache Commons工具类
|
||||
import org.apache.commons.lang3.StringUtils; // 字符串处理工具类
|
||||
// 导入自定义注解
|
||||
import com.annotation.IgnoreAuth; // 忽略认证注解
|
||||
// 导入日志类
|
||||
import org.slf4j.Logger; // 日志接口
|
||||
import org.slf4j.LoggerFactory; // 日志工厂类
|
||||
// 导入Spring注解
|
||||
import org.springframework.beans.factory.annotation.Autowired; // 自动注入注解
|
||||
import org.springframework.stereotype.Controller; // 控制器注解
|
||||
import org.springframework.web.bind.annotation.*; // Web请求相关注解
|
||||
// 导入MyBatis Plus类
|
||||
import com.baomidou.mybatisplus.mapper.EntityWrapper; // 条件构造器
|
||||
import com.baomidou.mybatisplus.mapper.Wrapper; // 条件构造器接口
|
||||
// 导入实体类
|
||||
import com.entity.*; // 实体类集合
|
||||
import com.entity.view.*; // 视图实体类集合
|
||||
// 导入服务接口
|
||||
import com.service.*; // 服务接口集合
|
||||
// 导入分页工具类
|
||||
import com.utils.PageUtils; // 分页工具类
|
||||
// 导入返回结果类
|
||||
import com.utils.R; // 统一返回结果类
|
||||
// 导入FastJSON类
|
||||
import com.alibaba.fastjson.*; // FastJSON工具类
|
||||
|
||||
|
||||
//用户控制器
|
||||
// 处理用户相关操作的RESTful接口
|
||||
|
||||
@RestController // 标识为RESTful控制器
|
||||
@Controller // 标识为Spring MVC控制器
|
||||
@RequestMapping("/yonghu") // 基础请求路径
|
||||
public class YonghuController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(YonghuController.class);
|
||||
private static final 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;
|
||||
|
||||
|
||||
@Autowired
|
||||
@Autowired // 自动注入Token服务
|
||||
private TokenService tokenService;
|
||||
|
||||
// 注入其他相关服务
|
||||
@Autowired
|
||||
private DictionaryService dictionaryService;//字典
|
||||
private DictionaryService dictionaryService; // 字典服务
|
||||
@Autowired
|
||||
private ForumService forumService;//健身论坛
|
||||
private ForumService forumService; // 健身论坛服务
|
||||
@Autowired
|
||||
private JianshenkechengService jianshenkechengService;//健身课程
|
||||
private JianshenkechengService jianshenkechengService; // 健身课程服务
|
||||
@Autowired
|
||||
private JianshenkechengCollectionService jianshenkechengCollectionService;//课程收藏
|
||||
private JianshenkechengCollectionService jianshenkechengCollectionService; // 课程收藏服务
|
||||
@Autowired
|
||||
private JianshenkechengLiuyanService jianshenkechengLiuyanService;//课程留言
|
||||
private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 课程留言服务
|
||||
@Autowired
|
||||
private JiaolianService jiaolianService;//教练
|
||||
private JiaolianService jiaolianService; // 教练服务
|
||||
@Autowired
|
||||
private JiaolianYuyueService jiaolianYuyueService;//教练预约申请
|
||||
private JiaolianYuyueService jiaolianYuyueService; // 教练预约服务
|
||||
@Autowired
|
||||
private NewsService newsService;//健身资讯
|
||||
private NewsService newsService; // 健身资讯服务
|
||||
@Autowired
|
||||
private SingleSeachService singleSeachService;//单页数据
|
||||
private SingleSeachService singleSeachService; // 单页数据服务
|
||||
@Autowired
|
||||
private UsersService usersService;//管理员
|
||||
|
||||
private UsersService usersService; // 管理员服务
|
||||
|
||||
/**
|
||||
* 后端列表
|
||||
*/
|
||||
//后端分页列表
|
||||
//@param params 请求参数Map
|
||||
//@param request HTTP请求对象
|
||||
//@return 分页结果
|
||||
@RequestMapping("/page")
|
||||
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永不会进入");
|
||||
else if("用户".equals(role))
|
||||
params.put("yonghuId",request.getSession().getAttribute("userId"));
|
||||
else if("教练".equals(role))
|
||||
params.put("jiaolianId",request.getSession().getAttribute("userId"));
|
||||
params.put("dataDeleteStart",1);params.put("dataDeleteEnd",1);
|
||||
CommonUtil.checkMap(params);
|
||||
PageUtils page = yonghuService.queryPage(params);
|
||||
|
||||
//字典表数据转换
|
||||
List<YonghuView> list =(List<YonghuView>)page.getList();
|
||||
for(YonghuView c:list){
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(c, request);
|
||||
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
||||
if(false) // 条件判断
|
||||
return R.error(511,"永不会进入"); // 返回错误信息
|
||||
else if("用户".equals(role)) // 如果是用户角色
|
||||
params.put("yonghuId",request.getSession().getAttribute("userId")); // 添加用户ID参数
|
||||
else if("教练".equals(role)) // 如果是教练角色
|
||||
params.put("jiaolianId",request.getSession().getAttribute("userId")); // 添加教练ID参数
|
||||
params.put("dataDeleteStart",1);params.put("dataDeleteEnd",1); // 设置逻辑删除条件
|
||||
CommonUtil.checkMap(params); // 检查参数
|
||||
PageUtils page = yonghuService.queryPage(params); // 分页查询
|
||||
|
||||
// 字典表数据转换
|
||||
List<YonghuView> list =(List<YonghuView>)page.getList(); // 获取分页数据
|
||||
for(YonghuView c:list){ // 遍历数据
|
||||
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}")
|
||||
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
||||
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
YonghuEntity yonghu = yonghuService.selectById(id);
|
||||
if(yonghu !=null){
|
||||
//entity转view
|
||||
YonghuView view = new YonghuView();
|
||||
BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
YonghuEntity yonghu = yonghuService.selectById(id); // 根据ID查询用户
|
||||
if(yonghu !=null){ // 如果查询到数据
|
||||
YonghuView view = new YonghuView(); // 创建视图对象
|
||||
BeanUtils.copyProperties(yonghu, view); // 复制属性到视图对象
|
||||
dictionaryService.dictionaryConvert(view, request); // 转换字典表字段
|
||||
return R.ok().put("data", view); // 返回成功结果
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
return R.error(511,"查不到数据"); // 返回错误信息
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端保存
|
||||
*/
|
||||
//后端保存用户
|
||||
//@param yonghu 用户实体
|
||||
//@param request HTTP请求对象
|
||||
//@return 操作结果
|
||||
@RequestMapping("/save")
|
||||
public R save(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
|
||||
logger.debug("save方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
|
||||
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
||||
if(false) // 条件判断
|
||||
return R.error(511,"永远不会进入"); // 返回错误信息
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
if(false)
|
||||
return R.error(511,"永远不会进入");
|
||||
|
||||
// 构建查询条件:检查用户名、手机号、身份证号是否已存在
|
||||
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
|
||||
.eq("username", yonghu.getUsername())
|
||||
.or()
|
||||
.eq("yonghu_phone", yonghu.getYonghuPhone())
|
||||
.or()
|
||||
.eq("yonghu_id_number", yonghu.getYonghuIdNumber())
|
||||
.eq("data_delete", 1)
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
|
||||
if(yonghuEntity==null){
|
||||
yonghu.setDataDelete(1);
|
||||
yonghu.setInsertTime(new Date());
|
||||
yonghu.setCreateTime(new Date());
|
||||
yonghu.setPassword("123456");
|
||||
yonghuService.insert(yonghu);
|
||||
return R.ok();
|
||||
.eq("username", yonghu.getUsername()) // 用户名条件
|
||||
.or() // 或条件
|
||||
.eq("yonghu_phone", yonghu.getYonghuPhone()) // 手机号条件
|
||||
.or() // 或条件
|
||||
.eq("yonghu_id_number", yonghu.getYonghuIdNumber()) // 身份证号条件
|
||||
.eq("data_delete", 1) // 未删除条件
|
||||
;
|
||||
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句
|
||||
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper); // 查询是否存在
|
||||
if(yonghuEntity==null){ // 如果不存在
|
||||
yonghu.setDataDelete(1); // 设置未删除状态
|
||||
yonghu.setInsertTime(new Date()); // 设置插入时间
|
||||
yonghu.setCreateTime(new Date()); // 设置创建时间
|
||||
yonghu.setPassword("123456"); // 设置默认密码
|
||||
yonghuService.insert(yonghu); // 插入新用户
|
||||
return R.ok(); // 返回成功结果
|
||||
}else {
|
||||
return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用");
|
||||
return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用"); // 返回错误信息
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端修改
|
||||
*/
|
||||
|
||||
//后端修改用户
|
||||
//@param yonghu 用户实体
|
||||
//@param request HTTP请求对象
|
||||
//@return 操作结果
|
||||
@RequestMapping("/update")
|
||||
public R update(@RequestBody YonghuEntity yonghu, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
|
||||
logger.debug("update方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
|
||||
YonghuEntity oldYonghuEntity = yonghuService.selectById(yonghu.getId());//查询原先数据
|
||||
YonghuEntity oldYonghuEntity = yonghuService.selectById(yonghu.getId()); // 查询原数据
|
||||
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
||||
|
||||
String role = String.valueOf(request.getSession().getAttribute("role"));
|
||||
// if(false)
|
||||
// return R.error(511,"永远不会进入");
|
||||
if("".equals(yonghu.getYonghuPhoto()) || "null".equals(yonghu.getYonghuPhoto())){
|
||||
yonghu.setYonghuPhoto(null);
|
||||
if("".equals(yonghu.getYonghuPhoto()) || "null".equals(yonghu.getYonghuPhoto())){ // 如果图片为空
|
||||
yonghu.setYonghuPhoto(null); // 设置为null
|
||||
}
|
||||
|
||||
yonghuService.updateById(yonghu);//根据id更新
|
||||
return R.ok();
|
||||
yonghuService.updateById(yonghu); // 更新用户信息
|
||||
return R.ok(); // 返回成功结果
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
//删除用户(逻辑删除)
|
||||
//@param ids 用户ID数组
|
||||
//@param request HTTP请求对象
|
||||
//@return 操作结果
|
||||
@RequestMapping("/delete")
|
||||
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
|
||||
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
|
||||
List<YonghuEntity> oldYonghuList =yonghuService.selectBatchIds(Arrays.asList(ids));//要删除的数据
|
||||
ArrayList<YonghuEntity> list = new ArrayList<>();
|
||||
for(Integer id:ids){
|
||||
YonghuEntity yonghuEntity = new YonghuEntity();
|
||||
yonghuEntity.setId(id);
|
||||
yonghuEntity.setDataDelete(2);
|
||||
list.add(yonghuEntity);
|
||||
List<YonghuEntity> oldYonghuList = yonghuService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据
|
||||
ArrayList<YonghuEntity> list = new ArrayList<>(); // 创建更新列表
|
||||
for(Integer id:ids){ // 遍历ID数组
|
||||
YonghuEntity yonghuEntity = new YonghuEntity(); // 创建用户实体
|
||||
yonghuEntity.setId(id); // 设置ID
|
||||
yonghuEntity.setDataDelete(2); // 设置删除状态
|
||||
list.add(yonghuEntity); // 添加到列表
|
||||
}
|
||||
if(list != null && list.size() >0){
|
||||
yonghuService.updateBatchById(list);
|
||||
if(list != null && list.size() >0){ // 如果有数据需要更新
|
||||
yonghuService.updateBatchById(list); // 批量更新
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
return R.ok(); // 返回成功结果
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量上传
|
||||
*/
|
||||
//批量导入用户数据
|
||||
//@param fileName Excel文件名
|
||||
//@param request HTTP请求对象
|
||||
//@return 导入结果
|
||||
@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);
|
||||
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
//.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
|
||||
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取当前用户ID
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 创建日期格式化对象
|
||||
try {
|
||||
List<YonghuEntity> yonghuList = new ArrayList<>();//上传的东西
|
||||
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
|
||||
Date date = new Date();
|
||||
int lastIndexOf = fileName.lastIndexOf(".");
|
||||
if(lastIndexOf == -1){
|
||||
return R.error(511,"该文件没有后缀");
|
||||
List<YonghuEntity> yonghuList = new ArrayList<>(); // 创建用户列表
|
||||
Map<String, List<String>> seachFields = new HashMap<>(); // 创建查重字段Map
|
||||
Date date = new Date(); // 当前时间
|
||||
int lastIndexOf = fileName.lastIndexOf("."); // 获取文件后缀位置
|
||||
if(lastIndexOf == -1){ // 如果没有后缀
|
||||
return R.error(511,"该文件没有后缀"); // 返回错误信息
|
||||
}else{
|
||||
String suffix = fileName.substring(lastIndexOf);
|
||||
if(!".xls".equals(suffix)){
|
||||
return R.error(511,"只支持后缀为xls的excel文件");
|
||||
String suffix = fileName.substring(lastIndexOf); // 获取文件后缀
|
||||
if(!".xls".equals(suffix)){ // 如果不是xls文件
|
||||
return R.error(511,"只支持后缀为xls的excel文件"); // 返回错误信息
|
||||
}else{
|
||||
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
|
||||
File file = new File(resource.getFile());
|
||||
if(!file.exists()){
|
||||
return R.error(511,"找不到上传文件,请联系管理员");
|
||||
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName); // 获取文件路径
|
||||
File file = new File(resource.getFile()); // 创建文件对象
|
||||
if(!file.exists()){ // 如果文件不存在
|
||||
return R.error(511,"找不到上传文件,请联系管理员"); // 返回错误信息
|
||||
}else{
|
||||
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
|
||||
dataList.remove(0);//删除第一行,因为第一行是提示
|
||||
for(List<String> data:dataList){
|
||||
//循环
|
||||
YonghuEntity yonghuEntity = new YonghuEntity();
|
||||
// yonghuEntity.setUsername(data.get(0)); //账户 要改的
|
||||
// yonghuEntity.setPassword("123456");//密码
|
||||
// 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")){
|
||||
List<String> username = seachFields.get("username");
|
||||
username.add(data.get(0));//要改的
|
||||
}else{
|
||||
List<String> username = new ArrayList<>();
|
||||
username.add(data.get(0));//要改的
|
||||
seachFields.put("username",username);
|
||||
}
|
||||
//用户手机号
|
||||
if(seachFields.containsKey("yonghuPhone")){
|
||||
List<String> yonghuPhone = seachFields.get("yonghuPhone");
|
||||
yonghuPhone.add(data.get(0));//要改的
|
||||
}else{
|
||||
List<String> yonghuPhone = new ArrayList<>();
|
||||
yonghuPhone.add(data.get(0));//要改的
|
||||
seachFields.put("yonghuPhone",yonghuPhone);
|
||||
}
|
||||
//用户身份证号
|
||||
if(seachFields.containsKey("yonghuIdNumber")){
|
||||
List<String> yonghuIdNumber = seachFields.get("yonghuIdNumber");
|
||||
yonghuIdNumber.add(data.get(0));//要改的
|
||||
}else{
|
||||
List<String> yonghuIdNumber = new ArrayList<>();
|
||||
yonghuIdNumber.add(data.get(0));//要改的
|
||||
seachFields.put("yonghuIdNumber",yonghuIdNumber);
|
||||
}
|
||||
List<List<String>> dataList = PoiUtil.poiImport(file.getPath()); // 读取Excel文件
|
||||
dataList.remove(0); // 删除标题行
|
||||
for(List<String> data:dataList){ // 遍历数据行
|
||||
YonghuEntity yonghuEntity = new YonghuEntity(); // 创建用户实体
|
||||
// 可以在此处设置实体属性,示例中被注释掉了
|
||||
yonghuList.add(yonghuEntity); // 添加到列表
|
||||
|
||||
// 构建查重字段Map
|
||||
// 账户查重
|
||||
if(seachFields.containsKey("username")){
|
||||
List<String> username = seachFields.get("username");
|
||||
username.add(data.get(0)); // 添加用户名
|
||||
}else{
|
||||
List<String> username = new ArrayList<>();
|
||||
username.add(data.get(0)); // 添加用户名
|
||||
seachFields.put("username",username); // 放入Map
|
||||
}
|
||||
// 手机号查重
|
||||
if(seachFields.containsKey("yonghuPhone")){
|
||||
List<String> yonghuPhone = seachFields.get("yonghuPhone");
|
||||
yonghuPhone.add(data.get(0)); // 添加手机号
|
||||
}else{
|
||||
List<String> yonghuPhone = new ArrayList<>();
|
||||
yonghuPhone.add(data.get(0)); // 添加手机号
|
||||
seachFields.put("yonghuPhone",yonghuPhone); // 放入Map
|
||||
}
|
||||
// 身份证号查重
|
||||
if(seachFields.containsKey("yonghuIdNumber")){
|
||||
List<String> yonghuIdNumber = seachFields.get("yonghuIdNumber");
|
||||
yonghuIdNumber.add(data.get(0)); // 添加身份证号
|
||||
}else{
|
||||
List<String> yonghuIdNumber = new ArrayList<>();
|
||||
yonghuIdNumber.add(data.get(0)); // 添加身份证号
|
||||
seachFields.put("yonghuIdNumber",yonghuIdNumber); // 放入Map
|
||||
}
|
||||
}
|
||||
|
||||
//查询是否重复
|
||||
//账户
|
||||
List<YonghuEntity> yonghuEntities_username = yonghuService.selectList(new EntityWrapper<YonghuEntity>().in("username", seachFields.get("username")).eq("data_delete", 1));
|
||||
if(yonghuEntities_username.size() >0 ){
|
||||
ArrayList<String> repeatFields = new ArrayList<>();
|
||||
for(YonghuEntity s:yonghuEntities_username){
|
||||
repeatFields.add(s.getUsername());
|
||||
// 查重验证
|
||||
// 验证用户名是否重复
|
||||
List<YonghuEntity> yonghuEntities_username = yonghuService.selectList(
|
||||
new EntityWrapper<YonghuEntity>().in("username", seachFields.get("username")).eq("data_delete", 1));
|
||||
if(yonghuEntities_username.size() >0 ){ // 如果有重复
|
||||
ArrayList<String> repeatFields = new ArrayList<>(); // 创建重复字段列表
|
||||
for(YonghuEntity s:yonghuEntities_username){ // 遍历重复数据
|
||||
repeatFields.add(s.getUsername()); // 添加重复用户名
|
||||
}
|
||||
return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString());
|
||||
return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString()); // 返回错误信息
|
||||
}
|
||||
//用户手机号
|
||||
List<YonghuEntity> yonghuEntities_yonghuPhone = yonghuService.selectList(new EntityWrapper<YonghuEntity>().in("yonghu_phone", seachFields.get("yonghuPhone")).eq("data_delete", 1));
|
||||
if(yonghuEntities_yonghuPhone.size() >0 ){
|
||||
ArrayList<String> repeatFields = new ArrayList<>();
|
||||
for(YonghuEntity s:yonghuEntities_yonghuPhone){
|
||||
repeatFields.add(s.getYonghuPhone());
|
||||
// 验证手机号是否重复
|
||||
List<YonghuEntity> yonghuEntities_yonghuPhone = yonghuService.selectList(
|
||||
new EntityWrapper<YonghuEntity>().in("yonghu_phone", seachFields.get("yonghuPhone")).eq("data_delete", 1));
|
||||
if(yonghuEntities_yonghuPhone.size() >0 ){ // 如果有重复
|
||||
ArrayList<String> repeatFields = new ArrayList<>(); // 创建重复字段列表
|
||||
for(YonghuEntity s:yonghuEntities_yonghuPhone){ // 遍历重复数据
|
||||
repeatFields.add(s.getYonghuPhone()); // 添加重复手机号
|
||||
}
|
||||
return R.error(511,"数据库的该表中的 [用户手机号] 字段已经存在 存在数据为:"+repeatFields.toString());
|
||||
return R.error(511,"数据库的该表中的 [用户手机号] 字段已经存在 存在数据为:"+repeatFields.toString()); // 返回错误信息
|
||||
}
|
||||
//用户身份证号
|
||||
List<YonghuEntity> yonghuEntities_yonghuIdNumber = yonghuService.selectList(new EntityWrapper<YonghuEntity>().in("yonghu_id_number", seachFields.get("yonghuIdNumber")).eq("data_delete", 1));
|
||||
if(yonghuEntities_yonghuIdNumber.size() >0 ){
|
||||
ArrayList<String> repeatFields = new ArrayList<>();
|
||||
for(YonghuEntity s:yonghuEntities_yonghuIdNumber){
|
||||
repeatFields.add(s.getYonghuIdNumber());
|
||||
// 验证身份证号是否重复
|
||||
List<YonghuEntity> yonghuEntities_yonghuIdNumber = yonghuService.selectList(
|
||||
new EntityWrapper<YonghuEntity>().in("yonghu_id_number", seachFields.get("yonghuIdNumber")).eq("data_delete", 1));
|
||||
if(yonghuEntities_yonghuIdNumber.size() >0 ){ // 如果有重复
|
||||
ArrayList<String> repeatFields = new ArrayList<>(); // 创建重复字段列表
|
||||
for(YonghuEntity s:yonghuEntities_yonghuIdNumber){ // 遍历重复数据
|
||||
repeatFields.add(s.getYonghuIdNumber()); // 添加重复身份证号
|
||||
}
|
||||
return R.error(511,"数据库的该表中的 [用户身份证号] 字段已经存在 存在数据为:"+repeatFields.toString());
|
||||
return R.error(511,"数据库的该表中的 [用户身份证号] 字段已经存在 存在数据为:"+repeatFields.toString()); // 返回错误信息
|
||||
}
|
||||
yonghuService.insertBatch(yonghuList);
|
||||
return R.ok();
|
||||
yonghuService.insertBatch(yonghuList); // 批量插入数据
|
||||
return R.ok(); // 返回成功结果
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return R.error(511,"批量插入数据异常,请联系管理员");
|
||||
}catch (Exception e){ // 捕获异常
|
||||
e.printStackTrace(); // 打印异常堆栈
|
||||
return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
@IgnoreAuth
|
||||
|
||||
//用户登录
|
||||
//@param username 用户名
|
||||
//@param password 密码
|
||||
//@param captcha 验证码
|
||||
//@param request HTTP请求对象
|
||||
//@return 登录结果
|
||||
@IgnoreAuth // 忽略认证
|
||||
@RequestMapping(value = "/login")
|
||||
public R login(String username, String password, String captcha, HttpServletRequest request) {
|
||||
YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("username", username));
|
||||
if(yonghu==null || !yonghu.getPassword().equals(password))
|
||||
return R.error("账号或密码不正确");
|
||||
else if(yonghu.getDataDelete() != 1)
|
||||
return R.error("账户已被删除");
|
||||
String token = tokenService.generateToken(yonghu.getId(),username, "yonghu", "用户");
|
||||
R r = R.ok();
|
||||
r.put("token", token);
|
||||
r.put("role","用户");
|
||||
r.put("username",yonghu.getYonghuName());
|
||||
r.put("tableName","yonghu");
|
||||
r.put("userId",yonghu.getId());
|
||||
return r;
|
||||
YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("username", username)); // 根据用户名查询用户
|
||||
if(yonghu==null || !yonghu.getPassword().equals(password)) // 验证用户名和密码
|
||||
return R.error("账号或密码不正确"); // 返回错误信息
|
||||
else if(yonghu.getDataDelete() != 1) // 检查是否被删除
|
||||
return R.error("账户已被删除"); // 返回错误信息
|
||||
String token = tokenService.generateToken(yonghu.getId(),username, "yonghu", "用户"); // 生成Token
|
||||
R r = R.ok(); // 创建返回结果
|
||||
r.put("token", token); // 添加Token
|
||||
r.put("role","用户"); // 添加角色
|
||||
r.put("username",yonghu.getYonghuName()); // 添加用户名
|
||||
r.put("tableName","yonghu"); // 添加表名
|
||||
r.put("userId",yonghu.getId()); // 添加用户ID
|
||||
return r; // 返回结果
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
@IgnoreAuth
|
||||
|
||||
//用户注册
|
||||
//@param yonghu 用户实体
|
||||
// @param request HTTP请求对象
|
||||
//@return 注册结果
|
||||
|
||||
@IgnoreAuth // 忽略认证
|
||||
@PostMapping(value = "/register")
|
||||
public R register(@RequestBody YonghuEntity yonghu, HttpServletRequest request) {
|
||||
// ValidatorUtils.validateEntity(user);
|
||||
// 构建查询条件:检查用户名、手机号、身份证号是否已存在
|
||||
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
|
||||
.eq("username", yonghu.getUsername())
|
||||
.or()
|
||||
.eq("yonghu_phone", yonghu.getYonghuPhone())
|
||||
.or()
|
||||
.eq("yonghu_id_number", yonghu.getYonghuIdNumber())
|
||||
.andNew()
|
||||
.eq("data_delete", 1)
|
||||
;
|
||||
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
|
||||
if(yonghuEntity != null)
|
||||
return R.error("账户或者用户手机号或者用户身份证号已经被使用");
|
||||
yonghu.setNewMoney(0.0);
|
||||
yonghu.setDataDelete(1);
|
||||
yonghu.setInsertTime(new Date());
|
||||
yonghu.setCreateTime(new Date());
|
||||
yonghuService.insert(yonghu);
|
||||
|
||||
return R.ok();
|
||||
.eq("username", yonghu.getUsername()) // 用户名条件
|
||||
.or() // 或条件
|
||||
.eq("yonghu_phone", yonghu.getYonghuPhone()) // 手机号条件
|
||||
.or() // 或条件
|
||||
.eq("yonghu_id_number", yonghu.getYonghuIdNumber()) // 身份证号条件
|
||||
.andNew() // 新条件组
|
||||
.eq("data_delete", 1) // 未删除条件
|
||||
;
|
||||
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper); // 查询是否存在
|
||||
if(yonghuEntity != null) // 如果已存在
|
||||
return R.error("账户或者用户手机号或者用户身份证号已经被使用"); // 返回错误信息
|
||||
yonghu.setNewMoney(0.0); // 设置初始余额
|
||||
yonghu.setDataDelete(1); // 设置未删除状态
|
||||
yonghu.setInsertTime(new Date()); // 设置插入时间
|
||||
yonghu.setCreateTime(new Date()); // 设置创建时间
|
||||
yonghuService.insert(yonghu); // 插入新用户
|
||||
return R.ok(); // 返回成功结果
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*/
|
||||
|
||||
//重置密码为默认值
|
||||
//@param id 用户ID
|
||||
//@param request HTTP请求对象
|
||||
// @return 操作结果
|
||||
|
||||
@GetMapping(value = "/resetPassword")
|
||||
public R resetPassword(Integer id, HttpServletRequest request) {
|
||||
YonghuEntity yonghu = yonghuService.selectById(id);
|
||||
yonghu.setPassword("123456");
|
||||
yonghuService.updateById(yonghu);
|
||||
return R.ok();
|
||||
public R resetPassword(Integer id, HttpServletRequest request) {
|
||||
YonghuEntity yonghu = yonghuService.selectById(id); // 根据ID查询用户
|
||||
yonghu.setPassword("123456"); // 重置密码
|
||||
yonghuService.updateById(yonghu); // 更新用户
|
||||
return R.ok(); // 返回成功结果
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
@GetMapping(value = "/updatePassword")
|
||||
public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) {
|
||||
YonghuEntity yonghu = yonghuService.selectById((Integer)request.getSession().getAttribute("userId"));
|
||||
if(newPassword == null){
|
||||
return R.error("新密码不能为空") ;
|
||||
}
|
||||
if(!oldPassword.equals(yonghu.getPassword())){
|
||||
return R.error("原密码输入错误");
|
||||
}
|
||||
if(newPassword.equals(yonghu.getPassword())){
|
||||
return R.error("新密码不能和原密码一致") ;
|
||||
}
|
||||
yonghu.setPassword(newPassword);
|
||||
yonghuService.updateById(yonghu);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 忘记密码
|
||||
*/
|
||||
@IgnoreAuth
|
||||
//修改密码
|
||||
//@param oldPassword 旧密码
|
||||
//@param newPassword 新密码
|
||||
//@param request HTTP请求对象
|
||||
// @return 操作结果
|
||||
|
||||
@GetMapping(value = "/updatePassword")
|
||||
public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) {
|
||||
YonghuEntity yonghu = yonghuService.selectById((Integer)request.getSession().getAttribute("userId")); // 获取当前用户
|
||||
if(newPassword == null){ // 检查新密码是否为空
|
||||
return R.error("新密码不能为空") ; // 返回错误信息
|
||||
}
|
||||
if(!oldPassword.equals(yonghu.getPassword())){ // 检查旧密码是否正确
|
||||
return R.error("原密码输入错误"); // 返回错误信息
|
||||
}
|
||||
if(newPassword.equals(yonghu.getPassword())){ // 检查新旧密码是否相同
|
||||
return R.error("新密码不能和原密码一致") ; // 返回错误信息
|
||||
}
|
||||
yonghu.setPassword(newPassword); // 设置新密码
|
||||
yonghuService.updateById(yonghu); // 更新用户
|
||||
return R.ok(); // 返回成功结果
|
||||
}
|
||||
|
||||
//忘记密码(重置为默认密码)
|
||||
//@param username 用户名
|
||||
//@param request HTTP请求对象
|
||||
//@return 操作结果
|
||||
@IgnoreAuth // 忽略认证
|
||||
@RequestMapping(value = "/resetPass")
|
||||
public R resetPass(String username, HttpServletRequest request) {
|
||||
YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("username", username));
|
||||
if(yonghu!=null){
|
||||
yonghu.setPassword("123456");
|
||||
yonghuService.updateById(yonghu);
|
||||
return R.ok();
|
||||
}else{
|
||||
return R.error("账号不存在");
|
||||
YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("username", username)); // 根据用户名查询用户
|
||||
if(yonghu!=null){ // 如果用户存在
|
||||
yonghu.setPassword("123456"); // 重置密码
|
||||
yonghuService.updateById(yonghu); // 更新用户
|
||||
return R.ok(); // 返回成功结果
|
||||
}else{ // 如果用户不存在
|
||||
return R.error("账号不存在"); // 返回错误信息
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户的session用户信息
|
||||
*/
|
||||
//获取当前会话用户信息
|
||||
//@param request HTTP请求对象
|
||||
//@return 用户信息
|
||||
@RequestMapping("/session")
|
||||
public R getCurrYonghu(HttpServletRequest request){
|
||||
Integer id = (Integer)request.getSession().getAttribute("userId");
|
||||
YonghuEntity yonghu = yonghuService.selectById(id);
|
||||
if(yonghu !=null){
|
||||
//entity转view
|
||||
YonghuView view = new YonghuView();
|
||||
BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中
|
||||
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
Integer id = (Integer)request.getSession().getAttribute("userId"); // 获取当前用户ID
|
||||
YonghuEntity yonghu = yonghuService.selectById(id); // 查询用户信息
|
||||
if(yonghu !=null){ // 如果用户存在
|
||||
YonghuView view = new YonghuView(); // 创建视图对象
|
||||
BeanUtils.copyProperties(yonghu, view); // 复制属性
|
||||
dictionaryService.dictionaryConvert(view, request); // 转换字典字段
|
||||
return R.ok().put("data", view); // 返回用户信息
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
return R.error(511,"查不到数据"); // 返回错误信息
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出
|
||||
*/
|
||||
//用户退出
|
||||
//@param request HTTP请求对象
|
||||
//@return 操作结果
|
||||
@GetMapping(value = "logout")
|
||||
public R logout(HttpServletRequest request) {
|
||||
request.getSession().invalidate();
|
||||
return R.ok("退出成功");
|
||||
request.getSession().invalidate(); // 使会话失效
|
||||
return R.ok("退出成功"); // 返回成功信息
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 前端列表
|
||||
*/
|
||||
@IgnoreAuth
|
||||
//前端分页列表
|
||||
//@param params 请求参数
|
||||
//@param request HTTP请求对象
|
||||
//@return 分页结果
|
||||
@IgnoreAuth // 忽略认证
|
||||
@RequestMapping("/list")
|
||||
public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
||||
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
||||
CommonUtil.checkMap(params); // 检查参数
|
||||
PageUtils page = yonghuService.queryPage(params); // 分页查询
|
||||
|
||||
CommonUtil.checkMap(params);
|
||||
PageUtils page = yonghuService.queryPage(params);
|
||||
// 字典表数据转换
|
||||
List<YonghuView> list =(List<YonghuView>)page.getList(); // 获取分页数据
|
||||
for(YonghuView c:list) // 遍历数据
|
||||
dictionaryService.dictionaryConvert(c, request); // 转换字典字段
|
||||
|
||||
//字典表数据转换
|
||||
List<YonghuView> list =(List<YonghuView>)page.getList();
|
||||
for(YonghuView c:list)
|
||||
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
|
||||
|
||||
return R.ok().put("data", page);
|
||||
return R.ok().put("data", page); // 返回分页结果
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端详情
|
||||
*/
|
||||
|
||||
//前端详情
|
||||
//@param id 用户ID
|
||||
//@param request HTTP请求对象
|
||||
//@return 用户详情
|
||||
@RequestMapping("/detail/{id}")
|
||||
public R detail(@PathVariable("id") Integer id, HttpServletRequest request){
|
||||
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
|
||||
YonghuEntity yonghu = yonghuService.selectById(id);
|
||||
if(yonghu !=null){
|
||||
|
||||
|
||||
//entity转view
|
||||
YonghuView view = new YonghuView();
|
||||
BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中
|
||||
|
||||
//修改对应字典表字段
|
||||
dictionaryService.dictionaryConvert(view, request);
|
||||
return R.ok().put("data", view);
|
||||
}else {
|
||||
return R.error(511,"查不到数据");
|
||||
}
|
||||
YonghuEntity yonghu = yonghuService.selectById(id); // 根据ID查询用户
|
||||
if(yonghu !=null){ // 如果用户存在
|
||||
YonghuView view = new YonghuView(); // 创建视图对象
|
||||
BeanUtils.copyProperties(yonghu, view); // 复制属性
|
||||
dictionaryService.dictionaryConvert(view, request); // 转换字典字段
|
||||
return R.ok().put("data", view); // 返回用户信息
|
||||
}else {
|
||||
return R.error(511,"查不到数据"); // 返回错误信息
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 前端保存
|
||||
*/
|
||||
//前端保存用户
|
||||
//@param yonghu 用户实体
|
||||
//@param request HTTP请求对象
|
||||
//@return 操作结果
|
||||
@RequestMapping("/add")
|
||||
public R add(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
|
||||
logger.debug("add方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
|
||||
// 构建查询条件:检查用户名、手机号、身份证号是否已存在
|
||||
Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
|
||||
.eq("username", yonghu.getUsername())
|
||||
.or()
|
||||
.eq("yonghu_phone", yonghu.getYonghuPhone())
|
||||
.or()
|
||||
.eq("yonghu_id_number", yonghu.getYonghuIdNumber())
|
||||
.andNew()
|
||||
.eq("data_delete", 1)
|
||||
// .notIn("yonghu_types", new Integer[]{102})
|
||||
;
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
||||
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
|
||||
if(yonghuEntity==null){
|
||||
yonghu.setDataDelete(1);
|
||||
yonghu.setInsertTime(new Date());
|
||||
yonghu.setCreateTime(new Date());
|
||||
yonghu.setPassword("123456");
|
||||
yonghuService.insert(yonghu);
|
||||
|
||||
return R.ok();
|
||||
.eq("username", yonghu.getUsername()) // 用户名条件
|
||||
.or() // 或条件
|
||||
.eq("yonghu_phone", yonghu.getYonghuPhone()) // 手机号条件
|
||||
.or() // 或条件
|
||||
.eq("yonghu_id_number", yonghu.getYonghuIdNumber()) // 身份证号条件
|
||||
.andNew() // 新条件组
|
||||
.eq("data_delete", 1) // 未删除条件
|
||||
;
|
||||
logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句
|
||||
YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper); // 查询是否存在
|
||||
if(yonghuEntity==null){ // 如果不存在
|
||||
yonghu.setDataDelete(1); // 设置未删除状态
|
||||
yonghu.setInsertTime(new Date()); // 设置插入时间
|
||||
yonghu.setCreateTime(new Date()); // 设置创建时间
|
||||
yonghu.setPassword("123456"); // 设置默认密码
|
||||
yonghuService.insert(yonghu); // 插入新用户
|
||||
return R.ok(); // 返回成功结果
|
||||
}else {
|
||||
return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用");
|
||||
return R.error(511,"账户或者用户手机号或者用户身份证号已经被使用"); // 返回错误信息
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue