Commit c60fbf54 by guojuxing

个人资料功能

parent 418b6625
......@@ -143,4 +143,17 @@ public interface UserApiService {
* @return com.gic.api.base.commons.ServiceResponse<java.lang.String>
 返回日志操作对象

 */
ServiceResponse<String> removeAccountGroup(Integer accountGroupId, Integer userId, Integer type);
/**
* 编辑修改个人资料:手机号码/密码
* @Title: editPhoneOrPassword

* @Description:

 * @author guojuxing
* @param userId
* @param nationCode
* @param phone
* @param password

* @return com.gic.api.base.commons.ServiceResponse<java.lang.String>


 */
ServiceResponse<String> editPhoneOrPassword(Integer userId, String nationCode, String phone, String password);
}
......@@ -404,6 +404,21 @@ public class UserApiServiceImpl implements UserApiService {
return ServiceResponse.success(tabUser.getUserName());
}
@Override
public ServiceResponse<String> editPhoneOrPassword(Integer userId, String nationCode, String phone, String password) {
TabSysUser tabUser = userService.getUserById(userId);
if (tabUser == null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "用户ID输入有误,无此数据");
}
UserDTO userDTO = new UserDTO();
userDTO.setUserId(userId);
userDTO.setPhoneNumber(phone);
userDTO.setPhoneAreaCode(nationCode);
userDTO.setPassword(password);
userService.editUser(userDTO);
return ServiceResponse.success(tabUser.getUserName());
}
/**
* 保存关联数据,角色关联、资源关联
* @Title: saveRole

......
......@@ -5,7 +5,9 @@ import com.gic.auth.dto.AuthCodeDTO;
import com.gic.auth.service.AuthCodeApiService;
import com.gic.auth.web.vo.LoginUserVO;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.Md5Util;
import com.gic.enterprise.utils.CreateRandomUtils;
import com.gic.enterprise.utils.UserDetail;
import com.gic.marketing.process.api.service.sms.SmsSendApiService;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.LogManager;
......@@ -43,7 +45,7 @@ public class UserController {
private AuthCodeApiService authCodeApiService;
@RequestMapping("/save-or-update-user")
public RestResponse editUser(@Validated({UserDTO.UserQoValid.class}) UserDTO userDTO) {
public RestResponse editUser(@Validated({ UserDTO.UserQoValid.class }) UserDTO userDTO) {
if (UserDetailUtils.getUserDetail().getUserInfo().getSuperAdmin().intValue() == 0) {
return RestResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "子管理员不能编辑");
}
......@@ -65,7 +67,8 @@ public class UserController {
if (StringUtils.isBlank(userDTO.getPhoneAreaCode())) {
userDTO.setPhoneAreaCode("86");
}
smsArr = new String[]{UserDetailUtils.getUserDetail().getEnterpriseInfo().getEnterpriseName(), userDTO.getPhoneNumber(), password};
smsArr = new String[] { UserDetailUtils.getUserDetail().getEnterpriseInfo().getEnterpriseName(),
userDTO.getPhoneNumber(), password };
}
}
ServiceResponse userResult;
......@@ -79,7 +82,8 @@ public class UserController {
if (userResult.isSuccess()) {
if (isNeedSendSms) {
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms("GICpassword001",
UserDetailUtils.getUserDetail().getEnterpriseInfo().getEnterpriseId(), userDTO.getPhoneAreaCode(), userDTO.getPhoneNumber(), smsArr);
UserDetailUtils.getUserDetail().getEnterpriseInfo().getEnterpriseId(),
userDTO.getPhoneAreaCode(), userDTO.getPhoneNumber(), smsArr);
if (!smsSendResult.isSuccess()) {
logger.warn(smsSendResult.getMessage());
}
......@@ -137,18 +141,23 @@ public class UserController {
return RestResponse.success(vo);
}
@RequestMapping("send-auth-code")
@RequestMapping("send-auth-code-to-modify-phone")
public RestResponse sendAuthCode(String phone, String nationCode) {
if (StringUtils.isBlank(nationCode)) {
nationCode = "86";
}
AuthCodeDTO authCodeDTO = new AuthCodeDTO();
authCodeDTO.setEnterpriseId(UserDetailUtils.getUserDetail().getEnterpriseId());
//生成4位数字验证码
authCodeDTO.setAuthCode(CreateRandomUtils.getStringRandom(4));
String authCode = CreateRandomUtils.getStringRandom(4);
authCodeDTO.setAuthCode(authCode);
ServiceResponse<Integer> result = authCodeApiService.saveAuth(authCodeDTO);
if (result.isSuccess()) {
Integer authCodeId = result.getResult();
//发送手机验证码
String[] smsArr = new String[]{};
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms("GICpassword001",
String[] smsArr = new String[] { authCode,
UserDetailUtils.getUserDetail().getEnterpriseInfo().getEnterpriseName() };
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms("GICphone",
UserDetailUtils.getUserDetail().getEnterpriseInfo().getEnterpriseId(), nationCode, phone, smsArr);
if (!smsSendResult.isSuccess()) {
return EnterpriseRestResponse.failure(smsSendResult);
......@@ -159,6 +168,80 @@ public class UserController {
return EnterpriseRestResponse.failure(result);
}
@RequestMapping("modify-phone")
public RestResponse modifyPhone(String phone, String nationCode, String authCode, Integer authCodeId) {
ServiceResponse authCodeResult = authCodeApiService.validateAuthCode(authCodeId, authCode);
if (authCodeResult.isSuccess()) {
UserDetail userDetail = UserDetailUtils.getUserDetail();
// password 自身作为盐值
String password = userDetail.getUserInfo().getPassword();
ServiceResponse<UserDTO> login = this.userApiService.login(userDetail.getUserInfo().getPhoneNumber(),
userDetail.getEnterpriseId(), password);
ServiceResponse<String> result = userApiService.editPhoneOrPassword(login.getResult().getUserId(),
nationCode, phone, null);
if (result.isSuccess()) {
//过期验证码
authCodeApiService.expireAuthCode(authCodeId);
}
return OperationResultUtils.operationResult(result, "修改手机号",
OperationResultUtils.getOperationObject(result));
}
return EnterpriseRestResponse.failure(authCodeResult);
}
@RequestMapping("send-auth-code-to-modify-password")
public RestResponse sendAuthCode() {
AuthCodeDTO authCodeDTO = new AuthCodeDTO();
authCodeDTO.setEnterpriseId(UserDetailUtils.getUserDetail().getEnterpriseId());
//生成4位数字验证码
String authCode = CreateRandomUtils.getStringRandom(4);
authCodeDTO.setAuthCode(authCode);
ServiceResponse<Integer> result = authCodeApiService.saveAuth(authCodeDTO);
if (result.isSuccess()) {
Integer authCodeId = result.getResult();
//发送手机验证码
String[] smsArr = new String[] { authCode,
UserDetailUtils.getUserDetail().getEnterpriseInfo().getEnterpriseName() };
ServiceResponse<Void> smsSendResult = smsSendApiService.sendPlatformSms("GICpassword",
UserDetailUtils.getUserDetail().getEnterpriseInfo().getEnterpriseId(),
UserDetailUtils.getUserDetail().getUserInfo().getPhoneAreaCode(),
UserDetailUtils.getUserDetail().getUserInfo().getPhoneNumber(), smsArr);
if (!smsSendResult.isSuccess()) {
return EnterpriseRestResponse.failure(smsSendResult);
} else {
return RestResponse.success(authCodeId);
}
}
return EnterpriseRestResponse.failure(result);
}
@RequestMapping("modify-password")
public RestResponse modifyPassword(String oldPassword, String newPhone, String authCode, Integer authCodeId) {
ServiceResponse authCodeResult = authCodeApiService.validateAuthCode(authCodeId, authCode);
if (authCodeResult.isSuccess()) {
UserDetail userDetail = UserDetailUtils.getUserDetail();
Md5Util md5 = new Md5Util();
// password 自身作为盐值
if (oldPassword.length() != 32) {
oldPassword = md5.encrypt(oldPassword + oldPassword);
}
ServiceResponse<UserDTO> login = this.userApiService.login(userDetail.getUserInfo().getPhoneNumber(),
userDetail.getEnterpriseId(), oldPassword);
if (!login.isSuccess()) {
return EnterpriseRestResponse.failure(login);
}
ServiceResponse<String> result = userApiService.editPhoneOrPassword(login.getResult().getUserId(),
null, null, md5.encrypt(newPhone + newPhone));
if (result.isSuccess()) {
//过期验证码
authCodeApiService.expireAuthCode(authCodeId);
}
return OperationResultUtils.operationResult(result, "修改密码",
OperationResultUtils.getOperationObject(result));
}
return EnterpriseRestResponse.failure(authCodeResult);
}
@RequestMapping("/list-user-nopage")
public RestResponse listUserNoPage(UserListQO params) {
params.setEnterpriseId(UserDetailUtils.getUserDetail().getEnterpriseId());
......@@ -179,8 +262,7 @@ public class UserController {
@RequestMapping("/remove-user-account-group")
public RestResponse removeUserAccountGroup(Integer type, Integer accountGroupId, Integer userId) {
ServiceResponse<String> result = userApiService.removeAccountGroup(accountGroupId, userId, type);
return OperationResultUtils.operationResult(result, "移除账号分组",
OperationResultUtils.getOperationObject(result));
return OperationResultUtils.operationResult(result, "移除账号分组", OperationResultUtils.getOperationObject(result));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment