From 5cba1b3e7b5e758045624d8b4e5b3236ca655f77 Mon Sep 17 00:00:00 2001 From: yechenhao Date: Sun, 17 May 2020 14:00:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E5=B1=8F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customer/service/CustomerViewService.java | 130 +++++++----------- .../com/kiisoo/ic/job/CustomerDataJob.java | 2 +- 2 files changed, 52 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/kiisoo/ic/customer/service/CustomerViewService.java b/src/main/java/com/kiisoo/ic/customer/service/CustomerViewService.java index 28efd2a..34109f1 100644 --- a/src/main/java/com/kiisoo/ic/customer/service/CustomerViewService.java +++ b/src/main/java/com/kiisoo/ic/customer/service/CustomerViewService.java @@ -717,89 +717,61 @@ public class CustomerViewService { * @return */ public void syncVip() throws InterruptedException { - //初始化线程 - ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(8); - //查询现有企业微信账号 List customers = opCustomerDOMapper.selectList(null); - if (CollectionUtils.isNotEmpty(customers)){ - //分组 - final List> afterPageList = com.kiisoo.ic.utils.CollectionUtils.portListByQuantity(customers, 100); - //定义线程池长度 - int threadPoolSize = afterPageList.size(); - //定义countDownLatch - final CountDownLatch countDownLatch = new CountDownLatch(threadPoolSize); - for (int i = 0; i < afterPageList.size(); i++) { - List opCustomers = afterPageList.get(i); - newFixedThreadPool.execute(new Runnable() { - @Override - public void run() { - try { - //查询企业微信已配置联系我的用户 - for (OpCustomer customer : opCustomers) { - String wechatUniId = customer.getWechatUniId(); - if (StringUtils.isBlank(wechatUniId)){ - continue; - } - String url = ""; - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Map params = new HashMap<>(); - params.put("unionId", wechatUniId); - String message = HttpClientUtil.httpPost(vipBsdUrl + MD5FileUtil.getMD5String("BOSIDENG" + sdf.format(new Date())), JSONObject.toJSONString(params)).getMessage(); - if (StringUtils.isBlank(message)){ - continue; - } - JSONObject vipJson = JSONObject.parseObject(message); - BsdVipResponse bsdResponse = vipJson.toJavaObject(BsdVipResponse.class); - if (bsdResponse.getSuccess() && bsdResponse.getData() != null){ - MemberDtlDTO data = bsdResponse.getData(); - - OpCustomer opCustomer = new OpCustomer(data.getMemberName(), data.getMobileNo()); - opCustomer.setUpdateBy(Constants.SYS_OPERATION); - - // 根据手机号码去重 - QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq("phone", data.getMobileNo()); - OpVip opVip = opVipDOMapper.selectOne(wrapper); - OpVip opVip1 = new OpVip(); - opVip1.setStatus(1L); - opVip1.setLevel(data.getMemberLevel().toString()); - opVip1.setPhone(data.getMobileNo()); - opVip1.setName(data.getMemberName()); - opVip1.setBirthday(data.getBirthday()); - opVip1.setRegisterTime(data.getCreateDate()); - if (opVip == null) { - //数据库没有这个数据--新建数据 - opVip1.setCreateBy(Constants.SYS_OPERATION); - opVip1.setCreateTime(new Date()); - opVipDOMapper.insert(opVip1); - //有vip信息就绑定信息 - opCustomer.setMemberId(opVip1.getId()); - } else { - opVip1.setId(opVip.getId()); - opVip1.setUpdateTime(new Date()); - opVip1.setUpdateBy(Constants.SYS_OPERATION); - opVipDOMapper.updateById(opVip1); - //有vip信息就绑定信息 - opCustomer.setMemberId(opVip.getId()); - } - QueryWrapper wrapper1 = new QueryWrapper<>(); - wrapper1.eq("wechat_uni_id", wechatUniId); - opCustomerDOMapper.update(opCustomer, wrapper1); - } - - } - } catch (Exception e) { - log.error("同步会员数据", e); - } finally { - //每次减去一,避免死锁 - countDownLatch.countDown(); - } - } - }); + //查询企业微信已配置联系我的用户 + for (OpCustomer customer : customers) { + String wechatUniId = customer.getWechatUniId(); + if (StringUtils.isBlank(wechatUniId)){ + continue; + } + String url = ""; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Map params = new HashMap<>(); + params.put("unionId", wechatUniId); + String message = HttpClientUtil.httpPost(vipBsdUrl + MD5FileUtil.getMD5String("BOSIDENG" + sdf.format(new Date())), JSONObject.toJSONString(params)).getMessage(); + if (StringUtils.isBlank(message)){ + continue; + } + JSONObject vipJson = JSONObject.parseObject(message); + BsdVipResponse bsdResponse = vipJson.toJavaObject(BsdVipResponse.class); + if (bsdResponse.getSuccess() && bsdResponse.getData() != null){ + MemberDtlDTO data = bsdResponse.getData(); + + OpCustomer opCustomer = new OpCustomer(data.getMemberName(), data.getMobileNo()); + opCustomer.setUpdateBy(Constants.SYS_OPERATION); + + // 根据手机号码去重 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("phone", data.getMobileNo()); + OpVip opVip = opVipDOMapper.selectOne(wrapper); + OpVip opVip1 = new OpVip(); + opVip1.setStatus(1L); + opVip1.setLevel(data.getMemberLevel().toString()); + opVip1.setPhone(data.getMobileNo()); + opVip1.setName(data.getMemberName()); + opVip1.setBirthday(data.getBirthday()); + opVip1.setRegisterTime(data.getCreateDate()); + if (opVip == null) { + //数据库没有这个数据--新建数据 + opVip1.setCreateBy(Constants.SYS_OPERATION); + opVip1.setCreateTime(new Date()); + opVipDOMapper.insert(opVip1); + //有vip信息就绑定信息 + opCustomer.setMemberId(opVip1.getId()); + } else { + opVip1.setId(opVip.getId()); + opVip1.setUpdateTime(new Date()); + opVip1.setUpdateBy(Constants.SYS_OPERATION); + opVipDOMapper.updateById(opVip1); + //有vip信息就绑定信息 + opCustomer.setMemberId(opVip.getId()); + } + QueryWrapper wrapper1 = new QueryWrapper<>(); + wrapper1.eq("wechat_uni_id", wechatUniId); + opCustomerDOMapper.update(opCustomer, wrapper1); } - countDownLatch.await(); } } } diff --git a/src/main/java/com/kiisoo/ic/job/CustomerDataJob.java b/src/main/java/com/kiisoo/ic/job/CustomerDataJob.java index 6926e95..b84916f 100644 --- a/src/main/java/com/kiisoo/ic/job/CustomerDataJob.java +++ b/src/main/java/com/kiisoo/ic/job/CustomerDataJob.java @@ -28,7 +28,7 @@ public class CustomerDataJob { // 指定 ring buffer字节大小,必需为2的N次方(能将求模运算转为位运算提高效率 ),否则影响性能 private static final int BUFFER_SIZE = 1024 * 1024; //固定线程数 - private static final int THREAD_NUMBERS = 50; + private static final int THREAD_NUMBERS = 30; @Autowired