|
@@ -3,8 +3,10 @@ package com.ym.mec.biz.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
+import com.ym.mec.biz.dal.dao.EmployeeDao;
|
|
|
import com.ym.mec.biz.dal.dao.PlatformProductDao;
|
|
|
import com.ym.mec.biz.dal.dto.PlatformProductDto;
|
|
|
import com.ym.mec.biz.dal.entity.PlatformProduct;
|
|
@@ -12,14 +14,13 @@ import com.ym.mec.biz.service.PlatformProductService;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
import com.ym.mec.common.page.PageUtil;
|
|
|
+import com.ym.mec.common.page.WrapperUtil;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author hgw
|
|
@@ -29,6 +30,8 @@ import java.util.Optional;
|
|
|
public class PlatformProductServiceImpl extends ServiceImpl<PlatformProductDao, PlatformProduct> implements PlatformProductService {
|
|
|
@Autowired
|
|
|
private SysUserFeignService sysUserFeignService;
|
|
|
+ @Autowired
|
|
|
+ private EmployeeDao employeeDao;
|
|
|
|
|
|
/**
|
|
|
* 增加
|
|
@@ -53,24 +56,91 @@ public class PlatformProductServiceImpl extends ServiceImpl<PlatformProductDao,
|
|
|
* 修改
|
|
|
*/
|
|
|
@Override
|
|
|
- public void updateProduct(PlatformProductDto obj) {
|
|
|
- Optional.ofNullable(obj.getId()).orElseThrow(() -> new BizException("产品Id不能为空"));
|
|
|
+ public void updateProduct(PlatformProductDto dto) {
|
|
|
+ Optional.ofNullable(dto.getId()).orElseThrow(() -> new BizException("产品Id不能为空"));
|
|
|
Integer userId = Optional.ofNullable(sysUserFeignService.queryUserInfo())
|
|
|
.map(SysUser::getId)
|
|
|
.orElseThrow(() -> new BizException("用户信息获取失败"));
|
|
|
+ //查询该产品
|
|
|
+ PlatformProduct sourceObj = Optional.ofNullable(this.getById(dto.getId()))
|
|
|
+ .filter(s -> s.getDeleted() == 0)
|
|
|
+ .orElseThrow(() -> new BizException("未查询到该产品信息!"));
|
|
|
+
|
|
|
PlatformProduct platformProduct = new PlatformProduct();
|
|
|
- platformProduct.setId(obj.getId());
|
|
|
- platformProduct.setName(obj.getName());
|
|
|
- platformProduct.setMenuId(obj.getMenuId());
|
|
|
- platformProduct.setRemark(obj.getRemark());
|
|
|
+ platformProduct.setId(dto.getId());
|
|
|
+ platformProduct.setName(dto.getName());
|
|
|
+ platformProduct.setMenuId(dto.getMenuId());
|
|
|
+ platformProduct.setRemark(dto.getRemark());
|
|
|
platformProduct.setUpdatedBy(userId);
|
|
|
platformProduct.setUpdatedTime(new Date());
|
|
|
baseMapper.updateByPrimaryKeySelective(platformProduct);
|
|
|
- //查询哪些机构用了这个产品,需要修改对应的权限
|
|
|
-// List<Integer> tenantIds = baseMapper.queryProductInTenant(obj.getId());
|
|
|
-// if(CollectionUtils.isEmpty(tenantIds)){
|
|
|
-// return;
|
|
|
-// }
|
|
|
+ //查询该产品有多少机构关联
|
|
|
+ Map<Integer, Integer> map = queryTenantByMultiId(dto.getId(), null, null);
|
|
|
+ if (Objects.isNull(map)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //检查是否需要修改权限
|
|
|
+ checkUpdateRole(dto.getMenuId(), sourceObj.getMenuId(), map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查哪些机构用了这个产品,需要修改对应的权限
|
|
|
+ *
|
|
|
+ * @param menuIds 修改后的的菜单id,用逗号隔开
|
|
|
+ * @param sourceMenuIds 修改之前的的菜单id,用逗号隔开
|
|
|
+ * @param map Map<机构id,机构的管理员id> queryProductInTenant
|
|
|
+ */
|
|
|
+ public void checkUpdateRole(String menuIds, String sourceMenuIds, Map<Integer, Integer> map) {
|
|
|
+ //需要删除的菜单id
|
|
|
+ List<Integer> deleteList = getList(sourceMenuIds);
|
|
|
+ //需要添加的菜单id
|
|
|
+ List<Integer> addList = getList(menuIds);
|
|
|
+ //求新旧产品菜单的差异
|
|
|
+ WrapperUtil.listDifference(deleteList, addList);
|
|
|
+ //修改数据
|
|
|
+ map.forEach((tenantId, uId) -> {
|
|
|
+ if (CollectionUtils.isNotEmpty(addList)) {
|
|
|
+ //uId查询机构管理员角色
|
|
|
+ List<Integer> roles = employeeDao.queryUserRole(uId);
|
|
|
+ //机构管理员只会有一个管理员角色
|
|
|
+ Integer adminRole = roles.get(0);
|
|
|
+ //给管理员角色添加dtoList菜单id
|
|
|
+ Lists.partition(addList, 50)
|
|
|
+ .forEach(idList -> employeeDao.batchInsertRoleMenu(adminRole, idList, tenantId));
|
|
|
+ }
|
|
|
+ //根据机构id 和 角色的菜单id删除信息
|
|
|
+ if (CollectionUtils.isNotEmpty(deleteList)) {
|
|
|
+ Lists.partition(deleteList, 50)
|
|
|
+ .forEach(idList -> employeeDao.delRoleMenu(tenantId, idList));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Integer> getList(String str) {
|
|
|
+ List<String> strings = Optional.ofNullable(str).map(WrapperUtil::toList).orElse(null);
|
|
|
+ if (CollectionUtils.isEmpty(strings)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return strings.stream()
|
|
|
+ .map(WrapperUtil::toInt)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据多个id 查询出机构的id 和机构管理员id
|
|
|
+ *
|
|
|
+ * @param productId 产品id
|
|
|
+ * @param serveId 服务id
|
|
|
+ * @param tenantId 机构id
|
|
|
+ */
|
|
|
+ public Map<Integer, Integer> queryTenantByMultiId(Integer productId, Integer serveId, Integer tenantId) {
|
|
|
+ List<Map<Integer, Integer>> mapList = baseMapper.queryTenantByMultiId(productId, serveId, tenantId);
|
|
|
+ if (CollectionUtils.isEmpty(mapList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //Map<机构id,机构的管理员id>
|
|
|
+ return mapList.stream()
|
|
|
+ .collect(Collectors.toMap(m -> m.get("tenantId"), m -> m.get("userId"), (a, b) -> b));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -85,8 +155,8 @@ public class PlatformProductServiceImpl extends ServiceImpl<PlatformProductDao,
|
|
|
.map(SysUser::getId)
|
|
|
.orElseThrow(() -> new BizException("用户信息获取失败"));
|
|
|
//校验哪些机构用了该产品
|
|
|
- List<Integer> tenantIds = baseMapper.queryProductInTenant(id);
|
|
|
- if(CollectionUtils.isNotEmpty(tenantIds)){
|
|
|
+ List<Map<Integer, Integer>> map = baseMapper.queryTenantByMultiId(id, null, null);
|
|
|
+ if (CollectionUtils.isEmpty(map)) {
|
|
|
throw new BizException("该产品关联的服务已有机构在使用,无法删除!");
|
|
|
}
|
|
|
|