All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openea.eap.module.system.convert.user.UserConvert Maven / Gradle / Ivy

Go to download

system 模块下,我们放通用业务,支撑上层的核心业务。 例如说:用户、部门、权限、数据字典等等

The newest version!
package org.openea.eap.module.system.convert.user;

import org.mapstruct.Mapping;
import org.openea.eap.framework.common.util.collection.CollectionUtils;
import org.openea.eap.framework.common.util.collection.MapUtils;
import org.openea.eap.framework.common.util.object.BeanUtils;
import org.openea.eap.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO;
import org.openea.eap.module.system.controller.admin.dept.vo.post.PostSimpleRespVO;
import org.openea.eap.module.system.controller.admin.permission.vo.role.RoleSimpleRespVO;
import org.openea.eap.module.system.controller.admin.user.vo.profile.UserProfileRespVO;
import org.openea.eap.module.system.controller.admin.user.vo.user.ExtUserListVo;
import org.openea.eap.module.system.controller.admin.user.vo.user.UserRespVO;
import org.openea.eap.module.system.controller.admin.user.vo.user.UserSimpleRespVO;
import org.openea.eap.module.system.dal.dataobject.dept.DeptDO;
import org.openea.eap.module.system.dal.dataobject.dept.PostDO;
import org.openea.eap.module.system.dal.dataobject.permission.RoleDO;
import org.openea.eap.module.system.dal.dataobject.social.SocialUserDO;
import org.openea.eap.module.system.dal.dataobject.user.AdminUserDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserConvert {

    UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);

    default List convertList(List list, Map deptMap) {
        return CollectionUtils.convertList(list, user -> convert(user, deptMap.get(user.getDeptId())));
    }

    default UserRespVO convert(AdminUserDO user, DeptDO dept) {
        UserRespVO userVO = BeanUtils.toBean(user, UserRespVO.class);
        if (dept != null) {
            userVO.setDeptName(dept.getName());
        }
        return userVO;
    }

    @Mapping(source = "bean.username", target = "account")
    @Mapping(source = "bean.nickname", target = "realName")
    @Mapping(source = "bean.avatar", target = "headIcon")
    ExtUserListVo convertIm(AdminUserDO bean);


    default List convertSimpleList(List list, Map deptMap) {
        return CollectionUtils.convertList(list, user -> {
            UserSimpleRespVO userVO = BeanUtils.toBean(user, UserSimpleRespVO.class);
            MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> userVO.setDeptName(dept.getName()));
            return userVO;
        });
    }

    default UserProfileRespVO convert(AdminUserDO user, List userRoles,
                                      DeptDO dept, List posts, List socialUsers) {
        UserProfileRespVO userVO = BeanUtils.toBean(user, UserProfileRespVO.class);
        userVO.setRoles(BeanUtils.toBean(userRoles, RoleSimpleRespVO.class));
        userVO.setDept(BeanUtils.toBean(dept, DeptSimpleRespVO.class));
        userVO.setPosts(BeanUtils.toBean(posts, PostSimpleRespVO.class));
        userVO.setSocialUsers(BeanUtils.toBean(socialUsers, UserProfileRespVO.SocialUser.class));
        return userVO;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy