AdministerServiceImpl.java
3.67 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
package com.zhongzhi.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhongzhi.common.constant.Platform;
import com.zhongzhi.common.constant.SmsCode;
import com.zhongzhi.common.exception.HttpException;
import com.zhongzhi.common.utils.JwtUtil;
import com.zhongzhi.dto.administer.AdministerPageDTO;
import com.zhongzhi.dto.administer.LoginDTO;
import com.zhongzhi.model.AdministerDO;
import com.zhongzhi.dao.AdministerDAO;
import com.zhongzhi.model.SmsCodeDO;
import com.zhongzhi.service.AdministerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongzhi.service.PermissionsService;
import com.zhongzhi.service.SmsCodeService;
import com.zhongzhi.vo.administer.AdministerVO;
import com.zhongzhi.vo.permission.PermissionVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 中心管理账户表 服务实现类
* </p>
*
* @author DengMin
* @since 2021-04-28
*/
@Service
public class AdministerServiceImpl extends ServiceImpl<AdministerDAO, AdministerDO> implements AdministerService {
@Autowired
private SmsCodeService smsCodeService;
@Autowired
private PermissionsService permissionsService;
@Override
public AdministerVO login(LoginDTO loginDTO) {
AdministerVO administerVO = new AdministerVO();
SmsCodeDO smsCodeDO = smsCodeService.getOneByTelePhone(loginDTO.getTelephone(), SmsCode.login, SmsCode.center);
if (smsCodeDO == null) {
throw new HttpException(10025);
}
if (!smsCodeDO.getCode().equals(loginDTO.getCode())) {
throw new HttpException(10021);
}
smsCodeService.removeById(smsCodeDO.getId());
AdministerDO administerDO = this.baseMapper.selectOne(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getTelephone, loginDTO.getTelephone()));
if (administerDO == null) {
throw new HttpException(10060);
}
BeanUtils.copyProperties(administerDO, administerVO);
String token = JwtUtil.generateToken(administerDO.getId(), Platform.center);
administerVO.setToken(token);
List<PermissionVO> list = permissionsService.getPermissionById(administerDO.getId());
List<PermissionVO> treeList = new ArrayList();
list.forEach(permissions -> {
if (permissions.getParentId() == null) {
treeList.add(permissions);
}
list.forEach(p -> {
if (p.getParentId() != null) {
if (p.getParentId().equals(permissions.getId())) {
if (permissions.getChildNodeList() == null) {
permissions.setChildNodeList(new ArrayList<>());
}
permissions.getChildNodeList().add(p);
}
}
});
});
administerVO.setPermission(treeList);
return administerVO;
}
@Override
public IPage getAdministerPage(AdministerPageDTO administerPageDTO) {
Page page = new Page(administerPageDTO.getPageNo(), administerPageDTO.getPageSize());
return this.baseMapper.selectPage(page, new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getRole, administerPageDTO.getListItem())
.like(AdministerDO::getUsername, administerPageDTO.getUsername()));
}
}