UserLevelBiz.java
4.83 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package com.cjs.cms.biz.user.point;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cjs.cms.biz.user.WeiXinBiz;
import com.cjs.cms.dao.user.WeixinDao;
import com.cjs.cms.dao.user.account.ClientDao;
import com.cjs.cms.dao.user.point.UserLevelRecordDao;
import com.cjs.cms.model.user.WxUserInfo;
import com.cjs.cms.model.user.point.UserLevelRecordInfo;
import com.cjs.cms.util.lang.DateUtil;
/**
* 会员等级
*
* @author tongyufu
*
*/
@Service
public class UserLevelBiz {
@Autowired
private ClientDao clientDao;
@Autowired
private WeixinDao weixinDao;
@Autowired
private UserLevelRecordDao userLevelRecordDao;
@Autowired
private WeiXinBiz weiXinBiz;
private Logger log = LogManager.getLogger();
/**
* 会员等级升级(定时任务)
* @throws Exception
*/
public void levelUp() throws Exception {
log.info("开始会员等级升级 " + DateUtil.getNow());
//将所有会员等级为空的设置为0(柜台开的机构会员账号好像会为空)
clientDao.repairLevel();
//普通会员升铜牌
this.levelUp(this.queryLevelUser(0, 10, 0), "1");
//铜牌升银牌
this.levelUp(this.queryLevelUser(1, 5, 1), "2");
//银牌升金牌
this.levelUp(this.queryLevelUser(2, 10, 2), "3");
//金牌升钻石
this.levelUp(this.queryLevelUser(3, 10, 3), "4");
log.info("结束会员等级升级 " + DateUtil.getNow());
}
/**
* 查询可升级用户和代理商
* @param subordinateLevel 下属等级
* @param subordinateAmount 需要下属数量
* @param userLevel 当前用户等级
* @return
*/
private List<Map<String, String>> queryLevelUser(Integer subordinateLevel,
Integer subordinateAmount, Integer userLevel) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("subordinateLevel", subordinateLevel);
params.put("subordinateAmount", subordinateAmount);
params.put("userLevel", userLevel);
List<Map<String, String>> users = clientDao.queryLevelUser(params);
users.addAll(clientDao.queryLevelAgent(params));
return users;
}
private void levelUp(List<Map<String, String>> users, String newLevel) throws Exception {
log.info("等级[" + newLevel + "]人数:" + users.size());
for (Map<String, String> user : users) {
String userId = user.get("CLIENT_ID");
if (StringUtils.isBlank(userId)) {
continue;
}
//代理商
/*
if (userId.length() == 4 || userId.length() == 6) {
AgentInfo agentInfo = agentInfoDao.queryByAgentNo(userId);
if (agentInfo == null) {
log.error("代理商信息不存在:" + userId);
return;
}
userId = agentInfo.getFundAccount();
} */
clientDao.updateUserLevel(userId, newLevel);
//升级记录
UserLevelRecordInfo record = new UserLevelRecordInfo();
record.setUserId(userId);
record.setLevel(newLevel);
record.setCreateBy("admin");
userLevelRecordDao.save(record);
//发送微信提示
log.info("准备发送模板");
WxUserInfo wxUserInfo = weixinDao.queryByUserId(userId);
if (wxUserInfo != null) {
log.info("已绑定模板");
Map<String, String> levelInfo = new HashMap<String, String>();
levelInfo.put("openId", wxUserInfo.getOpenId());
levelInfo.put("oldLevel",
this.levelName(Integer.parseInt(user.get("ASSET_LEVEL"))));
levelInfo.put("newLevel", this.levelName(Integer.parseInt(newLevel)));
weiXinBiz.postTemplate(levelInfo,
"/template/levelInfo?openId={openId}&oldLevel={oldLevel}&newLevel={newLevel}");
log.info("模板发送成功");
}
}
}
public String levelName(Integer userLevel) {
String name = "";
if (userLevel == 0) {
name = "普通会员";
}
if (userLevel == 1) {
name = "铜牌会员";
}
if (userLevel == 2) {
name = "银牌会员";
}
if (userLevel == 3) {
name = "金牌会员";
}
if (userLevel == 4) {
name = "钻石会员";
}
return name;
}
}