ActivityService.java
7.7 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package com.w1hd.zzhnc.service;
import java.math.BigDecimal;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.testng.util.Strings;
import com.w1hd.zzhnc.dao.LotteryLogDao;
import com.w1hd.zzhnc.enums.ActivityStatus;
import com.w1hd.zzhnc.model.Activity;
import com.w1hd.zzhnc.model.Lotterylog;
import com.w1hd.zzhnc.util.CommonUtil;
import com.w1hd.zzhnc.util.DateUtil;
import com.w1hd.zzhnc.util.PageResults;
import com.w1hd.zzhnc.util.RedisUtil;
import com.w1hd.zzhnc.vo.Lotterylog_Vo;
/**
* @ClassName ArticlesServiceImpl
* @Description TODO(杩欓噷鐢ㄤ竴鍙ヨ瘽鎻忚堪杩欎釜绫荤殑浣滅敤)
* @author hm
* @Date 2017骞�11鏈�22鏃� 涓婂崍10:13:53
* @version 1.0.0
*/
@Service
public class ActivityService {
final String ACTIVITY_SETTING = "ACTIVITY_SETTING";// 娲诲姩璁剧疆淇濆瓨key
@Autowired
LotteryLogDao logDao;
public String editActivitySetting(String beginTime, BigDecimal planMny, Integer minMny, Integer maxMny,
Integer lotteryPercent, String city, String keyword, String unLotteryReply, String finishReply,
String lotteryTitle, String lotterySubTitle, String noChanceReply, String replyWait, String replyWelcome,
String replyFailed2, String replySucceed,String badWordsReply) {
try {
Activity activity = null;
Integer turnid = 1;
Integer status = ActivityStatus.UNSTART.getIndex();
String activityjson = RedisUtil.get(ACTIVITY_SETTING);
if (!Strings.isNullOrEmpty(activityjson)) {
activityjson = CommonUtil.JsonToObject(activityjson);
Activity redisactivity = CommonUtil.getEntity(activityjson, Activity.class);
if (redisactivity != null && redisactivity.getTurn() != null && redisactivity.getTurn() > 0) {
turnid = redisactivity.getTurn();
}
if (redisactivity != null && redisactivity.getStatus() > 0) {
status = redisactivity.getStatus();
}
}
java.util.Date btime = null;
if (!Strings.isNullOrEmpty(beginTime)) {
try {
btime = DateUtil.parseTime1(beginTime);
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("btime:" + btime);
activity = new Activity(btime, null, status, planMny, minMny, maxMny, lotteryPercent, city, keyword,
unLotteryReply, finishReply, lotteryTitle, lotterySubTitle, turnid, noChanceReply, replyWait,
replyWelcome, replyFailed2, replySucceed,badWordsReply);
// 浠庢暟鎹簱涓幏鍙栨渶鏂扮殑宸插彂鏀鹃噾棰濓紝閬垮厤姣忔淇濆瓨閮藉皢currentMny娓呴浂.
BigDecimal currentMny = logDao.getSumMny(activity.getTurn(), 1);
activity.setCurrentMny(currentMny);
String json = CommonUtil.getJson(activity);
System.out.println("activity json:" + json.toString());
RedisUtil.set(ACTIVITY_SETTING, json.toString());
return "ok";
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "璁剧疆澶辫触锛屾暟鎹紓甯�";
}
}
public Activity getActivitySetting() {
String activityjson = RedisUtil.get(ACTIVITY_SETTING);
activityjson = CommonUtil.JsonToObject(activityjson);
Activity redisactivity = CommonUtil.getEntity(activityjson, Activity.class);
return redisactivity;
}
public String updateActivityStatus(Integer status) {
try {
String activityjson = RedisUtil.get(ACTIVITY_SETTING);
if (Strings.isNullOrEmpty(activityjson))
return "娲诲姩涓嶅瓨鍦�";
activityjson = CommonUtil.JsonToObject(activityjson);
Activity redisactivity = CommonUtil.getEntity(activityjson, Activity.class);
if (redisactivity == null)
return "娲诲姩涓嶅瓨鍦�";
// 涓嶅仛閫昏緫鍒ゆ柇锛屾兂鏀瑰氨鏀� ~(锝烇浚鈻斤浚)锝� 2017-12-13 create by zxt
// if (status == ActivityStatus.宸茬粨鏉�.getIndex() && redisactivity.getStatus() ==
// ActivityStatus.杩涜涓�.getIndex()) {
// redisactivity.setEndTime(CommonUtil.getTime());
// redisactivity.setStatus(status);
// } else if (status == ActivityStatus.杩涜涓�.getIndex()
// && redisactivity.getStatus() == ActivityStatus.鏈紑濮�.getIndex()) {
// redisactivity.setBeginTime(CommonUtil.getTime());
// redisactivity.setStatus(status);
// }
redisactivity.setBeginTime(CommonUtil.getTime());
redisactivity.setStatus(status);
String json = CommonUtil.getJson(redisactivity);
System.out.println("activity json:" + json.toString());
RedisUtil.set(ACTIVITY_SETTING, json.toString());
return "ok";
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "淇敼澶辫触,鏁版嵁寮傚父";
}
}
public String clearActivity() {
try {
String activityjson = RedisUtil.get(ACTIVITY_SETTING);
if (Strings.isNullOrEmpty(activityjson))
return "娲诲姩涓嶅瓨鍦�";
activityjson = CommonUtil.JsonToObject(activityjson);
Activity activity = CommonUtil.getEntity(activityjson, Activity.class);
if (activity == null)
return "娲诲姩涓嶅瓨鍦�";
if (activity.getStatus() <= 0 || activity.getStatus() != ActivityStatus.FINISH.getIndex()) {
return "褰撳墠娲诲姩杩樻湭缁撴潫锛岄渶娲诲姩缁撴潫鍚庢墠鍙噸鏂板紑鍚�";
}
int turnid = activity.getTurn();
if (activity.getStatus() == ActivityStatus.FINISH.getIndex()) {
activity.setStatus(ActivityStatus.UNSTART.getIndex());
activity.setTurn(turnid + 1);
activity.setPlanMny(BigDecimal.ZERO);
}
String json = CommonUtil.getJson(activity);
RedisUtil.set(ACTIVITY_SETTING, json.toString());
return "ok";
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "鎿嶄綔澶辫触锛屾暟鎹紓甯�";
}
}
/*
* (闈� Javadoc) Description:
*
* @see
* com.w1hd.zzhnc.service.ActivityService#addLotteryLog(java.lang.Integer,
* java.math.BigDecimal, java.lang.Integer)
*/
public String addLotteryLog(Integer fansid, BigDecimal mny, Integer status, Integer turn) {
Lotterylog log = new Lotterylog();
log.setCreatedtime(CommonUtil.getTime());
log.setFansid(fansid);
log.setMny(mny);
log.setStatus(status);
log.setTurn(turn);
int row = logDao.insertSelective(log);
return row > 0 ? "ok" : "娣诲姞澶辫触锛屾暟鎹紓甯�";
}
/*
* (闈� Javadoc) Description:
*
* @see
* com.w1hd.zzhnc.service.ActivityService#getLotteryLog(java.lang.Integer,
* java.lang.Integer, java.lang.Integer, java.lang.String)
*/
public PageResults<Lotterylog_Vo> getLotteryLogList(Integer page, Integer pagesize, Integer turn, String keyword,
Integer status) {
PageResults<Lotterylog_Vo> pageResults = new PageResults<>();
List<Lotterylog_Vo> list = logDao.getLotteryLogList((page - 1) * pagesize, pagesize, turn, keyword, status);
int total = logDao.getLotteryLogCount(turn, status);
BigDecimal bMny = logDao.getSumMny(turn, status);
int mny = bMny == null ? 0 : bMny.intValue();
pageResults.setPage(page);
pageResults.setPageSize(pagesize);
pageResults.setRows(list);
pageResults.setTotal(total);
pageResults.setSum(mny);
return pageResults;
}
public void updateCurrentMny(BigDecimal currentMny) {
try {
String activityjson = RedisUtil.get(ACTIVITY_SETTING);
if (Strings.isNullOrEmpty(activityjson))
return;
activityjson = CommonUtil.JsonToObject(activityjson);
Activity redisactivity = CommonUtil.getEntity(activityjson, Activity.class);
redisactivity.setCurrentMny(currentMny);
String json = CommonUtil.getJson(redisactivity);
System.out.println("activity json:" + json.toString());
RedisUtil.set(ACTIVITY_SETTING, json.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}