You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bsdgy-server/src/main/java/com/kiisoo/ic/job/count/CountDTOMessageHandler.java

111 lines
5.1 KiB
Java

6 years ago
package com.kiisoo.ic.job.count;
6 years ago
import com.kiisoo.ic.customer.CustomerService;
import com.kiisoo.ic.store.entity.PoiStoreStaff;
import com.kiisoo.ic.store.mapper.PoiStoreStaffDOMapper;
import com.kiisoo.ic.synchronous.entity.TurnBackDTO;
import com.kiisoo.ic.synchronous.entity.WxDataDTO;
6 years ago
import com.kiisoo.ic.wx.service.QWMailListManageService;
import com.lmax.disruptor.EventHandler;
import lombok.extern.slf4j.Slf4j;
6 years ago
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
6 years ago
import java.text.SimpleDateFormat;
6 years ago
import java.util.HashMap;
6 years ago
import java.util.List;
6 years ago
import java.util.Map;
import java.util.UUID;
@Slf4j
6 years ago
public class CountDTOMessageHandler implements EventHandler<CountDTOMessage> {
/**
*
6 years ago
* @param countDtoMessage
* @throws Exception
*/
@Override
6 years ago
public void onEvent(CountDTOMessage countDtoMessage, long l, boolean b) throws Exception {
6 years ago
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
6 years ago
countDtoMessage.setId(UUID.randomUUID().toString());
String cpUserId = countDtoMessage.getCpUserId();
CustomerService customerService = countDtoMessage.getCustomerService();
PoiStoreStaffDOMapper poiStoreStaffDOMapper = countDtoMessage.getPoiStoreStaffDOMapper();
QWMailListManageService qwMailListManageService = countDtoMessage.getQwMailListManageService();
Long storeId = countDtoMessage.getStoreId();
6 years ago
List<Map<String,Object>> tagList = poiStoreStaffDOMapper.selectStaffTagByStoreId(storeId);
6 years ago
Map<String,Long> tagMap = new HashMap<>();
for (Map<String,Object> map:tagList){
tagMap.put((String)map.get("tag"),(Long)map.get("staffId"));
}
6 years ago
List<WxCpUserExternalContactInfo> customers = null;
try {
customers = qwMailListManageService.getCustomer(cpUserId);
}catch (Exception e) {
log.error("查询联系人失败:"+cpUserId,e);
}
6 years ago
if (CollectionUtils.isEmpty(customers)){
6 years ago
return;
}
6 years ago
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);
6 years ago
}else if(tags != null && tags.length > 0 && tagList != null && tagList.size() > 0){
6 years ago
//判断是否有打tag
//todo 根据tag获取导购码
for (int j = 0;j<tags.length;j++){
String groupName = tags[j].getGroupName();
if ("导购".equals(groupName)){
String tagName = tags[j].getTagName();
6 years ago
Long staffId = tagMap.get(tagName);
6 years ago
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);
}
}
}