From e6b1b64bd66687b8a924b9298029982961c19adb Mon Sep 17 00:00:00 2001 From: WenG <450292408@qq.com> Date: Thu, 23 Dec 2021 21:28:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ekafka=E7=BD=91=E6=A0=BC?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pojo/dtos/kafka/SyncDataDTO.java | 51 ++++++++++++++++++- .../grid/impl/GridDeleteAfterHandlerImpl.java | 45 ++++++++++++++++ .../grid/impl/GridSaveAfterHandlerImpl.java | 26 ++++++++-- .../grid/impl/GridUpdateAfterHandlerImpl.java | 46 +++++++++++++++++ src/main/resources/application-dev.yml | 14 ++--- 5 files changed, 169 insertions(+), 13 deletions(-) create mode 100644 src/main/java/cn/com/tenlion/usercenter/service/grid/impl/GridDeleteAfterHandlerImpl.java create mode 100644 src/main/java/cn/com/tenlion/usercenter/service/grid/impl/GridUpdateAfterHandlerImpl.java diff --git a/src/main/java/cn/com/tenlion/usercenter/pojo/dtos/kafka/SyncDataDTO.java b/src/main/java/cn/com/tenlion/usercenter/pojo/dtos/kafka/SyncDataDTO.java index bcabb89..ba4eb22 100644 --- a/src/main/java/cn/com/tenlion/usercenter/pojo/dtos/kafka/SyncDataDTO.java +++ b/src/main/java/cn/com/tenlion/usercenter/pojo/dtos/kafka/SyncDataDTO.java @@ -10,8 +10,57 @@ package cn.com.tenlion.usercenter.pojo.dtos.kafka; public class SyncDataDTO { private String uid; + private String keyId; + private String keyValue; private String tableNumber; 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; + } } diff --git a/src/main/java/cn/com/tenlion/usercenter/service/grid/impl/GridDeleteAfterHandlerImpl.java b/src/main/java/cn/com/tenlion/usercenter/service/grid/impl/GridDeleteAfterHandlerImpl.java new file mode 100644 index 0000000..781600f --- /dev/null +++ b/src/main/java/cn/com/tenlion/usercenter/service/grid/impl/GridDeleteAfterHandlerImpl.java @@ -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 gridIds) { + if (gridIds.isEmpty()) { + return; + } + String gridIdString = StringUtils.join(gridIds, "_"); + SyncDataDTO syncDataDTO = new SyncDataDTO<>(); + syncDataDTO.setUid(gridIdString); + syncDataDTO.setAction("delete"); + syncDataDTO.setData(new HashMap<>()); + syncDataDTO.setTableNumber(""); + kafkaTemplate.send("C0021", JSONObject.toJSONString(syncDataDTO)); + } + +} diff --git a/src/main/java/cn/com/tenlion/usercenter/service/grid/impl/GridSaveAfterHandlerImpl.java b/src/main/java/cn/com/tenlion/usercenter/service/grid/impl/GridSaveAfterHandlerImpl.java index b32982b..b68d538 100644 --- a/src/main/java/cn/com/tenlion/usercenter/service/grid/impl/GridSaveAfterHandlerImpl.java +++ b/src/main/java/cn/com/tenlion/usercenter/service/grid/impl/GridSaveAfterHandlerImpl.java @@ -1,11 +1,16 @@ 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 org.json.JSONObject; +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; + /** * @ClassName: GridSaveAfterHandlerImpl * @Description: 网格新增 @@ -21,10 +26,21 @@ public class GridSaveAfterHandlerImpl implements IGridSaveAfterHandler { @Override public void handle(String gridId, String gridCode, String gridName, String fillColor, String areaCode, String areaName) { - JSONObject gridJSONObject = new JSONObject(); - gridJSONObject.put("uid", gridId); - gridJSONObject.put("action", "save"); - + if (StringUtils.isBlank(gridId)) { + return; + } + SyncDataDTO syncDataDTO = new SyncDataDTO<>(); + Map 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)); } } diff --git a/src/main/java/cn/com/tenlion/usercenter/service/grid/impl/GridUpdateAfterHandlerImpl.java b/src/main/java/cn/com/tenlion/usercenter/service/grid/impl/GridUpdateAfterHandlerImpl.java new file mode 100644 index 0000000..014a945 --- /dev/null +++ b/src/main/java/cn/com/tenlion/usercenter/service/grid/impl/GridUpdateAfterHandlerImpl.java @@ -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 syncDataDTO = new SyncDataDTO<>(); + Map 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)); + } + +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 4408680..2f39d5e 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,6 +1,6 @@ server: port: 7011 - ip: 192.168.0.103 + ip: 127.0.0.1 url: http://${server.ip}:7011/usercenter system-title: 统一用户管理系统 system-sub-title: 智慧城市 @@ -54,12 +54,12 @@ spring: use-global-data-source-stat: true data: mongodb: - uri: mongodb://smartcity:smartcity@127.0.0.1:27017/smartcity + uri: mongodb://smartcity:smartcity@192.168.0.151:27017/smartcity redis: database: 6 - host: 127.0.0.1 + host: 192.168.0.151 port: 6379 - password: 666 + password: root timeout: 3000ms jedis: pool: @@ -100,7 +100,7 @@ swagger: base-package-list: ink.wgink,cn.com.tenlion file: - upload-path: /project/UploadFiles/ + upload-path: C:\Users\wenc0\Desktop\UploadFiles\ image-types: png,jpg,jpeg,gif,blob video-types: mp4,rmvb audio-types: mp3,wmv,amr @@ -111,7 +111,7 @@ file: use-min-io: true # 与use-min-io配套使用 min-io: - endpoint: http://127.0.0.1:9900 + endpoint: http://192.168.0.151:9900 access-key: smartcity secret-key: smartcity @@ -144,7 +144,7 @@ sms: logging: # enable-api-log: true file: - name: /project/logs/usercenter-logs.log + name: C:\Users\wenc0\Desktop\UploadFiles\logs\usercenter-logs.log level: root: error org.springframework.data.mongodb: debug