| | |
| | | package org.springblade.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springblade.common.constant.CommonConstant; |
| | | import org.springblade.core.cache.utils.CacheUtil; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.system.entity.Strategy; |
| | | import org.springblade.system.mapper.StrategyMapper; |
| | | import org.springblade.system.service.IStrategyService; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.PageImpl; |
| | | import org.springframework.data.domain.PageRequest; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | */ |
| | | @Override |
| | | public Strategy queryById(String id) { |
| | | return this.strategyMapper.queryById(id); |
| | | return this.getById(id); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * |
| | | * @param strategy 筛选条件 |
| | | * @param pageRequest 分页对象 |
| | | * @param query 分页对象 |
| | | * @return 查询结果 |
| | | */ |
| | | @Override |
| | | public Page<Strategy> queryAllByPage(Strategy strategy, PageRequest pageRequest) { |
| | | long total = this.strategyMapper.count(strategy); |
| | | return new PageImpl<>(this.strategyMapper.queryAllByPage(strategy, pageRequest), pageRequest, total); |
| | | public PageImpl<Strategy> queryAllByPage(Query query) { |
| | | Page<Strategy> strategyPage = new Page<>(query.getCurrent(), query.getSize()); |
| | | return new PageImpl<>(this.strategyMapper.queryAllByPage(strategyPage)); |
| | | } |
| | | |
| | | /** |
| | |
| | | public boolean submit(Strategy strategy) { |
| | | //判断是否携带id |
| | | if(Func.isEmpty(strategy.getId())){ |
| | | //新增 |
| | | //执行新增 |
| | | Strategy dbstrategy = this.getOne(Wrappers.<Strategy>query().lambda() |
| | | .eq(Strategy::getStrategyName, strategy.getStrategyName())); |
| | | //如果数据库中存在这条组合名称的记录直接返回 |
| | | if(!Func.isEmpty(dbstrategy)){ |
| | | throw new ServiceException("该密码策略已存在!"); |
| | | } |
| | | //如果当前新增设置为默认密码策略,需要将已存在默认密码策略修改为非默认 |
| | | 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(Func.isEmpty(strategy.getCreateTime())){ |
| | | strategy.setCreateTime(new Date()); |
| | |
| | | boolean temp = super.saveOrUpdate(strategy); |
| | | return temp; |
| | | }else { |
| | | //如果当前修改设置为默认密码策略,需要将已存在默认密码策略修改为非默认 |
| | | 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(Func.isEmpty(strategy.getUpdateTime())){ |
| | | strategy.setUpdateTime(new Date()); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | 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)); |
| | | //如果存在默认策略的id,就不能直接删除给出提示 |
| | | if(!Func.isEmpty(strategy)){ |
| | | throw new ServiceException("不能删除默认密码策略!"); |
| | | } |
| | | boolean tenantTemp = this.removeBatchByIds(ids); |
| | | return tenantTemp; |
| | | } |