|
@@ -1,10 +1,53 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
+
|
|
|
+import org.apache.hc.client5.http.classic.methods.HttpGet;
|
|
|
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
|
|
|
+import org.apache.hc.client5.http.impl.classic.HttpClients;
|
|
|
+import org.apache.hc.core5.http.io.entity.EntityUtils;
|
|
|
+import org.apache.http.HttpStatus;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
|
|
+import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
+import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.DigestUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.annotation.IdType;
|
|
|
+import com.baomidou.mybatisplus.annotation.TableId;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.diagbot.client.AuthServiceClient;
|
|
|
-import com.diagbot.dto.*;
|
|
|
+import com.diagbot.dto.BasDeptInfoDTO;
|
|
|
+import com.diagbot.dto.BasHospitalInfoDTO;
|
|
|
+import com.diagbot.dto.JwtDTO;
|
|
|
+import com.diagbot.dto.LoginDTO;
|
|
|
+import com.diagbot.dto.SysRoleDTO;
|
|
|
+import com.diagbot.dto.SysUserDeptDTO;
|
|
|
+import com.diagbot.dto.SysUserPermissionDTO;
|
|
|
+import com.diagbot.dto.SysUserQueryDTO;
|
|
|
+import com.diagbot.dto.SysUserRoleDTO;
|
|
|
+import com.diagbot.dto.UserLoginDTO;
|
|
|
import com.diagbot.entity.BasHospitalInfo;
|
|
|
import com.diagbot.entity.ImageCaptchaParams;
|
|
|
import com.diagbot.entity.JWT;
|
|
@@ -38,25 +81,6 @@ import com.diagbot.vo.SysUserDeptVO;
|
|
|
import com.diagbot.vo.SysUserQueryVO;
|
|
|
import com.diagbot.vo.SysUserRoleVO;
|
|
|
import com.diagbot.vo.UserLoginVO;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
-import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
|
|
-import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
-import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.util.DigestUtils;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
-
|
|
|
-import javax.imageio.ImageIO;
|
|
|
-import javax.servlet.ServletOutputStream;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import javax.servlet.http.HttpSession;
|
|
|
-import java.awt.image.BufferedImage;
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description: 用户业务层
|
|
@@ -149,21 +173,143 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
* @return jwt
|
|
|
*/
|
|
|
public JwtDTO getJwt(HttpServletRequest request, UserLoginVO userLoginVO) {
|
|
|
- JwtDTO data = new JwtDTO();
|
|
|
+ JwtDTO data = new JwtDTO();
|
|
|
+ if(userLoginVO.getAuthToken() != null && userLoginVO.getAuthToken().trim().length() > 0) { //说明温附一的单点登录
|
|
|
+ //调用接口获取相应的数据
|
|
|
+
|
|
|
+ // 请求路径及参数
|
|
|
+ try {
|
|
|
+ // 创建 GET 请求对象
|
|
|
+ HttpGet httpGet = new HttpGet("https://wsyy.wzhospital.cn:8443/authentication/v1/login/getTokenUser");
|
|
|
+ httpGet.addHeader("token", userLoginVO.getAuthToken());
|
|
|
+ // 调用 HttpClient 的 execute 方法执行请求
|
|
|
+ CloseableHttpResponse response = HttpClients.createDefault().execute(httpGet);
|
|
|
+ // 获取请求状态
|
|
|
+ int code = response.getCode();
|
|
|
+ // 如果请求成功
|
|
|
+ if(code == HttpStatus.SC_OK){
|
|
|
+ String result = EntityUtils.toString(response.getEntity());
|
|
|
+ JSONObject json = JSON.parseObject(result);
|
|
|
+
|
|
|
+ String userId = json.getJSONObject("data").getInteger("yongHuID")+"_"+json.getJSONObject("data").getString("xingMing");
|
|
|
+
|
|
|
+ sys_user
|
|
|
+ sys_user_role
|
|
|
+ sys_user_hospital
|
|
|
+
|
|
|
+
|
|
|
+ QueryWrapper<SysUser> userQueryWrapper = new QueryWrapper<>();
|
|
|
+ userQueryWrapper.eq("username", userId);
|
|
|
+ SysUser user = this.getOne(userQueryWrapper, false);
|
|
|
+ if (null == user) {
|
|
|
+ //新增这个用户
|
|
|
+ SysUser new_user = new SysUser();
|
|
|
+ new_user.setIsDeleted("N");
|
|
|
+ new_user.setCreator("0");
|
|
|
+ new_user.setUsername(userId);
|
|
|
+ new_user.setLinkman(json.getJSONObject("data").getString("xingMing"));
|
|
|
+ new_user.setType(0);
|
|
|
+ new_user.setStatus(1);
|
|
|
+ save(new_user);
|
|
|
+
|
|
|
+ user = new_user;
|
|
|
+ //关联角色
|
|
|
+
|
|
|
+ SysUserRole sur = new SysUserRole();
|
|
|
+ sur.setIsDeleted("N");
|
|
|
+ sur.setCreator("0");
|
|
|
+ sur.setUserId(new_user.getId());
|
|
|
+ sur.setRoleId(1L);
|
|
|
+ sysUserRoleService.save(sur);
|
|
|
+
|
|
|
+ //关联医院
|
|
|
+ SysUserHospital suh = new SysUserHospital();
|
|
|
+ suh.setIsDeleted();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否删除,N:未删除,Y:删除
|
|
|
+ */
|
|
|
+ private String isDeleted;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户主键
|
|
|
+ */
|
|
|
+ private Long userId;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 医院ID
|
|
|
+ */
|
|
|
+ private Long hospitalId;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 备注
|
|
|
+ */
|
|
|
+ private String remark;
|
|
|
+
|
|
|
+
|
|
|
+ }else {
|
|
|
+ //设置部门
|
|
|
+ user.setRemark(result);
|
|
|
+ }
|
|
|
+ JWT jwt = authServiceClient.getToken("Basic dWFhLXNlcnZpY2U6MTIzNDU2","password", userLoginVO.getUsername(), "");
|
|
|
+ if (null == jwt) {
|
|
|
+ throw new CommonException(ServiceErrorCode.GET_TOKEN_FAIL);
|
|
|
+ }
|
|
|
+ data.setAccessToken(jwt.getAccess_token());
|
|
|
+ data.setRefreshToken(jwt.getRefresh_token());
|
|
|
+ data.setType(user.getType());
|
|
|
+ data.setTypeCn(ConstantEnum.getName(user.getType()));//返回中文
|
|
|
+ //获取用户角色
|
|
|
+ try {
|
|
|
+ SysUserBaseVO sysUserBaseVO = new SysUserBaseVO();
|
|
|
+ sysUserBaseVO.setUserId(user.getId());
|
|
|
+ List<SysRoleDTO> selRoles = getlocalUserRoles(sysUserBaseVO);
|
|
|
+ if (selRoles != null && !selRoles.isEmpty()) {
|
|
|
+ data.setSelRoles(selRoles);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ //token存入redis
|
|
|
+ JwtStore jwtStore = new JwtStore();
|
|
|
+ jwtStore.setAccessToken(jwt.getAccess_token());
|
|
|
+ jwtStore.setRefreshToken(jwt.getRefresh_token());
|
|
|
+ tokenFacade.createToken(jwtStore);
|
|
|
+
|
|
|
+ //每次登录在redis缓存该用户登录成功的token;缓存时间为token有效时间
|
|
|
+ long accessTokenTime = sysDictionaryFacade.getAccessTokenOutTime();
|
|
|
+ redisUtils.set("user:refreshToken:outTime_" + user.getId(), accessTokenTime, accessTokenTime);
|
|
|
+ // 获取用户医院id
|
|
|
+ // String hospitalID = SysUserUtils.getCurrentHospitalID();
|
|
|
+ Long id = user.getId();
|
|
|
+ QueryWrapper<SysUserHospital> UserHospitalQueryWrapper = new QueryWrapper<>();
|
|
|
+ UserHospitalQueryWrapper.eq("user_id", id).eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
+ SysUserHospital userHospital = sysUserHospitalFacade.getOne(UserHospitalQueryWrapper, false);
|
|
|
+ Long hospitalId = userHospital.getHospitalId();
|
|
|
+ String idStr = String.valueOf(hospitalId);
|
|
|
+ Boolean passwordRegular = passwordRegular(userLoginVO.getPassword(), idStr);
|
|
|
+ if (!passwordRegular) {
|
|
|
+ data.setPasswordComplexity("未修改初始密码,请及时修改密码");
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ //查找是否有这个用户
|
|
|
+ }
|
|
|
+ }catch(Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
if (StringUtil.isBlank(userLoginVO.getUsername())) {
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
- "请输入用户名");
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL,"请输入用户名");
|
|
|
}
|
|
|
if (StringUtil.isBlank(userLoginVO.getPassword())) {
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
- "请输入密码");
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL,"请输入密码");
|
|
|
}
|
|
|
//非湘雅医院执行
|
|
|
String captchaId = "";
|
|
|
if (0L == getHospitalMark()) {
|
|
|
if (StringUtils.isEmpty(userLoginVO.getCaptcha())) {
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
- "请输入验证码");
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL,"请输入验证码");
|
|
|
}
|
|
|
// 验证码校验
|
|
|
captchaId = request.getSession().getId();
|
|
@@ -176,9 +322,8 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
//使用MD5对密码进行加密
|
|
|
String MD5Password = DigestUtils.md5DigestAsHex(userLoginVO.getPassword().getBytes());
|
|
|
QueryWrapper<SysUser> userQueryWrapper = new QueryWrapper<>();
|
|
|
- userQueryWrapper.eq("username", userLoginVO.getUsername())
|
|
|
- .eq("status", StatusEnum.Enable.getKey())
|
|
|
- .eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
+ userQueryWrapper.eq("username", userLoginVO.getUsername()).eq("status", StatusEnum.Enable.getKey()).eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
+
|
|
|
SysUser user = this.getOne(userQueryWrapper, false);
|
|
|
if (null == user) {
|
|
|
throw new CommonException(ServiceErrorCode.USER_NOT_FOUND);
|