|
|
|
@ -0,0 +1,285 @@
|
|
|
|
|
package com.controller; // 声明包路径,表示该文件位于com.controller包下
|
|
|
|
|
|
|
|
|
|
import java.io.File; // 导入文件操作类,用于处理文件上传
|
|
|
|
|
import java.math.BigDecimal; // 导入高精度数学计算类,用于处理金额计算
|
|
|
|
|
import java.net.URL; // 导入网络URL处理类,用于获取资源路径
|
|
|
|
|
import java.text.SimpleDateFormat; // 导入日期格式化类,用于日期格式转换
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; // 导入FastJSON的JSON对象类,用于JSON处理
|
|
|
|
|
import java.util.*; // 导入Java常用工具类(集合、日期等)
|
|
|
|
|
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控制器,用于处理HTTP请求
|
|
|
|
|
@Controller // 标识为Spring控制器
|
|
|
|
|
@RequestMapping("/jianshenkechengLiuyan") // 定义请求映射路径
|
|
|
|
|
public class JianshenkechengLiuyanController {
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(JianshenkechengLiuyanController.class); // 日志记录器,用于记录日志信息
|
|
|
|
|
|
|
|
|
|
private static final String TABLE_NAME = "jianshenkechengLiuyan"; // 数据库表名常量
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 自动注入课程留言服务
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TokenService tokenService; // 自动注入Token服务
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DictionaryService dictionaryService; // 自动注入字典服务
|
|
|
|
|
@Autowired
|
|
|
|
|
private ForumService forumService; // 自动注入健身论坛服务
|
|
|
|
|
@Autowired
|
|
|
|
|
private JianshenkechengService jianshenkechengService; // 自动注入健身课程服务
|
|
|
|
|
@Autowired
|
|
|
|
|
private JianshenkechengCollectionService jianshenkechengCollectionService; // 自动注入课程收藏服务
|
|
|
|
|
@Autowired
|
|
|
|
|
private JiaolianService jiaolianService; // 自动注入教练服务
|
|
|
|
|
@Autowired
|
|
|
|
|
private JiaolianYuyueService jiaolianYuyueService; // 自动注入教练预约申请服务
|
|
|
|
|
@Autowired
|
|
|
|
|
private NewsService newsService; // 自动注入健身资讯服务
|
|
|
|
|
@Autowired
|
|
|
|
|
private SingleSeachService singleSeachService; // 自动注入单页数据服务
|
|
|
|
|
@Autowired
|
|
|
|
|
private YonghuService yonghuService; // 自动注入用户服务
|
|
|
|
|
@Autowired
|
|
|
|
|
private UsersService usersService; // 自动注入管理员服务
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//后端列表
|
|
|
|
|
//处理分页查询请求
|
|
|
|
|
@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")); // 从session中获取用户角色
|
|
|
|
|
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 = jianshenkechengLiuyanService.queryPage(params); // 调用服务层查询分页数据
|
|
|
|
|
|
|
|
|
|
// 字典表数据转换
|
|
|
|
|
List<JianshenkechengLiuyanView> list =(List<JianshenkechengLiuyanView>)page.getList(); // 获取分页数据列表
|
|
|
|
|
for(JianshenkechengLiuyanView c:list){ // 遍历列表
|
|
|
|
|
dictionaryService.dictionaryConvert(c, request); // 转换字典字段
|
|
|
|
|
}
|
|
|
|
|
return R.ok().put("data", page); // 返回分页数据
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//后端详情
|
|
|
|
|
//根据ID查询单条留言详情
|
|
|
|
|
@RequestMapping("/info/{id}") // 映射详情查询请求
|
|
|
|
|
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
|
|
|
|
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录请求日志
|
|
|
|
|
JianshenkechengLiuyanEntity jianshenkechengLiuyan = jianshenkechengLiuyanService.selectById(id); // 根据ID查询留言
|
|
|
|
|
if(jianshenkechengLiuyan !=null){ // 如果查询到数据
|
|
|
|
|
JianshenkechengLiuyanView view = new JianshenkechengLiuyanView(); // 创建视图对象
|
|
|
|
|
BeanUtils.copyProperties(jianshenkechengLiuyan, view); // 复制属性到视图对象
|
|
|
|
|
|
|
|
|
|
// 查询关联的健身课程信息
|
|
|
|
|
JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(jianshenkechengLiuyan.getJianshenkechengId());
|
|
|
|
|
if(jianshenkecheng != null){
|
|
|
|
|
BeanUtils.copyProperties(jianshenkecheng, view, new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});
|
|
|
|
|
view.setJianshenkechengId(jianshenkecheng.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询关联的用户信息
|
|
|
|
|
YonghuEntity yonghu = yonghuService.selectById(jianshenkechengLiuyan.getYonghuId());
|
|
|
|
|
if(yonghu != null){
|
|
|
|
|
BeanUtils.copyProperties(yonghu, view, new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});
|
|
|
|
|
view.setYonghuId(yonghu.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dictionaryService.dictionaryConvert(view, request); // 转换字典字段
|
|
|
|
|
return R.ok().put("data", view); // 返回详情数据
|
|
|
|
|
}else {
|
|
|
|
|
return R.error(511,"查不到数据"); // 返回错误信息
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//后端保存
|
|
|
|
|
//处理新增留言请求
|
|
|
|
|
@RequestMapping("/save") // 映射保存请求
|
|
|
|
|
public R save(@RequestBody JianshenkechengLiuyanEntity jianshenkechengLiuyan, HttpServletRequest request){
|
|
|
|
|
logger.debug("save方法:,,Controller:{},,jianshenkechengLiuyan:{}",this.getClass().getName(),jianshenkechengLiuyan.toString()); // 记录请求日志
|
|
|
|
|
|
|
|
|
|
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
|
|
|
|
if(false) // 永远不会执行的代码块
|
|
|
|
|
return R.error(511,"永远不会进入"); // 返回错误信息
|
|
|
|
|
else if("用户".equals(role)) // 如果是用户角色
|
|
|
|
|
jianshenkechengLiuyan.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); // 设置用户ID
|
|
|
|
|
|
|
|
|
|
jianshenkechengLiuyan.setCreateTime(new Date()); // 设置创建时间
|
|
|
|
|
jianshenkechengLiuyan.setInsertTime(new Date()); // 设置插入时间
|
|
|
|
|
jianshenkechengLiuyanService.insert(jianshenkechengLiuyan); // 调用服务层保存数据
|
|
|
|
|
|
|
|
|
|
return R.ok(); // 返回成功信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//后端修改
|
|
|
|
|
//处理更新留言请
|
|
|
|
|
@RequestMapping("/update") // 映射更新请求
|
|
|
|
|
public R update(@RequestBody JianshenkechengLiuyanEntity jianshenkechengLiuyan, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
|
|
|
|
|
logger.debug("update方法:,,Controller:{},,jianshenkechengLiuyan:{}",this.getClass().getName(),jianshenkechengLiuyan.toString()); // 记录请求日志
|
|
|
|
|
JianshenkechengLiuyanEntity oldJianshenkechengLiuyanEntity = jianshenkechengLiuyanService.selectById(jianshenkechengLiuyan.getId()); // 查询原有数据
|
|
|
|
|
|
|
|
|
|
// 处理空值情况
|
|
|
|
|
if("".equals(jianshenkechengLiuyan.getJianshenkechengLiuyanText()) || "null".equals(jianshenkechengLiuyan.getJianshenkechengLiuyanText())){
|
|
|
|
|
jianshenkechengLiuyan.setJianshenkechengLiuyanText(null);
|
|
|
|
|
}
|
|
|
|
|
if("".equals(jianshenkechengLiuyan.getReplyText()) || "null".equals(jianshenkechengLiuyan.getReplyText())){
|
|
|
|
|
jianshenkechengLiuyan.setReplyText(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jianshenkechengLiuyan.setUpdateTime(new Date()); // 设置更新时间
|
|
|
|
|
jianshenkechengLiuyanService.updateById(jianshenkechengLiuyan); // 调用服务层更新数据
|
|
|
|
|
return R.ok(); // 返回成功信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//删除
|
|
|
|
|
//处理删除留言请求
|
|
|
|
|
@RequestMapping("/delete") // 映射删除请求
|
|
|
|
|
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
|
|
|
|
|
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); // 记录请求日志
|
|
|
|
|
List<JianshenkechengLiuyanEntity> oldJianshenkechengLiuyanList = jianshenkechengLiuyanService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据
|
|
|
|
|
jianshenkechengLiuyanService.deleteBatchIds(Arrays.asList(ids)); // 调用服务层批量删除
|
|
|
|
|
return R.ok(); // 返回成功信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//批量上传
|
|
|
|
|
//处理批量导入数据请求
|
|
|
|
|
@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"))); // 获取用户ID
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 创建日期格式化对象
|
|
|
|
|
try {
|
|
|
|
|
List<JianshenkechengLiuyanEntity> jianshenkechengLiuyanList = new ArrayList<>(); // 创建数据列表
|
|
|
|
|
Map<String, List<String>> seachFields = new HashMap<>(); // 创建查询字段映射
|
|
|
|
|
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)){ // 如果不是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,"找不到上传文件,请联系管理员"); // 返回错误信息
|
|
|
|
|
}else{
|
|
|
|
|
List<List<String>> dataList = PoiUtil.poiImport(file.getPath()); // 读取Excel文件
|
|
|
|
|
dataList.remove(0); // 删除标题行
|
|
|
|
|
for(List<String> data:dataList){ // 遍历数据行
|
|
|
|
|
JianshenkechengLiuyanEntity jianshenkechengLiuyanEntity = new JianshenkechengLiuyanEntity(); // 创建实体对象
|
|
|
|
|
jianshenkechengLiuyanList.add(jianshenkechengLiuyanEntity); // 添加到列表
|
|
|
|
|
}
|
|
|
|
|
jianshenkechengLiuyanService.insertBatch(jianshenkechengLiuyanList); // 批量插入数据
|
|
|
|
|
return R.ok(); // 返回成功信息
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace(); // 打印异常堆栈
|
|
|
|
|
return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误信息
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//前端列表
|
|
|
|
|
//处理前端分页查询请求
|
|
|
|
|
@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 = jianshenkechengLiuyanService.queryPage(params); // 调用服务层查询分页数据
|
|
|
|
|
|
|
|
|
|
// 字典表数据转换
|
|
|
|
|
List<JianshenkechengLiuyanView> list =(List<JianshenkechengLiuyanView>)page.getList(); // 获取分页数据列表
|
|
|
|
|
for(JianshenkechengLiuyanView c:list){ // 遍历列表
|
|
|
|
|
dictionaryService.dictionaryConvert(c, request); // 转换字典字段
|
|
|
|
|
}
|
|
|
|
|
return R.ok().put("data", page); // 返回分页数据
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//前端详情
|
|
|
|
|
//处理前端详情查询请求
|
|
|
|
|
@RequestMapping("/detail/{id}") // 映射详情查询请求
|
|
|
|
|
public R detail(@PathVariable("id") Integer id, HttpServletRequest request){
|
|
|
|
|
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录请求日志
|
|
|
|
|
JianshenkechengLiuyanEntity jianshenkechengLiuyan = jianshenkechengLiuyanService.selectById(id); // 根据ID查询留言
|
|
|
|
|
if(jianshenkechengLiuyan !=null){ // 如果查询到数据
|
|
|
|
|
JianshenkechengLiuyanView view = new JianshenkechengLiuyanView(); // 创建视图对象
|
|
|
|
|
BeanUtils.copyProperties(jianshenkechengLiuyan, view); // 复制属性到视图对象
|
|
|
|
|
|
|
|
|
|
// 查询关联的健身课程信息
|
|
|
|
|
JianshenkechengEntity jianshenkecheng = jianshenkechengService.selectById(jianshenkechengLiuyan.getJianshenkechengId());
|
|
|
|
|
if(jianshenkecheng != null){
|
|
|
|
|
BeanUtils.copyProperties(jianshenkecheng, view, new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});
|
|
|
|
|
view.setJianshenkechengId(jianshenkecheng.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询关联的用户信息
|
|
|
|
|
YonghuEntity yonghu = yonghuService.selectById(jianshenkechengLiuyan.getYonghuId());
|
|
|
|
|
if(yonghu != null){
|
|
|
|
|
BeanUtils.copyProperties(yonghu, view, new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "yonghuId"});
|
|
|
|
|
view.setYonghuId(yonghu.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dictionaryService.dictionaryConvert(view, request); // 转换字典字段
|
|
|
|
|
return R.ok().put("data", view); // 返回详情数据
|
|
|
|
|
}else {
|
|
|
|
|
return R.error(511,"查不到数据"); // 返回错误信息
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//前端保存
|
|
|
|
|
//处理前端新增留言请求
|
|
|
|
|
@RequestMapping("/add") // 映射新增请求
|
|
|
|
|
public R add(@RequestBody JianshenkechengLiuyanEntity jianshenkechengLiuyan, HttpServletRequest request){
|
|
|
|
|
logger.debug("add方法:,,Controller:{},,jianshenkechengLiuyan:{}",this.getClass().getName(),jianshenkechengLiuyan.toString()); // 记录请求日志
|
|
|
|
|
jianshenkechengLiuyan.setCreateTime(new Date()); // 设置创建时间
|
|
|
|
|
jianshenkechengLiuyan.setInsertTime(new Date()); // 设置插入时间
|
|
|
|
|
jianshenkechengLiuyanService.insert(jianshenkechengLiuyan); // 调用服务层保存数据
|
|
|
|
|
return R.ok(); // 返回成功信息
|
|
|
|
|
}
|
|
|
|
|
}
|