From e14b44858dc12b21dfb5578145a7b1a2488898b2 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 14 Jun 2021 18:12:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=88=9D=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/bean/constant/ResType.java | 104 +++ .../controller/bean/models/SysResource.java | 227 +++++- .../bean/models/SysResourceExample.java | 660 +++++++++++++++++- .../controller/dao/SysResourceMapper.java | 24 +- .../controller/service/ContextInit.java | 17 +- .../controller/service/cas/IMenuService.java | 54 ++ .../service/cas/impl/MenuService.java | 145 ++++ .../duckula/ops/pages/cas/ResManager.java | 317 +++++++++ .../primary/sqlmap/SysResourceMapper.xml | 141 +++- .../ops/pages/cas/ResManager.properties | 1 + .../tams/duckula/ops/pages/cas/ResManager.tml | 401 +++++++++++ 11 files changed, 2061 insertions(+), 30 deletions(-) create mode 100644 src/main/java/net/wicp/tams/app/duckula/controller/bean/constant/ResType.java create mode 100644 src/main/java/net/wicp/tams/app/duckula/controller/service/cas/IMenuService.java create mode 100644 src/main/java/net/wicp/tams/app/duckula/controller/service/cas/impl/MenuService.java create mode 100644 src/main/java/net/wicp/tams/duckula/ops/pages/cas/ResManager.java create mode 100644 src/main/resources/net/wicp/tams/duckula/ops/pages/cas/ResManager.properties create mode 100644 src/main/resources/net/wicp/tams/duckula/ops/pages/cas/ResManager.tml diff --git a/src/main/java/net/wicp/tams/app/duckula/controller/bean/constant/ResType.java b/src/main/java/net/wicp/tams/app/duckula/controller/bean/constant/ResType.java new file mode 100644 index 0000000..d2f0a94 --- /dev/null +++ b/src/main/java/net/wicp/tams/app/duckula/controller/bean/constant/ResType.java @@ -0,0 +1,104 @@ +package net.wicp.tams.app.duckula.controller.bean.constant; + +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; + +import net.wicp.tams.common.constant.dic.intf.IEnumCombobox; + +/*** + * 组织单位类型 + * + * @author Administrator + * + */ +public enum ResType implements IEnumCombobox { + OPERATE("操作资源", "icon-position", null, false, null), + + DATA("数据资源", "icon-group", null, false, null), + + MODULE("模块", "icon-dept", OPERATE, false, null), + + DIR("目录", "icon-org", OPERATE, true, new ResType[] { MODULE }), + + URL("地址", "icon-dept", OPERATE, true, new ResType[] { MODULE, DIR }); + + private final String desc; + private final String icon; + + private final ResType parent;// 资源的父类型 + + private final boolean isEdit;// 所定义的类型能否被修改,true,可以被修改,false:不能被修改 + + private final ResType[] parentTree;// 资源可以放在哪个类型的资源下面,如URL只能放在DIR目录下。 + + private ResType(String desc, String icon, ResType parent, boolean isEdit, ResType[] parentTree) { + this.desc = desc; + this.parent = parent; + this.icon = icon; + this.isEdit = isEdit; + this.parentTree = parentTree; + } + + /*** + * 当前类型的资源能否被拖拽到另一资源类型下面 + * + * @param parent 要拖拽的目标资源类型 + * @return + */ + public boolean canDrag(ResType parent) { + if (ArrayUtils.isEmpty(parentTree)) { + return false; + } + return ArrayUtils.contains(this.parentTree, parent); + } + + /**** + * 通过名字返回类型,默认返回 ORG + * + * @param name + * @return + */ + public static ResType findByName(String name) { + if (StringUtils.isEmpty(name)) { + return URL; + } + for (ResType ele : ResType.values()) { + if (ele.name().equals(name)) { + return ele; + } + } + return URL; + } + + public String getDesc() { + return desc; + } + + public String getIcon() { + return icon; + } + + @Override + public String getName() { + return this.name(); + } + + @Override + public String getDesc_en() { + return this.desc; + } + + @Override + public String getDesc_zh() { + return this.desc; + } + + public ResType getParent() { + return parent; + } + + public boolean isEdit() { + return isEdit; + } + +} diff --git a/src/main/java/net/wicp/tams/app/duckula/controller/bean/models/SysResource.java b/src/main/java/net/wicp/tams/app/duckula/controller/bean/models/SysResource.java index 22cb478..8210c97 100644 --- a/src/main/java/net/wicp/tams/app/duckula/controller/bean/models/SysResource.java +++ b/src/main/java/net/wicp/tams/app/duckula/controller/bean/models/SysResource.java @@ -31,7 +31,7 @@ public class SysResource { * This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.res_type * @mbg.generated */ - private Integer resType; + private String resType; /** * This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.icon * @mbg.generated @@ -62,13 +62,59 @@ public class SysResource { * @mbg.generated */ private String remark; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound1 + * @mbg.generated + */ + private String bound1; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound2 + * @mbg.generated + */ + private String bound2; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound3 + * @mbg.generated + */ + private String bound3; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound4 + * @mbg.generated + */ + private String bound4; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound5 + * @mbg.generated + */ + private String bound5; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound6 + * @mbg.generated + */ + private String bound6; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound7 + * @mbg.generated + */ + private String bound7; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound8 + * @mbg.generated + */ + private String bound8; + /** + * This field was generated by MyBatis Generator. This field corresponds to the database column sys_resource.bound9 + * @mbg.generated + */ + private String bound9; /** * This method was generated by MyBatis Generator. This method corresponds to the database table sys_resource * @mbg.generated */ - public SysResource(Long id, String resCode, String resName, String resValue, Integer resType, String icon, - Integer resLevel, String isEdit, Long parentId, Long showOrder, String remark) { + public SysResource(Long id, String resCode, String resName, String resValue, String resType, String icon, + Integer resLevel, String isEdit, Long parentId, Long showOrder, String remark, String bound1, String bound2, + String bound3, String bound4, String bound5, String bound6, String bound7, String bound8, String bound9) { this.id = id; this.resCode = resCode; this.resName = resName; @@ -80,6 +126,15 @@ public class SysResource { this.parentId = parentId; this.showOrder = showOrder; this.remark = remark; + this.bound1 = bound1; + this.bound2 = bound2; + this.bound3 = bound3; + this.bound4 = bound4; + this.bound5 = bound5; + this.bound6 = bound6; + this.bound7 = bound7; + this.bound8 = bound8; + this.bound9 = bound9; } /** @@ -167,7 +222,7 @@ public class SysResource { * @return the value of sys_resource.res_type * @mbg.generated */ - public Integer getResType() { + public String getResType() { return resType; } @@ -176,7 +231,7 @@ public class SysResource { * @param resType the value for sys_resource.res_type * @mbg.generated */ - public void setResType(Integer resType) { + public void setResType(String resType) { this.resType = resType; } @@ -287,4 +342,166 @@ public class SysResource { public void setRemark(String remark) { this.remark = remark; } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound1 + * @return the value of sys_resource.bound1 + * @mbg.generated + */ + public String getBound1() { + return bound1; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound1 + * @param bound1 the value for sys_resource.bound1 + * @mbg.generated + */ + public void setBound1(String bound1) { + this.bound1 = bound1; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound2 + * @return the value of sys_resource.bound2 + * @mbg.generated + */ + public String getBound2() { + return bound2; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound2 + * @param bound2 the value for sys_resource.bound2 + * @mbg.generated + */ + public void setBound2(String bound2) { + this.bound2 = bound2; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound3 + * @return the value of sys_resource.bound3 + * @mbg.generated + */ + public String getBound3() { + return bound3; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound3 + * @param bound3 the value for sys_resource.bound3 + * @mbg.generated + */ + public void setBound3(String bound3) { + this.bound3 = bound3; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound4 + * @return the value of sys_resource.bound4 + * @mbg.generated + */ + public String getBound4() { + return bound4; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound4 + * @param bound4 the value for sys_resource.bound4 + * @mbg.generated + */ + public void setBound4(String bound4) { + this.bound4 = bound4; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound5 + * @return the value of sys_resource.bound5 + * @mbg.generated + */ + public String getBound5() { + return bound5; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound5 + * @param bound5 the value for sys_resource.bound5 + * @mbg.generated + */ + public void setBound5(String bound5) { + this.bound5 = bound5; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound6 + * @return the value of sys_resource.bound6 + * @mbg.generated + */ + public String getBound6() { + return bound6; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound6 + * @param bound6 the value for sys_resource.bound6 + * @mbg.generated + */ + public void setBound6(String bound6) { + this.bound6 = bound6; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound7 + * @return the value of sys_resource.bound7 + * @mbg.generated + */ + public String getBound7() { + return bound7; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound7 + * @param bound7 the value for sys_resource.bound7 + * @mbg.generated + */ + public void setBound7(String bound7) { + this.bound7 = bound7; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound8 + * @return the value of sys_resource.bound8 + * @mbg.generated + */ + public String getBound8() { + return bound8; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound8 + * @param bound8 the value for sys_resource.bound8 + * @mbg.generated + */ + public void setBound8(String bound8) { + this.bound8 = bound8; + } + + /** + * This method was generated by MyBatis Generator. This method returns the value of the database column sys_resource.bound9 + * @return the value of sys_resource.bound9 + * @mbg.generated + */ + public String getBound9() { + return bound9; + } + + /** + * This method was generated by MyBatis Generator. This method sets the value of the database column sys_resource.bound9 + * @param bound9 the value for sys_resource.bound9 + * @mbg.generated + */ + public void setBound9(String bound9) { + this.bound9 = bound9; + } } \ No newline at end of file diff --git a/src/main/java/net/wicp/tams/app/duckula/controller/bean/models/SysResourceExample.java b/src/main/java/net/wicp/tams/app/duckula/controller/bean/models/SysResourceExample.java index 202a1e7..c1d0b74 100644 --- a/src/main/java/net/wicp/tams/app/duckula/controller/bean/models/SysResourceExample.java +++ b/src/main/java/net/wicp/tams/app/duckula/controller/bean/models/SysResourceExample.java @@ -442,52 +442,62 @@ public class SysResourceExample { return (Criteria) this; } - public Criteria andResTypeEqualTo(Integer value) { + public Criteria andResTypeEqualTo(String value) { addCriterion("res_type =", value, "resType"); return (Criteria) this; } - public Criteria andResTypeNotEqualTo(Integer value) { + public Criteria andResTypeNotEqualTo(String value) { addCriterion("res_type <>", value, "resType"); return (Criteria) this; } - public Criteria andResTypeGreaterThan(Integer value) { + public Criteria andResTypeGreaterThan(String value) { addCriterion("res_type >", value, "resType"); return (Criteria) this; } - public Criteria andResTypeGreaterThanOrEqualTo(Integer value) { + public Criteria andResTypeGreaterThanOrEqualTo(String value) { addCriterion("res_type >=", value, "resType"); return (Criteria) this; } - public Criteria andResTypeLessThan(Integer value) { + public Criteria andResTypeLessThan(String value) { addCriterion("res_type <", value, "resType"); return (Criteria) this; } - public Criteria andResTypeLessThanOrEqualTo(Integer value) { + public Criteria andResTypeLessThanOrEqualTo(String value) { addCriterion("res_type <=", value, "resType"); return (Criteria) this; } - public Criteria andResTypeIn(List values) { + public Criteria andResTypeLike(String value) { + addCriterion("res_type like", value, "resType"); + return (Criteria) this; + } + + public Criteria andResTypeNotLike(String value) { + addCriterion("res_type not like", value, "resType"); + return (Criteria) this; + } + + public Criteria andResTypeIn(List values) { addCriterion("res_type in", values, "resType"); return (Criteria) this; } - public Criteria andResTypeNotIn(List values) { + public Criteria andResTypeNotIn(List values) { addCriterion("res_type not in", values, "resType"); return (Criteria) this; } - public Criteria andResTypeBetween(Integer value1, Integer value2) { + public Criteria andResTypeBetween(String value1, String value2) { addCriterion("res_type between", value1, value2, "resType"); return (Criteria) this; } - public Criteria andResTypeNotBetween(Integer value1, Integer value2) { + public Criteria andResTypeNotBetween(String value1, String value2) { addCriterion("res_type not between", value1, value2, "resType"); return (Criteria) this; } @@ -881,6 +891,636 @@ public class SysResourceExample { addCriterion("remark not between", value1, value2, "remark"); return (Criteria) this; } + + public Criteria andBound1IsNull() { + addCriterion("bound1 is null"); + return (Criteria) this; + } + + public Criteria andBound1IsNotNull() { + addCriterion("bound1 is not null"); + return (Criteria) this; + } + + public Criteria andBound1EqualTo(String value) { + addCriterion("bound1 =", value, "bound1"); + return (Criteria) this; + } + + public Criteria andBound1NotEqualTo(String value) { + addCriterion("bound1 <>", value, "bound1"); + return (Criteria) this; + } + + public Criteria andBound1GreaterThan(String value) { + addCriterion("bound1 >", value, "bound1"); + return (Criteria) this; + } + + public Criteria andBound1GreaterThanOrEqualTo(String value) { + addCriterion("bound1 >=", value, "bound1"); + return (Criteria) this; + } + + public Criteria andBound1LessThan(String value) { + addCriterion("bound1 <", value, "bound1"); + return (Criteria) this; + } + + public Criteria andBound1LessThanOrEqualTo(String value) { + addCriterion("bound1 <=", value, "bound1"); + return (Criteria) this; + } + + public Criteria andBound1Like(String value) { + addCriterion("bound1 like", value, "bound1"); + return (Criteria) this; + } + + public Criteria andBound1NotLike(String value) { + addCriterion("bound1 not like", value, "bound1"); + return (Criteria) this; + } + + public Criteria andBound1In(List values) { + addCriterion("bound1 in", values, "bound1"); + return (Criteria) this; + } + + public Criteria andBound1NotIn(List values) { + addCriterion("bound1 not in", values, "bound1"); + return (Criteria) this; + } + + public Criteria andBound1Between(String value1, String value2) { + addCriterion("bound1 between", value1, value2, "bound1"); + return (Criteria) this; + } + + public Criteria andBound1NotBetween(String value1, String value2) { + addCriterion("bound1 not between", value1, value2, "bound1"); + return (Criteria) this; + } + + public Criteria andBound2IsNull() { + addCriterion("bound2 is null"); + return (Criteria) this; + } + + public Criteria andBound2IsNotNull() { + addCriterion("bound2 is not null"); + return (Criteria) this; + } + + public Criteria andBound2EqualTo(String value) { + addCriterion("bound2 =", value, "bound2"); + return (Criteria) this; + } + + public Criteria andBound2NotEqualTo(String value) { + addCriterion("bound2 <>", value, "bound2"); + return (Criteria) this; + } + + public Criteria andBound2GreaterThan(String value) { + addCriterion("bound2 >", value, "bound2"); + return (Criteria) this; + } + + public Criteria andBound2GreaterThanOrEqualTo(String value) { + addCriterion("bound2 >=", value, "bound2"); + return (Criteria) this; + } + + public Criteria andBound2LessThan(String value) { + addCriterion("bound2 <", value, "bound2"); + return (Criteria) this; + } + + public Criteria andBound2LessThanOrEqualTo(String value) { + addCriterion("bound2 <=", value, "bound2"); + return (Criteria) this; + } + + public Criteria andBound2Like(String value) { + addCriterion("bound2 like", value, "bound2"); + return (Criteria) this; + } + + public Criteria andBound2NotLike(String value) { + addCriterion("bound2 not like", value, "bound2"); + return (Criteria) this; + } + + public Criteria andBound2In(List values) { + addCriterion("bound2 in", values, "bound2"); + return (Criteria) this; + } + + public Criteria andBound2NotIn(List values) { + addCriterion("bound2 not in", values, "bound2"); + return (Criteria) this; + } + + public Criteria andBound2Between(String value1, String value2) { + addCriterion("bound2 between", value1, value2, "bound2"); + return (Criteria) this; + } + + public Criteria andBound2NotBetween(String value1, String value2) { + addCriterion("bound2 not between", value1, value2, "bound2"); + return (Criteria) this; + } + + public Criteria andBound3IsNull() { + addCriterion("bound3 is null"); + return (Criteria) this; + } + + public Criteria andBound3IsNotNull() { + addCriterion("bound3 is not null"); + return (Criteria) this; + } + + public Criteria andBound3EqualTo(String value) { + addCriterion("bound3 =", value, "bound3"); + return (Criteria) this; + } + + public Criteria andBound3NotEqualTo(String value) { + addCriterion("bound3 <>", value, "bound3"); + return (Criteria) this; + } + + public Criteria andBound3GreaterThan(String value) { + addCriterion("bound3 >", value, "bound3"); + return (Criteria) this; + } + + public Criteria andBound3GreaterThanOrEqualTo(String value) { + addCriterion("bound3 >=", value, "bound3"); + return (Criteria) this; + } + + public Criteria andBound3LessThan(String value) { + addCriterion("bound3 <", value, "bound3"); + return (Criteria) this; + } + + public Criteria andBound3LessThanOrEqualTo(String value) { + addCriterion("bound3 <=", value, "bound3"); + return (Criteria) this; + } + + public Criteria andBound3Like(String value) { + addCriterion("bound3 like", value, "bound3"); + return (Criteria) this; + } + + public Criteria andBound3NotLike(String value) { + addCriterion("bound3 not like", value, "bound3"); + return (Criteria) this; + } + + public Criteria andBound3In(List values) { + addCriterion("bound3 in", values, "bound3"); + return (Criteria) this; + } + + public Criteria andBound3NotIn(List values) { + addCriterion("bound3 not in", values, "bound3"); + return (Criteria) this; + } + + public Criteria andBound3Between(String value1, String value2) { + addCriterion("bound3 between", value1, value2, "bound3"); + return (Criteria) this; + } + + public Criteria andBound3NotBetween(String value1, String value2) { + addCriterion("bound3 not between", value1, value2, "bound3"); + return (Criteria) this; + } + + public Criteria andBound4IsNull() { + addCriterion("bound4 is null"); + return (Criteria) this; + } + + public Criteria andBound4IsNotNull() { + addCriterion("bound4 is not null"); + return (Criteria) this; + } + + public Criteria andBound4EqualTo(String value) { + addCriterion("bound4 =", value, "bound4"); + return (Criteria) this; + } + + public Criteria andBound4NotEqualTo(String value) { + addCriterion("bound4 <>", value, "bound4"); + return (Criteria) this; + } + + public Criteria andBound4GreaterThan(String value) { + addCriterion("bound4 >", value, "bound4"); + return (Criteria) this; + } + + public Criteria andBound4GreaterThanOrEqualTo(String value) { + addCriterion("bound4 >=", value, "bound4"); + return (Criteria) this; + } + + public Criteria andBound4LessThan(String value) { + addCriterion("bound4 <", value, "bound4"); + return (Criteria) this; + } + + public Criteria andBound4LessThanOrEqualTo(String value) { + addCriterion("bound4 <=", value, "bound4"); + return (Criteria) this; + } + + public Criteria andBound4Like(String value) { + addCriterion("bound4 like", value, "bound4"); + return (Criteria) this; + } + + public Criteria andBound4NotLike(String value) { + addCriterion("bound4 not like", value, "bound4"); + return (Criteria) this; + } + + public Criteria andBound4In(List values) { + addCriterion("bound4 in", values, "bound4"); + return (Criteria) this; + } + + public Criteria andBound4NotIn(List values) { + addCriterion("bound4 not in", values, "bound4"); + return (Criteria) this; + } + + public Criteria andBound4Between(String value1, String value2) { + addCriterion("bound4 between", value1, value2, "bound4"); + return (Criteria) this; + } + + public Criteria andBound4NotBetween(String value1, String value2) { + addCriterion("bound4 not between", value1, value2, "bound4"); + return (Criteria) this; + } + + public Criteria andBound5IsNull() { + addCriterion("bound5 is null"); + return (Criteria) this; + } + + public Criteria andBound5IsNotNull() { + addCriterion("bound5 is not null"); + return (Criteria) this; + } + + public Criteria andBound5EqualTo(String value) { + addCriterion("bound5 =", value, "bound5"); + return (Criteria) this; + } + + public Criteria andBound5NotEqualTo(String value) { + addCriterion("bound5 <>", value, "bound5"); + return (Criteria) this; + } + + public Criteria andBound5GreaterThan(String value) { + addCriterion("bound5 >", value, "bound5"); + return (Criteria) this; + } + + public Criteria andBound5GreaterThanOrEqualTo(String value) { + addCriterion("bound5 >=", value, "bound5"); + return (Criteria) this; + } + + public Criteria andBound5LessThan(String value) { + addCriterion("bound5 <", value, "bound5"); + return (Criteria) this; + } + + public Criteria andBound5LessThanOrEqualTo(String value) { + addCriterion("bound5 <=", value, "bound5"); + return (Criteria) this; + } + + public Criteria andBound5Like(String value) { + addCriterion("bound5 like", value, "bound5"); + return (Criteria) this; + } + + public Criteria andBound5NotLike(String value) { + addCriterion("bound5 not like", value, "bound5"); + return (Criteria) this; + } + + public Criteria andBound5In(List values) { + addCriterion("bound5 in", values, "bound5"); + return (Criteria) this; + } + + public Criteria andBound5NotIn(List values) { + addCriterion("bound5 not in", values, "bound5"); + return (Criteria) this; + } + + public Criteria andBound5Between(String value1, String value2) { + addCriterion("bound5 between", value1, value2, "bound5"); + return (Criteria) this; + } + + public Criteria andBound5NotBetween(String value1, String value2) { + addCriterion("bound5 not between", value1, value2, "bound5"); + return (Criteria) this; + } + + public Criteria andBound6IsNull() { + addCriterion("bound6 is null"); + return (Criteria) this; + } + + public Criteria andBound6IsNotNull() { + addCriterion("bound6 is not null"); + return (Criteria) this; + } + + public Criteria andBound6EqualTo(String value) { + addCriterion("bound6 =", value, "bound6"); + return (Criteria) this; + } + + public Criteria andBound6NotEqualTo(String value) { + addCriterion("bound6 <>", value, "bound6"); + return (Criteria) this; + } + + public Criteria andBound6GreaterThan(String value) { + addCriterion("bound6 >", value, "bound6"); + return (Criteria) this; + } + + public Criteria andBound6GreaterThanOrEqualTo(String value) { + addCriterion("bound6 >=", value, "bound6"); + return (Criteria) this; + } + + public Criteria andBound6LessThan(String value) { + addCriterion("bound6 <", value, "bound6"); + return (Criteria) this; + } + + public Criteria andBound6LessThanOrEqualTo(String value) { + addCriterion("bound6 <=", value, "bound6"); + return (Criteria) this; + } + + public Criteria andBound6Like(String value) { + addCriterion("bound6 like", value, "bound6"); + return (Criteria) this; + } + + public Criteria andBound6NotLike(String value) { + addCriterion("bound6 not like", value, "bound6"); + return (Criteria) this; + } + + public Criteria andBound6In(List values) { + addCriterion("bound6 in", values, "bound6"); + return (Criteria) this; + } + + public Criteria andBound6NotIn(List values) { + addCriterion("bound6 not in", values, "bound6"); + return (Criteria) this; + } + + public Criteria andBound6Between(String value1, String value2) { + addCriterion("bound6 between", value1, value2, "bound6"); + return (Criteria) this; + } + + public Criteria andBound6NotBetween(String value1, String value2) { + addCriterion("bound6 not between", value1, value2, "bound6"); + return (Criteria) this; + } + + public Criteria andBound7IsNull() { + addCriterion("bound7 is null"); + return (Criteria) this; + } + + public Criteria andBound7IsNotNull() { + addCriterion("bound7 is not null"); + return (Criteria) this; + } + + public Criteria andBound7EqualTo(String value) { + addCriterion("bound7 =", value, "bound7"); + return (Criteria) this; + } + + public Criteria andBound7NotEqualTo(String value) { + addCriterion("bound7 <>", value, "bound7"); + return (Criteria) this; + } + + public Criteria andBound7GreaterThan(String value) { + addCriterion("bound7 >", value, "bound7"); + return (Criteria) this; + } + + public Criteria andBound7GreaterThanOrEqualTo(String value) { + addCriterion("bound7 >=", value, "bound7"); + return (Criteria) this; + } + + public Criteria andBound7LessThan(String value) { + addCriterion("bound7 <", value, "bound7"); + return (Criteria) this; + } + + public Criteria andBound7LessThanOrEqualTo(String value) { + addCriterion("bound7 <=", value, "bound7"); + return (Criteria) this; + } + + public Criteria andBound7Like(String value) { + addCriterion("bound7 like", value, "bound7"); + return (Criteria) this; + } + + public Criteria andBound7NotLike(String value) { + addCriterion("bound7 not like", value, "bound7"); + return (Criteria) this; + } + + public Criteria andBound7In(List values) { + addCriterion("bound7 in", values, "bound7"); + return (Criteria) this; + } + + public Criteria andBound7NotIn(List values) { + addCriterion("bound7 not in", values, "bound7"); + return (Criteria) this; + } + + public Criteria andBound7Between(String value1, String value2) { + addCriterion("bound7 between", value1, value2, "bound7"); + return (Criteria) this; + } + + public Criteria andBound7NotBetween(String value1, String value2) { + addCriterion("bound7 not between", value1, value2, "bound7"); + return (Criteria) this; + } + + public Criteria andBound8IsNull() { + addCriterion("bound8 is null"); + return (Criteria) this; + } + + public Criteria andBound8IsNotNull() { + addCriterion("bound8 is not null"); + return (Criteria) this; + } + + public Criteria andBound8EqualTo(String value) { + addCriterion("bound8 =", value, "bound8"); + return (Criteria) this; + } + + public Criteria andBound8NotEqualTo(String value) { + addCriterion("bound8 <>", value, "bound8"); + return (Criteria) this; + } + + public Criteria andBound8GreaterThan(String value) { + addCriterion("bound8 >", value, "bound8"); + return (Criteria) this; + } + + public Criteria andBound8GreaterThanOrEqualTo(String value) { + addCriterion("bound8 >=", value, "bound8"); + return (Criteria) this; + } + + public Criteria andBound8LessThan(String value) { + addCriterion("bound8 <", value, "bound8"); + return (Criteria) this; + } + + public Criteria andBound8LessThanOrEqualTo(String value) { + addCriterion("bound8 <=", value, "bound8"); + return (Criteria) this; + } + + public Criteria andBound8Like(String value) { + addCriterion("bound8 like", value, "bound8"); + return (Criteria) this; + } + + public Criteria andBound8NotLike(String value) { + addCriterion("bound8 not like", value, "bound8"); + return (Criteria) this; + } + + public Criteria andBound8In(List values) { + addCriterion("bound8 in", values, "bound8"); + return (Criteria) this; + } + + public Criteria andBound8NotIn(List values) { + addCriterion("bound8 not in", values, "bound8"); + return (Criteria) this; + } + + public Criteria andBound8Between(String value1, String value2) { + addCriterion("bound8 between", value1, value2, "bound8"); + return (Criteria) this; + } + + public Criteria andBound8NotBetween(String value1, String value2) { + addCriterion("bound8 not between", value1, value2, "bound8"); + return (Criteria) this; + } + + public Criteria andBound9IsNull() { + addCriterion("bound9 is null"); + return (Criteria) this; + } + + public Criteria andBound9IsNotNull() { + addCriterion("bound9 is not null"); + return (Criteria) this; + } + + public Criteria andBound9EqualTo(String value) { + addCriterion("bound9 =", value, "bound9"); + return (Criteria) this; + } + + public Criteria andBound9NotEqualTo(String value) { + addCriterion("bound9 <>", value, "bound9"); + return (Criteria) this; + } + + public Criteria andBound9GreaterThan(String value) { + addCriterion("bound9 >", value, "bound9"); + return (Criteria) this; + } + + public Criteria andBound9GreaterThanOrEqualTo(String value) { + addCriterion("bound9 >=", value, "bound9"); + return (Criteria) this; + } + + public Criteria andBound9LessThan(String value) { + addCriterion("bound9 <", value, "bound9"); + return (Criteria) this; + } + + public Criteria andBound9LessThanOrEqualTo(String value) { + addCriterion("bound9 <=", value, "bound9"); + return (Criteria) this; + } + + public Criteria andBound9Like(String value) { + addCriterion("bound9 like", value, "bound9"); + return (Criteria) this; + } + + public Criteria andBound9NotLike(String value) { + addCriterion("bound9 not like", value, "bound9"); + return (Criteria) this; + } + + public Criteria andBound9In(List values) { + addCriterion("bound9 in", values, "bound9"); + return (Criteria) this; + } + + public Criteria andBound9NotIn(List values) { + addCriterion("bound9 not in", values, "bound9"); + return (Criteria) this; + } + + public Criteria andBound9Between(String value1, String value2) { + addCriterion("bound9 between", value1, value2, "bound9"); + return (Criteria) this; + } + + public Criteria andBound9NotBetween(String value1, String value2) { + addCriterion("bound9 not between", value1, value2, "bound9"); + return (Criteria) this; + } } /** diff --git a/src/main/java/net/wicp/tams/app/duckula/controller/dao/SysResourceMapper.java b/src/main/java/net/wicp/tams/app/duckula/controller/dao/SysResourceMapper.java index 5ae2db3..8fdfb39 100644 --- a/src/main/java/net/wicp/tams/app/duckula/controller/dao/SysResourceMapper.java +++ b/src/main/java/net/wicp/tams/app/duckula/controller/dao/SysResourceMapper.java @@ -40,12 +40,16 @@ public interface SysResourceMapper extends BaseMapper{ * @mbg.generated */ @Insert({ "insert into sys_resource (id, res_code, ", "res_name, res_value, ", "res_type, icon, res_level, ", - "is_edit, parent_id, ", "show_order, remark)", - "values (#{id,jdbcType=BIGINT}, #{resCode,jdbcType=VARCHAR}, ", + "is_edit, parent_id, ", "show_order, remark, ", "bound1, bound2, ", "bound3, bound4, ", "bound5, bound6, ", + "bound7, bound8, ", "bound9)", "values (#{id,jdbcType=BIGINT}, #{resCode,jdbcType=VARCHAR}, ", "#{resName,jdbcType=VARCHAR}, #{resValue,jdbcType=VARCHAR}, ", - "#{resType,jdbcType=INTEGER}, #{icon,jdbcType=VARCHAR}, #{resLevel,jdbcType=INTEGER}, ", + "#{resType,jdbcType=VARCHAR}, #{icon,jdbcType=VARCHAR}, #{resLevel,jdbcType=INTEGER}, ", "#{isEdit,jdbcType=VARCHAR}, #{parentId,jdbcType=BIGINT}, ", - "#{showOrder,jdbcType=BIGINT}, #{remark,jdbcType=VARCHAR})" }) + "#{showOrder,jdbcType=BIGINT}, #{remark,jdbcType=VARCHAR}, ", + "#{bound1,jdbcType=VARCHAR}, #{bound2,jdbcType=VARCHAR}, ", + "#{bound3,jdbcType=VARCHAR}, #{bound4,jdbcType=VARCHAR}, ", + "#{bound5,jdbcType=VARCHAR}, #{bound6,jdbcType=VARCHAR}, ", + "#{bound7,jdbcType=VARCHAR}, #{bound8,jdbcType=VARCHAR}, ", "#{bound9,jdbcType=VARCHAR})" }) int insert(SysResource record); /** @@ -65,7 +69,8 @@ public interface SysResourceMapper extends BaseMapper{ * @mbg.generated */ @Select({ "select", "id, res_code, res_name, res_value, res_type, icon, res_level, is_edit, parent_id, ", - "show_order, remark", "from sys_resource", "where id = #{id,jdbcType=BIGINT}" }) + "show_order, remark, bound1, bound2, bound3, bound4, bound5, bound6, bound7, ", "bound8, bound9", + "from sys_resource", "where id = #{id,jdbcType=BIGINT}" }) @ResultMap("net.wicp.tams.app.duckula.controller.dao.SysResourceMapper.BaseResultMap") SysResource selectByPrimaryKey(Long id); @@ -93,9 +98,14 @@ public interface SysResourceMapper extends BaseMapper{ */ @Update({ "update sys_resource", "set res_code = #{resCode,jdbcType=VARCHAR},", "res_name = #{resName,jdbcType=VARCHAR},", "res_value = #{resValue,jdbcType=VARCHAR},", - "res_type = #{resType,jdbcType=INTEGER},", "icon = #{icon,jdbcType=VARCHAR},", + "res_type = #{resType,jdbcType=VARCHAR},", "icon = #{icon,jdbcType=VARCHAR},", "res_level = #{resLevel,jdbcType=INTEGER},", "is_edit = #{isEdit,jdbcType=VARCHAR},", "parent_id = #{parentId,jdbcType=BIGINT},", "show_order = #{showOrder,jdbcType=BIGINT},", - "remark = #{remark,jdbcType=VARCHAR}", "where id = #{id,jdbcType=BIGINT}" }) + "remark = #{remark,jdbcType=VARCHAR},", "bound1 = #{bound1,jdbcType=VARCHAR},", + "bound2 = #{bound2,jdbcType=VARCHAR},", "bound3 = #{bound3,jdbcType=VARCHAR},", + "bound4 = #{bound4,jdbcType=VARCHAR},", "bound5 = #{bound5,jdbcType=VARCHAR},", + "bound6 = #{bound6,jdbcType=VARCHAR},", "bound7 = #{bound7,jdbcType=VARCHAR},", + "bound8 = #{bound8,jdbcType=VARCHAR},", "bound9 = #{bound9,jdbcType=VARCHAR}", + "where id = #{id,jdbcType=BIGINT}" }) int updateByPrimaryKey(SysResource record); } \ No newline at end of file diff --git a/src/main/java/net/wicp/tams/app/duckula/controller/service/ContextInit.java b/src/main/java/net/wicp/tams/app/duckula/controller/service/ContextInit.java index fadcd06..d5913a3 100644 --- a/src/main/java/net/wicp/tams/app/duckula/controller/service/ContextInit.java +++ b/src/main/java/net/wicp/tams/app/duckula/controller/service/ContextInit.java @@ -1,16 +1,22 @@ package net.wicp.tams.app.duckula.controller.service; +import javax.servlet.ServletContext; + import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Service; +import org.springframework.web.context.ServletContextAware; import net.wicp.tams.app.duckula.controller.bean.models.SysGlobal; import net.wicp.tams.app.duckula.controller.config.constant.ConfigGlobleName; import net.wicp.tams.app.duckula.controller.dao.SysGlobalMapper; @Service -public class ContextInit implements ApplicationContextAware { +public class ContextInit implements ApplicationContextAware, ServletContextAware { + + public static volatile String pagePath;// page页面存放的根目录 + public static volatile String webRootPath;// Webroot所在目录 @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { @@ -21,4 +27,13 @@ public class ContextInit implements ApplicationContextAware { } } + + @Override + public void setServletContext(ServletContext servletContext) { + String realPath = servletContext.getRealPath("/"); + ContextInit.webRootPath = realPath;// 配置根目录 + String rootPath = Thread.currentThread().getContextClassLoader().getResource(".").getPath(); + String appPackage = servletContext.getInitParameter("tapestry.app-package"); + ContextInit.pagePath = String.format("%s%s/pages", rootPath, appPackage.replace(".", "/")); + } } diff --git a/src/main/java/net/wicp/tams/app/duckula/controller/service/cas/IMenuService.java b/src/main/java/net/wicp/tams/app/duckula/controller/service/cas/IMenuService.java new file mode 100644 index 0000000..fe69f0e --- /dev/null +++ b/src/main/java/net/wicp/tams/app/duckula/controller/service/cas/IMenuService.java @@ -0,0 +1,54 @@ +package net.wicp.tams.app.duckula.controller.service.cas; + +import java.util.List; + +import net.wicp.tams.app.duckula.controller.bean.models.SysResource; +import net.wicp.tams.app.duckula.controller.bean.models.SysRole; +import net.wicp.tams.common.apiext.json.easyuibean.EasyUINode; +import net.wicp.tams.common.callback.IConvertValue; + +/**** + * 菜单相关服务 + * + * @author Administrator + * + */ +public interface IMenuService { + /**** + * 跟据角色查到所拥有的节点,由于要查孙子节点,不能传入moduleId进行查询 + * + * @param roles + * @param isRoot true:只查询模块 false:查询模块以下的所有菜单 + * @return + */ + public List findAllModule(List roles, boolean isRoot); + + /*** + * 查询指定模块下面指定角色所有子节节点 + * + * @param moduleId + * @param roles + * @param I18NConvert + * @return + */ + public List findModuleMenuForRoles(int moduleId, List roles, IConvertValue I18NConvert); + + /***** + * 查询所有模块及其子菜单, + * + * @param i18NConvert + * @param hasUnallot 是否需要“未分配的资源”虚拟模块 + * @return + */ + public List findAllModuleMenu(IConvertValue i18NConvert, boolean hasUnallot); + + + + /** + * 查找需要同步的资源 + * + * @return + */ + public List findSyncRes(); + +} diff --git a/src/main/java/net/wicp/tams/app/duckula/controller/service/cas/impl/MenuService.java b/src/main/java/net/wicp/tams/app/duckula/controller/service/cas/impl/MenuService.java new file mode 100644 index 0000000..9f5c61b --- /dev/null +++ b/src/main/java/net/wicp/tams/app/duckula/controller/service/cas/impl/MenuService.java @@ -0,0 +1,145 @@ +package net.wicp.tams.app.duckula.controller.service.cas.impl; + +import java.util.List; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; +import org.apache.tapestry5.commons.util.CollectionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; + +import lombok.extern.slf4j.Slf4j; +import net.wicp.tams.app.duckula.controller.bean.constant.ResType; +import net.wicp.tams.app.duckula.controller.bean.models.SysResource; +import net.wicp.tams.app.duckula.controller.bean.models.SysRole; +import net.wicp.tams.app.duckula.controller.dao.SysResourceMapper; +import net.wicp.tams.app.duckula.controller.service.cas.IMenuService; +import net.wicp.tams.common.apiext.json.EasyUiAssist; +import net.wicp.tams.common.apiext.json.easyuibean.EasyUINode; +import net.wicp.tams.common.apiext.json.easyuibean.EasyUINodeConf; +import net.wicp.tams.common.callback.IConvertValue; + +@Slf4j +@Service +public class MenuService implements IMenuService { + + @Autowired + private SysResourceMapper sysResourceMapper; + + @Override + public List findAllModule(List roles, boolean isRoot) { + if (CollectionUtils.isEmpty(roles)) { + return CollectionFactory.newList(); + } + boolean isDev = isDev(roles); + QueryWrapper queryWrapper = new QueryWrapper(); + if (isRoot) { + queryWrapper.eq("res_level", 1); + } else { + queryWrapper.gt("res_level", 1); + } + if (!isDev) {// 不是开发者 + // criteria.add(Restrictions.in("crs.caRole", roles)); + } + // criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); + // criteria.addOrder(Order.asc("cr.showOrder")); + List retlist = sysResourceMapper.selectList(queryWrapper); + return retlist; + } + + @Override + public List findModuleMenuForRoles(final int moduleId, List roles, IConvertValue I18NConvert) { + // 查询该用户的所有模块资源 + List resList = this.findAllModule(roles, false); + EasyUINodeConf conf = new EasyUINodeConf("id", "resName", "caResource.id"); + conf.setAttrCols("resValue", "caResType.id"); + conf.setIsRoot(new Predicate() { + @Override + public boolean evaluate(Object object) { + int parentId = Integer.parseInt(String.valueOf(object)); + return parentId == moduleId; + } + }); + conf.setTextConvert(I18NConvert); + List ret = CollectionFactory.newList(); + try { + ret = EasyUiAssist.getTreeRoot(resList, conf); + } catch (Exception e) { + e.printStackTrace(); + } + return ret; + } + + @Override + public List findAllModuleMenu(IConvertValue i18NConvert, boolean hasUnallot) { + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.gt("res_level", 0); + if (!hasUnallot) { + queryWrapper.isNotNull("parent_id");// 父节点不能为空 + } + List resList = sysResourceMapper.selectList(queryWrapper); + EasyUINodeConf conf = new EasyUINodeConf("id", "resName", "parentId", "showOrder"); + // conf.setTextConvert(i18NConvert); + + conf.setIconClsCol("icon"); + conf.setAttrCols("isEdit","resType", "resLevel", "resCode", "resName", "resValue", "remark", "bound1", "bound2"); + + conf.setIsRoot(new Predicate() { + @Override + public boolean evaluate(Object object) { + long parentId = Long.parseLong(String.valueOf(object)); + return parentId == 1;// 设置所有的模块为树的根 + } + }); + + if (hasUnallot) { + // 构造虚拟的节点 + SysResource unAllot = new SysResource(); + unAllot.setId(-1l); + unAllot.setResName("未分配的资源"); + unAllot.setResValue("0"); + unAllot.setResType(ResType.DIR.name()); + unAllot.setIcon("icon-folder-star"); + unAllot.setResLevel(1); + unAllot.setParentId(1l); + unAllot.setShowOrder(10000l); + resList.add(unAllot); + // 把未分配的节点全放到它目录下 + for (SysResource res : resList) { + if (res.getParentId() == null) { + res.setParentId(-1l); + } + } + } + + List ret = CollectionFactory.newList(); + try { + ret = EasyUiAssist.getTreeRoot(resList, conf); + } catch (Exception e) { + log.error("构造资源树出错", e); + } + return ret; + } + + @Override + public List findSyncRes() { + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.gt("res_level", 1); + queryWrapper.eq("res_type", 3); + return sysResourceMapper.selectList(queryWrapper); + } + + private boolean isDev(List roles) { + boolean isDev = false; + for (SysRole role : roles) { + if (role.getId() == 0) { + isDev = true; + break; + } + } + return isDev; + } + +} diff --git a/src/main/java/net/wicp/tams/duckula/ops/pages/cas/ResManager.java b/src/main/java/net/wicp/tams/duckula/ops/pages/cas/ResManager.java new file mode 100644 index 0000000..5bfdb61 --- /dev/null +++ b/src/main/java/net/wicp/tams/duckula/ops/pages/cas/ResManager.java @@ -0,0 +1,317 @@ +package net.wicp.tams.duckula.ops.pages.cas; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.IOFileFilter; +import org.apache.commons.lang3.StringUtils; +import org.apache.tapestry5.annotations.Import; +import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.ioc.annotations.Inject; +import org.apache.tapestry5.json.JSONObject; +import org.apache.tapestry5.util.TextStreamResponse; +import org.w3c.dom.Document; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +import net.wicp.tams.app.duckula.controller.bean.constant.ResType; +import net.wicp.tams.app.duckula.controller.bean.models.SysResource; +import net.wicp.tams.app.duckula.controller.dao.SysResourceMapper; +import net.wicp.tams.app.duckula.controller.service.ContextInit; +import net.wicp.tams.app.duckula.controller.service.cas.IMenuService; +import net.wicp.tams.common.Result; +import net.wicp.tams.common.apiext.CollectionUtil; +import net.wicp.tams.common.apiext.StringUtil; +import net.wicp.tams.common.apiext.json.EasyUiAssist; +import net.wicp.tams.common.apiext.json.easyuibean.EasyUINode; +import net.wicp.tams.common.connector.XmlUtil; +import net.wicp.tams.common.constant.dic.YesOrNo; +import net.wicp.tams.component.tools.TapestryAssist; +import net.wicp.tams.duckula.ops.pages.ParentPageBean; + +@Import(stack = "easyuistack") +public class ResManager extends ParentPageBean { + @Inject + private IMenuService menuService; + + @Inject + private SysResourceMapper sysResourceMapper; + + public TextStreamResponse onQueryMenu() throws Exception { + List roots = menuService.findAllModuleMenu(I18NConvert, true); + String retstr = EasyUiAssist.getTreeFromList(roots); + return retStream(retstr); + } + + public TextStreamResponse onSaveRes() { + JSONObject params = TapestryAssist.packParams(request, false); + String id = params.getString("id"); + String parentId = params.getString("parentId"); + String icon = params.getString("icon"); + String resLevel = params.getString("resLevel"); + String caResType = params.getString("caResType"); + + String showOrder = params.getString("showOrder"); + String resCode = params.getString("resCode"); + String resName = params.getString("resName"); + String resValue = params.getString("resValue"); + String isEdit = params.getString("isEdit"); + String remark = params.getString("remark"); + String bound1 = params.getString("bound1");// app + String bound2 = params.getString("bound2");// 是否菜单 + if (StringUtil.isNull(bound1)) {// bound1如果为空 + bound1 = null; + if (Integer.parseInt(resLevel) == 2) { + bound1 = parentId; + } else if (Integer.parseInt(resLevel) == 3) {// 需要查一下数据库 + SysResource parentObj = (SysResource) sysResourceMapper.selectById(Long.parseLong(parentId)); + bound1 = String.valueOf(parentObj.getParentId()); + } + } + SysResource rs = new SysResource(); + if (StringUtils.isNotBlank(id)) { + rs.setId(Long.parseLong(id)); + } + + rs.setResCode(resCode); + rs.setResName(resName); + rs.setResValue(resValue); + rs.setResType(caResType); + rs.setIcon(icon); + rs.setResLevel(Integer.parseInt(resLevel)); + rs.setIsEdit(isEdit); + rs.setParentId(Long.parseLong(parentId)); + + rs.setShowOrder(Long.parseLong(showOrder)); + rs.setRemark(remark); + rs.setBound1(bound1); + rs.setBound2(bound2); + if (rs.getId() == null) { + sysResourceMapper.insert(rs); + } else { + sysResourceMapper.updateById(rs); + } + Result res = Result.getSuc(); + com.alibaba.fastjson.JSONObject retobj = res.retJsonObj(); + retobj.put("id", rs.getId()); + + JSONObject attributes = new JSONObject("resCode", resCode, "resName", resName, "resValue", resValue, "isEdit", + isEdit, "remark", remark, "bound1", bound1, "bound2", bound2); + retobj.put("attributes", attributes); + retobj.put("index", Integer.parseInt(showOrder)); + retobj.put("text", I18NConvert.getStr(resName)); + return retStream(retobj.toString()); + } + + /**** + * 删除Res + * + * @return + */ + public TextStreamResponse onDelRes() { + String id = request.getParameter("id"); + sysResourceMapper.deleteById(Long.parseLong(id)); + return TapestryAssist.getTextStreamResponse(Result.getSuc()); + } + + /** + * 更新菜单列表,当前的方案是:扫描page目录下的TML文件及目录结构 + * + * @return + */ + public TextStreamResponse onSyncRes() { + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.eq("parent_id", 1); + List selectList = sysResourceMapper.selectList(queryWrapper); + Set mods = CollectionUtil.getColSetFromObj(selectList, "id"); + + Result ret = Result.getSuc(); + try { + Collection files = FileUtils.listFiles(new File(ContextInit.pagePath), fileFilter, dirFilter); + + final List hasResList = new ArrayList(); + for (File file : files) { + SysResource res = new SysResource(); + res.setResType(ResType.URL.name()); + + String path = file.getPath(); + int beginIndex = path.indexOf("pages" + File.separator); + int endIndex = path.indexOf(".tml"); + path = path.substring(beginIndex + 5, endIndex); + res.setResValue(path.replaceAll("\\" + File.separator, "/"));// 资源值 + res.setResCode(path.replaceAll("\\" + File.separator, "_")); + String fileContext = FileUtils.readFileToString(file, "utf-8"); + int beginTitle = fileContext.indexOf(""); + + boolean isMenu = false; + String value = ""; + long module = -1; + if (beginTitle >= 0 && endTitle > beginTitle) { + try { + Document doc = XmlUtil.parserDocment(fileContext.substring(beginTitle, endTitle + 8)); + if (doc != null && doc.getFirstChild() != null && doc.getFirstChild().getFirstChild() != null) { + value = doc.getFirstChild().getFirstChild().getNodeValue(); + String isMenuStr = findAttrByName(doc, "isMenu"); + isMenu = Boolean.parseBoolean(isMenuStr); + + String moduleStr = findAttrByName(doc, "module");// 它可以没有 + try { + module = Long.parseLong(moduleStr); + if (!mods.contains(module)) {// 页面设置的模块不在数据库中 + module = -1; + } + } catch (Exception e) { + } + + } + } catch (Exception e) { + } + } + if (!isMenu) {// 是菜单 + continue; + } + + if (module > 0) { + res.setParentId(module); + } + + value = value.replace("$", "").replace("{", "").replace("}", "").replace("message:", ""); + res.setResName(StringUtils.isEmpty(value) ? file.getName() : value);// 资源名称,国际化的key值,如果没拿到key值,就用文件名代替 + hasResList.add(res); + } + final List dbResList = menuService.findSyncRes();// 查找数据库已有的菜单 + // 数据库中有的,但已不存在此页面的,需要删除 + List deleteList = (List) CollectionUtils.select(dbResList, new Predicate() { + @Override + public boolean evaluate(Object object) { + return !hasResList.contains(object); + } + }); + + for (SysResource ca_Resource : deleteList) { + sysResourceMapper.deleteById(ca_Resource.getId()); + } + + // dbResList 剩余的集合、更新 + List updateList = (List) CollectionUtils.select(dbResList, new Predicate() { + @Override + public boolean evaluate(Object object) { + SysResource tempobj = (SysResource) object; + return hasResList.contains(object); + // && "yes".equals(tempobj.getisEdit()); + } + }); + for (SysResource ca_Resource : updateList) { + SysResource updateObj = hasResList.get(hasResList.indexOf(ca_Resource)); + ca_Resource.setResCode(updateObj.getResCode()); + ca_Resource.setResName(updateObj.getResName()); + ca_Resource.setResValue(updateObj.getResValue()); + ca_Resource.setRemark("程序自动更新"); + } + for (SysResource caResource : updateList) { + sysResourceMapper.updateByPrimaryKey(caResource); + } + + // 数据库没有的,但已存在的、需添加 + List addList = (List) CollectionUtils.select(hasResList, new Predicate() { + @Override + public boolean evaluate(Object object) { + return !dbResList.contains(object); + } + }); + + for (SysResource caResource : addList) { + int secIndex = caResource.getResValue().indexOf("/", 1); + int threeIndex = caResource.getResValue().indexOf("/", secIndex + 1); + caResource.setIcon("icon-user"); + caResource.setIsEdit(YesOrNo.yes.name()); + caResource.setRemark("系统自动同步"); + // caResource.setCaResource(defaulModel); + caResource.setResLevel(2); + sysResourceMapper.updateByPrimaryKeySelective(caResource); + } + } catch (Exception e) { + ret.setMessage(LK("tip.sys.error.sync") + e.getMessage()); + } + return TapestryAssist.getTextStreamResponse(ret); + } + + private String findAttrByName(Document doc, String nodeName) { + String retstr = null; + try { + retstr = doc.getFirstChild().getAttributes().getNamedItem(nodeName).getNodeValue(); + } catch (Exception e) { + } + return retstr; + } + + IOFileFilter fileFilter = new IOFileFilter() { + @Override + public boolean accept(File dir, String name) { + if (name.endsWith(".tml")) { + return true; + } else { + return false; + } + } + + @Override + public boolean accept(File file) { + String name = file.getName(); + if (name.endsWith(".tml")) { + return true; + } else { + return false; + } + } + }; + + IOFileFilter dirFilter = new IOFileFilter() { + @Override + public boolean accept(File dir, String name) { + if (name.endsWith(".tml")) { + return true; + } else { + return false; + } + } + + @Override + public boolean accept(File file) { + return true; + } + }; + + @Override + public void doSave(SysResource t, boolean isInsert) { + // TODO Auto-generated method stub + + } + + @Override + public void doDel(String id) { + // TODO Auto-generated method stub + + } + + @Override + public BaseMapper getBaseMapper() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void packageQuery(SysResource t, QueryWrapper queryWrapper) { + // TODO Auto-generated method stub + + } + +} diff --git a/src/main/resources/mybatis/primary/sqlmap/SysResourceMapper.xml b/src/main/resources/mybatis/primary/sqlmap/SysResourceMapper.xml index 619061b..00ad1ef 100644 --- a/src/main/resources/mybatis/primary/sqlmap/SysResourceMapper.xml +++ b/src/main/resources/mybatis/primary/sqlmap/SysResourceMapper.xml @@ -11,13 +11,22 @@ - + + + + + + + + + + @@ -92,7 +101,8 @@ This element is automatically generated by MyBatis Generator, do not modify. --> id, res_code, res_name, res_value, res_type, icon, res_level, is_edit, parent_id, - show_order, remark + show_order, remark, bound1, bound2, bound3, bound4, bound5, bound6, bound7, bound8, + bound9 + + + + + 父资源 +
+ 显示顺序 + + + + + + + + 类型 + + + + 是否采集 + + + + 是否菜单 + + + + + + + 图标 + + + + 资源编码 + + + + + + + + + 资源名称 + + + + 资源值 + + + + + + + 备注 + + + + + + + + + + + \ No newline at end of file -- GitLab