|
|
@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO; |
|
|
|
import javax.imageio.ImageIO; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
import java.awt.image.BufferedImage; |
|
|
@ -43,12 +44,12 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
public EmployeeAndUserVO info() { |
|
|
|
public EmployeeAndUserVO info() { |
|
|
|
String userId = this.getUserId(); |
|
|
|
String userId = this.getUserId(); |
|
|
|
EmployeeAndUserVO employeeAndUser = employeeDao.getEmployeeByUserId(Long.parseLong(userId)); |
|
|
|
EmployeeAndUserVO employeeAndUser = employeeDao.getEmployeeByUserId(Long.parseLong(userId)); |
|
|
|
if (employeeAndUser == null){ |
|
|
|
if (employeeAndUser == null) { |
|
|
|
return employeeAndUser; |
|
|
|
return employeeAndUser; |
|
|
|
} |
|
|
|
} |
|
|
|
if (employeeAndUser.getWechatId() == null || employeeAndUser.getWechatId().length() == 0){ |
|
|
|
if (employeeAndUser.getWechatId() == null || employeeAndUser.getWechatId().length() == 0) { |
|
|
|
employeeAndUser.setWechatId(PromptSuccess.QR_CODE_FAIL); |
|
|
|
employeeAndUser.setWechatId(PromptSuccess.QR_CODE_FAIL); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
employeeAndUser.setWechatId(PromptSuccess.QR_CODE_BINDING_SUCCESS); |
|
|
|
employeeAndUser.setWechatId(PromptSuccess.QR_CODE_BINDING_SUCCESS); |
|
|
|
} |
|
|
|
} |
|
|
|
return employeeAndUser; |
|
|
|
return employeeAndUser; |
|
|
@ -66,16 +67,16 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
employeeAndUserVO.setId(employeeId); |
|
|
|
employeeAndUserVO.setId(employeeId); |
|
|
|
employeeAndUserVO.setUserId(Long.parseLong(userId)); |
|
|
|
employeeAndUserVO.setUserId(Long.parseLong(userId)); |
|
|
|
Boolean result = true; |
|
|
|
Boolean result = true; |
|
|
|
BeanUtils.copyProperties(employeeAndUserVO,employee); |
|
|
|
BeanUtils.copyProperties(employeeAndUserVO, employee); |
|
|
|
String phoneAccount = this.getBaseMapper().getPhoneAccount(employee.getUserId()); |
|
|
|
String phoneAccount = this.getBaseMapper().getPhoneAccount(employee.getUserId()); |
|
|
|
if ((phoneAccount == null || phoneAccount.length() == 0) |
|
|
|
if ((phoneAccount == null || phoneAccount.length() == 0) |
|
|
|
&& employeeAndUserVO.getPrimaryPhone() != null |
|
|
|
&& employeeAndUserVO.getPrimaryPhone() != null |
|
|
|
&& employeeAndUserVO.getPrimaryPhone().length() != 0 |
|
|
|
&& employeeAndUserVO.getPrimaryPhone().length() != 0 |
|
|
|
&& employeeAndUserVO.getPrimaryCode() != null |
|
|
|
&& employeeAndUserVO.getPrimaryCode() != null |
|
|
|
&& employeeAndUserVO.getPrimaryCode().length() != 0){ |
|
|
|
&& employeeAndUserVO.getPrimaryCode().length() != 0) { |
|
|
|
// 没有绑定手机号,现在绑定
|
|
|
|
// 没有绑定手机号,现在绑定
|
|
|
|
String code = RedisUtil.get(employeeAndUserVO.getPrimaryPhone()); |
|
|
|
String code = RedisUtil.get(employeeAndUserVO.getPrimaryPhone()); |
|
|
|
if (code == null || code.length() == 0 || !Objects.equals(employeeAndUserVO.getPrimaryCode(),code)){ |
|
|
|
if (code == null || code.length() == 0 || !Objects.equals(employeeAndUserVO.getPrimaryCode(), code)) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PHONE_CODE_MISTAKE); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PHONE_CODE_MISTAKE); |
|
|
|
} |
|
|
|
} |
|
|
|
RedisUtil.del(employeeAndUserVO.getPrimaryPhone()); |
|
|
|
RedisUtil.del(employeeAndUserVO.getPrimaryPhone()); |
|
|
@ -89,20 +90,20 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
&& employeeAndUserVO.getNewPhone().length() != 0 |
|
|
|
&& employeeAndUserVO.getNewPhone().length() != 0 |
|
|
|
&& employeeAndUserVO.getNewCode() != null |
|
|
|
&& employeeAndUserVO.getNewCode() != null |
|
|
|
&& employeeAndUserVO.getNewCode().length() != 0 |
|
|
|
&& employeeAndUserVO.getNewCode().length() != 0 |
|
|
|
&& phoneAccount != null && phoneAccount.length() != 0){ |
|
|
|
&& phoneAccount != null && phoneAccount.length() != 0) { |
|
|
|
// 更换绑定的手机号
|
|
|
|
// 更换绑定的手机号
|
|
|
|
if (!Objects.equals(phoneAccount,employeeAndUserVO.getPrimaryPhone())){ |
|
|
|
if (!Objects.equals(phoneAccount, employeeAndUserVO.getPrimaryPhone())) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PRIMARY_PHONE_MISTAKE); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PRIMARY_PHONE_MISTAKE); |
|
|
|
} |
|
|
|
} |
|
|
|
String primaryCode = RedisUtil.get(employeeAndUserVO.getPrimaryPhone()); |
|
|
|
String primaryCode = RedisUtil.get(employeeAndUserVO.getPrimaryPhone()); |
|
|
|
if (primaryCode == null || primaryCode.length() == 0 |
|
|
|
if (primaryCode == null || primaryCode.length() == 0 |
|
|
|
|| !Objects.equals(primaryCode,employeeAndUserVO.getPrimaryCode())){ |
|
|
|
|| !Objects.equals(primaryCode, employeeAndUserVO.getPrimaryCode())) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PRIMARY_CODE_MISTAKE); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PRIMARY_CODE_MISTAKE); |
|
|
|
} |
|
|
|
} |
|
|
|
RedisUtil.del(employeeAndUserVO.getPrimaryPhone()); |
|
|
|
RedisUtil.del(employeeAndUserVO.getPrimaryPhone()); |
|
|
|
String newCode = RedisUtil.get(employeeAndUserVO.getNewPhone()); |
|
|
|
String newCode = RedisUtil.get(employeeAndUserVO.getNewPhone()); |
|
|
|
if (newCode == null || newCode.length() == 0 |
|
|
|
if (newCode == null || newCode.length() == 0 |
|
|
|
|| !Objects.equals(newCode,employeeAndUserVO.getNewCode())){ |
|
|
|
|| !Objects.equals(newCode, employeeAndUserVO.getNewCode())) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_NEW_CODE_MISTAKE); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_NEW_CODE_MISTAKE); |
|
|
|
} |
|
|
|
} |
|
|
|
RedisUtil.del(employeeAndUserVO.getNewPhone()); |
|
|
|
RedisUtil.del(employeeAndUserVO.getNewPhone()); |
|
|
@ -116,33 +117,33 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String uploadFile(MultipartFile file) { |
|
|
|
public String uploadFile(MultipartFile file) { |
|
|
|
if (file == null || file.isEmpty()){ |
|
|
|
if (file == null || file.isEmpty()) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_FILE_IS_NULL); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_FILE_IS_NULL); |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
// 通过获取图片文件的宽度和高度来校验是否为图片文件
|
|
|
|
// 通过获取图片文件的宽度和高度来校验是否为图片文件
|
|
|
|
BufferedImage image = ImageIO.read(file.getInputStream()); |
|
|
|
BufferedImage image = ImageIO.read(file.getInputStream()); |
|
|
|
if (image == null || image.getHeight() <= 0 || image.getWidth() <= 0){ |
|
|
|
if (image == null || image.getHeight() <= 0 || image.getWidth() <= 0) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_FILE_TYPE_MISTAKE); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_FILE_TYPE_MISTAKE); |
|
|
|
} |
|
|
|
} |
|
|
|
}catch (IOException e){ |
|
|
|
} catch (IOException e) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_FILE_UPLOAD_FAIL); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_FILE_UPLOAD_FAIL); |
|
|
|
} |
|
|
|
} |
|
|
|
String filename = file.getOriginalFilename(); |
|
|
|
String filename = file.getOriginalFilename(); |
|
|
|
if (filename == null){ |
|
|
|
if (filename == null) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_FILE_TYPE_MISTAKE); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_FILE_TYPE_MISTAKE); |
|
|
|
} |
|
|
|
} |
|
|
|
String substring = filename.substring(filename.lastIndexOf(".")); |
|
|
|
String substring = filename.substring(filename.lastIndexOf(".")); |
|
|
|
String filePrefix = UUID.randomUUID().toString(); |
|
|
|
String filePrefix = UUID.randomUUID().toString(); |
|
|
|
// 图片上传绝对路径
|
|
|
|
// 图片上传绝对路径
|
|
|
|
String filePath = PromptSuccess.UPLOAD_FILE_PATH+filePrefix+substring; |
|
|
|
String filePath = PromptSuccess.UPLOAD_FILE_PATH + filePrefix + substring; |
|
|
|
try { |
|
|
|
try { |
|
|
|
file.transferTo(new File(filePath)); |
|
|
|
file.transferTo(new File(filePath)); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_FILE_UPLOAD_FAIL); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_FILE_UPLOAD_FAIL); |
|
|
|
} |
|
|
|
} |
|
|
|
// 图片访问路径
|
|
|
|
// 图片访问路径
|
|
|
|
return PromptSuccess.IMAGE_URL_PATH+filePrefix+substring; |
|
|
|
return PromptSuccess.IMAGE_URL_PATH + filePrefix + substring; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -153,27 +154,27 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
public Boolean updatePassword(String primaryPassword, String newPassword, String affirmNewPassword) { |
|
|
|
public Boolean updatePassword(String primaryPassword, String newPassword, String affirmNewPassword) { |
|
|
|
if (primaryPassword == null || primaryPassword.length() == 0 |
|
|
|
if (primaryPassword == null || primaryPassword.length() == 0 |
|
|
|
|| newPassword == null || newPassword.length() == 0 |
|
|
|
|| newPassword == null || newPassword.length() == 0 |
|
|
|
|| affirmNewPassword == null || affirmNewPassword.length() == 0){ |
|
|
|
|| affirmNewPassword == null || affirmNewPassword.length() == 0) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PASSWORD_NOT_NULL); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PASSWORD_NOT_NULL); |
|
|
|
} |
|
|
|
} |
|
|
|
// 两次输入是否相同
|
|
|
|
// 两次输入是否相同
|
|
|
|
if (!Objects.equals(affirmNewPassword, newPassword)){ |
|
|
|
if (!Objects.equals(affirmNewPassword, newPassword)) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PASSWORD_NO_CONSISTENT); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PASSWORD_NO_CONSISTENT); |
|
|
|
} |
|
|
|
} |
|
|
|
// 旧密码是否正确
|
|
|
|
// 旧密码是否正确
|
|
|
|
String userId = this.getUserId(); |
|
|
|
String userId = this.getUserId(); |
|
|
|
if (!Objects.equals(Md5Util.md5(primaryPassword + Long.parseLong(userId)),this.getBaseMapper().getPasswordById(Long.parseLong(userId)))){ |
|
|
|
if (!Objects.equals(Md5Util.md5(primaryPassword + Long.parseLong(userId)), this.getBaseMapper().getPasswordById(Long.parseLong(userId)))) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PASSWORD_MISTAKE); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PASSWORD_MISTAKE); |
|
|
|
} |
|
|
|
} |
|
|
|
// 正则校验
|
|
|
|
// 正则校验
|
|
|
|
if (!newPassword.matches(PromptSuccess.MATCHES_STRING)){ |
|
|
|
if (!newPassword.matches(PromptSuccess.MATCHES_STRING)) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PASSWORD_MATCHES); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PASSWORD_MATCHES); |
|
|
|
} |
|
|
|
} |
|
|
|
// 是否与账号相同
|
|
|
|
// 是否与账号相同
|
|
|
|
if (Objects.equals(newPassword,this.getBaseMapper().getAccountById(Long.parseLong(userId)))){ |
|
|
|
if (Objects.equals(newPassword, this.getBaseMapper().getAccountById(Long.parseLong(userId)))) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PASSWORD_IS_NO_ACCOUNT); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PASSWORD_IS_NO_ACCOUNT); |
|
|
|
} |
|
|
|
} |
|
|
|
return this.getBaseMapper().updatePassword(Long.parseLong(userId),Md5Util.md5(newPassword + Long.parseLong(userId))); |
|
|
|
return this.getBaseMapper().updatePassword(Long.parseLong(userId), Md5Util.md5(newPassword + Long.parseLong(userId))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -181,14 +182,14 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Boolean getVerificationCode(String phone) { |
|
|
|
public Boolean getVerificationCode(String phone) { |
|
|
|
if (phone == null || phone.length() == 0){ |
|
|
|
if (phone == null || phone.length() == 0) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PHONE_NOT_NULL); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PHONE_NOT_NULL); |
|
|
|
} |
|
|
|
} |
|
|
|
String code = (int)((Math.random() * 9 + 1) * 100000)+ ""; |
|
|
|
String code = (int) ((Math.random() * 9 + 1) * 100000) + ""; |
|
|
|
// 发送短信
|
|
|
|
// 发送短信
|
|
|
|
Boolean result = SendSMS.sendCode(phone,"SMS_204155294",code); |
|
|
|
Boolean result = SendSMS.sendCode(phone, "SMS_204155294", code); |
|
|
|
if (result){ |
|
|
|
if (result) { |
|
|
|
RedisUtil.setEx(phone,code,PromptSuccess.OVERDUE_TIME); |
|
|
|
RedisUtil.setEx(phone, code, PromptSuccess.OVERDUE_TIME); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -200,11 +201,11 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
@Transactional |
|
|
|
@Transactional |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Boolean bindingPhoneAccount(String phone, String code) { |
|
|
|
public Boolean bindingPhoneAccount(String phone, String code) { |
|
|
|
if (phone == null || phone.length() == 0 || code == null || code.length() == 0){ |
|
|
|
if (phone == null || phone.length() == 0 || code == null || code.length() == 0) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PHONE_OR_CODE_NOT_NULL); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_PHONE_OR_CODE_NOT_NULL); |
|
|
|
} |
|
|
|
} |
|
|
|
if (RedisUtil.get(phone) == null || RedisUtil.get(phone).length() == 0 |
|
|
|
if (RedisUtil.get(phone) == null || RedisUtil.get(phone).length() == 0 |
|
|
|
|| !Objects.equals(code,RedisUtil.get(phone))){ |
|
|
|
|| !Objects.equals(code, RedisUtil.get(phone))) { |
|
|
|
ExceptionCast.cast(HrmsCode.USER_BINDING_FAIL); |
|
|
|
ExceptionCast.cast(HrmsCode.USER_BINDING_FAIL); |
|
|
|
} |
|
|
|
} |
|
|
|
RedisUtil.del(phone); |
|
|
|
RedisUtil.del(phone); |
|
|
@ -218,15 +219,15 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Boolean cancel() { |
|
|
|
public Boolean cancel() { |
|
|
|
String userId = this.getUserId(); |
|
|
|
String userId = this.getUserId(); |
|
|
|
return this.getBaseMapper().updateWeChat(Long.parseLong(userId),null); |
|
|
|
return this.getBaseMapper().updateWeChat(Long.parseLong(userId), null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取当前登录用户信息 |
|
|
|
* 获取当前登录用户信息 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private String getUserId(){ |
|
|
|
private String getUserId() { |
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
|
|
|
String token = request.getHeader("token"); |
|
|
|
String token = request.getHeader("token"); |
|
|
|
return RedisUtil.get("dq:token:"+token); |
|
|
|
return RedisUtil.get("dq:token:" + token); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |