提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.system.convert.user; |
H |
2 |
|
|
3 |
import com.iailab.framework.common.util.collection.CollectionUtils; |
|
4 |
import com.iailab.framework.common.util.collection.MapUtils; |
|
5 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
6 |
import com.iailab.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; |
|
7 |
import com.iailab.module.system.controller.admin.dept.vo.post.PostSimpleRespVO; |
|
8 |
import com.iailab.module.system.controller.admin.permission.vo.role.RoleSimpleRespVO; |
|
9 |
import com.iailab.module.system.controller.admin.user.vo.profile.UserProfileRespVO; |
|
10 |
import com.iailab.module.system.controller.admin.user.vo.user.UserRespVO; |
|
11 |
import com.iailab.module.system.controller.admin.user.vo.user.UserSimpleRespVO; |
|
12 |
import com.iailab.module.system.dal.dataobject.dept.DeptDO; |
|
13 |
import com.iailab.module.system.dal.dataobject.dept.PostDO; |
|
14 |
import com.iailab.module.system.dal.dataobject.permission.RoleDO; |
|
15 |
import com.iailab.module.system.dal.dataobject.social.SocialUserDO; |
|
16 |
import com.iailab.module.system.dal.dataobject.user.AdminUserDO; |
|
17 |
import org.mapstruct.Mapper; |
|
18 |
import org.mapstruct.factory.Mappers; |
|
19 |
|
|
20 |
import java.util.List; |
|
21 |
import java.util.Map; |
|
22 |
|
|
23 |
@Mapper |
|
24 |
public interface UserConvert { |
|
25 |
|
|
26 |
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class); |
|
27 |
|
|
28 |
default List<UserRespVO> convertList(List<AdminUserDO> list, Map<Long, DeptDO> deptMap) { |
|
29 |
return CollectionUtils.convertList(list, user -> convert(user, deptMap.get(user.getDeptId()))); |
|
30 |
} |
|
31 |
|
|
32 |
default UserRespVO convert(AdminUserDO user, DeptDO dept) { |
|
33 |
UserRespVO userVO = BeanUtils.toBean(user, UserRespVO.class); |
|
34 |
if (dept != null) { |
|
35 |
userVO.setDeptName(dept.getName()); |
|
36 |
} |
|
37 |
return userVO; |
|
38 |
} |
|
39 |
|
|
40 |
default List<UserSimpleRespVO> convertSimpleList(List<AdminUserDO> list, Map<Long, DeptDO> deptMap) { |
|
41 |
return CollectionUtils.convertList(list, user -> { |
|
42 |
UserSimpleRespVO userVO = BeanUtils.toBean(user, UserSimpleRespVO.class); |
|
43 |
MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> userVO.setDeptName(dept.getName())); |
|
44 |
return userVO; |
|
45 |
}); |
|
46 |
} |
|
47 |
|
|
48 |
default UserProfileRespVO convert(AdminUserDO user, List<RoleDO> userRoles, |
|
49 |
DeptDO dept, List<PostDO> posts, List<SocialUserDO> socialUsers) { |
|
50 |
UserProfileRespVO userVO = BeanUtils.toBean(user, UserProfileRespVO.class); |
|
51 |
userVO.setRoles(BeanUtils.toBean(userRoles, RoleSimpleRespVO.class)); |
|
52 |
userVO.setDept(BeanUtils.toBean(dept, DeptSimpleRespVO.class)); |
|
53 |
userVO.setPosts(BeanUtils.toBean(posts, PostSimpleRespVO.class)); |
|
54 |
userVO.setSocialUsers(BeanUtils.toBean(socialUsers, UserProfileRespVO.SocialUser.class)); |
|
55 |
return userVO; |
|
56 |
} |
|
57 |
|
|
58 |
} |