|
@@ -46,6 +46,13 @@ 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;
|
|
@@ -96,9 +103,9 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
private RedisUtils redisUtils;
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 获取标识--选择登录页面
|
|
|
+ *
|
|
|
* @return java.lang.Long
|
|
|
*/
|
|
|
public Long getHospitalMark() {
|
|
@@ -107,30 +114,39 @@ 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 ImageCaptchaDTO getCaptcha() throws IOException {
|
|
|
- ImageCaptchaDTO base64ForWeb = ImageCaptchaUtil.createBase64ForWeb(new ImageCaptchaParams());
|
|
|
- String key = UUID.randomUUID().toString();
|
|
|
- base64ForWeb.setCaptchaId(key);
|
|
|
- redisUtils.set(key, base64ForWeb.getWords(), 60*2);
|
|
|
- return base64ForWeb;
|
|
|
- };
|
|
|
+ public void getCaptcha(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
+ HttpSession session = request.getSession();
|
|
|
+ String captchaId = session.getId();
|
|
|
+ session.setAttribute("captchaId", captchaId);
|
|
|
+ ServletOutputStream outputStream = response.getOutputStream();
|
|
|
+ ImageCaptchaUtil imageCaptchaUtil = new ImageCaptchaUtil();
|
|
|
+ BufferedImage image = imageCaptchaUtil.createRandom();
|
|
|
+ String captcha = imageCaptchaUtil.getText();
|
|
|
+ ImageIO.write(image, ImageCaptchaParams.DEFAULT_FORMAT, outputStream);
|
|
|
+ outputStream.flush();
|
|
|
+ outputStream.close();
|
|
|
+ redisUtils.set("user:captcha" + captchaId, captcha, 60 * 3);
|
|
|
+ }
|
|
|
+
|
|
|
+ ;
|
|
|
|
|
|
/**
|
|
|
* 获取jwt
|
|
|
+ *
|
|
|
* @param username 用户名
|
|
|
* @param password 密码
|
|
|
* @return jwt
|
|
|
*/
|
|
|
- public JwtDTO getJwt(String username, String password, String captcha, String captchaId) {
|
|
|
+ public JwtDTO getJwt(HttpServletRequest request, String username, String password, String captcha) {
|
|
|
JwtDTO data = new JwtDTO();
|
|
|
if (StringUtil.isBlank(username)) {
|
|
|
throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
@@ -140,17 +156,17 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
"请输入密码");
|
|
|
}
|
|
|
- /* if (StringUtils.isEmpty(captcha)) {
|
|
|
+ if (StringUtils.isEmpty(captcha)) {
|
|
|
throw new CommonException(CommonErrorCode.PARAM_IS_NULL,
|
|
|
"请输入验证码");
|
|
|
}
|
|
|
// 验证码校验
|
|
|
- Object captchaObject= redisUtils.get(captchaId);
|
|
|
- redisUtils.del(captchaId);
|
|
|
- if(null == captchaObject || StringUtils.isEmpty(captchaObject.toString()) || !captchaObject.toString().trim().equalsIgnoreCase(captcha)){
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,"验证码错误");
|
|
|
- }
|
|
|
-*/
|
|
|
+ String captchaId = request.getSession().getId();
|
|
|
+ Object captchaObject = redisUtils.get("user:captcha" + captchaId);
|
|
|
+ redisUtils.del("user:captcha" + captchaId);
|
|
|
+ if (null == captchaObject || StringUtils.isEmpty(captchaObject.toString()) || !captchaObject.toString().trim().equalsIgnoreCase(captcha)) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_ERROR, "验证码错误");
|
|
|
+ }
|
|
|
//使用MD5对密码进行加密
|
|
|
String MD5Password = DigestUtils.md5DigestAsHex(password.getBytes());
|
|
|
QueryWrapper<SysUser> userQueryWrapper = new QueryWrapper<>();
|
|
@@ -178,15 +194,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
|
|
@@ -197,8 +210,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
|
|
@@ -207,8 +220,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(password, idStr);
|
|
|
+ if (!passwordRegular) {
|
|
|
data.setPasswordComplexity("未修改初始密码,请及时修改密码");
|
|
|
}
|
|
|
return data;
|
|
@@ -320,8 +333,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();
|
|
@@ -351,23 +364,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;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 登录
|
|
|
*
|
|
@@ -382,13 +397,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,
|
|
@@ -411,8 +426,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);
|
|
@@ -568,6 +583,7 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
|
|
|
return sysUserRoleDTO;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 获取用户角色
|
|
|
*
|