大屏接口

dev_0531
yechenhao 6 years ago
parent 35803ae2eb
commit 274fc65655

@ -133,6 +133,19 @@ public class CustomerViewController extends BaseController {
}
}
/**
*
* @return
*/
@RequestMapping(value = "/sync/vip", method = RequestMethod.GET)
public void syncVip(){
try{
customerViewService.syncVip();
}catch (Exception e){
log.error("批量同步总数出错", e);
}
}
/**
* 广0
* @param userId id

@ -1,9 +1,13 @@
package com.kiisoo.ic.customer.service;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.kiisoo.ic.common.utils.MD5FileUtil;
import com.kiisoo.ic.common.utils.httpClientUtil.HttpClientUtil;
import com.kiisoo.ic.config.WxCpConfiguration;
import com.kiisoo.ic.constants.Constants;
import com.kiisoo.ic.customer.entity.*;
import com.kiisoo.ic.customer.mapper.OpCustomerDOMapper;
import com.kiisoo.ic.customer.mapper.OpVipDOMapper;
@ -16,6 +20,9 @@ import com.kiisoo.ic.generalize.entity.PrivilageOrganizational;
import com.kiisoo.ic.generalize.mapper.PoiCustomerContactDataStatMapper;
import com.kiisoo.ic.generalize.mapper.RetailCompanyMapper;
import com.kiisoo.ic.generalize.service.RetailCompanyService;
import com.kiisoo.ic.store.bean.BsdShareCodeResponse;
import com.kiisoo.ic.store.bean.BsdVipResponse;
import com.kiisoo.ic.store.bean.MemberDtlDTO;
import com.kiisoo.ic.store.entity.PoiStore;
import com.kiisoo.ic.store.entity.PoiStoreStaff;
import com.kiisoo.ic.store.entity.PrivilageCpUserStoreDO;
@ -31,6 +38,7 @@ import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
@ -115,6 +123,10 @@ public class CustomerViewService {
@Autowired
private RetailCompanyMapper retailCompanyMapper;
@Value("${bsd.vip}")
private String vipBsdUrl;
/**
* main
* @param userId id
@ -699,4 +711,95 @@ public class CustomerViewService {
countDownLatch.await();
}
}
/**
*
* @return
*/
public void syncVip() throws InterruptedException {
//初始化线程
ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(8);
//查询现有企业微信账号
List<OpCustomer> customers = opCustomerDOMapper.selectList(null);
if (CollectionUtils.isNotEmpty(customers)){
//分组
final List<List<OpCustomer>> 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<OpCustomer> 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<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();
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<OpVip> 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<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();
}
}
}

@ -0,0 +1,12 @@
package com.kiisoo.ic.store.bean;
import lombok.Data;
@Data
public class BsdVipResponse {
private Boolean success;
private String resultCode;
private String errorMessage;
private MemberDtlDTO data;
}

@ -0,0 +1,122 @@
package com.kiisoo.ic.store.bean;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
@Data
public class MemberDtlDTO {
/**
*
*/
private Long memberId;
/**
*
*/
private String userNo;
/**
*
*/
private String mobileNo;
/**
*
*/
private String memberName;
/**
* -1- 0- 1- 2-
*/
private Byte memberStatus;
/**
* (FEMALE MALE)
*/
private String gender;
/**
*
*/
private String storeNo;
/**
*
*/
private String cardNo;
/**
* (1- 2- 3- 4- 5-)
*/
private Long memberLevel;
/**
*
*/
private Date birthday;
/**
*
*/
private String address;
/**
*
*/
private Long educationLevel;
/**
*
*/
private Long monthlyIncome;
/**
*
*/
private Long industry;
/**
*
*/
private Date lastBuyDate;
/**
*
*/
private Integer totalTimes;
/**
*
*/
private Integer totalNum;
/**
*
*/
private BigDecimal totalAmount;
/**
*
*/
private Integer totalPoint;
/**
*
*/
private Integer adjustPoint;
/**
*
*/
private Integer usedPoint;
/**
*
*/
private Integer canusePoint;
/**
*
*/
private Date lastDate;
/**
*
*/
private Integer lastNum;
/**
*
*/
private BigDecimal lastAmount;
/**
*
*/
private String remark;
/**
*
*/
private Integer couponsCount;
/**
*
*/
private Date createDate;
}

@ -24,7 +24,7 @@ server:
bsd:
vip: http://vtest.bsd.cn/BSD_WXAPP/miniProgram/getMemberDtlByUnionId
vip: http://vtest.bsd.cn/BSD_WXAPP/miniProgram/getMemberDtlByUnionId?token=
qrCode: http://vtest.bsd.cn/BSD_WXAPP/qyWechat/getShareQRcode?token=
userBehavior: http://vtest.bsd.cn/BSD_WXAPP/qyWechat/getUserBehaviorData?token=
cancelQrCode: http://vtest.bsd.cn/BSD_WXAPP/qyWechat/cancelShareQRcode?token=

@ -23,7 +23,7 @@ server:
bsd:
vip: http://10.101.10.24:80/BSD_WXAPP/miniProgram/getMemberDtlByUnionId
vip: http://10.101.10.24:80/BSD_WXAPP/miniProgram/getMemberDtlByUnionId?token=
qrCode: http://10.101.10.24:80/BSD_WXAPP/qyWechat/getShareQRcode?token=
userBehavior: http://10.101.10.24:80/BSD_WXAPP/qyWechat/getUserBehaviorData?token=
cancelQrCode: http://10.101.10.24:80/BSD_WXAPP/qyWechat/cancelShareQRcode?token=
Loading…
Cancel
Save