大屏接口

dev_0531
yechenhao 6 years ago
parent fb0570eeb5
commit 5cba1b3e7b

@ -717,89 +717,61 @@ public class CustomerViewService {
* @return * @return
*/ */
public void syncVip() throws InterruptedException { public void syncVip() throws InterruptedException {
//初始化线程
ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(8);
//查询现有企业微信账号 //查询现有企业微信账号
List<OpCustomer> customers = opCustomerDOMapper.selectList(null); List<OpCustomer> customers = opCustomerDOMapper.selectList(null);
if (CollectionUtils.isNotEmpty(customers)){ //查询企业微信已配置联系我的用户
//分组 for (OpCustomer customer : customers) {
final List<List<OpCustomer>> afterPageList = com.kiisoo.ic.utils.CollectionUtils.portListByQuantity(customers, 100); String wechatUniId = customer.getWechatUniId();
//定义线程池长度 if (StringUtils.isBlank(wechatUniId)){
int threadPoolSize = afterPageList.size(); continue;
//定义countDownLatch }
final CountDownLatch countDownLatch = new CountDownLatch(threadPoolSize); String url = "";
for (int i = 0; i < afterPageList.size(); i++) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
List<OpCustomer> opCustomers = afterPageList.get(i); Map<String, Object> params = new HashMap<>();
newFixedThreadPool.execute(new Runnable() { params.put("unionId", wechatUniId);
@Override String message = HttpClientUtil.httpPost(vipBsdUrl + MD5FileUtil.getMD5String("BOSIDENG" + sdf.format(new Date())), JSONObject.toJSONString(params)).getMessage();
public void run() { if (StringUtils.isBlank(message)){
try { continue;
//查询企业微信已配置联系我的用户 }
for (OpCustomer customer : opCustomers) { JSONObject vipJson = JSONObject.parseObject(message);
String wechatUniId = customer.getWechatUniId(); BsdVipResponse bsdResponse = vipJson.toJavaObject(BsdVipResponse.class);
if (StringUtils.isBlank(wechatUniId)){ if (bsdResponse.getSuccess() && bsdResponse.getData() != null){
continue; MemberDtlDTO data = bsdResponse.getData();
}
String url = ""; OpCustomer opCustomer = new OpCustomer(data.getMemberName(), data.getMobileNo());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); opCustomer.setUpdateBy(Constants.SYS_OPERATION);
Map<String, Object> params = new HashMap<>();
params.put("unionId", wechatUniId); // 根据手机号码去重
String message = HttpClientUtil.httpPost(vipBsdUrl + MD5FileUtil.getMD5String("BOSIDENG" + sdf.format(new Date())), JSONObject.toJSONString(params)).getMessage(); QueryWrapper<OpVip> wrapper = new QueryWrapper<>();
if (StringUtils.isBlank(message)){ wrapper.eq("phone", data.getMobileNo());
continue; OpVip opVip = opVipDOMapper.selectOne(wrapper);
} OpVip opVip1 = new OpVip();
JSONObject vipJson = JSONObject.parseObject(message); opVip1.setStatus(1L);
BsdVipResponse bsdResponse = vipJson.toJavaObject(BsdVipResponse.class); opVip1.setLevel(data.getMemberLevel().toString());
if (bsdResponse.getSuccess() && bsdResponse.getData() != null){ opVip1.setPhone(data.getMobileNo());
MemberDtlDTO data = bsdResponse.getData(); opVip1.setName(data.getMemberName());
opVip1.setBirthday(data.getBirthday());
OpCustomer opCustomer = new OpCustomer(data.getMemberName(), data.getMobileNo()); opVip1.setRegisterTime(data.getCreateDate());
opCustomer.setUpdateBy(Constants.SYS_OPERATION); if (opVip == null) {
//数据库没有这个数据--新建数据
// 根据手机号码去重 opVip1.setCreateBy(Constants.SYS_OPERATION);
QueryWrapper<OpVip> wrapper = new QueryWrapper<>(); opVip1.setCreateTime(new Date());
wrapper.eq("phone", data.getMobileNo()); opVipDOMapper.insert(opVip1);
OpVip opVip = opVipDOMapper.selectOne(wrapper); //有vip信息就绑定信息
OpVip opVip1 = new OpVip(); opCustomer.setMemberId(opVip1.getId());
opVip1.setStatus(1L); } else {
opVip1.setLevel(data.getMemberLevel().toString()); opVip1.setId(opVip.getId());
opVip1.setPhone(data.getMobileNo()); opVip1.setUpdateTime(new Date());
opVip1.setName(data.getMemberName()); opVip1.setUpdateBy(Constants.SYS_OPERATION);
opVip1.setBirthday(data.getBirthday()); opVipDOMapper.updateById(opVip1);
opVip1.setRegisterTime(data.getCreateDate()); //有vip信息就绑定信息
if (opVip == null) { opCustomer.setMemberId(opVip.getId());
//数据库没有这个数据--新建数据 }
opVip1.setCreateBy(Constants.SYS_OPERATION); QueryWrapper<OpCustomer> wrapper1 = new QueryWrapper<>();
opVip1.setCreateTime(new Date()); wrapper1.eq("wechat_uni_id", wechatUniId);
opVipDOMapper.insert(opVip1); opCustomerDOMapper.update(opCustomer, wrapper1);
//有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<OpCustomer> wrapper1 = new QueryWrapper<>();
wrapper1.eq("wechat_uni_id", wechatUniId);
opCustomerDOMapper.update(opCustomer, wrapper1);
}
}
} catch (Exception e) {
log.error("同步会员数据", e);
} finally {
//每次减去一,避免死锁
countDownLatch.countDown();
}
}
});
} }
countDownLatch.await();
} }
} }
} }

@ -28,7 +28,7 @@ public class CustomerDataJob {
// 指定 ring buffer字节大小必需为2的N次方(能将求模运算转为位运算提高效率 ),否则影响性能 // 指定 ring buffer字节大小必需为2的N次方(能将求模运算转为位运算提高效率 ),否则影响性能
private static final int BUFFER_SIZE = 1024 * 1024; private static final int BUFFER_SIZE = 1024 * 1024;
//固定线程数 //固定线程数
private static final int THREAD_NUMBERS = 50; private static final int THREAD_NUMBERS = 30;
@Autowired @Autowired

Loading…
Cancel
Save