Commit 22f0fbd9 by 徐高华

导购删除、解绑

parent f9688eee
......@@ -369,7 +369,9 @@ public interface TabHaobanExternalClerkRelatedMapper {
int getCountByMemberId(@Param("memberId") String memberId);
void updateClerkInfo(@Param("staffId")String staffId, @Param("oldClerkId")String oldClerkId, @Param("newClerkId")String newClerkId, @Param("storeId")String storeId);
List<String> listByClerkId(@Param("staffId")String staffId, @Param("clerkId")String clerkId) ;
int updateExternalStatus(@Param("wxEnterpriseId")String wxEnterpriseId, @Param("externalUserid")String externalUserid, @Param("status")int status);
/**
......
......@@ -8,8 +8,11 @@ import java.util.Set;
public interface ClerkMainStoreRelatedService {
void setMainStore(String staffId, String storeId, String wxEnterpriseId);
// 自动刷新好友列表
void reflushExternal(String wxEnterpriseId ,String staffId) ;
TabHaobanClerkMainStoreRelated selectByWxEnterpriseIdAndStoreId(String staffId, String wxEnterpriseId);
TabHaobanClerkMainStoreRelated selectStaffMainStore(String staffId, String wxEnterpriseId);
/**
* 获取主门店 如果没有主门店设置主门店
......
......@@ -44,7 +44,7 @@ public class ClerkMainStoreRelatedServiceImpl implements ClerkMainStoreRelatedSe
private StaffService staffService;
@Override
public TabHaobanClerkMainStoreRelated selectByWxEnterpriseIdAndStoreId(String staffId, String wxEnterpriseId) {
public TabHaobanClerkMainStoreRelated selectStaffMainStore(String staffId, String wxEnterpriseId) {
return mapper.selectByWxEnterpriseIdAndStoreId(staffId, wxEnterpriseId, null);
}
......@@ -55,11 +55,6 @@ public class ClerkMainStoreRelatedServiceImpl implements ClerkMainStoreRelatedSe
logger.info("区经无需设置主门店:{}", staffId);
return;
}
TabHaobanStaff staff = staffService.selectById(staffId);
if (staff == null) {
logger.info("员工不存在:{}", staffId);
return;
}
String uuId = com.gic.haoban.common.utils.StringUtil.randomUUID();
Date now = new Date();
TabHaobanClerkMainStoreRelated t = new TabHaobanClerkMainStoreRelated();
......@@ -72,21 +67,23 @@ public class ClerkMainStoreRelatedServiceImpl implements ClerkMainStoreRelatedSe
t.setFreshFriendFlag(1);
t.setClerkMainStoreRelatedId(uuId);
mapper.insert(t);
logger.info("切换主门店-刷新企业微信好友:{},{}", staffId, storeId);
// 主门店切换需要刷新企业微信好友
// 判断是否需要刷新好友,如果只关联一个门店
List<StaffClerkRelationDTO> staffRelatioClerkList = staffClerkRelationService.listByStaffId(wxEnterpriseId, staffId) ;
boolean needFlag = CollectionUtils.isNotEmpty(staffRelatioClerkList) && staffRelatioClerkList.size()==1 && staffRelatioClerkList.get(0).getStoreId().equalsIgnoreCase(storeId) ;
if(needFlag) {
String taskName = "自动刷新企业微信好友(" + staff.getStaffName() + ")";
String taskId = dealSyncOperationApiService.createWxFriendTaskSingle(wxEnterpriseId, taskName, staffId, staff.getStaffName(), SyncTaskTypeEnum.FRIEND_SINGLE.getType());
if (StringUtils.isBlank(taskId)) {
logger.info("刷新好友失败或正在刷新:{},{}", staffId, storeId);
return;
}
dealSyncOperationApiService.dealWxFriendClerkSingle(taskId, staffId, staffId, wxEnterpriseId);
logger.info("开始自动刷新好友任务id={},staffId={}", taskId,staffId);
}
@Override
public void reflushExternal(String wxEnterpriseId ,String staffId) {
TabHaobanStaff staff = staffService.selectById(staffId);
if (staff == null) {
logger.info("员工不存在:{}", staffId);
return;
}
String taskName = "自动刷新企业微信好友(" + staff.getStaffName() + ")";
String taskId = dealSyncOperationApiService.createWxFriendTaskSingle(wxEnterpriseId, taskName, staffId, staff.getStaffName(), SyncTaskTypeEnum.FRIEND_SINGLE.getType());
if (StringUtils.isBlank(taskId)) {
logger.info("刷新好友失败或正在刷新:{},{}", staffId);
return;
}
dealSyncOperationApiService.dealWxFriendClerkSingle(taskId, staffId, staffId, wxEnterpriseId);
logger.info("开始自动刷新好友任务id={},staffId={}", taskId,staffId);
}
@Override
......
package com.gic.haoban.manage.service.service.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.Page;
import com.gic.clerk.api.dto.ClerkDTO;
import com.gic.clerk.api.service.ClerkService;
import com.gic.clerk.api.service.RightService;
import com.gic.commons.util.EntityUtil;
import com.gic.enterprise.api.dto.StoreDTO;
import com.gic.enterprise.api.service.StoreService;
import com.gic.haoban.base.api.common.BasePageInfo;
import com.gic.haoban.common.utils.PageUtil;
import com.gic.haoban.common.utils.StringUtil;
......@@ -15,25 +33,22 @@ import com.gic.haoban.manage.api.enums.BindTypeEnum;
import com.gic.haoban.manage.api.enums.ChannelCodeEnum;
import com.gic.haoban.manage.api.service.hm.HmClerkRelationApiService;
import com.gic.haoban.manage.api.service.hm.HmQrcodeApiService;
import com.gic.haoban.manage.service.dao.mapper.TabHaobanExternalClerkRelatedMapper;
import com.gic.haoban.manage.service.dao.mapper.TabHaobanMemberClerkChatConfigMapper;
import com.gic.haoban.manage.service.dao.mapper.TabHaobanStaffClerkRelationMapper;
import com.gic.haoban.manage.service.entity.MemberClerkChatConfig;
import com.gic.haoban.manage.service.entity.TabHaobanClerkMainStoreRelated;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.entity.TabHaobanStaffClerkRelation;
import com.gic.haoban.manage.service.service.*;
import com.gic.haoban.manage.service.service.ClerkMainStoreRelatedService;
import com.gic.haoban.manage.service.service.ExternalClerkRelatedService;
import com.gic.haoban.manage.service.service.StaffClerkBindLogService;
import com.gic.haoban.manage.service.service.StaffClerkRelationService;
import com.gic.haoban.manage.service.service.StaffService;
import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.member.api.service.MemberApiService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class StaffClerkRelationServiceImpl implements StaffClerkRelationService {
......@@ -51,10 +66,12 @@ public class StaffClerkRelationServiceImpl implements StaffClerkRelationService
@Autowired
private ClerkMainStoreRelatedService clerkMainStoreRelatedService;
@Autowired
private TabHaobanExternalClerkRelatedMapper externalClerkRelatedMapper;
@Autowired
private TabHaobanMemberClerkChatConfigMapper memberClerkChatConfigMapper;
@Autowired
private StoreService storeService ;
@Autowired
private HmQrcodeApiService hmQrcodeApiService;
@Autowired
......@@ -96,22 +113,49 @@ public class StaffClerkRelationServiceImpl implements StaffClerkRelationService
// wxEnterpriseId非必传
StaffClerkRelationDTO clerkRelation = mapper.getOneByClerkId(oldClerkId, wxEnterpriseId);
if (null == clerkRelation) {
logger.info("老的绑定关联不存在,clerkId={}", oldClerkId);
logger.info("老的绑定关联不存在,oldClerkId={}", oldClerkId);
return true;
}
wxEnterpriseId = clerkRelation.getWxEnterpriseId() ;
String enterpriseId = clerkRelation.getEnterpriseId();
logger.info("当前删除换绑的商户={},{}",enterpriseId,wxEnterpriseId);
String staffId = clerkRelation.getStaffId() ;
String storeId = clerkRelation.getStoreId() ;
// 删除老的绑定关系
int count = mapper.changeStatusByClerkId(oldClerkId, 0);
logger.info("删除导购关联,clerkId={}",oldClerkId);
boolean needFlush = false ;
if(StringUtils.isEmpty(newClerkId)) {
// 查询主门店
// 成员关联的门店
List<StaffClerkRelationDTO> relationList = this.listByStaffId(wxEnterpriseId, staffId) ;
if(CollectionUtils.isNotEmpty(relationList)) {
List<String> storeIdList = relationList.stream().filter(o->storeId.equals(o.getStoreId())).map(o->o.getStoreId()).collect(Collectors.toList()) ;
if(CollectionUtils.isNotEmpty(storeIdList)) {
Set<String> set = relationList.stream().map(o->o.getEnterpriseId()).collect(Collectors.toSet()) ;
// 否关联的多个商户
boolean multipleFlag = set.size() > 1 ;
List<String> storeIdList = relationList.stream().filter(o->!storeId.equals(o.getStoreId()) && o.getEnterpriseId().equals(enterpriseId)).map(o->o.getStoreId()).collect(Collectors.toList()) ;
logger.info("成员{},关联门店数={},同商户下的门店={}",staffId,relationList.size(),JSON.toJSON(storeIdList));
if(CollectionUtils.isNotEmpty(storeIdList)) {
if(multipleFlag) {
needFlush = true ;
TabHaobanClerkMainStoreRelated currentMainStore = this.clerkMainStoreRelatedService.selectStaffMainStore(staffId, wxEnterpriseId);
String mainStoreEnterpriseId = null ;
if(null == currentMainStore) {
mainStoreEnterpriseId = enterpriseId ;
}else {
String mainStoreId = currentMainStore.getStoreId() ;
StoreDTO store = this.storeService.getStore(mainStoreId) ;
mainStoreEnterpriseId = store.getEnterpriseId() ;
}
logger.info("当前主门店商户和处理商户是否一致{},{}",mainStoreEnterpriseId,enterpriseId);
if(mainStoreEnterpriseId.equals(enterpriseId)) {
// 删除关联关系
this.mapper.changeStatusByClerkId(oldClerkId, 0);
TabHaobanClerkMainStoreRelated mainStoreRelation = this.clerkMainStoreRelatedService.getMainStoreByStaffId(staffId, wxEnterpriseId, storeIdList) ;
String newStoreId = mainStoreRelation.getStoreId() ;
StaffClerkRelationDTO mainClerk = this.getOneBindByStoreId(staffId, newStoreId) ;
newClerkId = mainClerk.getClerkId() ;
logger.info("查询到成员的主门店导购={},{}",staffId,newClerkId);
needFlush = false ;
}
}else {
// 删除关联关系
this.mapper.changeStatusByClerkId(oldClerkId, 0);
TabHaobanClerkMainStoreRelated mainStore = this.clerkMainStoreRelatedService.getMainStoreByStaffId(staffId, wxEnterpriseId, storeIdList) ;
String newStoreId = mainStore.getStoreId() ;
StaffClerkRelationDTO mainClerk = this.getOneBindByStoreId(staffId, newStoreId) ;
......@@ -121,7 +165,15 @@ public class StaffClerkRelationServiceImpl implements StaffClerkRelationService
}
}
if(StringUtils.isNotBlank(newClerkId)) {
List<String> memberIdList = this.externalClerkRelatedMapper.listByClerkId(staffId, oldClerkId) ;
this.externalClerkRelatedService.updateClerkInfo(staffId , oldClerkId , newClerkId) ;
if(CollectionUtils.isNotEmpty(memberIdList)) {
ClerkDTO clerk = this.clerkService.getclerkById(newClerkId);
String newStoreId = clerk.getStoreId() ;
for(String memberId : memberIdList) {
logger.info("会员");
}
}
}else {
logger.info("成员删除所有关联导购={}",staffId);
List<String> memberIds = externalClerkRelatedService.getByStoreIdAndStaffId(storeId, staffId);
......@@ -130,14 +182,14 @@ public class StaffClerkRelationServiceImpl implements StaffClerkRelationService
//推入日志
delMemberQywxFlag(enterpriseId, memberIds);
}
this.staffClerkBindLogService.pushToMq(staffId, optStaffId, BindTypeEnum.UNBIND.getVal(), channelCode, clerkRelation.getStaffClerkRelationId());
// 如果不是导购更换ID
if(!changeClerkFlag) {
newClerkId = null ;
if(needFlush) {
logger.info("刷新好友,staffId={}",staffId);
this.clerkMainStoreRelatedService.reflushExternal(wxEnterpriseId, staffId);
}
this.staffClerkBindLogService.pushToMq(staffId, optStaffId, BindTypeEnum.UNBIND.getVal(), channelCode, clerkRelation.getStaffClerkRelationId());
//废弃活码
this.hmClerkRelationApiService.delByClerkId(oldClerkId, enterpriseId, wxEnterpriseId, channelCode, newClerkId);
return count > 0;
this.hmClerkRelationApiService.delByClerkId(oldClerkId, enterpriseId, wxEnterpriseId, channelCode, null);
return true;
}
......
......@@ -23,9 +23,10 @@ public class ClerkMainStoreRelatedApiServiceImpl implements ClerkMainStoreRelate
@Override
public void setMainStore(String staffId, String storeId, String wxEnterpriseId) {
TabHaobanClerkMainStoreRelated related = clerkMainStoreRelatedService.selectByWxEnterpriseIdAndStoreId(staffId, wxEnterpriseId);
TabHaobanClerkMainStoreRelated related = clerkMainStoreRelatedService.selectStaffMainStore(staffId, wxEnterpriseId);
if (related == null) {
clerkMainStoreRelatedService.setMainStore(staffId, storeId, wxEnterpriseId);
this.clerkMainStoreRelatedService.setMainStore(staffId, storeId, wxEnterpriseId);
this.clerkMainStoreRelatedService.reflushExternal(wxEnterpriseId, staffId);
} else if (null != related && (!related.getStoreId().equals(storeId))) {
related.setStatusFlag(0);
related.setUpdateTime(new Date());
......
......@@ -734,6 +734,13 @@
and status_flag in (1,3,4)
</update>
<select id="listByClerkId" resultType="String">
select member_id from tab_haoban_external_clerk_related
where staff_id = #{staffId}
and clerk_id = #{clerkId}
and status_flag = 1
</select>
<update id="updateExternalStatus">
update tab_haoban_external_clerk_related set external_status = #{status} where
external_user_id = #{externalUserid} and wx_enterprise_id = #{wxEnterpriseId}
......
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