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
package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.constant.CommonAttributes;
import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.MonthAwardMapper;
import cn.wisenergy.mapper.TradeRecordMapper;
import cn.wisenergy.model.app.MonthAward;
import cn.wisenergy.model.app.TradeRecord;
import cn.wisenergy.model.dto.MonthAwardQuery;
import cn.wisenergy.model.dto.TradeRecordQuery;
import cn.wisenergy.model.vo.MonthAwardVo;
import cn.wisenergy.service.app.MonthAwardService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author 86187
*/
@Slf4j
@Service
public class MonthAwardServiceImpl extends ServiceImpl<MonthAwardMapper, MonthAward> implements MonthAwardService {
private static final String PATTERN = "yyyy-MM";
@Autowired
private TradeRecordMapper tradeRecordMapper;
@Override
public R<MonthAwardVo> queryMonthAward(String userId) {
log.info("shop-mall[]MonthAwardServiceImpl[]queryMonthAward[]input.param.userId:" + userId);
if (StringUtils.isBlank(userId)) {
return R.error("入参为空!");
}
//获取本月最新的一条数据
String yearMonth = DateUtil.convertDateToStr(new Date(), "yyyy-MM");
MonthAwardVo monthAwardVo = new MonthAwardVo();
MonthAward monthAward = baseMapper.getByTime(yearMonth);
if (null == monthAward) {
return R.ok(monthAwardVo);
}
monthAwardVo.setAwardTime(monthAward.getCreateTime());
monthAwardVo.setAwardTotal(monthAward.getAwardTotal());
monthAwardVo.setFarmerAward(monthAward.getFarmerAward());
monthAwardVo.setForestStartAward(monthAward.getForestStartAward());
monthAwardVo.setGoldAward(monthAward.getGoldAward());
monthAwardVo.setGrowthAward(monthAward.getGrowthAward());
monthAwardVo.setMonthAwardTotal(monthAward.getMonthAwardTotal());
monthAwardVo.setMonthIncreased(monthAward.getMonthIncreased());
monthAwardVo.setPartnerAward(monthAward.getPartnerAward());
//获取用户本月奖金
Double sum = tradeRecordMapper.queryMonthAward(userId, new Date());
if (null == sum) {
monthAwardVo.setUserMonthAward(0.00);
} else {
monthAwardVo.setUserMonthAward(sum);
}
return R.ok(monthAwardVo);
}
@Override
public R<PageInfo<MonthAward>> getList(MonthAwardQuery query) {
log.info("shop-mall[]MonthAwardServiceImpl[]getList[]input.param.query:" + query);
if (null == query) {
return R.error("入参为空!");
}
pageHandle(query);
Map<String, Object> map = new HashMap<>(8);
if (!StringUtils.isBlank(query.getQueryTime())) {
map.put("queryTime", query.getQueryTime());
}
int total = baseMapper.count(map);
map.put("startNum", query.getStartNum());
map.put("endNum", query.getEndNum());
List<MonthAward> list = baseMapper.getList(map);
PageInfo<MonthAward> info = new PageInfo<>();
info.setPageSize(query.getPageSize());
info.setPageNum(query.getPageNo());
info.setTotal(total);
info.setList(list);
return R.ok(info);
}
/**
* 分页处理方法
*
* @param schemeVo 参数
*/
private void pageHandle(MonthAwardQuery schemeVo) {
Integer pageNum = schemeVo.getPageNo();
Integer pageSize = schemeVo.getPageSize();
if (null == pageSize || pageSize == 0) {
pageSize = 10;
}
if (null == pageNum || pageNum == 0) {
pageNum = 1;
}
Integer endNum = pageSize;
Integer startNum = (pageNum - CommonAttributes.NUM_ONE) * pageSize;
schemeVo.setEndNum(endNum);
schemeVo.setStartNum(startNum);
schemeVo.setPageNo(pageNum);
schemeVo.setPageSize(pageSize);
}
}