|
|
|
@ -1,14 +1,34 @@
|
|
|
|
|
package com.kiisoo.ic.job;
|
|
|
|
|
|
|
|
|
|
import com.kiisoo.ic.customer.CustomerService;
|
|
|
|
|
import com.kiisoo.ic.store.entity.PoiStoreStaff;
|
|
|
|
|
import com.kiisoo.ic.store.entity.PrivilageCpUserStoreDO;
|
|
|
|
|
import com.kiisoo.ic.store.mapper.PoiStoreStaffDOMapper;
|
|
|
|
|
import com.kiisoo.ic.synchronous.entity.TurnBackDTO;
|
|
|
|
|
import com.kiisoo.ic.synchronous.entity.WxDataDTO;
|
|
|
|
|
import com.lmax.disruptor.EventHandler;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
public class DTOMessageHandler implements EventHandler<DTOMessage> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PoiStoreStaffDOMapper poiStoreStaffDOMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CustomerService customerService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理事件, 如入库操作
|
|
|
|
|
* @param dtoMessage
|
|
|
|
@ -18,8 +38,64 @@ public class DTOMessageHandler implements EventHandler<DTOMessage> {
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void onEvent(DTOMessage dtoMessage, long l, boolean b) throws Exception {
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
dtoMessage.setId(UUID.randomUUID().toString());
|
|
|
|
|
log.info( dtoMessage.toString());
|
|
|
|
|
// 入库操作
|
|
|
|
|
String cpUserId = dtoMessage.getCpUserId();
|
|
|
|
|
PrivilageCpUserStoreDO cpUserStoreDO = dtoMessage.getPrivilageCpUserStoreDO();
|
|
|
|
|
List<WxCpUserExternalContactInfo> customers = dtoMessage.getCustomers();
|
|
|
|
|
for (WxCpUserExternalContactInfo customer:customers){
|
|
|
|
|
TurnBackDTO turnBackDTO = new TurnBackDTO();
|
|
|
|
|
|
|
|
|
|
WxCpUserExternalContactInfo.ExternalContact externalContact = customer.getExternalContact();
|
|
|
|
|
List<WxCpUserExternalContactInfo.FollowedUser> followedUsers = customer.getFollowedUsers();
|
|
|
|
|
|
|
|
|
|
turnBackDTO.setEaCode("");
|
|
|
|
|
if (CollectionUtils.isNotEmpty(followedUsers)){
|
|
|
|
|
for (WxCpUserExternalContactInfo.FollowedUser followedUser:followedUsers){
|
|
|
|
|
if (cpUserId.equals(followedUser.getUserId())){
|
|
|
|
|
String state = followedUser.getState();
|
|
|
|
|
WxCpUserExternalContactInfo.Tag[] tags = followedUser.getTags();
|
|
|
|
|
if (StringUtils.isNotBlank(state)){
|
|
|
|
|
//判断是否有导购码
|
|
|
|
|
turnBackDTO.setEaCode(state);
|
|
|
|
|
}else if(tags != null && tags.length > 0){
|
|
|
|
|
//判断是否有打tag
|
|
|
|
|
//todo 根据tag获取导购码
|
|
|
|
|
for (int j = 0;j<tags.length;j++){
|
|
|
|
|
String groupName = tags[j].getGroupName();
|
|
|
|
|
if ("导购".equals(groupName)){
|
|
|
|
|
String tagName = tags[j].getTagName();
|
|
|
|
|
Long staffId = poiStoreStaffDOMapper.selectStaffIdByTag(cpUserStoreDO.getStoreId(), tagName);
|
|
|
|
|
if (staffId != null){
|
|
|
|
|
PoiStoreStaff poiStoreStaff = poiStoreStaffDOMapper.selectById(staffId);
|
|
|
|
|
if (poiStoreStaff!=null){
|
|
|
|
|
turnBackDTO.setEaCode(poiStoreStaff.getStaffCode());
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
//todo 绑定在标签导购上,后续删除
|
|
|
|
|
turnBackDTO.setEaCode(tagName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Long joinTimeL = followedUser.getCreateTime();
|
|
|
|
|
Long time=new Long(joinTimeL);
|
|
|
|
|
String joinTime = sdf.format(time*1000);
|
|
|
|
|
turnBackDTO.setJoinTime(joinTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//type 1 微信,type 2 企业微信
|
|
|
|
|
turnBackDTO.setType(externalContact.getType());
|
|
|
|
|
turnBackDTO.setUserId(cpUserId);
|
|
|
|
|
turnBackDTO.setName(externalContact.getName());
|
|
|
|
|
WxDataDTO wxDataDTO = new WxDataDTO();
|
|
|
|
|
wxDataDTO.setAvatarUrl(externalContact.getAvatar());
|
|
|
|
|
wxDataDTO.setUserId(externalContact.getExternalUserId());
|
|
|
|
|
wxDataDTO.setUnionId(externalContact.getUnionId());
|
|
|
|
|
turnBackDTO.setWxData(wxDataDTO);
|
|
|
|
|
|
|
|
|
|
customerService.turnBack(turnBackDTO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|