package com.matrix.system.shopXcx.mqTask;
|
|
|
import com.matrix.biz.bean.BizUser;
|
import com.matrix.biz.service.BizUserService;
|
import com.matrix.component.rabbitmq.MqTask;
|
import com.matrix.core.tools.LogUtil;
|
import com.matrix.core.tools.StringUtils;
|
import com.matrix.system.constance.Dictionary;
|
import com.matrix.system.hive.bean.SysShopInfo;
|
import com.matrix.system.hive.bean.SysVipInfo;
|
import com.matrix.system.hive.dao.SysShopInfoDao;
|
import com.matrix.system.hive.dao.SysVipInfoDao;
|
import com.matrix.system.hive.plugin.util.CollectionUtils;
|
import com.rabbitmq.client.DeliverCallback;
|
import com.rabbitmq.client.Delivery;
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import java.io.IOException;
|
import java.util.List;
|
|
public class VipCreateTask implements DeliverCallback {
|
|
@Autowired
|
BizUserService bizUserService;
|
|
@Autowired
|
SysShopInfoDao shopInfoDao;
|
|
@Autowired
|
private SysVipInfoDao vipDap;
|
|
//TODO 用户可以都归属一个电商店铺,发货的时候指定仓库出货,微商城的产品可以绑定仓库库存
|
|
@Override
|
public void handle(String consumerTag, Delivery message) throws IOException {
|
try {
|
String messages = new String(message.getBody(), "UTF-8");
|
|
String userId=messages.split(",")[0];
|
Long shopId=Long.parseLong(messages.split(",")[1]);
|
|
BizUser userInfo = bizUserService.findByOpenId(userId);
|
|
// TODO 校验用户是否已存在 , 公司id不能写死
|
SysVipInfo vip = vipDap.selectByPhone(userInfo.getPhoneNumber());
|
if (vip != null) {
|
LogUtil.warn("会员{}已经存在", userInfo.getPhoneNumber());
|
//更新信息
|
vip.setOpenId(userInfo.getOpenId());
|
if(StringUtils.isBlank(vip.getPhoto())){
|
vip.setPhoto(userInfo.getAvatarUrl());
|
}
|
vipDap.update(vip);
|
} else {
|
SysVipInfo vipInfo = new SysVipInfo();
|
//在备注记下微商城的用户id
|
vipInfo.setOpenId(userInfo.getOpenId());
|
vipInfo.setAddr(userInfo.getProvince() + " " + userInfo.getCity());
|
vipInfo.setPhone(userInfo.getPhoneNumber());
|
if(StringUtils.isBlank(vipInfo.getPhoto())){
|
vipInfo.setPhoto(userInfo.getAvatarUrl());
|
}
|
if (userInfo.getGender() != null) {
|
vipInfo.setSex(userInfo.getGender().equals("1") ? "男" : "女");
|
}
|
vipInfo.setVipName(userInfo.getNickName());
|
vipInfo.setShopId(shopId);
|
vipInfo.setArrivalWay("微商城");
|
vipInfo.setVipState(Dictionary.VIP_STATE_HY);
|
vipInfo.setVipType(Dictionary.VIP_TYPE_NOCARD);
|
vipInfo.setIsDeal(SysVipInfo.UNDEAL_VIP);
|
vipDap.insert(vipInfo);
|
}
|
} catch (Exception e) {
|
LogUtil.error("消费者执行异常", e);
|
}
|
|
}
|
}
|