|
|
|
@ -42,214 +42,310 @@ import com.utils.CommonUtil;
|
|
|
|
|
/**
|
|
|
|
|
* 在线咨询
|
|
|
|
|
* 后端接口
|
|
|
|
|
* @author
|
|
|
|
|
* @email
|
|
|
|
|
* @author (这里应该填写作者姓名,但代码中未给出具体值)
|
|
|
|
|
* @email (这里应该填写作者邮箱,但代码中未给出具体值)
|
|
|
|
|
* @date 2023-02-21 09:46:06
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/chat")
|
|
|
|
|
public class ChatController {
|
|
|
|
|
|
|
|
|
|
// 自动注入ChatService实例,用于处理与聊天相关的业务逻辑
|
|
|
|
|
@Autowired
|
|
|
|
|
private ChatService chatService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 后端列表
|
|
|
|
|
* 用于获取聊天记录列表,根据不同用户角色(管理员或普通用户)进行数据筛选
|
|
|
|
|
* @param params 包含查询参数的Map,例如分页参数、筛选条件等
|
|
|
|
|
* @param chat ChatEntity对象,可能包含一些额外的查询条件
|
|
|
|
|
* @param request HttpServletRequest对象,用于获取当前会话信息
|
|
|
|
|
* @return R类型的结果,包含查询到的聊天记录列表数据及相关状态信息
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/page")
|
|
|
|
|
public R page(@RequestParam Map<String, Object> params, ChatEntity chat,
|
|
|
|
|
HttpServletRequest request) {
|
|
|
|
|
// 如果当前用户不是管理员角色,设置查询条件,只查询当前用户的聊天记录
|
|
|
|
|
if (!request.getSession().getAttribute("role").toString().equals("管理员")) {
|
|
|
|
|
|
|
|
|
|
chat.setUserid((Long) request.getSession().getAttribute("userId"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建一个EntityWrapper对象,用于构建MyBatis Plus的查询条件
|
|
|
|
|
EntityWrapper<ChatEntity> ew = new EntityWrapper<ChatEntity>();
|
|
|
|
|
|
|
|
|
|
// 调用chatService的queryPage方法进行分页查询,传入构建好的查询条件和参数
|
|
|
|
|
PageUtils page = chatService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, chat), params), params));
|
|
|
|
|
// 将查询结果设置到请求属性中,可能用于在后续的视图渲染中使用
|
|
|
|
|
request.setAttribute("data", page);
|
|
|
|
|
// 返回包含查询结果的R对象,通常R对象用于统一封装返回结果的状态和数据
|
|
|
|
|
return R.ok().put("data", page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 前端列表
|
|
|
|
|
* 功能与后端列表类似,但可能在前端展示时有不同的处理或用途
|
|
|
|
|
* @param params 包含查询参数的Map,例如分页参数、筛选条件等
|
|
|
|
|
* @param chat ChatEntity对象,可能包含一些额外的查询条件
|
|
|
|
|
* @param request HttpServletRequest对象,用于获取当前会话信息
|
|
|
|
|
* @return R类型的结果,包含查询到的聊天记录列表数据及相关状态信息
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/list")
|
|
|
|
|
public R list(@RequestParam Map<String, Object> params, ChatEntity chat,
|
|
|
|
|
HttpServletRequest request) {
|
|
|
|
|
// 如果当前用户不是管理员角色,设置查询条件,只查询当前用户的聊天记录
|
|
|
|
|
if (!request.getSession().getAttribute("role").toString().equals("管理员")) {
|
|
|
|
|
|
|
|
|
|
chat.setUserid((Long) request.getSession().getAttribute("userId"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建一个EntityWrapper对象,用于构建MyBatis Plus的查询条件
|
|
|
|
|
EntityWrapper<ChatEntity> ew = new EntityWrapper<ChatEntity>();
|
|
|
|
|
|
|
|
|
|
// 调用chatService的queryPage方法进行分页查询,传入构建好的查询条件和参数
|
|
|
|
|
PageUtils page = chatService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, chat), params), params));
|
|
|
|
|
// 将查询结果设置到请求属性中,可能用于在后续的视图渲染中使用
|
|
|
|
|
request.setAttribute("data", page);
|
|
|
|
|
// 返回包含查询结果的R对象,通常R对象用于统一封装返回结果的状态和数据
|
|
|
|
|
return R.ok().put("data", page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 列表
|
|
|
|
|
* 用于获取聊天记录列表,根据传入的ChatEntity对象构建查询条件
|
|
|
|
|
* @param chat ChatEntity对象,包含查询条件信息
|
|
|
|
|
* @return R类型的结果,包含查询到的聊天记录列表数据及相关状态信息
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/lists")
|
|
|
|
|
public R list(ChatEntity chat) {
|
|
|
|
|
// 创建一个EntityWrapper对象,用于构建MyBatis Plus的查询条件
|
|
|
|
|
EntityWrapper<ChatEntity> ew = new EntityWrapper<ChatEntity>();
|
|
|
|
|
// 根据传入的ChatEntity对象构建等值查询条件
|
|
|
|
|
ew.allEq(MPUtil.allEQMapPre(chat, "chat"));
|
|
|
|
|
// 调用chatService的selectListView方法进行查询,并返回结果
|
|
|
|
|
return R.ok().put("data", chatService.selectListView(ew));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询
|
|
|
|
|
* 用于查询特定条件的在线咨询记录,并返回详细信息视图
|
|
|
|
|
* @param chat ChatEntity对象,包含查询条件信息
|
|
|
|
|
* @return R类型的结果,包含查询到的在线咨询详细信息视图及相关状态信息
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/query")
|
|
|
|
|
public R query(ChatEntity chat) {
|
|
|
|
|
// 创建一个EntityWrapper对象,用于构建MyBatis Plus的查询条件
|
|
|
|
|
EntityWrapper<ChatEntity> ew = new EntityWrapper<ChatEntity>();
|
|
|
|
|
// 根据传入的ChatEntity对象构建等值查询条件
|
|
|
|
|
ew.allEq(MPUtil.allEQMapPre(chat, "chat"));
|
|
|
|
|
// 调用chatService的selectView方法进行查询,获取ChatView对象(可能是包含详细信息的视图对象)
|
|
|
|
|
ChatView chatView = chatService.selectView(ew);
|
|
|
|
|
// 返回包含查询结果的R对象,以及提示信息和查询到的详细信息视图
|
|
|
|
|
return R.ok("查询在线咨询成功").put("data", chatView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 后端详情
|
|
|
|
|
* 用于获取指定ID的聊天记录详细信息
|
|
|
|
|
* @param id 聊天记录的ID
|
|
|
|
|
* @return R类型的结果,包含查询到的聊天记录详细信息及相关状态信息
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/info/{id}")
|
|
|
|
|
public R info(@PathVariable("id") Long id) {
|
|
|
|
|
// 调用chatService的selectById方法,根据ID查询聊天记录
|
|
|
|
|
ChatEntity chat = chatService.selectById(id);
|
|
|
|
|
// 返回包含查询结果的R对象
|
|
|
|
|
return R.ok().put("data", chat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 前端详情
|
|
|
|
|
* 功能与后端详情类似,但可能在前端展示时有不同的处理或用途,且此方法标注了@IgnoreAuth,表示忽略权限验证
|
|
|
|
|
* @param id 聊天记录的ID
|
|
|
|
|
* @return R类型的结果,包含查询到的聊天记录详细信息及相关状态信息
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping("/detail/{id}")
|
|
|
|
|
public R detail(@PathVariable("id") Long id) {
|
|
|
|
|
// 调用chatService的selectById方法,根据ID查询聊天记录
|
|
|
|
|
ChatEntity chat = chatService.selectById(id);
|
|
|
|
|
// 返回包含查询结果的R对象
|
|
|
|
|
return R.ok().put("data", chat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 后端保存
|
|
|
|
|
* 用于保存新的聊天记录,包括设置一些默认值和根据聊天内容更新相关状态
|
|
|
|
|
* @param chat 包含聊天记录信息的ChatEntity对象
|
|
|
|
|
* @param request HttpServletRequest对象,用于获取当前会话信息
|
|
|
|
|
* @return R类型的结果,用于表示保存操作的结果状态
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/save")
|
|
|
|
|
public R save(@RequestBody ChatEntity chat, HttpServletRequest request) {
|
|
|
|
|
// 设置聊天记录的ID,由当前时间戳加上一个随机数生成
|
|
|
|
|
chat.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
|
|
|
|
|
// 此处原本可能用于验证ChatEntity对象的合法性,但被注释掉了
|
|
|
|
|
//ValidatorUtils.validateEntity(chat);
|
|
|
|
|
// 如果聊天记录的提问内容不为空
|
|
|
|
|
if (StringUtils.isNotBlank(chat.getAsk())) {
|
|
|
|
|
// 更新当前用户的未回复状态为0,表示有新提问
|
|
|
|
|
chatService.updateForSet("isreply=0", new EntityWrapper<ChatEntity>().eq("userid", request.getSession().getAttribute("userId")));
|
|
|
|
|
// 设置聊天记录的用户ID为当前用户ID
|
|
|
|
|
chat.setUserid((Long) request.getSession().getAttribute("userId"));
|
|
|
|
|
// 设置回复状态为1,表示已提问等待回复
|
|
|
|
|
chat.setIsreply(1);
|
|
|
|
|
}
|
|
|
|
|
// 如果聊天记录的回复内容不为空
|
|
|
|
|
if (StringUtils.isNotBlank(chat.getReply())) {
|
|
|
|
|
// 更新当前用户(提问用户)的未回复状态为0,表示有新回复
|
|
|
|
|
chatService.updateForSet("isreply=0", new EntityWrapper<ChatEntity>().eq("userid", chat.getUserid()));
|
|
|
|
|
// 设置聊天记录的管理员ID为当前用户ID(可能表示回复的管理员)
|
|
|
|
|
chat.setAdminid((Long) request.getSession().getAttribute("userId"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 调用chatService的insert方法插入新的聊天记录
|
|
|
|
|
chatService.insert(chat);
|
|
|
|
|
// 返回表示保存成功的R对象
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 前端保存
|
|
|
|
|
* 功能与后端保存类似,但可能在前端保存时有不同的处理或用途
|
|
|
|
|
* @param chat 包含聊天记录信息的ChatEntity对象
|
|
|
|
|
* @param request HttpServletRequest对象,用于获取当前会话信息
|
|
|
|
|
* @return R类型的结果,用于表示保存操作的结果状态
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/add")
|
|
|
|
|
public R add(@RequestBody ChatEntity chat, HttpServletRequest request) {
|
|
|
|
|
// 设置聊天记录的ID,由当前时间戳加上一个随机数生成
|
|
|
|
|
chat.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue());
|
|
|
|
|
//ValidatorUtils.validateEntity(chat);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置聊天记录的用户ID为当前用户ID
|
|
|
|
|
chat.setUserid((Long) request.getSession().getAttribute("userId"));
|
|
|
|
|
// 如果聊天记录的提问内容不为空
|
|
|
|
|
if (StringUtils.isNotBlank(chat.getAsk())) {
|
|
|
|
|
// 更新当前用户的未回复状态为0,表示有新提问
|
|
|
|
|
chatService.updateForSet("isreply=0", new EntityWrapper<ChatEntity>().eq("userid", request.getSession().getAttribute("userId")));
|
|
|
|
|
chat.setUserid((Long)request.getSession().getAttribute("userId"));
|
|
|
|
|
// 设置聊天记录的用户ID为当前用户ID
|
|
|
|
|
chat.setUserid((Long) request.getSession().getAttribute("UserId"));
|
|
|
|
|
// 设置回复状态为1,表示已提问等待回复
|
|
|
|
|
chat.setIsreply(1);
|
|
|
|
|
}
|
|
|
|
|
// 如果聊天记录的回复内容不为空
|
|
|
|
|
if (StringUtils.isNotBlank(chat.getReply())) {
|
|
|
|
|
// 更新当前用户(提问用户)的未回复状态为0,表示有新回复
|
|
|
|
|
chatService.updateForSet("isreply=0", new EntityWrapper<ChatEntity>().eq("userid", chat.getUserid()));
|
|
|
|
|
chat.setAdminid((Long)request.getSession().getAttribute("userId"));
|
|
|
|
|
// 设置聊天记录的管理员ID为当前用户ID(可能表示回复的管理员)
|
|
|
|
|
chat.setAdminid((Long) request.getSession().getAttribute("UserId"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 调用chatService的insert方法插入新的聊天记录
|
|
|
|
|
chatService.insert(chat);
|
|
|
|
|
// 返回表示保存成功的R对象
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改
|
|
|
|
|
* 用于修改已存在的聊天记录
|
|
|
|
|
* @param chat 包含修改后聊天记录信息的ChatEntity对象
|
|
|
|
|
* @param request HttpServletRequest对象,可能用于获取一些额外信息(此处未体现具体用途)
|
|
|
|
|
* @return R类型的结果,用于表示修改操作的结果状态
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/update")
|
|
|
|
|
@Transactional
|
|
|
|
|
public R update(@RequestBody ChatEntity chat, HttpServletRequest request) {
|
|
|
|
|
// 此处原本可能用于验证ChatEntity对象的合法性,但被注释掉了
|
|
|
|
|
//ValidatorUtils.validateEntity(chat);
|
|
|
|
|
// 调用chatService的updateById方法,根据ID更新聊天记录
|
|
|
|
|
chatService.updateById(chat); //全部更新
|
|
|
|
|
// 返回表示修改成功的R对象
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除
|
|
|
|
|
* 用于删除指定ID的聊天记录
|
|
|
|
|
* @param ids 包含要删除聊天记录ID的数组
|
|
|
|
|
* @return R类型的结果,用于表示删除操作的结果状态
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/delete")
|
|
|
|
|
public R delete(@RequestBody Long[] ids) {
|
|
|
|
|
// 调用chatService的deleteBatchIds方法,批量删除指定ID的聊天记录
|
|
|
|
|
chatService.deleteBatchIds(Arrays.asList(ids));
|
|
|
|
|
// 返回表示删除成功的R对象
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 提醒接口
|
|
|
|
|
* 根据指定的列名、类型以及其他查询条件,统计符合条件的聊天记录数量
|
|
|
|
|
* @param columnName 要进行条件判断的列名
|
|
|
|
|
* @param request HttpServletRequest对象,用于获取当前会话信息等
|
|
|
|
|
* @param type 提醒类型,可能用于区分不同的统计逻辑
|
|
|
|
|
* @param map 包含其他查询条件的Map,例如时间范围等
|
|
|
|
|
* @return R类型的结果,包含统计到的符合条件的聊天记录数量及相关状态信息
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/remind/{columnName}/{type}")
|
|
|
|
|
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
|
|
|
|
|
@PathVariable("type") String type, @RequestParam Map<String, Object> map) {
|
|
|
|
|
// 将列名和类型添加到查询条件Map中
|
|
|
|
|
map.put("column", columnName);
|
|
|
|
|
map.put("type", type);
|
|
|
|
|
|
|
|
|
|
// 如果提醒类型为2
|
|
|
|
|
if (type.equals("2")) {
|
|
|
|
|
// 创建SimpleDateFormat对象,用于日期格式化
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
// 获取Calendar实例,用于日期计算
|
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
|
Date remindStartDate = null;
|
|
|
|
|
Date remindEndDate = null;
|
|
|
|
|
// 如果查询条件Map中包含remindstart(开始提醒时间)
|
|
|
|
|
if (map.get("remindstart")!= null) {
|
|
|
|
|
// 将remindstart转换为整数,表示要添加的天数
|
|
|
|
|
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
|
|
|
|
|
// 设置当前日期为基础日期
|
|
|
|
|
c.setTime(new Date());
|
|
|
|
|
// 根据提醒开始天数添加到当前日期上
|
|
|
|
|
c.add(Calendar.DAY_OF_MONTH, remindStart);
|
|
|
|
|
// 获取计算后的提醒开始日期
|
|
|
|
|
remindStartDate = c.getTime();
|
|
|
|
|
// 将提醒开始日期格式化为指定格式,并更新到查询条件Map中
|
|
|
|
|
map.put("remindstart", sdf.format(remindStartDate));
|
|
|
|
|
}
|
|
|
|
|
// 如果查询条件Map中包含remindend(结束提醒时间)
|
|
|
|
|
if (map.get("remindend")!= null) {
|
|
|
|
|
// 将remindend转换为整数,表示要添加的天数
|
|
|
|
|
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
|
|
|
|
|
// 设置当前日期为基础日期
|
|
|
|
|
c.setTime(new Date());
|
|
|
|
|
// 根据提醒结束天数添加到当前日期上
|
|
|
|
|
c.add(Calendar.DAY_OF_MONTH, remindEnd);
|
|
|
|
|
// 获取计算后的提醒结束日期
|
|
|
|
|
remindEndDate = c.getTime();
|
|
|
|
|
// 将提醒结束日期格式化为指定格式,并更新到查询条件Map中
|
|
|
|
|
map.put("remindend", sdf.format(remindEndDate));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建一个EntityWrapper对象,用于构建MyBatis Plus的查询条件
|
|
|
|
|
Wrapper<ChatEntity> wrapper = new EntityWrapper<ChatEntity>();
|
|
|
|
|
// 如果查询条件Map中包含remindstart(开始提醒时间),添加大于等于条件到查询条件中
|
|
|
|
|
if (map.get("remindstart")!= null) {
|
|
|
|
|
wrapper.ge(columnName, map.get("remindstart"));
|
|
|
|
|
}
|
|
|
|
|
// 如果查询条件Map中包含remindend(结束提醒时间),添加小于等于条件到查询条件中
|
|
|
|
|
if (map.get("remindend")!= null) {
|
|
|
|
|
wrapper.le(columnName, map.get("remindend"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 调用chatService的selectCount方法,根据构建好的查询条件统计符合条件的聊天记录数量
|
|
|
|
|
int count = chatService.selectCount(wrapper);
|
|
|
|
|
// 返回包含统计结果的R对象
|
|
|
|
|
return R.ok().put("count", count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|