From 970dbe0b57be55160d569ee84d8de32b8953624e Mon Sep 17 00:00:00 2001 From: yechenhao Date: Mon, 25 May 2020 10:53:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=AE=A2=E6=88=B7=E5=AF=BC?= =?UTF-8?q?=E8=B4=AD=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kiisoo/ic/customer/CustomerService.java | 147 +++++++++--------- 1 file changed, 77 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/kiisoo/ic/customer/CustomerService.java b/src/main/java/com/kiisoo/ic/customer/CustomerService.java index 2e1ca2c..7f7c68d 100644 --- a/src/main/java/com/kiisoo/ic/customer/CustomerService.java +++ b/src/main/java/com/kiisoo/ic/customer/CustomerService.java @@ -177,10 +177,10 @@ public class CustomerService { public void turnBack(TurnBackDTO turnBackDTOS) throws Exception { String eaCode = turnBackDTOS.getEaCode(); // 判断是否是活动扫码 - if(eaCode.contains(Constants.ACTIVITY_QR_CODE_PREFIX)){ + if (eaCode.contains(Constants.ACTIVITY_QR_CODE_PREFIX)) { // 活动码处理 handleActivity(turnBackDTOS, eaCode); - }else{ + } else { // 导购码处理 handleCustomer(turnBackDTOS); } @@ -188,10 +188,11 @@ public class CustomerService { /** * 活动码处理 + * * @param turnBackDTOS 回调对象 - * @param eaCode 二维码的state字段 + * @param eaCode 二维码的state字段 */ - private void handleActivity(TurnBackDTO turnBackDTOS, String eaCode){ + private void handleActivity(TurnBackDTO turnBackDTOS, String eaCode) { String[] strArr = eaCode.split(Constants.LINE); Long instanceId = Long.parseLong(strArr[1]); int type = Integer.parseInt(strArr[2]); @@ -202,41 +203,43 @@ public class CustomerService { /** * 处理客户扫码回调的方法 + * * @param turnBackDTOS 回调对象 */ private void handleCustomer(TurnBackDTO turnBackDTOS) throws Exception { // 判断是1添加、2、删除 - if(null == turnBackDTOS.getOpType()){ + if (null == turnBackDTOS.getOpType()) { turnBackDTOS.setOpType(1); } - if(TurnBackDTO.OP_TYPE_DEL.equals(turnBackDTOS.getOpType())){ + if (TurnBackDTO.OP_TYPE_DEL.equals(turnBackDTOS.getOpType())) { handleDelCustomer(turnBackDTOS); - }else{ + } else { handleAddCustomer(turnBackDTOS); } } /** * 添加客户的处理 + * * @param turnBackDTOS 回调对象 * @throws Exception 异常 * @author dexiang.jiang * @date 2020/05/24 13:46 */ - private void handleAddCustomer (TurnBackDTO turnBackDTOS) throws Exception { + private void handleAddCustomer(TurnBackDTO turnBackDTOS) throws Exception { OpCustomer opCustomer = null; if (turnBackDTOS.getWxData().getUnionId() == null && turnBackDTOS.getWxData().getUserId() != null) { //此时说明是企业微信扫码添加 QueryWrapper customerWrapper = new QueryWrapper<>(); customerWrapper.eq("external_userid", turnBackDTOS.getWxData().getUserId()).last("limit 1"); opCustomer = opCustomerDOMapper.selectOne(customerWrapper); - }else if (turnBackDTOS.getWxData().getUnionId() != null && turnBackDTOS.getUserId() != null){ + } else if (turnBackDTOS.getWxData().getUnionId() != null && turnBackDTOS.getUserId() != null) { //客户信息 QueryWrapper customerWrapper = new QueryWrapper<>(); customerWrapper.eq("wechat_uni_id", turnBackDTOS.getWxData().getUnionId()).last("limit 1"); opCustomer = opCustomerDOMapper.selectOne(customerWrapper); - }else{ + } else { log.error("turn back error: " + turnBackDTOS.toString()); return; } @@ -253,16 +256,16 @@ public class CustomerService { if (!turnBackDTOS.getEaCode().equals("") && !turnBackDTOS.getEaCode().equals("0")) { //导购信息 QueryWrapper wrapper = new QueryWrapper<>(); - if (turnBackDTOS.getEaCode().matches("导购(.*)")){ - wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status","1").last("limit 1"); - }else{ - wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status","1").eq("store_id", poiStore.getStoreId()).last("limit 1"); + if (turnBackDTOS.getEaCode().matches("导购(.*)")) { + wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status", "1").last("limit 1"); + } else { + wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status", "1").eq("store_id", poiStore.getStoreId()).last("limit 1"); } poiStoreStaff = poiStoreStaffDOMapper.selectOne(wrapper); - }else{ + } else { turnBackDTOS.setEaCode(turnBackDTOS.getUserId()); QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("staff_code", turnBackDTOS.getUserId()).eq("status","1").eq("store_id", poiStore.getStoreId()).last("limit 1"); + wrapper.eq("staff_code", turnBackDTOS.getUserId()).eq("status", "1").eq("store_id", poiStore.getStoreId()).last("limit 1"); poiStoreStaff = poiStoreStaffDOMapper.selectOne(wrapper); } @@ -275,13 +278,14 @@ public class CustomerService { insertCustomer.setExternalUserid(turnBackDTOS.getWxData().getUserId()); insertCustomer.setCpUserId(turnBackDTOS.getUserId()); insertCustomer.setPhone(turnBackDTOS.getPhone()); - if (shop != null && StringUtils.isNotBlank(shop.getName())){ + if (shop != null && StringUtils.isNotBlank(shop.getName())) { insertCustomer.setShopName(shop.getName()); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - if (turnBackDTOS.getJoinTime() != null){ + if (StringUtils.isNotBlank(turnBackDTOS.getJoinTime())) { insertCustomer.setCreateTime(sdf.parse(turnBackDTOS.getJoinTime())); - }else{ + } else { + log.error("没有jointime"+new Gson().toJson(turnBackDTOS)); return; } if (null != opCustomer) { @@ -289,23 +293,23 @@ public class CustomerService { insertCustomer.setId(opCustomer.getId()); try { opCustomerDOMapper.updateById(insertCustomer); - }catch (Exception e) { - log.error(insertCustomer.toString(),e); + } catch (Exception e) { + log.error(insertCustomer.toString(), e); return; } if (poiStoreStaff != null) { //存在--1.处理客户导购关系。 try { sellerCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId()); - }catch (Exception e) { - log.error(insertCustomer.toString(),e); + } catch (Exception e) { + log.error(insertCustomer.toString(), e); return; } } else { try { - storeCustomerRelation(insertCustomer,sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId()); - }catch (Exception e) { - log.error(insertCustomer.toString(),e); + storeCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId()); + } catch (Exception e) { + log.error(insertCustomer.toString(), e); return; } } @@ -314,8 +318,8 @@ public class CustomerService { //不存在 try { opCustomerDOMapper.insert(insertCustomer); - }catch (Exception e) { - log.error(insertCustomer.toString(),e); + } catch (Exception e) { + log.error(insertCustomer.toString(), e); return; } @@ -323,15 +327,15 @@ public class CustomerService { //添加关系 try { sellerCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId()); - }catch (Exception e) { - log.error(insertCustomer.toString(),e); + } catch (Exception e) { + log.error(insertCustomer.toString(), e); return; } } else { try { - storeCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()),poiStore.getStoreId()); - }catch (Exception e) { - log.error(insertCustomer.toString(),e); + storeCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId()); + } catch (Exception e) { + log.error(insertCustomer.toString(), e); return; } } @@ -346,46 +350,47 @@ public class CustomerService { /** * 删除客户的处理 + * * @param turnBackDTOS 回调对象 * @throws Exception 异常 * @author dexiang.jiang * @date 2020/05/24 13:46 */ - private void handleDelCustomer (TurnBackDTO turnBackDTOS) { + private void handleDelCustomer(TurnBackDTO turnBackDTOS) { String customerUserId = turnBackDTOS.getWxData().getUserId(); - if (StringUtils.isBlank(customerUserId)){ + if (StringUtils.isBlank(customerUserId)) { return; } - privilageCpUserDOMapper.deleteCount(customerUserId,turnBackDTOS.getUserId()); + privilageCpUserDOMapper.deleteCount(customerUserId, turnBackDTOS.getUserId()); QueryWrapper customerQw = new QueryWrapper<>(); - customerQw.eq("external_userid",customerUserId).last("limit 1"); + customerQw.eq("external_userid", customerUserId).last("limit 1"); OpCustomer customer = opCustomerDOMapper.selectOne(customerQw); - if (customer == null){ + if (customer == null) { return; } //店铺信息 PrivilageCpUserStoreDO poiStore = privilageCpUserStoreDOMapper.selectOneCpUser(turnBackDTOS.getUserId()); if (null == poiStore) { QueryWrapper cpUserQw = new QueryWrapper<>(); - cpUserQw.eq("cp_user_id",turnBackDTOS.getUserId()).last("limit 1"); + cpUserQw.eq("cp_user_id", turnBackDTOS.getUserId()).last("limit 1"); PrivilageCpUserDO privilageCpUserDO = privilageCpUserDOMapper.selectOne(cpUserQw); QueryWrapper relationQw = new QueryWrapper<>(); - relationQw.eq("customer_id",customer.getId()).eq("user_id",privilageCpUserDO.getId()).eq("type",3); + relationQw.eq("customer_id", customer.getId()).eq("user_id", privilageCpUserDO.getId()).eq("type", 3); privilageCpUserStoreDOMapper.delete(relationQw); - }else{ + } else { String eaCode = turnBackDTOS.getEaCode(); PoiStoreStaff staff; QueryWrapper staffQw = new QueryWrapper<>(); - if (StringUtils.isNotBlank(eaCode) && !"0".equals(eaCode)){ - staffQw.eq("staff_code",eaCode).eq("type",4).eq("store_id",poiStore.getStoreId()).last("limit 1"); + if (StringUtils.isNotBlank(eaCode) && !"0".equals(eaCode)) { + staffQw.eq("staff_code", eaCode).eq("type", 4).eq("store_id", poiStore.getStoreId()).last("limit 1"); staff = poiStoreStaffDOMapper.selectOne(staffQw); - }else{ - staffQw.eq("staff_code",turnBackDTOS.getUserId()).eq("type",1).eq("store_id",poiStore.getStoreId()).last("limit 1"); + } else { + staffQw.eq("staff_code", turnBackDTOS.getUserId()).eq("type", 1).eq("store_id", poiStore.getStoreId()).last("limit 1"); staff = poiStoreStaffDOMapper.selectOne(staffQw); } QueryWrapper relationQw = new QueryWrapper<>(); - relationQw.eq("customer_id",customer.getId()).eq("user_id",staff.getId()); + relationQw.eq("customer_id", customer.getId()).eq("user_id", staff.getId()); privilageCpUserStoreDOMapper.delete(relationQw); } } @@ -427,9 +432,9 @@ public class CustomerService { opCustomer.setMemberId(opVip.getId()); } QueryWrapper wrapper1 = new QueryWrapper<>(); - if (turnBackDTO.getType() == 1){ + if (turnBackDTO.getType() == 1) { wrapper1.eq("wechat_uni_id", turnBackDTO.getWxData().getUnionId()); - }else{ + } else { wrapper1.eq("external_userid", turnBackDTO.getWxData().getUserId()); } opCustomerDOMapper.update(opCustomer, wrapper1); @@ -437,6 +442,7 @@ public class CustomerService { /** * 处理客户和导购的关系 + * * @param opCustomer * @param joinTime * @param shopId @@ -472,7 +478,7 @@ public class CustomerService { insertRelation.setType(2); } opSellerCustomerRelationDOMapper.insert(insertRelation); - }else{ + } else { //可能是同步过来的数据,此时已经存在的话,用有导购的代替 opSellerCustomerRelation.setCreateTime(joinTime); opSellerCustomerRelation.setUpdateTime(new Date()); @@ -487,7 +493,7 @@ public class CustomerService { } @Transactional(rollbackFor = Exception.class) - public void storeCustomerRelation(OpCustomer opCustomer, Date joinTime,long shopId) { + public void storeCustomerRelation(OpCustomer opCustomer, Date joinTime, long shopId) { QueryWrapper wrapper1 = new QueryWrapper<>(); wrapper1.eq("customer_id", opCustomer.getId()).eq("store_id", shopId).last("limit 1"); OpSellerCustomerRelation opSellerCustomerRelation = opSellerCustomerRelationDOMapper.selectOne(wrapper1); @@ -514,13 +520,13 @@ public class CustomerService { //无效 insertRelation.setType(2); } - if (shopId == 0L){ + if (shopId == 0L) { QueryWrapper cpQw = new QueryWrapper<>(); - cpQw.eq("cp_user_id",opCustomer.getCpUserId()).last("limit 1"); + cpQw.eq("cp_user_id", opCustomer.getCpUserId()).last("limit 1"); PrivilageCpUserDO privilageCpUserDO = privilageCpUserDOMapper.selectOne(cpQw); - if (privilageCpUserDO!=null){ + if (privilageCpUserDO != null) { insertRelation.setUserId(privilageCpUserDO.getId()); - }else{ + } else { privilageCpUserDO = new PrivilageCpUserDO(); privilageCpUserDO.setCpUserId(opCustomer.getCpUserId()); privilageCpUserDO.setStatus(1); @@ -628,14 +634,15 @@ public class CustomerService { /** * 查询好友列表,可根据导购、日期、搜索 - * @param userId 用户ID - * @param sellerId 导购ID - * @param search 搜索内容 - * @param roleCode 角色编码 - * @param type 会员与非会员类型 + * + * @param userId 用户ID + * @param sellerId 导购ID + * @param search 搜索内容 + * @param roleCode 角色编码 + * @param type 会员与非会员类型 * @param startDate 开始日期 - * @param endDate 结束日期 - * @param flag 0、新增好友 1、累计好友 + * @param endDate 结束日期 + * @param flag 0、新增好友 1、累计好友 * @return 返回数据集合 * @throws Exception 异常 * @author dexiang.jiang @@ -653,34 +660,34 @@ public class CustomerService { PageHelper.startPage(pageNum, pageSize); if (roleCode.equals(RoleEnum.ROLE_CODE_DZ.getRoleCode())) { // 0、新增好友 1、累计好友 - if(flag == 0){ + if (flag == 0) { thisList = opSellerCustomerRelationDOMapper.selectFriendListByShopId(shopId, sellerId, search, startDate, endDate, type); - }else{ + } else { thisList = opSellerCustomerRelationDOMapper.selectFriendListByShopIdAndDate(shopId, sellerId, search, startDate, endDate, type); } - if(CollectionUtils.isNotEmpty(thisList)){ + if (CollectionUtils.isNotEmpty(thisList)) { for (int i = 0; i < thisList.size(); i++) { // 设置导购名称 - if(!thisList.get(i).getInviteSellerId().equals(0L)){ + if (!thisList.get(i).getInviteSellerId().equals(0L)) { Map map = new HashMap<>(); map.put("id", thisList.get(i).getInviteSellerId()); String userName = poiStoreStaffDOMapper.selectUserNameById(thisList.get(i).getInviteSellerId()); - if(StringUtils.isNotEmpty(userName)){ + if (StringUtils.isNotEmpty(userName)) { thisList.get(i).setInviteSellerName(userName); - }else{ + } else { thisList.get(i).setInviteSellerName(""); } - }else{ + } else { thisList.get(i).setInviteSellerName(""); } } } } else { // 0、新增好友 1、累计好友 - if(flag == 0){ + if (flag == 0) { thisList = opSellerCustomerRelationDOMapper.selectFriendListBySeller(userId, search, startDate, endDate, type); - }else{ + } else { thisList = opSellerCustomerRelationDOMapper.selectFriendListBySellerAndDate(userId, search, startDate, endDate, type); } }