AdministerServiceImpl.java
5.38 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
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.dao.AdministerPermissionDAO;
import com.zhongzhi.dao.AdministerTrackMappingDAO;
import com.zhongzhi.dto.administer.AdministerPageDTO;
import com.zhongzhi.dto.administer.LoginDTO;
import com.zhongzhi.model.*;
import com.zhongzhi.dao.AdministerDAO;
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.administer.GetAdministerPageVO;
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;
@Autowired
private AdministerTrackMappingDAO administerTrackMappingDAO;
@Autowired
private AdministerPermissionDAO administerPermissionDAO;
@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);
administerVO.setId(administerDO.getId());
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());
IPage<GetAdministerPageVO> page1 = this.baseMapper.getAdministerPage(page,administerPageDTO.getListItem(),administerPageDTO.getUsername());
List<GetAdministerPageVO> records = page1.getRecords();
for (GetAdministerPageVO getAdministerPageVO : records){
List<AdministerTrackMappingDO> administerTrackMappingDOS = administerTrackMappingDAO.selectList(new QueryWrapper<AdministerTrackMappingDO>()
.lambda()
.eq(AdministerTrackMappingDO::getAdministerId,getAdministerPageVO.getId()));
getAdministerPageVO.setAdministerTrackMappingDOS(administerTrackMappingDOS);
List<PermissionVO> list = permissionsService.getPermissionById(getAdministerPageVO.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);
}
}
});
});
getAdministerPageVO.setAdministerPermissionDOS(treeList);
}
return page1;
}
@Override
public void updateAdminister(AdministerDO administerDO){
this.baseMapper.updateAdminister(administerDO);
}
}