ActivityService.java
4.6 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
package com.w1hd.zzhnc.service;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import org.hamcrest.core.IsInstanceOf;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.testng.collections.Lists;
import org.testng.util.Strings;
import org.theyeasy.weixin.service.WxPayService;
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.model.Prize;
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 = RedisUtil.PROJECTNAME.concat("_").concat("ACTIVITY_SETTING");// 娲诲姩璁剧疆淇濆瓨key
final String SEND_REDPACKAGE_ID = RedisUtil.PROJECTNAME.concat("_").concat("SEND_REDPACKAGE_ID_");
@Autowired
LotteryLogDao logDao;
@Autowired
RedisTemplate redisTemplate;
public Activity getActivitySetting() {
Activity redisactivity = (Activity) redisTemplate.opsForValue().get(ACTIVITY_SETTING);
if (redisactivity == null) {
redisactivity = new Activity(new Date(2017, 12, 27), new Date(2018, 2, 1), 1, new BigDecimal(500),
"zhenzhou", "keyworks", "you'r lose", "replay String of activity finished ", "input title pls",
"input subtitle pls", 0, "nochance replay", "waitting...", "welcome", "fail", "success",
"undefind");
redisTemplate.opsForValue().set(ACTIVITY_SETTING, redisactivity);
}
return redisactivity;
}
public String updateActivityStatus(Integer status) {
Activity activity = getActivitySetting();
activity.setStatus(status);
updateActivity(activity);
return "ok";
}
public String clearActivity() {
Activity activity = getActivitySetting();
activity.setTurn(activity.getTurn() + 1);
activity.setPlanMny(new BigDecimal(0));
activity.setStatus(0);
updateActivity(activity);
return "ok";
}
public String addLotteryLog(Integer fansid, BigDecimal mny, Integer status, Integer turn, String name) {
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" : "error";
}
public PageResults<Lotterylog_Vo> getLotteryLogList(Integer page, Integer pagesize, Integer turn, String keyword,
Integer status,Integer type) {
PageResults<Lotterylog_Vo> pageResults = new PageResults<>();
List<Lotterylog_Vo> list = logDao.getLotteryLogList((page - 1) * pagesize, pagesize, turn, keyword, status,type);
int total = logDao.getLotteryLogCount(turn,keyword, status,type);
BigDecimal bMny = logDao.getSumMny(turn, status);
double mny = bMny == null ? 0 : bMny.doubleValue();
if (status!=null && status == 2) {
updateCurrentMny(bMny);
}
pageResults.setPage(page);
pageResults.setPageSize(pagesize);
pageResults.setRows(list);
pageResults.setTotal(total);
pageResults.setSum(mny);
return pageResults;
}
public void updateCurrentMny(BigDecimal currentMny) {
Activity activity = getActivitySetting();
activity.setCurrentMny(currentMny);
updateActivity(activity);
}
public void updateActivity(Activity activity) {
redisTemplate.opsForValue().set(ACTIVITY_SETTING, activity);
}
public void updateActivityPrize(Integer type, Prize prize) {
prize.setId(type);
prizeService.update(prize);
}
@Autowired
PrizeService prizeService;
public List<Prize> getPrizeList() {
PageResults<Prize> search = prizeService.search(null, 1, 10);
return search.getRows();
}
@Autowired
WxPayService wxPayService;
public void sendRedPackage(String miniOpenId, Integer mny) {
Integer count = 1;
Object object = redisTemplate.opsForValue().get(SEND_REDPACKAGE_ID + miniOpenId);
if (object != null && object instanceof Integer) {
count = (Integer) object;
System.out.println("注意 !" + miniOpenId + " 已中过奖 " + count + " 次");
count++;
}
wxPayService.payMoney("pay" + DateTime.now().getMillis(), miniOpenId, mny, "来自【东莞万科万小二】的红包奖励");
redisTemplate.opsForValue().set(SEND_REDPACKAGE_ID + miniOpenId, count);
}
}