09-15-netty优化兼容其余类型,app版本模块

This commit is contained in:
2025-09-15 20:14:30 +08:00
parent da20820627
commit e8838a91d0
8 changed files with 214 additions and 23 deletions

View File

@ -279,8 +279,8 @@ springdoc:
# packages-to-scan: org.dromara.ctr
- group: 24.招标模块
packages-to-scan: org.dromara.tender
- group: 25.app版本模块
packages-to-scan: org.dromara.app
# knife4j的增强配置不需要增强可以不配
knife4j:
enable: true

View File

@ -0,0 +1,65 @@
package org.dromara.app.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.dromara.app.domain.SysPackage;
import org.dromara.app.service.SysPackageServiceImpl;
import org.dromara.common.core.domain.R;
import org.dromara.system.domain.vo.SysOssVo;
import org.dromara.system.service.impl.SysOssServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@RestController
@RequestMapping("/app/sysPackage")
public class SysPackageController {
@Autowired
private SysOssServiceImpl sysOssService;
@Autowired
private SysPackageServiceImpl sysPackageService;
/**
* 获取最新版本
*/
@GetMapping("/getNewVersion")
public R<List<SysPackage>> getNewVersion() {
LambdaQueryWrapper<SysPackage> lambdaQueryWrapper =new LambdaQueryWrapper<>();
lambdaQueryWrapper.orderByDesc(SysPackage::getCreateTime);
List<SysPackage> one = sysPackageService.list(lambdaQueryWrapper);
return R.ok(one);
}
/**
* 上传最新安装包及版本
*/
@Transactional
@GetMapping("/uploadNewVersion")
public R<SysPackage> uploadNewVersion(String version, String type, MultipartFile file) {
SysOssVo upload = sysOssService.upload(file);
if (upload == null){
return R.fail("上传失败");
}
SysPackage sysPackage = new SysPackage();
sysPackage.setVersion( version);
sysPackage.setFileId(upload.getOssId());
sysPackage.setFileUrl(upload.getUrl());
sysPackage.setType(type);
boolean save = sysPackageService.save(sysPackage);
if (!save){
return R.fail("保存失败");
}
return R.ok(sysPackage);
}
}

View File

@ -0,0 +1,33 @@
package org.dromara.app.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import java.io.Serial;
@Data
@TableName("sys_package")
@EqualsAndHashCode(callSuper = true)
public class SysPackage extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
@TableId(value = "id")
private Long id;
/**
* 0安卓1苹果2鸿蒙
*/
private String type;
private String version;
private Long fileId;
private String fileUrl;
}

View File

@ -0,0 +1,30 @@
package org.dromara.app.domain.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.app.domain.SysPackage;
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = SysPackage.class)
public class SysPackageVo {
@ExcelProperty("id")
private Long id;
/**
* 0安卓1苹果2鸿蒙
*/
@ExcelProperty("安装包类型(0安卓1苹果2鸿蒙)")
private String type;
@ExcelProperty("版本")
private String version;
private Long fileId;
@ExcelProperty("安装包地址")
private String fileUrl;
}

View File

@ -0,0 +1,11 @@
package org.dromara.app.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.app.domain.SysPackage;
import org.dromara.app.domain.vo.SysPackageVo;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
@Mapper
public interface SysPackageMapper extends BaseMapperPlus<SysPackage, SysPackageVo> {
}

View File

@ -0,0 +1,10 @@
package org.dromara.app.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.app.domain.SysPackage;
import org.dromara.app.mapper.SysPackageMapper;
import org.springframework.stereotype.Service;
@Service
public class SysPackageServiceImpl extends ServiceImpl<SysPackageMapper, SysPackage> {
}

View File

