|
@@ -1,5 +1,7 @@
|
|
|
package com.sckw.system.service;
|
|
package com.sckw.system.service;
|
|
|
|
|
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
@@ -7,6 +9,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
|
|
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
|
|
|
import com.sckw.core.exception.SystemException;
|
|
import com.sckw.core.exception.SystemException;
|
|
|
import com.sckw.core.model.constant.Global;
|
|
import com.sckw.core.model.constant.Global;
|
|
|
|
|
+import com.sckw.core.model.enums.MenuTypeEnum;
|
|
|
import com.sckw.core.utils.BeanUtils;
|
|
import com.sckw.core.utils.BeanUtils;
|
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.IdWorker;
|
|
import com.sckw.core.utils.IdWorker;
|
|
@@ -17,8 +20,12 @@ import com.sckw.system.dao.*;
|
|
|
import com.sckw.system.model.*;
|
|
import com.sckw.system.model.*;
|
|
|
import com.sckw.system.model.pojo.FindMenuTreePojo;
|
|
import com.sckw.system.model.pojo.FindMenuTreePojo;
|
|
|
import com.sckw.system.model.vo.req.FindMenuTreeReqVo;
|
|
import com.sckw.system.model.vo.req.FindMenuTreeReqVo;
|
|
|
|
|
+import com.sckw.system.model.vo.req.MoveMenuReqVo;
|
|
|
|
|
+import com.sckw.system.model.vo.req.QueryChildMenuReqVo;
|
|
|
import com.sckw.system.model.vo.req.RoleBindMenuReqVo;
|
|
import com.sckw.system.model.vo.req.RoleBindMenuReqVo;
|
|
|
import com.sckw.system.model.vo.res.KwsMenuResVo;
|
|
import com.sckw.system.model.vo.res.KwsMenuResVo;
|
|
|
|
|
+import com.sckw.system.model.vo.res.QueryChildMenuResVo;
|
|
|
|
|
+import org.jetbrains.annotations.Nullable;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -60,13 +67,28 @@ public class KwsMenuService {
|
|
|
if (parentId.compareTo(0L) != 0) {
|
|
if (parentId.compareTo(0L) != 0) {
|
|
|
KwsMenu kwsMenu = kwsMenuDao.selectByKey(parentId);
|
|
KwsMenu kwsMenu = kwsMenuDao.selectByKey(parentId);
|
|
|
if (Objects.isNull(kwsMenu)) {
|
|
if (Objects.isNull(kwsMenu)) {
|
|
|
- throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
|
|
|
|
|
|
|
+ throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.PARENT_MENU_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //有重复的序号,则把后面的都加1
|
|
|
|
|
- if (!Objects.isNull(params.getSort())) {
|
|
|
|
|
- moveSort(params);
|
|
|
|
|
|
|
+ //新增按钮时,有重复的序号,则把后面的都加1
|
|
|
|
|
+ if (params.getType() == MenuTypeEnum.BUTTON.getCode()) {
|
|
|
|
|
+ if (!Objects.isNull(params.getSort())) {
|
|
|
|
|
+ moveSort(params);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //新增菜单时,如果已经有同级菜单,则序号为最大的序号+1
|
|
|
|
|
+ if (params.getType() == MenuTypeEnum.DIRECTORY.getCode()) {
|
|
|
|
|
+ KwsMenu kwsMenuParam = new KwsMenu();
|
|
|
|
|
+ kwsMenuParam.setType(params.getType());
|
|
|
|
|
+ kwsMenuParam.setParentId(params.getParentId());
|
|
|
|
|
+ List<KwsMenu> select = kwsMenuDao.select(kwsMenuParam);
|
|
|
|
|
+ int sort = 1;
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(select)) {
|
|
|
|
|
+ sort = select.get(select.size()).getSort() + 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ params.setSort(sort);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (kwsMenuDao.insert(params) <= 0) {
|
|
if (kwsMenuDao.insert(params) <= 0) {
|
|
@@ -303,4 +325,55 @@ public class KwsMenuService {
|
|
|
public List<KwsMenu> selectAll() {
|
|
public List<KwsMenu> selectAll() {
|
|
|
return kwsMenuDao.selectAll();
|
|
return kwsMenuDao.selectAll();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional(rollbackFor = {})
|
|
|
|
|
+ public void moveMenu(MoveMenuReqVo reqVo) {
|
|
|
|
|
+ KwsMenu kwsMenu = kwsMenuDao.selectByKey(reqVo.getId());
|
|
|
|
|
+ if (Objects.isNull(kwsMenu)) {
|
|
|
|
|
+ throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.MENU_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //查出要被换位置的按钮
|
|
|
|
|
+ KwsMenu targetMenu = getTargetMenu(reqVo.getMoveType(), kwsMenu);
|
|
|
|
|
+
|
|
|
|
|
+ //修改要换位置的按钮
|
|
|
|
|
+ kwsMenu.setSort(kwsMenu.getSort() + reqVo.getMoveType());
|
|
|
|
|
+ if (kwsMenuDao.update(kwsMenu) <= 0) {
|
|
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (Objects.isNull(targetMenu)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //更新被换位置的按钮
|
|
|
|
|
+ targetMenu.setSort(targetMenu.getSort() - reqVo.getMoveType());
|
|
|
|
|
+ if (kwsMenuDao.update(targetMenu) <= 0) {
|
|
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private KwsMenu getTargetMenu(Integer moveType, KwsMenu kwsMenu) {
|
|
|
|
|
+ KwsMenu kwsMenuParam = new KwsMenu();
|
|
|
|
|
+ kwsMenuParam.setType(kwsMenu.getType());
|
|
|
|
|
+ kwsMenuParam.setParentId(kwsMenu.getParentId());
|
|
|
|
|
+ kwsMenuParam.setSort(kwsMenu.getSort() + moveType);
|
|
|
|
|
+ kwsMenuParam.setDelFlag(Global.NO);
|
|
|
|
|
+ List<KwsMenu> targetMenuList = kwsMenuDao.select(kwsMenuParam);
|
|
|
|
|
+ return CollectionUtils.isEmpty(targetMenuList) ? null : targetMenuList.get(0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public List<QueryChildMenuResVo> queryChildMenu(QueryChildMenuReqVo reqVo) {
|
|
|
|
|
+ KwsMenu kwsMenuParam = new KwsMenu();
|
|
|
|
|
+ kwsMenuParam.setParentId(reqVo.getId());
|
|
|
|
|
+ kwsMenuParam.setType(reqVo.getMenuType());
|
|
|
|
|
+ List<KwsMenu> select = kwsMenuDao.select(kwsMenuParam);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(select)) {
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+ return BeanUtils.copyToList(select, QueryChildMenuResVo.class);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|