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+Jpa+thymeleaf 搭建环境:jdk1.8+idea/eclipse+maven3+mysql5.6 本系统是基于Thymeleaf+SpringBoot+SpringDataJPA实现的的中小医院信息管理系统。简单实现了挂号收费,门诊管理,划价收费,药房取药,体检管理,药房管理,系统维护等基础功能。就诊卡提供了手动和读卡两种方式录入,其中IC读卡器使用的是"德卡D3",SDK使用的是德卡官网提供的。用户注册,验证邮件的邮箱考虑到安全问题,暂不提供授权码,如 有需求可使用自己邮箱,开启POP3/SMTP服务后,配置到项目里。前端页面未做过多优 化,若出现尺寸不适配情况,可适当调整浏览器缩放比例。系统管理员初始账号:1208585122@qq.com 系统管理员初始密码:123
资源推荐
资源详情
资源评论
收起资源包目录
基于Thymeleaf+SpringBoot+SpringDataJPA实现的的中小医院信息管理系统 (4139个子文件)
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
共 4139 条
- 1
- 2
- 3
- 4
- 5
- 6
- 42
资源评论
- m0_749068962023-06-08感谢资源主的分享,这个资源对我来说很有用,内容描述详尽,值得借鉴。
办公模板库素材蛙
- 粉丝: 1548
- 资源: 2289
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功