main
HuangHai 10 months ago
parent d49b9c2aa3
commit 2af137ae02

@ -5,14 +5,29 @@
</component>
<component name="ChangeListManager">
<list default="true" id="8a61ce26-c938-4ad4-aa09-565c63cde7d7" name="更改" comment="">
<change afterPath="$PROJECT_DIR$/dsRes/src/main/java/com/dsideal/resource/Test/testDb.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/dsRes/src/main/resource/Sql/test.sql" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dsBase/src/main/java/com/dsideal/base/LoginPerson/Controller/LoginPersonController.java" beforeDir="false" afterPath="$PROJECT_DIR$/dsBase/src/main/java/com/dsideal/base/LoginPerson/Controller/LoginPersonController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dsBase/src/main/java/com/dsideal/base/Menu/Controller/MenuController.java" beforeDir="false" afterPath="$PROJECT_DIR$/dsBase/src/main/java/com/dsideal/base/Menu/Controller/MenuController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dsBase/src/main/java/com/dsideal/base/Menu/Model/MenuModel.java" beforeDir="false" afterPath="$PROJECT_DIR$/dsBase/src/main/java/com/dsideal/base/Menu/Model/MenuModel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dsRes/src/main/java/com/dsideal/resource/Menu/Controller/MenuController.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/dsRes/src/main/java/com/dsideal/resource/Menu/Model/MenuModel.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/dsRes/src/main/java/com/dsideal/resource/ResApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/dsRes/src/main/java/com/dsideal/resource/ResApplication.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dsRes/src/main/java/com/dsideal/resource/Util/JwtUtil.java" beforeDir="false" afterPath="$PROJECT_DIR$/dsRes/src/main/java/com/dsideal/resource/Util/JwtUtil.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dsRes/src/main/resource/Sql/1.txt" beforeDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
@ -43,6 +58,7 @@
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "main",
"kotlin-language-version-configured": "true",
"last_opened_file_path": "D:/dsWork/dsProject/dsRes/src/main/resource/Sql",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
@ -56,10 +72,16 @@
"应用程序.BaseApplication.executor": "Debug",
"应用程序.GwApplication.executor": "Debug",
"应用程序.Publish.executor": "Run",
"应用程序.ResApplication.executor": "Debug"
"应用程序.ResApplication.executor": "Debug",
"应用程序.TestMenu.executor": "Run"
}
}]]></component>
<component name="RunManager" selected="应用程序.Publish">
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\dsWork\dsProject\dsRes\src\main\resource\Sql" />
</key>
</component>
<component name="RunManager" selected="应用程序.testDb">
<configuration name="BaseApplication" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.dsideal.base.BaseApplication" />
<module name="dsBase" />
@ -106,10 +128,24 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="testDb" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.dsideal.resource.Test.testDb" />
<module name="dsRes" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.dsideal.resource.Test.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="应用程序.Publish" />
<item itemvalue="应用程序.testDb" />
<item itemvalue="应用程序.BaseApplication" />
<item itemvalue="应用程序.Publish" />
<item itemvalue="应用程序.ResApplication" />
<item itemvalue="应用程序.GwApplication" />
</list>

