| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.vci.ubcs.system.cache.DictCache; |
| | | import com.vci.ubcs.system.cache.NacosConfigCache; |
| | | import com.vci.ubcs.system.cache.ParamCache; |
| | | import com.vci.ubcs.system.cache.SysCache; |
| | | import com.vci.ubcs.system.entity.Strategy; |
| | |
| | | import org.springblade.core.tool.constant.BladeConstant; |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.*; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.DigestUtils; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | import static com.vci.ubcs.common.constant.CommonConstant.DEFAULT_PARAM_PASSWORD; |
| | | |
| | |
| | | private final IUserOauthService userOauthService; |
| | | private final ISysClient sysClient; |
| | | private final BladeTenantProperties tenantProperties; |
| | | //拿到配置的超管id |
| | | @Value("${user-info.id}") |
| | | private String adminUserId; |
| | | @Value("${user-info.tenant-id}") |
| | | private String tenantId; |
| | | //拿到配置的超管 |
| | | private final NacosConfigCache nacosConfigCache; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean submit(User user) { |
| | | if (StringUtil.isBlank(user.getTenantId())) { |
| | | // user.setTenantId(BladeConstant.ADMIN_TENANT_ID); |
| | | // user.setTenantId(nacosConfigCache.getAdminUserInfo().getTenantId()); |
| | | // 默认设置为管理组下的用户 |
| | | user.setTenantId(this.tenantId); |
| | | user.setTenantId(nacosConfigCache.getAdminUserInfo().getTenantId()); |
| | | } |
| | | String tenantId = user.getTenantId(); |
| | | //Tenant tenant = SysCache.getTenant(tenantId); |
| | |
| | | Boolean flag = true; |
| | | for (User user : users){ |
| | | if (StringUtil.isBlank(user.getTenantId())) { |
| | | user.setTenantId(BladeConstant.ADMIN_TENANT_ID); |
| | | user.setTenantId(nacosConfigCache.getAdminUserInfo().getTenantId()); |
| | | } |
| | | String tenantId = user.getTenantId(); |
| | | if (Func.isNotEmpty(user.getPassword())) { |
| | |
| | | @Override |
| | | public List<User> selectAllUser(User user, Long deptId){ |
| | | List<Long> deptIdList = SysCache.getDeptChildIds(deptId); |
| | | List<User> users = baseMapper.selectUserPage(user, deptIdList, (AuthUtil.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? StringPool.EMPTY : AuthUtil.getTenantId())); |
| | | List<User> users = baseMapper.selectUserPage(user, deptIdList, (AuthUtil.getTenantId().equals(nacosConfigCache.getAdminUserInfo().getTenantId()) ? StringPool.EMPTY : AuthUtil.getTenantId())); |
| | | return users; |
| | | } |
| | | |
| | | @Override |
| | | public List<User> selectAllUser(){ |
| | | LambdaQueryWrapper<User> wrapper= Wrappers.lambdaQuery(); |
| | | wrapper.eq(User::getIsDeleted,0); |
| | | List<User> users = baseMapper.selectList(wrapper); |
| | | return users; |
| | | } |
| | | |
| | |
| | | if (ObjectUtil.isEmpty(user)) { |
| | | return null; |
| | | } |
| | | user.setDeptName(Func.join(SysCache.getDeptNames(user.getDeptId()))); |
| | | UserInfo userInfo = new UserInfo(); |
| | | userInfo.setUser(user); |
| | | if (Func.isNotEmpty(user)) { |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void importUser(List<UserExcel> data, Boolean isCovered) { |
| | | ArrayList<User> addUsers = new ArrayList<>(); |
| | | data.forEach(userExcel -> { |
| | | User user = Objects.requireNonNull(BeanUtil.copy(userExcel, User.class)); |
| | | // 设置用户平台 |
| | |
| | | // 获取默认密码配置 |
| | | String initPassword = ParamCache.getValue(DEFAULT_PARAM_PASSWORD); |
| | | user.setPassword(initPassword); |
| | | this.submit(user); |
| | | addUsers.add(user); |
| | | //this.submit(user); |
| | | }); |
| | | this.submitList(addUsers); |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public Long checkRenAndExpr(Long userId) { |
| | | //超级管理员直接返回不需要提醒密码修改 |
| | | if(adminUserId.equals(userId)){ |
| | | if(nacosConfigCache.getAdminUserInfo().getUserId().equals(userId)){ |
| | | return 0L; |
| | | } |
| | | QueryWrapper<User> wrapper = Wrappers.<User>query().eq("ID", userId); |
| | | User dbUser = this.getOne(wrapper); |
| | | //获取到密码修改时间 |
| | | Date pwdUpdateTime = this.getOne(wrapper).getPwdUpdateTime(); |
| | | Date pwdUpdateTime = Func.isNotEmpty(dbUser) ? dbUser.getPwdUpdateTime():new Date(); |
| | | Long pwdupdateday = 0L; |
| | | if(!Func.isEmpty(pwdUpdateTime)){ |
| | | pwdupdateday = dateToDay(pwdUpdateTime); |
| | | } |
| | | Strategy strategy = sysClient.getByUserId(userId).getData(); |
| | | if(Func.isNotEmpty(strategy)){ |
| | | throw new ServiceException("密码策略查询为空,请检查当前租户下是否存在默认密码策略!"); |
| | | } |
| | | //是否提醒通过最后一次修改密码的时间加上过期时间减去当前时间,如果小于过期提醒时间就进行提醒,如果<=0就提醒必须修改密码 |
| | | long reminder = pwdupdateday+strategy.getExpirationTime()-dateToDay(new Date()); |
| | | //提醒用户必须修改密码 |
| | |
| | | public List<Map<String,String>> getByRoleUserList(BladeUser user, String roleName) { |
| | | // 考虑到一个用户可以拥有多种角色权限,而用户关联角色权限是用role_id字段用逗号分隔角色id的,直接采用子查询来in查询不能实现,所以先查询角色id |
| | | R<String> roleIds = sysClient.getRoleIds(user.getTenantId(), roleName); |
| | | if(roleIds.getCode() != 200){ |
| | | if(!roleIds.isSuccess()){ |
| | | throw new ServiceException("系统服务feign接口调用错误!"); |
| | | } |
| | | if(Func.isBlank(roleIds.getData())){ |
| | |
| | | return list.stream().distinct().collect(Collectors.toList()); |
| | | } |
| | | |
| | | /*** |
| | | * 更新用户启用停用状态 |
| | | * @param userIds |
| | | * @param status |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean updateUserStatus(String userIds, boolean status) { |
| | | Integer userStatus = 0; |
| | | if(!status){ |
| | | userStatus = 1; |
| | | } |
| | | return this.update(Wrappers.<User>lambdaUpdate().in(User::getId, Func.toLongList(userIds)).set(User::getUserStatus,userStatus)); |
| | | } |
| | | |
| | | /** |
| | | * 日期时间格式转天 |
| | | * @param date |