|
@@ -1,6 +1,8 @@
|
|
|
package com.lantone.security.facade;
|
|
|
|
|
|
import cn.hutool.crypto.digest.BCrypt;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -14,6 +16,7 @@ import com.lantone.common.dto.GetUserDTO;
|
|
|
import com.lantone.common.dto.GetUserHospitalDeptDTO;
|
|
|
import com.lantone.common.dto.GetUserHospitalsDTO;
|
|
|
import com.lantone.common.dto.GetUserPageDTO;
|
|
|
+import com.lantone.common.dto.LoginLogDTO;
|
|
|
import com.lantone.common.dto.SoftwareDTO;
|
|
|
import com.lantone.common.dto.UserInfoDTO;
|
|
|
import com.lantone.common.dto.UserRoleDTO;
|
|
@@ -23,6 +26,7 @@ import com.lantone.common.enums.StatusEnum;
|
|
|
import com.lantone.common.exception.Asserts;
|
|
|
import com.lantone.common.util.DateUtil;
|
|
|
import com.lantone.common.util.EntityUtil;
|
|
|
+import com.lantone.common.util.HttpUtils;
|
|
|
import com.lantone.common.util.ListUtil;
|
|
|
import com.lantone.common.util.StringUtil;
|
|
|
import com.lantone.common.util.SysUserUtils;
|
|
@@ -50,6 +54,7 @@ import com.lantone.dblayermbg.facade.MedoupDoctorFacade;
|
|
|
import com.lantone.dblayermbg.facade.RoleFacade;
|
|
|
import com.lantone.dblayermbg.facade.UserFacade;
|
|
|
import com.lantone.dblayermbg.facade.UserRoleFacade;
|
|
|
+import com.lantone.security.component.MessageSender;
|
|
|
import com.lantone.security.enums.DataAuthDataTypeEnum;
|
|
|
import com.lantone.security.enums.DataAuthDetailTypeEnum;
|
|
|
import com.lantone.security.enums.DictionaryEnum;
|
|
@@ -57,6 +62,8 @@ import com.lantone.security.enums.HospitalTypeEnum;
|
|
|
import com.lantone.security.enums.RelationEnum;
|
|
|
import com.lantone.security.enums.ReturnTypeEnum;
|
|
|
import com.lantone.security.service.AuthService;
|
|
|
+import eu.bitwalker.useragentutils.UserAgent;
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
|
@@ -64,7 +71,9 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.DigestUtils;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
@@ -105,6 +114,8 @@ public class UserManagementFacade {
|
|
|
private DoctorFacade doctorfacade;
|
|
|
@Autowired
|
|
|
private DictionaryInfoFacade dictionaryInfoFacade;
|
|
|
+ @Autowired
|
|
|
+ private MessageSender messageSender;
|
|
|
|
|
|
public CommonResult login(LoginVO loginVO) {
|
|
|
Map<String, String> params = new HashMap<>();
|
|
@@ -114,6 +125,7 @@ public class UserManagementFacade {
|
|
|
params.put("username", loginVO.getUsername());
|
|
|
params.put("password", loginVO.getPassword());
|
|
|
CommonResult restResult = authService.getAccessToken(params);
|
|
|
+ sendLogRecordMessage(restResult);
|
|
|
return restResult;
|
|
|
}
|
|
|
|
|
@@ -288,6 +300,7 @@ public class UserManagementFacade {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 修改密码
|
|
|
*
|
|
@@ -301,11 +314,11 @@ public class UserManagementFacade {
|
|
|
String MD5ModifyPassword = BCrypt.hashpw(modifyPassword);
|
|
|
//对传入的密码进行格式验证
|
|
|
Long hospitalID = SysUserUtils.getCurrentHospitalId();
|
|
|
- Boolean regularBoolean = passwordRegular(modifyPassword,hospitalID+"");
|
|
|
- if(!regularBoolean){
|
|
|
+ Boolean regularBoolean = passwordRegular(modifyPassword, hospitalID + "");
|
|
|
+ if (!regularBoolean) {
|
|
|
Asserts.fail("请输入正确格式的新密码");
|
|
|
}
|
|
|
- String userId = SysUserUtils.getCurrentPrincipleId()+"";
|
|
|
+ String userId = SysUserUtils.getCurrentPrincipleId() + "";
|
|
|
User user = userFacade.getOne(new QueryWrapper<User>()
|
|
|
.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
.eq("status", StatusEnum.Enable.getKey())
|
|
@@ -329,24 +342,26 @@ public class UserManagementFacade {
|
|
|
|
|
|
/**
|
|
|
* 未加密密文正则表达式 至少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 = dictionaryInfoFacade.getDicMap(ReturnTypeEnum.INTERFACE.getKey(),
|
|
|
- Lists.newArrayList(DictionaryEnum.PASSWORD.getKey()+""));
|
|
|
- if(dictionaryWithKey!=null){
|
|
|
- Map<String, String> stringStringMap = dictionaryWithKey.get(DictionaryEnum.PASSWORD.getKey()+"");
|
|
|
- if(stringStringMap!=null) {
|
|
|
+ Lists.newArrayList(DictionaryEnum.PASSWORD.getKey() + ""));
|
|
|
+ if (dictionaryWithKey != null) {
|
|
|
+ Map<String, String> stringStringMap = dictionaryWithKey.get(DictionaryEnum.PASSWORD.getKey() + "");
|
|
|
+ if (stringStringMap != null) {
|
|
|
String regular = stringStringMap.get("check");
|
|
|
- if(StringUtil.isNotEmpty(regular)) {
|
|
|
+ if (StringUtil.isNotEmpty(regular)) {
|
|
|
check = password.matches(regular);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return check;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* @param roles
|
|
|
* @Description插入角色校验
|
|
@@ -354,7 +369,7 @@ public class UserManagementFacade {
|
|
|
*/
|
|
|
private void checkRoles(List<Long> roles) {
|
|
|
if (ListUtil.isNotEmpty(roles)) {
|
|
|
- if (roles.size() != roleFacade.getBaseMapper().getCount(roles,StatusEnum.Enable.getKey(), IsDeleteEnum.N.getKey())) {
|
|
|
+ if (roles.size() != roleFacade.getBaseMapper().getCount(roles, StatusEnum.Enable.getKey(), IsDeleteEnum.N.getKey())) {
|
|
|
Asserts.fail("插入用户角色列表有改动,请刷新页面重新操作");
|
|
|
}
|
|
|
}
|
|
@@ -749,7 +764,9 @@ public class UserManagementFacade {
|
|
|
* @Return java.util.List<com.lantone.common.dto.GetUserHospitalsDTO>
|
|
|
*/
|
|
|
private List<GetUserHospitalsDTO> transTreeData(Map<Long, List<GetUserHospitalsDTO>> softwareHospitalMap, List<GetUserHospitalsDTO> softwareHospitals) {
|
|
|
- if (softwareHospitalMap == null) return null;
|
|
|
+ if (softwareHospitalMap == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
List<GetUserHospitalsDTO> out = new ArrayList<>();
|
|
|
Set<Long> tempParents = new HashSet<>();
|
|
|
Set<Long> parents = softwareHospitalMap.keySet();
|
|
@@ -771,4 +788,34 @@ public class UserManagementFacade {
|
|
|
});
|
|
|
return out;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 用户获取token后发送登录信息
|
|
|
+ * @Param: [commonResult]
|
|
|
+ * @return: void
|
|
|
+ * @Author: cy
|
|
|
+ * @Date: 2021/9/5
|
|
|
+ */
|
|
|
+ public void sendLogRecordMessage(CommonResult commonResult) {
|
|
|
+ Object data = commonResult.getData();
|
|
|
+ Map<String, Object> map = JSONObject.parseObject(JSON.toJSONString(data));
|
|
|
+ if (map.containsKey("token") && null != map.get("token")) {
|
|
|
+ LoginLogDTO loginLog = new LoginLogDTO();
|
|
|
+ Date date = new Date();
|
|
|
+ loginLog.setLoginDate(date);
|
|
|
+ loginLog.setGmtCreate(date);
|
|
|
+ String token = map.get("token").toString();
|
|
|
+ UserDto userByToken = SysUserUtils.getUserByToken(token);
|
|
|
+ loginLog.setLoginId(userByToken.getId());
|
|
|
+ loginLog.setLoginName(userByToken.getUserName());
|
|
|
+ loginLog.setLoginIp(HttpUtils.getIpAddress());
|
|
|
+ UserAgent userAgent = UserAgent.parseUserAgentString(HttpUtils.getHttpServletRequest().getHeader("User-Agent"));
|
|
|
+ // 获取客户端浏览器
|
|
|
+ String browser = userAgent.getBrowser().getName();
|
|
|
+ loginLog.setLoginBrowser(browser);
|
|
|
+ messageSender.sendLogSuccessRecordMessage(loginLog);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ;
|
|
|
}
|