This commit is contained in:
杨建炊 2025-09-30 14:44:56 +08:00
parent 05707d924f
commit a497716897
10 changed files with 234 additions and 12 deletions

View File

@ -9,6 +9,7 @@ import org.shop.crop.constant.GlobalConstants;
import org.shop.crop.dao.CropConfig;
import org.shop.crop.dao.CropFile;
import org.shop.crop.dao.CropMessage;
import org.shop.crop.dao.CropMessageSensitiveRecord;
import org.shop.crop.dto.BaseMessageDto;
import org.shop.crop.dto.ChatData;
import org.shop.crop.dto.MessagePullResponse;
@ -105,8 +106,11 @@ public class CropController {
Set<Long> existingSeqSet = new HashSet<>(existingSeqs);
log.info("existingSeqSet={} 加密数据", existingSeqSet);
CropConfig config = cropConfigMapper.selectById(1);
CropConfig config = cropConfigMapper.selectById(1);//后续优化
Long maxSeq = config.getLastSeq();
Set<String> blockWords = config.getBlockWordSet();
/*List<CropMessageSensitiveRecord> sensitiveRecords = new ArrayList<>();*/
// 改为
List<CropFile> mediaFileInfos = new ArrayList<>();
for (ChatData chatData : chatdataList) {
@ -132,6 +136,24 @@ public class CropController {
if (chatData.getSeq() > maxSeq) {
maxSeq = chatData.getSeq();
}
/*if (!blockWords.isEmpty()&&messageDto.getMsgType()=="text") {
Set<String> matched = blockWords.stream()
.filter(messageDto.getText().getContent()::contains) // 简单包含判断
.collect(Collectors.toSet());
// 命中构造记录
CropMessageSensitiveRecord record = CropMessageSensitiveRecord.builder()
.seq(chatData.getSeq())
.msgid(message.getMsgId()) // 提取 msgid
.cropId(message.getCropId())
.content(messageDto.getText().getContent())
.keyword(String.join(",", matched))
.fromId(message.getFrom())
.roomid(message.getRoomid())
.type(message.getRoomid() == null || message.getRoomid().isEmpty() ? 1 : 2)
.build();
sensitiveRecords.add(record);
}*/
} catch (Exception e) {
log.error("解密失败{}", e.getMessage());
// 收集失败情况数据

View File

@ -7,6 +7,11 @@ import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
@Data
@TableName("crop_configs")
public class CropConfig {
@ -33,6 +38,9 @@ public class CropConfig {
*/
@TableField("message_secret")
private String messageSecret;
@TableField("block_words")
private String blockWords;
/**
* 创建时间备用字段可选
*/
@ -46,4 +54,15 @@ public class CropConfig {
private LocalDateTime updatedAt;
// 可选添加一个方法返回敏感词集合去重trim
public Set<String> getBlockWordSet() {
if (blockWords == null || blockWords.trim().isEmpty()) {
return Collections.emptySet();
}
return Arrays.stream(blockWords.split(","))
.map(String::trim)
.filter(word -> !word.isEmpty())
.collect(Collectors.toSet());
}
}

View File

@ -81,6 +81,9 @@ public class CropMessage {
@TableField("content")
private String content;
@TableField("keyword")
private String keyword;
/**
* 消息发送时间
*/

View File

@ -0,0 +1,71 @@
package org.shop.crop.dao;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Builder;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
@Builder
@Data
@TableName("crop_message_sensitive_records")
public class CropMessageSensitiveRecord {
/**
* 主键 ID自增
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
*
*/
@TableField(value = "cropid")
private String cropId;
/**
*
*/
@TableField(value = "msgid")
private String msgid;
/**
*
*/
@TableField(value = "seq")
private Long seq;
@TableField("type")
private Integer type;
@TableField("roomid")
private String roomid;
@TableField("from_id")
private String fromId;
@TableField("keyword")
private String keyword;
@TableField("content")
private String content;
/**
* 创建时间备用字段可选
*/
@TableField("created_at")
private LocalDateTime createdAt;
/**
* 修改时间自动填充
*/
@TableField("updated_at")
private LocalDateTime updatedAt;
}

View File

@ -60,6 +60,14 @@ public class BaseMessageDto {
*/
@JSONField(name = "msgtime")
private Long msgTime;
/**
* 消息类型
*/
@JSONField(name = "text")
private BaseMessageTextDto text;
@JSONField(name = "file")
private BaseMessageFileDto file;
// getter setter
@ -73,6 +81,13 @@ public class BaseMessageDto {
// id数组转为字符串
message.setTolist(JSON.toJSONString(this.toList));
message.setToId(this.toList.get(0));
if(this.getText() != null){
message.setKeyword(this.getText().getContent());
}
if(this.getFile() != null){
message.setKeyword(this.getFile().getFilename());
}
// 格式化时间
if(this.getMsgTime() != null){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");;

View File

@ -0,0 +1,29 @@
package org.shop.crop.dto;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
@Data
public class BaseMessageFileDto {
/**
* 消息类型
*/
@JSONField(name = "filename")
private String filename;
/**
* 消息类型
*/
@JSONField(name = "fileext")
private String fileext;
/**
* 消息类型
*/
@JSONField(name = "sdkfileid")
private String sdkfileid;
}

View File

@ -0,0 +1,24 @@
package org.shop.crop.dto;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import org.shop.crop.dao.CropMessage;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;
@Data
public class BaseMessageTextDto {
/**
* 消息类型
*/
@JSONField(name = "content")
private String content;
}

View File

@ -0,0 +1,22 @@
spring:
datasource:
url: jdbc:mysql://121.199.65.65:3306/shop?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf-8
username: sktod_test
password: JlZOLKtvma8Z19XF
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.example.demo.entity
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 打印SQL
global-config:
db-config:
id-type: auto
logic-delete-value: 1
logic-not-delete-value: 0
wechat:
media:
temp-dir: ./temp

View File

@ -0,0 +1,26 @@
spring:
#datasource:
#url: jdbc:mysql://121.199.65.65:3306/shop?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf-8
#username: sktod_test
#password: JlZOLKtvma8Z19XF
#driver-class-name: com.mysql.cj.jdbc.Driver
datasource:
url: jdbc:mysql://pc-bp10587hd90r70596.rwlb.rds.aliyuncs.com:3306/shop?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf-8
username: sktod_shop
password: tmeszR9VOwoWeaoa
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.example.demo.entity
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 打印SQL
global-config:
db-config:
id-type: auto
logic-delete-value: 1
logic-not-delete-value: 0
wechat:
media:
temp-dir: ./temp

View File

@ -1,15 +1,6 @@
spring:
#datasource:
#url: jdbc:mysql://121.199.65.65:3306/shop?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf-8
#username: sktod_test
#password: JlZOLKtvma8Z19XF
#driver-class-name: com.mysql.cj.jdbc.Driver
datasource:
url: jdbc:mysql://pc-bp10587hd90r70596.rwlb.rds.aliyuncs.com:3306/shop?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf-8
username: sktod_shop
password: tmeszR9VOwoWeaoa
driver-class-name: com.mysql.cj.jdbc.Driver
profiles:
active: dev
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.example.demo.entity