package com.xgs.hisystem.service.impl;
import com.xgs.hisystem.config.HisConstants;
import com.xgs.hisystem.config.ServerConfig;
import com.xgs.hisystem.pojo.bo.BaseResponse;
import com.xgs.hisystem.pojo.bo.PageRspBO;
import com.xgs.hisystem.pojo.entity.*;
import com.xgs.hisystem.pojo.vo.*;
import com.xgs.hisystem.repository.*;
import com.xgs.hisystem.service.IEmailService;
import com.xgs.hisystem.service.IUserService;
import com.xgs.hisystem.task.AsyncTask;
import com.xgs.hisystem.util.DateUtil;
import com.xgs.hisystem.util.MD5Util;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;
import javax.persistence.criteria.Predicate;
import javax.transaction.Transactional;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
public class UserServiceImpl implements IUserService {
@Autowired
private IUserRepository iUserRepository;
@Autowired
private ILoginInforRepository iLoginInforRepository;
@Autowired
private SpringTemplateEngine templateEngine;
@Autowired
private IEmailService iEmailService;
@Autowired
private IRoleRespository iRoleRespository;
@Autowired
private IUserRoleRepository iUserRoleRepository;
@Autowired
private IAnnouncementRepository iAnnouncementRepository;
@Autowired
private AsyncTask asyncTask;
@Autowired
private ServerConfig serverConfig;
private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
/**
* 登录验证
*
* @param reqVO
* @return
*/
@Override
public BaseResponse<String> doLogin(UserLoginReqVO reqVO) {
String email = reqVO.getEmail();
String password = reqVO.getPassword();
UserEntity user = iUserRepository.findByEmail(email);
if (StringUtils.isEmpty(user)) {
return BaseResponse.error(HisConstants.USER.USER_NOT_EXIST);
}
//登录验证
UsernamePasswordToken token = new UsernamePasswordToken(email, password);
Subject subject = SecurityUtils.getSubject();
try {
subject.login(token);
} catch (AuthenticationException e) {
return BaseResponse.error(HisConstants.USER.PASSWORD_ERROR);
}
//验证邮箱激活状态
if (user.getEmailStatus().equals(0)) {
return BaseResponse.error(HisConstants.USER.EMAIL_STATUS_INACTIVE);
}
//验证角色审核状态
List<UserRoleEntity> userRoleList = iUserRoleRepository.findByUId(user.getId());
//审核通过角色个数
long passStatusCount = userRoleList.stream()
.filter(userRole -> userRole.getRoleStatus().equals(1)).count();
if (passStatusCount == 0) {
//未审核角色个数
long unAuditStatusCount = userRoleList.stream()
.filter(userRole -> userRole.getRoleStatus().equals(0)).count();
if (unAuditStatusCount >= 1) {
return BaseResponse.error(HisConstants.USER.ROLE_STATUS_NOTAUDIT);
}
//审核未通过
else {
return BaseResponse.error(HisConstants.USER.ROLE_STATUS_NOTPASS);
}
}
//保存用户登录信息
asyncTask.saveLoginInfor(reqVO.getIp(), reqVO.getBroswer(), email);
return BaseResponse.success(HisConstants.USER.SUCCESS);
}
/**
* 保存用户注册信息,向用户发送激活链接
*
* @param reqVO
* @return
*/
@Transactional
@Override
public BaseResponse<String> saveUserAndSendEmail(UserRegisterReqVO reqVO) {
String email = reqVO.getEmail();
String roleName = reqVO.getRoleName();
try {
//验证角色
RoleEntity role = iRoleRespository.findByDescription(roleName);
if (role == null) {
return BaseResponse.error("您选择的角色不存在,请重试!");
}
//检查该账户是否已存在
UserEntity checkUser = iUserRepository.findByEmail(email);
if (checkUser != null) {
return BaseResponse.error(HisConstants.USER.ACCOUNT_EXIST);
}
UserEntity user = new UserEntity();
user.setEmail(email);
user.setUsername(reqVO.getUsername());
user.setPlainPassword(reqVO.getPassword());
//生成盐和加盐密码
String salt = MD5Util.md5Encrypt32Lower(reqVO.getEmail());
// 使用SimpleHash类对原始密码进行加密
String password = new SimpleHash("MD5", reqVO.getPassword(), salt, 1024).toHex();
user.setPassword(password);
user.setSalt(salt);
//生成激活码
String validateCode = MD5Util.md5Encrypt32Upper(reqVO.getEmail());
user.setValidateCode(validateCode);
user.setEmailStatus(0);
iUserRepository.saveAndFlush(user);
//保存用户与角色信息
UserRoleEntity userRole = new UserRoleEntity();
userRole.setuId(user.getId());
userRole.setRoleId(role.getId());
String description = user.getEmail() + "#" + role.getRole();
userRole.setDescription(description);
userRole.setRoleStatus(0);
iUserRoleRepository.saveAndFlush(userRole);
//组装发送邮件参数
String title = "账户激活";
Context context = new Context();
//组装激活地址
String url = serverConfig.getUrl().concat("/activation").concat("?email=")
.concat(email).concat("&validateCode=").concat(validateCode);
context.setVariable("url", url);
String emailContent = templateEngine.process("email/email", context);
//发送邮件
iEmailService.sendMail(reqVO.getEmail(), title, emailContent);
return BaseResponse.success(HisConstants.USER.SUCCESS);
} catch (Exception e) {
e.printStackTrace();
return BaseResponse.error("保存用户信息或邮件发送异常,请联系管理员处理!");
}
}
/**
* 激活账户
*
* @param email
* @param validateCode
* @return
* @throws ParseException
*/
@Transactional
@Override
public BaseResponse<String> activation(String email, String validateCode) throws ParseException {
try {
UserEntity user = iUserRepository.findByEmail(email);
if (user == null) {
return BaseResponse.error("未查询到该邮箱,请核对信息!");
}
String nowDate = DateUtil.getCurrentDateToString();
String createDate = user.getCreateDatetime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d HH:mm:ss");
Date start = sdf.parse(createD
没有合适的资源?快使用搜索试试~ 我知道了~
基于SpringBoot的中小医院信息管理系统.zip
共2000个文件
svg:2982个
scss:254个
class:139个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 154 浏览量
2023-05-23
02:21:56
上传
评论 1
收藏 16.08MB ZIP 举报
温馨提示
基于SpringBoot的中小医院信息管理系统.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot的中小医院信息管理系统.zip (2000个子文件)
UserServiceImpl.class 25KB
AdminServiceImpl.class 19KB
OutpatientServiceImpl.class 18KB
RegisterServiceImpl.class 17KB
TollServiceImpl.class 16KB
DrugStoreServiceImpl.class 12KB
MedicalExaminationServiceImpl.class 11KB
UserEntity.class 8KB
DateUtil.class 6KB
TakingDrugServiceImpl.class 6KB
PageController.class 6KB
AdminController.class 6KB
UserController.class 5KB
PatientEntity.class 4KB
ShiroConfig.class 4KB
MyRealm.class 4KB
RegisterEntity.class 4KB
OutpatientController.class 4KB
DrugStoreController.class 4KB
RegisterController.class 4KB
GlobalDefaultExceptionHandler.class 4KB
DrugReqVO.class 4KB
DrugEntity.class 4KB
PatientInforRspVO.class 4KB
RegisterServiceImpl$2.class 4KB
DrugStoreServiceImpl$1.class 4KB
TollController.class 4KB
RegisterServiceImpl$1.class 3KB
AsyncTask.class 3KB
MedicalRecordRspVO.class 3KB
BaseResponse.class 3KB
MD5Util.class 3KB
DrugRspVO.class 3KB
Dcrf32_h.class 3KB
ChineseCharacterUtil.class 3KB
Card.class 3KB
AdminServiceImpl$1.class 3KB
GetExaminationTollInfoRspVO.class 3KB
TollMedicalRecordRspVO.class 3KB
MedicalRecordReqVO.class 3KB
Swagger2Config.class 3KB
OutpatientQueueEntity.class 3KB
MedicalRecordEntity.class 3KB
AdminServiceImpl$2.class 3KB
MedicalExaminationEntity.class 3KB
medicalExaminationInfoReqVO.class 3KB
IAdminService.class 3KB
TollTakeDrugInfoEntity.class 2KB
PatientInforReqVO.class 2KB
GetPatientInfoServiceImpl.class 2KB
IUserService.class 2KB
RegisterInforReqVO.class 2KB
UserInfoVO.class 2KB
PatientInforRspVO.class 2KB
IDcardEntity.class 2KB
RegisterRecordRspVO.class 2KB
LoginInforEntity.class 2KB
RoleEntity.class 2KB
MedicalExaminationController.class 2KB
EmailServiceImpl.class 2KB
ServerConfig.class 2KB
RegisterDoctorRspVO.class 2KB
AnnouncementVO.class 2KB
UserRegisterReqVO.class 2KB
PatientInforRspVO.class 2KB
IDcardRspVO.class 2KB
DepartmentEntity.class 2KB
IRegisterService.class 2KB
OtherPatientInforReqVO.class 2KB
TollRspVO.class 2KB
AddressDetailVO.class 2KB
TakingDrugController.class 2KB
IOutpatientService.class 2KB
Swagger2Config$1.class 2KB
AnnouncementEntity.class 2KB
UserRoleEntity.class 2KB
IDrugStoreService.class 2KB
AddRoleVO.class 1KB
AddDepartmentReqVO.class 1KB
medicalExaminationInfoRspVO.class 1KB
ChangePasswordReqVO.class 1KB
UserLoginReqVO.class 1KB
HisConstants$USER.class 1KB
ITollService.class 1KB
RoleVO.class 1KB
DrugSearchReqVO.class 1KB
ExecutePoolTask.class 1KB
ContentVO.class 1KB
RegisterRecordSearchReqVO.class 1KB
GetAllOutpatientQueueRspVO.class 1KB
BaseEntity.class 1KB
LoginInforRspVO.class 1KB
GetAddressRspVO.class 1KB
applyRspVO.class 1KB
PageRspBO.class 1KB
SaveTollInfoReqVO.class 1KB
OutpatientQueueLaterRspVO.class 1KB
IRoleRespository.class 1KB
GetDepartmentRspVO.class 1012B
EfficacyClassificationEntity.class 952B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
老了敲不动了
- 粉丝: 83
- 资源: 4288
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- fdsfdsfdsfdsfdsfdsfdsfds
- 目标检测-零售食品LOGO检测数据集-5000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- 目标检测-零售食品LOGO检测数据集-1000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- 计算机科学选修课:人工智能导论 第四节 PPT
- 计算机科学选修课:人工智能导论 第三节 PPT
- Delphi 12 控件之LMD.VCL.Full.Version.zip
- 常用阀门定位器的调试步骤及说明
- 计算机科学选修课:人工智能导论 第二节 PPT
- 计算机科学选修课:人工智能导论 第一章 PPT
- Delphi 12 控件Indy-Indy-10.6.3.3.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功