1.新增网格员EXCEL导入代码
2.调整Kafka接口
This commit is contained in:
parent
fbced9a56f
commit
dfd36f3c39
@ -0,0 +1,35 @@
|
||||
package cn.com.tenlion.usercenter.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @ClassName: ParamsConfigProperties
|
||||
* @Description: 参数配置
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/1/26 4:29 PM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "params-config")
|
||||
public class ParamsConfigProperties {
|
||||
|
||||
private String roleSpecializedPerson;
|
||||
private String roleGridMember;
|
||||
|
||||
public String getRoleSpecializedPerson() {
|
||||
return roleSpecializedPerson == null ? "" : roleSpecializedPerson.trim();
|
||||
}
|
||||
|
||||
public void setRoleSpecializedPerson(String roleSpecializedPerson) {
|
||||
this.roleSpecializedPerson = roleSpecializedPerson;
|
||||
}
|
||||
|
||||
public String getRoleGridMember() {
|
||||
return roleGridMember == null ? "" : roleGridMember.trim();
|
||||
}
|
||||
|
||||
public void setRoleGridMember(String roleGridMember) {
|
||||
this.roleGridMember = roleGridMember;
|
||||
}
|
||||
}
|
@ -17,9 +17,21 @@ public interface ISmartCityUserCenterConsts {
|
||||
String KAFKA_TOPIC_TABLE_SYNC = "tableSync";
|
||||
String KAFKA_TOPIC_GRID_MEMBER_REALTIME_LOCATION = "gridMemberRealtimeLocation";
|
||||
|
||||
String KAFKA_TABLE_SYNC_GRID_MEMBER = "C0021";
|
||||
/**
|
||||
* 网格关系
|
||||
*/
|
||||
String KAFKA_TABLE_SYNC_GRID_RELATION = "C0021";
|
||||
String KAFKA_TABLE_SYNC_GRID = "C0022";
|
||||
String KAFKA_TABLE_SYNC_GRID_POINT = "C0023";
|
||||
String KAFKA_TABLE_SYNC_DEPARTMENT = "C0030";
|
||||
/**
|
||||
* 专管员(角色)
|
||||
*/
|
||||
String KAFKA_TABLE_SYNC_SPECIALIZED_PERSON = "C0031";
|
||||
/**
|
||||
* 网格员(角色)
|
||||
*/
|
||||
String KAFKA_TABLE_SYNC_GRID_MEMBER = "C0032";
|
||||
|
||||
String KAFKA_DATA_SAVE = "save";
|
||||
String KAFKA_DATA_UPDATE = "update";
|
||||
|
@ -1,169 +0,0 @@
|
||||
package cn.com.tenlion.usercenter.kafka;
|
||||
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import ink.wgink.interfaces.map.*;
|
||||
import ink.wgink.interfaces.user.IUserUpdateAfterHandler;
|
||||
import ink.wgink.module.map.pojo.dtos.grid.GridDTO;
|
||||
import ink.wgink.module.map.service.grid.IGridPointService;
|
||||
import ink.wgink.module.map.service.grid.IGridRelationService;
|
||||
import ink.wgink.module.map.service.grid.IGridService;
|
||||
import ink.wgink.pojo.dtos.user.UserDTO;
|
||||
import ink.wgink.service.user.service.IUserService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: KafKaPublishConsumer
|
||||
* @Description: kafka消费者
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/12/23 10:06 AM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
public class KafKaPublishConsumer implements ApplicationEventPublisherAware {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(KafKaPublishConsumer.class);
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
@Autowired
|
||||
private IGridService gridService;
|
||||
@Autowired
|
||||
private IGridPointService gridPointService;
|
||||
@Autowired
|
||||
private IGridRelationService gridRelationService;
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
@Autowired
|
||||
private IGridSaveAfterHandler gridSaveAfterHandler;
|
||||
@Autowired
|
||||
private IGridDeleteAfterHandler gridDeleteAfterHandler;
|
||||
@Autowired
|
||||
private IGridUpdateAfterHandler gridUpdateAfterHandler;
|
||||
@Autowired
|
||||
private IGridPointSaveAfterHandler gridPointSaveAfterHandler;
|
||||
@Autowired
|
||||
private IGridPointDeleteAfterHandler gridPointDeleteAfterHandler;
|
||||
@Autowired
|
||||
private IGridRelationSaveAfterHandler gridRelationSaveAfterHandler;
|
||||
@Autowired
|
||||
private IGridRelationDeleteAfterHandler gridRelationDeleteAfterHandler;
|
||||
@Autowired
|
||||
private IUserUpdateAfterHandler userUpdateAfterHandler;
|
||||
|
||||
public KafKaPublishConsumer() {
|
||||
}
|
||||
|
||||
@KafkaListener(id="C0021", topics = "C0021")
|
||||
public void gridRelation(ConsumerRecord<?, ?> record) {
|
||||
String recordValue = record.value().toString();
|
||||
LOG.debug("Grid Relation(C0021) recordValue: {}", recordValue);
|
||||
SyncDataDTO<Map<String, Object>> syncDataDTO = getSyncData(recordValue);
|
||||
if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_SAVE)) {
|
||||
if (StringUtils.isBlank(syncDataDTO.getUid())) {
|
||||
LOG.error("Grid Relation(C0021) save error, uid is empty");
|
||||
return;
|
||||
}
|
||||
UserDTO userDTO = userService.get(syncDataDTO.getUid());
|
||||
if (userDTO == null) {
|
||||
LOG.error("Grid Relation(C0021) save error, userDTO is null");
|
||||
}
|
||||
gridRelationSaveAfterHandler.handle(userDTO);
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_UPDATE)) {
|
||||
if (StringUtils.isBlank(syncDataDTO.getUid())) {
|
||||
LOG.error("Grid Relation(C0021) update error, uid is empty");
|
||||
return;
|
||||
}
|
||||
userUpdateAfterHandler.handle(syncDataDTO.getUid());
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_DELETE)) {
|
||||
if (StringUtils.isBlank(syncDataDTO.getUid())) {
|
||||
LOG.error("Grid Relation(C0021) delete error, uid is empty");
|
||||
return;
|
||||
}
|
||||
gridRelationDeleteAfterHandler.handle(Arrays.asList(syncDataDTO.getUid().split("_")));
|
||||
}
|
||||
}
|
||||
|
||||
@KafkaListener(id="C0022", topics = "C0022")
|
||||
public void mapGrid(ConsumerRecord<?, ?> record) {
|
||||
String recordValue = record.value().toString();
|
||||
LOG.debug("Grid(C0022) recordValue: {}", recordValue);
|
||||
SyncDataDTO<Map<String, Object>> syncDataDTO = getSyncData(recordValue);
|
||||
if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_SAVE)) {
|
||||
String uid = syncDataDTO.getUid();
|
||||
if (StringUtils.isBlank(uid)) {
|
||||
LOG.error("Grid(C0022) save error, uid is empty");
|
||||
return;
|
||||
}
|
||||
GridDTO gridDTO = gridService.get(uid);
|
||||
if (gridDTO == null) {
|
||||
LOG.error("Grid(C0022) save error, uid is null");
|
||||
return;
|
||||
}
|
||||
gridSaveAfterHandler.handle(gridDTO.getGridId(), gridDTO.getGridCode(), gridDTO.getGridName(), gridDTO.getFillColor(), gridDTO.getAreaCode(), gridDTO.getAreaName());
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_UPDATE)) {
|
||||
String uid = syncDataDTO.getUid();
|
||||
if (StringUtils.isBlank(uid)) {
|
||||
LOG.error("Grid(C0022) update error, uid is empty");
|
||||
return;
|
||||
}
|
||||
GridDTO gridDTO = gridService.get(uid);
|
||||
if (gridDTO == null) {
|
||||
LOG.error("Grid(C0022) update error, grid is null");
|
||||
return;
|
||||
}
|
||||
gridUpdateAfterHandler.handle(gridDTO.getGridId(), gridDTO.getGridName(), gridDTO.getFillColor());
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_DELETE)) {
|
||||
String uid = syncDataDTO.getUid();
|
||||
if (StringUtils.isBlank(uid)) {
|
||||
LOG.error("Grid(C0022) delete error, uid is empty");
|
||||
return;
|
||||
}
|
||||
gridDeleteAfterHandler.handler(Arrays.asList(uid.split("_")));
|
||||
}
|
||||
}
|
||||
|
||||
@KafkaListener(id="C0023", topics = "C0023")
|
||||
public void mapGridPoint(ConsumerRecord<?, ?> record) {
|
||||
String recordValue = record.value().toString();
|
||||
LOG.debug("Grid Point(C0023) recordValue: {}", recordValue);
|
||||
SyncDataDTO<Map<String, Object>> syncDataDTO = getSyncData(recordValue);
|
||||
if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_SAVE)) {
|
||||
String gridId = String.valueOf(syncDataDTO.getData().get("grid_id"));
|
||||
if (StringUtils.isBlank(gridId)) {
|
||||
LOG.error("Grid Point(C0023) delete error, gridId is empty");
|
||||
return;
|
||||
}
|
||||
// 删除原有点
|
||||
gridPointDeleteAfterHandler.handle(Arrays.asList(gridId));
|
||||
// 保存新的点
|
||||
gridPointSaveAfterHandler.handle(gridId);
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_DELETE)) {
|
||||
String keyValue = syncDataDTO.getKeyValue();
|
||||
if (keyValue.isEmpty()) {
|
||||
LOG.error("Grid Point(C0023) delete error, keyValue is empty");
|
||||
return;
|
||||
}
|
||||
gridPointDeleteAfterHandler.handle(Arrays.asList(keyValue.split("_")));
|
||||
}
|
||||
}
|
||||
|
||||
private SyncDataDTO<Map<String, Object>> getSyncData(String msg) {
|
||||
return JSON.parseObject(msg, SyncDataDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
}
|
@ -0,0 +1,430 @@
|
||||
package cn.com.tenlion.usercenter.kafka;
|
||||
|
||||
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import ink.wgink.interfaces.department.IDepartmentDeleteAfterHandler;
|
||||
import ink.wgink.interfaces.department.IDepartmentSaveAfterHandler;
|
||||
import ink.wgink.interfaces.department.IDepartmentUpdateAfterHandler;
|
||||
import ink.wgink.interfaces.map.*;
|
||||
import ink.wgink.interfaces.role.IRoleUserDeleteAfterHandler;
|
||||
import ink.wgink.interfaces.role.IRoleUserSaveAfterHandler;
|
||||
import ink.wgink.interfaces.user.IUserUpdateAfterHandler;
|
||||
import ink.wgink.module.map.pojo.dtos.grid.GridDTO;
|
||||
import ink.wgink.module.map.pojo.dtos.grid.GridRelationDTO;
|
||||
import ink.wgink.module.map.service.grid.IGridPointService;
|
||||
import ink.wgink.module.map.service.grid.IGridRelationService;
|
||||
import ink.wgink.module.map.service.grid.IGridService;
|
||||
import ink.wgink.pojo.dtos.user.UserDTO;
|
||||
import ink.wgink.pojo.pos.DepartmentPO;
|
||||
import ink.wgink.service.department.service.IDepartmentService;
|
||||
import ink.wgink.service.role.service.IRoleUserService;
|
||||
import ink.wgink.service.user.service.IUserService;
|
||||
import ink.wgink.util.ArrayListUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: KafKaPublishConsumer
|
||||
* @Description: kafka表同步消费者
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/12/23 10:06 AM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
public class KafKaSyncTableConsumer implements ApplicationEventPublisherAware {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(KafKaSyncTableConsumer.class);
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
@Autowired
|
||||
private IGridService gridService;
|
||||
@Autowired
|
||||
private IGridPointService gridPointService;
|
||||
@Autowired
|
||||
private IGridRelationService gridRelationService;
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
@Autowired
|
||||
private IDepartmentService departmentService;
|
||||
@Autowired
|
||||
private IGridSaveAfterHandler gridSaveAfterHandler;
|
||||
@Autowired
|
||||
private IGridDeleteAfterHandler gridDeleteAfterHandler;
|
||||
@Autowired
|
||||
private IGridUpdateAfterHandler gridUpdateAfterHandler;
|
||||
@Autowired
|
||||
private IGridPointSaveAfterHandler gridPointSaveAfterHandler;
|
||||
@Autowired
|
||||
private IGridPointDeleteAfterHandler gridPointDeleteAfterHandler;
|
||||
@Autowired
|
||||
private IGridRelationSaveAfterHandler gridRelationSaveAfterHandler;
|
||||
@Autowired
|
||||
private IGridRelationDeleteAfterHandler gridRelationDeleteAfterHandler;
|
||||
@Autowired
|
||||
private IUserUpdateAfterHandler userUpdateAfterHandler;
|
||||
@Autowired
|
||||
private IDepartmentSaveAfterHandler departmentSaveAfterHandler;
|
||||
@Autowired
|
||||
private IDepartmentUpdateAfterHandler departmentUpdateAfterHandler;
|
||||
@Autowired
|
||||
private IDepartmentDeleteAfterHandler departmentDeleteAfterHandler;
|
||||
@Autowired
|
||||
private IRoleUserSaveAfterHandler roleUserSaveAfterHandler;
|
||||
@Autowired
|
||||
private IRoleUserDeleteAfterHandler roleUserDeleteAfterHandler;
|
||||
@Autowired
|
||||
private IRoleUserService roleUserService;
|
||||
@Autowired
|
||||
private ParamsConfigProperties paramsConfigProperties;
|
||||
|
||||
|
||||
public KafKaSyncTableConsumer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 网格关系
|
||||
*
|
||||
* @param record
|
||||
*/
|
||||
@KafkaListener(id = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_RELATION, topics = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_RELATION)
|
||||
public void gridRelation(ConsumerRecord<?, ?> record) {
|
||||
String recordValue = record.value().toString();
|
||||
LOG.debug("Grid Relation(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_RELATION + ") recordValue: {}", recordValue);
|
||||
SyncDataDTO<Map<String, Object>> syncDataDTO = getSyncData(recordValue);
|
||||
if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_SAVE)) {
|
||||
if (StringUtils.isBlank(syncDataDTO.getUid())) {
|
||||
LOG.error("Grid Relation(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_RELATION + ") save error, uid is empty");
|
||||
return;
|
||||
}
|
||||
UserDTO userDTO = userService.get(syncDataDTO.getUid());
|
||||
if (userDTO == null) {
|
||||
LOG.error("Grid Relation(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_RELATION + ") save error, userDTO is null");
|
||||
}
|
||||
gridRelationSaveAfterHandler.handle(userDTO);
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_UPDATE)) {
|
||||
if (StringUtils.isBlank(syncDataDTO.getUid())) {
|
||||
LOG.error("Grid Relation(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_RELATION + ") update error, uid is empty");
|
||||
return;
|
||||
}
|
||||
userUpdateAfterHandler.handle(syncDataDTO.getUid());
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_DELETE)) {
|
||||
if (StringUtils.isBlank(syncDataDTO.getUid())) {
|
||||
LOG.error("Grid Relation(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_RELATION + ") delete error, uid is empty");
|
||||
return;
|
||||
}
|
||||
gridRelationDeleteAfterHandler.handle(Arrays.asList(syncDataDTO.getUid().split("_")));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 网格关系全量
|
||||
*
|
||||
* @param record
|
||||
*/
|
||||
@KafkaListener(id = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_RELATION + "FullSync", topics = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_RELATION + "FullSync")
|
||||
public void gridRelationFullSync(ConsumerRecord<?, ?> record) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
List<GridRelationDTO> gridRelationDTOs = gridRelationService.list(params);
|
||||
if (gridRelationDTOs.isEmpty()) {
|
||||
LOG.error("Grid Relation Full Sync(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_RELATION + "FullSync) error, gridRelationDTOs is empty");
|
||||
return;
|
||||
}
|
||||
List<String> relationIds = ArrayListUtil.listBeanStringIdValue(gridRelationDTOs, "relationId", GridRelationDTO.class);
|
||||
gridRelationSaveAfterHandler.handle(relationIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 网格
|
||||
*
|
||||
* @param record
|
||||
*/
|
||||
@KafkaListener(id = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID, topics = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID)
|
||||
public void mapGrid(ConsumerRecord<?, ?> record) {
|
||||
String recordValue = record.value().toString();
|
||||
LOG.debug("Grid(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID + ") recordValue: {}", recordValue);
|
||||
SyncDataDTO<Map<String, Object>> syncDataDTO = getSyncData(recordValue);
|
||||
if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_SAVE)) {
|
||||
String uid = syncDataDTO.getUid();
|
||||
if (StringUtils.isBlank(uid)) {
|
||||
LOG.error("Grid(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID + ") save error, uid is empty");
|
||||
return;
|
||||
}
|
||||
GridDTO gridDTO = gridService.get(uid);
|
||||
if (gridDTO == null) {
|
||||
LOG.error("Grid(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID + ") save error, uid is null");
|
||||
return;
|
||||
}
|
||||
gridSaveAfterHandler.handle(gridDTO.getGridId(), gridDTO.getGridCode(), gridDTO.getGridName(), gridDTO.getFillColor(), gridDTO.getAreaCode(), gridDTO.getAreaName());
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_UPDATE)) {
|
||||
String uid = syncDataDTO.getUid();
|
||||
if (StringUtils.isBlank(uid)) {
|
||||
LOG.error("Grid(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID + ") update error, uid is empty");
|
||||
return;
|
||||
}
|
||||
GridDTO gridDTO = gridService.get(uid);
|
||||
if (gridDTO == null) {
|
||||
LOG.error("Grid(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID + ") update error, grid is null");
|
||||
return;
|
||||
}
|
||||
gridUpdateAfterHandler.handle(gridDTO.getGridId(), gridDTO.getGridName(), gridDTO.getFillColor());
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_DELETE)) {
|
||||
String uid = syncDataDTO.getUid();
|
||||
if (StringUtils.isBlank(uid)) {
|
||||
LOG.error("Grid(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID + ") delete error, uid is empty");
|
||||
return;
|
||||
}
|
||||
gridDeleteAfterHandler.handler(Arrays.asList(uid.split("_")));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 网格全量
|
||||
*
|
||||
* @param record
|
||||
*/
|
||||
@KafkaListener(id = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID + "FullSync", topics = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID + "FullSync")
|
||||
public void mapGridFullSync(ConsumerRecord<?, ?> record) {
|
||||
Map<String, Object> params = new HashMap<>(0);
|
||||
List<GridDTO> gridDTOs = gridService.list(params);
|
||||
if (gridDTOs.isEmpty()) {
|
||||
LOG.error("Grid Full Sync(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID + "FullSync) error, gridDTOs is empty");
|
||||
return;
|
||||
}
|
||||
gridDTOs.forEach(gridDTO -> {
|
||||
gridSaveAfterHandler.handle(gridDTO.getGridId(), gridDTO.getGridCode(), gridDTO.getGridName(), gridDTO.getFillColor(), gridDTO.getAreaCode(), gridDTO.getAreaName());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 网格点
|
||||
*
|
||||
* @param record
|
||||
*/
|
||||
@KafkaListener(id = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_POINT, topics = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_POINT)
|
||||
public void mapGridPoint(ConsumerRecord<?, ?> record) {
|
||||
String recordValue = record.value().toString();
|
||||
LOG.debug("Grid Point(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_POINT + ") recordValue: {}", recordValue);
|
||||
SyncDataDTO<Map<String, Object>> syncDataDTO = getSyncData(recordValue);
|
||||
if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_SAVE)) {
|
||||
String gridId = String.valueOf(syncDataDTO.getData().get("grid_id"));
|
||||
if (StringUtils.isBlank(gridId)) {
|
||||
LOG.error("Grid Point(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_POINT + ") delete error, gridId is empty");
|
||||
return;
|
||||
}
|
||||
// 删除原有点
|
||||
gridPointDeleteAfterHandler.handle(Arrays.asList(gridId));
|
||||
// 保存新的点
|
||||
gridPointSaveAfterHandler.handle(gridId);
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_DELETE)) {
|
||||
String keyValue = syncDataDTO.getKeyValue();
|
||||
if (keyValue.isEmpty()) {
|
||||
LOG.error("Grid Point(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_POINT + ") delete error, keyValue is empty");
|
||||
return;
|
||||
}
|
||||
gridPointDeleteAfterHandler.handle(Arrays.asList(keyValue.split("_")));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 网格点全量
|
||||
*
|
||||
* @param record
|
||||
*/
|
||||
@KafkaListener(id = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_POINT + "FullSync", topics = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_POINT + "FullSync")
|
||||
public void mapGridPointFullSync(ConsumerRecord<?, ?> record) {
|
||||
Map<String, Object> params = new HashMap<>(0);
|
||||
List<GridDTO> gridDTOs = gridService.list(params);
|
||||
if (gridDTOs.isEmpty()) {
|
||||
LOG.error("Grid Point Full Sync(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_POINT + "FullSync) error, gridDTOs is empty");
|
||||
return;
|
||||
}
|
||||
gridDTOs.forEach(gridDTO -> {
|
||||
gridPointSaveAfterHandler.handle(gridDTO.getGridId());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 专管机构
|
||||
*
|
||||
* @param record
|
||||
*/
|
||||
@KafkaListener(id = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT, topics = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT)
|
||||
public void department(ConsumerRecord<?, ?> record) {
|
||||
String recordValue = record.value().toString();
|
||||
LOG.debug("Department(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT + ") recordValue: {}", recordValue);
|
||||
SyncDataDTO<Map<String, Object>> syncDataDTO = getSyncData(recordValue);
|
||||
if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_SAVE)) {
|
||||
String departmentId = String.valueOf(syncDataDTO.getUid());
|
||||
if (StringUtils.isBlank(departmentId)) {
|
||||
LOG.error("Department(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT + ") save error, uid is empty");
|
||||
return;
|
||||
}
|
||||
DepartmentPO departmentPO = departmentService.getPO(departmentId);
|
||||
if (departmentPO == null) {
|
||||
LOG.debug("Department(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT + ") save error, department is null");
|
||||
return;
|
||||
}
|
||||
departmentSaveAfterHandler.handle(departmentPO.getDepartmentId(),
|
||||
departmentPO.getDepartmentParentId(),
|
||||
departmentPO.getDepartmentName(),
|
||||
departmentPO.getDepartmentCode(),
|
||||
departmentPO.getDepartmentType(),
|
||||
departmentPO.getDepartmentAreaCode(),
|
||||
departmentPO.getDepartmentAreaName());
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_UPDATE)) {
|
||||
String departmentId = String.valueOf(syncDataDTO.getUid());
|
||||
if (StringUtils.isBlank(departmentId)) {
|
||||
LOG.error("Department(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT + ") update error, uid is empty");
|
||||
return;
|
||||
}
|
||||
DepartmentPO departmentPO = departmentService.getPO(departmentId);
|
||||
if (departmentPO == null) {
|
||||
LOG.debug("Department(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT + ") update error, department is null");
|
||||
return;
|
||||
}
|
||||
departmentUpdateAfterHandler.handle(departmentPO.getDepartmentId(),
|
||||
departmentPO.getDepartmentParentId(),
|
||||
departmentPO.getDepartmentName(),
|
||||
departmentPO.getDepartmentType(),
|
||||
departmentPO.getDepartmentAreaCode(),
|
||||
departmentPO.getDepartmentAreaName());
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_DELETE)) {
|
||||
String uid = syncDataDTO.getUid();
|
||||
if (uid.isEmpty()) {
|
||||
LOG.error("Department(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT + ") delete error, keyValue is empty");
|
||||
return;
|
||||
}
|
||||
departmentDeleteAfterHandler.handle(Arrays.asList(uid.split("_")));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 专管机构
|
||||
*
|
||||
* @param record
|
||||
*/
|
||||
@KafkaListener(id = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT + "FullSync", topics = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT + "FullSync")
|
||||
public void departmentFullSync(ConsumerRecord<?, ?> record) {
|
||||
List<DepartmentPO> departmentPOs = departmentService.listPO(new HashMap<>(0));
|
||||
if (departmentPOs.isEmpty()) {
|
||||
LOG.error("Department Full Sync(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT + "FullSync) error, departmentPOs is empty");
|
||||
return;
|
||||
}
|
||||
departmentPOs.forEach(departmentPO -> {
|
||||
departmentSaveAfterHandler.handle(departmentPO.getDepartmentId(),
|
||||
departmentPO.getDepartmentParentId(),
|
||||
departmentPO.getDepartmentName(),
|
||||
departmentPO.getDepartmentCode(),
|
||||
departmentPO.getDepartmentType(),
|
||||
departmentPO.getDepartmentAreaCode(),
|
||||
departmentPO.getDepartmentAreaName());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 专管员
|
||||
*
|
||||
* @param record
|
||||
*/
|
||||
@KafkaListener(id = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_SPECIALIZED_PERSON, topics = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_SPECIALIZED_PERSON)
|
||||
public void specializedPerson(ConsumerRecord<?, ?> record) {
|
||||
String recordValue = record.value().toString();
|
||||
LOG.debug("Specialized person(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_SPECIALIZED_PERSON + ") recordValue: {}", recordValue);
|
||||
SyncDataDTO<Map<String, Object>> syncDataDTO = getSyncData(recordValue);
|
||||
if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_SAVE)) {
|
||||
List<String> userIds = roleUserService.listUserId(paramsConfigProperties.getRoleSpecializedPerson());
|
||||
if (userIds.isEmpty()) {
|
||||
LOG.error("Specialized Person Full Sync(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_SPECIALIZED_PERSON + "FullSync) error, userIds is empty");
|
||||
return;
|
||||
}
|
||||
roleUserSaveAfterHandler.handle(paramsConfigProperties.getRoleSpecializedPerson(), userIds);
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_DELETE)) {
|
||||
String uid = syncDataDTO.getUid();
|
||||
if (uid.isEmpty()) {
|
||||
LOG.error("Specialized person(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_SPECIALIZED_PERSON + ") delete error, keyValue is empty");
|
||||
return;
|
||||
}
|
||||
roleUserDeleteAfterHandler.handle(paramsConfigProperties.getRoleSpecializedPerson(), Arrays.asList(uid.split("\\_")));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 专管员全量
|
||||
*
|
||||
* @param record
|
||||
*/
|
||||
@KafkaListener(id = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_SPECIALIZED_PERSON + "FullSync", topics = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_SPECIALIZED_PERSON + "FullSync")
|
||||
public void specializedPersonFullSync(ConsumerRecord<?, ?> record) {
|
||||
List<String> userIds = roleUserService.listUserId(paramsConfigProperties.getRoleSpecializedPerson());
|
||||
if (userIds.isEmpty()) {
|
||||
LOG.error("Specialized Person Full Sync(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_SPECIALIZED_PERSON + "FullSync) error, userIds is empty");
|
||||
return;
|
||||
}
|
||||
roleUserSaveAfterHandler.handle(paramsConfigProperties.getRoleSpecializedPerson(), userIds);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 专管员
|
||||
*
|
||||
* @param record
|
||||
*/
|
||||
@KafkaListener(id = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_MEMBER, topics = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_MEMBER)
|
||||
public void gridMember(ConsumerRecord<?, ?> record) {
|
||||
String recordValue = record.value().toString();
|
||||
LOG.debug("Specialized person(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_MEMBER + ") recordValue: {}", recordValue);
|
||||
SyncDataDTO<Map<String, Object>> syncDataDTO = getSyncData(recordValue);
|
||||
if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_SAVE)) {
|
||||
List<String> userIds = roleUserService.listUserId(paramsConfigProperties.getRoleSpecializedPerson());
|
||||
if (userIds.isEmpty()) {
|
||||
LOG.error("Grid Member Full Sync(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_MEMBER + ") error, userIds is empty");
|
||||
return;
|
||||
}
|
||||
roleUserSaveAfterHandler.handle(paramsConfigProperties.getRoleSpecializedPerson(), userIds);
|
||||
} else if (StringUtils.equals(syncDataDTO.getAction(), ISmartCityUserCenterConsts.KAFKA_DATA_DELETE)) {
|
||||
String uid = syncDataDTO.getUid();
|
||||
if (uid.isEmpty()) {
|
||||
LOG.error("Grid Member(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_MEMBER + ") delete error, keyValue is empty");
|
||||
return;
|
||||
}
|
||||
roleUserDeleteAfterHandler.handle(paramsConfigProperties.getRoleSpecializedPerson(), Arrays.asList(uid.split("\\_")));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 专管员全量
|
||||
*
|
||||
* @param record
|
||||
*/
|
||||
@KafkaListener(id = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_MEMBER + "FullSync", topics = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_MEMBER + "FullSync")
|
||||
public void gridMemberFullSync(ConsumerRecord<?, ?> record) {
|
||||
List<String> userIds = roleUserService.listUserId(paramsConfigProperties.getRoleSpecializedPerson());
|
||||
if (userIds.isEmpty()) {
|
||||
LOG.error("Grid Member Full Sync(" + ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_MEMBER + "FullSync) error, userIds is empty");
|
||||
return;
|
||||
}
|
||||
roleUserSaveAfterHandler.handle(paramsConfigProperties.getRoleGridMember(), userIds);
|
||||
}
|
||||
|
||||
private SyncDataDTO<Map<String, Object>> getSyncData(String msg) {
|
||||
return JSON.parseObject(msg, SyncDataDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package cn.com.tenlion.usercenter.service.kafka.impl;
|
||||
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.department.IDepartmentDeleteAfterHandler;
|
||||
import ink.wgink.util.string.WStringUtil;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @ClassName: DepartmentDeleteAfterHandlerImpl
|
||||
* @Description: 部门删除后操作
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/1/26 3:38 PM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class DepartmentDeleteAfterHandlerImpl implements IDepartmentDeleteAfterHandler {
|
||||
|
||||
@Autowired
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
|
||||
@Override
|
||||
public void handle(List<String> departmentIds) throws SystemException {
|
||||
if (departmentIds == null || departmentIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
SyncDataDTO<Map> syncDataDTO = new SyncDataDTO<>();
|
||||
syncDataDTO.setUid(WStringUtil.listToStr(departmentIds, "_"));
|
||||
syncDataDTO.setAction(ISmartCityUserCenterConsts.KAFKA_DATA_DELETE);
|
||||
syncDataDTO.setData(new HashMap());
|
||||
syncDataDTO.setTableNumber(ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT);
|
||||
kafkaTemplate.send(ISmartCityUserCenterConsts.KAFKA_TOPIC_TABLE_SYNC, JSONObject.toJSONString(syncDataDTO));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package cn.com.tenlion.usercenter.service.kafka.impl;
|
||||
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.department.IDepartmentSaveAfterHandler;
|
||||
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: DepartmentSaveAfterHandlerImpl
|
||||
* @Description: 部门用户新增后操作
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/1/26 3:37 PM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class DepartmentSaveAfterHandlerImpl implements IDepartmentSaveAfterHandler {
|
||||
|
||||
@Autowired
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
|
||||
@Override
|
||||
public void handle(String departmentId, String departmentParentId, String departmentName, String departmentCode, Integer departmentType, String departmentAreaCode, String departmentAreaName) throws SystemException {
|
||||
if (StringUtils.isBlank(departmentId)) {
|
||||
return;
|
||||
}
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put("code", departmentCode);
|
||||
dataMap.put("parent_id", departmentParentId);
|
||||
dataMap.put("type", departmentType == 1 ? "机构" : departmentType == 2 ? "部门" : "错误");
|
||||
dataMap.put("name", departmentName);
|
||||
if (!StringUtils.isBlank(departmentAreaCode)) {
|
||||
dataMap.put("area_code", departmentAreaCode);
|
||||
dataMap.put("area_name_all", departmentAreaName);
|
||||
String[] areaNameArray = departmentAreaName.split("\\/");
|
||||
dataMap.put("area_name", areaNameArray.length > 0 ? areaNameArray[areaNameArray.length - 1] : areaNameArray[0]);
|
||||
} else {
|
||||
dataMap.put("area_code", "");
|
||||
dataMap.put("area_name_all", "");
|
||||
dataMap.put("area_name", "");
|
||||
}
|
||||
SyncDataDTO<Map> syncDataDTO = new SyncDataDTO<>();
|
||||
syncDataDTO.setUid(departmentId);
|
||||
syncDataDTO.setAction(ISmartCityUserCenterConsts.KAFKA_DATA_SAVE);
|
||||
syncDataDTO.setData(dataMap);
|
||||
syncDataDTO.setTableNumber(ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT);
|
||||
kafkaTemplate.send(ISmartCityUserCenterConsts.KAFKA_TOPIC_TABLE_SYNC, JSONObject.toJSONString(syncDataDTO));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package cn.com.tenlion.usercenter.service.kafka.impl;
|
||||
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.department.IDepartmentUpdateAfterHandler;
|
||||
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: DepartmentUpdateAfterHandlerImpl
|
||||
* @Description: 部门修改后操作
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/1/26 3:37 PM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class DepartmentUpdateAfterHandlerImpl implements IDepartmentUpdateAfterHandler {
|
||||
|
||||
@Autowired
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
|
||||
@Override
|
||||
public void handle(String departmentId,
|
||||
String departmentParentId,
|
||||
String departmentName,
|
||||
Integer departmentType,
|
||||
String departmentAreaCode,
|
||||
String departmentAreaName) throws SystemException {
|
||||
if (StringUtils.isBlank(departmentId)) {
|
||||
return;
|
||||
}
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put("parent_id", departmentParentId);
|
||||
dataMap.put("type", departmentType == 1 ? "机构" : departmentType == 2 ? "部门" : "错误");
|
||||
dataMap.put("name", departmentName);
|
||||
if (!StringUtils.isBlank(departmentAreaCode)) {
|
||||
dataMap.put("area_code", departmentAreaCode);
|
||||
dataMap.put("area_name_all", departmentAreaName);
|
||||
String[] areaNameArray = departmentAreaName.split("\\/");
|
||||
dataMap.put("area_name", areaNameArray.length > 0 ? areaNameArray[areaNameArray.length - 1] : areaNameArray[0]);
|
||||
} else {
|
||||
dataMap.put("area_code", "");
|
||||
dataMap.put("area_name_all", "");
|
||||
dataMap.put("area_name", "");
|
||||
}
|
||||
SyncDataDTO<Map> syncDataDTO = new SyncDataDTO<>();
|
||||
syncDataDTO.setUid(departmentId);
|
||||
syncDataDTO.setAction(ISmartCityUserCenterConsts.KAFKA_DATA_UPDATE);
|
||||
syncDataDTO.setData(dataMap);
|
||||
syncDataDTO.setTableNumber(ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_DEPARTMENT);
|
||||
kafkaTemplate.send(ISmartCityUserCenterConsts.KAFKA_TOPIC_TABLE_SYNC, JSONObject.toJSONString(syncDataDTO));
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package cn.com.tenlion.usercenter.service.grid.impl;
|
||||
package cn.com.tenlion.usercenter.service.kafka.impl;
|
||||
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.map.IGridDeleteAfterHandler;
|
||||
import ink.wgink.util.string.WStringUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -30,7 +31,7 @@ public class GridDeleteAfterHandlerImpl implements IGridDeleteAfterHandler {
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
|
||||
@Override
|
||||
public void handler(List<String> gridIds) {
|
||||
public void handler(List<String> gridIds) throws SystemException {
|
||||
if (gridIds.isEmpty()) {
|
||||
return;
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package cn.com.tenlion.usercenter.service.grid.impl;
|
||||
package cn.com.tenlion.usercenter.service.kafka.impl;
|
||||
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.map.IGridPointDeleteAfterHandler;
|
||||
import ink.wgink.util.string.WStringUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -26,8 +27,8 @@ public class GridPointDeleteAfterHandlerImpl implements IGridPointDeleteAfterHan
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
|
||||
@Override
|
||||
public void handle(List<String> gridIds) {
|
||||
if (gridIds.isEmpty()) {
|
||||
public void handle(List<String> gridIds) throws SystemException {
|
||||
if (gridIds == null || gridIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
SyncDataDTO<Map> syncDataDTO = new SyncDataDTO<>();
|
@ -1,8 +1,9 @@
|
||||
package cn.com.tenlion.usercenter.service.grid.impl;
|
||||
package cn.com.tenlion.usercenter.service.kafka.impl;
|
||||
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.map.IGridPointSaveAfterHandler;
|
||||
import ink.wgink.module.map.pojo.dtos.grid.GridPointDTO;
|
||||
import ink.wgink.module.map.service.grid.IGridPointService;
|
||||
@ -32,7 +33,7 @@ public class GridPointSaveAfterHandlerImpl implements IGridPointSaveAfterHandler
|
||||
private IGridPointService gridPointService;
|
||||
|
||||
@Override
|
||||
public void handle(String gridId) {
|
||||
public void handle(String gridId) throws SystemException {
|
||||
if (StringUtils.isBlank(gridId)) {
|
||||
return;
|
||||
}
|
@ -1,14 +1,16 @@
|
||||
package cn.com.tenlion.usercenter.service.grid.impl;
|
||||
package cn.com.tenlion.usercenter.service.kafka.impl;
|
||||
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.map.IGridRelationDeleteAfterHandler;
|
||||
import ink.wgink.util.string.WStringUtil;
|
||||
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;
|
||||
|
||||
@ -26,14 +28,19 @@ public class GridRelationDeleteAfterHandlerImpl implements IGridRelationDeleteAf
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
|
||||
@Override
|
||||
public void handle(List<String> relationIds) {
|
||||
public void handle(List<String> relationIds) throws SystemException {
|
||||
if (relationIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("grid_code", "");
|
||||
data.put("grid_name", "");
|
||||
|
||||
SyncDataDTO<Map> syncDataDTO = new SyncDataDTO<>();
|
||||
syncDataDTO.setUid(WStringUtil.listToStr(relationIds, "_"));
|
||||
syncDataDTO.setAction(ISmartCityUserCenterConsts.KAFKA_DATA_DELETE);
|
||||
syncDataDTO.setTableNumber(ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_MEMBER);
|
||||
syncDataDTO.setData(data);
|
||||
syncDataDTO.setAction(ISmartCityUserCenterConsts.KAFKA_DATA_UPDATE);
|
||||
syncDataDTO.setTableNumber(ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_RELATION);
|
||||
kafkaTemplate.send(ISmartCityUserCenterConsts.KAFKA_TOPIC_TABLE_SYNC, JSONObject.toJSONString(syncDataDTO));
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package cn.com.tenlion.usercenter.service.grid.impl;
|
||||
package cn.com.tenlion.usercenter.service.kafka.impl;
|
||||
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.map.IGridRelationSaveAfterHandler;
|
||||
import ink.wgink.module.map.pojo.dtos.grid.GridDTO;
|
||||
import ink.wgink.module.map.service.grid.IGridService;
|
||||
@ -36,7 +37,7 @@ public class GridRelationSaveAfterHandlerImpl implements IGridRelationSaveAfterH
|
||||
private IGridService gridService;
|
||||
|
||||
@Override
|
||||
public void handle(List<String> relationIds) {
|
||||
public void handle(List<String> relationIds) throws SystemException {
|
||||
if (relationIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@ -51,37 +52,28 @@ public class GridRelationSaveAfterHandlerImpl implements IGridRelationSaveAfterH
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(UserDTO userDTO) {
|
||||
public void handle(UserDTO userDTO) throws SystemException {
|
||||
List<GridDTO> gridDTOs = gridService.listByRelationId(userDTO.getUserId());
|
||||
if (gridDTOs.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<String> areaNames = new ArrayList<>();
|
||||
List<String> areaCodes = new ArrayList<>();
|
||||
List<String> gridCodes = new ArrayList<>();
|
||||
List<String> gridNames = new ArrayList<>();
|
||||
|
||||
gridDTOs.forEach(gridDTO -> {
|
||||
areaNames.add(gridDTO.getAreaName());
|
||||
areaCodes.add(gridDTO.getAreaCode());
|
||||
gridCodes.add(gridDTO.getGridCode());
|
||||
gridNames.add(gridDTO.getGridCode());
|
||||
});
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("user_name", userDTO.getUserName());
|
||||
data.put("user_phone", userDTO.getUserUsername());
|
||||
data.put("user_avatar", userDTO.getUserAvatar());
|
||||
data.put("area_name", WStringUtil.listToStr(areaNames, ","));
|
||||
data.put("area_code", WStringUtil.listToStr(areaCodes, ","));
|
||||
data.put("grid_code", WStringUtil.listToStr(gridCodes, ","));
|
||||
data.put("grid_name", WStringUtil.listToStr(gridNames, ","));
|
||||
|
||||
SyncDataDTO<Map> syncDataDTO = new SyncDataDTO<>();
|
||||
syncDataDTO.setUid(userDTO.getUserId());
|
||||
syncDataDTO.setData(data);
|
||||
syncDataDTO.setAction(ISmartCityUserCenterConsts.KAFKA_DATA_SAVE);
|
||||
syncDataDTO.setTableNumber(ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_MEMBER);
|
||||
syncDataDTO.setAction(ISmartCityUserCenterConsts.KAFKA_DATA_UPDATE);
|
||||
syncDataDTO.setTableNumber(ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_RELATION);
|
||||
kafkaTemplate.send(ISmartCityUserCenterConsts.KAFKA_TOPIC_TABLE_SYNC, JSONObject.toJSONString(syncDataDTO));
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package cn.com.tenlion.usercenter.service.grid.impl;
|
||||
package cn.com.tenlion.usercenter.service.kafka.impl;
|
||||
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.map.IGridSaveAfterHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -26,7 +27,7 @@ public class GridSaveAfterHandlerImpl implements IGridSaveAfterHandler {
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
|
||||
@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) throws SystemException {
|
||||
if (StringUtils.isBlank(gridId)) {
|
||||
return;
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package cn.com.tenlion.usercenter.service.grid.impl;
|
||||
package cn.com.tenlion.usercenter.service.kafka.impl;
|
||||
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.map.IGridUpdateAfterHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -29,7 +30,7 @@ public class GridUpdateAfterHandlerImpl implements IGridUpdateAfterHandler {
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
|
||||
@Override
|
||||
public void handle(String gridId, String gridName, String fillColor) {
|
||||
public void handle(String gridId, String gridName, String fillColor) throws SystemException {
|
||||
if (StringUtils.isBlank(gridId)) {
|
||||
return;
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package cn.com.tenlion.usercenter.service.kafka.impl;
|
||||
|
||||
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.role.IRoleUserDeleteAfterHandler;
|
||||
import ink.wgink.util.string.WStringUtil;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: RoleUserDeleteAfterHandlerImpl
|
||||
* @Description: 角色用户删除后操作
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/1/26 3:41 PM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class RoleUserDeleteAfterHandlerImpl implements IRoleUserDeleteAfterHandler {
|
||||
|
||||
@Autowired
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
@Autowired
|
||||
private ParamsConfigProperties paramsConfigProperties;
|
||||
|
||||
@Override
|
||||
public void handle(String roleId, List<String> userIds) throws SystemException {
|
||||
if (StringUtils.isBlank(roleId)) {
|
||||
return;
|
||||
}
|
||||
if (userIds == null || userIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String tableNumber;
|
||||
if (StringUtils.equals(paramsConfigProperties.getRoleSpecializedPerson(), roleId)) {
|
||||
// 专管员
|
||||
tableNumber = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_SPECIALIZED_PERSON;
|
||||
} else if (StringUtils.equals(paramsConfigProperties.getRoleGridMember(), roleId)) {
|
||||
// 网格员
|
||||
tableNumber = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_MEMBER;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
SyncDataDTO<Map> syncDataDTO = new SyncDataDTO<>();
|
||||
syncDataDTO.setAction(ISmartCityUserCenterConsts.KAFKA_DATA_DELETE);
|
||||
syncDataDTO.setTableNumber(tableNumber);
|
||||
syncDataDTO.setUid(WStringUtil.listToStr(userIds, "_"));
|
||||
kafkaTemplate.send(ISmartCityUserCenterConsts.KAFKA_TOPIC_TABLE_SYNC, JSONObject.toJSONString(syncDataDTO));
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package cn.com.tenlion.usercenter.service.kafka.impl;
|
||||
|
||||
import cn.com.tenlion.usercenter.config.ParamsConfigProperties;
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.userexpand.UserExpandDTO;
|
||||
import cn.com.tenlion.usercenter.service.userexpand.IUserExpandService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.role.IRoleUserSaveAfterHandler;
|
||||
import ink.wgink.service.role.service.IRoleUserService;
|
||||
import ink.wgink.service.user.service.IUserService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @ClassName: RoleUserSaveAfterHandlerImpl
|
||||
* @Description: 角色用户新增后操作
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/1/26 3:41 PM
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class RoleUserSaveAfterHandlerImpl implements IRoleUserSaveAfterHandler {
|
||||
|
||||
@Autowired
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
@Autowired
|
||||
private IRoleUserService roleUserService;
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
@Autowired
|
||||
private IUserExpandService userExpandService;
|
||||
@Autowired
|
||||
private ParamsConfigProperties paramsConfigProperties;
|
||||
|
||||
@Override
|
||||
public void handle(String roleId, List<String> userIds) throws SystemException {
|
||||
if (StringUtils.isBlank(roleId)) {
|
||||
return;
|
||||
}
|
||||
if (userIds == null || userIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String tableNumber;
|
||||
if (StringUtils.equals(paramsConfigProperties.getRoleSpecializedPerson(), roleId)) {
|
||||
// 专管员
|
||||
tableNumber = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_SPECIALIZED_PERSON;
|
||||
} else if (StringUtils.equals(paramsConfigProperties.getRoleGridMember(), roleId)) {
|
||||
// 网格员
|
||||
tableNumber = ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_MEMBER;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> roleUserIds = roleUserService.listUserIdByRoleIdAndUserIds(roleId, userIds);
|
||||
if (roleUserIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<UserExpandDTO> userExpandDTOs = userExpandService.listByUserIds(roleUserIds);
|
||||
SyncDataDTO<Map> syncDataDTO = new SyncDataDTO<>();
|
||||
syncDataDTO.setAction(ISmartCityUserCenterConsts.KAFKA_DATA_SAVE);
|
||||
syncDataDTO.setTableNumber(tableNumber);
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
for (UserExpandDTO userExpandDTO : userExpandDTOs) {
|
||||
syncDataDTO.setUid(userExpandDTO.getUserId());
|
||||
dataMap.put("user_name", userExpandDTO.getUserName());
|
||||
dataMap.put("user_username", userExpandDTO.getUserUsername());
|
||||
dataMap.put("user_phone", userExpandDTO.getUserPhone());
|
||||
dataMap.put("user_avatar", userExpandDTO.getUserAvatar());
|
||||
dataMap.put("area_name", userExpandDTO.getAreaName());
|
||||
dataMap.put("area_code", userExpandDTO.getAreaCode());
|
||||
syncDataDTO.setData(dataMap);
|
||||
kafkaTemplate.send(ISmartCityUserCenterConsts.KAFKA_TOPIC_TABLE_SYNC, JSONObject.toJSONString(syncDataDTO));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package cn.com.tenlion.usercenter.service.grid.impl;
|
||||
package cn.com.tenlion.usercenter.service.kafka.impl;
|
||||
|
||||
import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts;
|
||||
import cn.com.tenlion.usercenter.pojo.dtos.kafka.SyncDataDTO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.exceptions.base.SystemException;
|
||||
import ink.wgink.interfaces.user.IUserUpdateAfterHandler;
|
||||
import ink.wgink.pojo.dtos.user.UserDTO;
|
||||
import ink.wgink.service.user.service.IUserService;
|
||||
@ -30,7 +31,7 @@ public class UserUpdateAfterHandlerImpl implements IUserUpdateAfterHandler {
|
||||
private IUserService userService;
|
||||
|
||||
@Override
|
||||
public void handle(String userId) {
|
||||
public void handle(String userId) throws SystemException {
|
||||
if (StringUtils.isBlank(userId)) {
|
||||
return;
|
||||
}
|
||||
@ -44,7 +45,7 @@ public class UserUpdateAfterHandlerImpl implements IUserUpdateAfterHandler {
|
||||
syncDataDTO.setUid(userDTO.getUserId());
|
||||
syncDataDTO.setData(data);
|
||||
syncDataDTO.setAction(ISmartCityUserCenterConsts.KAFKA_DATA_UPDATE);
|
||||
syncDataDTO.setTableNumber(ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_MEMBER);
|
||||
syncDataDTO.setTableNumber(ISmartCityUserCenterConsts.KAFKA_TABLE_SYNC_GRID_RELATION);
|
||||
kafkaTemplate.send(ISmartCityUserCenterConsts.KAFKA_TOPIC_TABLE_SYNC, JSONObject.toJSONString(syncDataDTO));
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ spring:
|
||||
max-idle: 8
|
||||
min-idle: 0
|
||||
kafka:
|
||||
bootstrap-servers: localhost:9092
|
||||
bootstrap-servers: 127.0.0.1:9092
|
||||
producer:
|
||||
# 写入失败时,重试次数。当leader节点失效,一个repli节点会替代成为leader节点,此时可能出现写入失败,
|
||||
# 当retris为0时,produce不会重复。retirs重发,此时repli节点完全成为leader节点,不会产生消息丢失。
|
||||
@ -156,3 +156,9 @@ logging:
|
||||
org.springframework.data.mongodb: debug
|
||||
org.springframework.boot.autoconfigure.security.servlet: debug
|
||||
ink.wgink: debug
|
||||
|
||||
params-config:
|
||||
# 专管员角色ID
|
||||
role-specialized-person: 6ac90f36-caa0-4273-9489-4d0197124c33
|
||||
# 网格员角色ID
|
||||
role-grid-member: 90675eba-e63e-4819-b45d-2c99ab78a278
|
@ -87,6 +87,17 @@ public class BaseGridMemberTest {
|
||||
private String SQL_GET_AREA_BY_AREA_CODE = "SELECT area_id, area_parent_id, area_name, area_code FROM data_area WHERE area_code = ?";
|
||||
private String SQL_GET_AREA_BY_AREA_ID = "SELECT area_id, area_parent_id, area_name, area_code FROM data_area WHERE area_id = ?";
|
||||
|
||||
private static Integer SAVE_USER_COUNT = 0;
|
||||
private static Integer SAVE_USER_EXPAND_COUNT = 0;
|
||||
private static Integer SAVE_USER_ROLE_COUNT = 0;
|
||||
private static Integer NO_PHONE_COUNT = 0;
|
||||
private static Integer NO_AREA_COUNT = 0;
|
||||
private static Integer NO_BIRTH_COUNT = 0;
|
||||
private static Integer NO_SEX_COUNT = 0;
|
||||
private static Integer NO_EDUCATION_COUNT = 0;
|
||||
private static Integer NO_POLITICAL_COUNT = 0;
|
||||
private static Integer EXIST_PHONE_COUNT = 0;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
@ -143,11 +154,9 @@ public class BaseGridMemberTest {
|
||||
|
||||
connection.setAutoCommit(false);
|
||||
|
||||
EasyExcel.read(new File("/Users/wanggeng/Desktop/乌兰察布市域社会治理/基础数据/集宁区/网格员/网格员(全).xlsx"), ExcelGridMember.class, new ExcelGridMemberExcelListener() {
|
||||
|
||||
private int saveUserCount = 0;
|
||||
private int saveUserExpandCount = 0;
|
||||
private int saveUserRoleCount = 0;
|
||||
String areaFolder = "丰镇市";
|
||||
String filePath = "/Users/wanggeng/Desktop/乌兰察布市域社会治理/基础数据/网格员/" + areaFolder + "/网格员.xlsx";
|
||||
EasyExcel.read(new File(filePath), ExcelGridMember.class, new ExcelGridMemberExcelListener() {
|
||||
|
||||
@Override
|
||||
public void doSave(List<ExcelGridMember> excelGridMembers) {
|
||||
@ -157,22 +166,17 @@ public class BaseGridMemberTest {
|
||||
getUserPS.setString(1, excelGridMember.getUserPhone());
|
||||
Map<String, Object> userMap = JdbcUtil.getResult(getUserPS.executeQuery());
|
||||
if (userMap != null) {
|
||||
EXIST_PHONE_COUNT++;
|
||||
continue;
|
||||
}
|
||||
String userId = UUIDUtil.getUUID();
|
||||
// 新增用户
|
||||
saveUserCount += saveUser(insertUserPS, userId, excelGridMember, currentDateTime);
|
||||
saveUser(insertUserPS, userId, excelGridMember, currentDateTime);
|
||||
// 新增用户拓展
|
||||
saveUserExpandCount += saveUserExpand(insertUserExpandPS, userId, excelGridMember, currentDateTime, getAreaByCodePS, getAreaByIdPS, sexMaps, educationMaps, politicalMaps);
|
||||
saveUserExpand(insertUserExpandPS, userId, excelGridMember, currentDateTime, getAreaByCodePS, getAreaByIdPS, sexMaps, educationMaps, politicalMaps);
|
||||
// 新增用户角色
|
||||
saveUserRoleCount += saveUserRole(insertUserRolePS, userId, gridMemberRoleId);
|
||||
saveUserRole(insertUserRolePS, userId, gridMemberRoleId);
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println("saveUserCount: " + saveUserCount);
|
||||
System.out.println("saveUserExpandCount: " + saveUserExpandCount);
|
||||
System.out.println("saveUserRoleCount: " + saveUserRoleCount);
|
||||
|
||||
connection.commit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -182,6 +186,18 @@ public class BaseGridMemberTest {
|
||||
}).headRowNumber(1).sheet(0).doRead();
|
||||
long endTime = System.currentTimeMillis();
|
||||
System.out.println("耗时:" + (endTime - startTime) + "ms");
|
||||
System.out.println("****************************************");
|
||||
System.out.println("导入用户: " + SAVE_USER_COUNT);
|
||||
System.out.println("导入用户拓展: " + SAVE_USER_EXPAND_COUNT);
|
||||
System.out.println("导入用户角色: " + SAVE_USER_ROLE_COUNT);
|
||||
System.out.println("无手机号: " + NO_PHONE_COUNT);
|
||||
System.out.println("无区域或不匹配: " + NO_AREA_COUNT);
|
||||
System.out.println("无生日: " + NO_BIRTH_COUNT);
|
||||
System.out.println("无性别: " + NO_SEX_COUNT);
|
||||
System.out.println("无学历: " + NO_EDUCATION_COUNT);
|
||||
System.out.println("无政治面貌: " + NO_POLITICAL_COUNT);
|
||||
System.out.println("已存在手机: " + EXIST_PHONE_COUNT);
|
||||
System.out.println("****************************************");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -305,17 +321,25 @@ public class BaseGridMemberTest {
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
private int saveUser(PreparedStatement insertUserPS, String userId, ExcelGridMember excelGridMember, String currentDateTime) throws SQLException {
|
||||
private void saveUser(PreparedStatement insertUserPS, String userId, ExcelGridMember excelGridMember, String currentDateTime) throws SQLException {
|
||||
// 新增用户
|
||||
insertUserPS.setString(1, userId);
|
||||
insertUserPS.setString(2, excelGridMember.getUserPhone());
|
||||
String username;
|
||||
if (StringUtils.isBlank(excelGridMember.getUserPhone())) {
|
||||
username = "GMR-" + UUIDUtil.get32UUID().toUpperCase();
|
||||
NO_PHONE_COUNT++;
|
||||
} else {
|
||||
username = excelGridMember.getUserPhone();
|
||||
}
|
||||
insertUserPS.setString(2, username);
|
||||
insertUserPS.setString(3, new BCryptPasswordEncoder().encode("88888888"));
|
||||
insertUserPS.setString(4, excelGridMember.getUserName().replaceAll("\\s", ""));
|
||||
insertUserPS.setString(5, excelGridMember.getUserPhone());
|
||||
insertUserPS.setString(6, currentDateTime);
|
||||
insertUserPS.setString(7, currentDateTime);
|
||||
System.out.println(insertUserPS);
|
||||
return insertUserPS.executeUpdate();
|
||||
SAVE_USER_COUNT++;
|
||||
insertUserPS.executeUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -328,31 +352,61 @@ public class BaseGridMemberTest {
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
private int saveUserExpand(PreparedStatement insertUserExpandPS,
|
||||
String userId,
|
||||
ExcelGridMember excelGridMember,
|
||||
String currentDateTime,
|
||||
PreparedStatement getAreaByCodePS,
|
||||
PreparedStatement getAreaByParentIdPS,
|
||||
List<Map<String, Object>> sexMaps,
|
||||
List<Map<String, Object>> educationMaps,
|
||||
List<Map<String, Object>> politicalMaps) throws SQLException {
|
||||
private void saveUserExpand(PreparedStatement insertUserExpandPS,
|
||||
String userId,
|
||||
ExcelGridMember excelGridMember,
|
||||
String currentDateTime,
|
||||
PreparedStatement getAreaByCodePS,
|
||||
PreparedStatement getAreaByParentIdPS,
|
||||
List<Map<String, Object>> sexMaps,
|
||||
List<Map<String, Object>> educationMaps,
|
||||
List<Map<String, Object>> politicalMaps) throws SQLException {
|
||||
// 新增用户拓展属性
|
||||
insertUserExpandPS.setString(1, userId);
|
||||
insertUserExpandPS.setString(2, excelGridMember.getAreaCode());
|
||||
insertUserExpandPS.setString(3, getFullArea(excelGridMember.getAreaCode(), getAreaByCodePS, getAreaByParentIdPS));
|
||||
if (StringUtils.isBlank(excelGridMember.getAreaCode())) {
|
||||
insertUserExpandPS.setString(2, "");
|
||||
insertUserExpandPS.setString(3, "");
|
||||
NO_AREA_COUNT++;
|
||||
} else {
|
||||
insertUserExpandPS.setString(2, excelGridMember.getAreaCode());
|
||||
insertUserExpandPS.setString(3, getFullArea(excelGridMember.getAreaCode(), getAreaByCodePS, getAreaByParentIdPS));
|
||||
}
|
||||
insertUserExpandPS.setInt(4, 4);
|
||||
insertUserExpandPS.setString(5, excelGridMember.getSexId());
|
||||
insertUserExpandPS.setString(6, getSexById(excelGridMember.getSexId(), sexMaps));
|
||||
insertUserExpandPS.setString(7, getBirth(excelGridMember.getUserBirth()));
|
||||
insertUserExpandPS.setString(8, excelGridMember.getPoliticalId());
|
||||
insertUserExpandPS.setString(9, getPoliticalById(excelGridMember.getPoliticalId(), politicalMaps));
|
||||
insertUserExpandPS.setString(10, excelGridMember.getEducationId());
|
||||
insertUserExpandPS.setString(11, getEducationById(excelGridMember.getEducationId(), educationMaps));
|
||||
if (StringUtils.isBlank(excelGridMember.getSexId())) {
|
||||
insertUserExpandPS.setString(5, "");
|
||||
insertUserExpandPS.setString(6, "");
|
||||
NO_SEX_COUNT++;
|
||||
} else {
|
||||
insertUserExpandPS.setString(5, excelGridMember.getSexId());
|
||||
insertUserExpandPS.setString(6, getSexById(excelGridMember.getSexId(), sexMaps));
|
||||
}
|
||||
if (StringUtils.isBlank(excelGridMember.getUserBirth())) {
|
||||
insertUserExpandPS.setString(7, "");
|
||||
NO_BIRTH_COUNT++;
|
||||
} else {
|
||||
insertUserExpandPS.setString(7, getBirth(excelGridMember.getUserBirth()));
|
||||
}
|
||||
if (StringUtils.isBlank(excelGridMember.getPoliticalId())) {
|
||||
insertUserExpandPS.setString(8, "");
|
||||
insertUserExpandPS.setString(9, "");
|
||||
NO_POLITICAL_COUNT++;
|
||||
} else {
|
||||
insertUserExpandPS.setString(8, excelGridMember.getPoliticalId());
|
||||
insertUserExpandPS.setString(9, getPoliticalById(excelGridMember.getPoliticalId(), politicalMaps));
|
||||
}
|
||||
if (StringUtils.isBlank(excelGridMember.getEducationId())) {
|
||||
insertUserExpandPS.setString(10, "");
|
||||
insertUserExpandPS.setString(11, "");
|
||||
NO_EDUCATION_COUNT++;
|
||||
} else {
|
||||
insertUserExpandPS.setString(10, excelGridMember.getEducationId());
|
||||
insertUserExpandPS.setString(11, getEducationById(excelGridMember.getEducationId(), educationMaps));
|
||||
}
|
||||
insertUserExpandPS.setString(12, currentDateTime);
|
||||
insertUserExpandPS.setString(13, currentDateTime);
|
||||
System.out.println(insertUserExpandPS);
|
||||
return insertUserExpandPS.executeUpdate();
|
||||
insertUserExpandPS.executeUpdate();
|
||||
SAVE_USER_EXPAND_COUNT++;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -364,12 +418,13 @@ public class BaseGridMemberTest {
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
private int saveUserRole(PreparedStatement insertUserRolePS, String userId, String roleId) throws SQLException {
|
||||
private void saveUserRole(PreparedStatement insertUserRolePS, String userId, String roleId) throws SQLException {
|
||||
// 新增用户角色
|
||||
insertUserRolePS.setString(1, roleId);
|
||||
insertUserRolePS.setString(2, userId);
|
||||
System.out.println(insertUserRolePS);
|
||||
return insertUserRolePS.executeUpdate();
|
||||
insertUserRolePS.executeUpdate();
|
||||
SAVE_USER_ROLE_COUNT++;
|
||||
}
|
||||
|
||||
public abstract class ExcelGridMemberExcelListener extends AnalysisEventListener<ExcelGridMember> {
|
||||
|
Loading…
Reference in New Issue
Block a user