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

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

@ -40,7 +40,7 @@ import com.utils.R;
*
*/
@RestController
public class CommonController{
public class CommonController{
private static final Logger logger = LoggerFactory.getLogger(CommonController.class);
@Autowired
private CommonService commonService;

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

Loading…
Cancel
Save