Commit 4237444c by fudahua

同步绑定流程

parent a1f74bc7
...@@ -24,6 +24,16 @@ public class ClerkSyncPojo extends BinlogBasePojo { ...@@ -24,6 +24,16 @@ public class ClerkSyncPojo extends BinlogBasePojo {
private Integer status; private Integer status;
private Integer oldStatus;
public Integer getOldStatus() {
return oldStatus;
}
public void setOldStatus(Integer oldStatus) {
this.oldStatus = oldStatus;
}
public ClerkSyncPojo() { public ClerkSyncPojo() {
prefix="clerk"; prefix="clerk";
} }
......
...@@ -10,6 +10,7 @@ import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO; ...@@ -10,6 +10,7 @@ import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.service.pojo.BinlogBasePojo; import com.gic.haoban.manage.service.pojo.BinlogBasePojo;
import com.gic.haoban.manage.service.pojo.ClerkSyncPojo; import com.gic.haoban.manage.service.pojo.ClerkSyncPojo;
import com.gic.haoban.manage.service.service.StaffClerkRelationService; import com.gic.haoban.manage.service.service.StaffClerkRelationService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -17,10 +18,7 @@ import org.slf4j.LoggerFactory; ...@@ -17,10 +18,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.listener.MessageListener; import org.springframework.kafka.listener.MessageListener;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* Created 2019/4/10. * Created 2019/4/10.
...@@ -60,31 +58,55 @@ public class KafkaMessageServiceImpl implements MessageListener<String, GicRecor ...@@ -60,31 +58,55 @@ public class KafkaMessageServiceImpl implements MessageListener<String, GicRecor
staffClerkRelationService.delBind(syncPojo.getClerkId()); staffClerkRelationService.delBind(syncPojo.getClerkId());
}else if (gicRecordType.equals(GicRecordType.INSERT)) { }else if (gicRecordType.equals(GicRecordType.INSERT)) {
StaffClerkRelationDTO relationDTO = staffClerkRelationService.getOneBindCodeNoStatus(syncPojo.getEnterpriseId(), syncPojo.getClerkCode()); StaffClerkRelationDTO relationDTO = staffClerkRelationService.getOneBindCodeNoStatus(syncPojo.getEnterpriseId(), syncPojo.getClerkCode());
if (null == relationDTO) { moveOrAddClerk(syncPojo,relationDTO);
logger.info("没有关联导购,不需要新增"); }else if (gicRecordType.equals(GicRecordType.UPDATE)) {
return; StaffClerkRelationDTO relationDTO = new StaffClerkRelationDTO();
relationDTO.setClerkId(syncPojo.getClerkId());
relationDTO.setStoreId(syncPojo.getStoreId());
relationDTO.setClerkCode(syncPojo.getClerkCode());
//非正常状态 删除
if (!syncPojo.getStatus().equals(1)) {
staffClerkRelationService.delBind(syncPojo.getClerkId());
}else {
List<String> clerkIds=new ArrayList<>();
clerkIds.add(syncPojo.getClerkId());
StaffClerkRelationDTO bindRelationDTO = staffClerkRelationService.getOneBindCodeNoStatus(syncPojo.getEnterpriseId(), syncPojo.getClerkCode());
if (bindRelationDTO == null) {
logger.info("没有关联导购,不需要操作");
return;
}
if (bindRelationDTO.getStatusFlag().equals(StatusEnum.NORMAL.getValue())
&&syncPojo.getOldStatus().equals(1)) {
logger.info("更新关联信息");
staffClerkRelationService.updateByClerkId(relationDTO);
}else {
logger.info("走新增逻辑");
//走新增逻辑
moveOrAddClerk(syncPojo,bindRelationDTO);
}
} }
//正常的时候 }
if (relationDTO.getStatusFlag() != StatusEnum.DEL.getValue()) { }
private void moveOrAddClerk(ClerkSyncPojo syncPojo,StaffClerkRelationDTO relationDTO) {
if (null == relationDTO) {
logger.info("没有关联导购,不需要新增");
return;
}
//正常的时候
if (relationDTO.getStatusFlag() != StatusEnum.DEL.getValue()) {
staffClerkRelationService.delBind(relationDTO.getClerkId());
relationDTO.setClerkId(syncPojo.getClerkId());
relationDTO.setStoreId(syncPojo.getStoreId());
staffClerkRelationService.bind(relationDTO);
}else {//删除状态 需要判断是否近段时间有操作删除 2分组内有更新 判断是转移操作
Date timeDiff = DateUtils.addMinutes(new Date(), -2);
if(relationDTO.getUpdateTime().after(timeDiff)){
staffClerkRelationService.delBind(relationDTO.getClerkId()); staffClerkRelationService.delBind(relationDTO.getClerkId());
relationDTO.setClerkId(syncPojo.getClerkId()); relationDTO.setClerkId(syncPojo.getClerkId());
relationDTO.setStoreId(syncPojo.getStoreId()); relationDTO.setStoreId(syncPojo.getStoreId());
staffClerkRelationService.bind(relationDTO); staffClerkRelationService.bind(relationDTO);
}else {//删除状态 需要判断是否近段时间有操作删除 2分组内有更新 判断是转移操作
Date timeDiff = DateUtils.addMinutes(new Date(), -2);
if(relationDTO.getUpdateTime().after(timeDiff)){
staffClerkRelationService.delBind(relationDTO.getClerkId());
relationDTO.setClerkId(syncPojo.getClerkId());
relationDTO.setStoreId(syncPojo.getStoreId());
staffClerkRelationService.bind(relationDTO);
}
} }
}else if (gicRecordType.equals(GicRecordType.UPDATE)) {
StaffClerkRelationDTO relationDTO = new StaffClerkRelationDTO();
relationDTO.setClerkId(syncPojo.getClerkId());
relationDTO.setStoreId(syncPojo.getStoreId());
relationDTO.setClerkCode(syncPojo.getClerkCode());
staffClerkRelationService.updateByClerkId(relationDTO);
} }
} }
...@@ -103,7 +125,13 @@ public class KafkaMessageServiceImpl implements MessageListener<String, GicRecor ...@@ -103,7 +125,13 @@ public class KafkaMessageServiceImpl implements MessageListener<String, GicRecor
private BinlogBasePojo binlogMap(List<GicField> list,GicRecordType recordType,Class<? extends BinlogBasePojo> aclass) { private BinlogBasePojo binlogMap(List<GicField> list,GicRecordType recordType,Class<? extends BinlogBasePojo> aclass) {
Map<String,String> mid=new HashMap<>(); Map<String,String> mid=new HashMap<>();
for (GicField gicField : list) { for (GicField gicField : list) {
mid.put(gicField.getName(),gicField.getValue()); if (gicField.getName().equals("status")
&&recordType.equals(GicRecordType.UPDATE)
&&!mid.containsKey("oldStatus")) {
mid.put("oldStatus",gicField.getValue());
}else {
mid.put(gicField.getName(), gicField.getValue());
}
} }
BinlogBasePojo pojo = EntityUtil.changeEntityByJSON(aclass, mid); BinlogBasePojo pojo = EntityUtil.changeEntityByJSON(aclass, mid);
pojo.setRecordType(recordType.value()); pojo.setRecordType(recordType.value());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment