你çšcqq 1 month ago
parent 4ae06f569a
commit 3ec17c7256

@ -1,5 +1,4 @@
package com.controller;
ppackage com.controller;
import java.io.File; import java.io.File;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -70,36 +69,37 @@ public class ChatController {
/** /**
* *
* 线 * 线
*
* @param params Map * @param params Map
* @param request HttpServletRequest * @param request HttpServletRequest
* @return R * @return R
*/ */
@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"));
// 这个条件永远为 false这里的代码逻辑可能有误正常不会进入此分支 // 这个条件永远为 false这里的代码逻辑可能有误正常不会进入此分支
if(false) if (false)
return R.error(511,"永不会进入"); return R.error(511, "永不会进入");
// 如果用户角色是 "用户",则将用户 ID 添加到请求参数中 // 如果用户角色是 "用户",则将用户 ID 添加到请求参数中
else if("用户".equals(role)) else if ("用户".equals(role))
params.put("yonghuId",request.getSession().getAttribute("userId")); params.put("yonghuId", request.getSession().getAttribute("userId"));
// 如果用户角色是 "医生",则将医生 ID 添加到请求参数中 // 如果用户角色是 "医生",则将医生 ID 添加到请求参数中
else if("医生".equals(role)) else if ("医生".equals(role))
params.put("yishengId",request.getSession().getAttribute("userId")); params.put("yishengId", request.getSession().getAttribute("userId"));
// 如果请求参数中没有指定排序字段,则默认按 id 排序 // 如果请求参数中没有指定排序字段,则默认按 id 排序
if(params.get("orderBy")==null || params.get("orderBy")==""){ if (params.get("orderBy") == null || params.get("orderBy") == "") {
params.put("orderBy","id"); params.put("orderBy", "id");
} }
// 调用 ChatService 的 queryPage 方法获取分页数据 // 调用 ChatService 的 queryPage 方法获取分页数据
PageUtils page = chatService.queryPage(params); PageUtils page = chatService.queryPage(params);
// 将分页数据中的列表转换为 ChatView 类型的列表 // 将分页数据中的列表转换为 ChatView 类型的列表
List<ChatView> list =(List<ChatView>)page.getList(); List<ChatView> list = (List<ChatView>) page.getList();
// 遍历列表,对每个 ChatView 对象进行字典表数据转换 // 遍历列表,对每个 ChatView 对象进行字典表数据转换
for(ChatView c:list){ for (ChatView c : list) {
dictionaryService.dictionaryConvert(c, request); dictionaryService.dictionaryConvert(c, request);
} }
// 返回成功响应,并将分页数据封装在 data 属性中 // 返回成功响应,并将分页数据封装在 data 属性中
@ -109,28 +109,29 @@ public class ChatController {
/** /**
* *
* 线 * 线
*
* @param id 线 ID * @param id 线 ID
* @param request HttpServletRequest * @param request HttpServletRequest
* @return R * @return R
*/ */
@RequestMapping("/info/{id}") @RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){ public R info(@PathVariable("id") Long id, HttpServletRequest request) {
// 记录调试日志,输出方法名、控制器类名和要查询的 ID // 记录调试日志,输出方法名、控制器类名和要查询的 ID
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id); logger.debug("info方法:,,Controller:{},,id:{}", this.getClass().getName(), id);
// 根据 ID 查询在线咨询记录 // 根据 ID 查询在线咨询记录
ChatEntity chat = chatService.selectById(id); ChatEntity chat = chatService.selectById(id);
// 如果查询到记录 // 如果查询到记录
if(chat !=null){ if (chat != null) {
// 将 ChatEntity 转换为 ChatView // 将 ChatEntity 转换为 ChatView
ChatView view = new ChatView(); ChatView view = new ChatView();
// 使用 BeanUtils 将 ChatEntity 的属性复制到 ChatView 中 // 使用 BeanUtils 将 ChatEntity 的属性复制到 ChatView 中
BeanUtils.copyProperties( chat , view ); BeanUtils.copyProperties(chat, view);
// 级联查询用户信息 // 级联查询用户信息
YonghuEntity yonghu = yonghuService.selectById(chat.getYonghuId()); YonghuEntity yonghu = yonghuService.selectById(chat.getYonghuId());
// 如果查询到用户信息 // 如果查询到用户信息
if(yonghu != null){ if (yonghu != null) {
// 将用户信息的部分属性复制到 ChatView 中,并排除指定字段 // 将用户信息的部分属性复制到 ChatView 中,并排除指定字段
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"}); BeanUtils.copyProperties(yonghu, view, new String[]{"id", "createTime", "insertTime", "updateTime"});
// 设置 ChatView 中的用户 ID // 设置 ChatView 中的用户 ID
view.setYonghuId(yonghu.getId()); view.setYonghuId(yonghu.getId());
} }
@ -139,9 +140,9 @@ public class ChatController {
dictionaryService.dictionaryConvert(view, request); dictionaryService.dictionaryConvert(view, request);
// 返回成功响应,并将处理后的 ChatView 数据封装在 data 属性中 // 返回成功响应,并将处理后的 ChatView 数据封装在 data 属性中
return R.ok().put("data", view); return R.ok().put("data", view);
}else { } else {
// 如果未查询到记录,返回错误响应 // 如果未查询到记录,返回错误响应
return R.error(511,"查不到数据"); return R.error(511, "查不到数据");
} }
} }
@ -149,22 +150,23 @@ public class ChatController {
/** /**
* *
* 线 * 线
*
* @param chat 线 * @param chat 线
* @param request HttpServletRequest * @param request HttpServletRequest
* @return R * @return R
*/ */
@RequestMapping("/save") @RequestMapping("/save")
public R save(@RequestBody ChatEntity chat, HttpServletRequest request){ public R save(@RequestBody ChatEntity chat, HttpServletRequest request) {
// 记录调试日志,输出方法名、控制器类名和要保存的 ChatEntity 对象 // 记录调试日志,输出方法名、控制器类名和要保存的 ChatEntity 对象
logger.debug("save方法:,,Controller:{},,chat:{}",this.getClass().getName(),chat.toString()); logger.debug("save方法:,,Controller:{},,chat:{}", this.getClass().getName(), chat.toString());
// 获取当前用户的角色信息 // 获取当前用户的角色信息
String role = String.valueOf(request.getSession().getAttribute("role")); String role = String.valueOf(request.getSession().getAttribute("role"));
// 这个条件永远为 false这里的代码逻辑可能有误正常不会进入此分支 // 这个条件永远为 false这里的代码逻辑可能有误正常不会进入此分支
if(false) if (false)
return R.error(511,"永远不会进入"); return R.error(511, "永远不会进入");
// 如果用户角色是 "用户",则设置在线咨询记录的用户 ID // 如果用户角色是 "用户",则设置在线咨询记录的用户 ID
else if("用户".equals(role)) else if ("用户".equals(role))
chat.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")))); chat.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
// 创建查询条件,检查是否已存在相同数据 // 创建查询条件,检查是否已存在相同数据
@ -173,38 +175,38 @@ public class ChatController {
.eq("chat_issue", chat.getChatIssue()) .eq("chat_issue", chat.getChatIssue())
.eq("chat_reply", chat.getChatReply()) .eq("chat_reply", chat.getChatReply())
.eq("zhuangtai_types", chat.getZhuangtaiTypes()) .eq("zhuangtai_types", chat.getZhuangtaiTypes())
.eq("chat_types", chat.getChatTypes()) .eq("chat_types", chat.getChatTypes());
;
// 记录查询条件的 SQL 片段日志 // 记录查询条件的 SQL 片段日志
logger.info("sql语句:"+queryWrapper.getSqlSegment()); logger.info("sql语句:" + queryWrapper.getSqlSegment());
// 根据查询条件查询是否已存在相同数据 // 根据查询条件查询是否已存在相同数据
ChatEntity chatEntity = chatService.selectOne(queryWrapper); ChatEntity chatEntity = chatService.selectOne(queryWrapper);
// 如果不存在相同数据 // 如果不存在相同数据
if(chatEntity==null){ if (chatEntity == null) {
// 设置插入时间为当前时间 // 设置插入时间为当前时间
chat.setInsertTime(new Date()); chat.setInsertTime(new Date());
// 插入在线咨询记录 // 插入在线咨询记录
chatService.insert(chat); chatService.insert(chat);
// 返回成功响应 // 返回成功响应
return R.ok(); return R.ok();
}else { } else {
// 如果存在相同数据,返回错误响应 // 如果存在相同数据,返回错误响应
return R.error(511,"表中有相同数据"); return R.error(511, "表中有相同数据");
} }
} }
/** /**
* *
* 线 * 线
*
* @param chat 线 * @param chat 线
* @param request HttpServletRequest * @param request HttpServletRequest
* @return R * @return R
*/ */
@RequestMapping("/update") @RequestMapping("/update")
public R update(@RequestBody ChatEntity chat, HttpServletRequest request){ public R update(@RequestBody ChatEntity chat, HttpServletRequest request) {
// 记录调试日志,输出方法名、控制器类名和要修改的 ChatEntity 对象 // 记录调试日志,输出方法名、控制器类名和要修改的 ChatEntity 对象
logger.debug("update方法:,,Controller:{},,chat:{}",this.getClass().getName(),chat.toString()); logger.debug("update方法:,,Controller:{},,chat:{}", this.getClass().getName(), chat.toString());
// 获取当前用户的角色信息 // 获取当前用户的角色信息
String role = String.valueOf(request.getSession().getAttribute("role")); String role = String.valueOf(request.getSession().getAttribute("role"));
@ -215,41 +217,41 @@ public class ChatController {
// 创建查询条件,检查是否已存在相同数据(排除当前要修改的记录) // 创建查询条件,检查是否已存在相同数据(排除当前要修改的记录)
Wrapper<ChatEntity> queryWrapper = new EntityWrapper<ChatEntity>() Wrapper<ChatEntity> queryWrapper = new EntityWrapper<ChatEntity>()
.notIn("id",chat.getId()) .notIn("id", chat.getId())
.andNew() .andNew()
.eq("yonghu_id", chat.getYonghuId()) .eq("yonghu_id", chat.getYonghuId())
.eq("chat_issue", chat.getChatIssue()) .eq("chat_issue", chat.getChatIssue())
.eq("chat_reply", chat.getChatReply()) .eq("chat_reply", chat.getChatReply())
.eq("zhuangtai_types", chat.getZhuangtaiTypes()) .eq("zhuangtai_types", chat.getZhuangtaiTypes())
.eq("chat_types", chat.getChatTypes()) .eq("chat_types", chat.getChatTypes());
;
// 记录查询条件的 SQL 片段日志 // 记录查询条件的 SQL 片段日志
logger.info("sql语句:"+queryWrapper.getSqlSegment()); logger.info("sql语句:" + queryWrapper.getSqlSegment());
// 根据查询条件查询是否已存在相同数据 // 根据查询条件查询是否已存在相同数据
ChatEntity chatEntity = chatService.selectOne(queryWrapper); ChatEntity chatEntity = chatService.selectOne(queryWrapper);
// 如果不存在相同数据 // 如果不存在相同数据
if(chatEntity==null){ if (chatEntity == null) {
// 根据 ID 更新在线咨询记录 // 根据 ID 更新在线咨询记录
chatService.updateById(chat); chatService.updateById(chat);
// 返回成功响应 // 返回成功响应
return R.ok(); return R.ok();
}else { } else {
// 如果存在相同数据,返回错误响应 // 如果存在相同数据,返回错误响应
return R.error(511,"表中有相同数据"); return R.error(511, "表中有相同数据");
} }
} }
/** /**
* *
* 线 * 线
*
* @param ids 线 ID * @param ids 线 ID
* @return R * @return R
*/ */
@RequestMapping("/delete") @RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids){ public R delete(@RequestBody Integer[] ids) {
// 记录调试日志,输出方法名、控制器类名和要删除的 ID 数组 // 记录调试日志,输出方法名、控制器类名和要删除的 ID 数组
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString()); logger.debug("delete:,,Controller:{},,ids:{}", this.getClass().getName(), ids.toString());
// 批量删除在线咨询记录 // 批量删除在线咨询记录
chatService.deleteBatchIds(Arrays.asList(ids)); chatService.deleteBatchIds(Arrays.asList(ids));
// 返回成功响应 // 返回成功响应
@ -259,49 +261,50 @@ public class ChatController {
/** /**
* *
* 线 Excel * 线 Excel
*
* @param fileName Excel * @param fileName Excel
* @return R * @return R
*/ */
@RequestMapping("/batchInsert") @RequestMapping("/batchInsert")
public R save( String fileName){ public R save(String fileName) {
// 记录调试日志,输出方法名、控制器类名和文件名 // 记录调试日志,输出方法名、控制器类名和文件名
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName); logger.debug("batchInsert方法:,,Controller:{},,fileName:{}", this.getClass().getName(), fileName);
try { try {
// 创建用于存储上传的在线咨询实体对象的列表 // 创建用于存储上传的在线咨询实体对象的列表
List<ChatEntity> chatList = new ArrayList<>(); List<ChatEntity> chatList = new ArrayList<>();
// 创建用于存储要查询的字段的 Map // 创建用于存储要查询的字段的 Map
Map<String, List<String>> seachFields= new HashMap<>(); 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, "该文件没有后缀");
}else{ } else {
// 获取文件后缀 // 获取文件后缀
String suffix = fileName.substring(lastIndexOf); String suffix = fileName.substring(lastIndexOf);
// 如果后缀不是.xls // 如果后缀不是.xls
if(!".xls".equals(suffix)){ if (!".xls".equals(suffix)) {
// 返回错误响应,提示只支持.xls 后缀的 Excel 文件 // 返回错误响应,提示只支持.xls 后缀的 Excel 文件
return R.error(511,"只支持后缀为xls的excel文件"); return R.error(511, "只支持后缀为xls的excel文件");
}else{ } else {
// 获取文件的 URL // 获取文件的 URL
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 {
// 从 Excel 文件中读取数据 // 从 Excel 文件中读取数据
List<List<String>> dataList = PoiUtil.poiImport(file.getPath()); List<List<String>> dataList = PoiUtil.poiImport(file.getPath());
// 删除第一行(通常是表头) // 删除第一行(通常是表头)
dataList.remove(0); dataList.remove(0);
// 遍历数据列表 // 遍历数据列表
for(List<String> data:dataList){ for (List<String> data : dataList) {
// 创建在线咨询实体对象 // 创建在线咨询实体对象
ChatEntity chatEntity = new ChatEntity(); ChatEntity chatEntity = new ChatEntity();
@ -317,34 +320,35 @@ public class ChatController {
} }
} }
} }
}catch (Exception e){ } catch (Exception e) {
// 如果发生异常,返回错误响应,提示批量插入数据异常 // 如果发生异常,返回错误响应,提示批量插入数据异常
return R.error(511,"批量插入数据异常,请联系管理员"); return R.error(511, "批量插入数据异常,请联系管理员");
} }
} }
/** /**
* *
* 线 * 线
*
* @param params Map * @param params Map
* @param request HttpServletRequest * @param request HttpServletRequest
* @return R * @return R
*/ */
@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));
// 如果没有指定排序字段,就默认按 id 倒序排序 // 如果没有指定排序字段,就默认按 id 倒序排序
if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){ if (StringUtil.isEmpty(String.valueOf(params.get("orderBy")))) {
params.put("orderBy","id"); params.put("orderBy", "id");
} }
// 调用 ChatService 的 queryPage 方法获取分页数据 // 调用 ChatService 的 queryPage 方法获取分页数据
PageUtils page = chatService.queryPage(params); PageUtils page = chatService.queryPage(params);
// 将分页数据中的列表转换为 ChatView 类型的列表 // 将分页数据中的列表转换为 ChatView 类型的列表
List<ChatView> list =(List<ChatView>)page.getList(); List<ChatView> list = (List<ChatView>) page.getList();
// 遍历列表,对每个 ChatView 对象进行字典表数据转换 // 遍历列表,对每个 ChatView 对象进行字典表数据转换
for(ChatView c:list) for (ChatView c : list)
dictionaryService.dictionaryConvert(c, request); dictionaryService.dictionaryConvert(c, request);
// 返回成功响应,并将分页数据封装在 data 属性中 // 返回成功响应,并将分页数据封装在 data 属性中
return R.ok().put("data", page); return R.ok().put("data", page);
@ -353,29 +357,30 @@ public class ChatController {
/** /**
* *
* 线 * 线
*
* @param id 线 ID * @param id 线 ID
* @param request HttpServletRequest * @param request HttpServletRequest
* @return R * @return R
*/ */
@RequestMapping("/detail/{id}") @RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id, HttpServletRequest request){ public R detail(@PathVariable("id") Long id, HttpServletRequest request) {
// 记录调试日志,输出方法名、控制器类名和要查询的 ID // 记录调试日志,输出方法名、控制器类名和要查询的 ID
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id); logger.debug("detail方法:,,Controller:{},,id:{}", this.getClass().getName(), id);
// 根据 ID 查询在线咨询记录 // 根据 ID 查询在线咨询记录
ChatEntity chat = chatService.selectById(id); ChatEntity chat = chatService.selectById(id);
// 如果查询到记录 // 如果查询到记录
if(chat !=null){ if (chat != null) {
// 将 ChatEntity 转换为 ChatView // 将 ChatEntity 转换为 ChatView
ChatView view = new ChatView(); ChatView view = new ChatView();
// 使用 BeanUtils 将 ChatEntity 的属性复制到 ChatView 中 // 使用 BeanUtils 将 ChatEntity 的属性复制到 ChatView 中
BeanUtils.copyProperties( chat , view ); BeanUtils.copyProperties(chat, view);
// 级联查询用户信息 // 级联查询用户信息
YonghuEntity yonghu = yonghuService.selectById(chat.getYonghuId()); YonghuEntity yonghu = yonghuService.selectById(chat.getYonghuId());
// 如果查询到用户信息 // 如果查询到用户信息
if(yonghu != null){ if (yonghu != null) {
// 将用户信息的部分属性复制到 ChatView 中,并排除指定字段 // 将用户信息的部分属性复制到 ChatView 中,并排除指定字段
BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"}); BeanUtils.copyProperties(yonghu, view, new String[]{"id", "createDate"});
// 设置 ChatView 中的用户 ID // 设置 ChatView 中的用户 ID
view.setYonghuId(yonghu.getId()); view.setYonghuId(yonghu.getId());
} }
@ -384,10 +389,10 @@ public class ChatController {
dictionaryService.dictionaryConvert(view, request); dictionaryService.dictionaryConvert(view, request);
// 返回成功响应,并将处理后的 ChatView 数据封装在 data 属性中 // 返回成功响应,并将处理后的 ChatView 数据封装在 data 属性中
return R.ok().put("data", view); return R.ok().put("data", view);
}else { } else {
// 如果未查询到记录,返回错误响应 // 如果未查询到记录,返回错误响应
return R.error(511,"查不到数据"); return R.error(511, "查不到数据");
} }
} }
}
/**

@ -58,7 +58,7 @@ public class UsersController {
/** /**
* *
*/111 */
@IgnoreAuth @IgnoreAuth
@PostMapping(value = "/register") @PostMapping(value = "/register")
public R register(@RequestBody UsersEntity user){ public R register(@RequestBody UsersEntity user){
@ -72,7 +72,7 @@ public class UsersController {
/** /**
* 退 * 退
*/43242 */
@GetMapping(value = "logout") @GetMapping(value = "logout")
public R logout(HttpServletRequest request) { public R logout(HttpServletRequest request) {
request.getSession().invalidate(); request.getSession().invalidate();

Loading…
Cancel
Save