fix:部门管理相关代码
This commit is contained in:
@@ -100,14 +100,14 @@ public class MenuController {
|
|||||||
@ApiOperation("查询菜单")
|
@ApiOperation("查询菜单")
|
||||||
@SaCheckPermission("menu:list")
|
@SaCheckPermission("menu:list")
|
||||||
public ResponseEntity<Object> pageQuery(@RequestParam Map whereJson, Pageable page) throws Exception {
|
public ResponseEntity<Object> pageQuery(@RequestParam Map whereJson, Pageable page) throws Exception {
|
||||||
Object system_type = whereJson.get("system_type");
|
// Object system_type = whereJson.get("system_type");
|
||||||
if (system_type!=null && whereJson.get("pid") == null){
|
// if (system_type!=null && whereJson.get("pid") == null){
|
||||||
JSONObject jsonObject = WQLObject.getWQLObject("sys_dict").query("code = 'system_type' and value = '" + system_type + "'").uniqueResult(0);
|
// JSONObject jsonObject = WQLObject.getWQLObject("sys_dict").query("code = 'system_type' and value = '" + system_type + "'").uniqueResult(0);
|
||||||
if (jsonObject==null || jsonObject.getString("para1") ==null){
|
// if (jsonObject==null || jsonObject.getString("para1") ==null){
|
||||||
throw new BadRequestException("字典表没有配置system_type系统相关参数");
|
// throw new BadRequestException("字典表没有配置system_type系统相关参数");
|
||||||
}
|
// }
|
||||||
whereJson.put("pid",jsonObject.getString("para1"));
|
// whereJson.put("pid",jsonObject.getString("para1"));
|
||||||
}
|
// }
|
||||||
JSONObject param = JSONObject.parseObject(JSON.toJSONString(whereJson));
|
JSONObject param = JSONObject.parseObject(JSON.toJSONString(whereJson));
|
||||||
JSONObject menuDtoList = menuService.queryAll(param, page);
|
JSONObject menuDtoList = menuService.queryAll(param, page);
|
||||||
return new ResponseEntity<>(menuDtoList, HttpStatus.OK);
|
return new ResponseEntity<>(menuDtoList, HttpStatus.OK);
|
||||||
|
|||||||
@@ -5,18 +5,24 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.nl.modules.common.exception.BadRequestException;
|
import org.nl.modules.common.exception.BadRequestException;
|
||||||
|
import org.nl.modules.wql.util.SpringContextHolder;
|
||||||
import org.nl.sso.system.domain.vo.MenuMetaVo;
|
import org.nl.sso.system.domain.vo.MenuMetaVo;
|
||||||
import org.nl.sso.system.domain.vo.MenuVo;
|
import org.nl.sso.system.domain.vo.MenuVo;
|
||||||
import org.nl.sso.system.service.MenuService;
|
import org.nl.sso.system.service.MenuService;
|
||||||
import org.nl.sso.system.service.dto.MenuDto;
|
import org.nl.sso.system.service.dto.MenuDto;
|
||||||
|
import org.nl.sso.system.service.menushook.event.CE;
|
||||||
|
import org.nl.sso.system.service.menushook.event.DE;
|
||||||
|
import org.nl.sso.system.service.menushook.event.UE;
|
||||||
import org.nl.sso.tools.IdUtil;
|
import org.nl.sso.tools.IdUtil;
|
||||||
import org.nl.sso.tools.SecurityUtils;
|
import org.nl.sso.tools.SecurityUtils;
|
||||||
import org.nl.modules.wql.WQL;
|
import org.nl.modules.wql.WQL;
|
||||||
import org.nl.modules.wql.core.bean.WQLObject;
|
import org.nl.modules.wql.core.bean.WQLObject;
|
||||||
import org.nl.modules.wql.util.WqlUtil;
|
import org.nl.modules.wql.util.WqlUtil;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -34,7 +40,12 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject queryAll(JSONObject param, Pageable page) throws Exception {
|
public JSONObject queryAll(JSONObject param, Pageable page) throws Exception {
|
||||||
JSONObject json = WQL.getWO("QSYS_MENU01").addParam("flag", "1").addParam("system_type",param.getString("system_type")).addParam("pid", param.getString("pid")).pageQuery(WqlUtil.getHttpContext(page), "");
|
param.put("flag", "1");
|
||||||
|
String blutty = param.getString("blurry");
|
||||||
|
if (StringUtils.isNotEmpty(blutty)){
|
||||||
|
param.put("blurry","%"+blutty+"%");
|
||||||
|
}
|
||||||
|
JSONObject json = WQL.getWO("QSYS_MENU01").addParamMap(param).pageQuery(WqlUtil.getHttpContext(page), "");
|
||||||
|
|
||||||
JSONArray content = json.getJSONArray("content");
|
JSONArray content = json.getJSONArray("content");
|
||||||
JSONArray res = new JSONArray();
|
JSONArray res = new JSONArray();
|
||||||
@@ -139,6 +150,7 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
//根节点数据库存为null
|
//根节点数据库存为null
|
||||||
if ("0".equals(form.getString("pid"))) {
|
if ("0".equals(form.getString("pid"))) {
|
||||||
form.remove("pid");
|
form.remove("pid");
|
||||||
|
SpringContextHolder.getApplicationContext().publishEvent(new CE(form));
|
||||||
}
|
}
|
||||||
//外链外联菜单
|
//外链外联菜单
|
||||||
if ("1".equals(form.getString("i_frame"))) {
|
if ("1".equals(form.getString("i_frame"))) {
|
||||||
@@ -191,12 +203,19 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(JSONObject form) {
|
public void update(JSONObject form) {
|
||||||
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
|
||||||
|
|
||||||
MenuDto newMenu = this.menuJsonToMenuDto(form);
|
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
||||||
if (newMenu.getMenu_id().equals(newMenu.getPid())) {
|
if (form.getString("menu_id").equals(form.getString("pid"))) {
|
||||||
throw new BadRequestException("上级不能为自己");
|
throw new BadRequestException("上级不能为自己");
|
||||||
}
|
}
|
||||||
|
//根节点数据库存为null
|
||||||
|
if ("0".equals(form.getString("pid"))) {
|
||||||
|
form.put("pid",null);
|
||||||
|
SpringContextHolder.getApplicationContext().publishEvent(new UE(form));
|
||||||
|
}else {
|
||||||
|
SpringContextHolder.getApplicationContext().publishEvent(new DE(Lists.newArrayList(form.getString("menu_id"))));
|
||||||
|
}
|
||||||
|
MenuDto newMenu = this.menuJsonToMenuDto(form);
|
||||||
|
|
||||||
if (newMenu.getI_frame()) {
|
if (newMenu.getI_frame()) {
|
||||||
String http = "http://", https = "https://";
|
String http = "http://", https = "https://";
|
||||||
@@ -204,10 +223,7 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//根节点数据库存为null
|
|
||||||
if ("0".equals(form.getString("pid"))) {
|
|
||||||
form.remove("pid");
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject oldMenuJson = menuTab.query("menu_id = '" + form.getString("menu_id") + "'").uniqueResult(0);
|
JSONObject oldMenuJson = menuTab.query("menu_id = '" + form.getString("menu_id") + "'").uniqueResult(0);
|
||||||
MenuDto oldMenu = this.menuJsonToMenuDto(oldMenuJson);
|
MenuDto oldMenu = this.menuJsonToMenuDto(oldMenuJson);
|
||||||
@@ -242,13 +258,17 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(Set<MenuDto> menuSet) {
|
public void delete(Set<MenuDto> menuSet) {
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
for (MenuDto menu : menuSet) {
|
for (MenuDto menu : menuSet) {
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
|
list.add(menu.getMenu_id());
|
||||||
delCaches(menu.getMenu_id());
|
delCaches(menu.getMenu_id());
|
||||||
// roleService.untiedMenu(menu.getMenu_id());
|
// roleService.untiedMenu(menu.getMenu_id());
|
||||||
WQLObject.getWQLObject("sys_menu").delete("menu_id = '" + menu.getMenu_id() + "'");
|
WQLObject.getWQLObject("sys_menu").delete("menu_id = '" + menu.getMenu_id() + "'");
|
||||||
updateSubCnt(menu.getPid());
|
updateSubCnt(menu.getPid());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
SpringContextHolder.getApplicationContext().publishEvent(new DE(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package org.nl.sso.system.service.menushook;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.nl.modules.wql.core.bean.WQLObject;
|
||||||
|
import org.nl.sso.security.dto.CurrentUser;
|
||||||
|
import org.nl.sso.system.service.dto.MenuDto;
|
||||||
|
import org.nl.sso.system.service.menushook.event.CE;
|
||||||
|
import org.nl.sso.system.service.menushook.event.DE;
|
||||||
|
import org.nl.sso.system.service.menushook.event.SysTypeEvent;
|
||||||
|
import org.nl.sso.system.service.menushook.event.UE;
|
||||||
|
import org.nl.sso.tools.IdUtil;
|
||||||
|
import org.nl.sso.tools.MapOf;
|
||||||
|
import org.nl.sso.tools.SecurityUtils;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author ZZQ
|
||||||
|
* @Date 2022/12/12 9:29 上午
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class SysMenuCUDHook implements ApplicationListener<SysTypeEvent> {
|
||||||
|
private static final String SYNC = "lock";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void onApplicationEvent(SysTypeEvent event) {
|
||||||
|
if (event instanceof CE){
|
||||||
|
JSONObject menu = (JSONObject)event.getSource();
|
||||||
|
synchronized (SYNC){
|
||||||
|
JSONArray arr = WQLObject.getWQLObject("sys_dict").query("code = 'system_type'", "value desc").getResultJSONArray(0);
|
||||||
|
Integer currentType = 0;
|
||||||
|
if (arr.size()>0){
|
||||||
|
currentType = arr.getJSONObject(0).getInteger("value");
|
||||||
|
}
|
||||||
|
HashMap map = MapOf.of("dict_id", IdUtil.getLongId()
|
||||||
|
, "label", menu.get("title")
|
||||||
|
, "value", currentType + 1
|
||||||
|
, "para1", menu.get("menu_id")
|
||||||
|
, "code", "system_type"
|
||||||
|
,"name","所属系统"
|
||||||
|
,"create_id", SecurityUtils.getCurrentUserId()
|
||||||
|
,"create_name",SecurityUtils.getCurrentUsername(), DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||||
|
WQLObject.getWQLObject("sys_dict").insert(map);
|
||||||
|
menu.put("system_type",currentType+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (event instanceof UE){
|
||||||
|
JSONObject menu = (JSONObject)event.getSource();
|
||||||
|
String pid = menu.getString("menu_id");
|
||||||
|
JSONArray arr = WQLObject.getWQLObject("sys_dict").query("code = 'system_type'", "value desc").getResultJSONArray(0);
|
||||||
|
if (!arr.stream().filter(a->pid.equals(((JSONObject)a).getString("para1"))).findAny().isPresent()){
|
||||||
|
JSONObject dict = arr.getJSONObject(0);
|
||||||
|
Integer currentType = dict.getInteger("value");
|
||||||
|
menu.put("system_type",currentType+1);
|
||||||
|
dict.put("dict_id", IdUtil.getLongId());
|
||||||
|
dict.put("label",menu.get("title"));
|
||||||
|
dict.put("value",currentType+1);
|
||||||
|
dict.put("para1",menu.get("menu_id"));
|
||||||
|
WQLObject.getWQLObject("sys_dict").insert(dict);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (event instanceof DE){
|
||||||
|
Collection<String> source = (Collection) event.getSource();
|
||||||
|
String sql = source.stream().collect(Collectors.joining("','"));
|
||||||
|
WQLObject.getWQLObject("sys_dict").
|
||||||
|
delete("code = 'system_type' and para1 in ('"+sql+"')");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.nl.sso.system.service.menushook.event;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author ZZQ
|
||||||
|
* @Date 2022/12/12 9:31 上午
|
||||||
|
*/
|
||||||
|
public class CE extends SysTypeEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@code ApplicationEvent}.
|
||||||
|
*
|
||||||
|
* @param source the object on which the event initially occurred or with
|
||||||
|
* which the event is associated (never {@code null})
|
||||||
|
*/
|
||||||
|
public CE(JSONObject source) {
|
||||||
|
super(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.nl.sso.system.service.menushook.event;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.nl.sso.system.service.dto.MenuDto;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author ZZQ
|
||||||
|
* @Date 2022/12/12 9:31 上午
|
||||||
|
*/
|
||||||
|
public class DE extends SysTypeEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@code ApplicationEvent}.
|
||||||
|
*
|
||||||
|
* @param source the object on which the event initially occurred or with
|
||||||
|
* which the event is associated (never {@code null})
|
||||||
|
*/
|
||||||
|
public DE(Collection<String> source) {
|
||||||
|
super(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.nl.sso.system.service.menushook.event;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author ZZQ
|
||||||
|
* @Date 2022/12/12 9:32 上午
|
||||||
|
*/
|
||||||
|
public class SysTypeEvent extends ApplicationEvent {
|
||||||
|
/**
|
||||||
|
* Create a new {@code ApplicationEvent}.
|
||||||
|
*
|
||||||
|
* @param source the object on which the event initially occurred or with
|
||||||
|
* which the event is associated (never {@code null})
|
||||||
|
*/
|
||||||
|
public SysTypeEvent(Object source) {
|
||||||
|
super(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.nl.sso.system.service.menushook.event;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author ZZQ
|
||||||
|
* @Date 2022/12/12 9:31 上午
|
||||||
|
*/
|
||||||
|
public class UE extends SysTypeEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@code ApplicationEvent}.
|
||||||
|
*
|
||||||
|
* @param source the object on which the event initially occurred or with
|
||||||
|
* which the event is associated (never {@code null})
|
||||||
|
*/
|
||||||
|
public UE(JSONObject source) {
|
||||||
|
super(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -56,11 +56,14 @@
|
|||||||
OPTION 输入.system_type <> ""
|
OPTION 输入.system_type <> ""
|
||||||
system_type = 输入.system_type
|
system_type = 输入.system_type
|
||||||
ENDOPTION
|
ENDOPTION
|
||||||
OPTION 输入.blurry <> ""
|
OPTION 输入.pid <> ""
|
||||||
title like "%" 输入.blurry "%"
|
|
||||||
ENDOPTION
|
|
||||||
OPTION 输入.pid <> ""
|
|
||||||
pid = 输入.pid
|
pid = 输入.pid
|
||||||
|
ENDOPTION
|
||||||
|
OPTION 输入.pid = ""
|
||||||
|
pid is null
|
||||||
|
ENDOPTION
|
||||||
|
OPTION 输入.blurry <> ""
|
||||||
|
title like 输入.blurry
|
||||||
ENDOPTION
|
ENDOPTION
|
||||||
ENDSELECT
|
ENDSELECT
|
||||||
ENDPAGEQUERY
|
ENDPAGEQUERY
|
||||||
|
|||||||
Reference in New Issue
Block a user