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
package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.constant.CommonAttributes;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.*;
import cn.wisenergy.model.app.*;
import cn.wisenergy.model.dto.AccountInfoQuery;
import cn.wisenergy.service.app.AccountService;
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.*;
/**
* @author 86187
*/
@Slf4j
@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo> implements AccountService {
@Autowired
private AccountMapper accountMapper;
@Autowired
private ShopVersionMapper shopVersionMapper;
@Override
public R<AccountInfo> getByUserId(String userId) {
AccountInfo accountInfo = accountMapper.getByUserId(userId);
return R.ok(accountInfo);
}
@Override
public R<PageInfo<AccountInfo>> getList(AccountInfoQuery query) {
log.info("shop-mall[]AccountServiceImpl[]getList[]input.param.query:" + query);
if (null == query) {
return R.error("入参不能为空!");
}
pageHandle(query);
Map<String, Object> map = new HashMap<>();
int total = accountMapper.count();
map.put("startNum", query.getStartNum());
map.put("endNum", query.getEndNum());
List<AccountInfo> list = accountMapper.getList(map);
PageInfo<AccountInfo> info = new PageInfo<>();
info.setPageSize(query.getPageSize());
info.setPageNum(query.getPageNo());
info.setTotal(total);
info.setList(list);
return R.ok(info);
}
@Override
public R<String> updateVersion(String version, Integer type) {
log.info("shop-mall[]AccountServiceImpl[]updateVersion[]input.param.version,type:" + version, type);
if (StringUtils.isBlank(version) || null == type) {
return R.error("入参不能为空!");
}
//获取版本号信息
ShopVersion shopVersion = shopVersionMapper.getByType(type);
if (null == shopVersion) {
return R.error("版本号信息不存在,请联系管理员!");
}
//版本号不相等
if (!shopVersion.getVersion().equals(version)) {
return R.ok(shopVersion.getUrl());
}
return R.error(1, "当前已是最新版本!");
}
@Override
public R<List<ShopVersion>> getVersion() {
log.info("shop-mall[]AccountServiceImpl[]getVersion[]input.param.method");
List<ShopVersion> list = shopVersionMapper.getList();
return R.ok(list);
}
/**
* 分页处理方法
*
* @param schemeVo 参数
*/
private void pageHandle(AccountInfoQuery 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);
}
}