| | |
| | | private IUserClient userClient; |
| | | |
| | | /** |
| | | * nacos上拉取的配置 |
| | | */ |
| | | @Resource |
| | | private NacosConfigCache nacosConfigCache; |
| | | |
| | | /** |
| | | * 通过ID查询单条数据 |
| | | * |
| | | * @param id 主键 |
| | |
| | | public Strategy queryByIsDefault() { |
| | | return this.strategyMapper.queryByIsDefault(AuthUtil.getTenantId() |
| | | .equals( |
| | | nacosConfigCache |
| | | NacosConfigCache |
| | | .getAdminUserInfo() |
| | | .getTenantId() |
| | | ) ? null:AuthUtil.getTenantId() |
| | |
| | | strategyPage, |
| | | AuthUtil.getTenantId() |
| | | .equals( |
| | | nacosConfigCache |
| | | NacosConfigCache |
| | | .getAdminUserInfo() |
| | | .getTenantId() |
| | | ) |
| | |
| | | public boolean submit(Strategy strategy) { |
| | | //老的默认密码策略 |
| | | Long oldIsDefaultStrategy = null; |
| | | //判断是否携带id |
| | | //判断是否携带id,不携带id为新增操作 |
| | | if(Func.isEmpty(strategy.getId())){ |
| | | //执行新增 |
| | | Strategy dbstrategy = this.getOne(Wrappers.<Strategy>query().lambda() |
| | |
| | | //检验密码策略是否符合要求 |
| | | checkPwdStrategy(strategy); |
| | | //如果当前修改设置为默认密码策略,需要将已存在默认密码策略修改为非默认 |
| | | if(strategy.getIsDefault().equals("1") || strategy.getIsDefault() == 1){ |
| | | if((strategy.getIsDefault().toString()).equals("1")){ |
| | | //查询老的默认密码策略,便于下面修改 |
| | | oldIsDefaultStrategy = this.queryByIsDefault().getId(); |
| | | this.update(Wrappers.<Strategy>update().lambda() |
| | | .set(Strategy::getIsDefault,CommonConstant.NOT_DEFAULT) |
| | | .eq(Strategy::getIsDefault,CommonConstant.IS_DEFAULT)); |
| | | Strategy strategyDefault = this.queryByIsDefault(); |
| | | // 在数据不出现问题的情况下不会出现strategyDefault为空的情况 |
| | | if(Func.isNotEmpty(strategyDefault)){ |
| | | oldIsDefaultStrategy = strategyDefault.getId(); |
| | | this.update(Wrappers.<Strategy>update().lambda() |
| | | .set(Strategy::getIsDefault,CommonConstant.NOT_DEFAULT) |
| | | .eq(Strategy::getIsDefault,CommonConstant.IS_DEFAULT)); |
| | | } |
| | | }else { |
| | | // 避免用户将唯一的默认密码策略改为非默认 |
| | | if(Func.isEmpty(queryByIsDefault())){ |
| | | throw new ServiceException("默认密码策略必须有且仅有一条!"); |
| | | } |
| | | } |
| | | strategy.setUpdateTime(new Date()); |
| | | CacheUtil.clear(SYS_CACHE, Boolean.FALSE); |
| | | boolean temp1 = super.saveOrUpdate(strategy); |
| | | boolean temp1 = this.update(strategy,Wrappers.<Strategy>update().lambda().eq(Strategy::getId,strategy.getId())); |
| | | boolean temp2 = false; |
| | | if(Func.isNotEmpty(oldIsDefaultStrategy)){ |
| | | temp2 = updateUserStrategyDefault(temp1, oldIsDefaultStrategy); |
| | |
| | | if(Func.isNotEmpty(strategy.getRequiredType()) && (strategy.getMinPwdLen() < strategy.getRequiredType() || strategy.getMaxPwdLen() < strategy.getRequiredType())){ |
| | | throw new ServiceException("密码最小长度不能小于必填种类的值!"); |
| | | } |
| | | if(strategy.getExpirationTime() <= strategy.getReminderTime()){ |
| | | throw new ServiceException("过期时间不能小于提醒时间!"); |
| | | } |
| | | //判断前端是否未提交,是否默认字段 |
| | | if(Func.isEmpty(strategy.getIsDefault())){ |
| | | strategy.setIsDefault(0L); |