UserServiceImpl.java
4.28 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
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.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 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);
}
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);
if (loginUser.getIntegral() == null) {
loginUser.setIntegral(0);
}
if (loginUser.getSignInCount() == null) {
loginUser.setSignInCount(0);
}
String firstDay = simpleDateFormat.format(DateUtils.firstDayOfMonth());
if (firstDay.equals(simpleDateFormat.format(new Date()))) {
loginUser.setIntegral(loginUser.getIntegral() + 1);
loginUser.setSignInCount(1);
tKzyUserIntegralFlowing.setIntegral(1);
} else {
if (loginUser.getSignInCount() <= 2) {
loginUser.setIntegral(loginUser.getIntegral() + 1);
loginUser.setSignInCount(loginUser.getSignInCount() + 1);
tKzyUserIntegralFlowing.setIntegral(1);
} else if (loginUser.getSignInCount() == 3) {
loginUser.setIntegral(loginUser.getIntegral() + 3);
loginUser.setSignInCount(loginUser.getSignInCount() + 1);
tKzyUserIntegralFlowing.setIntegral(3);
} else if (loginUser.getSignInCount() == 4) {
loginUser.setIntegral(loginUser.getIntegral() + 3);
loginUser.setSignInCount(loginUser.getSignInCount() + 1);
tKzyUserIntegralFlowing.setIntegral(1);
} else if (loginUser.getSignInCount() == 5) {
loginUser.setIntegral(loginUser.getIntegral() + 5);
loginUser.setSignInCount(1);
tKzyUserIntegralFlowing.setIntegral(5);
} else {
loginUser.setIntegral(1);
loginUser.setSignInCount(1);
tKzyUserIntegralFlowing.setIntegral(1);
}
}
loginUser.setLastSignDt(new Date());
tKzyUserMapper.updateByPrimaryKeySelective(loginUser);
tKzyUserIntegralFlowingMapper.insertSelective(tKzyUserIntegralFlowing);
return ResultMapUtil.returnMap("1", "操作成功!", null);
}
@Override
public Map<String, Object> signInList(TKzyUser loginUser) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
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);
return ResultMapUtil.returnMap("1", "", list);
}
}