From a53bfb25d59fb66555127f0e0eba756c928ead4d Mon Sep 17 00:00:00 2001 From: LegnaYet <1023868505@qq.com> Date: Tue, 12 May 2020 17:23:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=A8=E5=BA=97=E5=8F=B7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/EmployeeController.java | 32 +++ .../ic/employee/service/EmployeeService.java | 189 +++++++++++++++++- .../store/mapper/PoiStoreStaffDOMapper.java | 2 + .../PrivilageUserShopRelationDOMapper.xml | 5 + 4 files changed, 224 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/kiisoo/ic/employee/controller/EmployeeController.java b/src/main/java/com/kiisoo/ic/employee/controller/EmployeeController.java index ab10625..526913c 100644 --- a/src/main/java/com/kiisoo/ic/employee/controller/EmployeeController.java +++ b/src/main/java/com/kiisoo/ic/employee/controller/EmployeeController.java @@ -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 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 cleanCustomerRelation(@RequestParam("companyId") Long companyId){ + try { + employeeService.cleanCustomerRelationBycompanyId(companyId); + return success(); + }catch (Exception e){ + log.error("清理店铺客户数据失败",e); + return fail(); + } + } /** * 下载图片 * @return diff --git a/src/main/java/com/kiisoo/ic/employee/service/EmployeeService.java b/src/main/java/com/kiisoo/ic/employee/service/EmployeeService.java index ed50795..79c721a 100644 --- a/src/main/java/com/kiisoo/ic/employee/service/EmployeeService.java +++ b/src/main/java/com/kiisoo/ic/employee/service/EmployeeService.java @@ -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 poiStores = poiStoreDOMapper.selectShopByCompany(110L); + List storeIds = poiStores.stream().map(store -> store.getId()).collect(Collectors.toList()); + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.in("store_id",storeIds); + List 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 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 relations = customerMap.get(customerId); //根据导购分组 Map> sellerMap = new HashMap<>(); - for (OpSellerCustomerRelation opSellerCustomerRelation : poiStoreStaffs) { + for (OpSellerCustomerRelation opSellerCustomerRelation : relations) { + Long sellerId = opSellerCustomerRelation.getUserId(); + if (sellerMap.get(sellerId) != null){ + List sellerRelations = sellerMap.get(sellerId); + sellerRelations.add(opSellerCustomerRelation); + }else { + List sellerRelations = new ArrayList<>(); + sellerRelations.add(opSellerCustomerRelation); + sellerMap.put(sellerId,sellerRelations); + } + } + //获取sellerId为0的分组 + List storeRelation = sellerMap.get(0L); + if (CollectionUtils.isEmpty(storeRelation)){ + continue; + } + Set sellerIds = sellerMap.keySet(); + for (Long sellerId : sellerIds){ + if (sellerId.equals(0L)){ + continue; + } + //获取导购与客户的关系 + List 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 storeQw = new QueryWrapper<>(); + storeQw.eq("code",storeCode).last("limit 1"); + PoiStore poiStore = poiStoreDOMapper.selectOne(storeQw); + QueryWrapper qw = new QueryWrapper<>(); + qw.eq("store_id",poiStore.getId()); + List poiStoreStaffs = opSellerCustomerRelationDOMapper.selectList(qw); + //同一家店根据客户分组 + Map> customerMap = new HashMap<>(); + for (OpSellerCustomerRelation opSellerCustomerRelation : poiStoreStaffs) { + Long customerId = opSellerCustomerRelation.getCustomerId(); + if (customerMap.get(customerId) != null){ + List relations = customerMap.get(customerId); + relations.add(opSellerCustomerRelation); + }else { + List relations = new ArrayList<>(); + relations.add(opSellerCustomerRelation); + customerMap.put(customerId,relations); + } + } + Set customerIds = customerMap.keySet(); + for (Long customerId:customerIds) { + List relations = customerMap.get(customerId); + //根据导购分组 + Map> sellerMap = new HashMap<>(); + for (OpSellerCustomerRelation opSellerCustomerRelation : relations) { + Long sellerId = opSellerCustomerRelation.getUserId(); + if (sellerMap.get(sellerId) != null) { + List sellerRelations = sellerMap.get(sellerId); + sellerRelations.add(opSellerCustomerRelation); + } else { + List sellerRelations = new ArrayList<>(); + sellerRelations.add(opSellerCustomerRelation); + sellerMap.put(sellerId, sellerRelations); + } + } + //获取sellerId为0的分组 + List storeRelation = sellerMap.get(0L); + if (CollectionUtils.isEmpty(storeRelation)) { + continue; + } + Set sellerIds = sellerMap.keySet(); + for (Long sellerId : sellerIds) { + if (sellerId.equals(0L)) { + continue; + } + //获取导购与客户的关系 + List 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 poiStores = poiStoreDOMapper.selectShopByCompany(companyId); + if (CollectionUtils.isNotEmpty(poiStores)) { + for (PoiStore poiStore : poiStores) { + Long storeId = poiStore.getId(); + QueryWrapper qw = new QueryWrapper<>(); + qw.eq("store_id",storeId); + List poiStoreStaffs = opSellerCustomerRelationDOMapper.selectList(qw); + //同一家店根据客户分组 + Map> customerMap = new HashMap<>(); + for (OpSellerCustomerRelation opSellerCustomerRelation : poiStoreStaffs) { + Long customerId = opSellerCustomerRelation.getCustomerId(); + if (customerMap.get(customerId) != null){ + List relations = customerMap.get(customerId); + relations.add(opSellerCustomerRelation); + }else { + List relations = new ArrayList<>(); + relations.add(opSellerCustomerRelation); + customerMap.put(customerId,relations); + } + } + Set customerIds = customerMap.keySet(); + for (Long customerId:customerIds){ + List relations = customerMap.get(customerId); + //根据导购分组 + Map> sellerMap = new HashMap<>(); + for (OpSellerCustomerRelation opSellerCustomerRelation : relations) { Long sellerId = opSellerCustomerRelation.getUserId(); if (sellerMap.get(sellerId) != null){ List sellerRelations = sellerMap.get(sellerId); diff --git a/src/main/java/com/kiisoo/ic/store/mapper/PoiStoreStaffDOMapper.java b/src/main/java/com/kiisoo/ic/store/mapper/PoiStoreStaffDOMapper.java index 896804c..be567c0 100644 --- a/src/main/java/com/kiisoo/ic/store/mapper/PoiStoreStaffDOMapper.java +++ b/src/main/java/com/kiisoo/ic/store/mapper/PoiStoreStaffDOMapper.java @@ -48,4 +48,6 @@ public interface PoiStoreStaffDOMapper extends BaseMapper { List selectInfoById(@Param("userId") Long userId); Long selectStaffIdByUserId(@Param("userId") Long userId); + + Long selectStaffIdByTag(@Param("storeId") Long store,@Param("tag") String tag); } diff --git a/src/main/resources/mapper/PrivilageUserShopRelationDOMapper.xml b/src/main/resources/mapper/PrivilageUserShopRelationDOMapper.xml index 642d465..55b4c5a 100644 --- a/src/main/resources/mapper/PrivilageUserShopRelationDOMapper.xml +++ b/src/main/resources/mapper/PrivilageUserShopRelationDOMapper.xml @@ -47,4 +47,9 @@ select id from poi_store_staff where user_id = #{userId} limit 1 + +