之前做了前端得版本,今天正好把后端也放上,明后天还会开发点击查询后可以多人添加群聊还有一些辅助功能。
Controller
/**
* <p>
* 聊天
* </p>
*
* @author 啦啦
* @since 2023-02-22
*/
@Api(tags = "仿微信聊天")
@ApiSupport(order = 1, author = "啦啦")
@ApiRestController("weChatChat")
@RequiredArgsConstructor
public class ClientController extends BaseController{
private final ClientService clientService;
@GetMapping("/insertSendOut/{imputOn}")
@ApiOperation(value = "聊天-新增", tags = ApiVersion.VERSION_1_0_0)
public ResultWrapper<Integer> insertSendOut(@PathVariable String imputOn){
return ResultWrapper.ok(clientService.insertSendOut(imputOn));
}
@GetMapping("/getSendOut")
@ApiOperation(value = "聊天-查询", tags = ApiVersion.VERSION_1_0_0)
public ResultWrapper<List<ClientVO>> getSendOut(){
return ResultWrapper.ok(clientService.getSendOut());
}
@GetMapping("/getUserId")
@ApiOperation(value = "聊天-查询当前用户返回用户id", tags = ApiVersion.VERSION_1_0_0)
public ResultWrapper<String> getUserId(){
return ResultWrapper.ok(clientService.getUserId());
}
}
Service
/**
* <p>
* 仿微信聊天 服务实现类
* </p>
*
* @author guoliang
* @since 2022-04-03
*/
@Service
@RequiredArgsConstructor
public class ClientService extends MyServiceImpl<ContractMapper, ContractDO> {
private final ClientMapper clientMapper;
/**
* <p>
* 聊天-新增
* </p>
*
*/
public int insertSendOut( String imputOn ) {
Date date = new Date();
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
String data = dateFormat.format(date);
return clientMapper.insertSendOut( SecurityUtils.getCurrentUserId(), imputOn, data );
}
/**
* <p>
* 聊天-查询
* </p>
*
*/
public List<ClientVO> getSendOut( ) {
return clientMapper.getSendOut();
}
/**
* <p>
* 返回当前用户id
* </p>
*
*/
public String getUserId( ) {
return String.valueOf(SecurityUtils.getCurrentUserId());
}
}
Mapper
/**
* <p>
* 仿微信聊天
* </p>
*
* @author guoliang
* @since 2022-04-03
*/
public interface ClientMapper extends MyBaseMapper<ContractDO> {
/**
* <p>
* 聊天-新增
* </p>
*/
int insertSendOut( Long UserId, String imputOn, String data );
/**
* <p>
* 聊天-查询
* </p>
*/
List<ClientVO> getSendOut();
}
XML
<insert id="insertSendOut" >
INSERT INTO keyan_user_chat (user_id, content, content_time) VALUES (#{UserId}, #{imputOn}, #{data});
</insert>
<select id="getSendOut" resultType="com.keyan.modules.client.vo.ClientVO">
select t.id, user_id, content, content_time, y.nick_name, y.avatar_name from keyan_user_chat t LEFT JOIN sys_user y on t.user_id = y.id Order By content_time asc
</select>
VO
/**
* <p>
* 聊天
* </p>
*
* @author guoliang
* @since 2022-04-03
*/
@Data
@TableName(value = "user_chat", autoResultMap = true)
public class ClientVO implements Serializable {
@ApiModelProperty(value = "ID")
private Long id;
@ApiModelProperty(value = "说话人")
private Long userId;
@ApiModelProperty(value = "内容")
private String content;
@ApiModelProperty(value = "时间")
private String contentTime;
@ApiModelProperty(value = "当前人Id")
private String beforeOneId;
@ApiModelProperty(value = "说话人名称")
private String nickName;
@ApiModelProperty(value = "头像地址")
private String avatarName;
}
数据库
数据库里面有个列表页就是左侧列表,但是我还没有写完 最近事情有点多,后续我会都放出来一起学习学习,