|
|
@ -1,521 +1,532 @@
|
|
|
|
|
|
|
|
package com.controller; // 声明当前类所在的包路径
|
|
|
|
package com.controller;
|
|
|
|
|
|
|
|
|
|
|
|
// 导入Java IO类
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File; // 文件操作类
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
// 导入数学类
|
|
|
|
import java.net.URL;
|
|
|
|
import java.math.BigDecimal; // 高精度数字计算类
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
// 导入网络类
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import java.net.URL; // 统一资源定位符类
|
|
|
|
import java.util.*;
|
|
|
|
// 导入文本处理类
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import java.text.SimpleDateFormat; // 日期格式化类
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
// 导入JSON处理类
|
|
|
|
import org.springframework.web.context.ContextLoader;
|
|
|
|
import com.alibaba.fastjson.JSONObject; // FastJSON对象类
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
// 导入集合类
|
|
|
|
import com.service.TokenService;
|
|
|
|
import java.util.*; // 通用集合工具类
|
|
|
|
import com.utils.*;
|
|
|
|
// 导入Spring Bean工具类
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import org.springframework.beans.BeanUtils; // Bean属性复制工具类
|
|
|
|
|
|
|
|
// 导入Servlet类
|
|
|
|
import com.service.DictionaryService;
|
|
|
|
import javax.servlet.http.HttpServletRequest; // HTTP请求对象
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
// 导入Spring上下文类
|
|
|
|
import com.annotation.IgnoreAuth;
|
|
|
|
import org.springframework.web.context.ContextLoader; // Web应用上下文加载器
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
// 导入Servlet上下文类
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import javax.servlet.ServletContext; // Servlet上下文对象
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
// 导入自定义服务类
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import com.service.TokenService; // Token服务接口
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
// 导入自定义工具类
|
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
|
import com.utils.*; // 自定义工具类集合
|
|
|
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
|
|
|
// 导入反射异常类
|
|
|
|
import com.entity.*;
|
|
|
|
import java.lang.reflect.InvocationTargetException; // 反射调用异常类
|
|
|
|
import com.entity.view.*;
|
|
|
|
|
|
|
|
import com.service.*;
|
|
|
|
// 导入字典服务类
|
|
|
|
import com.utils.PageUtils;
|
|
|
|
import com.service.DictionaryService; // 字典数据服务接口
|
|
|
|
import com.utils.R;
|
|
|
|
// 导入Apache Commons工具类
|
|
|
|
import com.alibaba.fastjson.*;
|
|
|
|
import org.apache.commons.lang3.StringUtils; // 字符串处理工具类
|
|
|
|
|
|
|
|
// 导入自定义注解
|
|
|
|
/**
|
|
|
|
import com.annotation.IgnoreAuth; // 忽略认证注解
|
|
|
|
* 用户
|
|
|
|
// 导入日志类
|
|
|
|
* 后端接口
|
|
|
|
import org.slf4j.Logger; // 日志接口
|
|
|
|
* @author
|
|
|
|
import org.slf4j.LoggerFactory; // 日志工厂类
|
|
|
|
* @email
|
|
|
|
// 导入Spring注解
|
|
|
|
*/
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; // 自动注入注解
|
|
|
|
@RestController
|
|
|
|
import org.springframework.stereotype.Controller; // 控制器注解
|
|
|
|
@Controller
|
|
|
|
import org.springframework.web.bind.annotation.*; // Web请求相关注解
|
|
|
|
@RequestMapping("/yonghu")
|
|
|
|
// 导入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 {
|
|
|
|
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"));
|
|
|
|
params.put("yonghuId",request.getSession().getAttribute("userId")); // 添加用户ID参数
|
|
|
|
else if("教练".equals(role))
|
|
|
|
else if("教练".equals(role)) // 如果是教练角色
|
|
|
|
params.put("jiaolianId",request.getSession().getAttribute("userId"));
|
|
|
|
params.put("jiaolianId",request.getSession().getAttribute("userId")); // 添加教练ID参数
|
|
|
|
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);
|
|
|
|
YonghuEntity yonghu = yonghuService.selectById(id); // 根据ID查询用户
|
|
|
|
if(yonghu !=null){
|
|
|
|
if(yonghu !=null){ // 如果查询到数据
|
|
|
|
//entity转view
|
|
|
|
YonghuView view = new YonghuView(); // 创建视图对象
|
|
|
|
YonghuView view = new YonghuView();
|
|
|
|
BeanUtils.copyProperties(yonghu, view); // 复制属性到视图对象
|
|
|
|
BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中
|
|
|
|
dictionaryService.dictionaryConvert(view, request); // 转换字典表字段
|
|
|
|
//修改对应字典表字段
|
|
|
|
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());
|
|
|
|
logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句
|
|
|
|
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")); // 获取用户角色
|
|
|
|
|
|
|
|
|
|
|
|
String role = String.valueOf(request.getSession().getAttribute("role"));
|
|
|
|
if("".equals(yonghu.getYonghuPhoto()) || "null".equals(yonghu.getYonghuPhoto())){ // 如果图片为空
|
|
|
|
// if(false)
|
|
|
|
yonghu.setYonghuPhoto(null); // 设置为null
|
|
|
|
// return R.error(511,"永远不会进入");
|
|
|
|
|
|
|
|
if("".equals(yonghu.getYonghuPhoto()) || "null".equals(yonghu.getYonghuPhoto())){
|
|
|
|
|
|
|
|
yonghu.setYonghuPhoto(null);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
yonghuService.updateById(yonghu);//根据id更新
|
|
|
|
yonghuService.updateById(yonghu); // 更新用户信息
|
|
|
|
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){
|
|
|
|
for(Integer id:ids){ // 遍历ID数组
|
|
|
|
YonghuEntity yonghuEntity = new YonghuEntity();
|
|
|
|
YonghuEntity yonghuEntity = new YonghuEntity(); // 创建用户实体
|
|
|
|
yonghuEntity.setId(id);
|
|
|
|
yonghuEntity.setId(id); // 设置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")));
|
|
|
|
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))); // 获取当前用户ID
|
|
|
|
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<String, List<String>> seachFields = new HashMap<>(); // 创建查重字段Map
|
|
|
|
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)){
|
|
|
|
if(!".xls".equals(suffix)){ // 如果不是xls文件
|
|
|
|
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());//读取xls文件
|
|
|
|
List<List<String>> dataList = PoiUtil.poiImport(file.getPath()); // 读取Excel文件
|
|
|
|
dataList.remove(0);//删除第一行,因为第一行是提示
|
|
|
|
dataList.remove(0); // 删除标题行
|
|
|
|
for(List<String> data:dataList){
|
|
|
|
for(List<String> data:dataList){ // 遍历数据行
|
|
|
|
//循环
|
|
|
|
YonghuEntity yonghuEntity = new YonghuEntity(); // 创建用户实体
|
|
|
|
YonghuEntity yonghuEntity = new YonghuEntity();
|
|
|
|
// 可以在此处设置实体属性,示例中被注释掉了
|
|
|
|
// yonghuEntity.setUsername(data.get(0)); //账户 要改的
|
|
|
|
yonghuList.add(yonghuEntity); // 添加到列表
|
|
|
|
// yonghuEntity.setPassword("123456");//密码
|
|
|
|
|
|
|
|
// yonghuEntity.setYonghuName(data.get(0)); //用户名称 要改的
|
|
|
|
// 构建查重字段Map
|
|
|
|
// yonghuEntity.setYonghuPhone(data.get(0)); //用户手机号 要改的
|
|
|
|
// 账户查重
|
|
|
|
// yonghuEntity.setYonghuIdNumber(data.get(0)); //用户身份证号 要改的
|
|
|
|
if(seachFields.containsKey("username")){
|
|
|
|
// yonghuEntity.setYonghuPhoto("");//详情和图片
|
|
|
|
List<String> username = seachFields.get("username");
|
|
|
|
// yonghuEntity.setSexTypes(Integer.valueOf(data.get(0))); //性别 要改的
|
|
|
|
username.add(data.get(0)); // 添加用户名
|
|
|
|
// yonghuEntity.setYonghuEmail(data.get(0)); //用户邮箱 要改的
|
|
|
|
}else{
|
|
|
|
// yonghuEntity.setNewMoney(data.get(0)); //现有余额 要改的
|
|
|
|
List<String> username = new ArrayList<>();
|
|
|
|
// yonghuEntity.setDataDelete(1);//逻辑删除字段
|
|
|
|
username.add(data.get(0)); // 添加用户名
|
|
|
|
// yonghuEntity.setInsertTime(date);//时间
|
|
|
|
seachFields.put("username",username); // 放入Map
|
|
|
|
// yonghuEntity.setCreateTime(date);//时间
|
|
|
|
}
|
|
|
|
yonghuList.add(yonghuEntity);
|
|
|
|
// 手机号查重
|
|
|
|
|
|
|
|
if(seachFields.containsKey("yonghuPhone")){
|
|
|
|
|
|
|
|
List<String> yonghuPhone = seachFields.get("yonghuPhone");
|
|
|
|
//把要查询是否重复的字段放入map中
|
|
|
|
yonghuPhone.add(data.get(0)); // 添加手机号
|
|
|
|
//账户
|
|
|
|
}else{
|
|
|
|
if(seachFields.containsKey("username")){
|
|
|
|
List<String> yonghuPhone = new ArrayList<>();
|
|
|
|
List<String> username = seachFields.get("username");
|
|
|
|
yonghuPhone.add(data.get(0)); // 添加手机号
|
|
|
|
username.add(data.get(0));//要改的
|
|
|
|
seachFields.put("yonghuPhone",yonghuPhone); // 放入Map
|
|
|
|
}else{
|
|
|
|
}
|
|
|
|
List<String> username = new ArrayList<>();
|
|
|
|
// 身份证号查重
|
|
|
|
username.add(data.get(0));//要改的
|
|
|
|
if(seachFields.containsKey("yonghuIdNumber")){
|
|
|
|
seachFields.put("username",username);
|
|
|
|
List<String> yonghuIdNumber = seachFields.get("yonghuIdNumber");
|
|
|
|
}
|
|
|
|
yonghuIdNumber.add(data.get(0)); // 添加身份证号
|
|
|
|
//用户手机号
|
|
|
|
}else{
|
|
|
|
if(seachFields.containsKey("yonghuPhone")){
|
|
|
|
List<String> yonghuIdNumber = new ArrayList<>();
|
|
|
|
List<String> yonghuPhone = seachFields.get("yonghuPhone");
|
|
|
|
yonghuIdNumber.add(data.get(0)); // 添加身份证号
|
|
|
|
yonghuPhone.add(data.get(0));//要改的
|
|
|
|
seachFields.put("yonghuIdNumber",yonghuIdNumber); // 放入Map
|
|
|
|
}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<YonghuEntity> yonghuEntities_username = yonghuService.selectList(new EntityWrapper<YonghuEntity>().in("username", seachFields.get("username")).eq("data_delete", 1));
|
|
|
|
List<YonghuEntity> yonghuEntities_username = yonghuService.selectList(
|
|
|
|
if(yonghuEntities_username.size() >0 ){
|
|
|
|
new EntityWrapper<YonghuEntity>().in("username", seachFields.get("username")).eq("data_delete", 1));
|
|
|
|
ArrayList<String> repeatFields = new ArrayList<>();
|
|
|
|
if(yonghuEntities_username.size() >0 ){ // 如果有重复
|
|
|
|
for(YonghuEntity s:yonghuEntities_username){
|
|
|
|
ArrayList<String> repeatFields = new ArrayList<>(); // 创建重复字段列表
|
|
|
|
repeatFields.add(s.getUsername());
|
|
|
|
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));
|
|
|
|
List<YonghuEntity> yonghuEntities_yonghuPhone = yonghuService.selectList(
|
|
|
|
if(yonghuEntities_yonghuPhone.size() >0 ){
|
|
|
|
new EntityWrapper<YonghuEntity>().in("yonghu_phone", seachFields.get("yonghuPhone")).eq("data_delete", 1));
|
|
|
|
ArrayList<String> repeatFields = new ArrayList<>();
|
|
|
|
if(yonghuEntities_yonghuPhone.size() >0 ){ // 如果有重复
|
|
|
|
for(YonghuEntity s:yonghuEntities_yonghuPhone){
|
|
|
|
ArrayList<String> repeatFields = new ArrayList<>(); // 创建重复字段列表
|
|
|
|
repeatFields.add(s.getYonghuPhone());
|
|
|
|
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));
|
|
|
|
List<YonghuEntity> yonghuEntities_yonghuIdNumber = yonghuService.selectList(
|
|
|
|
if(yonghuEntities_yonghuIdNumber.size() >0 ){
|
|
|
|
new EntityWrapper<YonghuEntity>().in("yonghu_id_number", seachFields.get("yonghuIdNumber")).eq("data_delete", 1));
|
|
|
|
ArrayList<String> repeatFields = new ArrayList<>();
|
|
|
|
if(yonghuEntities_yonghuIdNumber.size() >0 ){ // 如果有重复
|
|
|
|
for(YonghuEntity s:yonghuEntities_yonghuIdNumber){
|
|
|
|
ArrayList<String> repeatFields = new ArrayList<>(); // 创建重复字段列表
|
|
|
|
repeatFields.add(s.getYonghuIdNumber());
|
|
|
|
for(YonghuEntity s:yonghuEntities_yonghuIdNumber){ // 遍历重复数据
|
|
|
|
|
|
|
|
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 用户名
|
|
|
|
@IgnoreAuth
|
|
|
|
//@param password 密码
|
|
|
|
|
|
|
|
//@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", "用户");
|
|
|
|
String token = tokenService.generateToken(yonghu.getId(),username, "yonghu", "用户"); // 生成Token
|
|
|
|
R r = R.ok();
|
|
|
|
R r = R.ok(); // 创建返回结果
|
|
|
|
r.put("token", token);
|
|
|
|
r.put("token", 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());
|
|
|
|
r.put("userId",yonghu.getId()); // 添加用户ID
|
|
|
|
return r;
|
|
|
|
return r; // 返回结果
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 注册
|
|
|
|
//用户注册
|
|
|
|
*/
|
|
|
|
//@param yonghu 用户实体
|
|
|
|
@IgnoreAuth
|
|
|
|
// @param request HTTP请求对象
|
|
|
|
|
|
|
|
//@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);
|
|
|
|
YonghuEntity yonghu = yonghuService.selectById(id); // 根据ID查询用户
|
|
|
|
yonghu.setPassword("123456");
|
|
|
|
yonghu.setPassword("123456"); // 重置密码
|
|
|
|
yonghuService.updateById(yonghu);
|
|
|
|
yonghuService.updateById(yonghu); // 更新用户
|
|
|
|
return R.ok();
|
|
|
|
return R.ok(); // 返回成功结果
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
//修改密码
|
|
|
|
* 修改密码
|
|
|
|
//@param oldPassword 旧密码
|
|
|
|
*/
|
|
|
|
//@param newPassword 新密码
|
|
|
|
@GetMapping(value = "/updatePassword")
|
|
|
|
//@param request HTTP请求对象
|
|
|
|
public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) {
|
|
|
|
// @return 操作结果
|
|
|
|
YonghuEntity yonghu = yonghuService.selectById((Integer)request.getSession().getAttribute("userId"));
|
|
|
|
|
|
|
|
if(newPassword == null){
|
|
|
|
@GetMapping(value = "/updatePassword")
|
|
|
|
return R.error("新密码不能为空") ;
|
|
|
|
public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) {
|
|
|
|
}
|
|
|
|
YonghuEntity yonghu = yonghuService.selectById((Integer)request.getSession().getAttribute("userId")); // 获取当前用户
|
|
|
|
if(!oldPassword.equals(yonghu.getPassword())){
|
|
|
|
if(newPassword == null){ // 检查新密码是否为空
|
|
|
|
return R.error("原密码输入错误");
|
|
|
|
return R.error("新密码不能为空") ; // 返回错误信息
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(newPassword.equals(yonghu.getPassword())){
|
|
|
|
if(!oldPassword.equals(yonghu.getPassword())){ // 检查旧密码是否正确
|
|
|
|
return R.error("新密码不能和原密码一致") ;
|
|
|
|
return R.error("原密码输入错误"); // 返回错误信息
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yonghu.setPassword(newPassword);
|
|
|
|
if(newPassword.equals(yonghu.getPassword())){ // 检查新旧密码是否相同
|
|
|
|
yonghuService.updateById(yonghu);
|
|
|
|
return R.error("新密码不能和原密码一致") ; // 返回错误信息
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yonghu.setPassword(newPassword); // 设置新密码
|
|
|
|
|
|
|
|
yonghuService.updateById(yonghu); // 更新用户
|
|
|
|
|
|
|
|
return R.ok(); // 返回成功结果
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 忘记密码
|
|
|
|
//忘记密码(重置为默认密码)
|
|
|
|
*/
|
|
|
|
//@param username 用户名
|
|
|
|
@IgnoreAuth
|
|
|
|
//@param request HTTP请求对象
|
|
|
|
|
|
|
|
//@return 操作结果
|
|
|
|
|
|
|
|
@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("账号不存在"); // 返回错误信息
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
//获取当前会话用户信息
|
|
|
|
* 获取用户的session用户信息
|
|
|
|
//@param request HTTP请求对象
|
|
|
|
*/
|
|
|
|
//@return 用户信息
|
|
|
|
@RequestMapping("/session")
|
|
|
|
@RequestMapping("/session")
|
|
|
|
public R getCurrYonghu(HttpServletRequest request){
|
|
|
|
public R getCurrYonghu(HttpServletRequest request){
|
|
|
|
Integer id = (Integer)request.getSession().getAttribute("userId");
|
|
|
|
Integer id = (Integer)request.getSession().getAttribute("userId"); // 获取当前用户ID
|
|
|
|
YonghuEntity yonghu = yonghuService.selectById(id);
|
|
|
|
YonghuEntity yonghu = yonghuService.selectById(id); // 查询用户信息
|
|
|
|
if(yonghu !=null){
|
|
|
|
if(yonghu !=null){ // 如果用户存在
|
|
|
|
//entity转view
|
|
|
|
YonghuView view = new YonghuView(); // 创建视图对象
|
|
|
|
YonghuView view = new YonghuView();
|
|
|
|
BeanUtils.copyProperties(yonghu, view); // 复制属性
|
|
|
|
BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中
|
|
|
|
dictionaryService.dictionaryConvert(view, request); // 转换字典字段
|
|
|
|
|
|
|
|
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);
|
|
|
|
// 字典表数据转换
|
|
|
|
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); // 返回分页结果
|
|
|
|
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);
|
|
|
|
YonghuEntity yonghu = yonghuService.selectById(id); // 根据ID查询用户
|
|
|
|
if(yonghu !=null){
|
|
|
|
if(yonghu !=null){ // 如果用户存在
|
|
|
|
|
|
|
|
YonghuView view = new YonghuView(); // 创建视图对象
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(yonghu, view); // 复制属性
|
|
|
|
//entity转view
|
|
|
|
dictionaryService.dictionaryConvert(view, request); // 转换字典字段
|
|
|
|
YonghuView view = new YonghuView();
|
|
|
|
return R.ok().put("data", view); // 返回用户信息
|
|
|
|
BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中
|
|
|
|
}else {
|
|
|
|
|
|
|
|
return R.error(511,"查不到数据"); // 返回错误信息
|
|
|
|
//修改对应字典表字段
|
|
|
|
}
|
|
|
|
dictionaryService.dictionaryConvert(view, request);
|
|
|
|
|
|
|
|
return R.ok().put("data", view);
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
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,"账户或者用户手机号或者用户身份证号已经被使用"); // 返回错误信息
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|