| | |
| | | import com.vci.ubcs.system.mapper.StrategyMapper; |
| | | import com.vci.ubcs.system.service.IStrategyService; |
| | | import org.springblade.core.cache.utils.CacheUtil; |
| | | import com.vci.ubcs.core.log.exception.ServiceException; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import com.vci.ubcs.system.entity.Strategy; |
| | |
| | | if(!Func.isEmpty(dbstrategy)){ |
| | | throw new ServiceException("该密码策略已存在!"); |
| | | } |
| | | //检验密码策略是否符合要求 |
| | | checkPwdStrategy(strategy); |
| | | //如果当前新增设置为默认密码策略,需要将已存在默认密码策略修改为非默认 |
| | | if(strategy.getIsDefault().equals("1") || strategy.getIsDefault() == 1){ |
| | | this.update(Wrappers.<Strategy>update().lambda() |
| | | .set(Strategy::getIsDefault, CommonConstant.NOT_SEALED_ID) |
| | | .eq(Strategy::getIsDefault, CommonConstant.DATA_SCOPE_CATEGORY)); |
| | | } |
| | | if(strategy.getRequiredType() > 0){ |
| | | throw new ServiceException("必填种类不能小于等于0!"); |
| | | } |
| | | if(strategy.getRequiredType() > strategy.getCombinationIds().split(",").length){ |
| | | throw new ServiceException("必填种类不能大于所选择的密码组合方式的个数!"); |
| | | } |
| | | if(strategy.getMaxPwdLen() > strategy.getMinPwdLen()){ |
| | | throw new ServiceException("密码最大长度不能小于最小长度!"); |
| | | } |
| | | if(strategy.getMinPwdLen() < strategy.getCombinationIds().split(",").length || strategy.getMaxPwdLen() < strategy.getCombinationIds().split(",").length){ |
| | | throw new ServiceException("密码最小长度不能小于秘密策略的值!"); |
| | | .set(Strategy::getIsDefault, CommonConstant.NOT_DEFAULT) |
| | | .eq(Strategy::getIsDefault, CommonConstant.IS_DEFAULT)); |
| | | } |
| | | if(Func.isEmpty(strategy.getCreateTime())){ |
| | | strategy.setCreateTime(new Date()); |
| | |
| | | boolean temp = super.saveOrUpdate(strategy); |
| | | return temp; |
| | | }else { |
| | | //检验密码策略是否符合要求 |
| | | checkPwdStrategy(strategy); |
| | | //如果当前修改设置为默认密码策略,需要将已存在默认密码策略修改为非默认 |
| | | if(strategy.getIsDefault().equals("1") || strategy.getIsDefault() == 1){ |
| | | this.update(Wrappers.<Strategy>update().lambda() |
| | | .set(Strategy::getIsDefault,CommonConstant.NOT_SEALED_ID) |
| | | .eq(Strategy::getIsDefault,CommonConstant.DATA_SCOPE_CATEGORY)); |
| | | .set(Strategy::getIsDefault,CommonConstant.NOT_DEFAULT) |
| | | .eq(Strategy::getIsDefault,CommonConstant.IS_DEFAULT)); |
| | | }else { |
| | | if(Func.isEmpty(queryByIsDefault())){ |
| | | throw new ServiceException("默认密码策略必须有且仅有一条!"); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 检验密码策略是否符合要求 |
| | | * @param strategy |
| | | */ |
| | | public void checkPwdStrategy(Strategy strategy){ |
| | | if(strategy.getRequiredType() > strategy.getCombinationIds().split(",").length){ |
| | | throw new ServiceException("必填种类不能大于所选择的密码组合方式的个数!"); |
| | | } |
| | | if(strategy.getMaxPwdLen() < strategy.getMinPwdLen()){ |
| | | throw new ServiceException("密码最大长度不能小于最小长度!"); |
| | | } |
| | | if(strategy.getMinPwdLen() < strategy.getRequiredType() || strategy.getMaxPwdLen() < strategy.getRequiredType()){ |
| | | throw new ServiceException("密码最小长度不能小于必填种类的值!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 通过主键删除数据 |
| | | * |
| | | * @param ids 主键 |
| | |
| | | public boolean deleteByIds(List<String> ids) { |
| | | Strategy strategy = this.getOne(Wrappers.<Strategy>query().lambda() |
| | | .in(Strategy::getId,ids) |
| | | .eq(Strategy::getIsDefault, CommonConstant.DATA_SCOPE_CATEGORY)); |
| | | .eq(Strategy::getIsDefault, CommonConstant.IS_DEFAULT)); |
| | | //如果存在默认策略的id,就不能直接删除给出提示 |
| | | if(!Func.isEmpty(strategy)){ |
| | | throw new ServiceException("不能删除默认密码策略!"); |