xyz.migoo.framework.infra.convert.AuthConvert Maven / Gradle / Ivy
The newest version!
package xyz.migoo.framework.infra.convert;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import org.slf4j.LoggerFactory;
import xyz.migoo.framework.common.util.collection.CollectionUtils;
import xyz.migoo.framework.infra.controller.login.vo.AuthMenuRespVO;
import xyz.migoo.framework.infra.controller.login.vo.AuthUserInfoRespVO;
import xyz.migoo.framework.infra.dal.dataobject.sys.Menu;
import xyz.migoo.framework.infra.enums.MenuIdEnum;
import xyz.migoo.framework.security.core.BaseUser;
import xyz.migoo.framework.security.core.LoginUser;
import java.util.*;
import static xyz.migoo.framework.common.enums.CommonStatus.isDisabled;
import static xyz.migoo.framework.common.enums.CommonStatus.isEnabled;
@Mapper
public interface AuthConvert {
AuthConvert INSTANCE = Mappers.getMapper(AuthConvert.class);
/**
* 转换为登录用户对象
*
* @param user 管理员或会员
* @return 登录用户对象
*/
default LoginUser convert(BaseUser user) {
return new LoginUser()
.setRequiredBindAuthenticator(isDisabled(user.getBindAuthenticator()))
.setRequiredVerifyAuthenticator(isEnabled(user.getRequiredVerifyAuthenticator()))
.setId(user.getId())
.setName(user.getName())
.setUpdateTime(new Date())
.setEnabled(isEnabled(user.getStatus()))
.setUsername(user.getUsername())
.setPassword(user.getPassword())
.setSecurityCode(user.getSecretKey());
}
default AuthUserInfoRespVO convert(BaseUser user, Set permissions) {
return new AuthUserInfoRespVO()
.setName(user.getName())
.setAvatar(user.getAvatar())
.setPermissions(permissions);
}
default AuthUserInfoRespVO convert(BaseUser user, List