init
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.newyetai.component.chat.constant;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
public interface ChatConstants {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.newyetai.component.chat.constant;
|
||||
|
||||
|
||||
|
||||
public enum ChatMsgStatusEnum {
|
||||
|
||||
/** 未读 **/
|
||||
INIT(1),
|
||||
/** 已读 **/
|
||||
READ(2),
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
private Integer status;
|
||||
|
||||
ChatMsgStatusEnum(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.newyetai.component.chat.constant;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.Map;
|
||||
|
||||
public enum ChatMsgTypeEnum {
|
||||
|
||||
/** 文字 */
|
||||
TEXT("text"),
|
||||
;
|
||||
|
||||
private String type;
|
||||
|
||||
ChatMsgTypeEnum(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.newyetai.component.chat.constant;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.Map;
|
||||
|
||||
public enum ChatStatusEnum {
|
||||
|
||||
/** 有效 **/
|
||||
ACTIVE(1),
|
||||
/** 关闭 **/
|
||||
CLOSED(2),
|
||||
;
|
||||
|
||||
private Integer status;
|
||||
|
||||
ChatStatusEnum(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.newyetai.component.chat.constant;
|
||||
|
||||
public enum ChatTypeEnum {
|
||||
|
||||
/** 岗位 */
|
||||
POSITION("position"),
|
||||
;
|
||||
|
||||
private String type;
|
||||
|
||||
ChatTypeEnum(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.newyetai.component.chat.controller;
|
||||
|
||||
import com.newyetai.common.util.UserContextHolder;
|
||||
import com.newyetai.usercenter.user.constant.UserTypeEnum;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import com.newyetai.common.validation.Update;
|
||||
import com.newyetai.common.AlitaResult;
|
||||
import com.newyetai.tkmybatis.pojo.Page;
|
||||
import com.newyetai.component.chat.dto.ChatQueryDTO;
|
||||
import com.newyetai.component.chat.service.ChatService;
|
||||
import com.newyetai.component.chat.dto.ChatDTO;
|
||||
import com.newyetai.component.chat.dto.ChatCreateDTO;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("chat")
|
||||
@Api(tags = "聊天会话")
|
||||
public class ChatController {
|
||||
|
||||
@Autowired
|
||||
private ChatService chatService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建")
|
||||
public AlitaResult<Long> create(
|
||||
@Validated @RequestBody ChatCreateDTO chatOperateDTO){
|
||||
return AlitaResult.success(chatService.create(chatOperateDTO));
|
||||
}
|
||||
|
||||
/* @PutMapping("/modify")
|
||||
@ApiOperation("修改")
|
||||
public AlitaResult<Boolean> modify(
|
||||
@Validated(Update.class) @RequestBody ChatCreateDTO chatOperateDTO){
|
||||
chatService.modify(chatOperateDTO);
|
||||
return AlitaResult.success(true);
|
||||
}*/
|
||||
|
||||
@DeleteMapping("/remove/{id}")
|
||||
@ApiOperation("删除")
|
||||
public AlitaResult<Boolean> remove(@PathVariable Long id){
|
||||
chatService.remove(id);
|
||||
return AlitaResult.success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("分页查询")
|
||||
public AlitaResult<Page<ChatDTO>> page(ChatQueryDTO chatQueryDTO){
|
||||
chatService.page(chatQueryDTO);
|
||||
return AlitaResult.success(chatQueryDTO.getPageResult());
|
||||
}
|
||||
|
||||
@GetMapping("/page_curr")
|
||||
@ApiOperation("分页查询")
|
||||
public AlitaResult<Page<ChatDTO>> pageCurr(ChatQueryDTO chatQueryDTO){
|
||||
Long orgId = UserContextHolder.getLoginOrgId();
|
||||
chatQueryDTO.setOrgId(orgId);
|
||||
Long userId = UserContextHolder.getLoginUserId();
|
||||
if (UserTypeEnum.PERSON.getType().equals(UserContextHolder.getUserType())){
|
||||
chatQueryDTO.setPersonUserId(userId);
|
||||
} else {
|
||||
chatQueryDTO.setOrgUserId(userId);
|
||||
}
|
||||
chatService.page(chatQueryDTO);
|
||||
return AlitaResult.success(chatQueryDTO.getPageResult());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.newyetai.component.chat.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.newyetai.component.chat.dto.ChatDTO;
|
||||
import com.newyetai.component.chat.dto.ChatQueryDTO;
|
||||
import com.newyetai.component.chat.entity.Chat;
|
||||
import com.newyetai.tkmybatis.mybatis.MyMapper;
|
||||
|
||||
/**
|
||||
* 聊天会话
|
||||
*
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
public interface ChatMapper extends MyMapper<Chat> {
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*
|
||||
* @param chatQueryDTO
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
List<ChatDTO> listChatDTO(@Param("param") ChatQueryDTO chatQueryDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.newyetai.component.chat.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.newyetai.component.chat.dto.ChatMsgDTO;
|
||||
import com.newyetai.component.chat.dto.ChatMsgQueryDTO;
|
||||
import com.newyetai.component.chat.entity.ChatMsg;
|
||||
import com.newyetai.tkmybatis.mybatis.MyMapper;
|
||||
|
||||
/**
|
||||
* 聊天消息
|
||||
*
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
public interface ChatMsgMapper extends MyMapper<ChatMsg> {
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*
|
||||
* @param chatMsgQueryDTO
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
List<ChatMsgDTO> listChatMsgDTO(@Param("param") ChatMsgQueryDTO chatMsgQueryDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.newyetai.component.chat.dto;
|
||||
|
||||
import com.newyetai.component.chat.constant.ChatTypeEnum;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Builder.Default;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import com.newyetai.common.validation.Update;
|
||||
|
||||
import com.newyetai.common.dto.BaseOperateDTO;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@ApiModel(description = "聊天会话操作")
|
||||
public class ChatCreateDTO extends BaseOperateDTO {
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull(message = "机构id不能为空")
|
||||
private Long orgId;
|
||||
@NotNull(message = "个人用户id不能为空")
|
||||
private Long personUserId;
|
||||
/** @see ChatTypeEnum 类型 */
|
||||
@Default
|
||||
private String type = ChatTypeEnum.POSITION.getType();
|
||||
|
||||
}
|
||||
44
src/main/java/com/newyetai/component/chat/dto/ChatDTO.java
Normal file
44
src/main/java/com/newyetai/component/chat/dto/ChatDTO.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package com.newyetai.component.chat.dto;
|
||||
|
||||
import com.newyetai.common.dto.BaseDTO;
|
||||
|
||||
import com.newyetai.component.chat.constant.ChatTypeEnum;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Builder
|
||||
@Data
|
||||
@ApiModel(description = "聊天会话")
|
||||
public class ChatDTO extends BaseDTO {
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 机构id */
|
||||
private Long orgId;
|
||||
/** 机构用户id */
|
||||
private Long orgUserId;
|
||||
/** 个人用户id */
|
||||
private Long personUserId;
|
||||
/** @see ChatTypeEnum 类型 */
|
||||
private Integer type;
|
||||
/** 状态:1有效,2关闭 */
|
||||
private Integer status;
|
||||
|
||||
/** 机构名称 */
|
||||
private String orgName;
|
||||
/** 个人用户名称*/
|
||||
private String personUserName;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.newyetai.component.chat.dto;
|
||||
|
||||
import com.newyetai.component.chat.constant.ChatMsgTypeEnum;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Builder.Default;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import com.newyetai.common.validation.Update;
|
||||
|
||||
import com.newyetai.common.dto.BaseOperateDTO;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@ApiModel(description = "聊天消息操作")
|
||||
public class ChatMsgCreateDTO extends BaseOperateDTO{
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 聊天id */
|
||||
private Long chatId;
|
||||
/** 机构id */
|
||||
private Long orgId;
|
||||
/** 个人用户id */
|
||||
private Long personUserId;
|
||||
/** --- 聊天id 或 orgId+personUserId 两者选其一不为空 --- */
|
||||
|
||||
/** 消息类型:text等 */
|
||||
@Default
|
||||
private String msgType = ChatMsgTypeEnum.TEXT.getType();
|
||||
/** 内容 */
|
||||
@NotEmpty(message = "内容不能为空")
|
||||
private String content;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.newyetai.component.chat.dto;
|
||||
|
||||
import com.newyetai.common.dto.BaseDTO;
|
||||
|
||||
import com.newyetai.component.chat.constant.ChatMsgStatusEnum;
|
||||
import com.newyetai.component.chat.constant.ChatMsgTypeEnum;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Builder.Default;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Builder
|
||||
@Data
|
||||
@ApiModel(description = "聊天消息")
|
||||
public class ChatMsgDTO extends BaseDTO {
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = 1L;
|
||||
/** 聊天id */
|
||||
private Long chatId;
|
||||
/** 发送用户id */
|
||||
private Long senderId;
|
||||
/** 消息类型:text等 */
|
||||
@Default
|
||||
private String msgType = ChatMsgTypeEnum.TEXT.getType();
|
||||
/** 内容 */
|
||||
private String content;
|
||||
/** 消息状态:1未读,2已读 */
|
||||
@Default
|
||||
private Integer msgStatus = ChatMsgStatusEnum.INIT.getStatus();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.newyetai.component.chat.dto;
|
||||
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
import com.newyetai.common.dto.PageQueryDTO;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@ApiModel(description = "聊天消息查询条件")
|
||||
public class ChatMsgQueryDTO extends PageQueryDTO<ChatMsgDTO>{
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long chatId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.newyetai.component.chat.dto;
|
||||
|
||||
|
||||
import com.newyetai.component.chat.constant.ChatTypeEnum;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Builder.Default;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
import com.newyetai.common.dto.PageQueryDTO;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@ApiModel(description = "聊天会话查询条件")
|
||||
public class ChatQueryDTO extends PageQueryDTO<ChatDTO>{
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("id")
|
||||
private Long id;
|
||||
/** 机构id */
|
||||
private Long orgId;
|
||||
/** 机构用户id */
|
||||
private Long orgUserId;
|
||||
/** 个人用户id */
|
||||
private Long personUserId;
|
||||
/** 状态:1有效,2关闭 */
|
||||
private Integer status;
|
||||
/** @see ChatTypeEnum 类型 */
|
||||
@Default
|
||||
private String type = ChatTypeEnum.POSITION.getType();
|
||||
|
||||
|
||||
}
|
||||
41
src/main/java/com/newyetai/component/chat/entity/Chat.java
Normal file
41
src/main/java/com/newyetai/component/chat/entity/Chat.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.newyetai.component.chat.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.newyetai.common.entity.BaseEntity;
|
||||
|
||||
import com.newyetai.component.chat.constant.ChatTypeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 聊天会话
|
||||
*
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
@TableName("xs_chat")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@SuperBuilder
|
||||
@Data
|
||||
public class Chat extends BaseEntity {
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = 1L;
|
||||
/** 机构id */
|
||||
private Long orgId;
|
||||
/** 机构用户id */
|
||||
private Long orgUserId;
|
||||
/** 个人用户id */
|
||||
private Long personUserId;
|
||||
/** @see ChatTypeEnum 类型 */
|
||||
private String type;
|
||||
/** 状态:1有效,2关闭 */
|
||||
private Integer status;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.newyetai.component.chat.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.newyetai.component.chat.constant.ChatMsgStatusEnum;
|
||||
import com.newyetai.component.chat.constant.ChatMsgTypeEnum;
|
||||
import com.newyetai.common.entity.BaseEntity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder.Default;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 聊天消息
|
||||
*
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
@TableName("xs_chat_msg")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@SuperBuilder
|
||||
@Data
|
||||
public class ChatMsg extends BaseEntity {
|
||||
|
||||
/** **/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 聊天id */
|
||||
private Long chatId;
|
||||
/** 发送用户id */
|
||||
private Long senderId;
|
||||
/** 消息类型:text等 */
|
||||
@Default
|
||||
private String msgType = ChatMsgTypeEnum.TEXT.getType();
|
||||
/** 内容 */
|
||||
private String content;
|
||||
/** 消息状态:1未读,2已读 */
|
||||
@Default
|
||||
private Integer msgStatus = ChatMsgStatusEnum.INIT.getStatus();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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.newyetai.component.chat.dao.ChatMapper">
|
||||
<select id="listChatDTO" resultType="com.newyetai.component.chat.dto.ChatDTO">
|
||||
select
|
||||
*,
|
||||
(select org_name from xs_org o where o.id = org_id) orgName,
|
||||
(select username from uc_user u where u.id = person_user_id) personUserName
|
||||
from xs_chat
|
||||
where
|
||||
deleted = 0
|
||||
<if test="param.id != null">
|
||||
and id = #{param.id}
|
||||
</if>
|
||||
<if test="param.orgId != null">
|
||||
and org_id = #{param.orgId}
|
||||
</if>
|
||||
<if test="param.orgUserId != null">
|
||||
and org_user_id = #{param.orgUserId}
|
||||
</if>
|
||||
<if test="param.personUserId != null">
|
||||
and person_user_id = #{param.personUserId}
|
||||
</if>
|
||||
<if test="param.status != null">
|
||||
and status = #{param.status}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?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.newyetai.component.chat.dao.ChatMsgMapper">
|
||||
<select id="listChatMsgDTO" resultType="com.newyetai.component.chat.dto.ChatMsgDTO">
|
||||
select
|
||||
*
|
||||
from xs_chat_msg
|
||||
where
|
||||
deleted = 0
|
||||
<if test="param.id != null">
|
||||
and id = #{param.id}
|
||||
</if>
|
||||
<if test="param.chatId != null">
|
||||
and chat_id = #{param.chatId}
|
||||
</if>
|
||||
order by id desc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.newyetai.component.chat.mapstruct;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import com.newyetai.component.chat.dto.ChatDTO;
|
||||
import com.newyetai.component.chat.entity.Chat;
|
||||
import com.newyetai.component.chat.dto.ChatCreateDTO;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
@Mapper
|
||||
public interface ChatMapMapper {
|
||||
|
||||
ChatMapMapper INSTANCE =
|
||||
Mappers.getMapper(ChatMapMapper.class);
|
||||
|
||||
/**
|
||||
* dto to entity
|
||||
*
|
||||
* @param chatDto
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
Chat toEntity(
|
||||
ChatDTO chatDto);
|
||||
|
||||
|
||||
/**
|
||||
* @param chatOperateDTO
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
Chat toEntity(ChatCreateDTO chatOperateDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.newyetai.component.chat.mapstruct;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import com.newyetai.component.chat.dto.ChatMsgDTO;
|
||||
import com.newyetai.component.chat.entity.ChatMsg;
|
||||
import com.newyetai.component.chat.dto.ChatMsgCreateDTO;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
@Mapper
|
||||
public interface ChatMsgMapMapper {
|
||||
|
||||
ChatMsgMapMapper INSTANCE =
|
||||
Mappers.getMapper(ChatMsgMapMapper.class);
|
||||
|
||||
/**
|
||||
* dto to entity
|
||||
*
|
||||
* @param chatMsgDto
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
ChatMsg toEntity(
|
||||
ChatMsgDTO chatMsgDto);
|
||||
|
||||
|
||||
/**
|
||||
* @param chatMsgCreateDTO
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
ChatMsg toEntity(ChatMsgCreateDTO chatMsgCreateDTO);
|
||||
|
||||
ChatMsgDTO toDto(ChatMsg chatMsg);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.newyetai.component.chat.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.newyetai.component.chat.dto.ChatMsgQueryDTO;
|
||||
import com.newyetai.component.chat.dto.ChatMsgCreateDTO;
|
||||
import com.newyetai.component.chat.dto.ChatMsgDTO;
|
||||
|
||||
/**
|
||||
* 聊天消息
|
||||
*
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
public interface ChatMsgService {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param chatMsgCreateDTO
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
Long create(ChatMsgCreateDTO chatMsgCreateDTO);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*
|
||||
* @param chatMsgCreateDTO
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
void modify(ChatMsgCreateDTO chatMsgCreateDTO);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
void remove(Long id);
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*
|
||||
* @param chatMsgQueryDTO
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
List<ChatMsgDTO> list(ChatMsgQueryDTO chatMsgQueryDTO);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param chatMsgQueryDTO
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
void page(ChatMsgQueryDTO chatMsgQueryDTO);
|
||||
|
||||
/**
|
||||
* 单个查询
|
||||
*
|
||||
* @param chatMsgQueryDTO
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
ChatMsgDTO find(ChatMsgQueryDTO chatMsgQueryDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.newyetai.component.chat.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.newyetai.component.chat.dto.ChatQueryDTO;
|
||||
import com.newyetai.component.chat.dto.ChatCreateDTO;
|
||||
import com.newyetai.component.chat.dto.ChatDTO;
|
||||
|
||||
/**
|
||||
* 聊天会话
|
||||
*
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
public interface ChatService {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param chatCreateDTO
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
Long create(ChatCreateDTO chatCreateDTO);
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
void remove(Long id);
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*
|
||||
* @param chatQueryDTO
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
List<ChatDTO> list(ChatQueryDTO chatQueryDTO);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param chatQueryDTO
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
void page(ChatQueryDTO chatQueryDTO);
|
||||
|
||||
/**
|
||||
* 单个查询
|
||||
*
|
||||
* @param chatQueryDTO
|
||||
* @return
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
ChatDTO find(ChatQueryDTO chatQueryDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.newyetai.component.chat.service.impl;
|
||||
|
||||
import com.newyetai.component.chat.dto.ChatCreateDTO;
|
||||
import com.newyetai.component.chat.dto.ChatDTO;
|
||||
import com.newyetai.component.chat.dto.ChatQueryDTO;
|
||||
import com.newyetai.component.chat.mapstruct.ChatMsgMapMapper;
|
||||
import com.newyetai.component.chat.service.ChatService;
|
||||
import com.newyetai.component.notice.constant.NoticeFirstTypeEnum;
|
||||
import com.newyetai.component.notice.dto.NoticeMsgDTO;
|
||||
import com.newyetai.component.notice.util.NoticeUtils;
|
||||
import com.newyetai.usercenter.user.constant.UserTypeEnum;
|
||||
import com.newyetai.usercenter.websocket.service.impl.WebsocketNoticeSendProvider;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.newyetai.component.chat.dao.ChatMsgMapper;
|
||||
import com.newyetai.component.chat.service.ChatMsgService;
|
||||
import com.newyetai.component.chat.dto.ChatMsgQueryDTO;
|
||||
import com.newyetai.component.chat.dto.ChatMsgDTO;
|
||||
import com.newyetai.component.chat.dto.ChatMsgCreateDTO;
|
||||
import com.newyetai.component.chat.entity.ChatMsg;
|
||||
|
||||
import com.newyetai.common.util.UserContextHolder;
|
||||
import com.newyetai.common.util.ListUtil;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
@Service
|
||||
public class ChatMsgServiceImpl implements ChatMsgService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ChatMsgServiceImpl.class);
|
||||
@Autowired
|
||||
private ChatMsgMapper chatMsgMapper;
|
||||
|
||||
@Autowired
|
||||
private ChatService chatService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Long create(ChatMsgCreateDTO chatMsgCreateDTO) {
|
||||
Long chatId = chatMsgCreateDTO.getChatId();
|
||||
Long senderId = UserContextHolder.getLoginUserId();
|
||||
Long personUserId = chatMsgCreateDTO.getPersonUserId();
|
||||
if (UserTypeEnum.PERSON.getType().equals(UserContextHolder.getUserType())){
|
||||
personUserId = senderId;
|
||||
}
|
||||
if (chatId == null) {
|
||||
chatId = chatService.create(ChatCreateDTO.builder().orgId(chatMsgCreateDTO.getOrgId())
|
||||
.personUserId(personUserId).build());
|
||||
}
|
||||
ChatMsg msg = ChatMsg.builder().chatId(chatId).senderId(senderId).content(chatMsgCreateDTO.getContent()).build();
|
||||
chatMsgMapper.saveEntity(msg);
|
||||
// 发通知
|
||||
this.sendAsyncNotice(chatId, ChatMsgMapMapper.INSTANCE.toDto(msg));
|
||||
return msg.getId();
|
||||
}
|
||||
|
||||
private void sendAsyncNotice(Long chatId, ChatMsgDTO msgDTO) {
|
||||
try {
|
||||
ChatDTO chatDTO = chatService.find(ChatQueryDTO.builder().id(chatId).build());
|
||||
Long receiverId =
|
||||
msgDTO.getSenderId().equals(chatDTO.getPersonUserId()) ? chatDTO.getOrgUserId()
|
||||
: chatDTO.getPersonUserId();
|
||||
NoticeUtils.sendAsyncNotice(
|
||||
NoticeMsgDTO.create(receiverId, NoticeFirstTypeEnum.CHAT.getType(), msgDTO));
|
||||
} catch (Exception e) {
|
||||
log.info("chat发送异步消息失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void modify(ChatMsgCreateDTO chatMsgCreateDTO) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void remove(Long id) {
|
||||
chatMsgMapper.deleteEntity(ChatMsg.builder().id(id).build(),
|
||||
UserContextHolder.getLoginUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChatMsgDTO> list(ChatMsgQueryDTO chatMsgQueryDTO) {
|
||||
chatMsgQueryDTO.disablePage();
|
||||
return chatMsgMapper.listChatMsgDTO(chatMsgQueryDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void page(ChatMsgQueryDTO chatMsgQueryDTO) {
|
||||
chatMsgMapper.listChatMsgDTO(chatMsgQueryDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatMsgDTO find(ChatMsgQueryDTO chatMsgQueryDTO) {
|
||||
List<ChatMsgDTO> chatMsgDTOs = this.list(chatMsgQueryDTO);
|
||||
return ListUtil.first(chatMsgDTOs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.newyetai.component.chat.service.impl;
|
||||
|
||||
import com.newyetai.common.exception.util.Assert;
|
||||
import com.newyetai.common.util.JsonUtils;
|
||||
import com.newyetai.common.validation.util.ValidateUtils;
|
||||
import com.newyetai.component.chat.constant.ChatStatusEnum;
|
||||
import com.newyetai.component.chat.mapstruct.ChatMapMapper;
|
||||
import com.newyetai.component.dynamictable.entity.DynamicTable;
|
||||
import com.newyetai.component.dynamictable.mapstruct.DynamicTableMapMapper;
|
||||
import com.newyetai.frame.redis.dto.LockDTO;
|
||||
import com.newyetai.frame.redis.redisson.RedissonUtils;
|
||||
import com.newyetai.usercenter.user.dao.OrgUserMapper;
|
||||
import com.newyetai.usercenter.user.dto.OrgUserDTO;
|
||||
import com.newyetai.usercenter.user.dto.OrgUserQueryDTO;
|
||||
import java.util.List;
|
||||
import org.springframework.aop.framework.AopContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.newyetai.component.chat.dao.ChatMapper;
|
||||
import com.newyetai.component.chat.service.ChatService;
|
||||
import com.newyetai.component.chat.dto.ChatQueryDTO;
|
||||
import com.newyetai.component.chat.dto.ChatDTO;
|
||||
import com.newyetai.component.chat.dto.ChatCreateDTO;
|
||||
import com.newyetai.component.chat.entity.Chat;
|
||||
|
||||
import com.newyetai.common.util.UserContextHolder;
|
||||
import com.newyetai.common.util.ListUtil;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
@Service
|
||||
public class ChatServiceImpl implements ChatService {
|
||||
|
||||
@Autowired
|
||||
private ChatMapper chatMapper;
|
||||
|
||||
@Autowired
|
||||
private OrgUserMapper orgUserMapper;
|
||||
|
||||
public static LockDTO getLockDTO(Long orgId, Long personUserId) {
|
||||
Assert.notNull(orgId, "机构id不能为空");
|
||||
Assert.notNull(personUserId, "个人用户id不能为空");
|
||||
return LockDTO.builder().methodName("chat").tryLockWaitTime(0L)
|
||||
.arg(orgId.toString())
|
||||
.arg(personUserId.toString())
|
||||
.failMsg("该机构-个人聊天正在被操作")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Long create(ChatCreateDTO createDTO) {
|
||||
ValidateUtils.validateBiz(createDTO);
|
||||
Long orgId = createDTO.getOrgId();
|
||||
Long personUserId = createDTO.getPersonUserId();
|
||||
ChatQueryDTO queryDTO = ChatQueryDTO.builder().orgId(orgId).personUserId(personUserId).status(
|
||||
ChatStatusEnum.ACTIVE.getStatus()).build();
|
||||
|
||||
return RedissonUtils.lockAndSave(getLockDTO(orgId, personUserId),
|
||||
() -> this.find(queryDTO), () -> {
|
||||
List<OrgUserDTO> orgUserDTOs = orgUserMapper.listOrgUserDTO(
|
||||
OrgUserQueryDTO.builder().orgId(orgId).administrator(Boolean.TRUE).build());
|
||||
Assert.isTrue(orgUserDTOs.size() == 1, orgId + ":机构管理员信息异常,请联系管理员");
|
||||
Chat chat =
|
||||
ChatMapMapper.INSTANCE.toEntity(createDTO);
|
||||
chat.setOrgUserId(orgUserDTOs.get(0).getUserId());
|
||||
chatMapper.saveEntity(chat);
|
||||
return chat.getId();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void remove(Long id) {
|
||||
chatMapper.deleteEntity(Chat.builder().id(id).build(),
|
||||
UserContextHolder.getLoginUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChatDTO> list(ChatQueryDTO chatQueryDTO) {
|
||||
chatQueryDTO.disablePage();
|
||||
return chatMapper.listChatDTO(chatQueryDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void page(ChatQueryDTO chatQueryDTO) {
|
||||
chatMapper.listChatDTO(chatQueryDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatDTO find(ChatQueryDTO chatQueryDTO) {
|
||||
List<ChatDTO> chatDTOs = this.list(chatQueryDTO);
|
||||
return ListUtil.first(chatDTOs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.newyetai.component.chat.util;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
public class ChatMsgUtils {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.newyetai.component.chat.util;
|
||||
|
||||
/**
|
||||
* @author sr on 2025-05-29
|
||||
*/
|
||||
public class ChatUtils {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user