Commit e96120ec authored by 赵啸非's avatar 赵啸非

添加目录字段

parent cfb0ba91
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
package com.mortals.xhx.base.system.user.service; package com.mortals.xhx.base.system.user.service;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Result; import com.mortals.framework.model.Result;
import com.mortals.framework.service.ICRUDCacheService; import com.mortals.framework.service.ICRUDCacheService;
...@@ -39,7 +38,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> { ...@@ -39,7 +38,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @return * @return
* @throws AppException * @throws AppException
*/ */
UserEntity doLogin(String loginName, String password, String loginIp) throws AppException; public UserEntity doLogin(String loginName, String password, String loginIp) throws AppException;
/** /**
* 校验用户名与密码是否正确 * 校验用户名与密码是否正确
...@@ -49,7 +48,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> { ...@@ -49,7 +48,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @return * @return
* @throws AppException * @throws AppException
*/ */
UserEntity doCheckUser(String loginName, String password) throws AppException; public UserEntity doCheckUser(String loginName, String password) throws AppException;
/** /**
* 检查用户是否存在 * 检查用户是否存在
...@@ -58,7 +57,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> { ...@@ -58,7 +57,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @param userId 密码 * @param userId 密码
* @return * @return
*/ */
boolean existUser(String loginName, Long userId) throws AppException; public boolean existUser(String loginName, Long userId) throws AppException;
/** /**
* 通过登录用户获取菜单功能权限 * 通过登录用户获取菜单功能权限
...@@ -66,7 +65,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> { ...@@ -66,7 +65,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @param user * @param user
* @return * @return
*/ */
List<MenuEntity> findOutlookBarList(IUser user); public List<MenuEntity> findOutlookBarList(IUser user);
/** /**
* 查询用户所有有权限的菜单ID * 查询用户所有有权限的菜单ID
...@@ -74,7 +73,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> { ...@@ -74,7 +73,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @param userEntity * @param userEntity
* @return * @return
*/ */
Set<Long> findAllAuthIds(UserEntity userEntity) throws AppException; public Set<Long> findAllAuthIds(UserEntity userEntity) throws AppException;
/** /**
* 查询用户记录 * 查询用户记录
...@@ -86,7 +85,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> { ...@@ -86,7 +85,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @return * @return
* @throws AppException * @throws AppException
*/ */
Result<UserEntity> find(Long platformId, UserEntity params, int currPage, int prePageResult) throws AppException; public Result<UserEntity> find(Long platformId, UserEntity params, int currPage, int prePageResult) throws AppException;
/** /**
* 为客户创建用户 * 为客户创建用户
...@@ -101,7 +100,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> { ...@@ -101,7 +100,7 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @return * @return
* @throws AppException * @throws AppException
*/ */
UserEntity createUser(IUser currUser, Long customerId, String customerName, String loginName, String password, public UserEntity createUser(IUser currUser, Long customerId, String customerName, String loginName, String password,
String userName, String mobile) throws AppException; String userName, String mobile) throws AppException;
/** /**
...@@ -113,11 +112,32 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> { ...@@ -113,11 +112,32 @@ public interface UserService extends ICRUDCacheService<UserEntity,Long> {
* @return * @return
* @throws AppException * @throws AppException
*/ */
boolean updateUserPwd(String loginName, String oldPwd, String newPwd) throws AppException; public boolean updateUserPwd(String loginName, String oldPwd, String newPwd) throws AppException;
/**
*
* @param entity
*/
void doHandlerUser(UserEntity entity);
Rest<Void> refreshUser();
UserDao getUserDao(); UserDao getUserDao();
/**
* 发送手机验证码
* @param mobileNumber
* @throws AppException
*/
void sendSmsVerifyCode(String mobileNumber) throws AppException;
/**
* 手机验证码登录
* @param mobileNumber
* @param verifyCode
* @param loginIp
* @return
* @throws AppException
*/
UserEntity doSmsLogin(String mobileNumber, String verifyCode, String loginIp) throws AppException;
} }
\ No newline at end of file
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
package com.mortals.xhx.base.system.user.service.impl; package com.mortals.xhx.base.system.user.service.impl;
import cn.hutool.core.util.PhoneUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.ap.SysConstains; import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.Rest;
import com.mortals.framework.common.code.UserType; import com.mortals.framework.common.code.UserType;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
...@@ -17,32 +19,26 @@ import com.mortals.framework.model.PageInfo; ...@@ -17,32 +19,26 @@ import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result; import com.mortals.framework.model.Result;
import com.mortals.framework.service.IUser; import com.mortals.framework.service.IUser;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.framework.util.HttpUtil;
import com.mortals.framework.util.SecurityUtil; import com.mortals.framework.util.SecurityUtil;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.menu.model.MenuEntity; import com.mortals.xhx.base.system.menu.model.MenuEntity;
import com.mortals.xhx.base.system.menu.service.MenuService; import com.mortals.xhx.base.system.menu.service.MenuService;
import com.mortals.xhx.base.system.resource.model.ResourceEntity; import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.service.ResourceService; import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.role.dao.RoleUserDao;
import com.mortals.xhx.base.system.role.model.RoleUserEntity; import com.mortals.xhx.base.system.role.model.RoleUserEntity;
import com.mortals.xhx.base.system.role.model.RoleUserQuery; import com.mortals.xhx.base.system.role.model.RoleUserQuery;
import com.mortals.xhx.base.system.role.service.RoleUserService;
import com.mortals.xhx.base.system.user.dao.UserDao; import com.mortals.xhx.base.system.user.dao.UserDao;
import com.mortals.xhx.base.system.user.model.UserEntity; import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery; import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService; import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.YesNoEnum; import org.apache.commons.collections4.CollectionUtils;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.feign.user.IUserFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* <p>Title: 用户信息</p> * <p>Title: 用户信息</p>
...@@ -54,7 +50,6 @@ import java.util.stream.Collectors; ...@@ -54,7 +50,6 @@ import java.util.stream.Collectors;
* @version 1.0.0 * @version 1.0.0
*/ */
@Service("userService") @Service("userService")
@Slf4j
public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserEntity, Long> implements UserService { public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserEntity, Long> implements UserService {
...@@ -63,18 +58,27 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -63,18 +58,27 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
@Autowired @Autowired
private ResourceService resourceService; private ResourceService resourceService;
@Autowired @Autowired
private RoleUserService roleUserService; private RoleUserDao roleUserDao;
@Lazy @Value("${sms.smsSendUrl:http://sms.wx3.com.cn/api/index/index}")
@Autowired private String smsApiUrl;
private IUserFeign userFeign; @Value("${sms.apiId:ADsUXLrS81vZDU95}")
private String appid;
/**
* 短信模板ID
**/
private static String SMS_TPYE = "30";
private static String SMS_VERIFY_CODE_KEY = "login:sms:verify:";
@Override @Override
protected String getExtKey(UserEntity data) { protected String getExtKey(UserEntity data) {
return data.getLoginName(); return data.getLoginName();
} }
private void doHandlerUser(UserEntity entity) throws AppException {
public void doHandlerUser(UserEntity entity) throws AppException {
if (StringUtils.isNotEmpty(entity.getLoginPwd())) { if (StringUtils.isNotEmpty(entity.getLoginPwd())) {
try { try {
entity.setLoginPwd(SecurityUtil.md5DoubleEncoding(entity.getLoginPwd())); entity.setLoginPwd(SecurityUtil.md5DoubleEncoding(entity.getLoginPwd()));
...@@ -84,63 +88,98 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -84,63 +88,98 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
} else { } else {
entity.setLoginPwd(null); entity.setLoginPwd(null);
} }
// if (entity.isSystemUser()) {
// entity.setUserType(UserType.SYSTEM.getValue());
// } else {
// entity.setUserType(UserType.CUSTOMER.getValue());
// }
} }
@Override @Override
protected void saveBefore(UserEntity entity, Context context) throws AppException { protected void saveBefore(UserEntity entity, Context context) throws AppException {
if (!ObjectUtils.isEmpty(entity.getLoginName()) && existUser(entity.getLoginName(), entity.getId())) {
throw new AppException("登录名已存在!");
}
this.doHandlerUser(entity); this.doHandlerUser(entity);
}
@Override
protected void saveAfter(UserEntity entity, Context context) throws AppException {
if (CollectionUtils.isNotEmpty(entity.getRoleIds())) {
List<RoleUserEntity> roleUserEntityList = new ArrayList<>();
entity.getRoleIds().stream().forEach(item -> {
RoleUserEntity roleUserEntity = new RoleUserEntity();
roleUserEntity.setUserId(entity.getId());
roleUserEntity.setRoleId(item);
roleUserEntityList.add(roleUserEntity);
});
roleUserDao.insertBatch(roleUserEntityList);
}
} }
@Override @Override
protected void updateBefore(UserEntity entity, Context context) throws AppException { protected void updateBefore(UserEntity entity, Context context) throws AppException {
// if (entity.getId().longValue() == SysConstains.ADMIN_ID && !context.getUser().isAdmin()) { /* if (entity.getId().longValue() == SysConstains.ADMIN_ID && !context.getUser().isAdmin()) {
// throw new AppException("你没有权限执行该操作"); throw new AppException("你没有权限执行该操作");
// } }*/
if (entity.getId().longValue() == SysConstains.ADMIN_ID) {
//更新不更新密码字段 throw new AppException("你没有权限执行该操作");
entity.setLoginPwd(null); }
this.doHandlerUser(entity); this.doHandlerUser(entity);
} }
@Override @Override
protected void saveAfter(UserEntity entity, Context context) throws AppException { protected void updateAfter(UserEntity entity, Context context) throws AppException {
//新增角色 if (CollectionUtils.isNotEmpty(entity.getRoleIds())) {
updateUserRole(entity); List<RoleUserEntity> roleUserEntityList = new ArrayList<>();
super.saveAfter(entity, context); entity.getRoleIds().stream().forEach(item -> {
RoleUserEntity roleUserEntity = new RoleUserEntity();
roleUserEntity.setUserId(entity.getId());
roleUserEntity.setRoleId(item);
roleUserEntityList.add(roleUserEntity);
});
RoleUserEntity condition = new RoleUserEntity();
condition.setUserId(entity.getId());
roleUserDao.delete(condition);
roleUserDao.insertBatch(roleUserEntityList);
}
} }
@Override @Override
protected void updateAfter(UserEntity entity, Context context) throws AppException { protected UserEntity findBefore(UserEntity params, Context context) throws AppException {
updateUserRole(entity); // if (StringUtils.isNotEmpty(params.getDeptIds())) {
super.updateAfter(entity, context); // params.setDeptIds(StringUtils.fillWithMark(params.getDeptIds(), ","));
// }
return super.findBefore(params, context);
} }
private void updateUserRole(UserEntity entity) { @Override
if (!ObjectUtils.isEmpty(entity.getId()) && entity.getId().longValue() != SysConstains.ADMIN_ID && !ObjectUtils.isEmpty(entity.getRoleIds())) { protected UserEntity findBefore(UserEntity params, PageInfo pageInfo, Context context) throws AppException {
RoleUserQuery roleUserQuery = new RoleUserQuery(); // if (StringUtils.isNotEmpty(params.getDeptIds())) {
roleUserQuery.setUserId(entity.getId()); // params.setDeptIds(StringUtils.fillWithMark(params.getDeptIds(), ","));
List<Long> idList = Arrays.asList(entity.getRoleIds().split(",")).stream().map(Long::parseLong).collect(Collectors.toList()); // }
roleUserQuery.setRoleIdList(idList); return super.findBefore(params, pageInfo, context);
roleUserService.doDistributionRole(roleUserQuery);
}
} }
@Override @Override
protected void findAfter(UserEntity params, PageInfo pageInfo, Context context, List<UserEntity> list) throws AppException { protected void findAfter(UserEntity params, PageInfo pageInfo, Context context, List<UserEntity> list) throws AppException {
list.stream().peek(item -> { if (CollectionUtils.isNotEmpty(list)) {
RoleUserQuery roleUserQuery = new RoleUserQuery(); list.stream().forEach(item -> {
roleUserQuery.setUserId(item.getId()); RoleUserEntity query = new RoleUserEntity();
String roleIds = roleUserService.find(roleUserQuery).stream().map(RoleUserEntity::getRoleId).map(String::valueOf).collect(Collectors.joining(",")); query.setUserId(item.getId());
item.setRoleIds(roleIds); List<RoleUserEntity> roleUserEntityList = roleUserDao.getList(query);
}).count(); List<Long> roleIds = new ArrayList<>();
super.findAfter(params, pageInfo, context, list); roleUserEntityList.stream().forEach(role -> {
roleIds.add(role.getRoleId());
});
item.setRoleIds(roleIds);
String roleIdStrs = StringUtils.join(roleIds, ",");
item.setRoleIdStrs(roleIdStrs);
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(item.getId());
});
}
} }
public UserEntity findByLoginName(String loginName) { public UserEntity findByLoginName(String loginName) {
UserQuery params = new UserQuery(); UserQuery params = new UserQuery();
params.setLoginName(loginName); params.setLoginName(loginName);
...@@ -164,6 +203,11 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -164,6 +203,11 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
} catch (Exception e) { } catch (Exception e) {
throw new AppException("密码验认出错!", e); throw new AppException("密码验认出错!", e);
} }
UserEntity update = new UserEntity();
update.setId(sysUser.getId());
update.setLastLoginAddress(loginIp);
update.setLastLoginTime(new Date());
this.dao.update(update);
return sysUser; return sysUser;
} }
...@@ -207,7 +251,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -207,7 +251,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
urls.addAll(StringUtils.converStr2Set(url)); urls.addAll(StringUtils.converStr2Set(url));
} }
} }
Set<Long> authIds = new HashSet<>(); Set<Long> authIds = new HashSet<Long>();
Map<Long, MenuEntity> menuMap = new HashMap<Long, MenuEntity>(); Map<Long, MenuEntity> menuMap = new HashMap<Long, MenuEntity>();
List<MenuEntity> userModuleList = this.menuService.findAllEnable(); List<MenuEntity> userModuleList = this.menuService.findAllEnable();
for (MenuEntity sysModule : userModuleList) { for (MenuEntity sysModule : userModuleList) {
...@@ -215,7 +259,6 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -215,7 +259,6 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
continue; continue;
} }
menuMap.put(sysModule.getId(), sysModule); menuMap.put(sysModule.getId(), sysModule);
if (!user.isAdmin() && urls.contains(StringUtils.trim(sysModule.getUrl()))) { if (!user.isAdmin() && urls.contains(StringUtils.trim(sysModule.getUrl()))) {
authIds.add(sysModule.getId()); authIds.add(sysModule.getId());
} }
...@@ -264,6 +307,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -264,6 +307,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
entity.initAttrValue(); entity.initAttrValue();
entity.setLoginName(loginName); entity.setLoginName(loginName);
entity.setRealName(userName); entity.setRealName(userName);
entity.setCustomerId(customerId);
entity.setLoginPwd(password); entity.setLoginPwd(password);
entity.setMobile(mobile); entity.setMobile(mobile);
entity.setUserType(UserType.CUSTOMER.getValue()); entity.setUserType(UserType.CUSTOMER.getValue());
...@@ -309,6 +353,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -309,6 +353,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
} }
try { try {
sysUser.setLoginPwd(SecurityUtil.md5DoubleEncoding(newPwd)); sysUser.setLoginPwd(SecurityUtil.md5DoubleEncoding(newPwd));
} catch (Exception e) { } catch (Exception e) {
throw new AppException("密码转换异常!", e); throw new AppException("密码转换异常!", e);
} }
...@@ -317,78 +362,78 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -317,78 +362,78 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
} }
@Override @Override
public Rest<Void> refreshUser() { public UserDao getUserDao() {
UserPdu userPdu = new UserPdu(); return this.getDao();
userPdu.setPage(1); }
userPdu.setSize(-1);
Rest<RespData<List<UserPdu>>> resp = userFeign.list(userPdu);
if (resp.getCode() == YesNoEnum.YES.getValue()) {
List<UserPdu> userPduList = resp.getData().getData();
log.info("用户总数量:{}", userPduList.size());
if (!ObjectUtils.isEmpty(userPduList)) {
List<UserEntity> newUserList = userPduList.stream().map(newUser -> {
UserEntity userEntity = new UserEntity();
userEntity.initAttrValue();
BeanUtils.copyProperties(newUser, userEntity, new String[]{"id", "lastLoginTime", "lastLoginAddress"});
return userEntity;
}).collect(Collectors.toList());
List<UserEntity> saveUpdateUserList = newUserList.parallelStream().map(item -> {
UserEntity extCache = this.getExtCache(item.getLoginName());
if (ObjectUtils.isEmpty(extCache)) {
item.setCreateUserId(1L);
item.setCreateUserName("系统管理员");
item.setCreateTime(new Date());
return item;
} else {
//更新用户列表
item.setId(extCache.getId());
item.setUpdateUserId(1L);
item.setUpdateUserName("系统管理员");
item.setUpdateTime(new Date());
return item;
}
}).collect(Collectors.toList());
Map<Boolean, List<UserEntity>> saveUpdateCollect = saveUpdateUserList.stream().collect(Collectors.partitioningBy(x -> x.getId() == null));
if (!ObjectUtils.isEmpty(saveUpdateCollect.get(true))) {
//需要新增的用户
log.info("需要新增用户数量:{}", saveUpdateCollect.get(true).size());
saveUpdateCollect.get(true).stream().forEach(item -> {
this.getUserDao().insert(item);
this.putCache(item.getId() == null ? "" : item.getId().toString(), item);
//更新默认用户角色
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(item.getId());
roleUserQuery.setRoleIdList(Arrays.asList(1L));
roleUserService.doDistributionRole(roleUserQuery);
});
}
if (!ObjectUtils.isEmpty(saveUpdateCollect.get(false))) { @Override
//需要新增的用户 public void sendSmsVerifyCode(String mobileNumber) throws AppException {
log.info("需要更新用户数量:{}", saveUpdateCollect.get(false).size()); if (StringUtils.isEmpty(mobileNumber)) {
saveUpdateCollect.get(false).stream().forEach(item -> { throw new AppException("手机号不能为空");
this.getUserDao().update(item); }
this.putCache(item.getId() == null ? "" : item.getId().toString(), item); if (!PhoneUtil.isPhone(mobileNumber)) {
}); throw new AppException("手机号码格式不正确");
} }
UserEntity user = this.selectOne(new UserQuery().mobile(mobileNumber));
if (user == null) {
throw new AppException("手机号码:" + mobileNumber + "没有注册用户");
}
String verifyCode = cacheService.get(SMS_VERIFY_CODE_KEY + mobileNumber);
if (StringUtils.isNotEmpty(verifyCode)) {
throw new AppException("当前手机号码已发送验证码,请稍后重试");
}
try {
Map<String, String> params = new HashMap<>();
params.put("appid", appid);
params.put("phone", mobileNumber);
params.put("type", SMS_TPYE);
String[] json = new String[2];
String vCode = RandomUtil.randomNumbers(6);
json[0] = vCode;
json[1] = "1";
params.put("json", JSONObject.toJSON(json).toString());
String resp = HttpUtil.doPost(smsApiUrl, params);
JSONObject respJson = JSONObject.parseObject(resp);
if (respJson.getIntValue("code") == 0) {
throw new AppException("短信发送失败:" + respJson.getString("message"));
} }
//查找新增 与更新 //有效期60秒
cacheService.setnx(SMS_VERIFY_CODE_KEY + mobileNumber, vCode, 60);
} catch (Exception e) {
log.error("短信发送异常", e);
throw new AppException("短信发送异常");
} }
return Rest.ok();
} }
@Override @Override
public UserDao getUserDao() { public UserEntity doSmsLogin(String mobileNumber, String verifyCode, String loginIp) throws AppException {
return getDao(); if (StringUtils.isEmpty(mobileNumber)) {
throw new AppException("手机号不能为空");
}
if (StringUtils.isEmpty(verifyCode)) {
throw new AppException("验证码不能为空");
}
if (!PhoneUtil.isPhone(mobileNumber)) {
throw new AppException("手机号码格式不正确");
}
UserEntity customer = this.selectOne(new UserQuery().mobile(mobileNumber));
if (customer == null) {
throw new AppException("手机号码:" + mobileNumber + "没有注册用户");
}
String vCode = cacheService.get(SMS_VERIFY_CODE_KEY + mobileNumber);
if (StringUtils.isEmpty(vCode)) {
throw new AppException("验证码已失效");
}
if (!verifyCode.equals(vCode)) {
throw new AppException("验证码不正确");
}
UserEntity update = new UserEntity();
update.setId(customer.getId());
update.setLastLoginAddress(loginIp);
update.setLastLoginTime(new Date());
this.update(update);
return customer;
} }
@Override
protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
super.removeAfter(ids, context, result);
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserIdList(Arrays.asList(ids));
Long[] userIds = roleUserService.find(roleUserQuery).stream().map(RoleUserEntity::getId).toArray(Long[]::new);
roleUserService.remove(userIds, context);
}
} }
\ No newline at end of file
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