|
|
@@ -7,6 +7,7 @@ import java.util.*;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.sckw.core.exception.SystemException;
|
|
|
import com.sckw.core.model.constant.Global;
|
|
|
+import com.sckw.core.model.enums.ClientTypeEnum;
|
|
|
import com.sckw.core.model.enums.MenuTypeEnum;
|
|
|
import com.sckw.core.model.enums.SystemTypeEnum;
|
|
|
import com.sckw.core.utils.BeanUtils;
|
|
|
@@ -46,6 +47,9 @@ public class KwsMenuService {
|
|
|
@Autowired
|
|
|
KwsEnterpriseDao kwsEnterpriseDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ KwsMenuMappingDao kwsMenuMappingDao;
|
|
|
+
|
|
|
/**
|
|
|
* @param params 实体
|
|
|
* @desc: 添加新纪录
|
|
|
@@ -67,8 +71,6 @@ public class KwsMenuService {
|
|
|
params.setParentId(0L);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//新增按钮时,有重复的序号,则把后面的都加1
|
|
|
//按钮继承父菜单的using_roles
|
|
|
if (params.getType() == MenuTypeEnum.BUTTON.getCode()) {
|
|
|
@@ -259,12 +261,34 @@ public class KwsMenuService {
|
|
|
extracted(reqVo.getUserId(), findMenuTreePojo);
|
|
|
|
|
|
List<KwsMenuResVo> menuList = kwsMenuDao.findList(findMenuTreePojo);
|
|
|
+ List<KwsMenuResVo> finalList = new ArrayList<>();
|
|
|
+ //app菜单特殊处理
|
|
|
+ if (SystemTypeEnum.COMPANY.getCode().equals(LoginUserHolder.getSystemType()) && ClientTypeEnum.app.getValue().equals(LoginUserHolder.getClientType())) {
|
|
|
+ for (KwsMenuResVo kwsMenuResVo : menuList) {
|
|
|
+ List<KwsMenuMapping> kwsMenuMappings = kwsMenuMappingDao.selectByMenuId(kwsMenuResVo.getId());
|
|
|
+ if (CollectionUtils.isEmpty(kwsMenuMappings)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> mapIds = kwsMenuMappings.stream().map(KwsMenuMapping::getMappingId).toList();
|
|
|
+ List<KwsMenu> kwsMenus = kwsMenuDao.selectByKeys(mapIds);
|
|
|
+ if (CollectionUtils.isEmpty(kwsMenus)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<KwsMenuResVo> kwsMenuResVos = BeanUtils.copyToList(kwsMenus, KwsMenuResVo.class);
|
|
|
+ finalList.addAll(kwsMenuResVos);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ finalList = menuList;
|
|
|
+ }
|
|
|
+
|
|
|
List<KwsMenuResVo> rootList = new ArrayList<>();
|
|
|
|
|
|
//获取根节点数据
|
|
|
- if (CollectionUtil.isNotEmpty(menuList)) {
|
|
|
- int level = menuList.get(0).getLevel();
|
|
|
- for (KwsMenuResVo kwsMenu : menuList) {
|
|
|
+ if (CollectionUtil.isNotEmpty(finalList)) {
|
|
|
+ int level = finalList.get(0).getLevel();
|
|
|
+ for (KwsMenuResVo kwsMenu : finalList) {
|
|
|
if (kwsMenu.getLevel() == level) {
|
|
|
rootList.add(kwsMenu);
|
|
|
}
|
|
|
@@ -273,7 +297,7 @@ public class KwsMenuService {
|
|
|
|
|
|
//遍历,找到二级机构(根机构的id和所有机构中的pid比较)
|
|
|
for (KwsMenuResVo kwsMenu : rootList) {
|
|
|
- List<KwsMenuResVo> child = getChild(kwsMenu.getId(), menuList);
|
|
|
+ List<KwsMenuResVo> child = getChild(kwsMenu.getId(), finalList);
|
|
|
kwsMenu.setChildren(child);
|
|
|
}
|
|
|
return BeanUtils.copyToList(rootList, FindMenuTreeResVo.class);
|
|
|
@@ -420,4 +444,46 @@ public class KwsMenuService {
|
|
|
return BeanUtils.copyToList(select, QueryChildMenuResVo.class);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param reqVo 入参
|
|
|
+ * @desc: 保存菜单映射关系
|
|
|
+ * @author: czh
|
|
|
+ * @date: 2023/9/5
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {})
|
|
|
+ public void saveMapping(SaveMappingReqVo reqVo) {
|
|
|
+ Long menuId = reqVo.getMenuId();
|
|
|
+ List<Long> mappingIdList = reqVo.getMappingIdList();
|
|
|
+ List<KwsMenuMapping> kwsMenuMappings = kwsMenuMappingDao.selectByMenuId(menuId);
|
|
|
+ Date date = new Date();
|
|
|
+ if (CollectionUtils.isNotEmpty(kwsMenuMappings)) {
|
|
|
+ for (KwsMenuMapping kwsMenuMapping : kwsMenuMappings) {
|
|
|
+ kwsMenuMapping.setDelFlag(Global.YES);
|
|
|
+ kwsMenuMapping.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwsMenuMapping.setUpdateTime(date);
|
|
|
+ if (kwsMenuMappingDao.updateById(kwsMenuMapping) <= 0) {
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<KwsMenuMapping> list = new ArrayList<>();
|
|
|
+ for (Long id : mappingIdList) {
|
|
|
+ KwsMenuMapping kwsMenuMapping = new KwsMenuMapping();
|
|
|
+ kwsMenuMapping.setMenuId(menuId);
|
|
|
+ kwsMenuMapping.setMappingId(id);
|
|
|
+ kwsMenuMapping.setId(new IdWorker(1L).nextId());
|
|
|
+ kwsMenuMapping.setRemark(reqVo.getRemark());
|
|
|
+ kwsMenuMapping.setStatus(Global.NO);
|
|
|
+ kwsMenuMapping.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ kwsMenuMapping.setCreateTime(date);
|
|
|
+ kwsMenuMapping.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwsMenuMapping.setUpdateTime(date);
|
|
|
+ kwsMenuMapping.setDelFlag(Global.NO);
|
|
|
+ list.add(kwsMenuMapping);
|
|
|
+ }
|
|
|
+ kwsMenuMappingDao.saveBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
}
|