| | |
| | | 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.mp.base.BaseServiceImpl; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.secure.BladeUser; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tenant.BladeTenantProperties; |
| | | import org.springblade.core.tool.api.R; |
| | | 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 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; |
| | | |
| | | //拿到配置的超管 |
| | | 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(BladeConstant.ADMIN_TENANT_ID); |
| | | // 默认设置为管理组下的用户 |
| | | user.setTenantId(nacosConfigCache.getAdminUserInfo().getTenantId()); |
| | | } |
| | | String tenantId = user.getTenantId(); |
| | | //Tenant tenant = SysCache.getTenant(tenantId); |
| | |
| | | } |
| | | |
| | | @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())); |
| | | 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; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<UserVO> selectUserSearch(UserVO user, Query query) { |
| | | LambdaQueryWrapper<User> queryWrapper = Wrappers.<User>query().lambda(); |
| | | String tenantId = AuthUtil.getTenantId(); |
| | |
| | | |
| | | @Override |
| | | public UserInfo userInfo(String tenantId, String account) { |
| | | User user = baseMapper.getUser(tenantId, account); |
| | | User user = baseMapper.getUser(tenantId, account,null); |
| | | return buildUserInfo(user); |
| | | } |
| | | |
| | | @Override |
| | | public UserInfo userInfo(String tenantId, String account,String name) { |
| | | User user = baseMapper.getUser(tenantId, account,name); |
| | | UserInfo userInfo = buildUserInfo(user); |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public UserInfo userInfo(String tenantId, String account, UserEnum userEnum) { |
| | | User user = baseMapper.getUser(tenantId, account); |
| | | User user = baseMapper.getUser(tenantId, account,null); |
| | | return buildUserInfo(user, userEnum); |
| | | } |
| | | |
| | |
| | | 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)) { |
| | |
| | | boolean result = RegexUtil.find(regex, newPassword1); |
| | | if(!result){ |
| | | throw new ServiceException("密码中只能存在【"+strategy.getCombinationNames()+"】中包含的字符!"); |
| | | //throw new ServiceException(resException); |
| | | } |
| | | //修改密码同时,改变用户信息中的密码修改状态字段,密码修改时间 |
| | | return this.update(Wrappers.<User>update().lambda() |
| | |
| | | @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); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 时间格式转天 |
| | | * 获取到指定身份权限的用户列表 |
| | | * @param user 用户查询的用户信息,如租户信息,通常为自动注入,前端可选择不传 |
| | | * @param roleName 要查询的角色身份 |
| | | * @return |
| | | */ |
| | | @Override |
| | | 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.isSuccess()){ |
| | | throw new ServiceException("系统服务feign接口调用错误!"); |
| | | } |
| | | if(Func.isBlank(roleIds.getData())){ |
| | | return new ArrayList<>(); |
| | | } |
| | | List<Map<String,String>> list = new ArrayList<>(); |
| | | Arrays.stream(roleIds.getData().split(",")).forEach(item->{ |
| | | list.addAll(this.baseMapper.getUserMap(item,user.getUserId().toString())); |
| | | }); |
| | | // 去除重复 |
| | | return list.stream().distinct().collect(Collectors.toList()); |
| | | } |
| | | |
| | | /** |
| | | * 日期时间格式转天 |
| | | * @param date |
| | | * @return |
| | | */ |