Commit 5e39eccd by 宋振民

feat:系统安全功能开发

parent dbabcc51
......@@ -69,10 +69,4 @@ public class LoginController {
return Result.success(token);
}
@GetMapping("init")
@ApiOperation("批量初始化密码")
public Object init() throws Exception {
int count = userService.init();
return Result.success(count);
}
}
......@@ -135,7 +135,7 @@ public class UserController {
*
* @return
*/
@PostMapping("init")
@GetMapping("init")
@ApiOperation("批量初始化密码")
public Object init() throws Exception {
int count = userService.init();
......
......@@ -14,6 +14,8 @@ public interface SysUserMapper {
List<SysUser> selectAll();
void copySysUser(@Param("tableName") String tableName);
int updateByPrimaryKey(SysUser record);
SysUser selectByCode(@Param("userCode") String loginName);
......
......@@ -58,7 +58,7 @@ public class LoginServiceImpl implements LoginService {
SysUser user = userServiceImpl.findByLoginName(logName);
//判断是否被锁定
if(user.isLockFlag())
if(user != null && user.isLockFlag())
throw new DBConfigurationError("该账号已被锁定请联系管理员解锁!");
//判断是否很久没有更改密码
if(sysConfigService.getStateByKey(SysConfigKeyType.PWD_TIME_LIMIT.getCode())
......
package com.hs.api.service.Impl;
import com.hs.api.common.utils.AESUtil;
import com.hs.api.common.utils.DateUtils;
import com.hs.api.mapper.DicUserMapper;
import com.hs.api.mapper.SysUserMapper;
import com.hs.api.model.SysUser;
......@@ -8,7 +9,10 @@ import com.hs.api.service.UserService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@Service
public class UserServiceImpl implements UserService {
......@@ -36,14 +40,18 @@ public class UserServiceImpl implements UserService {
@Override
public int init() {
List<SysUser> sysUsers = sysUserMapper.selectAll();
Calendar calendar = DateUtils.getCalendar(new Date());
sysUserMapper.copySysUser("sys_user" + calendar.getTimeInMillis());
AtomicInteger count = new AtomicInteger();
sysUsers.stream().forEach(user -> {
String password = user.getPassword();
user.setPassword(AESUtil.encrypt(password));
if(!user.getPwdInit()) {
user.setPwdInit(true);
sysUserMapper.updateByPrimaryKey(user);
count.getAndIncrement();
}
});
return sysUsers.size();
return count.intValue();
}
}
......@@ -84,6 +84,9 @@
from SYS_USER
where ID = #{id,jdbcType=DECIMAL}
</select>
<update id="copySysUser" parameterType="java.lang.String">
create table ${tableName} select * from sys_user
</update>
<select id="selectAll" resultMap="BaseResultMap">
select ID,
CREATE_DATE,
......
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