|
|
|
@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
@ -43,12 +44,12 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
|
public EmployeeAndUserVO info() { |
|
|
|
|
String userId = this.getUserId(); |
|
|
|
|
EmployeeAndUserVO employeeAndUser = employeeDao.getEmployeeByUserId(Long.parseLong(userId)); |
|
|
|
|
if (employeeAndUser == null){ |
|
|
|
|
if (employeeAndUser == null) { |
|
|
|
|
return employeeAndUser; |
|
|
|
|
} |
|
|
|
|
if (employeeAndUser.getWechatId() == null || employeeAndUser.getWechatId().length() == 0){ |
|
|
|
|
if (employeeAndUser.getWechatId() == null || employeeAndUser.getWechatId().length() == 0) { |
|
|
|
|
employeeAndUser.setWechatId(PromptSuccess.QR_CODE_FAIL); |
|
|
|
|
}else { |
|
|
|
|
} else { |
|
|
|
|
employeeAndUser.setWechatId(PromptSuccess.QR_CODE_BINDING_SUCCESS); |
|
|
|
|
} |
|
|
|
|
return employeeAndUser; |
|
|
|
@ -66,16 +67,16 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
|
employeeAndUserVO.setId(employeeId); |
|
|
|
|
employeeAndUserVO.setUserId(Long.parseLong(userId)); |
|
|
|
|
Boolean result = true; |
|
|
|
|
BeanUtils.copyProperties(employeeAndUserVO,employee); |
|
|
|
|
BeanUtils.copyProperties(employeeAndUserVO, employee); |
|
|
|
|
String phoneAccount = this.getBaseMapper().getPhoneAccount(employee.getUserId()); |
|
|
|
|
if ((phoneAccount == null || phoneAccount.length() == 0) |
|
|
|
|
&& employeeAndUserVO.getPrimaryPhone() != null |
|
|
|
|
&& employeeAndUserVO.getPrimaryPhone().length() != 0 |
|
|
|
|
&& employeeAndUserVO.getPrimaryCode() != null |
|
|
|
|
&& employeeAndUserVO.getPrimaryCode().length() != 0){ |
|
|
|
|
&& employeeAndUserVO.getPrimaryCode().length() != 0) { |
|
|
|
|
// 没有绑定手机号,现在绑定
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
RedisUtil.del(employeeAndUserVO.getPrimaryPhone()); |
|
|
|
@ -89,20 +90,20 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
|
&& employeeAndUserVO.getNewPhone().length() != 0 |
|
|
|
|
&& employeeAndUserVO.getNewCode() != null |
|
|
|
|
&& 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); |
|
|
|
|
} |
|
|
|
|
String primaryCode = RedisUtil.get(employeeAndUserVO.getPrimaryPhone()); |
|
|
|
|
if (primaryCode == null || primaryCode.length() == 0 |
|
|
|
|
|| !Objects.equals(primaryCode,employeeAndUserVO.getPrimaryCode())){ |
|
|
|
|
|| !Objects.equals(primaryCode, employeeAndUserVO.getPrimaryCode())) { |
|
|
|
|
ExceptionCast.cast(HrmsCode.USER_PRIMARY_CODE_MISTAKE); |
|
|
|
|
} |
|
|
|
|
RedisUtil.del(employeeAndUserVO.getPrimaryPhone()); |
|
|
|
|
String newCode = RedisUtil.get(employeeAndUserVO.getNewPhone()); |
|
|
|
|
if (newCode == null || newCode.length() == 0 |
|
|
|
|
|| !Objects.equals(newCode,employeeAndUserVO.getNewCode())){ |
|
|
|
|
|| !Objects.equals(newCode, employeeAndUserVO.getNewCode())) { |
|
|
|
|
ExceptionCast.cast(HrmsCode.USER_NEW_CODE_MISTAKE); |
|
|
|
|
} |
|
|
|
|
RedisUtil.del(employeeAndUserVO.getNewPhone()); |
|
|
|
@ -116,33 +117,33 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public String uploadFile(MultipartFile file) { |
|
|
|
|
if (file == null || file.isEmpty()){ |
|
|
|
|
if (file == null || file.isEmpty()) { |
|
|
|
|
ExceptionCast.cast(HrmsCode.USER_FILE_IS_NULL); |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
// 通过获取图片文件的宽度和高度来校验是否为图片文件
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
}catch (IOException e){ |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
ExceptionCast.cast(HrmsCode.USER_FILE_UPLOAD_FAIL); |
|
|
|
|
} |
|
|
|
|
String filename = file.getOriginalFilename(); |
|
|
|
|
if (filename == null){ |
|
|
|
|
if (filename == null) { |
|
|
|
|
ExceptionCast.cast(HrmsCode.USER_FILE_TYPE_MISTAKE); |
|
|
|
|
} |
|
|
|
|
String substring = filename.substring(filename.lastIndexOf(".")); |
|
|
|
|
String filePrefix = UUID.randomUUID().toString(); |
|
|
|
|
// 图片上传绝对路径
|
|
|
|
|
String filePath = PromptSuccess.UPLOAD_FILE_PATH+filePrefix+substring; |
|
|
|
|
String filePath = PromptSuccess.UPLOAD_FILE_PATH + filePrefix + substring; |
|
|
|
|
try { |
|
|
|
|
file.transferTo(new File(filePath)); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
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) { |
|
|
|
|
if (primaryPassword == null || primaryPassword.length() == 0 |
|
|
|
|
|| newPassword == null || newPassword.length() == 0 |
|
|
|
|
|| affirmNewPassword == null || affirmNewPassword.length() == 0){ |
|
|
|
|
|| affirmNewPassword == null || affirmNewPassword.length() == 0) { |
|
|
|
|
ExceptionCast.cast(HrmsCode.USER_PASSWORD_NOT_NULL); |
|
|
|
|
} |
|
|
|
|
// 两次输入是否相同
|
|
|
|
|
if (!Objects.equals(affirmNewPassword, newPassword)){ |
|
|
|
|
if (!Objects.equals(affirmNewPassword, newPassword)) { |
|
|
|
|
ExceptionCast.cast(HrmsCode.USER_PASSWORD_NO_CONSISTENT); |
|
|
|
|
} |
|
|
|
|
// 旧密码是否正确
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
// 正则校验
|
|
|
|
|
if (!newPassword.matches(PromptSuccess.MATCHES_STRING)){ |
|
|
|
|
if (!newPassword.matches(PromptSuccess.MATCHES_STRING)) { |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
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 |
|
|
|
|
public Boolean getVerificationCode(String phone) { |
|
|
|
|
if (phone == null || phone.length() == 0){ |
|
|
|
|
if (phone == null || phone.length() == 0) { |
|
|
|
|
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); |
|
|
|
|
if (result){ |
|
|
|
|
RedisUtil.setEx(phone,code,PromptSuccess.OVERDUE_TIME); |
|
|
|
|
Boolean result = SendSMS.sendCode(phone, "SMS_204155294", code); |
|
|
|
|
if (result) { |
|
|
|
|
RedisUtil.setEx(phone, code, PromptSuccess.OVERDUE_TIME); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
@ -200,11 +201,11 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
|
@Transactional |
|
|
|
|
@Override |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
RedisUtil.del(phone); |
|
|
|
@ -218,15 +219,15 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements |
|
|
|
|
@Override |
|
|
|
|
public Boolean cancel() { |
|
|
|
|
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(); |
|
|
|
|
String token = request.getHeader("token"); |
|
|
|
|
return RedisUtil.get("dq:token:"+token); |
|
|
|
|
return RedisUtil.get("dq:token:" + token); |
|
|
|
|
} |
|
|
|
|
} |