| | |
| | | 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("默认密码策略必须有且仅有一条!"); |
| | | } |