|
|
@ -1,174 +1,203 @@
|
|
|
|
// 声明当前 Java 文件所属的包,此包一般用于存放控制器相关的类,负责处理 HTTP 请求和响应
|
|
|
|
// 声明当前 Java 文件所属的包,此包用于存放控制器类,处理与教练相关的HTTP请求
|
|
|
|
package com.controller;
|
|
|
|
package com.controller;
|
|
|
|
|
|
|
|
|
|
|
|
// 导入 Java 标准库中的 File 类,用于操作文件和目录
|
|
|
|
// 导入Java IO包中的File类,用于文件操作
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
// 导入 Java 标准库中的 BigDecimal 类,用于进行高精度的十进制数运算
|
|
|
|
// 导入Java数学包中的BigDecimal类,用于高精度计算
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
// 导入 Java 标准库中的 URL 类,用于表示统一资源定位符,可用于处理网络资源
|
|
|
|
// 导入Java网络包中的URL类,用于处理统一资源定位符
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URL;
|
|
|
|
// 导入 Java 标准库中的 SimpleDateFormat 类,用于格式化和解析日期时间
|
|
|
|
// 导入Java文本包中的SimpleDateFormat类,用于日期格式化
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
// 导入阿里巴巴的 FastJSON 库中的 JSONObject 类,用于处理 JSON 对象,方便进行 JSON 数据的操作
|
|
|
|
// 导入FastJSON库中的JSONObject类,用于JSON数据处理
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
// 导入 Java 标准库中的 java.util 包下的所有类,该包包含了集合框架、日期和时间、随机数生成等常用工具类
|
|
|
|
// 导入Java工具包中的所有类,包括集合、日期等工具
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
// 导入 Spring 框架中的 BeanUtils 类,用于对象属性的复制,方便在不同对象之间传递数据
|
|
|
|
// 导入Spring框架的BeanUtils类,用于对象属性复制
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
// 导入 Java Servlet API 中的 HttpServletRequest 类,用于封装 HTTP 请求信息,在控制器中可获取请求参数等
|
|
|
|
// 导入Servlet的HttpServletRequest类,用于处理HTTP请求
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
// 导入 Spring 框架中的 ContextLoader 类,用于获取 Spring 的应用上下文
|
|
|
|
// 导入Spring框架的ContextLoader类,用于获取应用上下文
|
|
|
|
import org.springframework.web.context.ContextLoader;
|
|
|
|
import org.springframework.web.context.ContextLoader;
|
|
|
|
// 导入 Java Servlet API 中的 ServletContext 类,用于表示 Servlet 上下文,可获取应用的全局信息
|
|
|
|
// 导入Servlet的ServletContext类,表示Servlet上下文
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
// 导入自定义的 TokenService 类,该类可能用于处理令牌相关的业务逻辑
|
|
|
|
// 导入自定义的TokenService类,用于令牌管理
|
|
|
|
import com.service.TokenService;
|
|
|
|
import com.service.TokenService;
|
|
|
|
// 导入自定义的 utils 包下的所有类,这些类通常包含一些通用的工具方法
|
|
|
|
// 导入自定义工具类包中的所有工具类
|
|
|
|
import com.utils.*;
|
|
|
|
import com.utils.*;
|
|
|
|
// 导入 Java 反射机制中的 InvocationTargetException 类,当使用反射调用方法时,如果被调用的方法抛出异常,会被封装成该异常抛出
|
|
|
|
// 导入反射相关的InvocationTargetException类
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
|
|
|
|
|
|
|
// 导入自定义的 DictionaryService 类,该类可能用于处理字典数据的业务逻辑
|
|
|
|
// 导入自定义的DictionaryService类,用于字典数据管理
|
|
|
|
import com.service.DictionaryService;
|
|
|
|
import com.service.DictionaryService;
|
|
|
|
// 导入 Apache Commons Lang3 库中的 StringUtils 类,提供了许多方便的字符串操作方法
|
|
|
|
// 导入Apache Commons Lang3库的StringUtils类,用于字符串处理
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
// 导入自定义的 IgnoreAuth 注解,该注解可能用于标记不需要进行身份验证的接口
|
|
|
|
// 导入自定义的IgnoreAuth注解,用于标记不需要认证的接口
|
|
|
|
import com.annotation.IgnoreAuth;
|
|
|
|
import com.annotation.IgnoreAuth;
|
|
|
|
// 导入 SLF4J 日志框架中的 Logger 接口,用于记录日志信息
|
|
|
|
// 导入SLF4J日志框架的Logger接口
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
// 导入 SLF4J 日志框架中的 LoggerFactory 类,用于创建 Logger 实例
|
|
|
|
// 导入SLF4J日志框架的LoggerFactory类
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
// 导入 Spring 框架中的 Autowired 注解,用于自动注入依赖的 Bean
|
|
|
|
// 导入Spring框架的Autowired注解,用于依赖注入
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
// 导入 Spring 框架中的 Controller 注解,用于标记该类为控制器类,处理 HTTP 请求
|
|
|
|
// 导入Spring框架的Controller注解,标记该类为控制器
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
// 导入 Spring 框架中的 RestController 和 RequestMapping 等注解,用于构建 RESTful 风格的接口
|
|
|
|
// 导入Spring框架的RestController和RequestMapping等注解
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
// 导入 MyBatis-Plus 框架中的 EntityWrapper 类,用于构建实体对象的查询条件
|
|
|
|
// 导入MyBatis Plus的EntityWrapper类,用于构建查询条件
|
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
|
// 导入 MyBatis-Plus 框架中的 Wrapper 接口,EntityWrapper 实现了该接口,用于灵活构建查询条件
|
|
|
|
// 导入MyBatis Plus的Wrapper接口
|
|
|
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
|
|
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
|
|
|
// 导入自定义的 entity 包下的所有类,这些类通常是实体类,对应数据库表结构
|
|
|
|
// 导入自定义实体类包中的所有类
|
|
|
|
import com.entity.*;
|
|
|
|
import com.entity.*;
|
|
|
|
// 导入自定义的 view 包下的所有类,这些类可能是用于视图展示的实体类
|
|
|
|
// 导入自定义视图实体类包中的所有类
|
|
|
|
import com.entity.view.*;
|
|
|
|
import com.entity.view.*;
|
|
|
|
// 导入自定义的 service 包下的所有类,这些类通常包含业务逻辑处理方法
|
|
|
|
// 导入自定义服务类包中的所有类
|
|
|
|
import com.service.*;
|
|
|
|
import com.service.*;
|
|
|
|
// 导入自定义的 PageUtils 类,用于处理分页相关的逻辑
|
|
|
|
// 导入自定义分页工具类
|
|
|
|
import com.utils.PageUtils;
|
|
|
|
import com.utils.PageUtils;
|
|
|
|
// 导入自定义的 R 类,通常用于封装统一的响应结果
|
|
|
|
// 导入自定义统一返回结果类
|
|
|
|
import com.utils.R;
|
|
|
|
import com.utils.R;
|
|
|
|
// 导入阿里巴巴的 FastJSON 库中的所有类,进一步方便进行 JSON 数据的操作
|
|
|
|
// 导入FastJSON库中的所有类
|
|
|
|
import com.alibaba.fastjson.*;
|
|
|
|
import com.alibaba.fastjson.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
//教练
|
|
|
|
* 教练控制器
|
|
|
|
//后端接口
|
|
|
|
* 后端接口
|
|
|
|
//@author
|
|
|
|
*/
|
|
|
|
//@email
|
|
|
|
@RestController // 标记为RESTful控制器
|
|
|
|
@RestController
|
|
|
|
@Controller // 标记为Spring控制器
|
|
|
|
@Controller
|
|
|
|
@RequestMapping("/jiaolian") // 定义基础请求路径
|
|
|
|
@RequestMapping("/jiaolian")
|
|
|
|
|
|
|
|
public class JiaolianController {
|
|
|
|
public class JiaolianController {
|
|
|
|
|
|
|
|
// 创建日志记录器
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(JiaolianController.class);
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(JiaolianController.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义常量表名
|
|
|
|
private static final String TABLE_NAME = "jiaolian";
|
|
|
|
private static final String TABLE_NAME = "jiaolian";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 自动注入教练服务
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private JiaolianService jiaolianService;
|
|
|
|
private JiaolianService jiaolianService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 自动注入令牌服务
|
|
|
|
@Autowired
|
|
|
|
@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 JiaolianYuyueService jiaolianYuyueService;//教练预约申请
|
|
|
|
private JiaolianYuyueService jiaolianYuyueService;
|
|
|
|
|
|
|
|
// 自动注入健身资讯服务
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private NewsService newsService;//健身资讯
|
|
|
|
private NewsService newsService;
|
|
|
|
|
|
|
|
// 自动注入单页数据服务
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private SingleSeachService singleSeachService;//单页数据
|
|
|
|
private SingleSeachService singleSeachService;
|
|
|
|
|
|
|
|
// 自动注入用户服务
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private YonghuService yonghuService;//用户
|
|
|
|
private YonghuService yonghuService;
|
|
|
|
|
|
|
|
// 自动注入管理员服务
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private UsersService usersService;//管理员
|
|
|
|
private UsersService usersService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
//后端列表
|
|
|
|
* 后端列表查询
|
|
|
|
|
|
|
|
*/
|
|
|
|
@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("分页查询方法:,,控制器:{},,参数:{}",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"));
|
|
|
|
else if("教练".equals(role))
|
|
|
|
else if("教练".equals(role))
|
|
|
|
params.put("jiaolianId",request.getSession().getAttribute("userId"));
|
|
|
|
params.put("jiaolianId",request.getSession().getAttribute("userId"));
|
|
|
|
params.put("dataDeleteStart",1);params.put("dataDeleteEnd",1);
|
|
|
|
// 设置数据删除状态条件
|
|
|
|
|
|
|
|
params.put("dataDeleteStart",1);
|
|
|
|
|
|
|
|
params.put("dataDeleteEnd",1);
|
|
|
|
|
|
|
|
// 检查参数有效性
|
|
|
|
CommonUtil.checkMap(params);
|
|
|
|
CommonUtil.checkMap(params);
|
|
|
|
|
|
|
|
// 调用服务层查询分页数据
|
|
|
|
PageUtils page = jiaolianService.queryPage(params);
|
|
|
|
PageUtils page = jiaolianService.queryPage(params);
|
|
|
|
|
|
|
|
|
|
|
|
//字典表数据转换
|
|
|
|
// 字典数据转换
|
|
|
|
List<JiaolianView> list =(List<JiaolianView>)page.getList();
|
|
|
|
List<JiaolianView> list =(List<JiaolianView>)page.getList();
|
|
|
|
for(JiaolianView c:list){
|
|
|
|
for(JiaolianView c:list){
|
|
|
|
//修改对应字典表字段
|
|
|
|
// 转换字典表字段
|
|
|
|
dictionaryService.dictionaryConvert(c, request);
|
|
|
|
dictionaryService.dictionaryConvert(c, request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 返回分页数据
|
|
|
|
return R.ok().put("data", page);
|
|
|
|
return R.ok().put("data", page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
//后端详情
|
|
|
|
* 后端详情查询
|
|
|
|
|
|
|
|
*/
|
|
|
|
@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("详情查询方法:,,控制器:{},,ID:{}",this.getClass().getName(),id);
|
|
|
|
|
|
|
|
// 根据ID查询教练信息
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectById(id);
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectById(id);
|
|
|
|
if(jiaolian !=null){
|
|
|
|
if(jiaolian !=null){
|
|
|
|
//entity转view
|
|
|
|
// 实体转视图
|
|
|
|
JiaolianView view = new JiaolianView();
|
|
|
|
JiaolianView view = new JiaolianView();
|
|
|
|
BeanUtils.copyProperties( jiaolian , view );//把实体数据重构到view中
|
|
|
|
// 复制属性
|
|
|
|
//修改对应字典表字段
|
|
|
|
BeanUtils.copyProperties( jiaolian , view );
|
|
|
|
|
|
|
|
// 转换字典表字段
|
|
|
|
dictionaryService.dictionaryConvert(view, request);
|
|
|
|
dictionaryService.dictionaryConvert(view, request);
|
|
|
|
return R.ok().put("data", view);
|
|
|
|
return R.ok().put("data", view);
|
|
|
|
}else {
|
|
|
|
}else {
|
|
|
|
return R.error(511,"查不到数据");
|
|
|
|
return R.error(511,"查不到数据");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//后端保存
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 后端保存教练信息
|
|
|
|
|
|
|
|
*/
|
|
|
|
@RequestMapping("/save")
|
|
|
|
@RequestMapping("/save")
|
|
|
|
public R save(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request){
|
|
|
|
public R save(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request){
|
|
|
|
logger.debug("save方法:,,Controller:{},,jiaolian:{}",this.getClass().getName(),jiaolian.toString());
|
|
|
|
logger.debug("保存方法:,,控制器:{},,教练信息:{}",this.getClass().getName(),jiaolian.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前用户角色
|
|
|
|
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,"永远不会进入");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建查询条件,检查用户名和手机号是否已存在
|
|
|
|
Wrapper<JiaolianEntity> queryWrapper = new EntityWrapper<JiaolianEntity>()
|
|
|
|
Wrapper<JiaolianEntity> queryWrapper = new EntityWrapper<JiaolianEntity>()
|
|
|
|
.eq("username", jiaolian.getUsername())
|
|
|
|
.eq("username", jiaolian.getUsername())
|
|
|
|
.or()
|
|
|
|
.or()
|
|
|
|
.eq("jiaolian_phone", jiaolian.getJiaolianPhone())
|
|
|
|
.eq("jiaolian_phone", jiaolian.getJiaolianPhone())
|
|
|
|
.eq("data_delete", 1)
|
|
|
|
.eq("data_delete", 1)
|
|
|
|
;
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
|
|
|
logger.info("SQL语句:"+queryWrapper.getSqlSegment());
|
|
|
|
|
|
|
|
// 执行查询
|
|
|
|
JiaolianEntity jiaolianEntity = jiaolianService.selectOne(queryWrapper);
|
|
|
|
JiaolianEntity jiaolianEntity = jiaolianService.selectOne(queryWrapper);
|
|
|
|
if(jiaolianEntity==null){
|
|
|
|
if(jiaolianEntity==null){
|
|
|
|
jiaolian.setDataDelete(1);
|
|
|
|
// 设置默认值
|
|
|
|
jiaolian.setInsertTime(new Date());
|
|
|
|
jiaolian.setDataDelete(1); // 数据删除状态
|
|
|
|
jiaolian.setCreateTime(new Date());
|
|
|
|
jiaolian.setInsertTime(new Date()); // 插入时间
|
|
|
|
jiaolian.setPassword("123456");
|
|
|
|
jiaolian.setCreateTime(new Date()); // 创建时间
|
|
|
|
|
|
|
|
jiaolian.setPassword("123456"); // 默认密码
|
|
|
|
|
|
|
|
// 保存教练信息
|
|
|
|
jiaolianService.insert(jiaolian);
|
|
|
|
jiaolianService.insert(jiaolian);
|
|
|
|
return R.ok();
|
|
|
|
return R.ok();
|
|
|
|
}else {
|
|
|
|
}else {
|
|
|
@ -176,42 +205,47 @@ public class JiaolianController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
//后端修改
|
|
|
|
* 后端修改教练信息
|
|
|
|
|
|
|
|
*/
|
|
|
|
@RequestMapping("/update")
|
|
|
|
@RequestMapping("/update")
|
|
|
|
public R update(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
|
|
|
|
public R update(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
|
|
|
|
logger.debug("update方法:,,Controller:{},,jiaolian:{}",this.getClass().getName(),jiaolian.toString());
|
|
|
|
logger.debug("修改方法:,,控制器:{},,教练信息:{}",this.getClass().getName(),jiaolian.toString());
|
|
|
|
JiaolianEntity oldJiaolianEntity = jiaolianService.selectById(jiaolian.getId());//查询原先数据
|
|
|
|
// 查询原有数据
|
|
|
|
|
|
|
|
JiaolianEntity oldJiaolianEntity = jiaolianService.selectById(jiaolian.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(jiaolian.getJiaolianPhoto()) || "null".equals(jiaolian.getJiaolianPhoto())){
|
|
|
|
if("".equals(jiaolian.getJiaolianPhoto()) || "null".equals(jiaolian.getJiaolianPhoto())){
|
|
|
|
jiaolian.setJiaolianPhoto(null);
|
|
|
|
jiaolian.setJiaolianPhoto(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if("".equals(jiaolian.getJiaolianContent()) || "null".equals(jiaolian.getJiaolianContent())){
|
|
|
|
if("".equals(jiaolian.getJiaolianContent()) || "null".equals(jiaolian.getJiaolianContent())){
|
|
|
|
jiaolian.setJiaolianContent(null);
|
|
|
|
jiaolian.setJiaolianContent(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
jiaolianService.updateById(jiaolian);//根据id更新
|
|
|
|
// 更新数据
|
|
|
|
return R.ok();
|
|
|
|
jiaolianService.updateById(jiaolian);
|
|
|
|
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 删除教练信息(逻辑删除)
|
|
|
|
|
|
|
|
*/
|
|
|
|
//删除
|
|
|
|
|
|
|
|
@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("删除方法:,,控制器:{},,IDs:{}",this.getClass().getName(),ids.toString());
|
|
|
|
List<JiaolianEntity> oldJiaolianList =jiaolianService.selectBatchIds(Arrays.asList(ids));//要删除的数据
|
|
|
|
// 查询要删除的数据
|
|
|
|
|
|
|
|
List<JiaolianEntity> oldJiaolianList =jiaolianService.selectBatchIds(Arrays.asList(ids));
|
|
|
|
|
|
|
|
// 准备更新列表
|
|
|
|
ArrayList<JiaolianEntity> list = new ArrayList<>();
|
|
|
|
ArrayList<JiaolianEntity> list = new ArrayList<>();
|
|
|
|
for(Integer id:ids){
|
|
|
|
for(Integer id:ids){
|
|
|
|
JiaolianEntity jiaolianEntity = new JiaolianEntity();
|
|
|
|
JiaolianEntity jiaolianEntity = new JiaolianEntity();
|
|
|
|
jiaolianEntity.setId(id);
|
|
|
|
jiaolianEntity.setId(id);
|
|
|
|
jiaolianEntity.setDataDelete(2);
|
|
|
|
jiaolianEntity.setDataDelete(2); // 标记为删除
|
|
|
|
list.add(jiaolianEntity);
|
|
|
|
list.add(jiaolianEntity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 批量更新删除状态
|
|
|
|
if(list != null && list.size() >0){
|
|
|
|
if(list != null && list.size() >0){
|
|
|
|
jiaolianService.updateBatchById(list);
|
|
|
|
jiaolianService.updateBatchById(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -219,19 +253,24 @@ public class JiaolianController {
|
|
|
|
return R.ok();
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 批量导入教练数据
|
|
|
|
//批量上传
|
|
|
|
*/
|
|
|
|
@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("批量导入方法:,,控制器:{},,文件名:{}",this.getClass().getName(),fileName);
|
|
|
|
|
|
|
|
// 获取当前用户ID
|
|
|
|
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
|
|
|
|
Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));
|
|
|
|
|
|
|
|
// 创建日期格式化对象
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
//.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
List<JiaolianEntity> jiaolianList = new ArrayList<>();//上传的东西
|
|
|
|
// 准备导入的数据列表
|
|
|
|
Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
|
|
|
|
List<JiaolianEntity> jiaolianList = new ArrayList<>();
|
|
|
|
|
|
|
|
// 需要检查重复的字段映射
|
|
|
|
|
|
|
|
Map<String, List<String>> seachFields= new HashMap<>();
|
|
|
|
|
|
|
|
// 当前日期
|
|
|
|
Date date = new Date();
|
|
|
|
Date date = new Date();
|
|
|
|
|
|
|
|
// 检查文件后缀
|
|
|
|
int lastIndexOf = fileName.lastIndexOf(".");
|
|
|
|
int lastIndexOf = fileName.lastIndexOf(".");
|
|
|
|
if(lastIndexOf == -1){
|
|
|
|
if(lastIndexOf == -1){
|
|
|
|
return R.error(511,"该文件没有后缀");
|
|
|
|
return R.error(511,"该文件没有后缀");
|
|
|
@ -240,53 +279,54 @@ public class JiaolianController {
|
|
|
|
if(!".xls".equals(suffix)){
|
|
|
|
if(!".xls".equals(suffix)){
|
|
|
|
return R.error(511,"只支持后缀为xls的excel文件");
|
|
|
|
return R.error(511,"只支持后缀为xls的excel文件");
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
|
|
|
|
// 获取文件路径
|
|
|
|
|
|
|
|
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);
|
|
|
|
File file = new File(resource.getFile());
|
|
|
|
File file = new File(resource.getFile());
|
|
|
|
if(!file.exists()){
|
|
|
|
if(!file.exists()){
|
|
|
|
return R.error(511,"找不到上传文件,请联系管理员");
|
|
|
|
return R.error(511,"找不到上传文件,请联系管理员");
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
|
|
|
|
// 读取Excel文件
|
|
|
|
dataList.remove(0);//删除第一行,因为第一行是提示
|
|
|
|
List<List<String>> dataList = PoiUtil.poiImport(file.getPath());
|
|
|
|
|
|
|
|
dataList.remove(0);// 删除标题行
|
|
|
|
for(List<String> data:dataList){
|
|
|
|
for(List<String> data:dataList){
|
|
|
|
//循环
|
|
|
|
// 创建教练实体
|
|
|
|
JiaolianEntity jiaolianEntity = new JiaolianEntity();
|
|
|
|
JiaolianEntity jiaolianEntity = new JiaolianEntity();
|
|
|
|
// jiaolianEntity.setUsername(data.get(0)); //账户 要改的
|
|
|
|
// 设置各字段值(示例代码,实际应根据Excel列设置)
|
|
|
|
// jiaolianEntity.setPassword("123456");//密码
|
|
|
|
// jiaolianEntity.setUsername(data.get(0)); // 账户
|
|
|
|
// jiaolianEntity.setJiaolianName(data.get(0)); //教练名称 要改的
|
|
|
|
// jiaolianEntity.setPassword("123456"); // 密码
|
|
|
|
// jiaolianEntity.setJiaolianPhone(data.get(0)); //教练手机号 要改的
|
|
|
|
// jiaolianEntity.setJiaolianName(data.get(0)); // 教练名称
|
|
|
|
// jiaolianEntity.setJiaolianPhoto("");//详情和图片
|
|
|
|
// jiaolianEntity.setJiaolianPhone(data.get(0)); // 教练手机号
|
|
|
|
// jiaolianEntity.setSexTypes(Integer.valueOf(data.get(0))); //性别 要改的
|
|
|
|
// jiaolianEntity.setJiaolianPhoto(""); // 照片
|
|
|
|
// jiaolianEntity.setJiaolianEmail(data.get(0)); //教练邮箱 要改的
|
|
|
|
// jiaolianEntity.setSexTypes(Integer.valueOf(data.get(0))); // 性别
|
|
|
|
// jiaolianEntity.setJiaolianContent("");//详情和图片
|
|
|
|
// jiaolianEntity.setJiaolianEmail(data.get(0)); // 邮箱
|
|
|
|
// jiaolianEntity.setDataDelete(1);//逻辑删除字段
|
|
|
|
// jiaolianEntity.setJiaolianContent(""); // 内容
|
|
|
|
// jiaolianEntity.setInsertTime(date);//时间
|
|
|
|
// jiaolianEntity.setDataDelete(1); // 删除状态
|
|
|
|
// jiaolianEntity.setCreateTime(date);//时间
|
|
|
|
// jiaolianEntity.setInsertTime(date); // 插入时间
|
|
|
|
|
|
|
|
// jiaolianEntity.setCreateTime(date); // 创建时间
|
|
|
|
jiaolianList.add(jiaolianEntity);
|
|
|
|
jiaolianList.add(jiaolianEntity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 收集需要检查重复的字段
|
|
|
|
//把要查询是否重复的字段放入map中
|
|
|
|
// 账户字段检查
|
|
|
|
//账户
|
|
|
|
if(seachFields.containsKey("username")){
|
|
|
|
if(seachFields.containsKey("username")){
|
|
|
|
List<String> username = seachFields.get("username");
|
|
|
|
List<String> username = seachFields.get("username");
|
|
|
|
username.add(data.get(0));
|
|
|
|
username.add(data.get(0));//要改的
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
List<String> username = new ArrayList<>();
|
|
|
|
List<String> username = new ArrayList<>();
|
|
|
|
username.add(data.get(0));
|
|
|
|
username.add(data.get(0));//要改的
|
|
|
|
seachFields.put("username",username);
|
|
|
|
seachFields.put("username",username);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 手机号字段检查
|
|
|
|
//教练手机号
|
|
|
|
if(seachFields.containsKey("jiaolianPhone")){
|
|
|
|
if(seachFields.containsKey("jiaolianPhone")){
|
|
|
|
List<String> jiaolianPhone = seachFields.get("jiaolianPhone");
|
|
|
|
List<String> jiaolianPhone = seachFields.get("jiaolianPhone");
|
|
|
|
jiaolianPhone.add(data.get(0));
|
|
|
|
jiaolianPhone.add(data.get(0));//要改的
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
List<String> jiaolianPhone = new ArrayList<>();
|
|
|
|
List<String> jiaolianPhone = new ArrayList<>();
|
|
|
|
jiaolianPhone.add(data.get(0));
|
|
|
|
jiaolianPhone.add(data.get(0));//要改的
|
|
|
|
seachFields.put("jiaolianPhone",jiaolianPhone);
|
|
|
|
seachFields.put("jiaolianPhone",jiaolianPhone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//查询是否重复
|
|
|
|
// 检查账户是否重复
|
|
|
|
//账户
|
|
|
|
|
|
|
|
List<JiaolianEntity> jiaolianEntities_username = jiaolianService.selectList(new EntityWrapper<JiaolianEntity>().in("username", seachFields.get("username")).eq("data_delete", 1));
|
|
|
|
List<JiaolianEntity> jiaolianEntities_username = jiaolianService.selectList(new EntityWrapper<JiaolianEntity>().in("username", seachFields.get("username")).eq("data_delete", 1));
|
|
|
|
if(jiaolianEntities_username.size() >0 ){
|
|
|
|
if(jiaolianEntities_username.size() >0 ){
|
|
|
|
ArrayList<String> repeatFields = new ArrayList<>();
|
|
|
|
ArrayList<String> repeatFields = new ArrayList<>();
|
|
|
@ -295,7 +335,7 @@ public class JiaolianController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString());
|
|
|
|
return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//教练手机号
|
|
|
|
// 检查手机号是否重复
|
|
|
|
List<JiaolianEntity> jiaolianEntities_jiaolianPhone = jiaolianService.selectList(new EntityWrapper<JiaolianEntity>().in("jiaolian_phone", seachFields.get("jiaolianPhone")).eq("data_delete", 1));
|
|
|
|
List<JiaolianEntity> jiaolianEntities_jiaolianPhone = jiaolianService.selectList(new EntityWrapper<JiaolianEntity>().in("jiaolian_phone", seachFields.get("jiaolianPhone")).eq("data_delete", 1));
|
|
|
|
if(jiaolianEntities_jiaolianPhone.size() >0 ){
|
|
|
|
if(jiaolianEntities_jiaolianPhone.size() >0 ){
|
|
|
|
ArrayList<String> repeatFields = new ArrayList<>();
|
|
|
|
ArrayList<String> repeatFields = new ArrayList<>();
|
|
|
@ -304,6 +344,7 @@ public class JiaolianController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return R.error(511,"数据库的该表中的 [教练手机号] 字段已经存在 存在数据为:"+repeatFields.toString());
|
|
|
|
return R.error(511,"数据库的该表中的 [教练手机号] 字段已经存在 存在数据为:"+repeatFields.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 批量插入数据
|
|
|
|
jiaolianService.insertBatch(jiaolianList);
|
|
|
|
jiaolianService.insertBatch(jiaolianList);
|
|
|
|
return R.ok();
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -315,17 +356,23 @@ public class JiaolianController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
//登录
|
|
|
|
* 教练登录
|
|
|
|
@IgnoreAuth
|
|
|
|
*/
|
|
|
|
|
|
|
|
@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) {
|
|
|
|
|
|
|
|
// 根据用户名查询教练
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectOne(new EntityWrapper<JiaolianEntity>().eq("username", username));
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectOne(new EntityWrapper<JiaolianEntity>().eq("username", username));
|
|
|
|
|
|
|
|
// 验证账号密码
|
|
|
|
if(jiaolian==null || !jiaolian.getPassword().equals(password))
|
|
|
|
if(jiaolian==null || !jiaolian.getPassword().equals(password))
|
|
|
|
return R.error("账号或密码不正确");
|
|
|
|
return R.error("账号或密码不正确");
|
|
|
|
|
|
|
|
// 检查账号状态
|
|
|
|
else if(jiaolian.getDataDelete() != 1)
|
|
|
|
else if(jiaolian.getDataDelete() != 1)
|
|
|
|
return R.error("账户已被删除");
|
|
|
|
return R.error("账户已被删除");
|
|
|
|
|
|
|
|
// 生成令牌
|
|
|
|
String token = tokenService.generateToken(jiaolian.getId(),username, "jiaolian", "教练");
|
|
|
|
String token = tokenService.generateToken(jiaolian.getId(),username, "jiaolian", "教练");
|
|
|
|
|
|
|
|
// 构建返回结果
|
|
|
|
R r = R.ok();
|
|
|
|
R r = R.ok();
|
|
|
|
r.put("token", token);
|
|
|
|
r.put("token", token);
|
|
|
|
r.put("role","教练");
|
|
|
|
r.put("role","教练");
|
|
|
@ -335,87 +382,107 @@ public class JiaolianController {
|
|
|
|
return r;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//注册
|
|
|
|
/**
|
|
|
|
@IgnoreAuth
|
|
|
|
* 教练注册
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@IgnoreAuth // 忽略认证
|
|
|
|
@PostMapping(value = "/register")
|
|
|
|
@PostMapping(value = "/register")
|
|
|
|
public R register(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request) {
|
|
|
|
public R register(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request) {
|
|
|
|
// ValidatorUtils.validateEntity(user);
|
|
|
|
// 构建查询条件,检查用户名和手机号是否已存在
|
|
|
|
Wrapper<JiaolianEntity> queryWrapper = new EntityWrapper<JiaolianEntity>()
|
|
|
|
Wrapper<JiaolianEntity> queryWrapper = new EntityWrapper<JiaolianEntity>()
|
|
|
|
.eq("username", jiaolian.getUsername())
|
|
|
|
.eq("username", jiaolian.getUsername())
|
|
|
|
.or()
|
|
|
|
.or()
|
|
|
|
.eq("jiaolian_phone", jiaolian.getJiaolianPhone())
|
|
|
|
.eq("jiaolian_phone", jiaolian.getJiaolianPhone())
|
|
|
|
.andNew()
|
|
|
|
.andNew()
|
|
|
|
.eq("data_delete", 1)
|
|
|
|
.eq("data_delete", 1)
|
|
|
|
;
|
|
|
|
;
|
|
|
|
|
|
|
|
// 执行查询
|
|
|
|
JiaolianEntity jiaolianEntity = jiaolianService.selectOne(queryWrapper);
|
|
|
|
JiaolianEntity jiaolianEntity = jiaolianService.selectOne(queryWrapper);
|
|
|
|
if(jiaolianEntity != null)
|
|
|
|
if(jiaolianEntity != null)
|
|
|
|
return R.error("账户或者教练手机号已经被使用");
|
|
|
|
return R.error("账户或者教练手机号已经被使用");
|
|
|
|
jiaolian.setDataDelete(1);
|
|
|
|
// 设置默认值
|
|
|
|
jiaolian.setInsertTime(new Date());
|
|
|
|
jiaolian.setDataDelete(1); // 数据状态
|
|
|
|
jiaolian.setCreateTime(new Date());
|
|
|
|
jiaolian.setInsertTime(new Date()); // 插入时间
|
|
|
|
|
|
|
|
jiaolian.setCreateTime(new Date()); // 创建时间
|
|
|
|
|
|
|
|
// 保存教练信息
|
|
|
|
jiaolianService.insert(jiaolian);
|
|
|
|
jiaolianService.insert(jiaolian);
|
|
|
|
|
|
|
|
|
|
|
|
return R.ok();
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
//重置密码
|
|
|
|
* 重置密码
|
|
|
|
|
|
|
|
*/
|
|
|
|
@GetMapping(value = "/resetPassword")
|
|
|
|
@GetMapping(value = "/resetPassword")
|
|
|
|
public R resetPassword(Integer id, HttpServletRequest request) {
|
|
|
|
public R resetPassword(Integer id, HttpServletRequest request) {
|
|
|
|
|
|
|
|
// 根据ID查询教练
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectById(id);
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectById(id);
|
|
|
|
|
|
|
|
// 重置密码为默认值
|
|
|
|
jiaolian.setPassword("123456");
|
|
|
|
jiaolian.setPassword("123456");
|
|
|
|
|
|
|
|
// 更新密码
|
|
|
|
jiaolianService.updateById(jiaolian);
|
|
|
|
jiaolianService.updateById(jiaolian);
|
|
|
|
return R.ok();
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
//修改密码
|
|
|
|
* 修改密码
|
|
|
|
@GetMapping(value = "/updatePassword")
|
|
|
|
*/
|
|
|
|
public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) {
|
|
|
|
@GetMapping(value = "/updatePassword")
|
|
|
|
|
|
|
|
public R updatePassword(String oldPassword, String newPassword, HttpServletRequest request) {
|
|
|
|
|
|
|
|
// 获取当前登录教练
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectById((Integer)request.getSession().getAttribute("userId"));
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectById((Integer)request.getSession().getAttribute("userId"));
|
|
|
|
if(newPassword == null){
|
|
|
|
// 验证新密码
|
|
|
|
return R.error("新密码不能为空") ;
|
|
|
|
if(newPassword == null){
|
|
|
|
}
|
|
|
|
return R.error("新密码不能为空") ;
|
|
|
|
if(!oldPassword.equals(jiaolian.getPassword())){
|
|
|
|
}
|
|
|
|
return R.error("原密码输入错误");
|
|
|
|
// 验证旧密码
|
|
|
|
}
|
|
|
|
if(!oldPassword.equals(jiaolian.getPassword())){
|
|
|
|
if(newPassword.equals(jiaolian.getPassword())){
|
|
|
|
return R.error("原密码输入错误");
|
|
|
|
return R.error("新密码不能和原密码一致") ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 检查新旧密码是否相同
|
|
|
|
|
|
|
|
if(newPassword.equals(jiaolian.getPassword())){
|
|
|
|
|
|
|
|
return R.error("新密码不能和原密码一致") ;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 更新密码
|
|
|
|
jiaolian.setPassword(newPassword);
|
|
|
|
jiaolian.setPassword(newPassword);
|
|
|
|
jiaolianService.updateById(jiaolian);
|
|
|
|
jiaolianService.updateById(jiaolian);
|
|
|
|
return R.ok();
|
|
|
|
return R.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//忘记密码
|
|
|
|
/**
|
|
|
|
@IgnoreAuth
|
|
|
|
* 忘记密码(重置密码)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@IgnoreAuth // 忽略认证
|
|
|
|
@RequestMapping(value = "/resetPass")
|
|
|
|
@RequestMapping(value = "/resetPass")
|
|
|
|
public R resetPass(String username, HttpServletRequest request) {
|
|
|
|
public R resetPass(String username, HttpServletRequest request) {
|
|
|
|
|
|
|
|
// 根据用户名查询教练
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectOne(new EntityWrapper<JiaolianEntity>().eq("username", username));
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectOne(new EntityWrapper<JiaolianEntity>().eq("username", username));
|
|
|
|
if(jiaolian!=null){
|
|
|
|
if(jiaolian!=null){
|
|
|
|
|
|
|
|
// 重置密码为默认值
|
|
|
|
jiaolian.setPassword("123456");
|
|
|
|
jiaolian.setPassword("123456");
|
|
|
|
|
|
|
|
// 更新密码
|
|
|
|
jiaolianService.updateById(jiaolian);
|
|
|
|
jiaolianService.updateById(jiaolian);
|
|
|
|
return R.ok();
|
|
|
|
return R.ok();
|
|
|
|
}else{
|
|
|
|
}else {
|
|
|
|
return R.error("账号不存在");
|
|
|
|
return R.error("账号不存在");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
//获取用户的session用户信息
|
|
|
|
* 获取当前登录教练的会话信息
|
|
|
|
|
|
|
|
*/
|
|
|
|
@RequestMapping("/session")
|
|
|
|
@RequestMapping("/session")
|
|
|
|
public R getCurrJiaolian(HttpServletRequest request){
|
|
|
|
public R getCurrJiaolian(HttpServletRequest request){
|
|
|
|
|
|
|
|
// 从会话中获取用户ID
|
|
|
|
Integer id = (Integer)request.getSession().getAttribute("userId");
|
|
|
|
Integer id = (Integer)request.getSession().getAttribute("userId");
|
|
|
|
|
|
|
|
// 查询教练信息
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectById(id);
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectById(id);
|
|
|
|
if(jiaolian !=null){
|
|
|
|
if(jiaolian !=null){
|
|
|
|
//entity转view
|
|
|
|
// 实体转视图
|
|
|
|
JiaolianView view = new JiaolianView();
|
|
|
|
JiaolianView view = new JiaolianView();
|
|
|
|
BeanUtils.copyProperties( jiaolian , view );//把实体数据重构到view中
|
|
|
|
// 复制属性
|
|
|
|
|
|
|
|
BeanUtils.copyProperties( jiaolian , view );
|
|
|
|
//修改对应字典表字段
|
|
|
|
// 转换字典字段
|
|
|
|
dictionaryService.dictionaryConvert(view, request);
|
|
|
|
dictionaryService.dictionaryConvert(view, request);
|
|
|
|
return R.ok().put("data", view);
|
|
|
|
return R.ok().put("data", view);
|
|
|
|
}else {
|
|
|
|
}else {
|
|
|
@ -423,84 +490,86 @@ public class JiaolianController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 退出登录
|
|
|
|
//退出
|
|
|
|
*/
|
|
|
|
@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("退出成功");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 前端列表查询
|
|
|
|
|
|
|
|
*/
|
|
|
|
//前端列表
|
|
|
|
@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("前端列表查询方法:,,控制器:{},,参数:{}",this.getClass().getName(),JSONObject.toJSONString(params));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查参数有效性
|
|
|
|
CommonUtil.checkMap(params);
|
|
|
|
CommonUtil.checkMap(params);
|
|
|
|
|
|
|
|
// 查询分页数据
|
|
|
|
PageUtils page = jiaolianService.queryPage(params);
|
|
|
|
PageUtils page = jiaolianService.queryPage(params);
|
|
|
|
|
|
|
|
|
|
|
|
//字典表数据转换
|
|
|
|
// 字典数据转换
|
|
|
|
List<JiaolianView> list =(List<JiaolianView>)page.getList();
|
|
|
|
List<JiaolianView> list =(List<JiaolianView>)page.getList();
|
|
|
|
for(JiaolianView c:list)
|
|
|
|
for(JiaolianView c:list)
|
|
|
|
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
|
|
|
|
dictionaryService.dictionaryConvert(c, request); // 转换字典字段
|
|
|
|
|
|
|
|
|
|
|
|
return R.ok().put("data", page);
|
|
|
|
return R.ok().put("data", page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
//前端详情
|
|
|
|
* 前端详情查询
|
|
|
|
|
|
|
|
*/
|
|
|
|
@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("前端详情查询方法:,,控制器:{},,ID:{}",this.getClass().getName(),id);
|
|
|
|
|
|
|
|
// 根据ID查询教练
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectById(id);
|
|
|
|
JiaolianEntity jiaolian = jiaolianService.selectById(id);
|
|
|
|
if(jiaolian !=null){
|
|
|
|
if(jiaolian !=null){
|
|
|
|
|
|
|
|
// 实体转视图
|
|
|
|
|
|
|
|
JiaolianView view = new JiaolianView();
|
|
|
|
//entity转view
|
|
|
|
// 复制属性
|
|
|
|
JiaolianView view = new JiaolianView();
|
|
|
|
BeanUtils.copyProperties( jiaolian , view );
|
|
|
|
BeanUtils.copyProperties( jiaolian , view );//把实体数据重构到view中
|
|
|
|
// 转换字典字段
|
|
|
|
|
|
|
|
dictionaryService.dictionaryConvert(view, request);
|
|
|
|
//修改对应字典表字段
|
|
|
|
return R.ok().put("data", view);
|
|
|
|
dictionaryService.dictionaryConvert(view, request);
|
|
|
|
}else {
|
|
|
|
return R.ok().put("data", view);
|
|
|
|
return R.error(511,"查不到数据");
|
|
|
|
}else {
|
|
|
|
}
|
|
|
|
return R.error(511,"查不到数据");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 前端保存教练信息
|
|
|
|
//前端保存
|
|
|
|
*/
|
|
|
|
@RequestMapping("/add")
|
|
|
|
@RequestMapping("/add")
|
|
|
|
public R add(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request){
|
|
|
|
public R add(@RequestBody JiaolianEntity jiaolian, HttpServletRequest request){
|
|
|
|
logger.debug("add方法:,,Controller:{},,jiaolian:{}",this.getClass().getName(),jiaolian.toString());
|
|
|
|
logger.debug("前端保存方法:,,控制器:{},,教练信息:{}",this.getClass().getName(),jiaolian.toString());
|
|
|
|
|
|
|
|
// 构建查询条件,检查用户名和手机号是否已存在
|
|
|
|
Wrapper<JiaolianEntity> queryWrapper = new EntityWrapper<JiaolianEntity>()
|
|
|
|
Wrapper<JiaolianEntity> queryWrapper = new EntityWrapper<JiaolianEntity>()
|
|
|
|
.eq("username", jiaolian.getUsername())
|
|
|
|
.eq("username", jiaolian.getUsername())
|
|
|
|
.or()
|
|
|
|
.or()
|
|
|
|
.eq("jiaolian_phone", jiaolian.getJiaolianPhone())
|
|
|
|
.eq("jiaolian_phone", jiaolian.getJiaolianPhone())
|
|
|
|
.andNew()
|
|
|
|
.andNew()
|
|
|
|
.eq("data_delete", 1)
|
|
|
|
.eq("data_delete", 1)
|
|
|
|
// .notIn("jiaolian_types", new Integer[]{102})
|
|
|
|
;
|
|
|
|
;
|
|
|
|
logger.info("SQL语句:"+queryWrapper.getSqlSegment());
|
|
|
|
logger.info("sql语句:"+queryWrapper.getSqlSegment());
|
|
|
|
// 执行查询
|
|
|
|
JiaolianEntity jiaolianEntity = jiaolianService.selectOne(queryWrapper);
|
|
|
|
JiaolianEntity jiaolianEntity = jiaolianService.selectOne(queryWrapper);
|
|
|
|
if(jiaolianEntity==null){
|
|
|
|
if(jiaolianEntity==null){
|
|
|
|
jiaolian.setDataDelete(1);
|
|
|
|
// 设置默认值
|
|
|
|
jiaolian.setInsertTime(new Date());
|
|
|
|
jiaolian.setDataDelete(1); // 数据状态
|
|
|
|
jiaolian.setCreateTime(new Date());
|
|
|
|
jiaolian.setInsertTime(new Date()); // 插入时间
|
|
|
|
jiaolian.setPassword("123456");
|
|
|
|
jiaolian.setCreateTime(new Date()); // 创建时间
|
|
|
|
jiaolianService.insert(jiaolian);
|
|
|
|
jiaolian.setPassword("123456"); // 默认密码
|
|
|
|
|
|
|
|
// 保存教练信息
|
|
|
|
|
|
|
|
jiaolianService.insert(jiaolian);
|
|
|
|
return R.ok();
|
|
|
|
return R.ok();
|
|
|
|
}else {
|
|
|
|
}else {
|
|
|
|
return R.error(511,"账户或者教练手机号已经被使用");
|
|
|
|
return R.error(511,"账户或者教练手机号已经被使用");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|