|
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.diagbot.client.AuthServiceClient;
|
|
|
import com.diagbot.dto.*;
|
|
|
import com.diagbot.entity.BasHospitalInfo;
|
|
|
+import com.diagbot.entity.ImageCaptchaParams;
|
|
|
import com.diagbot.entity.JWT;
|
|
|
import com.diagbot.entity.JwtStore;
|
|
|
import com.diagbot.entity.SysHospitalSet;
|
|
@@ -26,7 +27,9 @@ import com.diagbot.service.impl.SysUserServiceImpl;
|
|
|
import com.diagbot.util.BeanUtil;
|
|
|
import com.diagbot.util.DateUtil;
|
|
|
import com.diagbot.util.EntityUtil;
|
|
|
+import com.diagbot.util.ImageCaptchaUtil;
|
|
|
import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.RedisUtils;
|
|
|
import com.diagbot.util.StringUtil;
|
|
|
import com.diagbot.util.SysUserUtils;
|
|
|
import com.diagbot.vo.BasDeptInfoVO;
|
|
@@ -34,6 +37,7 @@ import com.diagbot.vo.SysUserBaseVO;
|
|
|
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;
|
|
@@ -41,7 +45,16 @@ 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;
|
|
|
|
|
@@ -87,12 +100,13 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
private SysDictionaryFacade sysDictionaryFacade;
|
|
|
@Autowired
|
|
|
private SysHospitalSetFacade sysHospitalSetFacade;
|
|
|
-
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private RedisUtils redisUtils;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取标识--选择登录页面
|
|
|
+ *
|
|
|
* @return java.lang.Long
|
|
|
*/
|
|
|
public Long getHospitalMark() {
|
|
@@ -101,34 +115,67 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
.eq(SysHospitalSet::getHospitalId, 35)
|
|
|
.eq(SysHospitalSet::getIsDeleted, IsDeleteEnum.N.getKey())
|
|
|
.eq(SysHospitalSet::getCode, "special_page_csxy").one();
|
|
|
- if(null != sysHospitalSet){
|
|
|
+ if (null != sysHospitalSet) {
|
|
|
String val = sysHospitalSet.getValue();
|
|
|
- if(StringUtil.isNotBlank(val) && "1".equals(val)){
|
|
|
- mark = Long.valueOf(val);
|
|
|
+ if (StringUtil.isNotBlank(val) && "1".equals(val)) {
|
|
|
+ mark = Long.valueOf(val);
|
|
|
}
|
|
|
}
|
|
|
return mark;
|
|
|
}
|
|
|
+
|
|
|
+ public void getCaptcha(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
+ response.setContentType("image/png");
|
|
|
+ response.setHeader("Pragma", "no-cache");
|
|
|
+ response.setHeader("Cache-Control", "no-cache");
|
|
|
+ response.setDateHeader("Expires", 0);
|
|
|
+ HttpSession session = request.getSession();
|
|
|
+ String captchaId = session.getId();
|
|
|
+ ServletOutputStream outputStream = response.getOutputStream();
|
|
|
+ ImageCaptchaUtil imageCaptchaUtil = new ImageCaptchaUtil();
|
|
|
+ BufferedImage image = imageCaptchaUtil.createRandom();
|
|
|
+ String captcha = imageCaptchaUtil.getText();
|
|
|
+ redisUtils.set("user:captchaIds:" + captchaId, captcha, 60 * 3);
|
|
|
+ ImageIO.write(image, ImageCaptchaParams.DEFAULT_FORMAT, outputStream);
|
|
|
+ outputStream.flush();
|
|
|
+ outputStream.close();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取jwt
|
|
|
- * @param username 用户名
|
|
|
- * @param password 密码
|
|
|
+ *
|
|
|
+ * userLoginVO
|
|
|
* @return jwt
|
|
|
*/
|
|
|
- public JwtDTO getJwt(String username, String password) {
|
|
|
+ public JwtDTO getJwt(HttpServletRequest request, UserLoginVO userLoginVO) {
|
|
|
JwtDTO data = new JwtDTO();
|
|
|
- if (StringUtil.isBlank(username)) {
|
|
|
+ if (StringUtil.isBlank(userLoginVO.getUsername())) {
|
|
|
throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
"请输入用户名");
|
|
|
}
|
|
|
- if (StringUtil.isBlank(password)) {
|
|
|
+ if (StringUtil.isBlank(userLoginVO.getPassword())) {
|
|
|
throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
"请输入密码");
|
|
|
}
|
|
|
+ //非湘雅医院执行
|
|
|
+ String captchaId ="";
|
|
|
+ if(0L == getHospitalMark()) {
|
|
|
+ if ( StringUtils.isEmpty(userLoginVO.getCaptcha())) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
+ "请输入验证码");
|
|
|
+ }
|
|
|
+ // 验证码校验
|
|
|
+ captchaId = request.getSession().getId();
|
|
|
+ Object captchaObject = redisUtils.get("user:captchaIds:" + captchaId);
|
|
|
+ if (null == captchaObject || StringUtil.isBlank(captchaObject.toString()) || !captchaObject.toString().trim().equalsIgnoreCase(userLoginVO.getCaptcha())) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "验证码错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//使用MD5对密码进行加密
|
|
|
- String MD5Password = DigestUtils.md5DigestAsHex(password.getBytes());
|
|
|
+ String MD5Password = DigestUtils.md5DigestAsHex(userLoginVO.getPassword().getBytes());
|
|
|
QueryWrapper<SysUser> userQueryWrapper = new QueryWrapper<>();
|
|
|
- userQueryWrapper.eq("username", username)
|
|
|
+ userQueryWrapper.eq("username", userLoginVO.getUsername())
|
|
|
.eq("status", StatusEnum.Enable.getKey())
|
|
|
.eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
SysUser user = this.getOne(userQueryWrapper, false);
|
|
@@ -140,10 +187,13 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
throw new CommonException(ServiceErrorCode.USER_PASSWORD_ERROR);
|
|
|
}
|
|
|
JWT jwt = authServiceClient.getToken("Basic dWFhLXNlcnZpY2U6MTIzNDU2",
|
|
|
- "password", username, MD5Password);
|
|
|
+ "password", userLoginVO.getUsername(), MD5Password);
|
|
|
if (null == jwt) {
|
|
|
throw new CommonException(ServiceErrorCode.GET_TOKEN_FAIL);
|
|
|
}
|
|
|
+ if(0L == getHospitalMark()) {
|
|
|
+ redisUtils.del("user:captchaIds:" + captchaId);
|
|
|
+ }
|
|
|
data.setAccessToken(jwt.getAccess_token());
|
|
|
data.setRefreshToken(jwt.getRefresh_token());
|
|
|
data.setType(user.getType());
|
|
@@ -152,15 +202,12 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
try {
|
|
|
SysUserBaseVO sysUserBaseVO = new SysUserBaseVO();
|
|
|
sysUserBaseVO.setUserId(user.getId());
|
|
|
- List<SysRoleDTO> selRoles =getlocalUserRoles(sysUserBaseVO);
|
|
|
- if(selRoles!=null&&!selRoles.isEmpty())
|
|
|
- {
|
|
|
+ List<SysRoleDTO> selRoles = getlocalUserRoles(sysUserBaseVO);
|
|
|
+ if (selRoles != null && !selRoles.isEmpty()) {
|
|
|
data.setSelRoles(selRoles);
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
//token存入redis
|
|
@@ -171,8 +218,8 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
/***
|
|
|
* 未经过MD5加密密码复杂度判断
|
|
|
*/
|
|
|
- // 获取用户医院id
|
|
|
- // String hospitalID = SysUserUtils.getCurrentHospitalID();
|
|
|
+ // 获取用户医院id
|
|
|
+ // String hospitalID = SysUserUtils.getCurrentHospitalID();
|
|
|
Long id = user.getId();
|
|
|
QueryWrapper<SysUserHospital> UserHospitalQueryWrapper = new QueryWrapper<>();
|
|
|
UserHospitalQueryWrapper
|
|
@@ -181,8 +228,8 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
SysUserHospital userHospital = sysUserHospitalFacade.getOne(UserHospitalQueryWrapper, false);
|
|
|
Long hospitalId = userHospital.getHospitalId();
|
|
|
String idStr = String.valueOf(hospitalId);
|
|
|
- Boolean passwordRegular = passwordRegular(password,idStr);
|
|
|
- if(!passwordRegular){
|
|
|
+ Boolean passwordRegular = passwordRegular(userLoginVO.getPassword(), idStr);
|
|
|
+ if (!passwordRegular) {
|
|
|
data.setPasswordComplexity("未修改初始密码,请及时修改密码");
|
|
|
}
|
|
|
return data;
|
|
@@ -294,8 +341,8 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
}
|
|
|
//对传入的密码进行格式验证
|
|
|
String hospitalID = SysUserUtils.getCurrentHospitalID();
|
|
|
- Boolean regularBoolean = passwordRegular(modifyPassword,hospitalID);
|
|
|
- if(!regularBoolean){
|
|
|
+ Boolean regularBoolean = passwordRegular(modifyPassword, hospitalID);
|
|
|
+ if (!regularBoolean) {
|
|
|
throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "请输入正确格式的新密码");
|
|
|
}
|
|
|
String userId = SysUserUtils.getCurrentPrincipleID();
|
|
@@ -325,23 +372,25 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
|
|
|
/**
|
|
|
* 未加密密文正则表达式 至少8个字符,1个大写字母,1个小写字母,1个数字和1个特殊字符:
|
|
|
+ *
|
|
|
* @param password
|
|
|
* @return
|
|
|
*/
|
|
|
- public Boolean passwordRegular(String password,String hospitalId){
|
|
|
- boolean check=true;
|
|
|
+ public Boolean passwordRegular(String password, String hospitalId) {
|
|
|
+ boolean check = true;
|
|
|
Map<String, Map<String, String>> dictionaryWithKey = sysDictionaryFacade.getDictionaryWithKey();
|
|
|
- if(dictionaryWithKey!=null){
|
|
|
+ if (dictionaryWithKey != null) {
|
|
|
Map<String, String> stringStringMap = dictionaryWithKey.get("30");
|
|
|
- if(stringStringMap!=null) {
|
|
|
+ if (stringStringMap != null) {
|
|
|
String regular = stringStringMap.get(hospitalId);
|
|
|
- if(StringUtil.isNotEmpty(regular)) {
|
|
|
+ if (StringUtil.isNotEmpty(regular)) {
|
|
|
check = password.matches(regular);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return check;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 登录
|
|
|
*
|
|
@@ -356,13 +405,13 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
.eq("status", StatusEnum.Enable.getKey())
|
|
|
.eq("id", userId), false);
|
|
|
QueryWrapper<SysUserRole> sysUserRoleQueryWrapper = new QueryWrapper<>();
|
|
|
- sysUserRoleQueryWrapper.eq("user_id",userId);
|
|
|
- sysUserRoleQueryWrapper .eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
+ sysUserRoleQueryWrapper.eq("user_id", userId);
|
|
|
+ sysUserRoleQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
List<SysUserRole> sysUserRoleList = sysUserRoleFacade.list(sysUserRoleQueryWrapper);
|
|
|
- if(ListUtil.isNotEmpty(sysUserRoleList)){
|
|
|
- sysUserRoleList.forEach(sysUserRole ->{
|
|
|
- roleSet.add(sysUserRole.getRoleId()+"");
|
|
|
- } );
|
|
|
+ if (ListUtil.isNotEmpty(sysUserRoleList)) {
|
|
|
+ sysUserRoleList.forEach(sysUserRole -> {
|
|
|
+ roleSet.add(sysUserRole.getRoleId() + "");
|
|
|
+ });
|
|
|
}
|
|
|
if (user == null) {
|
|
|
throw new CommonException(CommonErrorCode.SERVER_IS_ERROR,
|
|
@@ -385,8 +434,8 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
}
|
|
|
|
|
|
//添加菜单信息
|
|
|
- List<SysMenuWrapper> menuList = sysMenuFacade.getByRole(user.getId(),roleSet);
|
|
|
- List<SysUserPermissionDTO> sysUserPermissionDTOList = sysMenuFacade.getByRolePermission(user.getId(),roleSet);
|
|
|
+ List<SysMenuWrapper> menuList = sysMenuFacade.getByRole(user.getId(), roleSet);
|
|
|
+ List<SysUserPermissionDTO> sysUserPermissionDTOList = sysMenuFacade.getByRolePermission(user.getId(), roleSet);
|
|
|
Map<Long, List<SysMenuWrapper>> menuMap = EntityUtil.makeEntityListMap(menuList, "parentId");
|
|
|
Map<Long, List<SysUserPermissionDTO>> menuPermissionMap = EntityUtil.makeEntityListMap(sysUserPermissionDTOList, "menuId");
|
|
|
List<SysMenuWrapper> menuRes = menuMap.get(-1L);
|
|
@@ -542,6 +591,7 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
|
|
|
return sysUserRoleDTO;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 获取用户角色
|
|
|
*
|