|
@@ -25,6 +25,7 @@ import com.gree.mall.contest.plus.entity.*;
|
|
import com.gree.mall.contest.plus.service.*;
|
|
import com.gree.mall.contest.plus.service.*;
|
|
import com.gree.mall.contest.utils.CommonUtils;
|
|
import com.gree.mall.contest.utils.CommonUtils;
|
|
import com.gree.mall.contest.utils.JwtUtils;
|
|
import com.gree.mall.contest.utils.JwtUtils;
|
|
|
|
+import com.gree.mall.contest.utils.MD5Utils;
|
|
import com.gree.mall.contest.utils.RedisUtil;
|
|
import com.gree.mall.contest.utils.RedisUtil;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -96,17 +97,17 @@ public class AdminUserLogic {
|
|
}
|
|
}
|
|
//如果是admin操作非admin账号登陆不需要判断密码是否正确
|
|
//如果是admin操作非admin账号登陆不需要判断密码是否正确
|
|
AdminUserCom adminUser1 = commonLogic.getAdminUser();
|
|
AdminUserCom adminUser1 = commonLogic.getAdminUser();
|
|
- if(adminUser1 == null || !(adminUser1.getUserName().equals("admin")) && !StringUtils.equals(userName,"admin")) {
|
|
|
|
|
|
+ if (adminUser1 == null || !(adminUser1.getUserName().equals("admin")) && !StringUtils.equals(userName, "admin")) {
|
|
|
|
|
|
String value = (String) redisUtil.get(Constant.RedisPrefix.TOKEN_VERIFICATION + code);
|
|
String value = (String) redisUtil.get(Constant.RedisPrefix.TOKEN_VERIFICATION + code);
|
|
- if(StringUtils.isBlank(value)){
|
|
|
|
|
|
+ if (StringUtils.isBlank(value)) {
|
|
throw new RemoteServiceException("验证码过期,请刷新验证码重试");
|
|
throw new RemoteServiceException("验证码过期,请刷新验证码重试");
|
|
}
|
|
}
|
|
if (!value.equals(codeValue)) {
|
|
if (!value.equals(codeValue)) {
|
|
throw new RemoteServiceException("验证码错误");
|
|
throw new RemoteServiceException("验证码错误");
|
|
}
|
|
}
|
|
|
|
|
|
- if(adminUser.getLoginErrNum() >= 3){
|
|
|
|
|
|
+ if (adminUser.getLoginErrNum() >= 3) {
|
|
throw new RemoteServiceException("登陆失败,您已连续输入错误3次密码,请联系管理人员重置密码");
|
|
throw new RemoteServiceException("登陆失败,您已连续输入错误3次密码,请联系管理人员重置密码");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -186,7 +187,7 @@ public class AdminUserLogic {
|
|
if (!StringUtils.isEmpty(adminUser1.getServiceProviderId())
|
|
if (!StringUtils.isEmpty(adminUser1.getServiceProviderId())
|
|
&& adminUser1.getServiceProviderId().equals(adminUser.getServiceProviderId()) &&
|
|
&& adminUser1.getServiceProviderId().equals(adminUser.getServiceProviderId()) &&
|
|
(adminUser1.getType().equals(RoleTypeEnum.B.getCode()))
|
|
(adminUser1.getType().equals(RoleTypeEnum.B.getCode()))
|
|
- ){
|
|
|
|
|
|
+ ) {
|
|
adminUser.setPassword(SecureUtil.md5(password));
|
|
adminUser.setPassword(SecureUtil.md5(password));
|
|
adminUser.setLoginErrNum(0);
|
|
adminUser.setLoginErrNum(0);
|
|
adminUser.updateById();
|
|
adminUser.updateById();
|
|
@@ -199,7 +200,7 @@ public class AdminUserLogic {
|
|
adminUser.setLoginErrNum(0);
|
|
adminUser.setLoginErrNum(0);
|
|
adminUser.updateById();
|
|
adminUser.updateById();
|
|
|
|
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
throw new RemoteServiceException("账号不允许重置别人密码");
|
|
throw new RemoteServiceException("账号不允许重置别人密码");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -220,7 +221,7 @@ public class AdminUserLogic {
|
|
}
|
|
}
|
|
//当前用户选择的部门
|
|
//当前用户选择的部门
|
|
MerchantWebsit merchantWebsit = merchantWebsitService.getById(adminUser.getAdminWebsitId());
|
|
MerchantWebsit merchantWebsit = merchantWebsitService.getById(adminUser.getAdminWebsitId());
|
|
- if(merchantWebsit == null){
|
|
|
|
|
|
+ if (merchantWebsit == null) {
|
|
throw new RemoteServiceException("请选择部门");
|
|
throw new RemoteServiceException("请选择部门");
|
|
}
|
|
}
|
|
//需要用户roleId
|
|
//需要用户roleId
|
|
@@ -234,7 +235,7 @@ public class AdminUserLogic {
|
|
if (adminUser.getRoleName().equals("推单员"))
|
|
if (adminUser.getRoleName().equals("推单员"))
|
|
throw new RemoteServiceException("推单员需要在推单员列表配置账号");
|
|
throw new RemoteServiceException("推单员需要在推单员列表配置账号");
|
|
|
|
|
|
- if(curAdminUser.getType().equals(RoleTypeEnum.B.getCode())) {
|
|
|
|
|
|
+ if (curAdminUser.getType().equals(RoleTypeEnum.B.getCode())) {
|
|
adminUser.setType(RoleTypeEnum.D.getCode());
|
|
adminUser.setType(RoleTypeEnum.D.getCode());
|
|
adminUser.setServiceProviderId(curAdminUser.getServiceProviderId());
|
|
adminUser.setServiceProviderId(curAdminUser.getServiceProviderId());
|
|
}
|
|
}
|
|
@@ -259,10 +260,10 @@ public class AdminUserLogic {
|
|
}
|
|
}
|
|
//当前用户选择的部门
|
|
//当前用户选择的部门
|
|
MerchantWebsit merchantWebsit = merchantWebsitService.getById(newUser.getAdminWebsitId());
|
|
MerchantWebsit merchantWebsit = merchantWebsitService.getById(newUser.getAdminWebsitId());
|
|
- if(merchantWebsit == null){
|
|
|
|
|
|
+ if (merchantWebsit == null) {
|
|
throw new RemoteServiceException("请选择部门");
|
|
throw new RemoteServiceException("请选择部门");
|
|
}
|
|
}
|
|
- this.setType(admin,oldUser,newUser);
|
|
|
|
|
|
+ this.setType(admin, oldUser, newUser);
|
|
|
|
|
|
newUser.setRoleName(addUserRole.getName());
|
|
newUser.setRoleName(addUserRole.getName());
|
|
newUser.setUserName(null);
|
|
newUser.setUserName(null);
|
|
@@ -273,26 +274,27 @@ public class AdminUserLogic {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 用户类型处理
|
|
* 用户类型处理
|
|
|
|
+ *
|
|
* @param curAdmin
|
|
* @param curAdmin
|
|
* @param oldAdmin
|
|
* @param oldAdmin
|
|
* @param newAdmin
|
|
* @param newAdmin
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public AdminUser setType(AdminUserCom curAdmin,AdminUser oldAdmin,AdminUser newAdmin){
|
|
|
|
- if(StringUtils.isBlank(newAdmin.getType())){
|
|
|
|
|
|
+ public AdminUser setType(AdminUserCom curAdmin, AdminUser oldAdmin, AdminUser newAdmin) {
|
|
|
|
+ if (StringUtils.isBlank(newAdmin.getType())) {
|
|
return newAdmin;
|
|
return newAdmin;
|
|
}
|
|
}
|
|
//服务商不可变更服务商信息
|
|
//服务商不可变更服务商信息
|
|
- if(curAdmin.getType().equals(oldAdmin.getType()) && !curAdmin.getUserName().equals("admin")){
|
|
|
|
|
|
+ if (curAdmin.getType().equals(oldAdmin.getType()) && !curAdmin.getUserName().equals("admin")) {
|
|
throw new RemoteServiceException("您暂无权限变更");
|
|
throw new RemoteServiceException("您暂无权限变更");
|
|
}
|
|
}
|
|
//如果是平台添加帐号则为业务员
|
|
//如果是平台添加帐号则为业务员
|
|
//如果是商家添加账号则为子账号
|
|
//如果是商家添加账号则为子账号
|
|
- if(oldAdmin.getType().equals(RoleTypeEnum.A.getCode())){
|
|
|
|
|
|
+ if (oldAdmin.getType().equals(RoleTypeEnum.A.getCode())) {
|
|
newAdmin.setType(RoleTypeEnum.A.getCode());
|
|
newAdmin.setType(RoleTypeEnum.A.getCode());
|
|
- }else if(oldAdmin.getType().equals(RoleTypeEnum.B.getCode())){
|
|
|
|
|
|
+ } else if (oldAdmin.getType().equals(RoleTypeEnum.B.getCode())) {
|
|
newAdmin.setType(RoleTypeEnum.D.getCode());
|
|
newAdmin.setType(RoleTypeEnum.D.getCode());
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
newAdmin.setType(oldAdmin.getType());
|
|
newAdmin.setType(oldAdmin.getType());
|
|
}
|
|
}
|
|
return newAdmin;
|
|
return newAdmin;
|
|
@@ -303,12 +305,12 @@ public class AdminUserLogic {
|
|
*
|
|
*
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public IPage<AdminUser> list(String adminWebsitId,String roleId, Boolean status, String userName, Integer pageNum, Integer pageSize) {
|
|
|
|
|
|
+ public IPage<AdminUser> list(String adminWebsitId, String roleId, Boolean status, String userName, Integer pageNum, Integer pageSize) {
|
|
AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
|
|
|
List<String> adminWebsitIds = adminUser.getAdminWebsitIds();
|
|
List<String> adminWebsitIds = adminUser.getAdminWebsitIds();
|
|
|
|
|
|
- if(StringUtils.isNotBlank(adminWebsitId)) {
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(adminWebsitId)) {
|
|
List<MerchantWebsit> list = new ArrayList<>();
|
|
List<MerchantWebsit> list = new ArrayList<>();
|
|
list.addAll(commonLogic.queryAllChild(list, adminWebsitId));
|
|
list.addAll(commonLogic.queryAllChild(list, adminWebsitId));
|
|
adminWebsitIds = list.stream().map(MerchantWebsit::getWebsitId).collect(Collectors.toList());
|
|
adminWebsitIds = list.stream().map(MerchantWebsit::getWebsitId).collect(Collectors.toList());
|
|
@@ -316,11 +318,11 @@ public class AdminUserLogic {
|
|
adminWebsitIds.add(adminWebsitId);
|
|
adminWebsitIds.add(adminWebsitId);
|
|
}
|
|
}
|
|
IPage<AdminUser> page = adminUserService.lambdaQuery()
|
|
IPage<AdminUser> page = adminUserService.lambdaQuery()
|
|
- .in(CollectionUtils.isNotEmpty(adminWebsitIds),AdminUser::getAdminWebsitId,adminWebsitIds)
|
|
|
|
|
|
+ .in(CollectionUtils.isNotEmpty(adminWebsitIds), AdminUser::getAdminWebsitId, adminWebsitIds)
|
|
.eq(StringUtils.isNotBlank(roleId), AdminUser::getRoleId, roleId)
|
|
.eq(StringUtils.isNotBlank(roleId), AdminUser::getRoleId, roleId)
|
|
.eq(status != null, AdminUser::getStatus, status)
|
|
.eq(status != null, AdminUser::getStatus, status)
|
|
- .and(StringUtils.isNotBlank(userName),item -> item.like(AdminUser::getUserName, userName)
|
|
|
|
- .or().like(AdminUser::getNickName,userName)
|
|
|
|
|
|
+ .and(StringUtils.isNotBlank(userName), item -> item.like(AdminUser::getUserName, userName)
|
|
|
|
+ .or().like(AdminUser::getNickName, userName)
|
|
)
|
|
)
|
|
|
|
|
|
.orderByDesc(AdminUser::getCreateTime)
|
|
.orderByDesc(AdminUser::getCreateTime)
|
|
@@ -413,7 +415,7 @@ public class AdminUserLogic {
|
|
return list.stream().map(AdminModule::getModuleId).collect(Collectors.toList());
|
|
return list.stream().map(AdminModule::getModuleId).collect(Collectors.toList());
|
|
}
|
|
}
|
|
List<AdminUserModuleRela> list = adminUserModuleRelaService.lambdaQuery()
|
|
List<AdminUserModuleRela> list = adminUserModuleRelaService.lambdaQuery()
|
|
- .eq(AdminUserModuleRela::getFlag,1)
|
|
|
|
|
|
+ .eq(AdminUserModuleRela::getFlag, 1)
|
|
.eq(AdminUserModuleRela::getAdminRoleId, adminRoleId).list();
|
|
.eq(AdminUserModuleRela::getAdminRoleId, adminRoleId).list();
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
return new ArrayList<>();
|
|
return new ArrayList<>();
|
|
@@ -493,16 +495,17 @@ public class AdminUserLogic {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 找回密码-获取验证码
|
|
* 找回密码-获取验证码
|
|
|
|
+ *
|
|
* @param userName
|
|
* @param userName
|
|
* @param mobile
|
|
* @param mobile
|
|
* @param code
|
|
* @param code
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public AdminUserBean resetPasswordGetCode(String userName,String mobile, String code) {
|
|
|
|
|
|
+ public AdminUserBean resetPasswordGetCode(String userName, String mobile, String code) {
|
|
smsLogic.checkSmsCode(mobile, code, "RESET");
|
|
smsLogic.checkSmsCode(mobile, code, "RESET");
|
|
|
|
|
|
final AdminUser adminUser = adminUserService.lambdaQuery()
|
|
final AdminUser adminUser = adminUserService.lambdaQuery()
|
|
- .eq(AdminUser::getUserName,userName)
|
|
|
|
|
|
+ .eq(AdminUser::getUserName, userName)
|
|
.eq(AdminUser::getLinkPhone, mobile)
|
|
.eq(AdminUser::getLinkPhone, mobile)
|
|
.one();
|
|
.one();
|
|
|
|
|
|
@@ -515,12 +518,37 @@ public class AdminUserLogic {
|
|
bean.setUserName(adminUser.getUserName());
|
|
bean.setUserName(adminUser.getUserName());
|
|
bean.setToken(IdUtil.simpleUUID());
|
|
bean.setToken(IdUtil.simpleUUID());
|
|
|
|
|
|
- redisUtil.set(adminUser.getAdminUserId() + ":" + bean.getToken(), bean.getToken(), 5*60);
|
|
|
|
|
|
+ redisUtil.set(adminUser.getAdminUserId() + ":" + bean.getToken(), bean.getToken(), 5 * 60);
|
|
return bean;
|
|
return bean;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 找回密码-获取验证码
|
|
|
|
+ *
|
|
|
|
+ * @param mobile
|
|
|
|
+ * @param code
|
|
|
|
+ * @param password
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public void miniResetPasswordGetCode(String mobile, String code, String password) {
|
|
|
|
+ if (StringUtils.isBlank(password)) {
|
|
|
|
+ throw new RemoteServiceException("新密码不能为空");
|
|
|
|
+ }
|
|
|
|
+ smsLogic.checkSmsCode(mobile, code, "RESET");
|
|
|
|
+
|
|
|
|
+ final boolean update = adminUserService.lambdaUpdate()
|
|
|
|
+ .set(AdminUser::getPassword, MD5Utils.md5(password))
|
|
|
|
+ .eq(AdminUser::getLinkPhone, mobile)
|
|
|
|
+ .update();
|
|
|
|
+
|
|
|
|
+ if (!update) {
|
|
|
|
+ throw new RemoteServiceException("账号不存在");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 找回密码-更新密码
|
|
* 找回密码-更新密码
|
|
|
|
+ *
|
|
* @param adminUserId
|
|
* @param adminUserId
|
|
* @param token
|
|
* @param token
|
|
* @param newPassword
|
|
* @param newPassword
|
|
@@ -532,8 +560,8 @@ public class AdminUserLogic {
|
|
throw new RemoteServiceException("超时操作,请重新找回");
|
|
throw new RemoteServiceException("超时操作,请重新找回");
|
|
}
|
|
}
|
|
|
|
|
|
- String value = (String)redisUtil.get(redisKey);
|
|
|
|
- if(!StringUtils.equals(value, token)) {
|
|
|
|
|
|
+ String value = (String) redisUtil.get(redisKey);
|
|
|
|
+ if (!StringUtils.equals(value, token)) {
|
|
throw new RemoteServiceException("修改密码,参数异常");
|
|
throw new RemoteServiceException("修改密码,参数异常");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -571,10 +599,75 @@ public class AdminUserLogic {
|
|
AdminUserBean bean = (AdminUserBean) o;
|
|
AdminUserBean bean = (AdminUserBean) o;
|
|
final AdminUser adminUser = adminUserService.getById(bean.getAdminUserId());
|
|
final AdminUser adminUser = adminUserService.getById(bean.getAdminUserId());
|
|
|
|
|
|
- bean.setToken(JwtUtils.refreshToken(token, Constant.PC_API));
|
|
|
|
|
|
+ final JwtUtils.JwtParseResult result = JwtUtils.parseToken(token);
|
|
|
|
+
|
|
|
|
+ bean.setToken(JwtUtils.refreshToken(token, result.getIssuer()));
|
|
|
|
|
|
//存放到redis
|
|
//存放到redis
|
|
redisUtil.set(Constant.RedisPrefix.TOKEN_MANAGE + bean.getToken(), adminUser, 2 * 60 * 60 * 1000);
|
|
redisUtil.set(Constant.RedisPrefix.TOKEN_MANAGE + bean.getToken(), adminUser, 2 * 60 * 60 * 1000);
|
|
return bean;
|
|
return bean;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public AdminUserBean miniLogin(String userName, String password, String code, Boolean isAccount) {
|
|
|
|
+
|
|
|
|
+ AdminUser adminUser;
|
|
|
|
+ if (isAccount) {
|
|
|
|
+ adminUser = adminUserService.lambdaQuery()
|
|
|
|
+ .eq(AdminUser::getUserName, userName)
|
|
|
|
+ .one();
|
|
|
|
+ } else {
|
|
|
|
+ adminUser = adminUserService.lambdaQuery()
|
|
|
|
+ .eq(AdminUser::getLinkPhone, userName)
|
|
|
|
+ .last("limit 1")
|
|
|
|
+ .one();
|
|
|
|
+ }
|
|
|
|
+ if (adminUser == null) {
|
|
|
|
+ throw new RemoteServiceException("帐号不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (adminUser.getLoginErrNum() >= 3) {
|
|
|
|
+ throw new RemoteServiceException("登陆失败,账号已锁,请联系管理人员重置密码");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!isAccount) {
|
|
|
|
+ smsLogic.checkSmsCode(userName, code, "LOGIN");
|
|
|
|
+ } else {
|
|
|
|
+ if (!StringUtils.equals(adminUser.getPassword(), SecureUtil.md5(password))) {
|
|
|
|
+ adminUser.setLoginErrNum(adminUser.getLoginErrNum() + 1);
|
|
|
|
+ adminUserService.saveOrUpdate(adminUser);
|
|
|
|
+ //记录错误次数
|
|
|
|
+ throw new RemoteServiceException("帐号密码错误");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!adminUser.getStatus()) {
|
|
|
|
+ throw new RemoteServiceException("帐号冻结中,请联系相关管理人员");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ adminUser.setLoginErrNum(0);
|
|
|
|
+ adminUser.setLastLoginTime(new Date());
|
|
|
|
+ adminUser.updateById();
|
|
|
|
+
|
|
|
|
+ AdminUserBean adminUserBean = new AdminUserBean();
|
|
|
|
+ BeanUtils.copyProperties(adminUser, adminUserBean);
|
|
|
|
+
|
|
|
|
+ // 注入服务对象
|
|
|
|
+ if (RoleTypeEnum.isMerchant(adminUser.getType())) {
|
|
|
|
+ if (StringUtils.isNotBlank(adminUser.getServiceProviderId())) {
|
|
|
|
+ adminUserBean.setMerchant(merchantService.getById(adminUser.getServiceProviderId()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // token到期时间
|
|
|
|
+ final DateTime offset = DateUtil.offset(DateUtil.date(), DateField.MINUTE, Math.toIntExact(expiration));
|
|
|
|
+ adminUserBean.setExpireTimeToken(offset);
|
|
|
|
+
|
|
|
|
+ //不返回密码
|
|
|
|
+ adminUserBean.setPassword(null);
|
|
|
|
+ adminUserBean.setToken(JwtUtils.generateToken(adminUser.getAdminUserId(), adminUser.getUserName(), adminUser.getNickName(), adminUser.getType(), Constant.MINIAPP_API));
|
|
|
|
+ //存放到redis
|
|
|
|
+ redisUtil.set(Constant.RedisPrefix.TOKEN_MANAGE + adminUserBean.getToken(), adminUser, expiration * 1000);
|
|
|
|
+
|
|
|
|
+ return adminUserBean;
|
|
|
|
+ }
|
|
}
|
|
}
|