新增kafka网格同步

This commit is contained in:
WenG 2021-12-23 21:28:24 +08:00
parent 0eed03283d
commit e6b1b64bd6
5 changed files with 169 additions and 13 deletions

View File

@ -10,8 +10,57 @@ package cn.com.tenlion.usercenter.pojo.dtos.kafka;
public class SyncDataDTO<T> { public class SyncDataDTO<T> {
private String uid; private String uid;
private String keyId;
private String keyValue;
private String tableNumber; private String tableNumber;
private String action; private String action;
private String private T data;
public String getUid() {
return uid == null ? "" : uid.trim();
}
public void setUid(String uid) {
this.uid = uid;
}
public String getKeyId() {
return keyId == null ? "" : keyId.trim();
}
public void setKeyId(String keyId) {
this.keyId = keyId;
}
public String getKeyValue() {
return keyValue == null ? "" : keyValue.trim();
}
public void setKeyValue(String keyValue) {
this.keyValue = keyValue;
}
public String getTableNumber() {
return tableNumber == null ? "" : tableNumber.trim();
}
public void setTableNumber(String tableNumber) {
this.tableNumber = tableNumber;
}
public String getAction() {
return action == null ? "" : action.trim();
}
public void setAction(String action) {
this.action = action;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
} }

View File

@ -0,0 +1,45 @@
package cn.com.tenlion.usercenter.service.grid.impl;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.interfaces.map.IGridDeleteAfterHandler;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: GridDeleteAfterHandlerImpl
* @Description:
* @Author: WangGeng
* @Date: 2021/12/23 21:15
* @Version: 1.0
**/
@Service
public class GridDeleteAfterHandlerImpl implements IGridDeleteAfterHandler {
@Autowired
private KafkaTemplate kafkaTemplate;
@Override
public void handler(List<String> gridIds) {
if (gridIds.isEmpty()) {
return;
}
String gridIdString = StringUtils.join(gridIds, "_");
SyncDataDTO<Map> syncDataDTO = new SyncDataDTO<>();
syncDataDTO.setUid(gridIdString);
syncDataDTO.setAction("delete");
syncDataDTO.setData(new HashMap<>());
syncDataDTO.setTableNumber("");
kafkaTemplate.send("C0021", JSONObject.toJSONString(syncDataDTO));
}
}

View File

@ -1,11 +1,16 @@
package cn.com.tenlion.usercenter.service.grid.impl; package cn.com.tenlion.usercenter.service.grid.impl;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.interfaces.map.IGridSaveAfterHandler; import ink.wgink.interfaces.map.IGridSaveAfterHandler;
import org.json.JSONObject; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/** /**
* @ClassName: GridSaveAfterHandlerImpl * @ClassName: GridSaveAfterHandlerImpl
* @Description: 网格新增 * @Description: 网格新增
@ -21,10 +26,21 @@ public class GridSaveAfterHandlerImpl implements IGridSaveAfterHandler {
@Override @Override
public void handle(String gridId, String gridCode, String gridName, String fillColor, String areaCode, String areaName) { public void handle(String gridId, String gridCode, String gridName, String fillColor, String areaCode, String areaName) {
JSONObject gridJSONObject = new JSONObject(); if (StringUtils.isBlank(gridId)) {
gridJSONObject.put("uid", gridId); return;
gridJSONObject.put("action", "save"); }
SyncDataDTO<Map> syncDataDTO = new SyncDataDTO<>();
Map<String, String> gridMap = new HashMap<>();
gridMap.put("gridCode", gridCode);
gridMap.put("gridName", gridName);
gridMap.put("fillColor", fillColor);
gridMap.put("areaCode", areaCode);
gridMap.put("areaName", areaName);
syncDataDTO.setUid(gridId);
syncDataDTO.setAction("save");
syncDataDTO.setData(gridMap);
syncDataDTO.setTableNumber("");
kafkaTemplate.send("C0021", JSONObject.toJSONString(syncDataDTO));
} }
} }

View File

@ -0,0 +1,46 @@
package cn.com.tenlion.usercenter.service.grid.impl;
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.interfaces.map.IGridUpdateAfterHandler;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: GridUpdateAfterHandlerImpl
* @Description:
* @Author: WangGeng
* @Date: 2021/12/23 21:14
* @Version: 1.0
**/
@Service
public class GridUpdateAfterHandlerImpl implements IGridUpdateAfterHandler {
@Autowired
private KafkaTemplate kafkaTemplate;
@Override
public void handle(String gridId, String gridName, String fillColor) {
if (StringUtils.isBlank(gridId)) {
return;
}
SyncDataDTO<Map> syncDataDTO = new SyncDataDTO<>();
Map<String, String> gridMap = new HashMap<>();
gridMap.put("gridName", gridName);
gridMap.put("fillColor", fillColor);
syncDataDTO.setUid(gridId);
syncDataDTO.setAction("update");
syncDataDTO.setData(gridMap);
syncDataDTO.setTableNumber("");
kafkaTemplate.send("C0021", JSONObject.toJSONString(syncDataDTO));
}
}

View File

@ -1,6 +1,6 @@
server: server:
port: 7011 port: 7011
ip: 192.168.0.103 ip: 127.0.0.1
url: http://${server.ip}:7011/usercenter url: http://${server.ip}:7011/usercenter
system-title: 统一用户管理系统 system-title: 统一用户管理系统
system-sub-title: 智慧城市 system-sub-title: 智慧城市
@ -54,12 +54,12 @@ spring:
use-global-data-source-stat: true use-global-data-source-stat: true
data: data:
mongodb: mongodb:
uri: mongodb://smartcity:smartcity@127.0.0.1:27017/smartcity uri: mongodb://smartcity:smartcity@192.168.0.151:27017/smartcity
redis: redis:
database: 6 database: 6
host: 127.0.0.1 host: 192.168.0.151
port: 6379 port: 6379
password: 666 password: root
timeout: 3000ms timeout: 3000ms
jedis: jedis:
pool: pool:
@ -100,7 +100,7 @@ swagger:
base-package-list: ink.wgink,cn.com.tenlion base-package-list: ink.wgink,cn.com.tenlion
file: file:
upload-path: /project/UploadFiles/ upload-path: C:\Users\wenc0\Desktop\UploadFiles\
image-types: png,jpg,jpeg,gif,blob image-types: png,jpg,jpeg,gif,blob
video-types: mp4,rmvb video-types: mp4,rmvb
audio-types: mp3,wmv,amr audio-types: mp3,wmv,amr
@ -111,7 +111,7 @@ file:
use-min-io: true use-min-io: true
# 与use-min-io配套使用 # 与use-min-io配套使用
min-io: min-io:
endpoint: http://127.0.0.1:9900 endpoint: http://192.168.0.151:9900
access-key: smartcity access-key: smartcity
secret-key: smartcity secret-key: smartcity
@ -144,7 +144,7 @@ sms:
logging: logging:
# enable-api-log: true # enable-api-log: true
file: file:
name: /project/logs/usercenter-logs.log name: C:\Users\wenc0\Desktop\UploadFiles\logs\usercenter-logs.log
level: level:
root: error root: error
org.springframework.data.mongodb: debug org.springframework.data.mongodb: debug