阅读列表:
一、 在线客户导入EC系统
二、 本地导入EC客户
三、 本地放弃客户(手机号)
四、 本地放弃客户(客户ID)
五、 从EC系统中获取客户信息并存储到本地
一、 在线客户导入EC系统


/** * 在线客户导入EC系统 * * @param model * @param pageNoStr * @param userAccount * @param userRealname * @param signCode * @param channel * @param startTime * @param endTime * @return */ @RequestMapping(value = "/list") public String userList(Model model, @RequestParam(required = false, value = "pageNo", defaultValue = "") String pageNoStr, @RequestParam(required = false, value = "userAccount", defaultValue = "") String userAccount, @RequestParam(required = false, value = "userRealname", defaultValue = "") String userRealname, @RequestParam(required = false, value = "signCode", defaultValue = "") String signCode, @RequestParam(required = false, value = "channel", defaultValue = "") String channel, @RequestParam(required = false, value = "startTime", defaultValue = "") String startTime, @RequestParam(required = false, value = "endTime", defaultValue = "") String endTime, @RequestParam(required = false, value = "isInvest", defaultValue = "") String isInvest) { // 判断是否是guest账户 boolean isGuest = RoleUtils.isGuest(adminService, roleService); // 请求参数校验和封装 Pager pager = new Pager(); MapparamMap = new HashMap (); if (StringUtils.isNotEmpty(pageNoStr)) { pageNoStr = pageNoStr.replace(",", ""); pager.setPageNo(Integer.parseInt(pageNoStr)); } if (StringUtils.isNotEmpty(userAccount)) { paramMap.put("userAccount", userAccount); } else { paramMap.put("userAccount", null); } if (StringUtils.isNotEmpty(userRealname)) { paramMap.put("userRealname", userRealname); } else { paramMap.put("userRealname", null); } if (StringUtils.isNotEmpty(signCode)) { paramMap.put("signCode", signCode); } else { paramMap.put("signCode", null); } if (StringUtils.isNotEmpty(channel)) { paramMap.put("channel", channel); } else { paramMap.put("channel", null); } if (StringUtils.isNotEmpty(startTime)) { paramMap.put("startTime", startTime); } else { paramMap.put("startTime", null); } if (StringUtils.isNotEmpty(endTime)) { paramMap.put("endTime", endTime); } else { paramMap.put("endTime", null); } if (StringUtils.isNotEmpty(isInvest)) { paramMap.put("isInvest", isInvest); } else { paramMap.put("isInvest", null); } pager.setCondition(paramMap); List results = userService.findList(pager); // 获取所有渠道列表 List channelList = channelService.findChannelList1(); pager.setResult(results); model.addAttribute("pager", pager); model.addAttribute("userAccount", userAccount); model.addAttribute("userRealname", userRealname); model.addAttribute("signCode", signCode); model.addAttribute("channel", channel); model.addAttribute("startTime", startTime); model.addAttribute("endTime", endTime); model.addAttribute("channelList", channelList); model.addAttribute("isGuest", isGuest); model.addAttribute("isInvest", isInvest); return "/user/list"; } /** * EC客户批量导入 * * @param model * @param pageNoStr * @param userAccount * @param userRealname * @param signCode * @param channel * @param startTime * @param endTime * @return */ @RequestMapping(value = "/ecImport") @ResponseBody public Map ecImport(Model model, @RequestParam(required = false, value = "pageNo", defaultValue = "") String pageNoStr, @RequestParam(required = false, value = "userAccount", defaultValue = "") String userAccount, @RequestParam(required = false, value = "userRealname", defaultValue = "") String userRealname, @RequestParam(required = false, value = "signCode", defaultValue = "") String signCode, @RequestParam(required = false, value = "channel", defaultValue = "") String channel, @RequestParam(required = false, value = "startTime", defaultValue = "") String startTime, @RequestParam(required = false, value = "endTime", defaultValue = "") String endTime, @RequestParam(required = false, value = "isInvest", defaultValue = "") String isInvest) { // 请求结果 Map resultMap = new HashMap<>(); try { // 请求参数校验和封装 Pager pager = new Pager(); Map paramMap = new HashMap (); if (StringUtils.isNotEmpty(pageNoStr)) { pageNoStr = pageNoStr.replace(",", ""); pager.setPageNo(Integer.parseInt(pageNoStr)); } if (StringUtils.isNotEmpty(userAccount)) { paramMap.put("userAccount", userAccount); } else { paramMap.put("userAccount", null); } if (StringUtils.isNotEmpty(userRealname)) { paramMap.put("userRealname", userRealname); } else { paramMap.put("userRealname", null); } if (StringUtils.isNotEmpty(signCode)) { paramMap.put("signCode", signCode); } else { paramMap.put("signCode", null); } if (StringUtils.isNotEmpty(channel)) { paramMap.put("channel", channel); } else { paramMap.put("channel", null); } if (StringUtils.isNotEmpty(startTime)) { paramMap.put("startTime", startTime); } else { paramMap.put("startTime", null); } if (StringUtils.isNotEmpty(endTime)) { paramMap.put("endTime", endTime); } else { paramMap.put("endTime", null); } if (StringUtils.isNotEmpty(isInvest)) { paramMap.put("isInvest", isInvest); } else { paramMap.put("isInvest", null); } pager.setPageSize(99999999); pager.setCondition(paramMap); // 导入客户列表 List userList = userService.findList(pager); // 判断手机号在本地系统是否存在 List userList_ = new LinkedList<>(); for (UserVo u: userList) { ECCustomer customer = ecCustomerService.findECCustomerByMobile(u.getUserAccount()); if (customer == null) { userList_.add(u); } } // 批量创建客户 Map _resultMap = addCustomer(userList_); if(_resultMap.get("success").equals(false)) { resultMap.put("success", false); resultMap.put("message", _resultMap.get("message")); return resultMap; } } catch(Exception e) { e.printStackTrace(); resultMap.put("success", false); resultMap.put("message", "EC客户导入失败"); return resultMap; } resultMap.put("success", true); resultMap.put("message", "EC客户导入成功"); return resultMap; } /** * EC创建客户 * */ public Map addCustomer(List userList) { // 请求结果 Map resultMap = new HashMap<>(); // 判断注册人是否为空 if(null == userList || userList.size() == 0) { resultMap.put("success", false); resultMap.put("message", "客户为空"); return resultMap; } // ------------------------------------------------- // 批量创建客户 // ------------------------------------------------- Map userDataMap = new HashMap<>(); List fieldNameMapping = new ArrayList (); fieldNameMapping.add("f_name"); // 用户名 fieldNameMapping.add("f_mobile"); // 手机号 fieldNameMapping.add("f_title"); // 来源 fieldNameMapping.add("f_memo"); // 备注 fieldNameMapping.add("f_gender"); // 性别:0无/1/男/2女 fieldNameMapping.add("f_birthday"); // 生日: 1988-03-24 userDataMap.put("fieldNameMapping", fieldNameMapping); // 插入字段名集合 List
二、 本地导入EC客户


/** * 本地导入EC客户 * * @param args * @throws IOException */ public static void main1(String[] args) throws IOException { // ---------------------------------------------------------------------------------------------- // EC更新客户资料 // ---------------------------------------------------------------------------------------------- ListphoneList = new ArrayList<>(); // 手机号集 List existPhoneList = new ArrayList<>(); // 已存在手机号集 List notExistPhoneList = new ArrayList<>(); // 不存在手机号集 // 读取数据 InputStreamReader isr = new FileReader("C:\\Users\\Administrator\\Desktop\\EC处理\\tmp.txt"); BufferedReader reader = new BufferedReader(isr); String line = ""; while ((line = reader.readLine())!=null) { phoneList.add(line.trim()); } reader.close(); System.out.println(phoneList.size()); // 判断手机号在本地系统是否存在 List phoneList_ = new LinkedList<>(); for (String p: phoneList) { ECCustomer customer = ecCustomerService.findECCustomerByMobile(p.trim()); if (customer == null) { phoneList_.add(u); } } // 判断手机号是否存在 for (String phone: phoneList_) { Map phonedataMap = new HashMap<>(); List
三、 本地放弃客户(手机号)


/** * 放弃客户 * * @param args * @throws IOException */ @Test public void abandon() throws IOException { // 批量放弃客户 MapdataMap = new HashMap<>(); dataMap.put("userId", "6517859"); // 操作人ID List mobiles = new ArrayList<>(); // 手机号集 Map resultMap = new HashMap<>(); // 返回结果 // 读取数据 InputStreamReader isr = new FileReader("C:\\Users\\Administrator\\Desktop\\已投资名单.txt"); BufferedReader reader = new BufferedReader(isr); String line = ""; while ((line = reader.readLine())!=null) { mobiles.add(line.trim()); } reader.close(); System.out.println(mobiles.size()); // 发送请求 dataMap.put("mobiles", mobiles); resultMap = EcUtils.abandon(dataMap); // 返回结果 int errCode = (Integer)resultMap.get("errCode"); // 返回码 String errMsg = (String)resultMap.get("errMsg"); // 返回信息 // 打印信息 System.out.println("errCode: " + errCode + "\n" + "errMsg: " + errMsg + "\n"); }
四、 本地放弃客户(客户ID)


/** * 放弃客户 * * @param args * @throws IOException */ @Test public void abandon() throws IOException { // 批量放弃客户 MapdataMap = new HashMap<>(); dataMap.put("userId", "6517859"); // 操作人ID List crmIds = new ArrayList<>(); // 客户ID集 Map resultMap = new HashMap<>(); // 返回结果 // 读取数据 InputStreamReader isr = new FileReader("C:\\Users\\Administrator\\Desktop\\已投资名单.txt"); BufferedReader reader = new BufferedReader(isr); String line = ""; while ((line = reader.readLine())!=null) { crmIds.add(line.trim()); } reader.close(); System.out.println(crmIds.size()); // 发送请求 dataMap.put("crmIds", crmIds); resultMap = EcUtils.abandon(dataMap); // 返回结果 int errCode = (Integer)resultMap.get("errCode"); // 返回码 String errMsg = (String)resultMap.get("errMsg"); // 返回信息 // 打印信息 System.out.println("errCode: " + errCode + "\n" + "errMsg: " + errMsg + "\n"); }
五、 从EC系统中获取客户信息并存储到本地


/** * 从EC中获取客户信息并存储到本地 * */ @RequestMapping(value = "/list") public String userList(Model model, @RequestParam(required = false, value = "pageNo", defaultValue = "") String pageNoStr, @RequestParam(required = false, value = "userAccount", defaultValue = "") String userAccount, @RequestParam(required = false, value = "userRealname", defaultValue = "") String userRealname, @RequestParam(required = false, value = "signCode", defaultValue = "") String signCode, @RequestParam(required = false, value = "channel", defaultValue = "") String channel, @RequestParam(required = false, value = "startTime", defaultValue = "") String startTime, @RequestParam(required = false, value = "endTime", defaultValue = "") String endTime) throws IOException { // EC客户创建时间 String[] cts = new String[6]; cts[0] = "2017-12-01 00:00:00;2018-01-01 00:00:00"; cts[1] = "2018-01-01 00:00:00;2018-02-01 00:00:00"; cts[2] = "2018-02-01 00:00:00;2018-03-01 00:00:00"; cts[3] = "2018-03-01 00:00:00;2018-04-01 00:00:00"; cts[4] = "2018-04-01 00:00:00;2018-05-01 00:00:00"; cts[5] = "2018-05-01 00:00:00;2018-06-01 00:00:00"; for (String ct: cts) { MapdataMap = new HashMap<>(); dataMap.put("createTime", ct); // 客户创建的开始时间和结束时间(间隔不能超过31天) dataMap.put("lastCrmId", "0"); // 根据此参数来进行翻页,必填。上一次请求得到的最后一条记录中的crmId,初始值为0。 Map resultMap = EcUtils.rangeQueryCustomer(dataMap); // data JSONObject data = (JSONObject)resultMap.get("data"); JSONArray crmDetails = (JSONArray)data.get("crmDetails"); // 获取分页信息 int total = (int)data.get("total"); // 总记录数 int pageSize = (int)data.get("pageSize"); // 每页显示条数 int maxPageNo = (int)data.get("maxPageNo"); // 最大页数 int pageNo = (int)data.get("pageNo"); // 当前页 System.out.println("total: " + total + "\n" + "pageSize: " + pageSize + "\n" + "maxPageNo: " + maxPageNo + "\n" + "pageNo: " + pageNo + "\n"); // 获取当前页所有客户信息 List firstCustomerList = new ArrayList<>(); for (int i = 0; i < crmDetails.size(); i++) { JSONObject customer = crmDetails.getJSONObject(i); ECCustomer ecCustomer = new ECCustomer(); int crmId = (int)customer.get("crmId"); // 客户id String name = (String)customer.get("name"); // 客户姓名 String mobile = (String)customer.get("mobile"); // 客户手机号: +8618645190586 // 绑卡状态:0.未绑卡;1.已绑卡 int bindcardStatus = 0; // 交易状态:0.未投资;1.已投资 int tradeStatus = 0; // 用户状态:0.有效;1.失效 int delStatus = 0; int followUserId = (int)customer.get("followUserId"); // 跟进人id // // --------------------------------------------------- // // 获取跟进人姓名 // // --------------------------------------------------- // Map dataMap_ = new HashMap<>(); // dataMap_.put("userId", followUserId + ""); // 跟进人ID // // MapresultMap_ = EcUtils.findUserInfoById(dataMap_); // // JSONObject data_ = (JSONObject)resultMap_.get("data"); // String followUserName = (String)data_.get("f_name"); // 跟进人姓名 String optUserName = "技术人员"; // 操作人姓名 String optBatch = getOptBatch(); // 分配批次 String createTime = (String)customer.get("createTime"); // 分配时间 // 手机号做截位处理 if (StringUtils.isNotEmpty(mobile)) { mobile = mobile.substring(3); } // 封装客户信息 ecCustomer.setCrmId(crmId); ecCustomer.setName(name); ecCustomer.setMobile(mobile); ecCustomer.setBindcardStatus(bindcardStatus); ecCustomer.setTradeStatus(tradeStatus); ecCustomer.setDelStatus(delStatus); ecCustomer.setFollowUserId(followUserId); // ecCustomer.setFollowUserName(followUserName); ecCustomer.setFollowUserName(""); ecCustomer.setOptUserName(optUserName); ecCustomer.setOptBatch(optBatch); ecCustomer.setCreateTime(Timestamp.valueOf(createTime)); ecCustomer.setRemark("电销四月份提成专用"); firstCustomerList.add(ecCustomer); } // 获取当前页最后一位客户 JSONObject lastCustomer = crmDetails.getJSONObject(crmDetails.size() - 1); int crmId = (int)lastCustomer.get("crmId"); // 客户id int followUserId = (int)lastCustomer.get("followUserId"); // 跟进人id String createTime = (String)lastCustomer.get("createTime"); // 创建客户时间 String name = (String)lastCustomer.get("name"); // 客户姓名 String mobile = (String)lastCustomer.get("mobile"); // 客户手机号 // 打印当前页最后一位客户信息 System.out.println("crmId: " + crmId + "\n" + "followUserId: " + followUserId + "\n" + "createTime: " + createTime + "\n" + "name: " + name + "\n" + "mobile: " + mobile + "\n"); // 遍历第二页以后所有客户信息 ListsurplusCustomerList = new ArrayList<>(); int lastCrmId = (int)lastCustomer.get("crmId"); // 上一页最后一位客户crmId while (maxPageNo > 1) { Map _dataMap = new HashMap<>(); _dataMap.put("createTime", ct); // 客户创建的开始时间和结束时间(间隔不能超过31天) _dataMap.put("lastCrmId", lastCrmId); // 根据此参数来进行翻页,必填。上一次请求得到的最后一条记录中的crmId,初始值为0。 Map _resultMap = EcUtils.rangeQueryCustomer(_dataMap); // data JSONObject _data = (JSONObject)_resultMap.get("data"); JSONArray _crmDetails = (JSONArray)_data.get("crmDetails"); // 获取当前页所有客户信息 for (int i = 0; i < _crmDetails.size(); i++) { JSONObject _customer = _crmDetails.getJSONObject(i); ECCustomer _ecCustomer = new ECCustomer(); int _crmId = (int)_customer.get("crmId"); // 客户id String _name = (String)_customer.get("name"); // 客户姓名 String _mobile = (String)_customer.get("mobile"); // 客户手机号: +8618645190586 // 绑卡状态:0.未绑卡;1.已绑卡 int _bindcardStatus = 0; // 交易状态:0.未投资;1.已投资 int _tradeStatus = 0; // 用户状态:0.有效;1.失效 int _delStatus = 0; int _followUserId = (int)_customer.get("followUserId"); // 跟进人id // // --------------------------------------------------- // // 获取跟进人姓名 // // --------------------------------------------------- // Map dataMap_ = new HashMap<>(); // dataMap_.put("userId", _followUserId + ""); // 跟进人ID // // MapresultMap_ = EcUtils.findUserInfoById(dataMap_); // // JSONObject data_ = (JSONObject)resultMap_.get("data"); // String _followUserName = (String)data_.get("f_name"); // 跟进人姓名 String _optUserName = "技术人员"; // 操作人姓名 String _optBatch = getOptBatch(); // 分配批次 String _createTime = (String)_customer.get("createTime"); // 分配时间 // 手机号做截位处理 if (StringUtils.isNotEmpty(_mobile)) { _mobile = _mobile.substring(3); } // 封装客户信息 _ecCustomer.setCrmId(_crmId); _ecCustomer.setName(_name); _ecCustomer.setMobile(_mobile); _ecCustomer.setBindcardStatus(_bindcardStatus); _ecCustomer.setTradeStatus(_tradeStatus); _ecCustomer.setDelStatus(_delStatus); _ecCustomer.setFollowUserId(_followUserId); // _ecCustomer.setFollowUserName(_followUserName); _ecCustomer.setFollowUserName(""); _ecCustomer.setOptUserName(_optUserName); _ecCustomer.setOptBatch(_optBatch); _ecCustomer.setCreateTime(Timestamp.valueOf(_createTime)); _ecCustomer.setRemark("电销四月份提成专用"); surplusCustomerList.add(_ecCustomer); } // 获取当前页最后一位客户 JSONObject _lastCustomer = _crmDetails.getJSONObject(_crmDetails.size() - 1); lastCrmId = (int)_lastCustomer.get("crmId"); // 最大页数重置 maxPageNo = (int)_data.get("maxPageNo"); // 最大页数 } // 所有用户 ListallCustomerList = new ArrayList<>(); List allCustomerListCopy = new ArrayList<>(); allCustomerListCopy.addAll(firstCustomerList); allCustomerListCopy.addAll(surplusCustomerList); // 判断手机号在本地系统是否存在 for (ECCustomer e: allCustomerListCopy) { ECCustomer customerN = ecCustomerService.findECCustomerByMobile(e.getName()); ECCustomer customerM = ecCustomerService.findECCustomerByMobile(e.getMobile()); if (customerN == null && customerM == null) { allCustomerList.add(e); } } // 保存所有用户信息 // 50一组插入 int groups = (int)Math.ceil(allCustomerList.size() / 50.0); int index = 0; int endIndex = 0; int sucTimes = 0; for (int i = 0; i < groups; i++) { List tmpCustomerList = new ArrayList<>(); endIndex = (i + 1) * 50; if (i == groups - 1) { endIndex = allCustomerList.size(); } for (int j = index; j < endIndex; j++) { tmpCustomerList.add(allCustomerList.get(j)); } // 保存EC客户信息 ecCustomerService.save(tmpCustomerList); index = endIndex; sucTimes++; System.out.println(sucTimes + "次插入成功"); } } return "/user/list"; } /** * 根据当前时间生成分配批次: 201804201704 * * @return */ public static String getOptBatch() { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date now = new Date(); String strNow = dateFormat.format(now); // 2018-04-10 16:56:20 // 生成分配批次 StringBuilder sb = new StringBuilder(); String day = strNow.split(" ")[0]; String hour = strNow.split(" ")[1]; for (String s: day.split("-")) { sb.append(s); } for (String s: hour.split(":")) { sb.append(s); } String optBatch = sb.toString().substring(0, sb.toString().length() - 2); // 返回分配批次 return optBatch; }
六、 本地更新EC客户资料(手机号)


1 /** 2 * 更新客户资料(手机号) 3 * 4 * @param args 5 * @throws IOException 6 */ 7 public static void main3(String[] args) throws IOException { 8 9 // 定义客户ID集 10 ListcrmIds = new ArrayList<>(); 11 // 定义客户手机号集 12 List mobiles = new ArrayList<>(); 13 14 // // 读取客户ID 15 // InputStreamReader isr = new FileReader("C:\\Users\\Administrator\\Desktop\\最后一次\\客户ID.txt"); 16 // BufferedReader reader = new BufferedReader(isr); 17 // String line = ""; 18 // while ((line = reader.readLine())!=null) { 19 // crmIds.add(line.trim()); 20 // } 21 // reader.close(); 22 crmIds.add("1251476745"); 23 crmIds.add("1251493493"); 24 25 // // 读取手机号 26 // InputStreamReader isr_ = new FileReader("C:\\Users\\Administrator\\Desktop\\最后一次\\客户手机号.txt"); 27 // BufferedReader reader_ = new BufferedReader(isr_); 28 // String line_ = ""; 29 // while ((line_ = reader_.readLine())!=null) { 30 // mobiles.add(line_.trim()); 31 // } 32 // reader_.close(); 33 mobiles.add("15730786278"); 34 mobiles.add("18704237885"); 35 36 // 遍历客户ID 37 int index = 0; 38 for (String crmId: crmIds) { 39 String mobile = mobiles.get(index); 40 index++; 41 42 // --------------------------------------------------------------------------------- 43 // 修改客户资料:updateCustomer() 44 // --------------------------------------------------------------------------------- 45 Map dataMap = new HashMap (); 46 dataMap.put("optUserId","6517859"); // 操作人ID 47 dataMap.put("crmId",crmId); // 客户ID 48 dataMap.put("f_mobile",mobile); // 手机号码(会校验是否重复) 49 50 updateCustomer(dataMap); 51 52 } 53 54 55 }