935090232@qq.com
2021-01-17 71580395e958879e49a8449c54c584f7c0b1fc7f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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);
        }
 
    }
}