@ -1,10 +1,13 @@
package com.dsideal.base.Menu.Controller;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.dsideal.base.Base.Model.BaseModel;
import com.dsideal.base.Interceptor.*;
import com.dsideal.base.Util.CommonUtil;
import com.dsideal.base.Menu.Model.MenuModel;
import com.dsideal.base.Util.JwtUtil;
import com.dsideal.base.Util.RetKit;
import com.dsideal.base.fay.tree.domain.MenuBean;
import com.dsideal.base.fay.tree.service.IFayTreeNode;
import com.dsideal.base.fay.tree.util.FayTreeUtil;
@ -15,10 +18,9 @@ import com.jfinal.ext.interceptor.POST;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import io.jsonwebtoken.Claims;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
@SuppressWarnings("unchecked")
public class MenuController extends Controller {
@ -153,8 +155,8 @@ public class MenuController extends Controller {
@EmptyInterface({"menu_name", "url", "memo", "identity_ids"})
@IsNumericInterface({"parent_id", "sort_id", "for_school", "for_bureau"})
@LengthInterface({"menu_name,1,32", "memo,1,255"})
public void AddMenu(int parent_id, int sort_id, String identity_ids, String menu_name, String url, String memo, int for_school, int for_bureau,String icon,int isFull) {
int menu_id = model.AddMenu(parent_id, sort_id, menu_name, url, memo, identity_ids, for_school, for_bureau,icon,isFull);
public void AddMenu(int parent_id, int sort_id, String identity_ids, String menu_name, String url, String memo, int for_school, int for_bureau, String icon, int isFull) {
int menu_id = model.AddMenu(parent_id, sort_id, menu_name, url, memo, identity_ids, for_school, for_bureau, icon, isFull);
JSONObject map = new JSONObject();
map.put("menu_id", menu_id);
if (menu_id > 0) {
@ -191,8 +193,8 @@ public class MenuController extends Controller {
@IsNumericInterface({"menu_id", "sort_id", "for_school", "for_bureau"})
@LengthInterface({"menu_name,1,32", "memo,1,255"})
public void UpdateMenu(int menu_id, int sort_id, String menu_name, String identity_ids, String url, String memo,
int for_school, int for_bureau,String icon,int isFull) {
model.UpdateMenu(menu_id, menu_name, sort_id, url, memo, identity_ids, for_school, for_bureau,icon,isFull);
int for_school, int for_bureau, String icon, int isFull) {
model.UpdateMenu(menu_id, menu_name, sort_id, url, memo, identity_ids, for_school, for_bureau, icon, isFull);
renderJson(CommonUtil.returnMessageJson(true, "修改成功!"));
}
@ -229,4 +231,30 @@ public class MenuController extends Controller {
Kv kv = Kv.by("success", true).set("list", list);
renderJson(kv);
}
/**
*
*/
@Before({GET.class})
public void getPersonMenu() {
//当前登录的人员是谁?
String token = getRequest().getHeader("Authorization");
if (token == null) {
renderJson(RetKit.renderFail("请先登录!"));
return;
}
Claims claims = JwtUtil.getClaims(token);
String person_id = claims.get("person_id").toString();
//可见菜单
List<Record> recordList = model.selectMenuByPersonId(person_id);
Set<Integer> menuIdSet = new HashSet<>();
for (Record record : recordList) {
menuIdSet.add(record.getInt("menu_id"));
}
//需要根据所有可见菜单,递归处理,生成树形菜单
List<MenuModel.Menu> menuList = model.fetchMenu(1, menuIdSet);
renderJson(RetKit.renderSuccess(JSONUtil.parseArray(menuList)));
}
}

@ -7,11 +7,10 @@ import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@SuppressWarnings("unchecked")
public class MenuModel {
@ -319,4 +318,80 @@ public class MenuModel {
list = Db.find(sqlPara);
return list;
}
//子类1菜单
@Getter
@Setter
public static class Menu {
private String path;
private String component;
private Meta meta;
private List<Menu> children = new ArrayList<>();
}
//子类2:LinkMeta
@Getter
@Setter
public static class Meta {
private String icon;
private String title;
private String isLink;
private boolean isHide;
private boolean isFull;
private boolean isAffix;
private String name;
private boolean isKeepAlive;
}
/**
*
*
* @param parent_id ID
* @return
*/
public List<Menu> fetchMenu(int parent_id, Set<Integer> menuIdSet) {
String sql = "select * from t_base_menu where parent_id = ? order by sort_id";
List<Record> list = Db.find(sql, parent_id);
List<Menu> res = new ArrayList<>();
for (Record rs : list) {
if (rs == null) return null;
int menu_id = rs.getInt("menu_id");
if (!menuIdSet.contains(menu_id)) {
return null;
}
Menu sMenu = new Menu();
String url = rs.getStr("url");
sMenu.setPath(url);
sMenu.setComponent(url);
Meta meta = new Meta();
meta.setIcon(rs.getStr("icon"));
meta.setTitle(rs.getStr("menu_name"));
meta.setIsLink("");
meta.setHide(false);
meta.setName(rs.getStr("menu_name"));
meta.setAffix(false);
if (rs.getStr("menu_name").equals("首页")) {
meta.setAffix(true);
}
if (rs.get("is_full") == null || rs.getInt("is_full") == 0) {
meta.setFull(false);
} else {
meta.setFull(true);
}
meta.setKeepAlive(true);
sMenu.setMeta(meta);
// 递归查找子菜单
List<Menu> childMenu = fetchMenu(rs.getInt("menu_id"), menuIdSet);
sMenu.setChildren(childMenu);
res.add(sMenu);
}
return res;
}
}

@ -1,39 +0,0 @@
package com.dsideal.resource.Menu.Controller;
import cn.hutool.json.JSONUtil;
import com.dsideal.resource.Menu.Model.MenuModel;
import com.dsideal.resource.Util.CommonUtil;
import com.dsideal.resource.Util.JwtUtil;
import com.dsideal.resource.Util.RetKit;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.ext.interceptor.GET;
import io.jsonwebtoken.Claims;
import java.util.List;
public class MenuController extends Controller {
MenuModel mm = new MenuModel();
/**
*
*/
@Before({GET.class})
public void getPersonMenu() {
//当前登录的人员是谁?
String token = getRequest().getHeader("Authorization");
if (token == null) {
renderJson(RetKit.renderFail("JWT token 为空,无法解析人员信息,请重新登录!"));
return;
}
Claims claims = JwtUtil.getClaims(token);
int identity_id = Integer.parseInt(claims.get("identity_id").toString());
String person_id = claims.get("person_id").toString();
//所有菜单
List<MenuModel.Menu> menuList = mm.fetchMenu(160);
renderJson(RetKit.renderSuccess(JSONUtil.parseArray(menuList)));
//后续需要根据人员角色菜单关系,去掉不可见菜单
}
}

@ -1,80 +0,0 @@
package com.dsideal.resource.Menu.Model;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
public class MenuModel {
//子类1菜单
@Getter
@Setter
public static class Menu {
private String path;
private String component;
private Meta meta;
private List<Menu> children = new ArrayList<>();
}
//子类2:LinkMeta
@Getter
@Setter
public static class Meta {
private String icon;
private String title;
private String isLink;
private boolean isHide;
private boolean isFull;
private boolean isAffix;
private String name;
private boolean isKeepAlive;
}
/**
*
*
* @param parent_id ID
* @return
*/
public List<Menu> fetchMenu(int parent_id) {
String sql = "select * from t_base_menu where parent_id = ? order by sort_id";
List<Record> list = Db.find(sql, parent_id);
List<Menu> res = new ArrayList<>();
for (Record rs : list) {
if (rs == null) return null;
Menu sMenu = new Menu();
String url = rs.getStr("url");
sMenu.setPath(url);
sMenu.setComponent(url);
Meta meta = new Meta();
meta.setIcon(rs.getStr("icon"));
meta.setTitle(rs.getStr("menu_name"));
meta.setIsLink("");
meta.setHide(false);
meta.setName(rs.getStr("menu_name"));
meta.setAffix(false);
if (rs.getStr("menu_name").equals("首页")) {
meta.setAffix(true);
}
if (rs.get("is_full") == null || rs.getInt("is_full") == 0) {
meta.setFull(false);
} else {
meta.setFull(true);
}
meta.setKeepAlive(true);
sMenu.setMeta(meta);
// 递归查找子菜单
List<Menu> childMenu = fetchMenu(rs.getInt("menu_id"));
sMenu.setChildren(childMenu);
res.add(sMenu);
}
return res;
}
}

@ -3,7 +3,6 @@ package com.dsideal.resource;
import com.dsideal.resource.Base.Controller.BaseController;
import com.dsideal.resource.Index.IndexController;
import com.dsideal.resource.Interceptor.*;
import com.dsideal.resource.Menu.Controller.MenuController;
import com.dsideal.resource.Plugin.YamlProp;
import com.dsideal.resource.Util.FileUtil;
import com.dsideal.resource.Util.LogBackLogFactory;
@ -59,8 +58,6 @@ public class ResApplication extends JFinalConfig {
public void configRoute(Routes me) {
//默认页面
me.add("/", IndexController.class);
//菜单
me.add("/menu", MenuController.class);
//资源基础管理
me.add("/base", BaseController.class);
}

@ -0,0 +1,40 @@
package com.dsideal.resource.Test;
import com.dsideal.resource.Plugin.YamlProp;
import com.dsideal.resource.ResApplication;
import com.jfinal.kit.Prop;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
import java.io.File;
public class testDb {
public static void main(String[] args) {
//加载配置文件
String configFile = "application_dev.yaml";
Prop PropKit = new YamlProp(configFile);
HikariCpPlugin masterPlugin = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
masterPlugin.start();
// 配置ActiveRecord插件
ActiveRecordPlugin masterArp = new ActiveRecordPlugin("master", masterPlugin);
masterArp.setDialect(new MysqlDialect());
//遍历sql目录下所有的sql文件
File sqlDir;
String basePath = ResApplication.class.getResource("/").getPath();
sqlDir = new File(basePath + "/Sql");
File[] sqlFiles = sqlDir.listFiles();
for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
//只加载.sql文件
if (sqlFile.getName().indexOf(".sql") > 0) {
masterArp.addSqlTemplate("/Sql/" + sqlFile.getName());
}
}
masterArp.start();
}
}

@ -1,6 +1,5 @@
package com.dsideal.resource.Util;
import cn.hutool.core.date.DateTime;
import com.dsideal.resource.ResApplication;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

@ -0,0 +1,21 @@
-- 菜单命名空间
#namespace("menu")
-- 查询菜单的ids
#sql("selectMenuForIds")
select t1.menu_id,t1.menu_name,t1.parent_id,t1.sort_id,t1.url,t1.memo,t1.create_time,t1.update_ts,t1.level_id,
(select count(1) from t_base_menu as t2 where t1.menu_id=t2.parent_id) as is_leaf
from t_base_menu as t1 where t1.menu_id in
(
#for(x:ids)
#(for.index == 0 ? "" : ",") #para(x)
#end
) order by t1.sort_id
#end
-- 人员根据职务+分管工作可见的菜单
#sql("selectMenuByPersonId")
select distinct menu_id from t_base_principalship_menu as t1 inner join t_person_duty_charge as t2 on t1.duties_id=t2.`duties_id`
and t1.in_charge_id=t2.`in_charge_id` where t2.person_id=? and t2.b_use=1
#end
#end
Loading…
Cancel
Save