9 changed files with 218 additions and 23 deletions
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
package com.cloud.kicc.system.api.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.cloud.kicc.common.data.entity.CommonEntity; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
/** |
||||
* <p> |
||||
* 聊天会话 |
||||
* </p> |
||||
* |
||||
* @author wangxiang4 |
||||
* @since 2023-12-12 |
||||
*/ |
||||
@Getter |
||||
@Setter |
||||
@Accessors(chain = true) |
||||
@TableName(value = "sys_im_session", excludeProperty = { "createById", "createByName", "createTime", "updateById", "updateByName", "updateTime", "remarks" }) |
||||
@ApiModel(value = "ImSession对象", description = "聊天会话") |
||||
public class ImSession extends CommonEntity { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@ApiModelProperty("主键") |
||||
private String id; |
||||
|
||||
@ApiModelProperty("用户主键") |
||||
private String userId; |
||||
|
||||
@ApiModelProperty("接收用户") |
||||
private String receiveUserId; |
||||
|
||||
@ApiModelProperty("接收时间") |
||||
private LocalDateTime receiveTime; |
||||
|
||||
} |
@ -0,0 +1,98 @@
@@ -0,0 +1,98 @@
|
||||
package com.cloud.kicc.system.controller; |
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil; |
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.cloud.kicc.common.core.api.R; |
||||
import com.cloud.kicc.common.core.constant.AppConstants; |
||||
import com.cloud.kicc.common.core.exception.CheckedException; |
||||
import com.cloud.kicc.common.security.annotation.Inner; |
||||
import com.cloud.kicc.common.security.util.SecurityUtils; |
||||
import com.cloud.kicc.system.api.entity.ImContent; |
||||
import com.cloud.kicc.system.api.entity.ImSession; |
||||
import com.cloud.kicc.system.service.IImSessionService; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.Arrays; |
||||
import java.util.Optional; |
||||
|
||||
/** |
||||
* <p> |
||||
* 聊天会话 前端控制器 |
||||
* </p> |
||||
* |
||||
* @author wangxiang4 |
||||
* @since 2023-12-12 |
||||
*/ |
||||
@Controller |
||||
@RequiredArgsConstructor |
||||
@RequestMapping(AppConstants.APP_SYSTEM + "/imSession") |
||||
public class ImSessionController { |
||||
|
||||
private final IImSessionService iImSessionService; |
||||
|
||||
private LambdaQueryWrapper<ImSession> getQueryWrapper(ImSession imSession) { |
||||
return new LambdaQueryWrapper<ImSession>() |
||||
.eq(StrUtil.isNotBlank(imSession.getUserId()), ImSession::getUserId, imSession.getUserId()) |
||||
.eq(StrUtil.isNotBlank(imSession.getReceiveUserId()), ImSession::getReceiveUserId, imSession.getReceiveUserId()) |
||||
.orderByDesc(ImSession::getReceiveTime); |
||||
} |
||||
|
||||
@GetMapping("/list") |
||||
public R list(Page page, ImSession imSession) { |
||||
IPage<ImSession> result = iImSessionService.page(page, getQueryWrapper(imSession)); |
||||
return R.ok(result.getRecords(), result.getTotal()); |
||||
} |
||||
|
||||
@GetMapping("/{id:\\w+}") |
||||
public R getById(@PathVariable("id") String id) { |
||||
return R.ok(iImSessionService.getById(id)); |
||||
} |
||||
|
||||
@PostMapping("/save") |
||||
public R save(@Validated @RequestBody ImSession imSession) { |
||||
iImSessionService.save(imSession); |
||||
return R.ok(); |
||||
} |
||||
|
||||
@Inner(false) |
||||
@PostMapping("/sessionSave") |
||||
public R sessionSave(@Validated @RequestBody ImSession imSession) { |
||||
SecurityUtils.openInterfaceTemporaryLoginSession(imSession.getUserId()); |
||||
imSession.setReceiveTime(LocalDateTime.now()); |
||||
iImSessionService.save(imSession); |
||||
return R.ok(imSession); |
||||
} |
||||
|
||||
@Inner(false) |
||||
@GetMapping("/lastSession") |
||||
public R lastSession(String userId) { |
||||
Optional.ofNullable(userId).orElseThrow(() -> new CheckedException("发送用户ID必传!")); |
||||
ImSession session = iImSessionService.getOne(Wrappers.<ImSession>lambdaQuery() |
||||
.eq(ImSession::getUserId, userId) |
||||
.orderByDesc(ImSession::getReceiveTime) |
||||
.last("LIMIT 1")); |
||||
return R.ok(session); |
||||
} |
||||
|
||||
@PutMapping("/update") |
||||
public R update(@Validated @RequestBody ImSession imSession) { |
||||
iImSessionService.updateById(imSession); |
||||
return R.ok(); |
||||
} |
||||
|
||||
@DeleteMapping("/remove/{id:[\\w,]+}") |
||||
public R remove(@PathVariable String[] id) { |
||||
iImSessionService.removeByIds(Arrays.asList(id)); |
||||
return R.ok(); |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
package com.cloud.kicc.system.mapper; |
||||
|
||||
import com.cloud.kicc.system.api.entity.ImSession; |
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
||||
/** |
||||
* <p> |
||||
* 聊天会话 Mapper 接口 |
||||
* </p> |
||||
* |
||||
* @author wangxiang4 |
||||
* @since 2023-12-12 |
||||
*/ |
||||
public interface ImSessionMapper extends BaseMapper<ImSession> { |
||||
|
||||
} |
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
package com.cloud.kicc.system.service; |
||||
|
||||
import com.cloud.kicc.system.api.entity.ImSession; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
||||
/** |
||||
* <p> |
||||
* 聊天会话 服务类 |
||||
* </p> |
||||
* |
||||
* @author wangxiang4 |
||||
* @since 2023-12-12 |
||||
*/ |
||||
public interface IImSessionService extends IService<ImSession> { |
||||
|
||||
} |
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
package com.cloud.kicc.system.service.impl; |
||||
|
||||
import com.cloud.kicc.system.api.entity.ImSession; |
||||
import com.cloud.kicc.system.mapper.ImSessionMapper; |
||||
import com.cloud.kicc.system.service.IImSessionService; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* <p> |
||||
* 聊天会话 服务实现类 |
||||
* </p> |
||||
* |
||||
* @author wangxiang4 |
||||
* @since 2023-12-12 |
||||
*/ |
||||
@Service |
||||
public class ImSessionServiceImpl extends ServiceImpl<ImSessionMapper, ImSession> implements IImSessionService { |
||||
|
||||
} |
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
<mapper namespace="com.cloud.kicc.system.mapper.ImSessionMapper"> |
||||
|
||||
</mapper> |
Loading…
Reference in new issue