UserServiceImpl.java
5.77 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
package com.server.web.common.service.Impl;
import com.server.utils.DateUtils;
import com.server.utils.ResultMapUtil;
import com.server.web.common.mapper.TKzyUserIntegralFlowingMapper;
import com.server.web.common.mapper.TKzyUserMapper;
import com.server.web.common.mapping.IntegralMapper;
import com.server.web.common.model.TKzyUser;
import com.server.web.common.model.TKzyUserIntegralFlowing;
import com.server.web.common.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* Created by 豆腐干Sama on 2018/12/6.
*/
@Service
public class UserServiceImpl implements UserService {
@Autowired
private TKzyUserMapper tKzyUserMapper;
@Autowired
private TKzyUserIntegralFlowingMapper tKzyUserIntegralFlowingMapper;
@Autowired
private IntegralMapper integralMapper;
@Override
public void save(TKzyUser user) {
}
public static void main(String[] args) {
Date last = DateUtils.firstDayOfMonth();
System.out.println(last);
}
@Override
public Map signIn(TKzyUser loginUser) {
if (loginUser == null || loginUser.getId() == null) {
return ResultMapUtil.returnMap("0", "请先登录!", null);
}
loginUser = tKzyUserMapper.selectByPrimaryKey(loginUser.getId());
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
if (loginUser.getLastSignDt() != null && simpleDateFormat.format(loginUser.getLastSignDt()).equals(simpleDateFormat.format(new Date()))) {
return ResultMapUtil.returnMap("0", "您已签到!", null);
}
TKzyUserIntegralFlowing tKzyUserIntegralFlowing = new TKzyUserIntegralFlowing();
tKzyUserIntegralFlowing.setCreateDt(new Date());
tKzyUserIntegralFlowing.setSourceType(1);
tKzyUserIntegralFlowing.setType(1);
tKzyUserIntegralFlowing.setUserId(loginUser.getId());
if (loginUser.getIntegral() == null) {
loginUser.setIntegral(0);
}
if (loginUser.getSignInCount() == null) {
loginUser.setSignInCount(0);
}
String firstDay = simpleDateFormat.format(DateUtils.firstDayOfMonth());
Integer integral = 1;
if (firstDay.equals(simpleDateFormat.format(new Date()))) {
loginUser.setSignInCount(1);
tKzyUserIntegralFlowing.setIntegral(1);
} else {
//判断昨天是否签到,昨天未签到,签到哦连续天数置0;
Map<String, Object> param2 = new HashMap<String, Object>();
param2.put("userId", loginUser.getId());
param2.put("today", simpleDateFormat.format(org.apache.commons.lang.time.DateUtils.addDays(new Date(), -1)));
Map<String, Object> yestoday = integralMapper.queryDaySign(param2);
if (yestoday == null || yestoday.get("id") == null) {
loginUser.setSignInCount(0);
}
if (loginUser.getSignInCount() == 5) {
loginUser.setSignInCount(1);
integral = 1;
} else {
if (loginUser.getSignInCount() < 2) {
integral = 1;
} else if (loginUser.getSignInCount() == 2) {
integral = 3;
} else if (loginUser.getSignInCount() == 3) {
integral = 1;
} else if (loginUser.getSignInCount() == 4) {
integral = 5;
} else {
integral = 1;
}
loginUser.setSignInCount(loginUser.getSignInCount() + 1);
}
}
loginUser.setIntegral(loginUser.getIntegral() + integral);
tKzyUserIntegralFlowing.setIntegral(integral);
loginUser.setLastSignDt(new Date());
tKzyUserMapper.updateByPrimaryKeySelective(loginUser);
tKzyUserIntegralFlowingMapper.insertSelective(tKzyUserIntegralFlowing);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("integral", integral);
dataMap.put("signInCount", loginUser.getSignInCount());
return ResultMapUtil.returnMap("1", "操作成功!", dataMap);
}
@Override
public Map<String, Object> signInList(TKzyUser loginUser) {
//List<String> dayList = getDayListOfMonth();
loginUser = tKzyUserMapper.selectByPrimaryKey(loginUser.getId());
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd");
Map<String, Object> param = new HashMap<String, Object>();
param.put("userId", loginUser.getId());
param.put("month", simpleDateFormat.format(new Date()));
List<Map<String, Object>> list = integralMapper.signInList(param);
List<String> hasSignDay = new ArrayList<>();
for (Map<String, Object> map : list) {
String dd = (String) map.get("days");
String[] _D = dd.split("/");
String ymd = _D[0] + "/" + (_D[1].startsWith("0") ? (_D[1].substring(1, _D[1].length())) : _D[1]) + "/" + (_D[2].startsWith("0") ? (_D[2].substring(0, _D[2].length())) : _D[2]);
hasSignDay.add(ymd);
}
Map<String, Object> param2 = new HashMap<String, Object>();
param2.put("userId", loginUser.getId());
param2.put("today", simpleDateFormat2.format(new Date()));
Map<String, Object> todaySign = integralMapper.queryDaySign(param2);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("list", list);
dataMap.put("todaySign", todaySign);
dataMap.put("daysList", hasSignDay);
dataMap.put("integral", loginUser.getIntegral());
return ResultMapUtil.returnMap("1", "", dataMap);
}
}