|
@@ -1,139 +0,0 @@
|
|
|
-package com.lantone.security.facade;
|
|
|
-
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.diagbot.enums.IsDeleteEnum;
|
|
|
-import com.diagbot.exception.CommonErrorCode;
|
|
|
-import com.diagbot.exception.CommonException;
|
|
|
-import com.diagbot.util.ListUtil;
|
|
|
-import com.diagbot.util.StringUtil;
|
|
|
-import com.lantone.common.dto.HospitalDTO;
|
|
|
-import com.lantone.common.dto.MenuInfoDTO;
|
|
|
-import com.lantone.common.dto.RoleDTO;
|
|
|
-import com.lantone.dblayermbg.entity.Hospital;
|
|
|
-import com.lantone.dblayermbg.entity.User;
|
|
|
-import com.lantone.dblayermbg.entity.UserRole;
|
|
|
-import com.lantone.dblayermbg.facade.UserRoleFacade;
|
|
|
-import com.lantone.dblayermbg.service.impl.UserServiceImpl;
|
|
|
-import com.lantone.security.client.AuthServiceClient;
|
|
|
-import com.lantone.security.dto.JWT;
|
|
|
-import com.lantone.security.dto.JwtDTO;
|
|
|
-import com.lantone.security.dto.JwtStore;
|
|
|
-import com.lantone.security.enums.StatusEnum;
|
|
|
-import com.lantone.security.exception.ServiceErrorCode;
|
|
|
-import com.lantone.security.util.SysUserUtils;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
|
|
-import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.util.DigestUtils;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
-/**
|
|
|
- * <p>
|
|
|
- * 系统用户表 服务实现类Facade
|
|
|
- * </p>
|
|
|
- */
|
|
|
-@Component
|
|
|
-public class UserLoginFacade extends UserServiceImpl {
|
|
|
- @Autowired
|
|
|
- private TokenFacade tokenFacade;
|
|
|
- @Autowired
|
|
|
- private AuthServiceClient authServiceClient;
|
|
|
- @Autowired
|
|
|
- private UserRoleFacade userRoleFacade;
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取jwt
|
|
|
- *
|
|
|
- * @param username 用户名
|
|
|
- * @param password 密码
|
|
|
- * @return jwt
|
|
|
- */
|
|
|
- public JwtDTO getJwt(String username, String password) {
|
|
|
- JwtDTO data = new JwtDTO();
|
|
|
- if (StringUtil.isBlank(username)) {
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
- "请输入用户名");
|
|
|
- }
|
|
|
- if (StringUtil.isBlank(password)) {
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
- "请输入密码");
|
|
|
- }
|
|
|
- //使用MD5对密码进行加密
|
|
|
- String MD5Password = DigestUtils.md5DigestAsHex(password.getBytes());
|
|
|
- QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
|
|
|
- userQueryWrapper.eq("username", username)
|
|
|
- .eq("status", StatusEnum.Enable.getKey())
|
|
|
- .eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
- User user = this.getOne(userQueryWrapper, false);
|
|
|
- if (null == user) {
|
|
|
- throw new CommonException(ServiceErrorCode.USER_NOT_FOUND);
|
|
|
- }
|
|
|
- PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
|
|
- if (!passwordEncoder.matches(MD5Password, user.getPassword())) {
|
|
|
- throw new CommonException(ServiceErrorCode.USER_PASSWORD_ERROR);
|
|
|
- }
|
|
|
- JWT jwt = authServiceClient.getToken("Basic dWFhLXNlcnZpY2U6MTIzNDU2",
|
|
|
- "password", username, MD5Password);
|
|
|
- if (null == jwt) {
|
|
|
- throw new CommonException(ServiceErrorCode.GET_TOKEN_FAIL);
|
|
|
- }
|
|
|
- data.setAccessToken(jwt.getAccess_token());
|
|
|
- data.setRefreshToken(jwt.getRefresh_token());
|
|
|
- //获取用户组织信息
|
|
|
- Long id = user.getId();
|
|
|
- List<Hospital> hospitals = this.baseMapper.getUserOrganizeByUserID(id);
|
|
|
- if (ListUtil.isNotEmpty(hospitals)) {
|
|
|
- List<HospitalDTO> organizeDTOS = new ArrayList<>();
|
|
|
- //获取用户当前组织下的角色信息
|
|
|
- for (Hospital hospital: hospitals) {
|
|
|
- HospitalDTO hospitalDTO = new HospitalDTO();
|
|
|
- BeanUtils.copyProperties(hospital,hospitalDTO);
|
|
|
- if(hospital.getId()!=null){
|
|
|
- List<RoleDTO> roles= this.baseMapper.getUserRoleByUserID(id,hospital.getId());
|
|
|
- hospitalDTO.setRoles(roles);
|
|
|
- }
|
|
|
- organizeDTOS.add(hospitalDTO);
|
|
|
- }
|
|
|
- data.setOrganizes(organizeDTOS);
|
|
|
- }
|
|
|
-
|
|
|
- //token存入redis
|
|
|
- JwtStore jwtStore = new JwtStore();
|
|
|
- jwtStore.setAccessToken(jwt.getAccess_token());
|
|
|
- jwtStore.setRefreshToken(jwt.getRefresh_token());
|
|
|
- tokenFacade.createToken(jwtStore);
|
|
|
- return data;
|
|
|
- }
|
|
|
- /**
|
|
|
- * @Author songxl
|
|
|
- * @Description 获取用户显示的菜单
|
|
|
- * @Date 2021/7/19
|
|
|
- * @Param []
|
|
|
- * @Return com.lantone.security.dto.MenuInfoDTO
|
|
|
- * @MethodName getUserOrgMenu
|
|
|
- */
|
|
|
- public MenuInfoDTO getUserOrgMenu() {
|
|
|
- MenuInfoDTO menuInfoDTO = new MenuInfoDTO();
|
|
|
- Set<String> roleSet = new HashSet<>();
|
|
|
- Long userId = Long.parseLong(SysUserUtils.getCurrentPrincipleID());
|
|
|
- //获取当前登录用户角色
|
|
|
- List<UserRole> userRoles = userRoleFacade.list(new QueryWrapper<UserRole>()
|
|
|
- .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .eq("status", StatusEnum.Enable.getKey())
|
|
|
- .eq("id", userId));
|
|
|
- //1.超级管理员
|
|
|
- if(!ListUtil.isEmpty(userRoles)&&userRoles.contains(0)){
|
|
|
-
|
|
|
- }
|
|
|
- //添加菜单信息
|
|
|
- return menuInfoDTO;
|
|
|
- }
|
|
|
-
|
|
|
-}
|