|
@@ -18,6 +18,7 @@ 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 org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -37,6 +38,7 @@ public class PlatformProductServiceImpl extends ServiceImpl<PlatformProductDao,
|
|
|
* 增加
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void addProduct(PlatformProductDto obj) {
|
|
|
Integer userId = Optional.ofNullable(sysUserFeignService.queryUserInfo())
|
|
|
.map(SysUser::getId)
|
|
@@ -56,6 +58,7 @@ public class PlatformProductServiceImpl extends ServiceImpl<PlatformProductDao,
|
|
|
* 修改
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void updateProduct(PlatformProductDto dto) {
|
|
|
Optional.ofNullable(dto.getId()).orElseThrow(() -> new BizException("产品Id不能为空"));
|
|
|
Integer userId = Optional.ofNullable(sysUserFeignService.queryUserInfo())
|
|
@@ -76,9 +79,6 @@ public class PlatformProductServiceImpl extends ServiceImpl<PlatformProductDao,
|
|
|
baseMapper.updateByPrimaryKeySelective(platformProduct);
|
|
|
//查询该产品有多少机构关联
|
|
|
Map<Integer, Integer> map = queryTenantByMultiId(dto.getId(), null, null);
|
|
|
- if (Objects.isNull(map)) {
|
|
|
- return;
|
|
|
- }
|
|
|
//检查是否需要修改权限
|
|
|
checkUpdateRole(dto.getMenuId(), sourceObj.getMenuId(), map);
|
|
|
}
|
|
@@ -86,31 +86,40 @@ public class PlatformProductServiceImpl extends ServiceImpl<PlatformProductDao,
|
|
|
/**
|
|
|
* 检查哪些机构用了这个产品,需要修改对应的权限
|
|
|
*
|
|
|
- * @param afterMenuIds 修改后的的菜单id,用逗号隔开
|
|
|
- * @param sourceMenuIds 修改之前的的菜单id,用逗号隔开
|
|
|
- * @param map Map<机构id,机构的管理员id> queryProductInTenant
|
|
|
+ * @param newMenuIds 修改后的的菜单id,用逗号隔开
|
|
|
+ * @param oldMenuIds 修改之前的的菜单id,用逗号隔开
|
|
|
+ * @param map Map<机构id,机构的管理员id> queryProductInTenant
|
|
|
*/
|
|
|
- public void checkUpdateRole(String afterMenuIds, String sourceMenuIds, Map<Integer, Integer> map) {
|
|
|
- //需要删除的菜单id
|
|
|
- List<Integer> deleteList = getList(sourceMenuIds);
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void checkUpdateRole(String newMenuIds, String oldMenuIds, Map<Integer, Integer> map) {
|
|
|
//需要添加的菜单id
|
|
|
- List<Integer> addList = getList(afterMenuIds);
|
|
|
+ List<Integer> newList = getList(newMenuIds);
|
|
|
+ //需要删除的菜单id
|
|
|
+ List<Integer> oldList = getList(oldMenuIds);
|
|
|
+ //合并修改权限
|
|
|
+ opsRoleMenu(map, newList, oldList);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void opsRoleMenu(Map<Integer, Integer> map, List<Integer> newList, List<Integer> oldList) {
|
|
|
+ if (Objects.isNull(map)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
//求新旧产品菜单的差异
|
|
|
- WrapperUtil.listDifference(deleteList, addList);
|
|
|
+ WrapperUtil.listDifference(oldList, newList);
|
|
|
//修改数据
|
|
|
map.forEach((tenantId, uId) -> {
|
|
|
- if (CollectionUtils.isNotEmpty(addList)) {
|
|
|
+ if (CollectionUtils.isNotEmpty(newList)) {
|
|
|
//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));
|
|
|
+ Lists.partition(newList, 50)
|
|
|
+ .forEach(idList -> baseMapper.batchInsertRoleMenu(adminRole, idList, tenantId));
|
|
|
}
|
|
|
//根据机构id 和 角色的菜单id删除信息
|
|
|
- if (CollectionUtils.isNotEmpty(deleteList)) {
|
|
|
- Lists.partition(deleteList, 50)
|
|
|
+ if (CollectionUtils.isNotEmpty(oldList)) {
|
|
|
+ Lists.partition(oldList, 50)
|
|
|
.forEach(idList -> employeeDao.delRoleMenu(tenantId, idList));
|
|
|
}
|
|
|
});
|
|
@@ -150,6 +159,7 @@ public class PlatformProductServiceImpl extends ServiceImpl<PlatformProductDao,
|
|
|
* @param id 产品id
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void deleteProduct(Integer id) {
|
|
|
Optional.ofNullable(id).orElseThrow(() -> new BizException("产品Id不能为空"));
|
|
|
Integer userId = Optional.ofNullable(sysUserFeignService.queryUserInfo())
|