|
|
|
@ -0,0 +1,285 @@
|
|
|
|
|
package com.controller;
|
|
|
|
|
// 文件操作相关类
|
|
|
|
|
import java.io.File;
|
|
|
|
|
// 高精度数学计算类
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
// 网络URL处理类
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
// 日期格式化类
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
// FastJSON的JSON对象处理类
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
// Java集合框架类
|
|
|
|
|
import java.util.*;
|
|
|
|
|
// Spring Bean属性复制工具类
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
// HTTP请求处理类
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
// Spring Web上下文加载器
|
|
|
|
|
import org.springframework.web.context.ContextLoader;
|
|
|
|
|
// Servlet上下文接口
|
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
|
// 自定义Token服务接口
|
|
|
|
|
import com.service.TokenService;
|
|
|
|
|
// 自定义工具类包
|
|
|
|
|
import com.utils.*;
|
|
|
|
|
// Java反射异常类
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
|
|
|
|
|
// 自定义字典服务接口
|
|
|
|
|
import com.service.DictionaryService;
|
|
|
|
|
// Apache Commons字符串处理工具
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
// 自定义忽略鉴权注解
|
|
|
|
|
import com.annotation.IgnoreAuth;
|
|
|
|
|
// 日志接口
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
// 日志工厂类
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
// Spring自动注入注解
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
// Spring控制器注解
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
// Spring Web映射注解包
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
// MyBatis Plus实体包装器
|
|
|
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
|
|
// MyBatis Plus包装器接口
|
|
|
|
|
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.*;
|
|
|
|
|
|
|
|
|
|
//字典
|
|
|
|
|
//后端接口
|
|
|
|
|
//@author
|
|
|
|
|
// @email
|
|
|
|
|
|
|
|
|
|
@RestController // 声明这是一个RESTful风格的控制器
|
|
|
|
|
@Controller // 声明这是一个Spring MVC控制器
|
|
|
|
|
@RequestMapping("/dictionary") // 定义请求的基础路径
|
|
|
|
|
public class DictionaryController {
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DictionaryController.class); // 日志记录器
|
|
|
|
|
|
|
|
|
|
private static final String TABLE_NAME = "dictionary"; // 表名常量
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DictionaryService dictionaryService; // 注入字典服务
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TokenService tokenService; // 注入Token服务
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ForumService forumService; // 注入健身论坛服务
|
|
|
|
|
@Autowired
|
|
|
|
|
private JianshenkechengService jianshenkechengService; // 注入健身课程服务
|
|
|
|
|
@Autowired
|
|
|
|
|
private JianshenkechengCollectionService jianshenkechengCollectionService; // 注入课程收藏服务
|
|
|
|
|
@Autowired
|
|
|
|
|
private JianshenkechengLiuyanService jianshenkechengLiuyanService; // 注入课程留言服务
|
|
|
|
|
@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") // 处理分页请求
|
|
|
|
|
@IgnoreAuth // 忽略鉴权
|
|
|
|
|
public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
|
|
|
|
|
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params)); // 记录日志
|
|
|
|
|
CommonUtil.checkMap(params); // 检查参数
|
|
|
|
|
PageUtils page = dictionaryService.queryPage(params); // 调用服务查询分页数据
|
|
|
|
|
|
|
|
|
|
// 字典表数据转换
|
|
|
|
|
List<DictionaryView> list =(List<DictionaryView>)page.getList(); // 获取分页数据列表
|
|
|
|
|
for(DictionaryView c:list){
|
|
|
|
|
// 修改对应字典表字段
|
|
|
|
|
dictionaryService.dictionaryConvert(c, request); // 转换字典数据
|
|
|
|
|
}
|
|
|
|
|
return R.ok().put("data", page); // 返回成功响应和数据
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//后端详情
|
|
|
|
|
@RequestMapping("/info/{id}") // 处理详情请求
|
|
|
|
|
public R info(@PathVariable("id") Long id, HttpServletRequest request){
|
|
|
|
|
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); // 记录日志
|
|
|
|
|
DictionaryEntity dictionary = dictionaryService.selectById(id); // 根据ID查询字典数据
|
|
|
|
|
if(dictionary !=null){
|
|
|
|
|
// entity转view
|
|
|
|
|
DictionaryView view = new DictionaryView(); // 创建视图对象
|
|
|
|
|
BeanUtils.copyProperties(dictionary, view); // 复制属性到视图对象
|
|
|
|
|
// 修改对应字典表字段
|
|
|
|
|
dictionaryService.dictionaryConvert(view, request); // 转换字典数据
|
|
|
|
|
return R.ok().put("data", view); // 返回成功响应和数据
|
|
|
|
|
}else {
|
|
|
|
|
return R.error(511,"查不到数据"); // 返回错误响应
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//后端保存
|
|
|
|
|
@RequestMapping("/save") // 处理保存请求
|
|
|
|
|
public R save(@RequestBody DictionaryEntity dictionary, HttpServletRequest request){
|
|
|
|
|
logger.debug("save方法:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString()); // 记录日志
|
|
|
|
|
|
|
|
|
|
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
|
|
|
|
if(false)
|
|
|
|
|
return R.error(511,"永远不会进入"); // 模拟条件判断
|
|
|
|
|
|
|
|
|
|
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
|
|
|
|
|
.eq("dic_code", dictionary.getDicCode()) // 构建查询条件
|
|
|
|
|
.eq("index_name", dictionary.getIndexName());
|
|
|
|
|
if(dictionary.getDicCode().contains("_erji_types")){
|
|
|
|
|
queryWrapper.eq("super_id",dictionary.getSuperId()); // 如果是二级类型,添加父ID条件
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句
|
|
|
|
|
DictionaryEntity dictionaryEntity = dictionaryService.selectOne(queryWrapper); // 查询是否已存在相同数据
|
|
|
|
|
if(dictionaryEntity==null){
|
|
|
|
|
dictionary.setCreateTime(new Date()); // 设置创建时间
|
|
|
|
|
dictionaryService.insert(dictionary); // 插入新数据
|
|
|
|
|
// 字典表新增数据,把数据再重新查出,放入监听器中
|
|
|
|
|
List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>()); // 查询所有字典数据
|
|
|
|
|
ServletContext servletContext = request.getServletContext(); // 获取ServletContext
|
|
|
|
|
Map<String, Map<Integer,String>> map = new HashMap<>(); // 创建字典映射
|
|
|
|
|
for(DictionaryEntity d :dictionaryEntities){
|
|
|
|
|
Map<Integer, String> m = map.get(d.getDicCode()); // 获取当前字典代码的映射
|
|
|
|
|
if(m ==null || m.isEmpty()){
|
|
|
|
|
m = new HashMap<>(); // 如果不存在则创建新映射
|
|
|
|
|
}
|
|
|
|
|
m.put(d.getCodeIndex(),d.getIndexName()); // 添加编码和名称到映射
|
|
|
|
|
map.put(d.getDicCode(),m); // 将映射放入字典映射中
|
|
|
|
|
}
|
|
|
|
|
servletContext.setAttribute("dictionaryMap",map); // 将字典映射存入ServletContext
|
|
|
|
|
return R.ok(); // 返回成功响应
|
|
|
|
|
}else {
|
|
|
|
|
return R.error(511,"表中有相同数据"); // 返回错误响应
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//后端修改
|
|
|
|
|
@RequestMapping("/update") // 处理更新请求
|
|
|
|
|
public R update(@RequestBody DictionaryEntity dictionary, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {
|
|
|
|
|
logger.debug("update方法:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString()); // 记录日志
|
|
|
|
|
DictionaryEntity oldDictionaryEntity = dictionaryService.selectById(dictionary.getId()); // 查询原数据
|
|
|
|
|
|
|
|
|
|
String role = String.valueOf(request.getSession().getAttribute("role")); // 获取用户角色
|
|
|
|
|
// if(false)
|
|
|
|
|
// return R.error(511,"永远不会进入");
|
|
|
|
|
|
|
|
|
|
dictionaryService.updateById(dictionary); // 根据ID更新数据
|
|
|
|
|
// 如果字典表修改数据的话,把数据再重新查出,放入监听器中
|
|
|
|
|
List<DictionaryEntity> dictionaryEntities = dictionaryService.selectList(new EntityWrapper<DictionaryEntity>()); // 查询所有字典数据
|
|
|
|
|
ServletContext servletContext = request.getServletContext(); // 获取ServletContext
|
|
|
|
|
Map<String, Map<Integer,String>> map = new HashMap<>(); // 创建字典映射
|
|
|
|
|
for(DictionaryEntity d :dictionaryEntities){
|
|
|
|
|
Map<Integer, String> m = map.get(d.getDicCode()); // 获取当前字典代码的映射
|
|
|
|
|
if(m ==null || m.isEmpty()){
|
|
|
|
|
m = new HashMap<>(); // 如果不存在则创建新映射
|
|
|
|
|
}
|
|
|
|
|
m.put(d.getCodeIndex(),d.getIndexName()); // 添加编码和名称到映射
|
|
|
|
|
map.put(d.getDicCode(),m); // 将映射放入字典映射中
|
|
|
|
|
}
|
|
|
|
|
servletContext.setAttribute("dictionaryMap",map); // 将字典映射存入ServletContext
|
|
|
|
|
return R.ok(); // 返回成功响应
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//删除
|
|
|
|
|
@RequestMapping("/delete") // 处理删除请求
|
|
|
|
|
public R delete(@RequestBody Integer[] ids, HttpServletRequest request){
|
|
|
|
|
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); // 记录日志
|
|
|
|
|
List<DictionaryEntity> oldDictionaryList =dictionaryService.selectBatchIds(Arrays.asList(ids)); // 查询要删除的数据
|
|
|
|
|
dictionaryService.deleteBatchIds(Arrays.asList(ids)); // 批量删除数据
|
|
|
|
|
|
|
|
|
|
return R.ok(); // 返回成功响应
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//最大值
|
|
|
|
|
@RequestMapping("/maxCodeIndex") // 处理获取最大编码请求
|
|
|
|
|
public R maxCodeIndex(@RequestBody DictionaryEntity dictionary){
|
|
|
|
|
logger.debug("maxCodeIndex:,,Controller:{},,dictionary:{}",this.getClass().getName(),dictionary.toString()); // 记录日志
|
|
|
|
|
List<String> descs = new ArrayList<>(); // 创建排序字段列表
|
|
|
|
|
descs.add("code_index"); // 添加排序字段
|
|
|
|
|
Wrapper<DictionaryEntity> queryWrapper = new EntityWrapper<DictionaryEntity>()
|
|
|
|
|
.eq("dic_code", dictionary.getDicCode()) // 构建查询条件
|
|
|
|
|
.orderDesc(descs); // 添加排序条件
|
|
|
|
|
logger.info("sql语句:"+queryWrapper.getSqlSegment()); // 记录SQL语句
|
|
|
|
|
List<DictionaryEntity> dictionaryEntityList = dictionaryService.selectList(queryWrapper); // 查询数据
|
|
|
|
|
if(dictionaryEntityList.size()>0 ){
|
|
|
|
|
return R.ok().put("maxCodeIndex",dictionaryEntityList.get(0).getCodeIndex()+1); // 返回最大编码加1
|
|
|
|
|
}else{
|
|
|
|
|
return R.ok().put("maxCodeIndex",1); // 返回默认值1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//批量上传
|
|
|
|
|
@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<DictionaryEntity> dictionaryList = 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)){
|
|
|
|
|
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){
|
|
|
|
|
// 循环处理每一行数据
|
|
|
|
|
DictionaryEntity dictionaryEntity = new DictionaryEntity(); // 创建字典实体
|
|
|
|
|
// dictionaryEntity.setDicCode(data.get(0)); // 设置字段代码(示例)
|
|
|
|
|
// dictionaryEntity.setDicName(data.get(0)); // 设置字段名(示例)
|
|
|
|
|
// dictionaryEntity.setCodeIndex(Integer.valueOf(data.get(0))); // 设置编码(示例)
|
|
|
|
|
// dictionaryEntity.setIndexName(data.get(0)); // 设置编码名(示例)
|
|
|
|
|
// dictionaryEntity.setSuperId(Integer.valueOf(data.get(0))); // 设置父ID(示例)
|
|
|
|
|
// dictionaryEntity.setBeizhu(data.get(0)); // 设置备注(示例)
|
|
|
|
|
// dictionaryEntity.setCreateTime(date); // 设置创建时间(示例)
|
|
|
|
|
dictionaryList.add(dictionaryEntity); // 添加到列表
|
|
|
|
|
}
|
|
|
|
|
dictionaryService.insertBatch(dictionaryList); // 批量插入数据
|
|
|
|
|
return R.ok(); // 返回成功响应
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace(); // 打印异常堆栈
|
|
|
|
|
return R.error(511,"批量插入数据异常,请联系管理员"); // 返回错误响应
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|