|
@@ -1,21 +1,34 @@
|
|
|
package com.ym.mec.auth.service.impl;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.apache.commons.lang.time.DateUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.auth.api.entity.SysUserLogin;
|
|
|
+import com.ym.mec.auth.api.enums.UserLockFlag;
|
|
|
+import com.ym.mec.auth.dal.dao.SysUserDao;
|
|
|
import com.ym.mec.auth.dal.dao.SysUserLoginDao;
|
|
|
import com.ym.mec.auth.service.SysUserLoginService;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
|
|
@Service
|
|
|
-public class SysUserLoginServiceImpl extends BaseServiceImpl<Long, SysUserLogin> implements SysUserLoginService {
|
|
|
-
|
|
|
+public class SysUserLoginServiceImpl extends BaseServiceImpl<Integer, SysUserLogin> implements SysUserLoginService {
|
|
|
+
|
|
|
@Autowired
|
|
|
private SysUserLoginDao sysUserLoginDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysUserDao sysUserDao;
|
|
|
+
|
|
|
@Override
|
|
|
- public BaseDAO<Long, SysUserLogin> getDAO() {
|
|
|
+ public BaseDAO<Integer, SysUserLogin> getDAO() {
|
|
|
return sysUserLoginDao;
|
|
|
}
|
|
|
|
|
@@ -23,4 +36,37 @@ public class SysUserLoginServiceImpl extends BaseServiceImpl<Long, SysUserLogin>
|
|
|
public SysUserLogin findLoginByUserId(Integer userId) {
|
|
|
return sysUserLoginDao.findLoginByUserId(userId);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
+ public boolean autoUnlock() {
|
|
|
+ List<SysUser> users = sysUserDao.queryByStatus(UserLockFlag.LOCKED);
|
|
|
+ if (users != null) {
|
|
|
+ SysUserLogin userLogin = null;
|
|
|
+ Date targetDate = null;
|
|
|
+ Date currentDate = new Date();
|
|
|
+ Integer lockTime = null;
|
|
|
+ for (SysUser user : users) {
|
|
|
+ userLogin = get(user.getId());
|
|
|
+ if (userLogin != null) {
|
|
|
+ lockTime = userLogin.getLockTime();
|
|
|
+ if (lockTime == null || lockTime == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ targetDate = DateUtils.addMinutes(userLogin.getLockDate(), lockTime);
|
|
|
+ if (targetDate.getTime() < currentDate.getTime()) {
|
|
|
+ userLogin.setFailCount(0);
|
|
|
+ userLogin.setLockDate(null);
|
|
|
+ userLogin.setLockTime(0);
|
|
|
+ update(userLogin);
|
|
|
+
|
|
|
+ user.setLockFlag(UserLockFlag.NORMAL);
|
|
|
+ user.setUpdateTime(currentDate);
|
|
|
+ sysUserDao.update(user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|