@ -27,6 +27,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@ -171,6 +173,7 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
}
JSONObject message = new JSONObject();
message.put("type", "3");
message.put("messageType","txt");
message.put("unReadCount", roomCounts);
log.info("发送所有未读消息:{}",message);
if(message.get("unReadCount") != null && !roomCounts.isEmpty()) {
@ -293,7 +296,9 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
// "type":"0",
// "from":"66666666",
// "roomId": "1",
// "message": "testing"
// "messageType":"text"
// "fileName":""
// "message": "testing" base64
// }
//0聊天推送的正常消息 1前端主动发送消息以确认消息收到 3发送离线后未读消息列表
//前端判断当前聊天框跟消息接收ID一致后收到消息后主动发送消息给服务端确认该消息收到
@ -334,6 +339,48 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
}else {
userRoomCountMap.put(id + "+" + RoomId, userRoomCountMap.get(id + "+" + RoomId) + 1);
}
//发送消息完成后添加聊天记录
ChatHistory chatHistory = new ChatHistory();
chatHistory.setMessageDate(new Date());
chatHistory.setGeterId(Long.valueOf(RoomId));
chatHistory.setSenderId(sysUserVo.getUserId());
chatHistory.setIsRead("1");
chatHistory.setMessageType(jsonObject.get("messageType").toString());
if (!jsonObject.get("messageType").equals("text")){
//将携带base64转为文件然后进行存储 赋值url
String base64Data = jsonObject.get("message").toString();
// 移除可能的数据URL前缀
if (base64Data.contains(",")) {
base64Data = base64Data.substring(base64Data.indexOf(",") + 1);
}
byte[] fileBytes = Base64.getDecoder().decode(base64Data);
// 创建临时文件
File tempFile = File.createTempFile("", jsonObject.get("fileName").toString());
tempFile.deleteOnExit();
// 写入文件
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
fos.write(fileBytes);
}
SysOssVo upload = sysOssService.upload(tempFile);
chatHistory.setMessageFileId(upload.getOssId());
jsonObject.put("message", jsonObject.get("fileName"));
}
chatHistory.setMessage(String.valueOf(jsonObject));
chatHistoryService.save(chatHistory);
//将房间最后消息及时间存储
byId.setLastMessage(jsonObject.get("message").toString());
byId.setLastMessageTime(new Date());
chatGroupService.updateById(byId);
//通过每个用户ID拿到该用户所有通道实例
List<ChannelHandlerContext> channelHandlerContexts = userChannelMap.get(id.toString());
//如果满足则说明用户在线
@ -346,19 +393,7 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
log.info("发送消息{}", jsonObject);
}
}
//发送消息完成后添加聊天记录
ChatHistory chatHistory = new ChatHistory();
chatHistory.setMessageDate(new Date());
chatHistory.setGeterId(Long.valueOf(RoomId));
chatHistory.setSenderId(sysUserVo.getUserId());
chatHistory.setIsRead("1");
chatHistory.setMessage(String.valueOf(jsonObject));
chatHistoryService.save(chatHistory);
//将房间最后消息及时间存储
byId.setLastMessage(jsonObject.get("message").toString());
byId.setLastMessageTime(new Date());
chatGroupService.updateById(byId);
}
}
@ -392,6 +427,7 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
JSONObject message = new JSONObject();
message.put("type", "1");
message.put("unReadCount", temp);
message.put("messageType","txt");
//发送
sendMessage(ctx, message.toString());
}
@ -553,7 +589,6 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
}
//发送消息后 将该房间未读消息数加1
if (userRoomCountMap.containsKey(userId+"+"+groupServiceOne.getId())){
//该房间未读消息数加1
@ -585,6 +620,7 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
}
});
jsonObject.put("unReadCount", temp);
jsonObject.put("messageType", "txt");
}
@ -598,6 +634,7 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket
JSONObject jsonObject = new JSONObject();
jsonObject.put("type", "5");
jsonObject.put("messageType","txt");
jsonObject.put("roomInfo", chatGroup);
for (ChannelHandlerContext channelHandlerContext : channelHandlerContexts) {

View File

@ -21,13 +21,6 @@ public class ChatHistory implements Serializable {
@TableId(value = "id")
private Long id;
/***
* 0私聊1群聊
*/
// private String type;
// private Long groupId;
private Long senderId;
/***
@ -35,6 +28,18 @@ public class ChatHistory implements Serializable {
*/
private Long geterId;
/**
* 消息类型: txt,file,img,audio
*/
private String messageType;
/**
* 消息文件地址
*/
private String messageAddress;
private Long messageFileId;
private String message;
private Date messageDate;