| | |
| | | import org.springblade.core.mp.base.BaseServiceImpl; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tenant.BladeTenantProperties; |
| | | import org.springblade.core.tool.constant.BladeConstant; |
| | |
| | | import org.springblade.modules.system.vo.UserDetailVO; |
| | | import org.springblade.modules.system.vo.UserVO; |
| | | import org.springblade.modules.system.wrapper.UserWrapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.connection.ReturnType; |
| | | import org.springframework.data.redis.core.RedisCallback; |
| | | import org.springframework.data.redis.core.ValueOperations; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import static org.springblade.common.constant.CommonConstant.DEFAULT_PARAM_PASSWORD; |
| | | |
| | |
| | | private final IDeptService deptService; |
| | | private final BladeTenantProperties tenantProperties; |
| | | private final IPoliceAffairsGridService policeAffairsGridService; |
| | | |
| | | @Autowired |
| | | private BladeRedis redisTemplate; |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | return b; |
| | | } |
| | | |
| | | /** |
| | | * 尝试获取锁 |
| | | * @param timeout 超时时间(毫秒) |
| | | * @return 是否成功获取锁 |
| | | */ |
| | | public boolean lock(long timeout,String lockKey) { |
| | | long endTime = System.currentTimeMillis() + timeout; |
| | | ValueOperations<String, Object> ops = redisTemplate.getValueOps(); |
| | | while (System.currentTimeMillis() < endTime) { |
| | | // 使用setIfAbsent命令尝试设置值,仅当key不存在时设置,类似于SETNX |
| | | Boolean result = ops.setIfAbsent(lockKey, String.valueOf(System.currentTimeMillis() + 5000), 5, TimeUnit.SECONDS); |
| | | if (result != null && result) { |
| | | return true; |
| | | } |
| | | try { |
| | | // 短暂休眠,防止CPU过度占用 |
| | | Thread.sleep(10); |
| | | } catch (InterruptedException e) { |
| | | Thread.currentThread().interrupt(); |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 释放锁 |
| | | */ |
| | | public void unlock(String lockKey) { |
| | | // 使用lua脚本保证操作的原子性,避免删除非本客户端创建的锁 |
| | | String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end"; |
| | | redisTemplate.getRedisTemplate().execute((RedisCallback<Object>) (connection) -> connection.eval(script.getBytes(), ReturnType.INTEGER, 1, lockKey.getBytes(), String.valueOf(redisTemplate.getValueOps().get(lockKey)).getBytes())); |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public IPage<User> selectUserPage(IPage<User> page, User user, String deptId, String tenantId) { |
| | | if (Strings.isBlank(deptId) && !AuthUtil.isAdministrator() && !AuthUtil.isAdmin()) { |
| | |
| | | * @param tenantId |
| | | * @param account |
| | | * @param password |
| | | * @param type 登录类型 2:pc 3:app |
| | | * @param type 登录类型 2:pc 3:app |
| | | * @return |
| | | */ |
| | | @Override |
| | |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param user |
| | | * @param type 登录类型 2:pc 3:app |
| | | * @return |
| | |
| | | userInfo.setUser(user); |
| | | if (Func.isNotEmpty(user)) { |
| | | // 判断登录类型设置对应的角色id |
| | | user.setRoleId(Strings.join(roleService.getRoleIdStrByRoleIdAndType(user.getRoleId(),type), ',')); |
| | | user.setRoleId(Strings.join(roleService.getRoleIdStrByRoleIdAndType(user.getRoleId(), type), ',')); |
| | | // 设置角色别名 |
| | | List<String> roleAlias = roleService.getRoleAliases(user.getRoleId()); |
| | | userInfo.setRoles(roleAlias); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean registerUser(UserVO user) { |
| | | if (StringUtils.isEmpty(user.getAccount())) { |
| | | throw new ServiceException("账号不能为空!"); |
| | | } |
| | | if (StringUtils.isEmpty(user.getPassword())) { |
| | | throw new ServiceException("密码不能为空!"); |
| | | } |
| | | if (!StringUtils.equals(user.getPassword(), user.getPassword2())) { |
| | | throw new ServiceException("两次的密码不一致!"); |
| | | } |
| | | long count = count(Wrappers.<User>lambdaQuery().eq(User::getAccount, user.getAccount())); |
| | | if (count > 0) { |
| | | throw new ServiceException("改账号已存在,请更换其他账号!"); |
| | | } |
| | | |
| | | user.setPassword(DigestUtil.encrypt(user.getPassword())); |
| | | user.setRoleId("1717429059648606209"); |
| | | boolean oauthTemp = save(user); |
| | | return (oauthTemp); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updatePlatform(Long userId, Integer userType, String userExt) { |
| | | if (userType.equals(UserEnum.WEB.getCategory())) { |
| | | UserWeb userWeb = new UserWeb(); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 处理漏绑定的user_dept |
| | | */ |
| | |
| | | userInfo.setRoleId(userInfo.getRoleId() + ",1727864411451359233"); |
| | | } |
| | | // 设置性别 |
| | | setSex(userInfo,userExcel); |
| | | setSex(userInfo, userExcel); |
| | | // 更新机构 |
| | | setDeptId(userInfo, userExcel); |
| | | // 更新 |
| | |
| | | user.setPhone(userExcel.getPhone()); |
| | | user.setAccount(userExcel.getPhone()); |
| | | // 设置性别 |
| | | setSex(user,userExcel); |
| | | setSex(user, userExcel); |
| | | // 更新机构 |
| | | setDeptId(user, userExcel); |
| | | // 设置初始密码 |
| | |
| | | |
| | | /** |
| | | * 设置性别 |
| | | * |
| | | * @param user |
| | | * @param userExcel |
| | | */ |
| | | private void setSex(User user, PoliceUserExcel userExcel) { |
| | | if (userExcel.getSex().contains("男")){ |
| | | if (userExcel.getSex().contains("男")) { |
| | | user.setSex(1); |
| | | } |
| | | if (userExcel.getSex().contains("女")){ |
| | | if (userExcel.getSex().contains("女")) { |
| | | user.setSex(2); |
| | | } |
| | | } |