更改
This commit is contained in:
parent
05707d924f
commit
a497716897
@ -9,6 +9,7 @@ import org.shop.crop.constant.GlobalConstants;
|
|||||||
import org.shop.crop.dao.CropConfig;
|
import org.shop.crop.dao.CropConfig;
|
||||||
import org.shop.crop.dao.CropFile;
|
import org.shop.crop.dao.CropFile;
|
||||||
import org.shop.crop.dao.CropMessage;
|
import org.shop.crop.dao.CropMessage;
|
||||||
|
import org.shop.crop.dao.CropMessageSensitiveRecord;
|
||||||
import org.shop.crop.dto.BaseMessageDto;
|
import org.shop.crop.dto.BaseMessageDto;
|
||||||
import org.shop.crop.dto.ChatData;
|
import org.shop.crop.dto.ChatData;
|
||||||
import org.shop.crop.dto.MessagePullResponse;
|
import org.shop.crop.dto.MessagePullResponse;
|
||||||
@ -105,8 +106,11 @@ public class CropController {
|
|||||||
Set<Long> existingSeqSet = new HashSet<>(existingSeqs);
|
Set<Long> existingSeqSet = new HashSet<>(existingSeqs);
|
||||||
log.info("existingSeqSet={} 加密数据", existingSeqSet);
|
log.info("existingSeqSet={} 加密数据", existingSeqSet);
|
||||||
|
|
||||||
CropConfig config = cropConfigMapper.selectById(1);
|
CropConfig config = cropConfigMapper.selectById(1);//后续优化
|
||||||
Long maxSeq = config.getLastSeq();
|
Long maxSeq = config.getLastSeq();
|
||||||
|
Set<String> blockWords = config.getBlockWordSet();
|
||||||
|
/*List<CropMessageSensitiveRecord> sensitiveRecords = new ArrayList<>();*/
|
||||||
|
|
||||||
// 改为:
|
// 改为:
|
||||||
List<CropFile> mediaFileInfos = new ArrayList<>();
|
List<CropFile> mediaFileInfos = new ArrayList<>();
|
||||||
for (ChatData chatData : chatdataList) {
|
for (ChatData chatData : chatdataList) {
|
||||||
@ -132,6 +136,24 @@ public class CropController {
|
|||||||
if (chatData.getSeq() > maxSeq) {
|
if (chatData.getSeq() > maxSeq) {
|
||||||
maxSeq = chatData.getSeq();
|
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) {
|
} catch (Exception e) {
|
||||||
log.error("解密失败{}", e.getMessage());
|
log.error("解密失败{}", e.getMessage());
|
||||||
// 收集失败情况数据
|
// 收集失败情况数据
|
||||||
|
|||||||
@ -7,6 +7,11 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@TableName("crop_configs")
|
@TableName("crop_configs")
|
||||||
public class CropConfig {
|
public class CropConfig {
|
||||||
@ -33,6 +38,9 @@ public class CropConfig {
|
|||||||
*/
|
*/
|
||||||
@TableField("message_secret")
|
@TableField("message_secret")
|
||||||
private String messageSecret;
|
private String messageSecret;
|
||||||
|
|
||||||
|
@TableField("block_words")
|
||||||
|
private String blockWords;
|
||||||
/**
|
/**
|
||||||
* 创建时间(备用字段,可选)
|
* 创建时间(备用字段,可选)
|
||||||
*/
|
*/
|
||||||
@ -46,4 +54,15 @@ public class CropConfig {
|
|||||||
private LocalDateTime updatedAt;
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,6 +81,9 @@ public class CropMessage {
|
|||||||
@TableField("content")
|
@TableField("content")
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
|
@TableField("keyword")
|
||||||
|
private String keyword;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息发送时间
|
* 消息发送时间
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -60,6 +60,14 @@ public class BaseMessageDto {
|
|||||||
*/
|
*/
|
||||||
@JSONField(name = "msgtime")
|
@JSONField(name = "msgtime")
|
||||||
private Long msgTime;
|
private Long msgTime;
|
||||||
|
/**
|
||||||
|
* 消息类型
|
||||||
|
*/
|
||||||
|
@JSONField(name = "text")
|
||||||
|
private BaseMessageTextDto text;
|
||||||
|
|
||||||
|
@JSONField(name = "file")
|
||||||
|
private BaseMessageFileDto file;
|
||||||
|
|
||||||
// getter setter
|
// getter setter
|
||||||
|
|
||||||
@ -73,6 +81,13 @@ public class BaseMessageDto {
|
|||||||
// id数组转为字符串
|
// id数组转为字符串
|
||||||
message.setTolist(JSON.toJSONString(this.toList));
|
message.setTolist(JSON.toJSONString(this.toList));
|
||||||
message.setToId(this.toList.get(0));
|
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){
|
if(this.getMsgTime() != null){
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");;
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");;
|
||||||
|
|||||||
29
src/main/java/org/shop/crop/dto/BaseMessageFileDto.java
Normal file
29
src/main/java/org/shop/crop/dto/BaseMessageFileDto.java
Normal 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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
24
src/main/java/org/shop/crop/dto/BaseMessageTextDto.java
Normal file
24
src/main/java/org/shop/crop/dto/BaseMessageTextDto.java
Normal 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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
22
src/main/resources/application-dev.yml
Normal file
22
src/main/resources/application-dev.yml
Normal 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
|
||||||
26
src/main/resources/application-prod.yml
Normal file
26
src/main/resources/application-prod.yml
Normal 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
|
||||||
@ -1,15 +1,6 @@
|
|||||||
spring:
|
spring:
|
||||||
#datasource:
|
profiles:
|
||||||
#url: jdbc:mysql://121.199.65.65:3306/shop?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf-8
|
active: dev
|
||||||
#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:
|
mybatis-plus:
|
||||||
mapper-locations: classpath:mapper/*.xml
|
mapper-locations: classpath:mapper/*.xml
|
||||||
type-aliases-package: com.example.demo.entity
|
type-aliases-package: com.example.demo.entity
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user