门店号管理

master
LegnaYet 6 years ago
parent 33b003e4c3
commit a53bfb25d5

@ -100,6 +100,38 @@ public class EmployeeController extends BaseController {
return fail();
}
}
/**
*
* @return
* @throws Exception
*/
@RequestMapping(value = "clean/store/custommer",method = RequestMethod.GET)
@ResponseBody
public Map<String,Object> cleanCustomerRelation(@RequestParam("storeCode") String storeCode){
try {
employeeService.cleanCustomerRelationByStoreCode(storeCode);
return success();
}catch (Exception e){
log.error("清理店铺客户数据失败",e);
return fail();
}
}
/**
*
* @return
* @throws Exception
*/
@RequestMapping(value = "clean/company/custommer",method = RequestMethod.GET)
@ResponseBody
public Map<String,Object> cleanCustomerRelation(@RequestParam("companyId") Long companyId){
try {
employeeService.cleanCustomerRelationBycompanyId(companyId);
return success();
}catch (Exception e){
log.error("清理店铺客户数据失败",e);
return fail();
}
}
/**
*
* @return

@ -23,7 +23,6 @@ import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.Quotient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -42,6 +41,7 @@ import java.util.List;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@ -78,6 +78,9 @@ public class EmployeeService {
@Autowired
private PoiStoreDOMapper poiStoreDOMapper;
@Autowired
private PoiStoreStaffDOMapper poiStoreStaffDOMapper;
public final Integer TYPE_CUSTOMER_EFFECTIVE = 1;
public final Integer TYPE_CUSTOMER_INVALID = 2;
@ -496,7 +499,15 @@ public class EmployeeService {
String groupName = tags[i].getGroupName();
if ("导购".equals(groupName)){
String tagName = tags[i].getTagName();
turnBackDTO.setEaCode(tagName);
Long staffId = poiStoreStaffDOMapper.selectStaffIdByTag(privilageCpUserStoreDO.getStoreId(), tagName);
if (staffId != null){
PoiStoreStaff poiStoreStaff = poiStoreStaffDOMapper.selectById(staffId);
if (poiStoreStaff!=null){
turnBackDTO.setEaCode(poiStoreStaff.getStaffCode());
}
}else{
turnBackDTO.setEaCode(tagName);
}
}
}
}
@ -525,6 +536,27 @@ public class EmployeeService {
}
public void modifyTagRelation() throws Exception {
List<PoiStore> poiStores = poiStoreDOMapper.selectShopByCompany(110L);
List<Long> storeIds = poiStores.stream().map(store -> store.getId()).collect(Collectors.toList());
QueryWrapper<OpSellerCustomerRelation> queryWrapper = new QueryWrapper();
queryWrapper.in("store_id",storeIds);
List<OpSellerCustomerRelation> relations = opSellerCustomerRelationDOMapper.selectList(queryWrapper);
for (OpSellerCustomerRelation opSellerCustomerRelation:relations){
Long userId = opSellerCustomerRelation.getUserId();
if (userId.equals(0L)){
continue;
}
PoiStoreStaff poiStoreStaff = poiStoreStaffDOMapper.selectById(userId);
if (poiStoreStaff!=null && StringUtils.isNotEmpty(poiStoreStaff.getStaffCode()) &&poiStoreStaff.getStaffCode().contains("导购")){
String tag = poiStoreStaff.getStaffCode();
Long staffId = poiStoreStaffDOMapper.selectStaffIdByTag(poiStoreStaff.getStoreId(), tag);
opSellerCustomerRelation.setUserId(staffId);
opSellerCustomerRelationDOMapper.updateById(opSellerCustomerRelation);
}
}
}
public void syncCustoemrByCpUserIds(String cpUserIds) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//查询所有店长
@ -548,10 +580,13 @@ public class EmployeeService {
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())){
Long storeId = privilageCpUserStoreDOMapper.selectOneByCpUserId(cpUserId);
String state = followedUser.getState();
WxCpUserExternalContactInfo.Tag[] tags = followedUser.getTags();
if (StringUtils.isNotBlank(state)){
@ -564,7 +599,15 @@ public class EmployeeService {
String groupName = tags[i].getGroupName();
if ("导购".equals(groupName)){
String tagName = tags[i].getTagName();
turnBackDTO.setEaCode(tagName);
Long staffId = poiStoreStaffDOMapper.selectStaffIdByTag(storeId, tagName);
if (staffId != null){
PoiStoreStaff poiStoreStaff = poiStoreStaffDOMapper.selectById(staffId);
if (poiStoreStaff!=null){
turnBackDTO.setEaCode(poiStoreStaff.getStaffCode());
}
}else{
turnBackDTO.setEaCode(tagName);
}
}
}
}
@ -618,7 +661,145 @@ public class EmployeeService {
List<OpSellerCustomerRelation> relations = customerMap.get(customerId);
//根据导购分组
Map<Long, List<OpSellerCustomerRelation>> sellerMap = new HashMap<>();
for (OpSellerCustomerRelation opSellerCustomerRelation : poiStoreStaffs) {
for (OpSellerCustomerRelation opSellerCustomerRelation : relations) {
Long sellerId = opSellerCustomerRelation.getUserId();
if (sellerMap.get(sellerId) != null){
List<OpSellerCustomerRelation> sellerRelations = sellerMap.get(sellerId);
sellerRelations.add(opSellerCustomerRelation);
}else {
List<OpSellerCustomerRelation> sellerRelations = new ArrayList<>();
sellerRelations.add(opSellerCustomerRelation);
sellerMap.put(sellerId,sellerRelations);
}
}
//获取sellerId为0的分组
List<OpSellerCustomerRelation> storeRelation = sellerMap.get(0L);
if (CollectionUtils.isEmpty(storeRelation)){
continue;
}
Set<Long> sellerIds = sellerMap.keySet();
for (Long sellerId : sellerIds){
if (sellerId.equals(0L)){
continue;
}
//获取导购与客户的关系
List<OpSellerCustomerRelation> sellRelations = sellerMap.get(sellerId);
//遍历关系,看是否存在店铺关系,如果存在则删除店铺关系
for (OpSellerCustomerRelation sellRelation : sellRelations) {
Long sellCustomer = sellRelation.getCustomerId();
for (OpSellerCustomerRelation opSellerCustomerRelation : storeRelation) {
if (opSellerCustomerRelation.getCustomerId().equals(sellCustomer)){
//店铺中存在则删除这条店铺记录(该记录为回调产生,保留的是同步过来的数据)
if (opSellerCustomerRelation.getType().equals(TYPE_CUSTOMER_EFFECTIVE)){
//判断是否有效,有效则说明导购数据是有效的
sellRelation.setType(TYPE_CUSTOMER_EFFECTIVE);
opSellerCustomerRelationDOMapper.updateById(sellRelation);
}
//删除店铺数据
opSellerCustomerRelationDOMapper.deleteById(opSellerCustomerRelation.getId());
}
}
}
}
}
}
}
}
public void cleanCustomerRelationByStoreCode(String storeCode){
QueryWrapper<PoiStore> storeQw = new QueryWrapper<>();
storeQw.eq("code",storeCode).last("limit 1");
PoiStore poiStore = poiStoreDOMapper.selectOne(storeQw);
QueryWrapper<OpSellerCustomerRelation> qw = new QueryWrapper<>();
qw.eq("store_id",poiStore.getId());
List<OpSellerCustomerRelation> poiStoreStaffs = opSellerCustomerRelationDOMapper.selectList(qw);
//同一家店根据客户分组
Map<Long, List<OpSellerCustomerRelation>> customerMap = new HashMap<>();
for (OpSellerCustomerRelation opSellerCustomerRelation : poiStoreStaffs) {
Long customerId = opSellerCustomerRelation.getCustomerId();
if (customerMap.get(customerId) != null){
List<OpSellerCustomerRelation> relations = customerMap.get(customerId);
relations.add(opSellerCustomerRelation);
}else {
List<OpSellerCustomerRelation> relations = new ArrayList<>();
relations.add(opSellerCustomerRelation);
customerMap.put(customerId,relations);
}
}
Set<Long> customerIds = customerMap.keySet();
for (Long customerId:customerIds) {
List<OpSellerCustomerRelation> relations = customerMap.get(customerId);
//根据导购分组
Map<Long, List<OpSellerCustomerRelation>> sellerMap = new HashMap<>();
for (OpSellerCustomerRelation opSellerCustomerRelation : relations) {
Long sellerId = opSellerCustomerRelation.getUserId();
if (sellerMap.get(sellerId) != null) {
List<OpSellerCustomerRelation> sellerRelations = sellerMap.get(sellerId);
sellerRelations.add(opSellerCustomerRelation);
} else {
List<OpSellerCustomerRelation> sellerRelations = new ArrayList<>();
sellerRelations.add(opSellerCustomerRelation);
sellerMap.put(sellerId, sellerRelations);
}
}
//获取sellerId为0的分组
List<OpSellerCustomerRelation> storeRelation = sellerMap.get(0L);
if (CollectionUtils.isEmpty(storeRelation)) {
continue;
}
Set<Long> sellerIds = sellerMap.keySet();
for (Long sellerId : sellerIds) {
if (sellerId.equals(0L)) {
continue;
}
//获取导购与客户的关系
List<OpSellerCustomerRelation> sellRelations = sellerMap.get(sellerId);
//遍历关系,看是否存在店铺关系,如果存在则删除店铺关系
for (OpSellerCustomerRelation sellRelation : sellRelations) {
Long sellCustomer = sellRelation.getCustomerId();
for (OpSellerCustomerRelation opSellerCustomerRelation : storeRelation) {
if (opSellerCustomerRelation.getCustomerId().equals(sellCustomer)) {
//店铺中存在则删除这条店铺记录(该记录为回调产生,保留的是同步过来的数据)
if (opSellerCustomerRelation.getType().equals(TYPE_CUSTOMER_EFFECTIVE)) {
//判断是否有效,有效则说明导购数据是有效的
sellRelation.setType(TYPE_CUSTOMER_EFFECTIVE);
opSellerCustomerRelationDOMapper.updateById(sellRelation);
}
//删除店铺数据
opSellerCustomerRelationDOMapper.deleteById(opSellerCustomerRelation.getId());
}
}
}
}
}
}
public void cleanCustomerRelationBycompanyId(Long companyId){
List<PoiStore> poiStores = poiStoreDOMapper.selectShopByCompany(companyId);
if (CollectionUtils.isNotEmpty(poiStores)) {
for (PoiStore poiStore : poiStores) {
Long storeId = poiStore.getId();
QueryWrapper<OpSellerCustomerRelation> qw = new QueryWrapper<>();
qw.eq("store_id",storeId);
List<OpSellerCustomerRelation> poiStoreStaffs = opSellerCustomerRelationDOMapper.selectList(qw);
//同一家店根据客户分组
Map<Long, List<OpSellerCustomerRelation>> customerMap = new HashMap<>();
for (OpSellerCustomerRelation opSellerCustomerRelation : poiStoreStaffs) {
Long customerId = opSellerCustomerRelation.getCustomerId();
if (customerMap.get(customerId) != null){
List<OpSellerCustomerRelation> relations = customerMap.get(customerId);
relations.add(opSellerCustomerRelation);
}else {
List<OpSellerCustomerRelation> relations = new ArrayList<>();
relations.add(opSellerCustomerRelation);
customerMap.put(customerId,relations);
}
}
Set<Long> customerIds = customerMap.keySet();
for (Long customerId:customerIds){
List<OpSellerCustomerRelation> relations = customerMap.get(customerId);
//根据导购分组
Map<Long, List<OpSellerCustomerRelation>> sellerMap = new HashMap<>();
for (OpSellerCustomerRelation opSellerCustomerRelation : relations) {
Long sellerId = opSellerCustomerRelation.getUserId();
if (sellerMap.get(sellerId) != null){
List<OpSellerCustomerRelation> sellerRelations = sellerMap.get(sellerId);

@ -48,4 +48,6 @@ public interface PoiStoreStaffDOMapper extends BaseMapper<PoiStoreStaff> {
List<StafferInfoVO> selectInfoById(@Param("userId") Long userId);
Long selectStaffIdByUserId(@Param("userId") Long userId);
Long selectStaffIdByTag(@Param("storeId") Long store,@Param("tag") String tag);
}

@ -47,4 +47,9 @@
select id from poi_store_staff where user_id = #{userId}
limit 1
</select>
<select id="selectStaffIdByTag" resultType="java.lang.Long">
select staff_id from poi_store_staff_tag where store_id = #{storeId} and tag = #{tag}
limit 1
</select>
</mapper>

Loading…
Cancel
Save