mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2025-12-26 16:26:41 +08:00
Jeecg-Boot 2.1.2版本发布
This commit is contained in:
@ -11,6 +11,10 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 关于 ElasticSearch 的一些方法(创建索引、添加数据、查询等)
|
||||
*
|
||||
@ -20,11 +24,54 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class JeecgElasticsearchTemplate {
|
||||
|
||||
@Value("${jeecg.elasticsearch.cluster-nodes}")
|
||||
/**
|
||||
* 用户配置是否通过,未通过就不走任何方法
|
||||
*/
|
||||
private static boolean configIsPassed = true;
|
||||
/**
|
||||
* 是否已检测过配置
|
||||
*/
|
||||
private static boolean configIsChecked = false;
|
||||
|
||||
private String baseUrl;
|
||||
|
||||
private final String FORMAT_JSON = "format=json";
|
||||
|
||||
public JeecgElasticsearchTemplate(@Value("${jeecg.elasticsearch.cluster-nodes}") String baseUrl) {
|
||||
log.debug("JeecgElasticsearchTemplate BaseURL:" + baseUrl);
|
||||
|
||||
// 未检测过配置,进行检测操作
|
||||
if (!configIsChecked) {
|
||||
configIsChecked = true;
|
||||
// 为空则代表未配置 baseUrl
|
||||
if (StringUtils.isEmpty(baseUrl)) {
|
||||
configIsPassed = false;
|
||||
} else {
|
||||
this.baseUrl = baseUrl;
|
||||
// 判断配置的地址是否有效
|
||||
try {
|
||||
RestUtil.get(this.getBaseUrl().toString());
|
||||
} catch (Exception e) {
|
||||
configIsPassed = false;
|
||||
}
|
||||
}
|
||||
if (configIsPassed) {
|
||||
log.info("ElasticSearch服务连接成功");
|
||||
} else {
|
||||
log.warn("ElasticSearch 服务连接失败,原因:配置未通过。可能是BaseURL未配置或配置有误,也可能是Elasticsearch服务未启动。接下来将会拒绝执行任何方法!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查配置是否通过,未通过就抛出异常,中断执行
|
||||
*/
|
||||
private void checkConfig() {
|
||||
if (!configIsPassed) {
|
||||
throw new RuntimeException("配置未通过,拒绝执行该方法");
|
||||
}
|
||||
}
|
||||
|
||||
public StringBuilder getBaseUrl(String indexName, String typeName) {
|
||||
typeName = typeName.trim().toLowerCase();
|
||||
return this.getBaseUrl(indexName).append("/").append(typeName);
|
||||
@ -43,6 +90,7 @@ public class JeecgElasticsearchTemplate {
|
||||
* cat 查询ElasticSearch系统数据,返回json
|
||||
*/
|
||||
public <T> ResponseEntity<T> _cat(String urlAfter, Class<T> responseType) {
|
||||
this.checkConfig();
|
||||
String url = this.getBaseUrl().append("/_cat").append(urlAfter).append("?").append(FORMAT_JSON).toString();
|
||||
return RestUtil.request(url, HttpMethod.GET, null, null, null, responseType);
|
||||
}
|
||||
@ -53,6 +101,7 @@ public class JeecgElasticsearchTemplate {
|
||||
* 查询地址:GET http://{baseUrl}/_cat/indices
|
||||
*/
|
||||
public JSONArray getIndices() {
|
||||
this.checkConfig();
|
||||
return getIndices(null);
|
||||
}
|
||||
|
||||
@ -63,6 +112,7 @@ public class JeecgElasticsearchTemplate {
|
||||
* 查询地址:GET http://{baseUrl}/_cat/indices/{indexName}
|
||||
*/
|
||||
public JSONArray getIndices(String indexName) {
|
||||
this.checkConfig();
|
||||
StringBuilder urlAfter = new StringBuilder("/indices");
|
||||
if (!StringUtils.isEmpty(indexName)) {
|
||||
urlAfter.append("/").append(indexName.trim().toLowerCase());
|
||||
@ -74,6 +124,7 @@ public class JeecgElasticsearchTemplate {
|
||||
* 索引是否存在
|
||||
*/
|
||||
public boolean indexExists(String indexName) {
|
||||
this.checkConfig();
|
||||
try {
|
||||
JSONArray array = getIndices(indexName);
|
||||
return array != null;
|
||||
@ -92,6 +143,7 @@ public class JeecgElasticsearchTemplate {
|
||||
* 查询地址:PUT http://{baseUrl}/{indexName}
|
||||
*/
|
||||
public boolean createIndex(String indexName) {
|
||||
this.checkConfig();
|
||||
String url = this.getBaseUrl(indexName).toString();
|
||||
|
||||
/* 返回结果 (仅供参考)
|
||||
@ -119,6 +171,7 @@ public class JeecgElasticsearchTemplate {
|
||||
* 查询地址:DELETE http://{baseUrl}/{indexName}
|
||||
*/
|
||||
public boolean removeIndex(String indexName) {
|
||||
this.checkConfig();
|
||||
String url = this.getBaseUrl(indexName).toString();
|
||||
try {
|
||||
return RestUtil.delete(url).getBoolean("acknowledged");
|
||||
@ -136,6 +189,7 @@ public class JeecgElasticsearchTemplate {
|
||||
* 保存数据,详见:saveOrUpdate
|
||||
*/
|
||||
public boolean save(String indexName, String typeName, String dataId, JSONObject data) {
|
||||
this.checkConfig();
|
||||
return this.saveOrUpdate(indexName, typeName, dataId, data);
|
||||
}
|
||||
|
||||
@ -143,6 +197,7 @@ public class JeecgElasticsearchTemplate {
|
||||
* 更新数据,详见:saveOrUpdate
|
||||
*/
|
||||
public boolean update(String indexName, String typeName, String dataId, JSONObject data) {
|
||||
this.checkConfig();
|
||||
return this.saveOrUpdate(indexName, typeName, dataId, data);
|
||||
}
|
||||
|
||||
@ -158,6 +213,7 @@ public class JeecgElasticsearchTemplate {
|
||||
* @return
|
||||
*/
|
||||
public boolean saveOrUpdate(String indexName, String typeName, String dataId, JSONObject data) {
|
||||
this.checkConfig();
|
||||
String url = this.getBaseUrl(indexName, typeName).append("/").append(dataId).toString();
|
||||
/* 返回结果(仅供参考)
|
||||
"createIndexA2": {
|
||||
@ -178,12 +234,17 @@ public class JeecgElasticsearchTemplate {
|
||||
|
||||
try {
|
||||
// 去掉 data 中为空的值
|
||||
for (String key : data.keySet()) {
|
||||
Set<String> keys = data.keySet();
|
||||
List<String> emptyKeys = new ArrayList<>(keys.size());
|
||||
for (String key : keys) {
|
||||
String value = data.getString(key);
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
data.remove(key);
|
||||
emptyKeys.add(key);
|
||||
}
|
||||
}
|
||||
for (String key : emptyKeys) {
|
||||
data.remove(key);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -198,6 +259,7 @@ public class JeecgElasticsearchTemplate {
|
||||
* 请求地址:DELETE http://{baseUrl}/{indexName}/{typeName}/{dataId}
|
||||
*/
|
||||
public boolean delete(String indexName, String typeName, String dataId) {
|
||||
this.checkConfig();
|
||||
String url = this.getBaseUrl(indexName, typeName).append("/").append(dataId).toString();
|
||||
/* 返回结果(仅供参考)
|
||||
{
|
||||
@ -235,6 +297,7 @@ public class JeecgElasticsearchTemplate {
|
||||
* 请求地址:POST http://{baseUrl}/{indexName}/{typeName}/_search
|
||||
*/
|
||||
public JSONObject search(String indexName, String typeName, JSONObject queryObject) {
|
||||
this.checkConfig();
|
||||
String url = this.getBaseUrl(indexName, typeName).append("/_search").toString();
|
||||
|
||||
log.info("search: " + queryObject.toJSONString());
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package org.jeecg.common.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
* 填值规则接口
|
||||
*
|
||||
* @author Yan_东
|
||||
* 如需使用填值规则功能,规则实现类必须实现此接口
|
||||
*/
|
||||
public interface IFillRuleHandler {
|
||||
|
||||
public Object execute(JSONObject params, JSONObject formData);
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import java.util.List;
|
||||
import org.jeecg.common.system.vo.ComboModel;
|
||||
import org.jeecg.common.system.vo.DictModel;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.system.vo.SysDepartModel;
|
||||
|
||||
/**
|
||||
* @Description: 底层共通业务API,提供其他独立模块调用
|
||||
@ -115,12 +116,26 @@ public interface ISysBaseAPI {
|
||||
*/
|
||||
public List<ComboModel> queryAllUser();
|
||||
|
||||
/**
|
||||
* 获取所有有效用户 带参
|
||||
* userIds 默认选中用户
|
||||
* @return
|
||||
*/
|
||||
public List<ComboModel> queryAllUser(String[] userIds);
|
||||
|
||||
/**
|
||||
* 获取所有角色
|
||||
* @return
|
||||
*/
|
||||
public List<ComboModel> queryAllRole();
|
||||
|
||||
/**
|
||||
* 获取所有角色 带参
|
||||
* roleIds 默认选中角色
|
||||
* @return
|
||||
*/
|
||||
public List<ComboModel> queryAllRole(String[] roleIds );
|
||||
|
||||
/**
|
||||
* 通过用户账号查询角色Id集合
|
||||
* @param username
|
||||
@ -141,5 +156,11 @@ public interface ISysBaseAPI {
|
||||
* @return
|
||||
*/
|
||||
public DictModel getParentDepartId(String departId);
|
||||
|
||||
/**
|
||||
* 查询所有部门
|
||||
* @return
|
||||
*/
|
||||
public List<SysDepartModel> getAllSysDepart();
|
||||
|
||||
}
|
||||
|
||||
@ -19,9 +19,9 @@ import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.system.util.JeecgDataAutorUtils;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.common.system.vo.SysPermissionDataRuleModel;
|
||||
import org.jeecg.common.util.SqlInjectionUtil;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.system.entity.SysPermissionDataRule;
|
||||
import org.springframework.util.NumberUtils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@ -94,7 +94,7 @@ public class QueryGenerator {
|
||||
|
||||
//区间条件组装 模糊查询 高级查询组装 简单排序 权限查询
|
||||
PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(searchObj);
|
||||
Map<String,SysPermissionDataRule> ruleMap = getRuleMap();
|
||||
Map<String,SysPermissionDataRuleModel> ruleMap = getRuleMap();
|
||||
|
||||
//权限规则自定义SQL表达式
|
||||
for (String c : ruleMap.keySet()) {
|
||||
@ -444,14 +444,14 @@ public class QueryGenerator {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, SysPermissionDataRule> getRuleMap() {
|
||||
Map<String, SysPermissionDataRule> ruleMap = new HashMap<String, SysPermissionDataRule>();
|
||||
List<SysPermissionDataRule> list =JeecgDataAutorUtils.loadDataSearchConditon();
|
||||
public static Map<String, SysPermissionDataRuleModel> getRuleMap() {
|
||||
Map<String, SysPermissionDataRuleModel> ruleMap = new HashMap<String, SysPermissionDataRuleModel>();
|
||||
List<SysPermissionDataRuleModel> list =JeecgDataAutorUtils.loadDataSearchConditon();
|
||||
if(list != null&&list.size()>0){
|
||||
if(list.get(0)==null){
|
||||
return ruleMap;
|
||||
}
|
||||
for (SysPermissionDataRule rule : list) {
|
||||
for (SysPermissionDataRuleModel rule : list) {
|
||||
String column = rule.getRuleColumn();
|
||||
if(QueryRuleEnum.SQL_RULES.getValue().equals(rule.getRuleConditions())) {
|
||||
column = SQL_RULES_COLUMN+rule.getId();
|
||||
@ -462,7 +462,7 @@ public class QueryGenerator {
|
||||
return ruleMap;
|
||||
}
|
||||
|
||||
private static void addRuleToQueryWrapper(SysPermissionDataRule dataRule,String name, Class propertyType, QueryWrapper<?> queryWrapper) {
|
||||
private static void addRuleToQueryWrapper(SysPermissionDataRuleModel dataRule, String name, Class propertyType, QueryWrapper<?> queryWrapper) {
|
||||
QueryRuleEnum rule = QueryRuleEnum.getByValue(dataRule.getRuleConditions());
|
||||
if(rule.equals(QueryRuleEnum.IN) && ! propertyType.equals(String.class)) {
|
||||
String[] values = dataRule.getRuleValue().split(",");
|
||||
@ -636,7 +636,7 @@ public class QueryGenerator {
|
||||
public static String installAuthJdbc(Class<?> clazz) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
//权限查询
|
||||
Map<String,SysPermissionDataRule> ruleMap = getRuleMap();
|
||||
Map<String,SysPermissionDataRuleModel> ruleMap = getRuleMap();
|
||||
PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(clazz);
|
||||
String sql_and = " and ";
|
||||
for (String c : ruleMap.keySet()) {
|
||||
@ -651,7 +651,7 @@ public class QueryGenerator {
|
||||
continue;
|
||||
}
|
||||
if(ruleMap.containsKey(name)) {
|
||||
SysPermissionDataRule dataRule = ruleMap.get(name);
|
||||
SysPermissionDataRuleModel dataRule = ruleMap.get(name);
|
||||
QueryRuleEnum rule = QueryRuleEnum.getByValue(dataRule.getRuleConditions());
|
||||
Class propType = origDescriptors[i].getPropertyType();
|
||||
boolean isString = propType.equals(String.class);
|
||||
@ -677,7 +677,7 @@ public class QueryGenerator {
|
||||
*/
|
||||
public static void installAuthMplus(QueryWrapper<?> queryWrapper,Class<?> clazz) {
|
||||
//权限查询
|
||||
Map<String,SysPermissionDataRule> ruleMap = getRuleMap();
|
||||
Map<String,SysPermissionDataRuleModel> ruleMap = getRuleMap();
|
||||
PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(clazz);
|
||||
for (String c : ruleMap.keySet()) {
|
||||
if(oConvertUtils.isNotEmpty(c) && c.startsWith(SQL_RULES_COLUMN)){
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
package org.jeecg.common.system.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.jeecg.common.system.vo.SysPermissionDataRuleModel;
|
||||
import org.jeecg.common.system.vo.SysUserCacheInfo;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.modules.system.entity.SysPermissionDataRule;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: JeecgDataAutorUtils
|
||||
* @Description: 数据权限查询规则容器工具类
|
||||
@ -29,16 +28,16 @@ public class JeecgDataAutorUtils {
|
||||
* 往链接请求里面,传入数据查询条件
|
||||
*
|
||||
* @param request
|
||||
* @param MENU_DATA_AUTHOR_RULES
|
||||
* @param dataRules
|
||||
*/
|
||||
public static synchronized void installDataSearchConditon(HttpServletRequest request, List<SysPermissionDataRule> dataRules) {
|
||||
public static synchronized void installDataSearchConditon(HttpServletRequest request, List<SysPermissionDataRuleModel> dataRules) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<SysPermissionDataRule> list = (List<SysPermissionDataRule>)loadDataSearchConditon();// 1.先从request获取MENU_DATA_AUTHOR_RULES,如果存则获取到LIST
|
||||
List<SysPermissionDataRuleModel> list = (List<SysPermissionDataRuleModel>)loadDataSearchConditon();// 1.先从request获取MENU_DATA_AUTHOR_RULES,如果存则获取到LIST
|
||||
if (list==null) {
|
||||
// 2.如果不存在,则new一个list
|
||||
list = new ArrayList<SysPermissionDataRule>();
|
||||
list = new ArrayList<SysPermissionDataRuleModel>();
|
||||
}
|
||||
for (SysPermissionDataRule tsDataRule : dataRules) {
|
||||
for (SysPermissionDataRuleModel tsDataRule : dataRules) {
|
||||
list.add(tsDataRule);
|
||||
}
|
||||
request.setAttribute(MENU_DATA_AUTHOR_RULES, list); // 3.往list里面增量存指
|
||||
@ -47,19 +46,17 @@ public class JeecgDataAutorUtils {
|
||||
/**
|
||||
* 获取请求对应的数据权限规则
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static synchronized List<SysPermissionDataRule> loadDataSearchConditon() {
|
||||
return (List<SysPermissionDataRule>) SpringContextUtils.getHttpServletRequest().getAttribute(MENU_DATA_AUTHOR_RULES);
|
||||
public static synchronized List<SysPermissionDataRuleModel> loadDataSearchConditon() {
|
||||
return (List<SysPermissionDataRuleModel>) SpringContextUtils.getHttpServletRequest().getAttribute(MENU_DATA_AUTHOR_RULES);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求对应的数据权限SQL
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public static synchronized String loadDataSearchConditonSQLString() {
|
||||
@ -70,7 +67,7 @@ public class JeecgDataAutorUtils {
|
||||
* 往链接请求里面,传入数据查询条件
|
||||
*
|
||||
* @param request
|
||||
* @param MENU_DATA_AUTHOR_RULE_SQL
|
||||
* @param sql
|
||||
*/
|
||||
public static synchronized void installDataSearchConditon(HttpServletRequest request, String sql) {
|
||||
String ruleSql = (String)loadDataSearchConditonSQLString();
|
||||
|
||||
@ -14,13 +14,19 @@ import java.io.Serializable;
|
||||
public class ComboModel implements Serializable {
|
||||
private String id;
|
||||
private String title;
|
||||
/**文档管理 表单table默认选中*/
|
||||
private boolean checked;
|
||||
/**文档管理 表单table 用户账号*/
|
||||
private String username;
|
||||
|
||||
public ComboModel(){
|
||||
|
||||
};
|
||||
|
||||
public ComboModel(String id,String title){
|
||||
public ComboModel(String id,String title,boolean checked,String username){
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.checked = false;
|
||||
this.username = username;
|
||||
};
|
||||
}
|
||||
|
||||
@ -0,0 +1,147 @@
|
||||
package org.jeecg.common.system.vo;
|
||||
|
||||
/**
|
||||
* lvdandan 部门机构model
|
||||
*/
|
||||
public class SysDepartModel {
|
||||
/**ID*/
|
||||
private String id;
|
||||
/**父机构ID*/
|
||||
private String parentId;
|
||||
/**机构/部门名称*/
|
||||
private String departName;
|
||||
/**英文名*/
|
||||
private String departNameEn;
|
||||
/**缩写*/
|
||||
private String departNameAbbr;
|
||||
/**排序*/
|
||||
private Integer departOrder;
|
||||
/**描述*/
|
||||
private Object description;
|
||||
/**机构类别 1组织机构,2岗位*/
|
||||
private String orgCategory;
|
||||
/**机构类型*/
|
||||
private String orgType;
|
||||
/**机构编码*/
|
||||
private String orgCode;
|
||||
/**手机号*/
|
||||
private String mobile;
|
||||
/**传真*/
|
||||
private String fax;
|
||||
/**地址*/
|
||||
private String address;
|
||||
/**备注*/
|
||||
private String memo;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setParentId(String parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public String getDepartName() {
|
||||
return departName;
|
||||
}
|
||||
|
||||
public void setDepartName(String departName) {
|
||||
this.departName = departName;
|
||||
}
|
||||
|
||||
public String getDepartNameEn() {
|
||||
return departNameEn;
|
||||
}
|
||||
|
||||
public void setDepartNameEn(String departNameEn) {
|
||||
this.departNameEn = departNameEn;
|
||||
}
|
||||
|
||||
public String getDepartNameAbbr() {
|
||||
return departNameAbbr;
|
||||
}
|
||||
|
||||
public void setDepartNameAbbr(String departNameAbbr) {
|
||||
this.departNameAbbr = departNameAbbr;
|
||||
}
|
||||
|
||||
public Integer getDepartOrder() {
|
||||
return departOrder;
|
||||
}
|
||||
|
||||
public void setDepartOrder(Integer departOrder) {
|
||||
this.departOrder = departOrder;
|
||||
}
|
||||
|
||||
public Object getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(Object description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getOrgCategory() {
|
||||
return orgCategory;
|
||||
}
|
||||
|
||||
public void setOrgCategory(String orgCategory) {
|
||||
this.orgCategory = orgCategory;
|
||||
}
|
||||
|
||||
public String getOrgType() {
|
||||
return orgType;
|
||||
}
|
||||
|
||||
public void setOrgType(String orgType) {
|
||||
this.orgType = orgType;
|
||||
}
|
||||
|
||||
public String getOrgCode() {
|
||||
return orgCode;
|
||||
}
|
||||
|
||||
public void setOrgCode(String orgCode) {
|
||||
this.orgCode = orgCode;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
public String getFax() {
|
||||
return fax;
|
||||
}
|
||||
|
||||
public void setFax(String fax) {
|
||||
this.fax = fax;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getMemo() {
|
||||
return memo;
|
||||
}
|
||||
|
||||
public void setMemo(String memo) {
|
||||
this.memo = memo;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,151 @@
|
||||
package org.jeecg.common.system.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单权限规则表
|
||||
* </p>
|
||||
*
|
||||
* @Author huangzhilin
|
||||
* @since 2019-03-29
|
||||
*/
|
||||
public class SysPermissionDataRuleModel {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 对应的菜单id
|
||||
*/
|
||||
private String permissionId;
|
||||
|
||||
/**
|
||||
* 规则名称
|
||||
*/
|
||||
private String ruleName;
|
||||
|
||||
/**
|
||||
* 字段
|
||||
*/
|
||||
private String ruleColumn;
|
||||
|
||||
/**
|
||||
* 条件
|
||||
*/
|
||||
private String ruleConditions;
|
||||
|
||||
/**
|
||||
* 规则值
|
||||
*/
|
||||
private String ruleValue;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPermissionId() {
|
||||
return permissionId;
|
||||
}
|
||||
|
||||
public void setPermissionId(String permissionId) {
|
||||
this.permissionId = permissionId;
|
||||
}
|
||||
|
||||
public String getRuleName() {
|
||||
return ruleName;
|
||||
}
|
||||
|
||||
public void setRuleName(String ruleName) {
|
||||
this.ruleName = ruleName;
|
||||
}
|
||||
|
||||
public String getRuleColumn() {
|
||||
return ruleColumn;
|
||||
}
|
||||
|
||||
public void setRuleColumn(String ruleColumn) {
|
||||
this.ruleColumn = ruleColumn;
|
||||
}
|
||||
|
||||
public String getRuleConditions() {
|
||||
return ruleConditions;
|
||||
}
|
||||
|
||||
public void setRuleConditions(String ruleConditions) {
|
||||
this.ruleConditions = ruleConditions;
|
||||
}
|
||||
|
||||
public String getRuleValue() {
|
||||
return ruleValue;
|
||||
}
|
||||
|
||||
public void setRuleValue(String ruleValue) {
|
||||
this.ruleValue = ruleValue;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getCreateBy() {
|
||||
return createBy;
|
||||
}
|
||||
|
||||
public void setCreateBy(String createBy) {
|
||||
this.createBy = createBy;
|
||||
}
|
||||
|
||||
public Date getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public String getUpdateBy() {
|
||||
return updateBy;
|
||||
}
|
||||
|
||||
public void setUpdateBy(String updateBy) {
|
||||
this.updateBy = updateBy;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package org.jeecg.common.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jeecg.common.handler.IFillRuleHandler;
|
||||
|
||||
|
||||
/**
|
||||
* 规则值自动生成工具类
|
||||
*
|
||||
* @author qinfeng
|
||||
* @举例: 自动生成订单号;自动生成当前日期
|
||||
*/
|
||||
public class FillRuleUtil {
|
||||
|
||||
/**
|
||||
* @param ruleCode ruleCode
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Object executeRule(String ruleCode, JSONObject formData) {
|
||||
if (!StringUtils.isEmpty(ruleCode)) {
|
||||
try {
|
||||
// 获取 Service
|
||||
ServiceImpl impl = (ServiceImpl) SpringContextUtils.getBean("sysFillRuleServiceImpl");
|
||||
// 根据 ruleCode 查询出实体
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
queryWrapper.eq("rule_code", ruleCode);
|
||||
JSONObject entity = JSON.parseObject(JSON.toJSONString(impl.getOne(queryWrapper)));
|
||||
// 获取必要的参数
|
||||
String ruleClass = entity.getString("ruleClass");
|
||||
JSONObject params = entity.getJSONObject("ruleParams");
|
||||
if (params == null) {
|
||||
params = new JSONObject();
|
||||
}
|
||||
if (formData == null) {
|
||||
formData = new JSONObject();
|
||||
}
|
||||
// 通过反射执行配置的类里的方法
|
||||
IFillRuleHandler ruleHandler = (IFillRuleHandler) Class.forName(ruleClass).newInstance();
|
||||
return ruleHandler.execute(params, formData);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,121 @@
|
||||
package org.jeecg.common.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
/**
|
||||
* 通过 RESTful 风格的接口操纵 desform 里的数据
|
||||
*
|
||||
* @author sunjianlei
|
||||
*/
|
||||
public class RestDesformUtil {
|
||||
|
||||
private static String domain = null;
|
||||
private static String path = null;
|
||||
|
||||
static {
|
||||
domain = SpringContextUtils.getDomain();
|
||||
path = SpringContextUtils.getApplicationContext().getEnvironment().getProperty("server.servlet.context-path");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据
|
||||
*
|
||||
* @param desformCode
|
||||
* @param dataId
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public static Result queryOne(String desformCode, String dataId, String token) {
|
||||
String url = getBaseUrl(desformCode, dataId).toString();
|
||||
HttpHeaders headers = getHeaders(token);
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, HttpMethod.GET, headers, null, null, JSONObject.class);
|
||||
return packageReturn(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param desformCode
|
||||
* @param formData
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public static Result addOne(String desformCode, JSONObject formData, String token) {
|
||||
return addOrEditOne(desformCode, formData, token, HttpMethod.POST);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param desformCode
|
||||
* @param formData
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public static Result editOne(String desformCode, JSONObject formData, String token) {
|
||||
return addOrEditOne(desformCode, formData, token, HttpMethod.PUT);
|
||||
}
|
||||
|
||||
private static Result addOrEditOne(String desformCode, JSONObject formData, String token, HttpMethod method) {
|
||||
String url = getBaseUrl(desformCode).toString();
|
||||
HttpHeaders headers = getHeaders(token);
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, formData, JSONObject.class);
|
||||
return packageReturn(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param desformCode
|
||||
* @param dataId
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public static Result removeOne(String desformCode, String dataId, String token) {
|
||||
String url = getBaseUrl(desformCode, dataId).toString();
|
||||
HttpHeaders headers = getHeaders(token);
|
||||
ResponseEntity<JSONObject> result = RestUtil.request(url, HttpMethod.DELETE, headers, null, null, JSONObject.class);
|
||||
return packageReturn(result);
|
||||
}
|
||||
|
||||
private static Result packageReturn(ResponseEntity<JSONObject> result) {
|
||||
if (result.getBody() != null) {
|
||||
return result.getBody().toJavaObject(Result.class);
|
||||
}
|
||||
return Result.error("操作失败");
|
||||
}
|
||||
|
||||
private static StringBuilder getBaseUrl() {
|
||||
StringBuilder builder = new StringBuilder(domain).append(path);
|
||||
builder.append("/desform/api");
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static StringBuilder getBaseUrl(String desformCode, String dataId) {
|
||||
StringBuilder builder = getBaseUrl();
|
||||
builder.append("/").append(desformCode);
|
||||
if (dataId != null) {
|
||||
builder.append("/").append(dataId);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static StringBuilder getBaseUrl(String desformCode) {
|
||||
return getBaseUrl(desformCode, null);
|
||||
}
|
||||
|
||||
private static HttpHeaders getHeaders(String token) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
String mediaType = MediaType.APPLICATION_JSON_UTF8_VALUE;
|
||||
headers.setContentType(MediaType.parseMediaType(mediaType));
|
||||
headers.set("Accept", mediaType);
|
||||
headers.set("X-Access-Token", token);
|
||||
return headers;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
package org.jeecg.common.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||
@ -13,13 +14,29 @@ import javax.servlet.http.HttpServletRequest;
|
||||
* @Date 2019/9/23 14:12
|
||||
* @Description: 编程校验token有效性
|
||||
*/
|
||||
@Slf4j
|
||||
public class TokenUtils {
|
||||
|
||||
/**
|
||||
* 获取 request 里传递的 token
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public static String getTokenByRequest(HttpServletRequest request) {
|
||||
String token = request.getParameter("token");
|
||||
if (token == null) {
|
||||
token = request.getHeader("X-Access-Token");
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证Token
|
||||
*/
|
||||
public static boolean verifyToken(HttpServletRequest request, ISysBaseAPI sysBaseAPI, RedisUtil redisUtil) {
|
||||
String token = request.getParameter("token");
|
||||
log.info(" -- url --" + request.getRequestURL());
|
||||
String token = getTokenByRequest(request);
|
||||
|
||||
// 解密获得username,用于和数据库进行对比
|
||||
String username = JwtUtil.getUsername(token);
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package org.jeecg.common.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
@ -28,6 +31,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
* @Author 张代浩
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
public class oConvertUtils {
|
||||
public static boolean isEmpty(Object object) {
|
||||
if (object == null) {
|
||||
@ -588,4 +592,43 @@ public class oConvertUtils {
|
||||
}
|
||||
return select;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将entityList转换成modelList
|
||||
* @param fromList
|
||||
* @param tClass
|
||||
* @param <F>
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static<F,T> List<T> entityListToModelList(List<F> fromList, Class<T> tClass){
|
||||
if(fromList.isEmpty() || fromList == null){
|
||||
return null;
|
||||
}
|
||||
List<T> tList = new ArrayList<>();
|
||||
for(F f : fromList){
|
||||
T t = entityToModel(f, tClass);
|
||||
tList.add(t);
|
||||
}
|
||||
return tList;
|
||||
}
|
||||
|
||||
public static<F,T> T entityToModel(F entity, Class<T> modelClass) {
|
||||
log.debug("entityToModel : Entity属性的值赋值到Model");
|
||||
Object model = null;
|
||||
if (entity == null || modelClass ==null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
model = modelClass.newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
log.error("entityToModel : 实例化异常", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error("entityToModel : 安全权限异常", e);
|
||||
}
|
||||
BeanUtils.copyProperties(entity, model);
|
||||
return (T)model;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,156 @@
|
||||
package org.jeecg.common.util.oss;
|
||||
|
||||
import com.aliyun.oss.ClientConfiguration;
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
|
||||
import com.aliyun.oss.model.CannedAccessControlList;
|
||||
import com.aliyun.oss.model.PutObjectResult;
|
||||
import org.apache.tomcat.util.http.fileupload.FileItemStream;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @Description: 阿里云 oss 上传工具类(高依赖版)
|
||||
* @Date: 2019/5/10
|
||||
*/
|
||||
public class OssBootUtil {
|
||||
|
||||
private static String endPoint;
|
||||
private static String accessKeyId;
|
||||
private static String accessKeySecret;
|
||||
private static String bucketName;
|
||||
private static String staticDomain;
|
||||
|
||||
public static void setEndPoint(String endPoint) {
|
||||
OssBootUtil.endPoint = endPoint;
|
||||
}
|
||||
|
||||
public static void setAccessKeyId(String accessKeyId) {
|
||||
OssBootUtil.accessKeyId = accessKeyId;
|
||||
}
|
||||
|
||||
public static void setAccessKeySecret(String accessKeySecret) {
|
||||
OssBootUtil.accessKeySecret = accessKeySecret;
|
||||
}
|
||||
|
||||
public static void setBucketName(String bucketName) {
|
||||
OssBootUtil.bucketName = bucketName;
|
||||
}
|
||||
|
||||
public static void setStaticDomain(String staticDomain) {
|
||||
OssBootUtil.staticDomain = staticDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* oss 工具客户端
|
||||
*/
|
||||
private static OSSClient ossClient = null;
|
||||
private static String FILE_URL;
|
||||
|
||||
/**
|
||||
* 上传文件至阿里云 OSS
|
||||
* 文件上传成功,返回文件完整访问路径
|
||||
* 文件上传失败,返回 null
|
||||
*
|
||||
* @param file 待上传文件
|
||||
* @param fileDir 文件保存目录
|
||||
* @return oss 中的相对文件路径
|
||||
*/
|
||||
public static String upload(MultipartFile file, String fileDir) {
|
||||
initOSS(endPoint, accessKeyId, accessKeySecret);
|
||||
StringBuilder fileUrl = new StringBuilder();
|
||||
try {
|
||||
String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.'));
|
||||
String fileName = UUID.randomUUID().toString().replace("-", "") + suffix;
|
||||
if (!fileDir.endsWith("/")) {
|
||||
fileDir = fileDir.concat("/");
|
||||
}
|
||||
fileUrl = fileUrl.append(fileDir + fileName);
|
||||
|
||||
FILE_URL = "https://" + bucketName + "." + endPoint + "/" + fileUrl;
|
||||
//FILE_URL = staticDomain + "/" + fileUrl;
|
||||
PutObjectResult result = ossClient.putObject(bucketName, fileUrl.toString(), file.getInputStream());
|
||||
// 设置权限(公开读)
|
||||
ossClient.setBucketAcl(bucketName, CannedAccessControlList.PublicRead);
|
||||
if (result != null) {
|
||||
System.out.println("------OSS文件上传成功------" + fileUrl);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return FILE_URL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传文件至阿里云 OSS
|
||||
* 文件上传成功,返回文件完整访问路径
|
||||
* 文件上传失败,返回 null
|
||||
*
|
||||
* @param file 待上传文件
|
||||
* @param fileDir 文件保存目录
|
||||
* @return oss 中的相对文件路径
|
||||
*/
|
||||
public static String upload(FileItemStream file, String fileDir) {
|
||||
initOSS(endPoint, accessKeyId, accessKeySecret);
|
||||
StringBuilder fileUrl = new StringBuilder();
|
||||
try {
|
||||
String suffix = file.getName().substring(file.getName().lastIndexOf('.'));
|
||||
String fileName = UUID.randomUUID().toString().replace("-", "") + suffix;
|
||||
if (!fileDir.endsWith("/")) {
|
||||
fileDir = fileDir.concat("/");
|
||||
}
|
||||
fileUrl = fileUrl.append(fileDir + fileName);
|
||||
|
||||
FILE_URL = "https://" + bucketName + "." + endPoint + "/" + fileUrl;
|
||||
//FILE_URL = staticDomain + "/" + fileUrl;
|
||||
PutObjectResult result = ossClient.putObject(bucketName, fileUrl.toString(), file.openStream());
|
||||
// 设置权限(公开读)
|
||||
ossClient.setBucketAcl(bucketName, CannedAccessControlList.PublicRead);
|
||||
if (result != null) {
|
||||
System.out.println("------OSS文件上传成功------" + fileUrl);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return FILE_URL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param url
|
||||
*/
|
||||
public static void deleteUrl(String url) {
|
||||
String bucketUrl = "https://" + bucketName + "." + endPoint + "/";
|
||||
//String bucketUrl = staticDomain + "/";
|
||||
url = url.replace(bucketUrl,"");
|
||||
ossClient.deleteObject(bucketName, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param fileName
|
||||
*/
|
||||
public static void delete(String fileName) {
|
||||
ossClient.deleteObject(bucketName, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 oss 客户端
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static OSSClient initOSS(String endpoint, String accessKeyId, String accessKeySecret) {
|
||||
if (ossClient == null) {
|
||||
ossClient = new OSSClient(endpoint,
|
||||
new DefaultCredentialProvider(accessKeyId, accessKeySecret),
|
||||
new ClientConfiguration());
|
||||
}
|
||||
return ossClient;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,78 +0,0 @@
|
||||
package org.jeecg.modules.system.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单权限规则表
|
||||
* </p>
|
||||
*
|
||||
* @Author huangzhilin
|
||||
* @since 2019-03-29
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SysPermissionDataRule implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.ID_WORKER_STR)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 对应的菜单id
|
||||
*/
|
||||
private String permissionId;
|
||||
|
||||
/**
|
||||
* 规则名称
|
||||
*/
|
||||
private String ruleName;
|
||||
|
||||
/**
|
||||
* 字段
|
||||
*/
|
||||
private String ruleColumn;
|
||||
|
||||
/**
|
||||
* 条件
|
||||
*/
|
||||
private String ruleConditions;
|
||||
|
||||
/**
|
||||
* 规则值
|
||||
*/
|
||||
private String ruleValue;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private String updateBy;
|
||||
}
|
||||
Reference in New Issue
Block a user