ludc
2023-06-19 93845180efe4380609a2deb4dc22dd0523dbcd2a
Source/UBCS/ubcs-service/ubcs-user/src/main/java/com/vci/ubcs/system/user/service/impl/UserServiceImpl.java
@@ -19,6 +19,7 @@
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.vci.ubcs.system.cache.DictCache;
@@ -67,6 +68,7 @@
@Service
@RequiredArgsConstructor
public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implements IUserService {
   private static final String GUEST_NAME = "guest";
   private final IUserDeptService userDeptService;
@@ -160,6 +162,13 @@
   }
   @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 IPage<UserVO> selectUserSearch(UserVO user, Query query) {
      LambdaQueryWrapper<User> queryWrapper = Wrappers.<User>query().lambda();
      String tenantId = AuthUtil.getTenantId();
@@ -204,13 +213,20 @@
   @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);
   }
@@ -307,6 +323,10 @@
      }
      //获取用户采用的密码策略
      Strategy strategy = sysClient.getByUserId(userId).getData();
      // 几乎不会出现这种情况
      if(ObjectUtil.isEmpty(strategy)) {
         throw new ServiceException("当前用户未应用密码策略!");
      }
      //密码长度校验
      if(newPassword1.length() < strategy.getMinPwdLen() || newPassword1.length() > strategy.getMaxPwdLen()){
         throw new ServiceException("密码中必须含有【"+strategy.getCombinationNames()+"】中的【"+strategy.getRequiredType()+"】种密码组合方式,且密码长度必须在【"+strategy.getMinPwdLen()+"-"+strategy.getMaxPwdLen()+"】范围内");
@@ -318,7 +338,7 @@
         if(reqType>=strategy.getRequiredType()){
            break;
         }
         if(!Func.isEmpty(RegexUtil.findResult(regexs.get(i),newPassword1))){
         if(RegexUtil.find(regexs.get(i),newPassword1)){
            reqType++;
         }
      }
@@ -326,12 +346,13 @@
      if(reqType<strategy.getRequiredType()){
         throw new ServiceException(resException);
      }
      // 是否属于组合方式中的类型
      // 是否属于组合方式中的类型,以前是密码必须是包含在组合方式中的类型
      String regex = sysClient.getRegex(Arrays.asList(strategy.getCombinationIds().split(","))).getData();
      regex = "^"+regex+"{"+strategy.getRequiredType()+",}$";
      boolean result = RegexUtil.find(regex, newPassword1);
      if(!result){
         throw new ServiceException(resException);
         throw new ServiceException("密码中只能存在【"+strategy.getCombinationNames()+"】中包含的字符!");
         //throw new ServiceException(resException);
      }
      //修改密码同时,改变用户信息中的密码修改状态字段,密码修改时间
      return this.update(Wrappers.<User>update().lambda()
@@ -417,6 +438,7 @@
      boolean oauthTemp = userOauthService.updateById(userOauth);
      return (userTemp && oauthTemp);
   }
   @Override
   public boolean updatePlatform(Long userId, Integer userType, String userExt) {
      if (userType.equals(UserEnum.WEB.getCategory())) {
@@ -481,8 +503,9 @@
      if(adminUserId.equals(userId)){
         return 0L;
      }
      QueryWrapper<User> wrapper = Wrappers.<User>query().eq("ID", userId);
      //获取到密码修改时间
      Date pwdUpdateTime = this.getOne(Wrappers.<User>query().eq("ID", userId)).getPwdUpdateTime();
      Date pwdUpdateTime = this.getOne(wrapper).getPwdUpdateTime();
      Long pwdupdateday = 0L;
      if(!Func.isEmpty(pwdUpdateTime)){
         pwdupdateday = dateToDay(pwdUpdateTime);
@@ -503,6 +526,11 @@
      return 0L;
   }
   @Override
   public boolean updateByUseStrategyId(List<Long> userIds) {
      return this.update(Wrappers.<User>lambdaUpdate().in(User::getId, userIds).set(User::getStrategyUpdateStatus,CommonConstant.IS_DEFAULT));
   }
   /**
    * 时间格式转天
    * @param date