|
|
@@ -1,13 +1,20 @@
|
|
|
package cn.tr.module.sys.user.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.tr.core.exception.ServiceException;
|
|
|
+import cn.tr.core.exception.TRExcCode;
|
|
|
import cn.tr.module.sys.mapper.user.SysPortalMapper;
|
|
|
import cn.tr.module.sys.user.dto.SysPortalDTO;
|
|
|
import cn.tr.module.sys.user.dto.SysPortalQueryDTO;
|
|
|
+import cn.tr.module.sys.user.enums.PortalEnum;
|
|
|
+import cn.tr.module.sys.user.po.SysPortalMenuPO;
|
|
|
import cn.tr.module.sys.user.po.SysPortalPO;
|
|
|
+import cn.tr.module.sys.user.repository.SysPortalMenuRepository;
|
|
|
import cn.tr.module.sys.user.repository.SysPortalRepository;
|
|
|
+import cn.tr.module.sys.user.repository.SysUserPortalRepository;
|
|
|
import cn.tr.module.sys.user.service.ISysPortalService;
|
|
|
+import cn.tr.module.sys.user.service.ISysUserPortalService;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -25,12 +32,17 @@ import java.util.*;
|
|
|
public class SysPortalServiceImpl implements ISysPortalService {
|
|
|
@Autowired
|
|
|
private SysPortalRepository portalRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysPortalMenuRepository portalMenuRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserPortalService userPortalService;
|
|
|
@Override
|
|
|
public List<SysPortalDTO> selectSysPortalList(SysPortalQueryDTO query) {
|
|
|
return SysPortalMapper.INSTANCE.toSysPortalDTOList(portalRepository.selectList(new LambdaQueryWrapper<SysPortalPO>()
|
|
|
.like(StrUtil.isNotEmpty(query.getPortalCode()),SysPortalPO::getCode,query.getPortalCode())
|
|
|
.like(StrUtil.isNotEmpty(query.getPortalName()),SysPortalPO::getName,query.getPortalName())
|
|
|
- .eq(ObjectUtil.isNotNull(query.getDisable()),SysPortalPO::getDisable,query.getDisable())
|
|
|
));
|
|
|
}
|
|
|
|
|
|
@@ -42,17 +54,57 @@ public class SysPortalServiceImpl implements ISysPortalService {
|
|
|
|
|
|
@Override
|
|
|
public boolean updateSysPortalById(SysPortalDTO source) {
|
|
|
- return portalRepository.updateById( SysPortalMapper.INSTANCE.toSysPortalPO(source))!=0;
|
|
|
+ SysPortalPO po = SysPortalMapper.INSTANCE.toSysPortalPO(source);
|
|
|
+ validatePortalSource(po);
|
|
|
+ return portalRepository.updateById(po)!=0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public boolean insertSysPortal(SysPortalDTO source) {
|
|
|
- return portalRepository.insert(SysPortalMapper.INSTANCE.toSysPortalPO(source))!=0;
|
|
|
+ SysPortalPO po = SysPortalMapper.INSTANCE.toSysPortalPO(source);
|
|
|
+ validatePortalSource(po);
|
|
|
+ return portalRepository.insert(po)!=0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int deleteSysPortalByIds(Collection<String> ids) {
|
|
|
- return portalRepository.deleteBatchIds(ids);
|
|
|
+ List<SysPortalPO> portals = portalRepository.selectBatchIds(ids);
|
|
|
+ for (SysPortalPO portal : portals) {
|
|
|
+ if (StrUtil.equals(portal.getType(), PortalEnum.sys.name())) {
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"无法对系统门户进行操作");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Set<String> userIds = userPortalService.findUserIdsByPortalId(ids);
|
|
|
+ if(CollectionUtil.isNotEmpty(userIds)){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"所选门户已与用户关联,无法删除");
|
|
|
+ }
|
|
|
+ int result = portalRepository.deleteBatchIds(ids);
|
|
|
+ if(result!=0){
|
|
|
+ portalMenuRepository.delete(new LambdaQueryWrapper<SysPortalMenuPO>().in(SysPortalMenuPO::getPortalId,ids));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void validatePortalSource(SysPortalPO source){
|
|
|
+ SysPortalPO role = portalRepository.selectOne(new LambdaQueryWrapper<SysPortalPO>()
|
|
|
+ .eq(SysPortalPO::getCode, source.getCode())
|
|
|
+ .last("limit 1"));
|
|
|
+ if(role!=null&& StrUtil.equals(role.getId(),source.getId())){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,String.format("门户编码{%s}不能重复",source.getCode()));
|
|
|
+ }
|
|
|
+ if(StrUtil.equals(source.getType(), PortalEnum.sys.name())){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"无法对系统级门户进行操作");
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(source.getId())){
|
|
|
+ SysPortalPO sysRolePO = portalRepository.selectById(source.getId());
|
|
|
+ if(sysRolePO==null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(StrUtil.equals(sysRolePO.getType(), PortalEnum.sys.name())){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"无法对系统角色进行操作");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|