init
This commit is contained in:
104
jeelowcode-core/pom.xml
Normal file
104
jeelowcode-core/pom.xml
Normal file
@@ -0,0 +1,104 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>jeelowcode</artifactId>
|
||||
<version>${jeelowcode.version}</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>jeelowcode-core</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>${project.artifactId}</name>
|
||||
<version>${jeelowcode.version}</version>
|
||||
<description> JeeLowCode低代码核心代码 </description>
|
||||
|
||||
<dependencies>
|
||||
<!-- Web 相关 -->
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>tool-spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 鉴权 相关 -->
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>tool-spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- DB 相关 -->
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>tool-spring-boot-starter-mybatis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- redis 相关 -->
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>tool-spring-boot-starter-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 租户 相关 -->
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>tool-spring-boot-starter-biz-tenant</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- **************** jeelowcode低代码框架 **************** -->
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>jeelowcode-excel</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>jeelowcode-exception</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>jeelowcode-plus</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>jeelowcode-tenant</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>jeelowcode-utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>jeelowcode-global</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>jeelowcode-ai</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>QLExpress</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.oracle.database.jdbc</groupId>
|
||||
<artifactId>ojdbc8</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>tool-spring-boot-starter-biz-data-permission</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>jeelowcode-service-infra-api</artifactId>
|
||||
<version>${jeelowcode.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jeelowcode</groupId>
|
||||
<artifactId>jeelowcode-module-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,549 @@
|
||||
|
||||
|
||||
package com.jeelowcode.core.framework.adapter;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.jeelowcode.core.framework.entity.FormFieldDictEntity;
|
||||
import com.jeelowcode.framework.tenant.annotation.JeeLowCodeTenantIgnore;
|
||||
import com.jeelowcode.framework.utils.annotation.JeelowCodeCache;
|
||||
import com.jeelowcode.tool.framework.security.core.LoginUser;
|
||||
import com.jeelowcode.tool.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.jeelowcode.tool.framework.tenant.config.TenantProperties;
|
||||
import com.jeelowcode.tool.framework.tenant.core.context.TenantContextHolder;
|
||||
import com.jeelowcode.core.framework.mapper.AdapterMapper;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.framework.plus.SqlHelper;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.wrapper.SqlInfoQueryWrapper;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
|
||||
import com.jeelowcode.framework.utils.enums.DefaultDbFieldEnum;
|
||||
import com.jeelowcode.framework.utils.model.*;
|
||||
import com.jeelowcode.framework.utils.params.JeeLowCodeDeptParam;
|
||||
import com.jeelowcode.framework.utils.params.JeeLowCodeDictParam;
|
||||
import com.jeelowcode.framework.utils.params.JeeLowCodeUserParam;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import com.jeelowcode.framework.utils.utils.JeeLowCodeUtils;
|
||||
import com.jeelowcode.core.framework.service.IFrameSqlService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 芋道源码适配器
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class FrameWorkAdapter implements IJeeLowCodeAdapter {
|
||||
|
||||
@Autowired
|
||||
private IFrameSqlService sqlService;
|
||||
|
||||
@Autowired
|
||||
private TenantProperties tenantProperties;
|
||||
|
||||
@Autowired
|
||||
private AdapterMapper adapterMapper;
|
||||
|
||||
//获取当前在线人id
|
||||
@Override
|
||||
public Long getOnlineUserId() {
|
||||
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
||||
return loginUserId;
|
||||
}
|
||||
|
||||
//获取当前在线人账号
|
||||
@Override
|
||||
public String getOnlineUserName() {
|
||||
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
||||
String userName = adapterMapper.getUserName(loginUserId);
|
||||
return userName;
|
||||
}
|
||||
|
||||
@JeelowCodeCache(cacheNames = "'FrameWorkAdapter:getOnlineUserName:' + #userId", reflexClass = String.class, alwaysEffective = true)
|
||||
@Override
|
||||
public String getOnlineUserName(Long userId) {
|
||||
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
||||
String userName = adapterMapper.getUserName(loginUserId);
|
||||
return userName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOnlineUserNickName() {
|
||||
Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
||||
return adapterMapper.getNickname(loginUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getOnlineUserDeptId() {
|
||||
Long loginDeptId = SecurityFrameworkUtils.getLoginDeptId();
|
||||
return loginDeptId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOnlineUserDeptName() {
|
||||
Long deptId = getOnlineUserDeptId();
|
||||
String deptName = adapterMapper.getDeptName(deptId);
|
||||
return deptName;
|
||||
}
|
||||
|
||||
//获取当前在线人id
|
||||
@Override
|
||||
public Long getTenantId() {
|
||||
//当前线程
|
||||
Long tenantId = TenantContextHolder.getTenantId();
|
||||
if (Func.isNotEmpty(tenantId) && tenantId > 0) {
|
||||
return tenantId;
|
||||
}
|
||||
//当前线程没有租户信息,则从登录用户获取
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
if (FuncBase.isNotEmpty(loginUser)) {
|
||||
return loginUser.getTenantId();
|
||||
}
|
||||
return -1L;
|
||||
}
|
||||
|
||||
//判断请求是否排除多租户
|
||||
@Override
|
||||
public boolean getTenantIsIgnore() {
|
||||
HttpServletRequest request = FuncWeb.getRequest();
|
||||
if (!Func.isJeeLowCodeUrl(request)) {//低代码平台有自己一套租户逻辑
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean ignore = TenantContextHolder.isIgnore();
|
||||
return ignore;
|
||||
}
|
||||
|
||||
//获取所有租户列表
|
||||
@Override
|
||||
public List<JeeLowTenant> getTenantList() {
|
||||
List<String> selectList = new ArrayList<>();
|
||||
selectList.add("id");
|
||||
selectList.add("name");
|
||||
|
||||
SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper()
|
||||
.setTableName("system_tenant")
|
||||
.select(selectList, true)
|
||||
.setWhere(where -> {
|
||||
where.eq("deleted", 0);
|
||||
where.eq("status", 0);
|
||||
}).build();
|
||||
List<Map<String, Object>> tenantList = sqlService.getDataListByPlus(wrapper);
|
||||
|
||||
return tenantList.stream()
|
||||
.map(tenantMap -> {
|
||||
String id = JeeLowCodeUtils.getMap2Str(tenantMap, "id");
|
||||
String name = JeeLowCodeUtils.getMap2Str(tenantMap, "name");
|
||||
JeeLowTenant jeeLowTenant = new JeeLowTenant();
|
||||
jeeLowTenant.setTenantId(id);
|
||||
jeeLowTenant.setTenantName(name);
|
||||
return jeeLowTenant;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
//获取字典列表
|
||||
@Override
|
||||
public List<JeeLowCodeDict> getDictList(JeeLowCodeDictParam param) {
|
||||
List<JeeLowCodeDict> resultList = new ArrayList<>();
|
||||
List<String> dictCodeList = param.getDictCodeList();
|
||||
Map<String, JeeLowCodeDictParam.DictCodeDataParam> paramMap = FuncBase.isEmpty(param.getParamMap()) ? new HashMap<>() : param.getParamMap();
|
||||
|
||||
SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper()
|
||||
.setTableName("system_dict_type")
|
||||
.setWhere(where -> {
|
||||
where.eq("deleted", 0);
|
||||
where.eq("status", 0);
|
||||
where.in("type", dictCodeList);
|
||||
}).build();
|
||||
List<Map<String, Object>> typeList = sqlService.getDataListByPlus(wrapper);
|
||||
|
||||
typeList.stream()
|
||||
.map(typeMap -> {
|
||||
String code = JeeLowCodeUtils.getMap2Str(typeMap, "type");
|
||||
JeeLowCodeDictParam.DictCodeDataParam dictCodeDataParam = paramMap.get(code);
|
||||
|
||||
List<String> dictDataLabelList = FuncBase.isNotEmpty(dictCodeDataParam) ? dictCodeDataParam.getDictDataLabelList() : Collections.emptyList();
|
||||
List<String> dictDataValueList = FuncBase.isNotEmpty(dictCodeDataParam) ? dictCodeDataParam.getDictDataValueList() : Collections.emptyList();
|
||||
|
||||
SqlInfoQueryWrapper.Wrapper wrapperData = SqlHelper.getQueryWrapper()
|
||||
.setTableName("system_dict_data")
|
||||
.select("value", "label")
|
||||
.setWhere(where -> {
|
||||
where.eq("deleted", 0);
|
||||
where.eq("status", 0);
|
||||
where.eq("dict_type", code);
|
||||
where.in("label", dictDataLabelList);
|
||||
where.in("value", dictDataValueList);
|
||||
})
|
||||
.orderByAsc("sort")
|
||||
.build();
|
||||
List<Map<String, Object>> dataList = sqlService.getDataListByPlus(wrapperData);
|
||||
|
||||
List<JeeLowCodeDict.DictData> list = dataList.stream()
|
||||
.map(tmpMap -> {
|
||||
String value = JeeLowCodeUtils.getMap2Str(tmpMap, "value");
|
||||
String label = JeeLowCodeUtils.getMap2Str(tmpMap, "label");
|
||||
|
||||
JeeLowCodeDict.DictData data = new JeeLowCodeDict.DictData();
|
||||
data.setLabel(label);
|
||||
data.setVal(value);
|
||||
return data;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
JeeLowCodeDict dict = new JeeLowCodeDict();
|
||||
dict.setDataList(list);
|
||||
dict.setDictCode(code);
|
||||
return dict;
|
||||
})
|
||||
.forEach(resultList::add);
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
//获取部门列表
|
||||
@Override
|
||||
public List<JeeLowCodeDept> getDeptList(JeeLowCodeDeptParam param) {
|
||||
|
||||
String deptName = param.getDeptName();//部门名称搜索
|
||||
String type = Func.isEmpty(param.getType()) ? "all" : param.getType();
|
||||
List<Long> deptIdList = new ArrayList<>();//部门id列表,为空则查所有
|
||||
if (Func.equals(type, "now")) {//本级
|
||||
deptIdList.add(this.getOnlineUserDeptId());
|
||||
} else if (Func.equals(type, "sub")) {//本级以及下级
|
||||
deptIdList = this.getChildDeptIdList(this.getOnlineUserDeptId(),true);
|
||||
} else if (Func.equals(type, "all_sub")) {//所有下级
|
||||
deptIdList = this.getChildDeptIdList(this.getOnlineUserDeptId(),false);
|
||||
} else if (Func.equals(type, "direct_sub")) {//直接下级
|
||||
deptIdList = this.getDirectChildDeptIdList(this.getOnlineUserDeptId());
|
||||
}
|
||||
|
||||
List<Long> finalDeptIdList = deptIdList;
|
||||
SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper()
|
||||
.select("id", "parent_id", "name")
|
||||
.setTableName("system_dept")
|
||||
.setWhere(where -> {
|
||||
where.in(Func.isNotEmpty(finalDeptIdList), "id", finalDeptIdList);
|
||||
where.like(FuncBase.isNotEmpty(deptName), "name", deptName);
|
||||
where.eq("deleted", 0);
|
||||
})
|
||||
.orderByAsc("sort")
|
||||
.build();
|
||||
List<Map<String, Object>> deptList = sqlService.getDataListByPlus(wrapper);
|
||||
|
||||
List<JeeLowCodeDept> resultList = deptList.stream()
|
||||
.map(deptMap -> {
|
||||
String id = JeeLowCodeUtils.getMap2Str(deptMap, "id");
|
||||
String pid = JeeLowCodeUtils.getMap2Str(deptMap, "parent_id");
|
||||
String name = JeeLowCodeUtils.getMap2Str(deptMap, "name");
|
||||
|
||||
JeeLowCodeDept dept = new JeeLowCodeDept();
|
||||
dept.setDeptId(id);
|
||||
dept.setDeptPid(pid);
|
||||
dept.setDeptName(name);
|
||||
return dept;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
//获取所有角色列表
|
||||
@Override
|
||||
public List<JeeLowCodeRole> getRoleList() {
|
||||
Long tenantId = TenantContextHolder.getTenantId();
|
||||
SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper()
|
||||
.select("id", "name")
|
||||
.setTableName("system_role")
|
||||
.setWhere(where -> {
|
||||
where.in("deleted", 0);
|
||||
where.eq("tenant_id", tenantId);
|
||||
})
|
||||
.orderByAsc("sort")
|
||||
.build();
|
||||
List<Map<String, Object>> roleList = sqlService.getDataListByPlus(wrapper);
|
||||
|
||||
List<JeeLowCodeRole> resultList = roleList.stream()
|
||||
.map(roleMap -> {
|
||||
String id = JeeLowCodeUtils.getMap2Str(roleMap, "id");
|
||||
String name = JeeLowCodeUtils.getMap2Str(roleMap, "name");
|
||||
|
||||
JeeLowCodeRole role = new JeeLowCodeRole();
|
||||
role.setRoleId(id);
|
||||
role.setRoleName(name);
|
||||
return role;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
//获取用户详情
|
||||
@JeeLowCodeTenantIgnore
|
||||
@Override
|
||||
public List<Map<String, Object>> getUserInfoList(List<Long> userIdList) {
|
||||
SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper()
|
||||
.select("id", "username", "nickname", "mobile", "sex")
|
||||
.setTableName("system_users")
|
||||
.setWhere(where -> {
|
||||
where.in("id", userIdList);
|
||||
})
|
||||
.build();
|
||||
List<Map<String, Object>> dataList = sqlService.getDataListByPlus(wrapper);
|
||||
return dataList;
|
||||
}
|
||||
|
||||
//回显用户
|
||||
@JeeLowCodeTenantIgnore
|
||||
@Override
|
||||
public List<Map<String, Object>> getUserViewList(List<Long> userIdList) {
|
||||
SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper()
|
||||
.select("id", "nickname")
|
||||
.setTableName("system_users")
|
||||
.setWhere(where -> {
|
||||
where.in("id", userIdList);
|
||||
})
|
||||
.build();
|
||||
List<Map<String, Object>> dataList = sqlService.getDataListByPlus(wrapper);
|
||||
return dataList;
|
||||
}
|
||||
|
||||
//回显部门
|
||||
@JeeLowCodeTenantIgnore
|
||||
@Override
|
||||
public List<Map<String, Object>> getDeptViewList(List<Long> deptIdList) {
|
||||
SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper()
|
||||
.select("id", "name")
|
||||
.setTableName("system_dept")
|
||||
.setWhere(where -> {
|
||||
where.in("id", deptIdList);
|
||||
})
|
||||
.build();
|
||||
List<Map<String, Object>> dataList = sqlService.getDataListByPlus(wrapper);
|
||||
return dataList;
|
||||
}
|
||||
|
||||
|
||||
//获取用户分页列表
|
||||
@Override
|
||||
public Object getUserPage(Integer pageNo, Integer pageSize, JeeLowCodeUserParam param) {
|
||||
Page page = FuncWeb.getPage(pageNo, pageSize);
|
||||
Long deptId = param.getDeptId();
|
||||
Long roleId = param.getRoleId();
|
||||
String type = param.getType();//all now sub
|
||||
|
||||
String nickName = param.getNickName();
|
||||
String mobile = param.getMobile();
|
||||
List<String> fieldList = param.getFieldList();
|
||||
|
||||
List<Long> deptIdList = new ArrayList<>();//部门id列表
|
||||
if (Func.isEmpty(deptId)) {//部门为空的时候,type才生效
|
||||
if (Func.equals(type, "now")) {//本级
|
||||
deptIdList.add(this.getOnlineUserDeptId());
|
||||
} else if (Func.equals(type, "sub")) {//本级以及下级
|
||||
deptIdList = this.getChildDeptIdList(this.getOnlineUserDeptId(),true);
|
||||
}else if (Func.equals(type, "all_sub")) {//所有下级
|
||||
deptIdList = this.getChildDeptIdList(this.getOnlineUserDeptId(),false);
|
||||
} else if (Func.equals(type, "direct_sub")) {//直接下级
|
||||
deptIdList = this.getDirectChildDeptIdList(this.getOnlineUserDeptId());
|
||||
}
|
||||
} else {//指定部门
|
||||
deptIdList.add(deptId);
|
||||
}
|
||||
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("nickName", nickName);
|
||||
params.put("mobile", mobile);
|
||||
|
||||
IPage<JeeLowCodeUser> pages = null;
|
||||
if (Func.isNotEmpty(roleId)) {//说明有选择了角色
|
||||
pages = adapterMapper.getUserPageByRoleId(getTenantId(), page, roleId, deptIdList, params);
|
||||
} else {
|
||||
pages = adapterMapper.getUserPageByDeptId(getTenantId(), page, deptIdList, params);
|
||||
}
|
||||
if (Func.isEmpty(fieldList)) {//查所有
|
||||
return pages;
|
||||
}
|
||||
|
||||
//存在自定义列
|
||||
Map<String, Consumer<JeeLowCodeUser>> fieldSetters = new HashMap<>();
|
||||
fieldSetters.put("userId", user -> user.setUserId(null));
|
||||
fieldSetters.put("nickName", user -> user.setNickName(null));
|
||||
fieldSetters.put("mobile", user -> user.setMobile(null));
|
||||
fieldSetters.put("email", user -> user.setEmail(null));
|
||||
fieldSetters.put("sex", user -> user.setSex(null));
|
||||
fieldSetters.put("post", user -> user.setPost(null));
|
||||
fieldSetters.put("avatar", user -> user.setAvatar(null));
|
||||
fieldSetters.put("deptName", user -> user.setDeptName(null));
|
||||
fieldSetters.put("deptId", user -> user.setDeptId(null));
|
||||
// 为其他字段添加更多的条目
|
||||
|
||||
List<JeeLowCodeUser> records = pages.getRecords();
|
||||
records.stream().peek(user -> fieldSetters.forEach((fieldName, setter) -> {
|
||||
if (!fieldList.contains(fieldName)) {
|
||||
setter.accept(user);
|
||||
}
|
||||
}))
|
||||
.collect(Collectors.toList());
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getUserPageByUserIds(Integer pageNo, Integer pageSize, List<Long> userIds) {
|
||||
Page page = FuncWeb.getPage(pageNo, pageSize);
|
||||
IPage<JeeLowCodeUser> pages = adapterMapper.getUserPageByUserIds(getTenantId(), page, userIds);
|
||||
return pages;
|
||||
}
|
||||
|
||||
|
||||
//初始化-新增数据默认项
|
||||
@Override
|
||||
public void initSaveDefaultData(Map<String, Object> map) {
|
||||
//默认值由系统赋值,不做修改
|
||||
map.remove(DefaultDbFieldEnum.CREATE_USER.getFieldCode());
|
||||
map.remove(DefaultDbFieldEnum.CREATE_TIME.getFieldCode());
|
||||
map.remove(DefaultDbFieldEnum.CREATE_DEPT.getFieldCode());
|
||||
map.remove(DefaultDbFieldEnum.IS_DELETED.getFieldCode());
|
||||
map.remove(DefaultDbFieldEnum.TENANT_ID.getFieldCode());
|
||||
map.remove(DefaultDbFieldEnum.UPDATE_USER.getFieldCode());
|
||||
map.remove(DefaultDbFieldEnum.UPDATE_TIME.getFieldCode());
|
||||
|
||||
DateTime now = DateUtil.date();
|
||||
|
||||
if (FuncBase.isEmpty(map.get(DefaultDbFieldEnum.ID.getFieldCode()))) {
|
||||
map.put(DefaultDbFieldEnum.ID.getFieldCode(), IdWorker.getId());
|
||||
}
|
||||
|
||||
map.put(DefaultDbFieldEnum.CREATE_USER.getFieldCode(), this.getOnlineUserId());
|
||||
map.put(DefaultDbFieldEnum.CREATE_TIME.getFieldCode(), now);
|
||||
map.put(DefaultDbFieldEnum.CREATE_DEPT.getFieldCode(), this.getOnlineUserDeptId());
|
||||
map.put(DefaultDbFieldEnum.IS_DELETED.getFieldCode(), 0);
|
||||
map.put(DefaultDbFieldEnum.TENANT_ID.getFieldCode(), this.getTenantId());
|
||||
}
|
||||
|
||||
//初始化-修改数据默认项
|
||||
@Override
|
||||
public void initUpdateDefaultData(Map<String, Object> map) {
|
||||
//默认值由系统赋值,不做修改
|
||||
map.remove(DefaultDbFieldEnum.CREATE_USER.getFieldCode());
|
||||
map.remove(DefaultDbFieldEnum.CREATE_TIME.getFieldCode());
|
||||
map.remove(DefaultDbFieldEnum.CREATE_DEPT.getFieldCode());
|
||||
map.remove(DefaultDbFieldEnum.IS_DELETED.getFieldCode());
|
||||
map.remove(DefaultDbFieldEnum.TENANT_ID.getFieldCode());
|
||||
map.remove(DefaultDbFieldEnum.UPDATE_USER.getFieldCode());
|
||||
map.remove(DefaultDbFieldEnum.UPDATE_TIME.getFieldCode());
|
||||
|
||||
DateTime now = DateUtil.date();
|
||||
map.put(DefaultDbFieldEnum.UPDATE_USER.getFieldCode(), this.getOnlineUserId());
|
||||
map.put(DefaultDbFieldEnum.UPDATE_TIME.getFieldCode(), now);
|
||||
|
||||
}
|
||||
|
||||
//获取所有不用租户的表
|
||||
@Override
|
||||
public Set<String> getTenantIgnoreTable() {
|
||||
return tenantProperties.getIgnoreTables();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getTenantIgnoreUrl() {
|
||||
return tenantProperties.getIgnoreUrls().stream()
|
||||
.filter(url -> !url.contains("jeelowcode"))
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
}
|
||||
|
||||
//判断多租户是否启用
|
||||
@Override
|
||||
public boolean getTenantEnable() {
|
||||
return tenantProperties.getEnable();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有子部门
|
||||
* @param id
|
||||
* @param includeNowFlag true=包括本级
|
||||
* @return
|
||||
*/
|
||||
private List<Long> getChildDeptIdList(Long id,boolean includeNowFlag) {
|
||||
List<Long> children = new LinkedList<>();//子集
|
||||
children.add(-1L);//保证不会跳过这个过滤条件
|
||||
if(includeNowFlag){
|
||||
children.add(id);
|
||||
}
|
||||
|
||||
// 遍历每一层
|
||||
List<Long> parentIdList = new ArrayList<>();
|
||||
parentIdList.add(id);
|
||||
|
||||
for (int i = 0; i < Short.MAX_VALUE; i++) { // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环
|
||||
|
||||
List<Long> finalParentIdList = parentIdList;
|
||||
SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper()
|
||||
.select("id")
|
||||
.setTableName("system_dept")
|
||||
.setWhere(where -> {
|
||||
where.eq("deleted", 0);
|
||||
where.in("parent_id", finalParentIdList);
|
||||
})
|
||||
.build();
|
||||
List<Map<String, Object>> deptList = sqlService.getDataListByPlus(wrapper);
|
||||
|
||||
// 1. 如果没有子部门,则结束遍历
|
||||
if (Func.isEmpty(deptList)) {
|
||||
break;
|
||||
}
|
||||
|
||||
List<Long> tmpIdList = deptList.stream()
|
||||
.map(deptMap -> Func.getMap2Long(deptMap, "id"))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
children.addAll(tmpIdList);//存入到总集合里面
|
||||
parentIdList = tmpIdList;//进行下一轮
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
|
||||
//获取直接下级
|
||||
private List<Long> getDirectChildDeptIdList(Long id) {
|
||||
List<Long> children = new LinkedList<>();//子集
|
||||
children.add(-1L);
|
||||
|
||||
// 遍历每一层
|
||||
List<Long> parentIdList = new ArrayList<>();
|
||||
parentIdList.add(id);
|
||||
List<Long> finalParentIdList = parentIdList;
|
||||
SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper()
|
||||
.select("id")
|
||||
.setTableName("system_dept")
|
||||
.setWhere(where -> {
|
||||
where.eq("deleted", 0);
|
||||
where.in("parent_id", finalParentIdList);
|
||||
})
|
||||
.build();
|
||||
List<Map<String, Object>> deptList = sqlService.getDataListByPlus(wrapper);
|
||||
|
||||
// 1. 如果没有子部门,则结束遍历
|
||||
if (Func.isEmpty(deptList)) {
|
||||
return children;
|
||||
}
|
||||
|
||||
List<Long> tmpIdList = deptList.stream()
|
||||
.map(deptMap -> Func.getMap2Long(deptMap, "id"))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
children.addAll(tmpIdList);//存入到总集合里面
|
||||
return children;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,683 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.BuildSqlEnhanceContext;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceParam;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceResult;
|
||||
import com.jeelowcode.core.framework.entity.EnhanceSqlEntity;
|
||||
import com.jeelowcode.core.framework.mapper.JeeLowCodeMapper;
|
||||
import com.jeelowcode.core.framework.mapper.JeeLowCodeSqlMapper;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
|
||||
import com.jeelowcode.framework.plus.SqlHelper;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.wrapper.SqlInfoQueryWrapper;
|
||||
import com.jeelowcode.framework.plus.core.model.SqlFormatModel;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
|
||||
import com.jeelowcode.framework.utils.constant.JeeLowCodeConstant;
|
||||
import com.jeelowcode.framework.utils.enums.JeeLowCodeFieldTypeEnum;
|
||||
import com.jeelowcode.framework.utils.enums.ParamEnum;
|
||||
import com.jeelowcode.framework.utils.enums.QueryModelEnum;
|
||||
import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import com.jeelowcode.framework.utils.utils.JeeLowCodeUtils;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.jeelowcode.core.framework.config.aspect.enhance.JeeLowCodeAnnotationAspectjJAVA.EXPRESSION;
|
||||
import static com.jeelowcode.core.framework.config.aspect.enhance.JeeLowCodeAnnotationAspectjJAVA.aspectMethodNameMap;
|
||||
import static com.jeelowcode.framework.utils.constant.EnhanceConstant.*;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-19 13:46
|
||||
* @dedescription:
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class JeeLowCodeAnnoaionAspectjSQL {
|
||||
|
||||
|
||||
@Autowired
|
||||
private IJeeLowCodeAdapter jeeLowCodeAdapter;
|
||||
|
||||
@Autowired
|
||||
private JeeLowCodeSqlMapper sqlMapper;
|
||||
|
||||
@Autowired
|
||||
private JeeLowCodeMapper jeeLowCodeMapper;
|
||||
|
||||
private static Map<String, List<EnhanceSqlEntity>> sqlPlugins = new HashMap<>();
|
||||
|
||||
|
||||
@AfterReturning(value = EXPRESSION, returning = "returnVal")
|
||||
public Object afterReturingAdvice(JoinPoint joinPoint, Object returnVal) {
|
||||
BuildSqlEnhanceContext contextAndPlugins = getContextAndPlugins(joinPoint, returnVal);
|
||||
if (FuncBase.isEmpty(contextAndPlugins)) {
|
||||
return returnVal;
|
||||
}
|
||||
EnhanceContext context = contextAndPlugins.getContext();
|
||||
//判断结果类型
|
||||
ExecuteEnhanceModel formModel = null; //表单类
|
||||
ResultDataModel listModel = null; //查询类
|
||||
|
||||
Boolean resultFlag = false;
|
||||
if (Func.isNotEmpty(returnVal) && returnVal instanceof ExecuteEnhanceModel) {//表单类
|
||||
formModel = (ExecuteEnhanceModel) returnVal;
|
||||
resultFlag = true;
|
||||
}
|
||||
if (Func.isNotEmpty(returnVal) && returnVal instanceof ResultDataModel) {//列表类
|
||||
listModel = (ResultDataModel) returnVal;
|
||||
}
|
||||
|
||||
//把结果放到上下文中再执行插件
|
||||
if (resultFlag) {
|
||||
String id = formModel.getId();
|
||||
context.getResult().setId(id);
|
||||
context.getResult().setExitFlag(formModel.isExitFlag());
|
||||
} else {
|
||||
context.getResult().setRecords(listModel.getRecords());
|
||||
context.getResult().setTotal(listModel.getTotal());
|
||||
context.getResult().setExitFlag(listModel.isExitFlag());
|
||||
}
|
||||
|
||||
//集合操作的插件
|
||||
List<EnhanceSqlEntity> setOperations = contextAndPlugins.getSetOperations();
|
||||
if (CollectionUtils.isNotEmpty(setOperations)) {
|
||||
//执行
|
||||
executeEnhanceSetOperation(context, setOperations);
|
||||
listModel.setTotal(context.getResult().getTotal());
|
||||
listModel.setRecords(context.getResult().getRecords());
|
||||
}
|
||||
|
||||
//所有sql增强
|
||||
List<EnhanceSqlEntity> enhanceSqlEntityList = contextAndPlugins.getEntitys();
|
||||
|
||||
for (EnhanceSqlEntity enhanceSqlEntity : enhanceSqlEntityList) {
|
||||
if (setOperations.contains(enhanceSqlEntity)) {
|
||||
continue;
|
||||
}
|
||||
this.executSQLPlugin(context, enhanceSqlEntity);
|
||||
if (FuncBase.isNotEmpty(context.getResult()) && context.getResult().isExitFlag()) {
|
||||
listModel.setTotal(context.getResult().getTotal());
|
||||
listModel.setRecords(context.getResult().getRecords());
|
||||
return listModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (resultFlag) {//结果类型
|
||||
ExecuteEnhanceModel executeEnhanceModel = new ExecuteEnhanceModel();
|
||||
executeEnhanceModel.setId(context.getResult().getId());
|
||||
return executeEnhanceModel;
|
||||
} else {
|
||||
listModel.setTotal(context.getResult().getTotal());
|
||||
listModel.setRecords(context.getResult().getRecords());
|
||||
}
|
||||
return listModel;
|
||||
}
|
||||
|
||||
public BuildSqlEnhanceContext getContextAndPlugins(JoinPoint joinPoint, Object returnVal) {
|
||||
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
|
||||
// 获取方法名称
|
||||
String methodName = methodSignature.getName();
|
||||
if (!aspectMethodNameMap.containsKey(methodName)) {//不在拦截范围内 add
|
||||
return null;
|
||||
}
|
||||
Object[] args = joinPoint.getArgs();
|
||||
LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
|
||||
String[] parameterNames = discoverer.getParameterNames(methodSignature.getMethod());
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
for (int i = 0; i < parameterNames.length; i++) {
|
||||
paramMap.put(parameterNames[i], args[i]);
|
||||
}
|
||||
|
||||
Long dbFormId = (Long) paramMap.getOrDefault("dbFormId", null);
|
||||
Long dataId = (Long) paramMap.getOrDefault("id", null);
|
||||
Page page = (Page) paramMap.getOrDefault("page", null);
|
||||
|
||||
String buttonCode = aspectMethodNameMap.get(methodName);
|
||||
String key = dbFormId + "_" + buttonCode;
|
||||
List<EnhanceSqlEntity> allPlugins = sqlPlugins.getOrDefault(key, null);
|
||||
if (Func.isEmpty(allPlugins)) {
|
||||
return null;
|
||||
}
|
||||
List<EnhanceSqlEntity> setOperation = new ArrayList<>();
|
||||
if (FuncBase.isNotEmpty(allPlugins)) {
|
||||
setOperation = allPlugins.stream()
|
||||
.filter(enhanceSqlEntity -> (FuncBase.equals(enhanceSqlEntity.getButtonCode(), ENHANCE_LIST) ||
|
||||
FuncBase.equals(enhanceSqlEntity.getButtonCode(), ENHANCE_EXPORT)))
|
||||
.collect(Collectors.toList());
|
||||
if (setOperation.size() < 2) {
|
||||
//如果只有一条,则直接执行,不用走集合操作
|
||||
setOperation.clear();
|
||||
}
|
||||
}
|
||||
List<Map<String, Object>> dataList = new ArrayList<>();
|
||||
if (returnVal instanceof ResultDataModel) {
|
||||
dataList = ((ResultDataModel) returnVal).getRecords();
|
||||
}
|
||||
EnhanceContext context = new EnhanceContext();
|
||||
Map<String, Object> params = JeeLowCodeUtils.getMap2Map(paramMap, "params");
|
||||
context.setParam(dbFormId, params, dataList, dataId, page);
|
||||
context.setResult(new EnhanceResult());
|
||||
return new BuildSqlEnhanceContext(context, allPlugins, setOperation);
|
||||
}
|
||||
|
||||
public static void initSqlPlugins(Map<String, List<EnhanceSqlEntity>> initSQLPlugins) {
|
||||
sqlPlugins = initSQLPlugins;
|
||||
}
|
||||
|
||||
public void executSQLPlugin(EnhanceContext context, EnhanceSqlEntity enhanceSqlEntity) {
|
||||
|
||||
switch (enhanceSqlEntity.getButtonCode()) {
|
||||
case ENHANCE_ADD:
|
||||
//新增
|
||||
this.executeEnhanceAfterAdd(context, enhanceSqlEntity);
|
||||
break;
|
||||
case ENHANCE_DELETE:
|
||||
//删除
|
||||
this.executeEnhanceAfterDelete(context, enhanceSqlEntity);
|
||||
break;
|
||||
case ENHANCE_EDIT:
|
||||
//编辑
|
||||
this.executeEnhanceAfterEdit(context, enhanceSqlEntity);
|
||||
break;
|
||||
case ENHANCE_DETAIL:
|
||||
//详情
|
||||
this.executeEnhanceAfterDetail(context, enhanceSqlEntity);
|
||||
break;
|
||||
case ENHANCE_IMPORT:
|
||||
//导入
|
||||
this.executeEnhanceAfterImport(context, enhanceSqlEntity);
|
||||
break;
|
||||
case ENHANCE_LIST:
|
||||
//列表 前端只保留了一个
|
||||
Map<String, Object> params = context.getParam().getParams();
|
||||
Integer pageSize = JeeLowCodeUtils.getMap2Integer(params, "pageSize");
|
||||
if (Func.isEmpty(pageSize) || pageSize == -1 || Func.equals(pageSize, JeeLowCodeConstant.NOT_PAGE)) {
|
||||
this.executeEnhanceAfterList(context, enhanceSqlEntity);
|
||||
} else {
|
||||
this.executeEnhanceAfterPage(context, enhanceSqlEntity);
|
||||
}
|
||||
break;
|
||||
case ENHANCE_PAGE:
|
||||
//分页
|
||||
this.executeEnhanceAfterPage(context, enhanceSqlEntity);
|
||||
break;
|
||||
case ENHANCE_EXPORT:
|
||||
//导出
|
||||
this.executeEnhanceAfterExport(context, enhanceSqlEntity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//新增
|
||||
public void executeEnhanceAfterAdd(EnhanceContext context, EnhanceSqlEntity sqlEntity) {
|
||||
Long dbFormId = context.getParam().getDbFormId();
|
||||
Map<String, Object> paramMap = context.getParam().getParams();
|
||||
if (FuncBase.isNotEmpty(context.getParam().getDataId())) {//把id放入到参数
|
||||
paramMap.put("id", context.getParam().getDataId());
|
||||
}
|
||||
|
||||
this.executeSql(sqlEntity.getExecuteSql(), paramMap);
|
||||
|
||||
}
|
||||
|
||||
//删除
|
||||
public void executeEnhanceAfterDelete(EnhanceContext context, EnhanceSqlEntity sqlEntity) {
|
||||
EnhanceParam param = context.getParam();
|
||||
Map<String, Object> params = param.getParams();
|
||||
List<Long> dataIdList = (List<Long>) params.getOrDefault("dataIdList", null);
|
||||
|
||||
String executeSql = sqlEntity.getExecuteSql();
|
||||
if (FuncBase.isEmpty(executeSql)) {
|
||||
return;
|
||||
}
|
||||
//因为是批量删除的,需要拆分出来
|
||||
for (Long dataId : dataIdList) {
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put("id", dataId);
|
||||
|
||||
//执行sql
|
||||
this.executeSql(executeSql, dataMap);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//编辑
|
||||
public void executeEnhanceAfterEdit(EnhanceContext context, EnhanceSqlEntity sqlEntity) {
|
||||
Long dataId = context.getParam().getDataId();
|
||||
Map<String, Object> paramMap = context.getParam().getParams();
|
||||
|
||||
paramMap.put("id", dataId);//把id放到json里面传递
|
||||
|
||||
this.executeSql(sqlEntity.getExecuteSql(), paramMap);
|
||||
|
||||
}
|
||||
|
||||
//详情
|
||||
public void executeEnhanceAfterDetail(EnhanceContext context, EnhanceSqlEntity sqlEntity) {
|
||||
|
||||
Long dbFormId = context.getParam().getDbFormId();
|
||||
Long id = (Long) context.getParam().getDataId();
|
||||
Map<String, Object> params = context.getParam().getParams();
|
||||
params.put("id", id);//把id放入参数集
|
||||
|
||||
String autoWhereSql = this.getAutoWhereSql(dbFormId, params);
|
||||
|
||||
String executeSql = sqlEntity.getExecuteSql();
|
||||
List<Map<String, Object>> dataMapList = this.executeSelectListSql(executeSql, params, autoWhereSql);
|
||||
context.setResult(ResultDataModel.fomatList(dataMapList));
|
||||
|
||||
}
|
||||
|
||||
//导入
|
||||
public void executeEnhanceAfterImport(EnhanceContext context, EnhanceSqlEntity sqlEntity) {
|
||||
|
||||
Map<String, Object> paramMap = context.getParam().getParams();
|
||||
|
||||
this.executeSql(sqlEntity.getExecuteSql(), paramMap);
|
||||
}
|
||||
|
||||
//列表
|
||||
public void executeEnhanceAfterList(EnhanceContext context, EnhanceSqlEntity sqlEntity) {
|
||||
Long dbFormId = context.getParam().getDbFormId();
|
||||
Map<String, Object> params = context.getParam().getParams();
|
||||
String executeSql = sqlEntity.getExecuteSql();
|
||||
|
||||
String autoWhereSql = this.getAutoWhereSql(dbFormId, params);
|
||||
List<Map<String, Object>> dataMapList = this.executeSelectListSql(executeSql, params, autoWhereSql);
|
||||
context.getResult().setRecords(dataMapList);
|
||||
context.getResult().setExitFlag(true);
|
||||
}
|
||||
|
||||
// 分页
|
||||
public void executeEnhanceAfterPage(EnhanceContext context, EnhanceSqlEntity sqlEntity) {
|
||||
Long dbFormId = context.getParam().getDbFormId();
|
||||
Map<String, Object> params = context.getParam().getParams();
|
||||
Integer pageNo = JeeLowCodeUtils.getMap2Integer(params, "pageNo");
|
||||
Integer pageSize = JeeLowCodeUtils.getMap2Integer(params, "pageSize");
|
||||
Page page = FuncWeb.getPage(pageNo, pageSize);
|
||||
String executeSql = sqlEntity.getExecuteSql();
|
||||
String autoWhereSql = this.getAutoWhereSql(dbFormId, params);
|
||||
IPage<Map<String, Object>> pages = this.executeSelectPageSql(executeSql, params, autoWhereSql, page);
|
||||
FuncWeb.setPageResult(context, pages);
|
||||
}
|
||||
|
||||
//导出
|
||||
public void executeEnhanceAfterExport(EnhanceContext context, EnhanceSqlEntity sqlEntity) {
|
||||
Long dbFormId = context.getParam().getDbFormId();
|
||||
Map<String, Object> params = context.getParam().getParams();
|
||||
String executeSql = sqlEntity.getExecuteSql();
|
||||
|
||||
String autoWhereSql = this.getAutoWhereSql(dbFormId, params);
|
||||
List<Map<String, Object>> dataMapList = this.executeSelectListSql(executeSql, params, autoWhereSql);
|
||||
if (FuncBase.isEmpty(dataMapList)) {
|
||||
dataMapList = new ArrayList<>();
|
||||
}
|
||||
context.getResult().setRecords(dataMapList);
|
||||
context.getResult().setExitFlag(true);
|
||||
}
|
||||
|
||||
//执行集合操作
|
||||
public void executeEnhanceSetOperation(EnhanceContext context, List<EnhanceSqlEntity> sqlEntitys) {
|
||||
sqlEntitys.sort(Comparator.comparing(EnhanceSqlEntity::getSort, Comparator.nullsLast(Integer::compareTo)));
|
||||
for (int i = 0; i < sqlEntitys.size() - 1; i++) {
|
||||
EnhanceSqlEntity leftEntity = null;
|
||||
EnhanceSqlEntity rightEntity = null;
|
||||
if (i == 0) {
|
||||
leftEntity = sqlEntitys.get(i);
|
||||
rightEntity = sqlEntitys.get(i + 1);
|
||||
} else {
|
||||
rightEntity = sqlEntitys.get(i + 1);
|
||||
}
|
||||
switch (rightEntity.getListResultHandleType()) {
|
||||
case "1":
|
||||
//执行合集操作
|
||||
executSetOperationOr(leftEntity, rightEntity, context);
|
||||
break;
|
||||
case "2":
|
||||
//执行差集操作
|
||||
executSetOperationDiffer(leftEntity, rightEntity, context);
|
||||
break;
|
||||
case "3":
|
||||
//执行并集操作
|
||||
executSetOperationUnion(leftEntity, rightEntity, context);
|
||||
break;
|
||||
case "4":
|
||||
//执行交集操作
|
||||
executSetOperationInterSerction(leftEntity, rightEntity, context);
|
||||
break;
|
||||
default:
|
||||
case "0":
|
||||
//执行串行操作
|
||||
executSetOperationAnd(leftEntity, rightEntity, context);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//执行合集操作
|
||||
private void executSetOperationOr(EnhanceSqlEntity leftEntity, EnhanceSqlEntity rightEntity, EnhanceContext context) {
|
||||
List<Map<String, Object>> leftRecords;
|
||||
if (FuncBase.isNotEmpty(leftEntity)) {
|
||||
EnhanceContext leftContext = context.clone();
|
||||
executSQLPlugin(leftContext, leftEntity);
|
||||
leftRecords = leftContext.getResult().getRecords();
|
||||
} else {
|
||||
leftRecords = context.getResult().getRecords();
|
||||
}
|
||||
EnhanceContext rightContext = context.clone();
|
||||
executSQLPlugin(rightContext, rightEntity);
|
||||
List<Map<String, Object>> rightRecords = rightContext.getResult().getRecords();
|
||||
CollectionUtils.addAll(leftRecords, rightRecords);
|
||||
context.getResult().setRecords(leftRecords);
|
||||
|
||||
}
|
||||
|
||||
private void executSetOperationDiffer(EnhanceSqlEntity leftEntity, EnhanceSqlEntity rightEntity, EnhanceContext context) {
|
||||
List<Map<String, Object>> differ;
|
||||
List<Map<String, Object>> leftRecords;
|
||||
if (FuncBase.isNotEmpty(leftEntity)) {
|
||||
EnhanceContext leftContext = context.clone();
|
||||
executSQLPlugin(leftContext, leftEntity);
|
||||
leftRecords = leftContext.getResult().getRecords();
|
||||
} else {
|
||||
leftRecords = context.getResult().getRecords();
|
||||
}
|
||||
EnhanceContext rightContext = context.clone();
|
||||
executSQLPlugin(rightContext, rightEntity);
|
||||
List<Map<String, Object>> rightRecords = rightContext.getResult().getRecords();
|
||||
differ = (List<Map<String, Object>>) CollectionUtils.subtract(leftRecords, rightRecords);
|
||||
context.getResult().setRecords(differ);
|
||||
|
||||
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
//并集
|
||||
public void executSetOperationUnion(EnhanceSqlEntity leftEntity, EnhanceSqlEntity rightEntity, EnhanceContext context) {
|
||||
List<Map<String, Object>> union;
|
||||
List<Map<String, Object>> leftRecords;
|
||||
if (FuncBase.isNotEmpty(leftEntity)) {
|
||||
EnhanceContext leftContext = context.clone();
|
||||
executSQLPlugin(leftContext, leftEntity);
|
||||
leftRecords = leftContext.getResult().getRecords();
|
||||
} else {
|
||||
leftRecords = context.getResult().getRecords();
|
||||
}
|
||||
EnhanceContext rightContext = context.clone();
|
||||
executSQLPlugin(rightContext, rightEntity);
|
||||
List<Map<String, Object>> rightRecords = rightContext.getResult().getRecords();
|
||||
union = (List<Map<String, Object>>) CollectionUtils.union(leftRecords, rightRecords);
|
||||
context.getResult().setRecords(union);
|
||||
}
|
||||
|
||||
//交集
|
||||
public void executSetOperationInterSerction(EnhanceSqlEntity leftEntity, EnhanceSqlEntity rightEntity, EnhanceContext context) {
|
||||
List<Map<String, Object>> intersection;
|
||||
List<Map<String, Object>> leftRecords;
|
||||
if (FuncBase.isNotEmpty(leftEntity)) {
|
||||
EnhanceContext leftContext = context.clone();
|
||||
executSQLPlugin(leftContext, leftEntity);
|
||||
leftRecords = leftContext.getResult().getRecords();
|
||||
} else {
|
||||
leftRecords = context.getResult().getRecords();
|
||||
}
|
||||
EnhanceContext rightContext = context.clone();
|
||||
executSQLPlugin(rightContext, rightEntity);
|
||||
List<Map<String, Object>> rightRecords = rightContext.getResult().getRecords();
|
||||
intersection = (List<Map<String, Object>>) CollectionUtils.intersection(leftRecords, rightRecords);
|
||||
context.getResult().setRecords(intersection);
|
||||
}
|
||||
|
||||
//串行
|
||||
public void executSetOperationAnd(EnhanceSqlEntity leftEntity, EnhanceSqlEntity rightEntity, EnhanceContext context) {
|
||||
executSQLPlugin(context, leftEntity);
|
||||
executSQLPlugin(context, rightEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自动构建where的语句
|
||||
*
|
||||
* @param dbFormId
|
||||
* @return
|
||||
*/
|
||||
public String getAutoWhereSql(Long dbFormId, Map<String, Object> params) {
|
||||
SqlInfoQueryWrapper.Wrapper queryWrapper = SqlHelper.getQueryWrapper();
|
||||
|
||||
List<Map<String, String>> whereFieldMapList = jeeLowCodeMapper.getDbWhereFieldList(dbFormId);
|
||||
|
||||
//没有搜索条件
|
||||
if (FuncBase.isEmpty(whereFieldMapList)) {
|
||||
SqlFormatModel sqlFormatModel = queryWrapper.buildSql();
|
||||
String whereSql = sqlFormatModel.getSql();
|
||||
Map<String, Object> paramMap = sqlFormatModel.getDataMap();
|
||||
if (Func.isNotEmpty(paramMap)) {
|
||||
params.putAll(paramMap);
|
||||
}
|
||||
whereSql = whereSql.substring(6);//因为是where开头要去掉
|
||||
return whereSql;
|
||||
}
|
||||
|
||||
//如果是多选的时候,要做特殊处理,因为多选的时候 ,数据库存储的是 11,22,33
|
||||
String moreSelectFieldListStr = (String) params.get(ParamEnum.MORE_SELECT_FIELD.getCode());
|
||||
List<String> moreSelectFieldList = null;
|
||||
if (FuncBase.isNotEmpty(moreSelectFieldListStr)) {
|
||||
moreSelectFieldList = FuncBase.toStrList(moreSelectFieldListStr);
|
||||
}
|
||||
|
||||
for (Map<String, String> whereFieldMap : whereFieldMapList) {
|
||||
String field_code = whereFieldMap.get("field_code");//字段
|
||||
String field_type = whereFieldMap.get("field_type");//类型
|
||||
String query_mode = whereFieldMap.get("query_mode");//EQ LIKE
|
||||
Object obj = params.get(field_code);
|
||||
if (FuncBase.isEmpty(obj)) {
|
||||
continue;
|
||||
}
|
||||
JeeLowCodeFieldTypeEnum fieldTypeEnum = JeeLowCodeFieldTypeEnum.getByFieldType(field_type);
|
||||
switch (fieldTypeEnum) {
|
||||
case DATE:
|
||||
obj = DateUtil.parse(Func.toStr(obj), "yyyy-MM-dd");
|
||||
break;
|
||||
case DATETIME:
|
||||
obj = DateUtil.parse(Func.toStr(obj), "yyyy-MM-dd HH:mm:ss");
|
||||
break;
|
||||
case TIME:
|
||||
obj = DateUtil.parse(Func.toStr(obj), "HH:mm:ss");
|
||||
break;
|
||||
}
|
||||
Object finalObj = obj;
|
||||
//类型转换 111,22,33
|
||||
if (FuncBase.equals(query_mode, QueryModelEnum.EQ.getCode())) {//精确
|
||||
if (FuncBase.isNotEmpty(moreSelectFieldList) && moreSelectFieldList.contains(field_code)) {//在多选里面
|
||||
|
||||
queryWrapper.setWhere(where -> {
|
||||
where.and(w -> w.eq(field_code, finalObj)
|
||||
.or().likeLeft(field_code, "," + finalObj)
|
||||
.or().likeRight(field_code, finalObj + ",")
|
||||
.or().like(field_code, "," + finalObj + ","));
|
||||
});
|
||||
} else {
|
||||
queryWrapper.setWhere(where -> {
|
||||
where.eq(field_code, finalObj);
|
||||
});
|
||||
}
|
||||
|
||||
} else if (FuncBase.equals(query_mode, QueryModelEnum.RANGE.getCode())) {//范围
|
||||
String listStr = FuncBase.toStr(obj);
|
||||
List<String> paramList = FuncBase.toStrList(listStr);// 1<=x<2
|
||||
Object leftVal = paramList.get(0);
|
||||
Object rightVal = paramList.get(1);
|
||||
if (FuncBase.equals(field_type, JeeLowCodeFieldTypeEnum.BIGINT)) {//防止大整型出现精度问题
|
||||
leftVal = FuncBase.toLong(leftVal);
|
||||
rightVal = FuncBase.toLong(rightVal);
|
||||
}
|
||||
if (FuncBase.isNotEmpty(leftVal) && FuncBase.isNotEmpty(rightVal)) {
|
||||
Object finalLeftVal = leftVal;
|
||||
Object finalRightVal = rightVal;
|
||||
queryWrapper.setWhere(where -> {
|
||||
where.between(field_code, finalLeftVal, finalRightVal);//区间
|
||||
});
|
||||
} else if (FuncBase.isNotEmpty(leftVal)) {//>=
|
||||
Object finalLeftVal1 = leftVal;
|
||||
queryWrapper.setWhere(where -> {
|
||||
where.ge(field_code, finalLeftVal1);
|
||||
});
|
||||
} else if (FuncBase.isNotEmpty(rightVal)) {//<=
|
||||
Object finalRightVal1 = rightVal;
|
||||
queryWrapper.setWhere(where -> {
|
||||
where.le(field_code, finalRightVal1);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
queryWrapper.setWhere(where -> {
|
||||
where.like(field_code, finalObj);
|
||||
});
|
||||
}
|
||||
}
|
||||
SqlFormatModel sqlFormatModel = queryWrapper.buildSql();
|
||||
|
||||
String whereSql = sqlFormatModel.getSql();
|
||||
if (FuncBase.isEmpty(whereSql)) {
|
||||
return whereSql;
|
||||
}
|
||||
Map<String, Object> paramMap = sqlFormatModel.getDataMap();
|
||||
if (Func.isNotEmpty(paramMap)) {
|
||||
params.putAll(paramMap);
|
||||
}
|
||||
whereSql = whereSql.substring(6);//因为是where开头要去掉
|
||||
return whereSql;
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行增删改
|
||||
*
|
||||
* @param executeSql
|
||||
* @param paramMap
|
||||
* @throws Throwable
|
||||
*/
|
||||
public void executeSql(String executeSql, Map<String, Object> paramMap) {
|
||||
String sql = this.getSql(executeSql, paramMap);
|
||||
this.execute(sql, paramMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行查询
|
||||
*
|
||||
* @param executeSql
|
||||
* @param paramMap
|
||||
* @return
|
||||
* @throws Throwable
|
||||
*/
|
||||
public List<Map<String, Object>> executeSelectListSql(String executeSql, Map<String, Object> paramMap, String autoWhereSql) {
|
||||
String sql = this.getSql(executeSql, paramMap, autoWhereSql);
|
||||
Object obj = this.execute(sql, paramMap);
|
||||
return (List<Map<String, Object>>) obj;
|
||||
}
|
||||
|
||||
//分页
|
||||
public IPage<Map<String, Object>> executeSelectPageSql(String executeSql, Map<String, Object> paramMap, String autoWhereSql, Page page) {
|
||||
String sql = this.getSql(executeSql, paramMap, autoWhereSql);
|
||||
Object obj = this.execute(sql, paramMap, page);
|
||||
return (IPage<Map<String, Object>>) obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取执行sql
|
||||
*
|
||||
* @param executeSql
|
||||
* @param paramMap
|
||||
* @return
|
||||
*/
|
||||
private String getSql(String executeSql, Map<String, Object> paramMap) {
|
||||
return this.getSql(executeSql, paramMap, null);
|
||||
}
|
||||
|
||||
private String getSql(String executeSql, Map<String, Object> paramMap, String autoWhereSql) {
|
||||
|
||||
//替换参数
|
||||
executeSql = Func.replaceParam(executeSql, paramMap, autoWhereSql, jeeLowCodeAdapter);
|
||||
|
||||
return executeSql.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行sql
|
||||
*
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
private Object execute(String sql, Map<String, Object> dataMap) {
|
||||
return execute(sql, dataMap, null);
|
||||
}
|
||||
|
||||
private Object execute(String sql, Map<String, Object> dataMap, Page page) {
|
||||
sql = sql.trim();
|
||||
//执行sql
|
||||
if (sql.startsWith("insert") || sql.startsWith("INSERT")) {
|
||||
sqlMapper.insertData(JeeLowCodeBaseConstant.DS_MASTER,sql, dataMap);
|
||||
} else if (sql.startsWith("update") || sql.startsWith("UPDATE")) {
|
||||
sqlMapper.updateData(JeeLowCodeBaseConstant.DS_MASTER,sql, dataMap);
|
||||
} else if (sql.startsWith("delete") || sql.startsWith("DELETE")) {
|
||||
sqlMapper.deleteData(JeeLowCodeBaseConstant.DS_MASTER,sql, dataMap);
|
||||
} else if (sql.startsWith("select") || sql.startsWith("SELECT")) {
|
||||
if (FuncBase.isNotEmpty(page)) {
|
||||
return sqlMapper.selectPageData(JeeLowCodeBaseConstant.DS_MASTER,page, sql, dataMap);
|
||||
}
|
||||
return sqlMapper.selectData(JeeLowCodeBaseConstant.DS_MASTER,sql, dataMap);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 新增增强
|
||||
public static void addPlugin(EnhanceSqlEntity sqlEntity) {
|
||||
String key = sqlEntity.getDbformId() + "_" + sqlEntity.getButtonCode();
|
||||
sqlPlugins.merge(key, new ArrayList<>(Collections.singletonList(sqlEntity)), (oldValue, newValue) -> {
|
||||
oldValue.addAll(newValue);
|
||||
return oldValue;
|
||||
});
|
||||
}
|
||||
|
||||
// 修改增强
|
||||
public static void updatePlugin(EnhanceSqlEntity sqlEntity) {
|
||||
String key = sqlEntity.getDbformId() + "_" + sqlEntity.getButtonCode();
|
||||
sqlPlugins.merge(key, new ArrayList<>(Collections.singletonList(sqlEntity)), (oldValue, newValue) -> {
|
||||
// 先删除再新增
|
||||
oldValue.removeIf(enhanceSql -> FuncBase.equals(enhanceSql.getId(), sqlEntity.getId()));
|
||||
oldValue.add(sqlEntity);
|
||||
return oldValue;
|
||||
});
|
||||
}
|
||||
|
||||
// 删除增强
|
||||
public static void removePlugin(EnhanceSqlEntity sqlEntity) {
|
||||
String key = sqlEntity.getDbformId() + "_" + sqlEntity.getButtonCode();
|
||||
List<EnhanceSqlEntity> sqlEntityList = sqlPlugins.getOrDefault(key, new ArrayList<>());
|
||||
// id相同则删除
|
||||
sqlEntityList.removeIf(enhanceSqlEntity -> sqlEntity.getId().equals(enhanceSqlEntity.getId()));
|
||||
if (FuncBase.isEmpty(sqlEntityList)) {
|
||||
sqlPlugins.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,740 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance;
|
||||
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.criteria.*;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.*;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.plugin.*;
|
||||
import com.jeelowcode.core.framework.config.listener.JeeLowCodeListener;
|
||||
import com.jeelowcode.core.framework.entity.EnhanceJavaEntity;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeException;
|
||||
import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import groovy.lang.GroovyObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.*;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.jeelowcode.framework.utils.constant.EnhanceConstant.ENHANCE_EXPORT;
|
||||
import static com.jeelowcode.framework.utils.constant.EnhanceConstant.ENHANCE_LIST;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-12 10:26
|
||||
* @dedescription:
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class JeeLowCodeAnnotationAspectjJAVA {
|
||||
|
||||
public final static String EXPRESSION = "execution(* com.jeelowcode.core.framework.service.impl.FrameServiceImpl.*(..))";
|
||||
|
||||
//需要处理的增强
|
||||
private static Map<String, List<EnhanceJavaEntity>> pluginNames = new HashMap<>();
|
||||
|
||||
//需要处理的切面方法
|
||||
public static Map<String, String> aspectMethodNameMap = new HashMap<>();
|
||||
|
||||
@Autowired
|
||||
private JeeLowCodeListener jeeLowCodeListener;
|
||||
|
||||
@Before(value = EXPRESSION)
|
||||
public void before(JoinPoint joinPoint) throws Throwable {
|
||||
|
||||
BuildEnhanceContext buildEnhanceContext = this.getContextAndPlugins("start",joinPoint);//
|
||||
if (FuncBase.isEmpty(buildEnhanceContext)) {
|
||||
return;
|
||||
}
|
||||
List<EnhanceJavaEntity> enhanceJavaEntityList = buildEnhanceContext.getEntitys();
|
||||
if (Func.isEmpty(enhanceJavaEntityList)) {
|
||||
return;
|
||||
}
|
||||
EnhanceContext context = buildEnhanceContext.getContext();
|
||||
//执行增强
|
||||
for (EnhanceJavaEntity enhanceJavaEntity : enhanceJavaEntityList) {
|
||||
this.executeEnhance(enhanceJavaEntity, context, JavaEnhanceEventState.START.getName(), joinPoint);
|
||||
if (FuncBase.isNotEmpty(context.getResult()) && context.getResult().isExitFlag()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@AfterReturning(value = EXPRESSION, returning = "returnVal")
|
||||
public Object afterReturning(JoinPoint joinPoint, Object returnVal) throws Throwable {
|
||||
//获取参数
|
||||
BuildEnhanceContext buildEnhanceContext = this.getContextAndPlugins("end",joinPoint);
|
||||
if (FuncBase.isEmpty(buildEnhanceContext)) {
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
if (!(returnVal instanceof ResultDataModel) && !(returnVal instanceof ExecuteEnhanceModel)) {
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
List<EnhanceJavaEntity> enhanceJavaEntityList = buildEnhanceContext.getEntitys();
|
||||
if (Func.isEmpty(enhanceJavaEntityList)) {//无增强
|
||||
return returnVal;
|
||||
}
|
||||
EnhanceContext context = buildEnhanceContext.getContext();
|
||||
boolean resultFlag = false;
|
||||
//封装返回值
|
||||
if (returnVal instanceof ResultDataModel) {//列表相关
|
||||
ResultDataModel resultDataModel = (ResultDataModel) returnVal;
|
||||
EnhanceResult enhanceResult = new EnhanceResult();
|
||||
enhanceResult.setRecords(resultDataModel.getRecords());
|
||||
enhanceResult.setTotal(resultDataModel.getTotal());
|
||||
context.getParam().setList(resultDataModel.getRecords());
|
||||
context.setResult(enhanceResult);
|
||||
resultFlag = true;
|
||||
} else if (returnVal instanceof ExecuteEnhanceModel) {//新增,修改,删除
|
||||
ExecuteEnhanceModel executeEnhanceModel = (ExecuteEnhanceModel) returnVal;
|
||||
EnhanceResult enhanceResult = new EnhanceResult();
|
||||
enhanceResult.setId(executeEnhanceModel.getId());
|
||||
enhanceResult.setExitFlag(executeEnhanceModel.isExitFlag());
|
||||
context.setResult(enhanceResult);
|
||||
}
|
||||
|
||||
//集合操作
|
||||
List<EnhanceJavaEntity> setOperations = buildEnhanceContext.getSetOperations();
|
||||
|
||||
executeSetOperation(context, setOperations);
|
||||
//执行插件
|
||||
for (EnhanceJavaEntity enhanceJavaEntity : enhanceJavaEntityList) {
|
||||
//里面集合存在,不用执行
|
||||
if (Func.isNotEmpty(setOperations) && setOperations.contains(enhanceJavaEntity)){
|
||||
continue;
|
||||
}
|
||||
this.executeEnhance(enhanceJavaEntity, context, JavaEnhanceEventState.END.getName(), joinPoint);
|
||||
if (FuncBase.isNotEmpty(context.getResult()) && context.getResult().isExitFlag()) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//返回结果
|
||||
Object result = getResult(context);
|
||||
if (resultFlag) {
|
||||
ResultDataModel returnValData = (ResultDataModel) returnVal;
|
||||
ResultDataModel resultDataModel = (ResultDataModel) result;
|
||||
returnValData.setRecords(resultDataModel.getRecords());
|
||||
returnValData.setTotal(resultDataModel.getTotal());
|
||||
return returnValData;
|
||||
} else {
|
||||
ExecuteEnhanceModel returnValData = (ExecuteEnhanceModel) returnVal;
|
||||
ExecuteEnhanceModel resultDataModel = (ExecuteEnhanceModel) result;
|
||||
returnValData.setId(resultDataModel.getId());
|
||||
return returnValData;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Around(value = EXPRESSION)
|
||||
public Object aroudAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
BuildEnhanceContext buildEnhanceContext = this.getContextAndPlugins("around",joinPoint);
|
||||
if (FuncBase.isEmpty(buildEnhanceContext)) {
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
List<EnhanceJavaEntity> enhanceJavaEntityList = buildEnhanceContext.getEntitys();
|
||||
if (Func.isEmpty(enhanceJavaEntityList)) {
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
EnhanceContext context = buildEnhanceContext.getContext();
|
||||
|
||||
|
||||
for (EnhanceJavaEntity enhanceJavaEntity : enhanceJavaEntityList) {
|
||||
this.executeEnhance(enhanceJavaEntity, context, JavaEnhanceEventState.AROUND.getName(), joinPoint);
|
||||
|
||||
if (FuncBase.isNotEmpty(context.getResult()) && context.getResult().isExitFlag()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return getResult(context);
|
||||
}
|
||||
|
||||
@AfterThrowing(value = EXPRESSION, throwing = "ex")
|
||||
public void afterThrowing(JoinPoint joinPoint, Exception ex) throws Throwable {
|
||||
BuildEnhanceContext buildEnhanceContext = this.getContextAndPlugins("throwing",joinPoint);
|
||||
if (FuncBase.isEmpty(buildEnhanceContext)) {
|
||||
return;
|
||||
}
|
||||
List<EnhanceJavaEntity> enhanceJavaEntityList = buildEnhanceContext.getEntitys();
|
||||
if (Func.isEmpty(enhanceJavaEntityList)) {
|
||||
return;
|
||||
}
|
||||
EnhanceContext context = buildEnhanceContext.getContext();
|
||||
for (EnhanceJavaEntity enhanceJavaEntity : enhanceJavaEntityList) {
|
||||
this.executeEnhance(enhanceJavaEntity, context, JavaEnhanceEventState.THROWING.getName(), joinPoint);
|
||||
if (FuncBase.isNotEmpty(context.getResult()) && context.getResult().isExitFlag()) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void initPluginNames(Map<String, List<EnhanceJavaEntity>> initPluginNames) {
|
||||
pluginNames = initPluginNames;
|
||||
}
|
||||
|
||||
public static void initAspectMethodNameMap(Map<String, String> initAspectMethodNameMap) {
|
||||
aspectMethodNameMap = initAspectMethodNameMap;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type start end around throwing
|
||||
* @param joinPoint
|
||||
* @return
|
||||
*/
|
||||
public BuildEnhanceContext getContextAndPlugins(String type,JoinPoint joinPoint) {
|
||||
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
|
||||
// 获取方法名称
|
||||
String methodName = methodSignature.getName();
|
||||
if (!aspectMethodNameMap.containsKey(methodName)) {//不在拦截范围内 add
|
||||
return null;
|
||||
}
|
||||
//处理参数
|
||||
Object[] args = joinPoint.getArgs();
|
||||
LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
|
||||
String[] parameterNames = discoverer.getParameterNames(methodSignature.getMethod());
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
for (int i = 0; i < parameterNames.length; i++) {
|
||||
paramMap.put(parameterNames[i], args[i]);
|
||||
}
|
||||
|
||||
//判断该表单,当前的功能是否有增强
|
||||
Long dbFormId = (Long) paramMap.get("dbFormId");
|
||||
String buttonCode = aspectMethodNameMap.get(methodName);
|
||||
String key = dbFormId + "_" + buttonCode;
|
||||
List<EnhanceJavaEntity> enhanceJavaEntityAllList = pluginNames.getOrDefault(key, null);
|
||||
if (Func.isEmpty(enhanceJavaEntityAllList)) {//不存在增强
|
||||
return null;
|
||||
}
|
||||
//获取专属增强
|
||||
List<EnhanceJavaEntity> enhanceJavaEntityList=new ArrayList<>();
|
||||
for(EnhanceJavaEntity javaEntity:enhanceJavaEntityAllList){
|
||||
String javaClassUrl = javaEntity.getJavaClassUrl();//
|
||||
String javaType = javaEntity.getJavaType();
|
||||
BaseAdvicePlugin plugin = PluginManager.getPlugin(javaClassUrl);//只有class spring 方式
|
||||
switch (type) {
|
||||
case "start"://前置增强
|
||||
if (!(plugin instanceof BeforeAdvicePlugin)) {
|
||||
break;
|
||||
}
|
||||
enhanceJavaEntityList.add(javaEntity);
|
||||
break;
|
||||
case "end"://后置增强
|
||||
if (!(plugin instanceof AfterAdvicePlugin)) {
|
||||
break;
|
||||
}
|
||||
enhanceJavaEntityList.add(javaEntity);
|
||||
break;
|
||||
case "around":
|
||||
//如果是在线编辑和http增强,只有环绕
|
||||
if (FuncBase.equals(javaType, JavaEnhanceEnum.ONLINIE.getType())) {
|
||||
//执行在线增强
|
||||
enhanceJavaEntityList.add(javaEntity);
|
||||
break;
|
||||
} else if (FuncBase.equals(javaType, JavaEnhanceEnum.HTTP.getType())) {
|
||||
//执行http增强
|
||||
enhanceJavaEntityList.add(javaEntity);
|
||||
break;
|
||||
}
|
||||
if (!(plugin instanceof AroundAdvicePlugin)) {
|
||||
break;
|
||||
}
|
||||
enhanceJavaEntityList.add(javaEntity);
|
||||
break;
|
||||
case "throwing":
|
||||
enhanceJavaEntityList.add(javaEntity);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//判断是否是列表,导出增强
|
||||
List<EnhanceJavaEntity> setOperation = enhanceJavaEntityList.stream()
|
||||
.filter(enhanceJavaEntity -> (FuncBase.equals(enhanceJavaEntity.getButtonCode(), ENHANCE_LIST) ||
|
||||
FuncBase.equals(enhanceJavaEntity.getButtonCode(), ENHANCE_EXPORT)) && FuncBase.isNotEmpty(PluginManager.getPlugin(enhanceJavaEntity)))
|
||||
.collect(Collectors.toList());
|
||||
if (setOperation.size() < 2) {
|
||||
//如果只有一条,则直接执行,不用走集合操作
|
||||
setOperation.clear();
|
||||
}
|
||||
|
||||
|
||||
EnhanceParam param = new EnhanceParam();
|
||||
param.setDbFormId(dbFormId);
|
||||
param.setDataId((Long)paramMap.getOrDefault("id", null));
|
||||
param.setList((ArrayList) paramMap.getOrDefault("dataList", null));
|
||||
param.setParams((Map<String, Object>) paramMap.getOrDefault("params", null));
|
||||
|
||||
//把参数放入到上下文
|
||||
EnhanceContext context = new EnhanceContext();
|
||||
context.setParam(param);
|
||||
|
||||
BuildEnhanceContext buildEnhanceContext = new BuildEnhanceContext(context, enhanceJavaEntityList, setOperation);
|
||||
return buildEnhanceContext;
|
||||
}
|
||||
|
||||
//执行增强
|
||||
public void executeEnhance(EnhanceJavaEntity enhanceJavaEntity, EnhanceContext context, String type, JoinPoint joinPoint) throws Throwable {
|
||||
String javaType = enhanceJavaEntity.getJavaType();
|
||||
if (FuncBase.equals(javaType, JavaEnhanceEnum.SPRING.getType()) || (FuncBase.equals(javaType, JavaEnhanceEnum.CLASS.getType()))) {
|
||||
//执行spring增强与class增强
|
||||
this.executeSpringEnhance(enhanceJavaEntity, type, context, joinPoint);
|
||||
|
||||
} else if (FuncBase.equals(javaType, JavaEnhanceEnum.ONLINIE.getType())) {
|
||||
//执行在线增强
|
||||
this.executeOnLineScript(enhanceJavaEntity, type, context, joinPoint);
|
||||
|
||||
} else if (FuncBase.equals(javaType, JavaEnhanceEnum.HTTP.getType())) {
|
||||
//执行http增强
|
||||
this.executeHttpEnhance(enhanceJavaEntity, type, context, joinPoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 执行spring增强
|
||||
*/
|
||||
private void executeSpringEnhance(EnhanceJavaEntity enhanceJavaEntity, String type, EnhanceContext context, JoinPoint joinPoint) throws Throwable {
|
||||
String javaClassUrl = enhanceJavaEntity.getJavaClassUrl();//
|
||||
BaseAdvicePlugin plugin = PluginManager.getPlugin(javaClassUrl);
|
||||
switch (type) {
|
||||
case "start"://前置增强
|
||||
if (!(plugin instanceof BeforeAdvicePlugin)) {
|
||||
break;
|
||||
}
|
||||
//执行
|
||||
PluginManager.executePlugin(javaClassUrl, context);
|
||||
break;
|
||||
case "end"://后置增强
|
||||
if (!(plugin instanceof AfterAdvicePlugin)) {
|
||||
break;
|
||||
}
|
||||
//执行
|
||||
PluginManager.executePlugin(javaClassUrl, context);
|
||||
break;
|
||||
case "around":
|
||||
if (!(plugin instanceof AroundAdvicePlugin)) {
|
||||
break;
|
||||
}
|
||||
|
||||
//环绕-前置
|
||||
PluginManager.executeAroundBeforePlugin(plugin, context);
|
||||
|
||||
if (Func.isEmpty(context.getResult())) {
|
||||
context.setResult(new EnhanceResult());
|
||||
}
|
||||
if (context.getResult().isExitFlag()) {//说明终止,不用往下走
|
||||
break;
|
||||
}
|
||||
|
||||
//执行原方法
|
||||
ProceedingJoinPoint proceedingJoinPoint = (ProceedingJoinPoint) joinPoint;
|
||||
Object proceed = proceedingJoinPoint.proceed();
|
||||
if (proceed instanceof ResultDataModel) {
|
||||
EnhanceResult enhanceResult = context.getResult();
|
||||
enhanceResult.setRecords(((ResultDataModel) proceed).getRecords());
|
||||
enhanceResult.setTotal(((ResultDataModel) proceed).getTotal());
|
||||
} else if (proceed instanceof ExecuteEnhanceModel) {
|
||||
EnhanceResult enhanceResult = context.getResult();
|
||||
enhanceResult.setId(((ExecuteEnhanceModel) proceed).getId());
|
||||
}
|
||||
|
||||
//环绕-后置
|
||||
PluginManager.executeAroundAfterPlugin(plugin, context);
|
||||
break;
|
||||
case "throwing":
|
||||
if (!(plugin instanceof ThrowAdvicePlugin)) {
|
||||
break;
|
||||
}
|
||||
PluginManager.executePlugin(javaClassUrl, context);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 执行Online增强---只有环绕增强
|
||||
*/
|
||||
private void executeOnLineScript(EnhanceJavaEntity enhanceJavaEntity, String type, EnhanceContext context, JoinPoint joinPoint) throws Throwable {
|
||||
if (!FuncBase.equals(type, JavaEnhanceEventState.AROUND.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Class<?> onlineClass = jeeLowCodeListener.getGroovyClassLoader().parseClass(enhanceJavaEntity.getOnlineScript());
|
||||
GroovyObject groovyObject = (GroovyObject) onlineClass.newInstance();
|
||||
groovyObject.invokeMethod("beforeExecute", context);
|
||||
|
||||
//只有前置
|
||||
if (context.getOnlyBefore()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//执行原方法
|
||||
ProceedingJoinPoint proceedingJointpoint = (ProceedingJoinPoint) joinPoint;
|
||||
Object proceed = proceedingJointpoint.proceed();
|
||||
if (proceed instanceof ResultDataModel) {
|
||||
EnhanceResult enhanceResult = context.getResult();
|
||||
enhanceResult.setRecords(((ResultDataModel) proceed).getRecords());
|
||||
enhanceResult.setTotal(((ResultDataModel) proceed).getTotal());
|
||||
} else if (proceed instanceof ExecuteEnhanceModel) {
|
||||
EnhanceResult enhanceResult = context.getResult();
|
||||
enhanceResult.setId(((ExecuteEnhanceModel) proceed).getId());
|
||||
}
|
||||
groovyObject.invokeMethod("afterExecute", context);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void executeHttpEnhance(EnhanceJavaEntity enhanceJavaEntity, String type, EnhanceContext context, JoinPoint joinPoint) {
|
||||
if (!FuncBase.equals(type, JavaEnhanceEventState.AROUND.getName())) {
|
||||
return;
|
||||
}
|
||||
context.setBefore(true);
|
||||
String accept = null;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
accept = Func.sendPost(enhanceJavaEntity.getJavaClassUrl(), context);
|
||||
|
||||
EnhanceRespModel respBody = Func.json2Bean(accept, EnhanceRespModel.class);
|
||||
if (respBody.checkStatus()) {
|
||||
context = respBody.getData();
|
||||
context.setBefore(false);
|
||||
break;
|
||||
}
|
||||
Map<String, Object> errorMap = new HashMap<>();
|
||||
errorMap.put("body", Func.json2Str(context));
|
||||
errorMap.put("url", enhanceJavaEntity.getJavaClassUrl());
|
||||
errorMap.put("respBody", Func.json2Str(respBody));
|
||||
|
||||
log.error("发送HTTP增强失败:" + Func.json2Str(errorMap));
|
||||
Thread.sleep(2000);//休息2秒
|
||||
} catch (Exception e) {
|
||||
log.error("发送HTTP增强失败-e:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (context.getOnlyBefore()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
ProceedingJoinPoint proceedingJointpoint = (ProceedingJoinPoint) joinPoint;
|
||||
Object proceed = proceedingJointpoint.proceed();
|
||||
if (proceed instanceof ResultDataModel) {
|
||||
EnhanceResult enhanceResult = context.getResult();
|
||||
enhanceResult.setRecords(((ResultDataModel) proceed).getRecords());
|
||||
enhanceResult.setTotal(((ResultDataModel) proceed).getTotal());
|
||||
} else if (proceed instanceof ExecuteEnhanceModel) {
|
||||
EnhanceResult enhanceResult = context.getResult();
|
||||
enhanceResult.setId(((ExecuteEnhanceModel) proceed).getId());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
throw new JeeLowCodeException("发送HTTP增强失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
accept = Func.sendPost(enhanceJavaEntity.getJavaClassUrl(), context);
|
||||
|
||||
EnhanceRespModel respBody = Func.json2Bean(accept, EnhanceRespModel.class);
|
||||
if (respBody.checkStatus()) {
|
||||
context = respBody.getData();
|
||||
break;
|
||||
}
|
||||
Map<String, Object> errorMap = new HashMap<>();
|
||||
errorMap.put("body", Func.json2Str(context));
|
||||
errorMap.put("url", enhanceJavaEntity.getJavaClassUrl());
|
||||
errorMap.put("respBody", Func.json2Str(respBody));
|
||||
|
||||
log.error("发送HTTP增强失败:" + Func.json2Str(errorMap));
|
||||
Thread.sleep(2000);//休息2秒
|
||||
} catch (Exception e) {
|
||||
log.error("发送HTTP增强失败-e:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void executeSetOperation(EnhanceContext context, List<EnhanceJavaEntity> javaEntityList) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
if (Func.isEmpty(javaEntityList) || javaEntityList.size() < 2) {
|
||||
return;
|
||||
}
|
||||
//只有后置增强才有集合操作
|
||||
List<EnhanceJavaEntity> afterJavaList = javaEntityList.stream().filter(javaEntity -> {
|
||||
Object o = null;
|
||||
if (Func.equals(JavaEnhanceEnum.SPRING.getType(), javaEntity.getJavaType())) {
|
||||
o = SpringUtils.getBean(javaEntity.getJavaClassUrl());
|
||||
} else if (Func.equals(JavaEnhanceEnum.CLASS.getType(), javaEntity.getJavaType())) {
|
||||
try {
|
||||
o = Class.forName(javaEntity.getJavaClassUrl()).newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException ignored) {}
|
||||
}
|
||||
return o instanceof AfterAdvicePlugin;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
if (Func.isEmpty(afterJavaList) || afterJavaList.size() < 2) {
|
||||
if (Func.isNotEmpty(afterJavaList)) {
|
||||
javaEntityList.removeAll(afterJavaList);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//根据序号排序
|
||||
afterJavaList.sort(
|
||||
Comparator.comparing(
|
||||
EnhanceJavaEntity::getSort, Comparator.nullsLast(Integer::compareTo)));
|
||||
|
||||
|
||||
for (int i = 0; i < afterJavaList.size() - 1; i++) {
|
||||
EnhanceJavaEntity leftEntity = null;
|
||||
EnhanceJavaEntity rightEntity = null;
|
||||
if (i == 0) {
|
||||
leftEntity = afterJavaList.get(i);
|
||||
rightEntity = afterJavaList.get(i + 1);
|
||||
} else {
|
||||
rightEntity = afterJavaList.get(i + 1);
|
||||
}
|
||||
|
||||
switch (rightEntity.getListResultHandleType()) {
|
||||
case "1":
|
||||
//执行合集操作
|
||||
executSetOperationOr(leftEntity, rightEntity, context);
|
||||
break;
|
||||
case "2":
|
||||
//执行差集操作
|
||||
executSetOperationDiffer(leftEntity, rightEntity, context);
|
||||
break;
|
||||
case "3":
|
||||
//执行并集操作
|
||||
executSetOperationUnion(leftEntity, rightEntity, context);
|
||||
break;
|
||||
case "4":
|
||||
//执行交集操作
|
||||
executSetOperationInterSerction(leftEntity, rightEntity, context);
|
||||
break;
|
||||
default:
|
||||
case "0":
|
||||
//执行串行操作
|
||||
executSetOperationAnd(leftEntity, rightEntity, context);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//串行
|
||||
private void executSetOperationAnd(EnhanceJavaEntity leftEntity, EnhanceJavaEntity rightEntity, EnhanceContext context) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
|
||||
AfterAdvicePlugin leftPlugin = judgeLeftPlugin(leftEntity);
|
||||
AfterAdvicePlugin rightPlugin = (AfterAdvicePlugin)PluginManager.getPlugin(rightEntity);
|
||||
AndCriteriaFilterAdvicePlugin andAdvicePlugin = new AndCriteriaFilterAdvicePlugin(leftPlugin, rightPlugin);
|
||||
andAdvicePlugin.execute(context);
|
||||
|
||||
}
|
||||
|
||||
//合集
|
||||
private void executSetOperationOr(EnhanceJavaEntity leftEntity, EnhanceJavaEntity rightEntity, EnhanceContext context) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
AfterAdvicePlugin leftPlugin = judgeLeftPlugin(leftEntity);
|
||||
AfterAdvicePlugin rightPlugin = (AfterAdvicePlugin)PluginManager.getPlugin(rightEntity);
|
||||
OrCriteriaFilterAdvicePlugin orAdvicePlugin = new OrCriteriaFilterAdvicePlugin(leftPlugin, rightPlugin);
|
||||
orAdvicePlugin.execute(context);
|
||||
|
||||
}
|
||||
|
||||
//差集
|
||||
private void executSetOperationDiffer(EnhanceJavaEntity leftEntity, EnhanceJavaEntity rightEntity, EnhanceContext context) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
AfterAdvicePlugin leftPlugin = judgeLeftPlugin(leftEntity);
|
||||
AfterAdvicePlugin rightPlugin = (AfterAdvicePlugin)PluginManager.getPlugin(rightEntity);
|
||||
DifferenceCriteriaFilterAdvicePlugin differPlugin = new DifferenceCriteriaFilterAdvicePlugin(leftPlugin, rightPlugin);
|
||||
differPlugin.execute(context);
|
||||
}
|
||||
|
||||
//并集
|
||||
private void executSetOperationUnion(EnhanceJavaEntity leftEntity, EnhanceJavaEntity rightEntity, EnhanceContext context) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
|
||||
AfterAdvicePlugin leftPlugin = judgeLeftPlugin(leftEntity);
|
||||
AfterAdvicePlugin rightPlugin = (AfterAdvicePlugin)PluginManager.getPlugin(rightEntity);
|
||||
UnionCriteriaFilterAdvicePlugin unionPlugin = new UnionCriteriaFilterAdvicePlugin(leftPlugin, rightPlugin);
|
||||
unionPlugin.execute(context);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//交集
|
||||
private void executSetOperationInterSerction(EnhanceJavaEntity leftEntity, EnhanceJavaEntity rightEntity, EnhanceContext context) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||
AfterAdvicePlugin leftPlugin = judgeLeftPlugin(leftEntity);
|
||||
AfterAdvicePlugin rightPlugin = (AfterAdvicePlugin)PluginManager.getPlugin(rightEntity);
|
||||
IntersectionCriteriaFilterAdvicePlugin intersectionPlugin = new IntersectionCriteriaFilterAdvicePlugin(leftPlugin, rightPlugin);
|
||||
intersectionPlugin.execute(context);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Object getResult(EnhanceContext context) {
|
||||
if (Func.isEmpty(context.getResult().getRecords()) && FuncBase.isEmpty(context.getResult().getId())) {
|
||||
return ResultDataModel.fomat(0L, new ArrayList<>());
|
||||
}
|
||||
if (FuncBase.isEmpty(context.getResult().getRecords())) {
|
||||
ExecuteEnhanceModel enhanceModel = new ExecuteEnhanceModel();
|
||||
enhanceModel.setId(context.getResult().getId());
|
||||
enhanceModel.setExitFlag(context.getResult().isExitFlag());
|
||||
|
||||
return enhanceModel;
|
||||
} else {
|
||||
|
||||
ResultDataModel resultDataModel = new ResultDataModel();
|
||||
resultDataModel.setRecords(context.getResult().getRecords());
|
||||
resultDataModel.setTotal(context.getResult().getTotal());
|
||||
resultDataModel.setExitFlag(context.getResult().isExitFlag());
|
||||
return resultDataModel;
|
||||
}
|
||||
}
|
||||
|
||||
//判断左边是否为空
|
||||
public AfterAdvicePlugin judgeLeftPlugin(EnhanceJavaEntity leftEntity) {
|
||||
AfterAdvicePlugin leftPlugin = null;
|
||||
if (FuncBase.isNotEmpty(leftEntity)) {
|
||||
leftPlugin = (AfterAdvicePlugin)PluginManager.getPlugin(leftEntity);
|
||||
} else {
|
||||
leftPlugin = enhanceContext -> {
|
||||
};
|
||||
}
|
||||
return leftPlugin;
|
||||
}
|
||||
|
||||
//新增增强
|
||||
public static void addPlugin(EnhanceJavaEntity javaEntity){
|
||||
try {
|
||||
String key = javaEntity.getDbformId()+"_"+javaEntity.getButtonCode();
|
||||
// 1.处理 pluginNames
|
||||
pluginNames.merge(key, new ArrayList<>(Collections.singletonList(javaEntity)), (oldValue, newValue) -> {
|
||||
oldValue.addAll(newValue);
|
||||
return oldValue;
|
||||
});
|
||||
|
||||
// 2.处理 plugins
|
||||
if (Func.equals(javaEntity.getJavaType(), JavaEnhanceEnum.SPRING.getType())){
|
||||
String javaClassUrl = javaEntity.getJavaClassUrl();
|
||||
Object bean = SpringUtils.getBean(javaClassUrl);
|
||||
if (Func.isNotEmpty(bean) && bean instanceof BaseAdvicePlugin) {
|
||||
PluginManager.addPlugin(javaClassUrl, (BaseAdvicePlugin) bean);
|
||||
}
|
||||
}else if (Func.equals(javaEntity.getJavaType(), JavaEnhanceEnum.CLASS.getType())){
|
||||
Class<?> enhanceClass = Class.forName(javaEntity.getJavaClassUrl());
|
||||
BaseAdvicePlugin plugin = (BaseAdvicePlugin) enhanceClass.newInstance();
|
||||
PluginManager.addPlugin(javaEntity.getJavaClassUrl(), plugin);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new JeeLowCodeException("增强插件加载失败");
|
||||
}
|
||||
}
|
||||
|
||||
//修改增强
|
||||
public static void updatePlugins(EnhanceJavaEntity javaEntity){
|
||||
try {
|
||||
String key = javaEntity.getDbformId()+"_"+javaEntity.getButtonCode();
|
||||
AtomicReference<String> oldJavaClassUrlAtomicRe = new AtomicReference<>();
|
||||
// 1.处理 pluginNames
|
||||
pluginNames.merge(key, new ArrayList<>(Collections.singletonList(javaEntity)), (oldValue, newValue) -> {
|
||||
// 先删除再新增
|
||||
oldValue.removeIf(oldJavaEntity -> {
|
||||
if (FuncBase.equals(oldJavaEntity.getId(), javaEntity.getId())) {
|
||||
oldJavaClassUrlAtomicRe.set(oldJavaEntity.getJavaClassUrl());
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
oldValue.add(javaEntity);
|
||||
return oldValue;
|
||||
});
|
||||
|
||||
// 2.处理 plugins 先删除再新增
|
||||
removePlugins(oldJavaClassUrlAtomicRe.get());
|
||||
String javaType = javaEntity.getJavaType();
|
||||
String javaClassUrl = javaEntity.getJavaClassUrl();
|
||||
if (Func.equals(javaType, JavaEnhanceEnum.SPRING.getType())){
|
||||
Object bean = SpringUtils.getBean(javaClassUrl);
|
||||
if (Func.isNotEmpty(bean) && bean instanceof BaseAdvicePlugin) {
|
||||
PluginManager.addPlugin(javaClassUrl, (BaseAdvicePlugin) bean);
|
||||
}
|
||||
}else if (Func.equals(javaType, JavaEnhanceEnum.CLASS.getType())){
|
||||
Class<?> enhanceClass = Class.forName(javaClassUrl);
|
||||
BaseAdvicePlugin plugin = (BaseAdvicePlugin) enhanceClass.newInstance();
|
||||
PluginManager.addPlugin(javaClassUrl, plugin);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new JeeLowCodeException("增强插件加载失败");
|
||||
}
|
||||
}
|
||||
|
||||
//删除增强
|
||||
public static void deletePlugins(EnhanceJavaEntity javaEntity){
|
||||
String key = javaEntity.getDbformId() + "_" + javaEntity.getButtonCode();
|
||||
// 1.处理 pluginNames
|
||||
List<EnhanceJavaEntity> javaEntityList = pluginNames.getOrDefault(key, new ArrayList<>());
|
||||
AtomicReference<String> oldJavaClassUrlAtomicRe = new AtomicReference<>();
|
||||
javaEntityList.removeIf(oldJavaEntity -> {
|
||||
if (oldJavaEntity.getId().equals(javaEntity.getId())) {
|
||||
oldJavaClassUrlAtomicRe.set(oldJavaEntity.getJavaClassUrl());
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (FuncBase.isEmpty(javaEntityList)) {
|
||||
pluginNames.remove(key);
|
||||
}
|
||||
|
||||
// 2.处理 plugins
|
||||
removePlugins(oldJavaClassUrlAtomicRe.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 plugins 中的增强
|
||||
*/
|
||||
private static void removePlugins(String oldJavaClassUrl){
|
||||
if (Func.isEmpty(oldJavaClassUrl)) {
|
||||
return;
|
||||
}
|
||||
Set<String> JavaClassUrlSet = pluginNames.values().stream().flatMap(Collection::stream)
|
||||
.map(EnhanceJavaEntity::getJavaClassUrl).collect(Collectors.toSet());
|
||||
if (!JavaClassUrlSet.contains(oldJavaClassUrl)) {
|
||||
PluginManager.removePlugin(oldJavaClassUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.criteria;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.plugin.AfterAdvicePlugin;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-20 10:37
|
||||
* @dedescription:
|
||||
*/
|
||||
public class AndCriteriaFilterAdvicePlugin extends BaseCriterFilterAdvicePlugin implements AfterAdvicePlugin {
|
||||
|
||||
public AndCriteriaFilterAdvicePlugin(AfterAdvicePlugin leftCriterFilter, AfterAdvicePlugin rightCriterFilter) {
|
||||
super(leftCriterFilter,rightCriterFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(EnhanceContext enhanceContext) {
|
||||
leftCriterFilter.execute(enhanceContext);
|
||||
rightCriterFilter.execute(enhanceContext);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.criteria;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.plugin.AfterAdvicePlugin;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-19 14:48
|
||||
* @dedescription: 基础过滤条件
|
||||
*/
|
||||
public class BaseCriterFilterAdvicePlugin {
|
||||
|
||||
|
||||
public AfterAdvicePlugin leftCriterFilter;
|
||||
|
||||
public AfterAdvicePlugin rightCriterFilter;
|
||||
|
||||
public BaseCriterFilterAdvicePlugin(AfterAdvicePlugin leftCriterFilter, AfterAdvicePlugin rightCriterFilter) {
|
||||
|
||||
this.leftCriterFilter = leftCriterFilter;
|
||||
this.rightCriterFilter = rightCriterFilter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.criteria;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceResult;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.plugin.AfterAdvicePlugin;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-19 14:52
|
||||
* @dedescription: 差集
|
||||
*/
|
||||
public class DifferenceCriteriaFilterAdvicePlugin extends BaseCriterFilterAdvicePlugin implements AfterAdvicePlugin {
|
||||
|
||||
public DifferenceCriteriaFilterAdvicePlugin(AfterAdvicePlugin leftCriterFilter, AfterAdvicePlugin rightCriterFilter) {
|
||||
super(leftCriterFilter,rightCriterFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(EnhanceContext enhanceContext) {
|
||||
List<Map<String,Object>> differ = new ArrayList<>();
|
||||
EnhanceContext leftEnhanceContext = enhanceContext.clone();
|
||||
EnhanceContext rightEnhanceContext = enhanceContext.clone();
|
||||
|
||||
//执行增强
|
||||
leftCriterFilter.execute(leftEnhanceContext);
|
||||
rightCriterFilter.execute(rightEnhanceContext);
|
||||
//合并结果
|
||||
EnhanceResult leftResult = leftEnhanceContext.getResult();
|
||||
EnhanceResult rightResult = rightEnhanceContext.getResult();
|
||||
List<Map<String, Object>> leftRecords = leftResult.getRecords();
|
||||
List<Map<String, Object>> rightRecords = rightResult.getRecords();
|
||||
differ = (List<Map<String, Object>>) CollectionUtils.subtract(leftRecords, rightRecords);
|
||||
|
||||
enhanceContext.getResult().setRecords(differ);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.criteria;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceResult;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.plugin.AfterAdvicePlugin;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-19 14:46
|
||||
* @dedescription: 交集
|
||||
*/
|
||||
public class IntersectionCriteriaFilterAdvicePlugin extends BaseCriterFilterAdvicePlugin implements AfterAdvicePlugin {
|
||||
|
||||
public IntersectionCriteriaFilterAdvicePlugin(AfterAdvicePlugin leftCriterFilter, AfterAdvicePlugin rightCriterFilter) {
|
||||
super(leftCriterFilter,rightCriterFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(EnhanceContext enhanceContext) {
|
||||
List<Map<String,Object>> intersection = new ArrayList<>();
|
||||
EnhanceContext leftEnhanceContext = enhanceContext.clone();
|
||||
EnhanceContext rightEnhanceContext = enhanceContext.clone();
|
||||
//执行增强
|
||||
leftCriterFilter.execute(leftEnhanceContext);
|
||||
rightCriterFilter.execute(rightEnhanceContext);
|
||||
//合并结果
|
||||
EnhanceResult leftResult = leftEnhanceContext.getResult();
|
||||
EnhanceResult rightResult = rightEnhanceContext.getResult();
|
||||
List<Map<String, Object>> leftRecords = leftResult.getRecords();
|
||||
List<Map<String, Object>> rightRecords = rightResult.getRecords();
|
||||
intersection = (List<Map<String, Object>>) CollectionUtils.intersection(leftRecords, rightRecords);
|
||||
|
||||
enhanceContext.getResult().setRecords(intersection);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.criteria;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceResult;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.plugin.AfterAdvicePlugin;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-19 14:56
|
||||
* @dedescription: 合集
|
||||
*/
|
||||
public class OrCriteriaFilterAdvicePlugin extends BaseCriterFilterAdvicePlugin implements AfterAdvicePlugin {
|
||||
|
||||
public OrCriteriaFilterAdvicePlugin(AfterAdvicePlugin leftCriterFilter, AfterAdvicePlugin rightCriterFilter) {
|
||||
|
||||
super(leftCriterFilter,rightCriterFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(EnhanceContext enhanceContext) {
|
||||
List<Map<String,Object>> or = new ArrayList<>();
|
||||
EnhanceContext leftEnhanceContext = enhanceContext.clone();
|
||||
EnhanceContext rightEnhanceContext = enhanceContext.clone();
|
||||
//执行增强
|
||||
leftCriterFilter.execute(leftEnhanceContext);
|
||||
rightCriterFilter.execute(rightEnhanceContext);
|
||||
//合并结果
|
||||
EnhanceResult leftResult = leftEnhanceContext.getResult();
|
||||
EnhanceResult rightResult = rightEnhanceContext.getResult();
|
||||
List<Map<String, Object>> leftRecords = leftResult.getRecords();
|
||||
List<Map<String, Object>> rightRecords = rightResult.getRecords();
|
||||
CollectionUtils.addAll(leftRecords,rightRecords);
|
||||
or = leftRecords;
|
||||
enhanceContext.getResult().setRecords(or);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.criteria;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceResult;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.plugin.AfterAdvicePlugin;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-19 14:12
|
||||
* @dedescription: 并集
|
||||
*/
|
||||
public class UnionCriteriaFilterAdvicePlugin extends BaseCriterFilterAdvicePlugin implements AfterAdvicePlugin {
|
||||
|
||||
|
||||
public UnionCriteriaFilterAdvicePlugin(AfterAdvicePlugin leftCriterFilter, AfterAdvicePlugin rightCriterFilter) {
|
||||
super(leftCriterFilter,rightCriterFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(EnhanceContext enhanceContext) {
|
||||
List<Map<String,Object>> union = new ArrayList<>();
|
||||
EnhanceContext leftEnhanceContext = enhanceContext.clone();
|
||||
EnhanceContext rightEnhanceContext = enhanceContext.clone();
|
||||
//执行增强
|
||||
leftCriterFilter.execute(leftEnhanceContext);
|
||||
rightCriterFilter.execute(rightEnhanceContext);
|
||||
//合并结果
|
||||
EnhanceResult leftResult = leftEnhanceContext.getResult();
|
||||
EnhanceResult rightResult = rightEnhanceContext.getResult();
|
||||
List<Map<String, Object>> leftRecords = leftResult.getRecords();
|
||||
List<Map<String, Object>> rightRecords = rightResult.getRecords();
|
||||
union = (List<Map<String, Object>>) CollectionUtils.union(leftRecords, rightRecords);
|
||||
enhanceContext.getResult().setRecords(union);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.model;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-19 12:00
|
||||
* @dedescription:
|
||||
*/
|
||||
public class BaseEnhanceContext {
|
||||
|
||||
private Boolean before; //当前是前置增强
|
||||
|
||||
private Boolean onlyBefore = false; //只执行前置增强
|
||||
|
||||
public Boolean getBefore() {
|
||||
return before;
|
||||
}
|
||||
|
||||
public void setBefore(Boolean before) {
|
||||
this.before = before;
|
||||
}
|
||||
|
||||
public Boolean getOnlyBefore() {
|
||||
return onlyBefore;
|
||||
}
|
||||
|
||||
public void setOnlyBefore(Boolean onlyBefore) {
|
||||
this.onlyBefore = onlyBefore;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.model;
|
||||
|
||||
import com.jeelowcode.core.framework.entity.EnhanceJavaEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-15 15:46
|
||||
* @dedescription:
|
||||
*/
|
||||
public class BuildEnhanceContext {
|
||||
|
||||
private EnhanceContext context;
|
||||
|
||||
private List<EnhanceJavaEntity> entitys;
|
||||
|
||||
private List<EnhanceJavaEntity> setOperations;
|
||||
public BuildEnhanceContext(EnhanceContext context, List<EnhanceJavaEntity> entitys,List<EnhanceJavaEntity> setOperations) {
|
||||
this.context = context;
|
||||
this.entitys = entitys;
|
||||
this.setOperations = setOperations;
|
||||
}
|
||||
|
||||
public EnhanceContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void setContext(EnhanceContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public List<EnhanceJavaEntity> getEntitys() {
|
||||
return entitys;
|
||||
}
|
||||
|
||||
public void setEntitys(List<EnhanceJavaEntity> entitys) {
|
||||
this.entitys = entitys;
|
||||
}
|
||||
|
||||
public List<EnhanceJavaEntity> getSetOperations() {
|
||||
return setOperations;
|
||||
}
|
||||
|
||||
public void setSetOperations(List<EnhanceJavaEntity> setOperations) {
|
||||
this.setOperations = setOperations;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.model;
|
||||
|
||||
import com.jeelowcode.core.framework.entity.EnhanceSqlEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-21 15:52
|
||||
* @dedescription:
|
||||
*/
|
||||
public class BuildSqlEnhanceContext {
|
||||
|
||||
|
||||
private EnhanceContext context;
|
||||
|
||||
private List<EnhanceSqlEntity> entitys;
|
||||
|
||||
private List<EnhanceSqlEntity> setOperations;
|
||||
|
||||
public EnhanceContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void setContext(EnhanceContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public List<EnhanceSqlEntity> getEntitys() {
|
||||
return entitys;
|
||||
}
|
||||
|
||||
public void setEntitys(List<EnhanceSqlEntity> entitys) {
|
||||
this.entitys = entitys;
|
||||
}
|
||||
|
||||
public List<EnhanceSqlEntity> getSetOperations() {
|
||||
return setOperations;
|
||||
}
|
||||
|
||||
public void setSetOperations(List<EnhanceSqlEntity> setOperations) {
|
||||
this.setOperations = setOperations;
|
||||
}
|
||||
|
||||
public BuildSqlEnhanceContext(EnhanceContext context, List<EnhanceSqlEntity> entitys, List<EnhanceSqlEntity> setOperations) {
|
||||
this.context = context;
|
||||
this.entitys = entitys;
|
||||
this.setOperations = setOperations;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.model;
|
||||
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-12 9:14
|
||||
* @dedescription: 增强执行上下文
|
||||
*/
|
||||
public class EnhanceContext extends BaseEnhanceContext implements Serializable{
|
||||
//参数
|
||||
private EnhanceParam param=new EnhanceParam();
|
||||
//结果
|
||||
private EnhanceResult result=new EnhanceResult();
|
||||
|
||||
|
||||
public EnhanceParam getParam() {
|
||||
return param;
|
||||
}
|
||||
|
||||
public void setParam(EnhanceParam param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
public EnhanceResult getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(EnhanceResult result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public void setResult(ResultDataModel resultDataModel){
|
||||
this.result.setExitFlag(resultDataModel.isExitFlag());
|
||||
this.result.setRecords(resultDataModel.getRecords());
|
||||
this.result.setTotal(resultDataModel.getTotal());
|
||||
}
|
||||
|
||||
//通过序列化和反序列化实现深拷贝
|
||||
@Override
|
||||
public EnhanceContext clone(){
|
||||
try {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(bos);
|
||||
oos.writeObject(this);
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(bis);
|
||||
return (EnhanceContext) ois.readObject();
|
||||
} catch (IOException |ClassNotFoundException e ) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setParam(Long dbFormId,Map<String,Object> params,List<Map<String,Object>> list){
|
||||
this.param = new EnhanceParam(dbFormId,params,list);
|
||||
}
|
||||
|
||||
public void setResult(boolean exitFlag,String id,Long total,List<Map<String,Object>> records){
|
||||
this.result = new EnhanceResult(exitFlag,id,total,records);
|
||||
}
|
||||
|
||||
public void setParam(Long dbFormId, Map<String, Object> params, List<Map<String, Object>> list, Long dataId, Page page){
|
||||
this.param = new EnhanceParam(dbFormId,params,list,dataId,page);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.model;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jeelowcode.core.framework.params.SaveImportDataParam;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-15 10:02
|
||||
* @dedescription:
|
||||
*/
|
||||
public class EnhanceParam implements Serializable {
|
||||
|
||||
private Long dbFormId;
|
||||
|
||||
private Map<String, Object> params;
|
||||
|
||||
private List<Map<String, Object>> list;
|
||||
|
||||
private Long dataId;
|
||||
|
||||
private Page page;
|
||||
|
||||
public Long getDbFormId() {
|
||||
return dbFormId;
|
||||
}
|
||||
|
||||
public void setDbFormId(Long dbFormId) {
|
||||
this.dbFormId = dbFormId;
|
||||
}
|
||||
|
||||
public Map<String, Object> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(Map<String, Object> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<Map<String, Object>> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public EnhanceParam() {
|
||||
}
|
||||
|
||||
public Long getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
public void setDataId(Long dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
public Page getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(Page page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public EnhanceParam(Long dbFormId, Map<String, Object> params, List<Map<String, Object>> list) {
|
||||
this.dbFormId = dbFormId;
|
||||
this.params = params;
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public EnhanceParam(Long dbFormId, Map<String, Object> params, List<Map<String, Object>> list, Long dataId, Page page) {
|
||||
this.dbFormId = dbFormId;
|
||||
this.params = params;
|
||||
this.list = list;
|
||||
this.dataId = dataId;
|
||||
this.page = page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.model;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-16 16:32
|
||||
* @dedescription:
|
||||
*/
|
||||
public class EnhanceRespModel {
|
||||
|
||||
private int status;
|
||||
|
||||
private EnhanceContext data;
|
||||
|
||||
private String message;
|
||||
|
||||
public boolean checkStatus(){
|
||||
return this.status == 200;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public EnhanceContext getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(EnhanceContext data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-15 10:02
|
||||
* @dedescription:
|
||||
*/
|
||||
public class EnhanceResult implements Serializable {
|
||||
private boolean exitFlag = false;//是否退出
|
||||
|
||||
//表单
|
||||
private String id;
|
||||
|
||||
//列表
|
||||
private Long total;
|
||||
private List<Map<String, Object>> records;
|
||||
|
||||
public boolean isExitFlag() {
|
||||
return exitFlag;
|
||||
}
|
||||
|
||||
public void setExitFlag(boolean exitFlag) {
|
||||
this.exitFlag = exitFlag;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Long total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getRecords() {
|
||||
return records;
|
||||
}
|
||||
|
||||
public void setRecords(List<Map<String, Object>> records) {
|
||||
this.records = records;
|
||||
}
|
||||
|
||||
public EnhanceResult() {
|
||||
}
|
||||
|
||||
public EnhanceResult(boolean exitFlag, String id, Long total, List<Map<String, Object>> records) {
|
||||
this.exitFlag = exitFlag;
|
||||
this.id = id;
|
||||
this.total = total;
|
||||
this.records = records;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.model;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-16 14:03
|
||||
* @dedescription:
|
||||
*/
|
||||
public enum JavaEnhanceEnum {
|
||||
|
||||
SPRING("spring"),
|
||||
CLASS("class"),
|
||||
ONLINIE("online_edit"),
|
||||
HTTP("http");
|
||||
|
||||
private String type;
|
||||
|
||||
JavaEnhanceEnum(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.model;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-15 16:05
|
||||
* @dedescription:
|
||||
*/
|
||||
public enum JavaEnhanceEventState {
|
||||
|
||||
START("start"),
|
||||
END("end"),
|
||||
AROUND("around"),
|
||||
THROWING("throwing");
|
||||
|
||||
|
||||
private String name;
|
||||
|
||||
JavaEnhanceEventState(String NAME) {
|
||||
this.name = NAME;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.plugin;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-12 9:27
|
||||
* @dedescription: 后置增强插件
|
||||
*/
|
||||
public interface AfterAdvicePlugin extends BaseAdvicePlugin {
|
||||
|
||||
void execute(EnhanceContext enhanceContext);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.plugin;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-12 9:25
|
||||
* @dedescription: 环绕增强插件
|
||||
*/
|
||||
public interface AroundAdvicePlugin extends BaseAdvicePlugin {
|
||||
|
||||
void beforeExecute(EnhanceContext enhanceContext);
|
||||
|
||||
void afterExecute(EnhanceContext enhanceContext);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.plugin;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-13 15:34
|
||||
* @dedescription: 基础增强插件
|
||||
*/
|
||||
public interface BaseAdvicePlugin {
|
||||
|
||||
default void execute(EnhanceContext enhanceContext){}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.plugin;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-12 9:20
|
||||
* @dedescription: 前置增强插件
|
||||
*/
|
||||
public interface BeforeAdvicePlugin extends BaseAdvicePlugin {
|
||||
|
||||
void execute(EnhanceContext enhanceContext);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.plugin;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
|
||||
import com.jeelowcode.core.framework.entity.EnhanceJavaEntity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-12 9:38
|
||||
* @dedescription:
|
||||
*/
|
||||
public class PluginManager{
|
||||
|
||||
public static Map<String, BaseAdvicePlugin> plugins = new HashMap<>();
|
||||
|
||||
|
||||
public static BaseAdvicePlugin getPlugin(String key){
|
||||
return plugins.get(key);
|
||||
}
|
||||
|
||||
public static BaseAdvicePlugin getPlugin(EnhanceJavaEntity entity){
|
||||
return plugins.get(entity.getJavaClassUrl());
|
||||
}
|
||||
|
||||
|
||||
public static void addPlugin(String key, BaseAdvicePlugin plugin){
|
||||
plugins.put(key,plugin);
|
||||
}
|
||||
|
||||
public static void addPlugin(BaseAdvicePlugin plugin){
|
||||
plugins.put(plugin.getClass().getName(), plugin);
|
||||
}
|
||||
|
||||
public static boolean removePlugin(String name){
|
||||
plugins.remove(name);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void executePlugin(String name, EnhanceContext enhanceContext){
|
||||
BaseAdvicePlugin plugin = plugins.get(name);
|
||||
plugin.execute(enhanceContext);
|
||||
}
|
||||
|
||||
public static void executePlugin(BaseAdvicePlugin plugin, EnhanceContext enhanceContext){
|
||||
plugin.execute(enhanceContext);
|
||||
}
|
||||
|
||||
public static void executeAroundBeforePlugin(BaseAdvicePlugin plugin, EnhanceContext enhanceContext){
|
||||
AroundAdvicePlugin aroundPlugin = (AroundAdvicePlugin) plugin;
|
||||
aroundPlugin.beforeExecute(enhanceContext);
|
||||
}
|
||||
public static void executeAroundAfterPlugin(BaseAdvicePlugin plugin, EnhanceContext enhanceContext){
|
||||
AroundAdvicePlugin aroundPlugin = (AroundAdvicePlugin) plugin;
|
||||
aroundPlugin.afterExecute(enhanceContext);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhance.plugin;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceContext;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-12 11:50
|
||||
* @dedescription: 异常增强插件
|
||||
*/
|
||||
public interface ThrowAdvicePlugin extends BaseAdvicePlugin {
|
||||
|
||||
void execute(EnhanceContext model);
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhancereport;
|
||||
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceResult;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.JavaEnhanceEnum;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.plugin.AfterAdvicePlugin;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhancereport.model.BuildEnhanceReportContext;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhancereport.model.EnhanceReportContext;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhancereport.model.EnhanceReportParam;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhancereport.plugin.ReportAfterAdvicePlugin;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhancereport.plugin.ReportBaseAdvicePlugin;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhancereport.plugin.ReportPluginManager;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeException;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 报表统计
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class JeeLowCodeAnnotationAspectjReport {
|
||||
|
||||
public final static String EXPRESSION = "execution(* com.jeelowcode.core.framework.service.impl.FrameServiceImpl.*(..))";
|
||||
|
||||
//拦截方法
|
||||
public final static String ASPECT_METHODNAME ="getReportDataList";
|
||||
|
||||
//需要处理的增强 key=报表code value=增强
|
||||
private static Map<String, String> pluginNames = new HashMap<>();
|
||||
|
||||
@AfterReturning(value = EXPRESSION, returning = "returnVal")
|
||||
public Object afterReturning(JoinPoint joinPoint, Object returnVal) throws Throwable {
|
||||
//获取参数
|
||||
BuildEnhanceReportContext buildEnhanceContext = this.getContextAndPlugins(joinPoint);
|
||||
if (FuncBase.isEmpty(buildEnhanceContext)) {//没有增强
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
//不是列表类增强
|
||||
if (!(returnVal instanceof ResultDataModel)) {
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
//增强列表
|
||||
String javaClass = buildEnhanceContext.getJavaClass();
|
||||
if (Func.isEmpty(javaClass)) {//无增强
|
||||
return returnVal;
|
||||
}
|
||||
EnhanceReportContext context = buildEnhanceContext.getContext();
|
||||
|
||||
|
||||
//把原来返回值封装到上下文context
|
||||
ResultDataModel resultDataModel = (ResultDataModel) returnVal;
|
||||
List<Map<String, Object>> records = resultDataModel.getRecords();
|
||||
if(Func.isEmpty(records)){
|
||||
records=new ArrayList<>();
|
||||
}
|
||||
|
||||
EnhanceResult enhanceResult = new EnhanceResult();
|
||||
enhanceResult.setRecords(records);
|
||||
enhanceResult.setTotal((long)records.size());
|
||||
context.getParam().setList(records);
|
||||
context.setResult(enhanceResult);
|
||||
|
||||
//执行增强
|
||||
this.executeJavaEnhance(javaClass, context);
|
||||
|
||||
|
||||
//返回结果
|
||||
ResultDataModel returnValData = (ResultDataModel) returnVal;
|
||||
resultDataModel = (ResultDataModel) getResult(context);
|
||||
returnValData.setRecords(resultDataModel.getRecords());
|
||||
returnValData.setTotal(resultDataModel.getTotal());
|
||||
return returnValData;
|
||||
|
||||
}
|
||||
|
||||
public BuildEnhanceReportContext getContextAndPlugins(JoinPoint joinPoint) {
|
||||
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
|
||||
// 获取方法名称
|
||||
String methodName = methodSignature.getName();
|
||||
if (Func.notEquals(methodName,ASPECT_METHODNAME)) {//不在拦截范围内 add
|
||||
return null;
|
||||
}
|
||||
//处理参数
|
||||
Object[] args = joinPoint.getArgs();
|
||||
LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
|
||||
String[] parameterNames = discoverer.getParameterNames(methodSignature.getMethod());
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
for (int i = 0; i < parameterNames.length; i++) {
|
||||
paramMap.put(parameterNames[i], args[i]);
|
||||
}
|
||||
|
||||
//判断该表单,当前的功能是否有增强
|
||||
String reportCode = (String) paramMap.get("reportCode");
|
||||
String javaClass = pluginNames.getOrDefault(reportCode, null);
|
||||
if (Func.isEmpty(javaClass)) {//不存在增强
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
EnhanceReportParam param = new EnhanceReportParam();
|
||||
param.setReportCode(reportCode);
|
||||
param.setList((ArrayList) paramMap.getOrDefault("dataList", null));
|
||||
param.setParams((Map<String, Object>) paramMap.getOrDefault("params", null));
|
||||
|
||||
//把参数放入到上下文
|
||||
EnhanceReportContext context = new EnhanceReportContext();
|
||||
context.setParam(param);
|
||||
|
||||
BuildEnhanceReportContext buildEnhanceContext = new BuildEnhanceReportContext(context, javaClass);
|
||||
return buildEnhanceContext;
|
||||
}
|
||||
|
||||
//执行JAVA增强
|
||||
private void executeJavaEnhance(String javaClassUrl, EnhanceReportContext context) throws Throwable {
|
||||
ReportBaseAdvicePlugin plugin = ReportPluginManager.getPlugin(javaClassUrl);
|
||||
if (!(plugin instanceof ReportAfterAdvicePlugin)) {
|
||||
return;
|
||||
}
|
||||
//执行
|
||||
ReportPluginManager.executePlugin(javaClassUrl, context);
|
||||
}
|
||||
|
||||
public Object getResult(EnhanceReportContext context) {
|
||||
if (Func.isEmpty(context.getResult().getRecords()) && FuncBase.isEmpty(context.getResult().getId())) {
|
||||
return ResultDataModel.fomat(0L, new ArrayList<>());
|
||||
}
|
||||
|
||||
ResultDataModel resultDataModel = new ResultDataModel();
|
||||
resultDataModel.setRecords(context.getResult().getRecords());
|
||||
resultDataModel.setTotal(context.getResult().getTotal());
|
||||
resultDataModel.setExitFlag(context.getResult().isExitFlag());
|
||||
return resultDataModel;
|
||||
}
|
||||
|
||||
//刷新插件
|
||||
public static void refreshPlugin(String type,String reportCode,String javaClass){
|
||||
try {
|
||||
if(Func.isEmpty(javaClass)){
|
||||
return;
|
||||
}
|
||||
|
||||
if(Func.equals(type,"ADD") ||Func.equals(type,"UPDATE")){
|
||||
JavaEnhanceEnum javaEnhanceEnum=javaClass.indexOf(".")>0?JavaEnhanceEnum.CLASS:JavaEnhanceEnum.SPRING;
|
||||
if(Func.equals(javaEnhanceEnum,JavaEnhanceEnum.SPRING)){
|
||||
Object bean = SpringUtils.getBean(javaClass);
|
||||
if (Func.isNotEmpty(bean) && bean instanceof ReportBaseAdvicePlugin) {
|
||||
ReportPluginManager.addPlugin(javaClass, (ReportBaseAdvicePlugin) bean);
|
||||
pluginNames.put(reportCode,javaClass);
|
||||
}
|
||||
}else{
|
||||
Class<?> enhanceClass = Class.forName(javaClass);
|
||||
ReportBaseAdvicePlugin plugin = (ReportBaseAdvicePlugin) enhanceClass.newInstance();
|
||||
ReportPluginManager.addPlugin(javaClass, plugin);
|
||||
pluginNames.put(reportCode,javaClass);
|
||||
}
|
||||
}else if(Func.equals(type,"DEL")){
|
||||
pluginNames.remove(reportCode,javaClass);
|
||||
if (!new HashSet<>(pluginNames.values()).contains(javaClass)) {
|
||||
ReportPluginManager.removePlugin(javaClass);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
throw new JeeLowCodeException("增强["+javaClass+"]插件加载失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhancereport.model;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-15 15:46
|
||||
* @dedescription:
|
||||
*/
|
||||
public class BuildEnhanceReportContext {
|
||||
|
||||
private EnhanceReportContext context;
|
||||
|
||||
private String javaClass;
|
||||
|
||||
public BuildEnhanceReportContext(EnhanceReportContext context, String javaClass) {
|
||||
this.context = context;
|
||||
this.javaClass = javaClass;
|
||||
}
|
||||
|
||||
public EnhanceReportContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void setContext(EnhanceReportContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public String getJavaClass() {
|
||||
return javaClass;
|
||||
}
|
||||
|
||||
public void setJavaClass(String javaClass) {
|
||||
this.javaClass = javaClass;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhancereport.model;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.BaseEnhanceContext;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.model.EnhanceResult;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-12 9:14
|
||||
* @dedescription: 增强执行上下文
|
||||
*/
|
||||
public class EnhanceReportContext extends BaseEnhanceContext implements Serializable{
|
||||
//参数
|
||||
private EnhanceReportParam param;
|
||||
//结果
|
||||
private EnhanceResult result;
|
||||
|
||||
|
||||
public EnhanceReportParam getParam() {
|
||||
return param;
|
||||
}
|
||||
|
||||
public void setParam(EnhanceReportParam param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
public EnhanceResult getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(EnhanceResult result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public void setResult(ResultDataModel resultDataModel){
|
||||
this.result.setExitFlag(resultDataModel.isExitFlag());
|
||||
this.result.setRecords(resultDataModel.getRecords());
|
||||
this.result.setTotal(resultDataModel.getTotal());
|
||||
}
|
||||
|
||||
//通过序列化和反序列化实现深拷贝
|
||||
@Override
|
||||
public EnhanceReportContext clone(){
|
||||
try {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(bos);
|
||||
oos.writeObject(this);
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(bis);
|
||||
return (EnhanceReportContext) ois.readObject();
|
||||
} catch (IOException |ClassNotFoundException e ) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setParam(String reportCode,Map<String,Object> params,List<Map<String,Object>> list){
|
||||
this.param = new EnhanceReportParam(reportCode,params,list);
|
||||
}
|
||||
|
||||
public void setResult(boolean exitFlag,String id,Long total,List<Map<String,Object>> records){
|
||||
this.result = new EnhanceResult(exitFlag,id,total,records);
|
||||
}
|
||||
|
||||
public void setParam(String reportCode, Map<String, Object> params, List<Map<String, Object>> list, Long dataId, Page page, List<Long> dataIdList){
|
||||
this.param = new EnhanceReportParam(reportCode,params,list,dataId,page,dataIdList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhancereport.model;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-15 10:02
|
||||
* @dedescription:
|
||||
*/
|
||||
public class EnhanceReportParam implements Serializable {
|
||||
|
||||
private String reportCode;
|
||||
|
||||
private Map<String, Object> params;
|
||||
|
||||
private List<Map<String, Object>> list;
|
||||
|
||||
private Long dataId;
|
||||
|
||||
private Page page;
|
||||
|
||||
private List<Long> dataIdList;
|
||||
|
||||
public String getReportCode() {
|
||||
return reportCode;
|
||||
}
|
||||
|
||||
public void setReportCode(String reportCode) {
|
||||
this.reportCode = reportCode;
|
||||
}
|
||||
|
||||
public Map<String, Object> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(Map<String, Object> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<Map<String, Object>> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public EnhanceReportParam() {
|
||||
}
|
||||
|
||||
public Long getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
public void setDataId(Long dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
public Page getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(Page page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public List<Long> getDataIdList() {
|
||||
return dataIdList;
|
||||
}
|
||||
|
||||
public void setDataIdList(List<Long> dataIdList) {
|
||||
this.dataIdList = dataIdList;
|
||||
}
|
||||
|
||||
public EnhanceReportParam(String reportCode, Map<String, Object> params, List<Map<String, Object>> list) {
|
||||
this.reportCode = reportCode;
|
||||
this.params = params;
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public EnhanceReportParam(String reportCode, Map<String, Object> params, List<Map<String, Object>> list, Long dataId, Page page, List<Long> dataIdList) {
|
||||
this.reportCode = reportCode;
|
||||
this.params = params;
|
||||
this.list = list;
|
||||
this.dataId = dataId;
|
||||
this.page = page;
|
||||
this.dataIdList = dataIdList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhancereport.plugin;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhancereport.model.EnhanceReportContext;
|
||||
|
||||
/**
|
||||
* 报表统计 后置增强(报表统计专属)
|
||||
*/
|
||||
public interface ReportAfterAdvicePlugin extends ReportBaseAdvicePlugin {
|
||||
|
||||
void execute(EnhanceReportContext enhanceContext);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhancereport.plugin;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhancereport.model.EnhanceReportContext;
|
||||
|
||||
/**
|
||||
* @author JX
|
||||
* @create 2024-08-13 15:34
|
||||
* @dedescription: 基础增强插件
|
||||
*/
|
||||
public interface ReportBaseAdvicePlugin {
|
||||
|
||||
default void execute(EnhanceReportContext enhanceContext){}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.enhancereport.plugin;
|
||||
|
||||
import com.jeelowcode.core.framework.config.aspect.enhancereport.model.EnhanceReportContext;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class ReportPluginManager {
|
||||
|
||||
public static Map<String, ReportBaseAdvicePlugin> plugins = new HashMap<>();
|
||||
|
||||
|
||||
public static ReportBaseAdvicePlugin getPlugin(String key){
|
||||
return plugins.get(key);
|
||||
}
|
||||
|
||||
|
||||
public static void addPlugin(String key, ReportBaseAdvicePlugin plugin){
|
||||
plugins.put(key,plugin);
|
||||
}
|
||||
|
||||
public static void addPlugin(ReportBaseAdvicePlugin plugin){
|
||||
plugins.put(plugin.getClass().getName(), plugin);
|
||||
}
|
||||
|
||||
public static boolean removePlugin(String name){
|
||||
plugins.remove(name);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void executePlugin(String name, EnhanceReportContext enhanceContext){
|
||||
ReportBaseAdvicePlugin plugin = plugins.get(name);
|
||||
plugin.execute(enhanceContext);
|
||||
}
|
||||
|
||||
public static void executePlugin(ReportBaseAdvicePlugin plugin, EnhanceReportContext enhanceContext){
|
||||
plugin.execute(enhanceContext);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.aspect.nologin;
|
||||
|
||||
import com.jeelowcode.core.framework.service.IFormService;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.framework.constants.FrameErrorCodeConstants;
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeException;
|
||||
import com.jeelowcode.framework.utils.enums.AuthTypeEnum;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 不登录是否可以查看dbform配置
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class JeeLowCodeNoLoginViewDbFormAspect {
|
||||
|
||||
private ExpressionParser parser = new SpelExpressionParser();
|
||||
|
||||
@Autowired
|
||||
private IFormService formService;
|
||||
|
||||
@Around("@annotation(com.jeelowcode.framework.utils.annotation.JeeLowCodeNoLoginViewDbForm)")
|
||||
public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
// 获取方法的参数
|
||||
Object[] args = joinPoint.getArgs();
|
||||
// 假设dbformId是第一个参数,你可以根据实际情况调整索引
|
||||
Long dbformId = (Long) args[0];
|
||||
if (Func.isEmpty(dbformId)) {
|
||||
throw new JeeLowCodeException(FrameErrorCodeConstants.FRAME_PARAM_NULL_ERROR.getMsg());
|
||||
}
|
||||
//判断该接口是否勾选 不登录可查看
|
||||
AuthTypeEnum authType = formService.getAuthType(dbformId);
|
||||
|
||||
if (!Func.equals(authType, AuthTypeEnum.authOpen)) {//配置没有勾选,判断是否已经登录了
|
||||
throw new JeeLowCodeException(FrameErrorCodeConstants.FRAME_LOGIN_VIEW_ERROR.getMsg());
|
||||
}
|
||||
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.button.IButtonCommand;
|
||||
|
||||
/**
|
||||
* 命令发起者
|
||||
*/
|
||||
public class ButtonInvoker<T> {
|
||||
|
||||
private IButtonCommand<T> buttonCommand;
|
||||
|
||||
//发起命令
|
||||
public T executeCommand(){
|
||||
return (T)buttonCommand.execute();
|
||||
}
|
||||
|
||||
public IButtonCommand getButtonCommand() {
|
||||
return buttonCommand;
|
||||
}
|
||||
|
||||
public void setButtonCommand(IButtonCommand buttonCommand) {
|
||||
this.buttonCommand = buttonCommand;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.button;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.receiver.IButtonCommandReceiver;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 具体命令-新增按钮命令
|
||||
*/
|
||||
public class AddBatchButtonCommand implements IButtonCommand<List<String>> {
|
||||
//命令执行者
|
||||
private IButtonCommandReceiver<List<String>> recevier;
|
||||
|
||||
private String name = "批量新增";
|
||||
|
||||
/**
|
||||
* 绑定执行者
|
||||
* @param recevier 执行者
|
||||
*/
|
||||
public AddBatchButtonCommand(IButtonCommandReceiver recevier) {
|
||||
this.recevier = recevier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> execute() {
|
||||
return recevier.receiver();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.button;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.receiver.IButtonCommandReceiver;
|
||||
import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel;
|
||||
|
||||
/**
|
||||
* 具体命令-新增按钮命令
|
||||
*/
|
||||
public class AddButtonCommand implements IButtonCommand<ExecuteEnhanceModel> {
|
||||
//命令执行者
|
||||
private IButtonCommandReceiver<ExecuteEnhanceModel> recevier;
|
||||
|
||||
private String name = "新增";
|
||||
|
||||
/**
|
||||
* 绑定执行者
|
||||
* @param recevier 执行者
|
||||
*/
|
||||
public AddButtonCommand(IButtonCommandReceiver recevier) {
|
||||
this.recevier = recevier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExecuteEnhanceModel execute() {
|
||||
return recevier.receiver();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.button;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.receiver.IButtonCommandReceiver;
|
||||
|
||||
/**
|
||||
* 具体命令-分页按钮命令
|
||||
*/
|
||||
public class DefinableButtonCommand implements IButtonCommand<Object> {
|
||||
//命令执行者
|
||||
private IButtonCommandReceiver recevier;
|
||||
|
||||
private String name = "自定义";
|
||||
|
||||
/**
|
||||
* 绑定执行者
|
||||
*
|
||||
* @param recevier 执行者
|
||||
*/
|
||||
public DefinableButtonCommand(IButtonCommandReceiver recevier) {
|
||||
this.recevier = recevier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Object execute() {
|
||||
return recevier.receiver();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.button;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.receiver.IButtonCommandReceiver;
|
||||
import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel;
|
||||
|
||||
/**
|
||||
* 具体命令-删除按钮命令
|
||||
*/
|
||||
public class DelButtonCommand implements IButtonCommand<ExecuteEnhanceModel> {
|
||||
//命令执行者
|
||||
private IButtonCommandReceiver<ExecuteEnhanceModel> recevier;
|
||||
|
||||
private String name = "删除";
|
||||
|
||||
/**
|
||||
* 绑定执行者
|
||||
*
|
||||
* @param recevier 执行者
|
||||
*/
|
||||
public DelButtonCommand(IButtonCommandReceiver recevier) {
|
||||
this.recevier = recevier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExecuteEnhanceModel execute() {
|
||||
return recevier.receiver();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.button;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.receiver.IButtonCommandReceiver;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
|
||||
/**
|
||||
* 具体命令-详情按钮命令
|
||||
*/
|
||||
public class DetailsButtonCommand implements IButtonCommand<ResultDataModel> {
|
||||
//命令执行者
|
||||
private IButtonCommandReceiver<ResultDataModel> recevier;
|
||||
|
||||
private String name = "详情";
|
||||
|
||||
/**
|
||||
* 绑定执行者
|
||||
*
|
||||
* @param recevier 执行者
|
||||
*/
|
||||
public DetailsButtonCommand(IButtonCommandReceiver recevier) {
|
||||
this.recevier = recevier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ResultDataModel execute() {
|
||||
return recevier.receiver();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.button;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.receiver.IButtonCommandReceiver;
|
||||
import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel;
|
||||
|
||||
/**
|
||||
* 具体命令-编辑按钮命令
|
||||
*/
|
||||
public class EditBatchButtonCommand implements IButtonCommand<ExecuteEnhanceModel> {
|
||||
//命令执行者
|
||||
private IButtonCommandReceiver<ExecuteEnhanceModel> recevier;
|
||||
|
||||
private String name = "批量编辑";
|
||||
|
||||
/**
|
||||
* 绑定执行者
|
||||
*
|
||||
* @param recevier 执行者
|
||||
*/
|
||||
public EditBatchButtonCommand(IButtonCommandReceiver recevier) {
|
||||
this.recevier = recevier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExecuteEnhanceModel execute() {
|
||||
return recevier.receiver();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.button;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.receiver.IButtonCommandReceiver;
|
||||
import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel;
|
||||
|
||||
/**
|
||||
* 具体命令-编辑按钮命令
|
||||
*/
|
||||
public class EditButtonCommand implements IButtonCommand<ExecuteEnhanceModel> {
|
||||
//命令执行者
|
||||
private IButtonCommandReceiver<ExecuteEnhanceModel> recevier;
|
||||
|
||||
private String name = "编辑";
|
||||
|
||||
/**
|
||||
* 绑定执行者
|
||||
*
|
||||
* @param recevier 执行者
|
||||
*/
|
||||
public EditButtonCommand(IButtonCommandReceiver recevier) {
|
||||
this.recevier = recevier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExecuteEnhanceModel execute() {
|
||||
return recevier.receiver();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.button;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.receiver.IButtonCommandReceiver;
|
||||
import com.jeelowcode.core.framework.params.model.ExcelModel;
|
||||
|
||||
/**
|
||||
* 具体命令-新增按钮命令
|
||||
*/
|
||||
public class ExportButtonCommand implements IButtonCommand<ExcelModel> {
|
||||
//命令执行者
|
||||
private IButtonCommandReceiver<ExcelModel> recevier;
|
||||
|
||||
private String name = "导出数据";
|
||||
|
||||
/**
|
||||
* 绑定执行者
|
||||
* @param recevier 执行者
|
||||
*/
|
||||
public ExportButtonCommand(IButtonCommandReceiver recevier) {
|
||||
this.recevier = recevier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExcelModel execute() {
|
||||
ExcelModel receiver = recevier.receiver();
|
||||
return receiver;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.button;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.receiver.IButtonCommandReceiver;
|
||||
import com.jeelowcode.core.framework.params.model.ExcelTemplateModel;
|
||||
|
||||
/**
|
||||
* 具体命令-新增按钮命令
|
||||
*/
|
||||
public class ExportTemplateButtonCommand implements IButtonCommand<ExcelTemplateModel> {
|
||||
//命令执行者
|
||||
private IButtonCommandReceiver<ExcelTemplateModel> recevier;
|
||||
|
||||
private String name = "导出数据模板";
|
||||
|
||||
/**
|
||||
* 绑定执行者
|
||||
* @param recevier 执行者
|
||||
*/
|
||||
public ExportTemplateButtonCommand(IButtonCommandReceiver recevier) {
|
||||
this.recevier = recevier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExcelTemplateModel execute() {
|
||||
ExcelTemplateModel receiver = recevier.receiver();
|
||||
return receiver;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.button;
|
||||
|
||||
/**
|
||||
* 命令-所有具体命令都要实现该接口
|
||||
* @param <T>
|
||||
*/
|
||||
public interface IButtonCommand<T> {
|
||||
//统一执行方法
|
||||
T execute();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.button;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.receiver.IButtonCommandReceiver;
|
||||
import com.jeelowcode.core.framework.params.model.ExcelImportResultModel;
|
||||
|
||||
/**
|
||||
* 具体命令-新增按钮命令
|
||||
*/
|
||||
public class ImportButtonCommand implements IButtonCommand<ExcelImportResultModel> {
|
||||
//命令执行者
|
||||
private IButtonCommandReceiver<ExcelImportResultModel> recevier;
|
||||
|
||||
private String name = "导入";
|
||||
|
||||
/**
|
||||
* 绑定执行者
|
||||
* @param recevier 执行者
|
||||
*/
|
||||
public ImportButtonCommand(IButtonCommandReceiver recevier) {
|
||||
this.recevier = recevier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExcelImportResultModel execute() {
|
||||
ExcelImportResultModel receiver = recevier.receiver();
|
||||
return receiver;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.button;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.receiver.IButtonCommandReceiver;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
|
||||
/**
|
||||
* 具体命令-分页按钮命令
|
||||
*/
|
||||
public class ListButtonCommand implements IButtonCommand<ResultDataModel> {
|
||||
//命令执行者
|
||||
private IButtonCommandReceiver<ResultDataModel> recevier;
|
||||
|
||||
private String name = "分页";
|
||||
|
||||
/**
|
||||
* 绑定执行者
|
||||
*
|
||||
* @param recevier 执行者
|
||||
*/
|
||||
public ListButtonCommand(IButtonCommandReceiver recevier) {
|
||||
this.recevier = recevier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ResultDataModel execute() {
|
||||
return recevier.receiver();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.button;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.receiver.IButtonCommandReceiver;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 具体命令-统计按钮命令
|
||||
*/
|
||||
public class SummaryButtonCommand implements IButtonCommand<Map> {
|
||||
//命令执行者
|
||||
private IButtonCommandReceiver<Map> recevier;
|
||||
|
||||
private String name = "统计";
|
||||
|
||||
/**
|
||||
* 绑定执行者
|
||||
*
|
||||
* @param recevier 执行者
|
||||
*/
|
||||
public SummaryButtonCommand(IButtonCommandReceiver recevier) {
|
||||
this.recevier = recevier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map execute() {
|
||||
return recevier.receiver();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.definable;
|
||||
|
||||
/**
|
||||
* 自定义按钮
|
||||
* @param <T> 返回值
|
||||
* @param <S> 参数
|
||||
*/
|
||||
public interface DefinableButtonPlugin<T,S> {
|
||||
T execute(S param);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.definable;
|
||||
|
||||
import cn.hutool.cache.Cache;
|
||||
import cn.hutool.cache.CacheUtil;
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeException;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public class DefinablePluginManager<T> {
|
||||
|
||||
//从数据库读取,放入到map
|
||||
public static Map<String,String> allDefinableMap=new HashMap<>();
|
||||
|
||||
|
||||
//只保留最近10个常用的
|
||||
Cache<String, DefinableButtonPlugin> cache = CacheUtil.newLRUCache(10);
|
||||
|
||||
//初始化实例
|
||||
public static DefinableButtonPlugin initClazz(String clazzStr) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(clazzStr);
|
||||
DefinableButtonPlugin definableButtonPlugin = (DefinableButtonPlugin)clazz.newInstance();//实例化
|
||||
return definableButtonPlugin;
|
||||
} catch (Exception e) {
|
||||
throw new JeeLowCodeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//添加插件
|
||||
public void addPlugin(String key, DefinableButtonPlugin plugin) {
|
||||
cache.put(key, plugin);
|
||||
}
|
||||
|
||||
//移除
|
||||
public void remove(String key) {
|
||||
if (cache.containsKey(key)) {
|
||||
cache.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public DefinableButtonPlugin getPlugin(String key) {
|
||||
if (cache.containsKey(key)) {
|
||||
return cache.get(key);
|
||||
}
|
||||
if(!allDefinableMap.containsKey(key)){
|
||||
log.error("自定义按钮控件不存在==》"+key);
|
||||
return null;
|
||||
}
|
||||
|
||||
//没有在队列里面,则重新实例化
|
||||
String clazzUrl = allDefinableMap.get(key);
|
||||
|
||||
addPlugin(key, initClazz(clazzUrl));
|
||||
return cache.get(key);
|
||||
}
|
||||
|
||||
//运行插件
|
||||
public Object executePlugin(String key,T param) {
|
||||
DefinableButtonPlugin plugin = this.getPlugin(key);
|
||||
if(Func.isEmpty(plugin)){
|
||||
return null;
|
||||
}
|
||||
return plugin.execute(param);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 新增按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamAdd {
|
||||
private Long dbFormId;//表单id
|
||||
private Map<String, Object> params;//参数
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 新增按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamAddBatch {
|
||||
private Long dbFormId;//表单id
|
||||
private List<JSONObject> dataMapList;//批量参数
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 自定义按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamDefinable {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 删除按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamDel {
|
||||
private Long dbFormId;
|
||||
private List<Long> dataIdList;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 新增按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamDetail {
|
||||
private Long dbFormId;//表单id
|
||||
private Long dataId;
|
||||
private Map<String,Object> params;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 编辑按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamEdit {
|
||||
private Long dbFormId;
|
||||
private Long dataId;
|
||||
private Map<String,Object> params;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 编辑按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamEditBatch {
|
||||
private Long dbFormId;
|
||||
private List<JSONObject> jsonObjectList;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 导入按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamExport {
|
||||
private Long dbFormId;//表单id
|
||||
private Map<String, Object> params ;//文参数
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 导入按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamExportTemplate {
|
||||
private Long dbFormId;//表单id
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 导入按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamImport {
|
||||
private String serviceType;//业务类型 IMPORT_TEMPLATE = 导入模版 HANBLE_TEMPLATE = 处理模版
|
||||
private Long dbFormId;//表单id
|
||||
private String fileName;
|
||||
private List<Map<String, Object>> dataMapList;//数据列表
|
||||
private Long batchCode;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 分页按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamList {
|
||||
private Long dbFormId;//表单id
|
||||
private Page page;
|
||||
private Map<String,Object> params;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 导入按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamReportExport {
|
||||
private String reportCode;//报表编码
|
||||
private Map<String, Object> params ;//文参数
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 分页按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamReportList {
|
||||
private String reportCode;//报表编号
|
||||
private Page page;
|
||||
private Map<String,Object> params;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 统计按钮参数
|
||||
*/
|
||||
@Data
|
||||
public class ButtonParamSummary {
|
||||
private Long dbFormId;//表单id
|
||||
private Map<String,Object> params;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamAdd;
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 新增按钮执行者
|
||||
*/
|
||||
public class ButtonReceiverAdd implements IButtonCommandReceiver<ExecuteEnhanceModel> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private ButtonParamAdd param;
|
||||
|
||||
public ButtonReceiverAdd(ButtonParamAdd param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExecuteEnhanceModel receiver() {
|
||||
IFrameService frameService = SpringUtils.getBean(IFrameService.class);
|
||||
|
||||
Long dbFormId = param.getDbFormId();
|
||||
Map<String, Object> paramMap = param.getParams();
|
||||
if(Func.isNotEmpty(paramMap)){
|
||||
paramMap.remove("id");
|
||||
}
|
||||
|
||||
ExecuteEnhanceModel enhanceModel = frameService.saveData(dbFormId, paramMap);
|
||||
|
||||
return enhanceModel;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamAddBatch;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 新增按钮执行者
|
||||
*/
|
||||
public class ButtonReceiverAddBatch implements IButtonCommandReceiver<List<String>> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private ButtonParamAddBatch param;
|
||||
|
||||
public ButtonReceiverAddBatch(ButtonParamAddBatch param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> receiver() {
|
||||
IFrameService frameService = SpringUtils.getBean(IFrameService.class);
|
||||
|
||||
Long dbFormId = param.getDbFormId();
|
||||
List<JSONObject> jsonList = param.getDataMapList();
|
||||
for(JSONObject jsonObject:jsonList){
|
||||
jsonObject.remove("id");
|
||||
}
|
||||
|
||||
List<String> idList = frameService.saveBatchData(dbFormId, jsonList);
|
||||
|
||||
|
||||
return idList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import com.jeelowcode.core.framework.entity.FormFieldEntity;
|
||||
import com.jeelowcode.core.framework.entity.ReportEntity;
|
||||
import com.jeelowcode.core.framework.mapper.FormFieldMapper;
|
||||
import com.jeelowcode.core.framework.params.vo.role.DbFormRoleFieldVo;
|
||||
import com.jeelowcode.framework.excel.model.ExcelTitleModel;
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeException;
|
||||
import com.jeelowcode.framework.utils.enums.YNEnum;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.core.framework.config.virtualization.VirtualizationFieldPluginManager;
|
||||
import com.jeelowcode.core.framework.entity.FormFieldWebEntity;
|
||||
import com.jeelowcode.core.framework.mapper.FormFieldWebMapper;
|
||||
import com.jeelowcode.core.framework.params.model.WebFormatConfigModel;
|
||||
import com.jeelowcode.core.framework.service.IFormService;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import org.apache.commons.collections4.map.LinkedMap;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 公共
|
||||
*/
|
||||
public class ButtonReceiverBase {
|
||||
|
||||
//移除不是导入项目
|
||||
public void removeNotExport(LinkedMap<String, ExcelTitleModel> headTitleMap, List<DbFormRoleFieldVo> roleFieldVoList) {
|
||||
if(Func.isEmpty(roleFieldVoList)){
|
||||
return;
|
||||
}
|
||||
Map<String, DbFormRoleFieldVo> roleDisableMap =roleFieldVoList.stream()
|
||||
.collect(Collectors.toMap(DbFormRoleFieldVo::getFieldCode, entity -> entity));
|
||||
|
||||
Iterator<Map.Entry<String, ExcelTitleModel>> iterator = headTitleMap.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, ExcelTitleModel> entry = iterator.next();
|
||||
String key = entry.getKey();
|
||||
if(roleDisableMap.containsKey(key)){//存在权限问题
|
||||
DbFormRoleFieldVo roleVo = roleDisableMap.get(key);
|
||||
//如果全部为空话,看最大的那个,最大的那个为N说明是没有权限,需要剔除
|
||||
if(Func.isEmpty(roleVo.getFormIsEdit()) && Func.isEmpty(roleVo.getFormIsView()) && Func.isEmpty(roleVo.getListIsView())&&Func.equals(roleVo.getEnableState(), YNEnum.N.getCode())){
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* 移除不是界面显示的列表-列表数据
|
||||
*
|
||||
* @param records
|
||||
*/
|
||||
public void removeNotWebView(Long dbFormId, List<Map<String, Object>> records,List<DbFormRoleFieldVo> roleFieldVoList) {
|
||||
if (Func.isEmpty(records)) {
|
||||
return;
|
||||
}
|
||||
Map<String, DbFormRoleFieldVo> roleDisableMap =null;
|
||||
if(Func.isNotEmpty(roleFieldVoList)){
|
||||
//转为map
|
||||
roleDisableMap = roleFieldVoList.stream()
|
||||
.collect(Collectors.toMap(DbFormRoleFieldVo::getFieldCode, entity -> entity));
|
||||
}
|
||||
|
||||
IFormService formService = SpringUtils.getBean(IFormService.class);
|
||||
Set<String> webViewFieldSet = new HashSet<>(formService.getWebViewFieldList(dbFormId));
|
||||
|
||||
Map<String, DbFormRoleFieldVo> finalRoleDisableMap = roleDisableMap;
|
||||
ForkJoinPool pool = null;
|
||||
try {
|
||||
pool = FuncBase.jeelowcodeForkJoinPool();
|
||||
pool.submit(() -> records.parallelStream().forEach(recordMap -> recordMap.keySet().removeIf(key -> {
|
||||
if(Func.equals(key,"jeelowcode_subtable_data") || Func.equals(key,"hasChildren") || Func.equals(key,"leaf")){
|
||||
return false;
|
||||
}
|
||||
boolean noRoleFlag=false;
|
||||
if(Func.isNotEmpty(finalRoleDisableMap) && finalRoleDisableMap.containsKey(key)){
|
||||
DbFormRoleFieldVo roleVo = finalRoleDisableMap.get(key);
|
||||
//如果全部为空话,看最大的那个,最大的那个为N说明是没有权限,需要剔除
|
||||
if(Func.isEmpty(roleVo.getFormIsEdit()) && Func.isEmpty(roleVo.getFormIsView()) && Func.isEmpty(roleVo.getListIsView())&&Func.equals(roleVo.getEnableState(),YNEnum.N.getCode())){
|
||||
noRoleFlag=true;
|
||||
}
|
||||
}
|
||||
return !webViewFieldSet.contains(key) || noRoleFlag;
|
||||
}))).get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
} finally {
|
||||
if (pool != null) {
|
||||
pool.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理字段凭接(虚拟化字段)
|
||||
*
|
||||
* @param dbFormId
|
||||
* @param records
|
||||
*/
|
||||
public void webViewAppend(Long dbFormId, List<Map<String, Object>> records) {
|
||||
FormFieldWebMapper fieldWebMapper = SpringUtils.getBean(FormFieldWebMapper.class);
|
||||
FormFieldMapper fieldMapper = SpringUtils.getBean(FormFieldMapper.class);
|
||||
|
||||
// 获取表单的字段对应的字典
|
||||
IFormService formService = SpringUtils.getBean(IFormService.class);
|
||||
Map<String, Map<String, Object>> fieldDictMap = formService.getFieldDict(dbFormId);
|
||||
|
||||
//表单map
|
||||
Map<String, FormFieldEntity> dbFormMap = fieldMapper.getByDbFormMap(dbFormId);
|
||||
|
||||
List<FormFieldWebEntity> webEntityList = fieldWebMapper.webEntityListAndFormatConfigIsNotNull(dbFormId);
|
||||
webEntityList.stream().forEach(web->{
|
||||
String fieldCode = web.getFieldCode();
|
||||
String formatConfig = web.getFormatConfig();
|
||||
if(Func.isEmpty(formatConfig)){
|
||||
return;
|
||||
}
|
||||
FormFieldEntity formFieldEntity = dbFormMap.get(fieldCode);
|
||||
if(Func.isEmpty(formFieldEntity)){
|
||||
return;
|
||||
}
|
||||
String isDb = formFieldEntity.getIsDb();
|
||||
if(Func.equals(isDb,YNEnum.Y.getCode())){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WebFormatConfigModel webFormatConfigModel = Func.json2Bean(formatConfig, WebFormatConfigModel.class);
|
||||
if(Func.isEmpty(webFormatConfigModel)){
|
||||
return;
|
||||
}
|
||||
String formatType = webFormatConfigModel.getFormatType();
|
||||
if(Func.isEmpty(formatType) || !Func.equals(formatType,"java")){
|
||||
return;
|
||||
}
|
||||
WebFormatConfigModel.Json formatJson= webFormatConfigModel.getFormatJson();
|
||||
WebFormatConfigModel.JavaModel javaModel = formatJson.getJava();
|
||||
String valueType = javaModel.getValueType();
|
||||
List<WebFormatConfigModel.JavaGroup> groupList = javaModel.getGroup();
|
||||
WebFormatConfigModel.JavaCustom custom = javaModel.getCustom();
|
||||
switch (valueType){
|
||||
case "group"://表达式
|
||||
records.stream().forEach(record -> {
|
||||
record.put(fieldCode, this.getGroupVal(fieldDictMap, groupList, new HashMap<>(record)));
|
||||
});
|
||||
break;
|
||||
case "custom":
|
||||
records.stream().forEach(record -> {
|
||||
//运行插件
|
||||
String result = VirtualizationFieldPluginManager.executePlugin(custom.getJavaPath(), new HashMap<>(record));
|
||||
record.put(fieldCode, result);
|
||||
});
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//获取分组
|
||||
private String getGroupVal(Map<String, Map<String, Object>> fieldDictMap, List<WebFormatConfigModel.JavaGroup> groupList, Map<String, Object> dataMap) {
|
||||
this.replaceDict(fieldDictMap, dataMap);// 替换字典值
|
||||
String formatVal = ""; // 用于存储格式化后的值
|
||||
for (WebFormatConfigModel.JavaGroup group : groupList) {
|
||||
String value = group.getValue();
|
||||
String type = group.getType();
|
||||
if(Func.isEmpty(value)){
|
||||
continue;
|
||||
}
|
||||
switch (type) {
|
||||
case "CONCAT":
|
||||
formatVal += value;
|
||||
break;
|
||||
case "CALCULATE":
|
||||
formatVal += Func.executeJavaExpress(value, dataMap);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return formatVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换字典值
|
||||
*/
|
||||
private void replaceDict(Map<String, Map<String, Object>> fieldDictMap, Map<String, Object> dataMap){
|
||||
if (Func.isEmpty(fieldDictMap) || Func.isEmpty(dataMap)) {
|
||||
return;
|
||||
}
|
||||
fieldDictMap.keySet().stream().forEach(field -> {
|
||||
Object oldValue = dataMap.get(field);
|
||||
if (Func.isEmpty(oldValue)) {
|
||||
return;
|
||||
}
|
||||
Map<String, Object> dictMap = fieldDictMap.get(field);
|
||||
if (Func.isEmpty(dictMap)) {
|
||||
return;
|
||||
}
|
||||
Object newValue = dictMap.get(oldValue.toString());
|
||||
if (Func.isEmpty(newValue)) {
|
||||
return;
|
||||
}
|
||||
dataMap.put(field, newValue);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.definable.DefinablePluginManager;
|
||||
|
||||
/**
|
||||
* 自定义按钮执行者
|
||||
*/
|
||||
public class ButtonReceiverDefinable implements IButtonCommandReceiver<Object> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private Object param;
|
||||
|
||||
public ButtonReceiverDefinable(String pluginKey, Object param) {
|
||||
this.pluginKey = pluginKey;
|
||||
this.param = param;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Object receiver() {
|
||||
DefinablePluginManager definablePluginManager=new DefinablePluginManager();
|
||||
return definablePluginManager.executePlugin(pluginKey, param);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamDel;
|
||||
import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 删除按钮执行者
|
||||
*/
|
||||
public class ButtonReceiverDel implements IButtonCommandReceiver<ExecuteEnhanceModel> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private ButtonParamDel param;
|
||||
|
||||
public ButtonReceiverDel(ButtonParamDel param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExecuteEnhanceModel receiver() {
|
||||
IFrameService frameService = SpringUtils.getBean(IFrameService.class);
|
||||
Long dbformId = param.getDbFormId();
|
||||
List<Long> dataIdList = param.getDataIdList();
|
||||
|
||||
Map<String,Object> params=new HashMap<>();
|
||||
params.put("dataIdList",dataIdList);
|
||||
params.put("whereFieldCode","id");
|
||||
|
||||
//逻辑删除
|
||||
ExecuteEnhanceModel enhanceModel = frameService.delData(dbformId, params);
|
||||
return enhanceModel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamDetail;
|
||||
import com.jeelowcode.core.framework.params.vo.role.DbFormRoleFieldVo;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.core.framework.service.IDbFormRoleService;
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 详情按钮执行者
|
||||
*/
|
||||
public class ButtonReceiverDetail extends ButtonReceiverBase implements IButtonCommandReceiver<ResultDataModel> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private ButtonParamDetail param;
|
||||
|
||||
public ButtonReceiverDetail(ButtonParamDetail param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ResultDataModel receiver() {
|
||||
IFrameService frameService = SpringUtils.getBean(IFrameService.class);
|
||||
IDbFormRoleService dbFormRoleService = SpringUtils.getBean(IDbFormRoleService.class);
|
||||
IJeeLowCodeAdapter jeeLowCodeAdapter = SpringUtils.getBean(IJeeLowCodeAdapter.class);
|
||||
Long tenantId = jeeLowCodeAdapter.getTenantId();
|
||||
|
||||
Long dbformId = param.getDbFormId();
|
||||
Long dataId = param.getDataId();
|
||||
Map<String, Object> params = param.getParams();
|
||||
|
||||
List<DbFormRoleFieldVo> roleFieldVoList = dbFormRoleService.listRoleField(tenantId, dbformId,false);
|
||||
|
||||
ResultDataModel resultDataModel = frameService.getDataDetail(dbformId, dataId, params);
|
||||
super.webViewAppend(dbformId,resultDataModel.getRecords());
|
||||
super.removeNotWebView(dbformId,resultDataModel.getRecords(),roleFieldVoList);
|
||||
return resultDataModel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamEdit;
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 编辑按钮执行者
|
||||
*/
|
||||
public class ButtonReceiverEdit implements IButtonCommandReceiver<ExecuteEnhanceModel> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private ButtonParamEdit param;
|
||||
|
||||
public ButtonReceiverEdit(ButtonParamEdit param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExecuteEnhanceModel receiver() {
|
||||
IFrameService frameService = SpringUtils.getBean(IFrameService.class);
|
||||
Long dbformId = param.getDbFormId();
|
||||
Long dataId = param.getDataId();
|
||||
Map<String, Object> params = param.getParams();
|
||||
|
||||
ExecuteEnhanceModel enhanceModel = frameService.editData(dbformId, dataId, params);
|
||||
|
||||
return enhanceModel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamEditBatch;
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 编辑按钮执行者
|
||||
*/
|
||||
public class ButtonReceiverEditBatch implements IButtonCommandReceiver<ExecuteEnhanceModel> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private ButtonParamEditBatch param;
|
||||
|
||||
public ButtonReceiverEditBatch(ButtonParamEditBatch param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExecuteEnhanceModel receiver() {
|
||||
IFrameService frameService = SpringUtils.getBean(IFrameService.class);
|
||||
Long dbformId = param.getDbFormId();
|
||||
List<JSONObject> jsonObjectList = param.getJsonObjectList();
|
||||
frameService.editBatchData(dbformId, jsonObjectList);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamExport;
|
||||
import com.jeelowcode.core.framework.params.model.ExcelModel;
|
||||
import com.jeelowcode.core.framework.params.vo.role.DbFormRoleFieldVo;
|
||||
import com.jeelowcode.core.framework.service.IDbFormRoleService;
|
||||
import com.jeelowcode.core.framework.service.IExcelService;
|
||||
import com.jeelowcode.core.framework.service.IFormService;
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 新增导出执行者
|
||||
*/
|
||||
public class ButtonReceiverExport extends ButtonReceiverBase implements IButtonCommandReceiver<ExcelModel> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private ButtonParamExport param;
|
||||
|
||||
public ButtonReceiverExport(ButtonParamExport param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExcelModel receiver() {
|
||||
IExcelService excelService = SpringUtils.getBean(IExcelService.class);
|
||||
IFormService formService = SpringUtils.getBean(IFormService.class);
|
||||
IFrameService frameService = SpringUtils.getBean(IFrameService.class);
|
||||
IDbFormRoleService dbFormRoleService = SpringUtils.getBean(IDbFormRoleService.class);
|
||||
IJeeLowCodeAdapter jeeLowCodeAdapter = SpringUtils.getBean(IJeeLowCodeAdapter.class);
|
||||
|
||||
|
||||
Long tenantId = jeeLowCodeAdapter.getTenantId();
|
||||
|
||||
Long dbFormId = param.getDbFormId();
|
||||
Map<String, Object> params = param.getParams();
|
||||
|
||||
ResultDataModel model = frameService.getExportDataList(dbFormId, params);
|
||||
//数据
|
||||
List<Map<String, Object>> dataMapList = model.getRecords();
|
||||
//格式化数据,转为字符串
|
||||
formService.formatDataList(dbFormId,dataMapList);
|
||||
|
||||
//处理权限问题
|
||||
List<DbFormRoleFieldVo> roleFieldVoList = dbFormRoleService.listRoleField(tenantId, dbFormId,false);
|
||||
super.webViewAppend(dbFormId,dataMapList);//格式化
|
||||
super.removeNotWebView(dbFormId,dataMapList,roleFieldVoList);
|
||||
|
||||
//获取基本信息
|
||||
ExcelModel excelModel = excelService.getExportExcelModel(dbFormId);
|
||||
excelModel.setDataMapList(dataMapList);
|
||||
|
||||
//剔除表头
|
||||
super.removeNotExport(excelModel.getHeadTitleMap(),roleFieldVoList);
|
||||
return excelModel;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import com.jeelowcode.framework.excel.model.ExcelTitleModel;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamExportTemplate;
|
||||
import com.jeelowcode.core.framework.params.model.ExcelTemplateModel;
|
||||
import com.jeelowcode.core.framework.params.vo.role.DbFormRoleFieldVo;
|
||||
import com.jeelowcode.core.framework.service.IDbFormRoleService;
|
||||
import com.jeelowcode.core.framework.service.IExcelService;
|
||||
import org.apache.commons.collections4.map.LinkedMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 导出模板按钮执行者
|
||||
*/
|
||||
public class ButtonReceiverExportTemplate extends ButtonReceiverBase implements IButtonCommandReceiver<ExcelTemplateModel> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private ButtonParamExportTemplate param;
|
||||
|
||||
public ButtonReceiverExportTemplate(ButtonParamExportTemplate param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExcelTemplateModel receiver() {
|
||||
IExcelService excelService = SpringUtils.getBean(IExcelService.class);
|
||||
IDbFormRoleService dbFormRoleService = SpringUtils.getBean(IDbFormRoleService.class);
|
||||
IJeeLowCodeAdapter jeeLowCodeAdapter = SpringUtils.getBean(IJeeLowCodeAdapter.class);
|
||||
Long tenantId = jeeLowCodeAdapter.getTenantId();
|
||||
|
||||
Long dbFormId = param.getDbFormId();
|
||||
ExcelTemplateModel excelTemplateModel = excelService.getImportExcelTemplate(dbFormId);
|
||||
LinkedMap<String, ExcelTitleModel> headTitleMap = excelTemplateModel.getHeadTitleMap();
|
||||
|
||||
List<DbFormRoleFieldVo> roleFieldVoList = dbFormRoleService.listRoleField(tenantId, dbFormId,false);
|
||||
super.removeNotExport(headTitleMap,roleFieldVoList);
|
||||
return excelTemplateModel;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamImport;
|
||||
import com.jeelowcode.core.framework.params.model.ExcelImportResultModel;
|
||||
import com.jeelowcode.core.framework.service.IExcelFileService;
|
||||
import com.jeelowcode.core.framework.service.IExcelService;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
/**
|
||||
* 新增按钮执行者
|
||||
*/
|
||||
public class ButtonReceiverImport implements IButtonCommandReceiver<ExcelImportResultModel> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private ButtonParamImport param;
|
||||
|
||||
public ButtonReceiverImport(ButtonParamImport param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ExcelImportResultModel receiver() {
|
||||
IExcelService excelService = SpringUtils.getBean(IExcelService.class);
|
||||
IExcelFileService excelFileService = SpringUtils.getBean(IExcelFileService.class);
|
||||
|
||||
// 将request设置为子线程共享
|
||||
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
|
||||
ExcelImportResultModel resultModel=null;
|
||||
//保存Excel数据
|
||||
String serviceType = param.getServiceType();
|
||||
switch (serviceType){
|
||||
case "IMPORT_TEMPLATE"://导入excel到临时库
|
||||
long fileId = IdWorker.getId();
|
||||
excelFileService.saveExcelSync(fileId,param);
|
||||
|
||||
resultModel = new ExcelImportResultModel();
|
||||
resultModel.setBatchCode(Func.toStr(fileId));
|
||||
resultModel.setDbFormId(param.getDbFormId());
|
||||
resultModel.setTotalCou(param.getDataMapList().size());
|
||||
resultModel.setFileId(fileId);
|
||||
break;
|
||||
case "HANBLE_TEMPLATE"://处理临时库数据
|
||||
excelService.handleTempTable(sra,param.getDbFormId(),param.getBatchCode());
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return resultModel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
|
||||
import com.jeelowcode.framework.utils.enums.ParamEnum;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamList;
|
||||
import com.jeelowcode.core.framework.params.vo.role.DbFormRoleFieldVo;
|
||||
import com.jeelowcode.core.framework.service.IDbFormRoleService;
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 编辑按钮执行者
|
||||
*/
|
||||
public class ButtonReceiverList extends ButtonReceiverBase implements IButtonCommandReceiver<ResultDataModel> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private ButtonParamList param;
|
||||
|
||||
public ButtonReceiverList(ButtonParamList param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ResultDataModel receiver() {
|
||||
IFrameService frameService = SpringUtils.getBean(IFrameService.class);
|
||||
IDbFormRoleService dbFormRoleService = SpringUtils.getBean(IDbFormRoleService.class);
|
||||
IJeeLowCodeAdapter jeeLowCodeAdapter = SpringUtils.getBean(IJeeLowCodeAdapter.class);
|
||||
Long tenantId = jeeLowCodeAdapter.getTenantId();
|
||||
|
||||
|
||||
Long dbformId = param.getDbFormId();
|
||||
Map<String, Object> params = param.getParams();
|
||||
if(Func.isNotEmpty(params)){
|
||||
params.remove(ParamEnum.ALL_QUERY_FIELD.getCode());//特殊字段不允许用户带过来
|
||||
}
|
||||
Page page = param.getPage();
|
||||
ResultDataModel resultDataModel = frameService.getDataList(dbformId, page, params);
|
||||
|
||||
List<DbFormRoleFieldVo> roleFieldVoList = dbFormRoleService.listRoleField(tenantId, dbformId,false);
|
||||
super.webViewAppend(dbformId,resultDataModel.getRecords());//格式化
|
||||
super.removeNotWebView(dbformId,resultDataModel.getRecords(),roleFieldVoList);
|
||||
return resultDataModel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamReportExport;
|
||||
import com.jeelowcode.core.framework.params.model.ExcelModel;
|
||||
import com.jeelowcode.core.framework.service.IExcelService;
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 新增报表导出执行者
|
||||
*/
|
||||
public class ButtonReceiverReportExport extends ButtonReceiverBase implements IButtonCommandReceiver<ExcelModel> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private ButtonParamReportExport param;
|
||||
|
||||
public ButtonReceiverReportExport(ButtonParamReportExport param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ExcelModel receiver() {
|
||||
IExcelService excelService = SpringUtils.getBean(IExcelService.class);
|
||||
IFrameService frameService = SpringUtils.getBean(IFrameService.class);
|
||||
|
||||
String reportCode = param.getReportCode();
|
||||
Map<String, Object> params = param.getParams();
|
||||
|
||||
//数据列表
|
||||
Page page=new Page(1,-1);
|
||||
ResultDataModel model = frameService.getReportDataList(reportCode, page,params);
|
||||
|
||||
//获取基本信息
|
||||
ExcelModel excelModel = excelService.getExcelReportModel(reportCode);
|
||||
excelModel.setDataMapList(model.getRecords());
|
||||
|
||||
return excelModel;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamReportList;
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据报表分页执行者
|
||||
*/
|
||||
public class ButtonReceiverReportList extends ButtonReceiverBase implements IButtonCommandReceiver<ResultDataModel> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private ButtonParamReportList param;
|
||||
|
||||
public ButtonReceiverReportList(ButtonParamReportList param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ResultDataModel receiver() {
|
||||
|
||||
String reportCode = param.getReportCode();
|
||||
Page page = param.getPage();
|
||||
Map<String, Object> params = param.getParams();
|
||||
|
||||
IFrameService frameService = SpringUtils.getBean(IFrameService.class);
|
||||
ResultDataModel reportDataPage = frameService.getReportDataList(reportCode, page, params);
|
||||
return reportDataPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.ButtonParamSummary;
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 统计按钮执行者
|
||||
*/
|
||||
public class ButtonReceiverSummary implements IButtonCommandReceiver<Map<String, Object>> {
|
||||
|
||||
|
||||
private String pluginKey;
|
||||
|
||||
private ButtonParamSummary param;
|
||||
|
||||
public ButtonReceiverSummary(ButtonParamSummary param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> receiver() {
|
||||
IFrameService frameService = SpringUtils.getBean(IFrameService.class);
|
||||
Long dbformId = param.getDbFormId();
|
||||
Map<String, Object> params = param.getParams();
|
||||
ResultDataModel resultDataModel = frameService.getDataSummaryList(dbformId, params);
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
if(Func.isEmpty(resultDataModel)){
|
||||
return resultMap;
|
||||
}
|
||||
List<Map<String, Object>> dataMapList = resultDataModel.getRecords();
|
||||
if (Func.isEmpty(dataMapList)) {//数据为空
|
||||
return resultMap;
|
||||
}
|
||||
return dataMapList.get(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.btncommand.receiver;
|
||||
|
||||
/**
|
||||
* 按钮执行者
|
||||
* @param <T> 返回值
|
||||
*/
|
||||
public interface IButtonCommandReceiver<T> {
|
||||
|
||||
/**
|
||||
* 执行
|
||||
* @return
|
||||
*/
|
||||
T receiver();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.job;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.jeelowcode.tool.framework.quartz.core.handler.JobHandler;
|
||||
import com.jeelowcode.core.framework.service.IJeeLowCodeConfigService;
|
||||
import com.jeelowcode.core.framework.service.IJeeLowCodeService;
|
||||
import com.jeelowcode.framework.tenant.annotation.JeeLowCodeTenantIgnore;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 删除excel临时表数据
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ClearExcelDataJob implements JobHandler {
|
||||
|
||||
@Autowired
|
||||
private IJeeLowCodeService jeeLowCodeService;
|
||||
|
||||
@Autowired
|
||||
private IJeeLowCodeConfigService jeeLowCodeConfigService;
|
||||
|
||||
|
||||
@Override
|
||||
@JeeLowCodeTenantIgnore
|
||||
public String execute(String param) {
|
||||
log.info("*********** 开始清理Excel Data日志 ************");
|
||||
Date now = DateUtil.date();
|
||||
Integer day = jeeLowCodeConfigService.getExcelFileDataDay();
|
||||
|
||||
//x天之前
|
||||
Date clearDate = DateUtil.offsetDay(now, -day);
|
||||
|
||||
Integer clearCou = jeeLowCodeService.clearExcelData(clearDate);
|
||||
|
||||
String resultStr="*********** Excel Data日志清理完成,共清理了"+clearCou+"条 ************";
|
||||
log.info(resultStr);
|
||||
return resultStr;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.job;
|
||||
|
||||
import com.jeelowcode.tool.framework.quartz.core.handler.JobHandler;
|
||||
import com.jeelowcode.core.framework.service.IJeeLowCodeService;
|
||||
import com.jeelowcode.framework.tenant.annotation.JeeLowCodeTenantIgnore;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 保存模块使用记录
|
||||
*/
|
||||
@Slf4j
|
||||
@Component("saveModelUsageRecordsJob")
|
||||
public class SaveModelUsageRecordsJob implements JobHandler {
|
||||
|
||||
@Autowired
|
||||
private IJeeLowCodeService jeeLowCodeService;
|
||||
|
||||
@Override
|
||||
@JeeLowCodeTenantIgnore
|
||||
public String execute(String param) {
|
||||
log.info("*********** 开始保存模块使用记录 ************");
|
||||
Integer cou = jeeLowCodeService.saveModelUsageRecords();
|
||||
String resultStr = "*********** 保存模块使用记录完成,共保存了" + cou + "条 ************";
|
||||
log.info(resultStr);
|
||||
return resultStr;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.jeelowcode.core.framework.config.job;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.jeelowcode.core.framework.controller.BaseController;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.jeelowcode.module.api.JeeLowCodeApi;
|
||||
import com.jeelowcode.tool.framework.quartz.core.handler.JobHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 同步报表 获取阿里隐患工单 数据
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SyncRiskDataJob extends BaseController implements JobHandler {
|
||||
|
||||
@Autowired
|
||||
private JeeLowCodeApi jeeLowCodeApi;;
|
||||
|
||||
@Override
|
||||
public String execute(String param) throws Exception {
|
||||
log.info("*********** 开始同步报表 获取阿里隐患工单数据 日志 ************");
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
ResultDataModel pages = getReportDataList(param, params);
|
||||
jeeLowCodeApi.syncData(param,params,pages);
|
||||
|
||||
int syncCount=pages.getRecords().size();
|
||||
String resultStr="*********** 同步报表 获取阿里隐患工单 数据完成,共同步了"+syncCount+"条 ************";
|
||||
log.info(resultStr);
|
||||
return resultStr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.listener;
|
||||
|
||||
import com.jeelowcode.core.framework.service.IFormService;
|
||||
import com.jeelowcode.core.framework.service.IReportService;
|
||||
import com.jeelowcode.framework.utils.component.redis.JeeLowCodeRedisUtils;
|
||||
import groovy.lang.GroovyClassLoader;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Order(value = 999)
|
||||
@Component
|
||||
public class JeeLowCodeListener implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
@Autowired
|
||||
JeeLowCodeRedisUtils redisUtil;
|
||||
|
||||
@Autowired
|
||||
private IFormService dbFormService;
|
||||
|
||||
@Autowired
|
||||
private IReportService reportService;
|
||||
|
||||
|
||||
public GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
|
||||
|
||||
public GroovyClassLoader getGroovyClassLoader() {
|
||||
return groovyClassLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
dbFormService.initConfigBtnCommand();
|
||||
log.info("1.初始化自定义按钮--->完成");
|
||||
dbFormService.cleanCache();
|
||||
log.info("2.清除框架缓存--->完成");
|
||||
dbFormService.initOnlineScript(groovyClassLoader);
|
||||
log.info("3.初始化在线脚本--->完成");
|
||||
dbFormService.initEnhancePluginManager();
|
||||
log.info("4.初始化增强--->完成");
|
||||
reportService.initEnhancePluginManager();
|
||||
log.info("5.初始化报表增强--->完成");
|
||||
dbFormService.initDataAuthTable();
|
||||
log.info("6.处理那些表需要做数据权限--->完成");
|
||||
dbFormService.initOtherDataSource();
|
||||
log.info("7.初始化动态数据源--->完成");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.log;
|
||||
|
||||
|
||||
|
||||
import com.jeelowcode.tool.framework.common.util.servlet.ServletUtils;
|
||||
import com.jeelowcode.core.framework.adapter.FrameWorkAdapter;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeException;
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeMoreException;
|
||||
import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import com.jeelowcode.core.framework.params.model.LogRequestApiModel;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.util.ContentCachingRequestWrapper;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 请求日志切面
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class ApiLogAspect {
|
||||
|
||||
|
||||
|
||||
// JeeLowCode
|
||||
@Pointcut("execution(* com.jeelowcode.core.framework.controller.*Controller.*(..)))")
|
||||
private void pointcutJeeLowCode() {}
|
||||
|
||||
// 芋道
|
||||
@Pointcut("@annotation(io.swagger.v3.oas.annotations.Operation)")
|
||||
private void pointcutFrameWork() {}
|
||||
|
||||
|
||||
/**
|
||||
* 切入点是所有控制住
|
||||
* @param point
|
||||
* @return
|
||||
* @throws Throwable
|
||||
*/
|
||||
@Around("pointcutJeeLowCode()||pointcutFrameWork()")
|
||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||
//获取类名
|
||||
String className = point.getTarget().getClass().getName();
|
||||
//获取方法
|
||||
String methodName = point.getSignature().getName();
|
||||
|
||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
Operation operation = method.getAnnotation(Operation.class);
|
||||
String modelName="其他模块";
|
||||
if(Func.isNotEmpty(operation) && Func.isNotEmpty(operation.tags())){
|
||||
modelName =operation.tags()[0];
|
||||
}
|
||||
|
||||
String apiName="请求日志";
|
||||
if(Func.isNotEmpty(operation) && Func.isNotEmpty(operation.summary())){
|
||||
apiName =operation.summary();
|
||||
}
|
||||
if (Func.equals("刷新令牌", apiName)){
|
||||
return point.proceed();
|
||||
}
|
||||
|
||||
// 发送异步日志事件
|
||||
long beginTime = System.currentTimeMillis();
|
||||
|
||||
LogRequestApiModel logApiModel = getRequestParam(methodName, className, apiName,modelName);
|
||||
//执行方法
|
||||
String error="";
|
||||
try{
|
||||
return point.proceed();
|
||||
}catch (JeeLowCodeMoreException e){
|
||||
String message = e.getMessage();
|
||||
Map<String,String> map = Func.json2Bean(message, Map.class);
|
||||
String title = map.get("title");
|
||||
String e1 = map.get("e");
|
||||
error=getErrorStr(e);
|
||||
throw new JeeLowCodeMoreException(title,e1);
|
||||
}catch (JeeLowCodeException e){
|
||||
error=getErrorStr(e);
|
||||
throw new JeeLowCodeException(e.getMessage());
|
||||
}catch (Exception e){
|
||||
error=getErrorStr(e);
|
||||
throw e;
|
||||
}finally {
|
||||
//执行时长(毫秒)
|
||||
long time = System.currentTimeMillis() - beginTime;
|
||||
//记录日志
|
||||
this.publishEvent(logApiModel, time,error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//获取具体错误信息
|
||||
private static String getErrorStr(Exception e){
|
||||
StringBuffer sb=new StringBuffer();
|
||||
sb.append(e).append("\r\n");
|
||||
StackTraceElement[] trace = e.getStackTrace();
|
||||
for (StackTraceElement traceElement : trace){
|
||||
sb.append("\tat ").append(traceElement).append("\r\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static LogRequestApiModel getRequestParam(String methodName, String methodClass, String title,String modelTitle) {
|
||||
try{
|
||||
HttpServletRequest request = FuncWeb.getRequest();
|
||||
ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request);
|
||||
|
||||
FrameWorkAdapter jeeLowCodeAdapter = SpringUtils.getBean(FrameWorkAdapter.class);
|
||||
|
||||
LogRequestApiModel logApiModel=new LogRequestApiModel();
|
||||
logApiModel.setId(IdWorker.getId());
|
||||
logApiModel.setTenantId(jeeLowCodeAdapter.getTenantId());
|
||||
logApiModel.setCreateUser(jeeLowCodeAdapter.getOnlineUserId());
|
||||
logApiModel.setCreateUserName(jeeLowCodeAdapter.getOnlineUserName());
|
||||
logApiModel.setCreateTime(LocalDateTime.now());
|
||||
|
||||
logApiModel.setIp(ServletUtils.getClientIP(request));//ip
|
||||
logApiModel.setTitle(title);
|
||||
logApiModel.setModelTitle(modelTitle);//模块名称
|
||||
logApiModel.setMethodName(methodName);//方法名称
|
||||
logApiModel.setMethodClass(methodClass);//类名称
|
||||
logApiModel.setRequestUri(FuncWeb.getPath(requestWrapper.getRequestURI()));//请求url
|
||||
logApiModel.setRequestParams(FuncWeb.getRequestParams(requestWrapper));//请求参数
|
||||
logApiModel.setRequestMethod(requestWrapper.getMethod());//请求方式
|
||||
|
||||
|
||||
return logApiModel;
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void publishEvent(LogRequestApiModel logApiModel, long time, String error) {
|
||||
try{
|
||||
if(FuncBase.isEmpty(logApiModel)){
|
||||
return;
|
||||
}
|
||||
String requestUri = logApiModel.getRequestUri();
|
||||
if(Func.equals(requestUri, JeeLowCodeBaseConstant.REQUEST_URL_START+"/apilog/page") || Func.equals(requestUri,JeeLowCodeBaseConstant.REQUEST_URL_START+"/apilog/detail")){
|
||||
return;//本身查看
|
||||
}
|
||||
|
||||
|
||||
logApiModel.setTime(time);//耗时
|
||||
logApiModel.setError(error);
|
||||
|
||||
SpringUtils.getApplicationContext().publishEvent(new ApiLogEvent(logApiModel));
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.log;
|
||||
|
||||
import com.jeelowcode.core.framework.params.model.LogRequestApiModel;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
public class ApiLogEvent extends ApplicationEvent {
|
||||
|
||||
public ApiLogEvent(LogRequestApiModel model) {
|
||||
super(model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.log;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.jeelowcode.core.framework.entity.LogRequestApiEntity;
|
||||
import com.jeelowcode.core.framework.entity.LogRequestErrorApiEntity;
|
||||
import com.jeelowcode.core.framework.mapper.LogApiErrorMapper;
|
||||
import com.jeelowcode.core.framework.mapper.LogApiMapper;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import com.jeelowcode.core.framework.params.model.LogRequestApiModel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 异步监听日志事件
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class ApiLogListener {
|
||||
|
||||
|
||||
@Autowired
|
||||
private LogApiMapper logApiMapper;
|
||||
|
||||
@Autowired
|
||||
private LogApiErrorMapper logApiErrorMapper;
|
||||
|
||||
static List<String> skipModelTitleList=new ArrayList();
|
||||
static {
|
||||
skipModelTitleList.add("授权管理");
|
||||
}
|
||||
|
||||
|
||||
@Async("asyncPoolTaskExecutor")
|
||||
@Order
|
||||
@EventListener(ApiLogEvent.class)
|
||||
public void saveApiLog(ApiLogEvent event) {
|
||||
LogRequestApiModel apiModel =(LogRequestApiModel)event.getSource();
|
||||
String error = apiModel.getError();
|
||||
String modelTitle = apiModel.getModelTitle();
|
||||
if(Func.isNotEmpty(modelTitle) && skipModelTitleList.contains(modelTitle)){
|
||||
return;
|
||||
}
|
||||
|
||||
if(Func.isEmpty(error)){//正常日志
|
||||
LogRequestApiEntity infoEntity = BeanUtil.copyProperties(apiModel, LogRequestApiEntity.class);
|
||||
logApiMapper.insert(infoEntity);
|
||||
}else{//错误日志
|
||||
LogRequestErrorApiEntity errorEntity = BeanUtil.copyProperties(apiModel, LogRequestErrorApiEntity.class);
|
||||
logApiErrorMapper.insert(errorEntity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.validate;
|
||||
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeException;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeelowCodeValidate;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import com.jeelowcode.framework.utils.utils.JeeLowCodeUtils;
|
||||
import com.jeelowcode.framework.utils.component.properties.JeeLowCodeProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* 校验表名是否合法
|
||||
*/
|
||||
@Component
|
||||
public class DbFormCopyValidate implements IJeelowCodeValidate {
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private IFrameService frameService;
|
||||
|
||||
@Override
|
||||
public void validate(HttpServletRequest req) throws JeeLowCodeException {
|
||||
Map<String, Object> parameterMap = FuncWeb.getParameterMap(req);
|
||||
String tableName = JeeLowCodeUtils.getMap2Str(parameterMap, "tableName");
|
||||
|
||||
if (FuncBase.isEmpty(tableName)) {
|
||||
throw new JeeLowCodeException("表名不允许为空");
|
||||
}
|
||||
|
||||
if (!Func.checkTableName(tableName)) {
|
||||
StringJoiner joiner = new StringJoiner(",");
|
||||
JeeLowCodeProperties.getExcludeTableNames().forEach(joiner::add);
|
||||
String errorMsg = joiner.toString();
|
||||
throw new JeeLowCodeException(String.format("表名称不允许以【%s】开头", errorMsg));
|
||||
}
|
||||
//校验表名是否重复
|
||||
if (frameService.checkTable(tableName)) {
|
||||
String errorStr = String.format("数据库表【%s】已存在", tableName);
|
||||
throw new JeeLowCodeException(errorStr);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.validate;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jeelowcode.core.framework.entity.ReportEntity;
|
||||
import com.jeelowcode.core.framework.service.IReportService;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeException;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeelowCodeValidate;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import com.jeelowcode.framework.utils.utils.JeeLowCodeUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 校验表名是否合法
|
||||
*/
|
||||
@Component
|
||||
public class ReportCopyValidate implements IJeelowCodeValidate {
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private IReportService reportService;
|
||||
|
||||
@Override
|
||||
public void validate(HttpServletRequest req) throws JeeLowCodeException {
|
||||
Map<String, Object> parameterMap = FuncWeb.getParameterMap(req);
|
||||
String reportCode = JeeLowCodeUtils.getMap2Str(parameterMap, "reportCode");
|
||||
|
||||
if (FuncBase.isEmpty(reportCode)) {
|
||||
throw new JeeLowCodeException("报表编号不允许为空");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<ReportEntity> wrapper=new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ReportEntity::getReportCode,reportCode);
|
||||
long count = reportService.count(wrapper);
|
||||
|
||||
//校验表名是否重复
|
||||
if (count>0) {
|
||||
String errorStr = String.format("报表编号【%s】已存在", reportCode);
|
||||
throw new JeeLowCodeException(errorStr);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.validate;
|
||||
|
||||
import com.jeelowcode.core.framework.params.DbFormAddOrUpdateParam;
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeException;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeelowCodeValidate;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import com.jeelowcode.framework.utils.component.properties.JeeLowCodeProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* 校验表名是否合法
|
||||
*/
|
||||
@Component
|
||||
public class TableNameValidate implements IJeelowCodeValidate {
|
||||
|
||||
@Autowired
|
||||
private IFrameService frameService;
|
||||
|
||||
@Override
|
||||
public void validate(HttpServletRequest req) throws JeeLowCodeException {
|
||||
DbFormAddOrUpdateParam param = FuncWeb.getParameterBodyObj(req, DbFormAddOrUpdateParam.class);
|
||||
String tableName = param.getDbForm().getTableName().trim();
|
||||
if (FuncBase.isEmpty(tableName)) {
|
||||
throw new JeeLowCodeException("表名不允许为空");
|
||||
}
|
||||
|
||||
if (!Func.checkTableName(tableName)) {
|
||||
StringJoiner joiner = new StringJoiner(",");
|
||||
JeeLowCodeProperties.getExcludeTableNames().forEach(joiner::add);
|
||||
String errorMsg = joiner.toString();
|
||||
throw new JeeLowCodeException(String.format("表名称不允许以【%s】开头", errorMsg));
|
||||
}
|
||||
//校验表名是否重复
|
||||
if (frameService.checkTable(tableName)) {
|
||||
String errorStr = String.format("数据库表【%s】已存在", tableName);
|
||||
throw new JeeLowCodeException(errorStr);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.virtualization;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 虚拟化字段相关-JAVA函数处理
|
||||
*/
|
||||
public interface VirtualizationFieldPlugin {
|
||||
|
||||
String execute(Map<String, Object> dataMap);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
|
||||
package com.jeelowcode.core.framework.config.virtualization;
|
||||
|
||||
import cn.hutool.cache.Cache;
|
||||
import cn.hutool.cache.CacheUtil;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeException;
|
||||
import com.jeelowcode.framework.utils.tool.spring.SpringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 虚拟化字段 插件管理器
|
||||
*/
|
||||
@Slf4j
|
||||
public class VirtualizationFieldPluginManager {
|
||||
|
||||
//只保留最近10个常用的
|
||||
static Cache<String, VirtualizationFieldPlugin> cache = CacheUtil.newLRUCache(10);
|
||||
|
||||
//初始化实例
|
||||
public static VirtualizationFieldPlugin initClazz(String clazzStr) {
|
||||
try {
|
||||
if(clazzStr.contains(".")){//全路径
|
||||
Class<?> clazz = Class.forName(clazzStr);
|
||||
VirtualizationFieldPlugin plugin = (VirtualizationFieldPlugin)clazz.newInstance();//实例化
|
||||
return plugin;
|
||||
}else{
|
||||
VirtualizationFieldPlugin plugin = (VirtualizationFieldPlugin)SpringUtils.getBean(clazzStr);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new JeeLowCodeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//添加插件
|
||||
private static void addPlugin(String key, VirtualizationFieldPlugin plugin) {
|
||||
cache.put(key, plugin);
|
||||
}
|
||||
|
||||
|
||||
private static VirtualizationFieldPlugin getPlugin(String key) {
|
||||
if (cache.containsKey(key)) {
|
||||
return cache.get(key);
|
||||
}
|
||||
|
||||
//没有在队列里面,则重新实例化
|
||||
addPlugin(key, initClazz(key));
|
||||
return cache.get(key);
|
||||
}
|
||||
|
||||
//运行插件
|
||||
public static String executePlugin(String key,Map<String,Object> dataMap) {
|
||||
VirtualizationFieldPlugin plugin = getPlugin(key);
|
||||
if(Func.isEmpty(plugin)){
|
||||
return null;
|
||||
}
|
||||
return plugin.execute(dataMap);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
|
||||
package com.jeelowcode.core.framework.controller;
|
||||
|
||||
import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
|
||||
import com.jeelowcode.framework.utils.model.JeeLowCodeDept;
|
||||
import com.jeelowcode.framework.utils.model.JeeLowCodeRole;
|
||||
import com.jeelowcode.framework.utils.model.JeeLowCodeUser;
|
||||
import com.jeelowcode.framework.utils.model.JeeLowTenant;
|
||||
import com.jeelowcode.framework.utils.params.JeeLowCodeDeptParam;
|
||||
import com.jeelowcode.framework.utils.params.JeeLowCodeUserParam;
|
||||
import com.jeelowcode.framework.utils.model.global.BaseWebResult;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "低代码框架-芋道框架接口")
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(JeeLowCodeBaseConstant.REQUEST_URL_START + "/adapter")
|
||||
public class AdapterController extends BaseController {
|
||||
|
||||
private final IJeeLowCodeAdapter jeeLowCodeAdapter;
|
||||
|
||||
@GetMapping("/tenant/list")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(tags = "芋道适配器",summary = "获取租户列表")
|
||||
public BaseWebResult tenantList() {
|
||||
List<JeeLowTenant> tenantList = jeeLowCodeAdapter.getTenantList();
|
||||
return BaseWebResult.success(tenantList);
|
||||
}
|
||||
|
||||
@GetMapping("/dept/list")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(tags = "芋道适配器",summary = "获取部门列表")
|
||||
public BaseWebResult deptList(JeeLowCodeDeptParam param) {
|
||||
List<JeeLowCodeDept> deptList = jeeLowCodeAdapter.getDeptList(param);
|
||||
return BaseWebResult.success(deptList);
|
||||
}
|
||||
|
||||
@GetMapping("/role/list")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(tags = "芋道适配器",summary = "获取角色列表")
|
||||
public BaseWebResult roleList() {
|
||||
List<JeeLowCodeRole> roleList = jeeLowCodeAdapter.getRoleList();
|
||||
return BaseWebResult.success(roleList);
|
||||
}
|
||||
|
||||
@PostMapping("/user/list")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "芋道适配器",summary = "获取用户列表")
|
||||
public BaseWebResult userList(@RequestBody JeeLowCodeUserParam param) {
|
||||
IPage<JeeLowCodeUser> userPage =(IPage<JeeLowCodeUser>) jeeLowCodeAdapter.getUserPage(param.getPageNo(), param.getPageSize(), param);
|
||||
return BaseWebResult.success(userPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
|
||||
package com.jeelowcode.core.framework.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import com.jeelowcode.core.framework.entity.LogRequestApiEntity;
|
||||
import com.jeelowcode.core.framework.entity.LogRequestErrorApiEntity;
|
||||
import com.jeelowcode.core.framework.params.LogRequestApiParam;
|
||||
import com.jeelowcode.core.framework.params.vo.PageVo;
|
||||
import com.jeelowcode.core.framework.service.IApiLogService;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
|
||||
import com.jeelowcode.framework.utils.model.global.BaseWebResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
@Tag(name = "低代码框架-API请求接口")
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(JeeLowCodeBaseConstant.REQUEST_URL_START + "/apilog")
|
||||
public class ApiLogController extends BaseController {
|
||||
|
||||
private final IApiLogService apiLogService;
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('api:log')")
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(tags = "审计日志",summary = "增强-详情")
|
||||
public BaseWebResult getDetail(LogRequestApiParam param) {
|
||||
String logType = param.getLogType();
|
||||
if (Func.equals(logType, "error")) {
|
||||
LogRequestErrorApiEntity detailEntity = apiLogService.getErrorApiLogDetail(param.getId());
|
||||
return BaseWebResult.success(detailEntity);
|
||||
}
|
||||
LogRequestApiEntity detailEntity = apiLogService.getInfoApiLogDetail(param.getId());
|
||||
return BaseWebResult.success(detailEntity);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('api:log')")
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "审计日志",summary = "删除(真实删除)")
|
||||
public BaseWebResult del(LogRequestApiParam param) {
|
||||
DateTime delDateTime = DateUtil.parse(param.getDelDate(), "yyyy-MM-dd");
|
||||
String logType = param.getLogType();
|
||||
if (Func.equals(logType, "error")) {
|
||||
apiLogService.clearApiErrorLog(delDateTime);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
apiLogService.clearApiLog(delDateTime);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('api:log')")
|
||||
@GetMapping("/page")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "审计日志",summary = "获取列表(分页)")
|
||||
public BaseWebResult page(LogRequestApiParam param, PageVo pageVo) {
|
||||
Page page = FuncWeb.getPage(pageVo.getPageNo(), pageVo.getPageSize());
|
||||
String logType = param.getLogType();
|
||||
if (Func.equals(logType, "error")) {
|
||||
IPage<LogRequestErrorApiEntity> pages = apiLogService.getErrorApiLogPage(param,page);
|
||||
return BaseWebResult.success(pages);
|
||||
}
|
||||
IPage<LogRequestApiEntity> pages = apiLogService.getInfoApiLogPage(param,page);
|
||||
return BaseWebResult.success(pages);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,436 @@
|
||||
|
||||
package com.jeelowcode.core.framework.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.jeelowcode.core.framework.config.btncommand.ButtonInvoker;
|
||||
import com.jeelowcode.core.framework.config.btncommand.button.*;
|
||||
import com.jeelowcode.core.framework.config.btncommand.param.*;
|
||||
import com.jeelowcode.core.framework.config.btncommand.receiver.*;
|
||||
import com.jeelowcode.core.framework.entity.FormFieldDictEntity;
|
||||
import com.jeelowcode.core.framework.entity.FormFieldEntity;
|
||||
import com.jeelowcode.core.framework.entity.FormFieldQueryEntity;
|
||||
import com.jeelowcode.core.framework.entity.FormFieldWebEntity;
|
||||
import com.jeelowcode.core.framework.params.model.ExcelImportResultModel;
|
||||
import com.jeelowcode.core.framework.params.model.ExcelModel;
|
||||
import com.jeelowcode.core.framework.params.model.ExcelTemplateModel;
|
||||
import com.jeelowcode.core.framework.params.vo.FormEntityPageVo;
|
||||
import com.jeelowcode.core.framework.service.IFormService;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeException;
|
||||
import com.jeelowcode.framework.utils.enums.JeeLowCodeFieldTypeEnum;
|
||||
import com.jeelowcode.framework.utils.model.ExecuteEnhanceModel;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
|
||||
@Tag(name = "低代码框架-公共框架接口")
|
||||
public class BaseController {
|
||||
|
||||
|
||||
/**
|
||||
* 转换类型
|
||||
* @param source
|
||||
* @param targetType
|
||||
* @param <S>
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <S, T> List<T> toVoBean(List<S> source, Class<T> targetType) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
List<T> list = BeanUtil.copyToList(source, targetType);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换类型
|
||||
* @param source
|
||||
* @param targetType
|
||||
* @param <S>
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <S, T> IPage<T> toVoBean(IPage<S> source, Class<T> targetType) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
List<T> list = BeanUtil.copyToList(source.getRecords(), targetType);
|
||||
|
||||
IPage<T> resultPage=new Page<>();
|
||||
resultPage.setTotal(source.getTotal());
|
||||
resultPage.setRecords(list);
|
||||
resultPage.setPages(source.getPages());
|
||||
resultPage.setSize(source.getSize());
|
||||
resultPage.setCurrent(source.getCurrent());
|
||||
return resultPage;
|
||||
}
|
||||
|
||||
|
||||
//获取分页数据列表
|
||||
protected ResultDataModel getDataPage(Long dbformId, Map<String, Object> params){
|
||||
Page page = FuncWeb.getPage(params);
|
||||
|
||||
//封装参数
|
||||
ButtonParamList buttonParam = new ButtonParamList();
|
||||
buttonParam.setDbFormId(dbformId);
|
||||
buttonParam.setParams(params);
|
||||
buttonParam.setPage(page);
|
||||
//执行者绑定参数
|
||||
IButtonCommandReceiver receiver = new ButtonReceiverList(buttonParam);
|
||||
|
||||
//执行者和命令绑定
|
||||
ListButtonCommand command = new ListButtonCommand(receiver);
|
||||
|
||||
//创建调用者
|
||||
ButtonInvoker<ResultDataModel> invoker = new ButtonInvoker();
|
||||
invoker.setButtonCommand(command);//调用者设置命令
|
||||
ResultDataModel resultDataModel = invoker.executeCommand();//调用者下发命令
|
||||
|
||||
return resultDataModel;
|
||||
}
|
||||
|
||||
//获取统计
|
||||
protected Map getSummaryData(Long dbformId, Map<String, Object> params){
|
||||
//封装参数
|
||||
ButtonParamSummary buttonParam = new ButtonParamSummary();
|
||||
buttonParam.setDbFormId(dbformId);
|
||||
buttonParam.setParams(params);
|
||||
|
||||
//执行者绑定参数
|
||||
IButtonCommandReceiver receiver = new ButtonReceiverSummary(buttonParam);
|
||||
|
||||
//执行者和命令绑定
|
||||
SummaryButtonCommand command = new SummaryButtonCommand(receiver);
|
||||
|
||||
//创建调用者
|
||||
ButtonInvoker<Map> invoker = new ButtonInvoker();
|
||||
invoker.setButtonCommand(command);//调用者设置命令
|
||||
Map map = invoker.executeCommand();//调用者下发命令
|
||||
return map;
|
||||
}
|
||||
|
||||
//获取详情数据列表
|
||||
protected ResultDataModel getDataDetail(Long dbformId,Long dataId, Map<String, Object> params){
|
||||
//封装参数
|
||||
params.put("id",dataId);//把id放到参数集合里面
|
||||
|
||||
ButtonParamDetail buttonParam = new ButtonParamDetail();
|
||||
buttonParam.setDbFormId(dbformId);
|
||||
buttonParam.setDataId(dataId);
|
||||
buttonParam.setParams(params);
|
||||
|
||||
//执行者绑定参数
|
||||
IButtonCommandReceiver receiver = new ButtonReceiverDetail(buttonParam);
|
||||
|
||||
//执行者和命令绑定
|
||||
DetailsButtonCommand command = new DetailsButtonCommand(receiver);
|
||||
|
||||
//创建调用者
|
||||
ButtonInvoker<ResultDataModel> invoker = new ButtonInvoker();
|
||||
invoker.setButtonCommand(command);//调用者设置命令
|
||||
ResultDataModel resultDataModel = invoker.executeCommand();//调用者下发命令
|
||||
return resultDataModel;
|
||||
}
|
||||
|
||||
//新增数据
|
||||
protected String addJsonData(Long dbformId, JSONObject jsonObject){
|
||||
ButtonParamAdd buttonParam = new ButtonParamAdd();
|
||||
buttonParam.setDbFormId(dbformId);
|
||||
buttonParam.setParams(jsonObject);
|
||||
IButtonCommandReceiver receiver = new ButtonReceiverAdd(buttonParam);
|
||||
|
||||
//执行者和命令绑定
|
||||
AddButtonCommand command = new AddButtonCommand(receiver);
|
||||
|
||||
//创建调用者
|
||||
ButtonInvoker<ExecuteEnhanceModel> invoker = new ButtonInvoker();
|
||||
invoker.setButtonCommand(command);//调用者设置命令
|
||||
ExecuteEnhanceModel saveDataModel = invoker.executeCommand();//调用者下发命令
|
||||
|
||||
return saveDataModel.getId();
|
||||
}
|
||||
protected List<String> addJsonData(Long dbformId, List<JSONObject> jsonObjectList){
|
||||
ButtonParamAddBatch buttonParam = new ButtonParamAddBatch();
|
||||
buttonParam.setDbFormId(dbformId);
|
||||
buttonParam.setDataMapList(jsonObjectList);
|
||||
|
||||
IButtonCommandReceiver receiver = new ButtonReceiverAddBatch(buttonParam);
|
||||
|
||||
//执行者和命令绑定
|
||||
IButtonCommand command = new AddBatchButtonCommand(receiver);
|
||||
|
||||
//创建调用者
|
||||
ButtonInvoker<List<String>> invoker = new ButtonInvoker();
|
||||
invoker.setButtonCommand(command);//调用者设置命令
|
||||
List<String> idList = invoker.executeCommand();//调用者下发命令
|
||||
return idList;
|
||||
}
|
||||
|
||||
//编辑数据
|
||||
protected void editJsonData(Long dbformId, JSONObject jsonObject){
|
||||
Long id = jsonObject.getLong("id");
|
||||
|
||||
//封装参数
|
||||
ButtonParamEdit buttonParam = new ButtonParamEdit();
|
||||
buttonParam.setDbFormId(dbformId);
|
||||
buttonParam.setDataId(id);
|
||||
buttonParam.setParams(jsonObject);
|
||||
|
||||
//执行者绑定参数
|
||||
IButtonCommandReceiver receiver = new ButtonReceiverEdit(buttonParam);
|
||||
|
||||
//执行者和命令绑定
|
||||
EditButtonCommand command = new EditButtonCommand(receiver);
|
||||
|
||||
//创建调用者
|
||||
ButtonInvoker<ExecuteEnhanceModel> invoker = new ButtonInvoker();
|
||||
invoker.setButtonCommand(command);//调用者设置命令
|
||||
invoker.executeCommand();//调用者下发命令
|
||||
}
|
||||
|
||||
protected void editJsonData(Long dbformId, List<JSONObject> jsonObjectList){
|
||||
//封装参数
|
||||
ButtonParamEditBatch buttonParam = new ButtonParamEditBatch();
|
||||
buttonParam.setDbFormId(dbformId);
|
||||
buttonParam.setJsonObjectList(jsonObjectList);
|
||||
|
||||
//执行者绑定参数
|
||||
IButtonCommandReceiver receiver = new ButtonReceiverEditBatch(buttonParam);
|
||||
|
||||
//执行者和命令绑定
|
||||
EditBatchButtonCommand command = new EditBatchButtonCommand(receiver);
|
||||
|
||||
//创建调用者
|
||||
ButtonInvoker<ExecuteEnhanceModel> invoker = new ButtonInvoker();
|
||||
invoker.setButtonCommand(command);//调用者设置命令
|
||||
invoker.executeCommand();//调用者下发命令
|
||||
|
||||
}
|
||||
|
||||
//删除数据
|
||||
protected void deleteDataById(Long dbformId, List<Long> dataIdList){
|
||||
|
||||
//封装参数
|
||||
ButtonParamDel delButtonParam = new ButtonParamDel();
|
||||
delButtonParam.setDbFormId(dbformId);
|
||||
delButtonParam.setDataIdList(dataIdList);
|
||||
|
||||
//执行者绑定参数
|
||||
IButtonCommandReceiver receiver = new ButtonReceiverDel(delButtonParam);
|
||||
|
||||
//执行者和命令绑定
|
||||
DelButtonCommand command = new DelButtonCommand(receiver);
|
||||
|
||||
//创建调用者
|
||||
ButtonInvoker<ExecuteEnhanceModel> invoker = new ButtonInvoker();
|
||||
invoker.setButtonCommand(command);//调用者设置命令
|
||||
invoker.executeCommand();//调用者下发命令
|
||||
|
||||
}
|
||||
|
||||
//导出模板
|
||||
protected ExcelTemplateModel exportExcelTemplate(Long dbformId){
|
||||
//封装参数
|
||||
ButtonParamExportTemplate buttonParam = new ButtonParamExportTemplate();
|
||||
buttonParam.setDbFormId(dbformId);
|
||||
//执行者绑定参数
|
||||
IButtonCommandReceiver receiver = new ButtonReceiverExportTemplate(buttonParam);
|
||||
|
||||
//执行者和命令绑定
|
||||
ExportTemplateButtonCommand command = new ExportTemplateButtonCommand(receiver);
|
||||
|
||||
//创建调用者
|
||||
ButtonInvoker<ExcelTemplateModel> invoker = new ButtonInvoker();
|
||||
invoker.setButtonCommand(command);//调用者设置命令
|
||||
ExcelTemplateModel excelTemplateModel = invoker.executeCommand();//调用者下发命令
|
||||
return excelTemplateModel;
|
||||
}
|
||||
//导出Excel数据
|
||||
protected ExcelModel exportExcelData(Long dbformId, Map<String, Object> params ){
|
||||
|
||||
//封装参数
|
||||
ButtonParamExport buttonParam = new ButtonParamExport();
|
||||
buttonParam.setDbFormId(dbformId);
|
||||
buttonParam.setParams(params);
|
||||
|
||||
|
||||
//执行者绑定参数
|
||||
IButtonCommandReceiver receiver = new ButtonReceiverExport(buttonParam);
|
||||
|
||||
//执行者和命令绑定
|
||||
ExportButtonCommand command = new ExportButtonCommand(receiver);
|
||||
|
||||
//创建调用者
|
||||
ButtonInvoker<ExcelModel> invoker = new ButtonInvoker();
|
||||
invoker.setButtonCommand(command);//调用者设置命令
|
||||
ExcelModel excelModel = invoker.executeCommand();//调用者下发命令
|
||||
return excelModel;
|
||||
}
|
||||
|
||||
//导入Excel数据
|
||||
protected ExcelImportResultModel importExcelData(ButtonParamImport buttonParam){
|
||||
//执行者绑定参数
|
||||
IButtonCommandReceiver receiver = new ButtonReceiverImport(buttonParam);
|
||||
|
||||
//执行者和命令绑定
|
||||
ImportButtonCommand command = new ImportButtonCommand(receiver);
|
||||
|
||||
//创建调用者
|
||||
ButtonInvoker<ExcelImportResultModel> invoker = new ButtonInvoker();
|
||||
invoker.setButtonCommand(command);//调用者设置命令
|
||||
ExcelImportResultModel resultModel = invoker.executeCommand();//调用者下发命令
|
||||
return resultModel;//批次号
|
||||
}
|
||||
|
||||
//----------- 数据统计 -------------------
|
||||
|
||||
//获取分页数据列表
|
||||
protected ResultDataModel getReportDataList(String reportCode, Map<String, Object> params){
|
||||
Page page = FuncWeb.getPage(params);
|
||||
|
||||
//封装参数
|
||||
ButtonParamReportList buttonParam = new ButtonParamReportList();
|
||||
buttonParam.setReportCode(reportCode);
|
||||
buttonParam.setParams(params);
|
||||
buttonParam.setPage(page);
|
||||
//执行者绑定参数
|
||||
ButtonReceiverReportList receiver = new ButtonReceiverReportList(buttonParam);
|
||||
|
||||
//执行者和命令绑定
|
||||
ListButtonCommand command = new ListButtonCommand(receiver);
|
||||
|
||||
//创建调用者
|
||||
ButtonInvoker<ResultDataModel> invoker = new ButtonInvoker();
|
||||
invoker.setButtonCommand(command);//调用者设置命令
|
||||
ResultDataModel resultDataModel = invoker.executeCommand();//调用者下发命令
|
||||
|
||||
return resultDataModel;
|
||||
}
|
||||
|
||||
|
||||
protected void formatFormEntityPageVo(List<FormEntityPageVo> records, IFormService dbFormService){
|
||||
ForkJoinPool pool = null;
|
||||
try {
|
||||
pool = FuncBase.jeelowcodeForkJoinPool();
|
||||
pool.submit(() -> records.parallelStream().forEach(vo ->{
|
||||
Map<String, Object> couMap = dbFormService.getFormCou(vo.getId());
|
||||
Integer js_cou = Func.getMap2IntDefault(couMap, "js_cou",0);
|
||||
Integer scss_cou = Func.getMap2IntDefault(couMap, "scss_cou",0);
|
||||
Integer button_cou = Func.getMap2IntDefault(couMap, "button_cou",0);
|
||||
Integer java_cou = Func.getMap2IntDefault(couMap, "java_cou",0);
|
||||
Integer sql_cou = Func.getMap2IntDefault(couMap, "sql_cou",0);
|
||||
Integer field_cou = Func.getMap2IntDefault(couMap, "field_cou",0);
|
||||
|
||||
vo.setJsCou(js_cou);
|
||||
vo.setScssCou(scss_cou);
|
||||
vo.setButtonCou(button_cou);
|
||||
vo.setJavaCou(java_cou);
|
||||
vo.setSqlCou(sql_cou);
|
||||
vo.setFieldCou(field_cou);
|
||||
})).get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
} finally {
|
||||
if (pool != null) {
|
||||
pool.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//导出Excel数据
|
||||
protected ExcelModel exportReportData(String reportCode, Map<String, Object> params ){
|
||||
|
||||
//封装参数
|
||||
ButtonParamReportExport buttonParam = new ButtonParamReportExport();
|
||||
buttonParam.setReportCode(reportCode);
|
||||
buttonParam.setParams(params);
|
||||
|
||||
//执行者绑定参数
|
||||
IButtonCommandReceiver receiver = new ButtonReceiverReportExport(buttonParam);
|
||||
|
||||
//执行者和命令绑定
|
||||
ExportButtonCommand command = new ExportButtonCommand(receiver);
|
||||
|
||||
//创建调用者
|
||||
ButtonInvoker<ExcelModel> invoker = new ButtonInvoker();
|
||||
invoker.setButtonCommand(command);//调用者设置命令
|
||||
ExcelModel excelModel = invoker.executeCommand();//调用者下发命令
|
||||
return excelModel;
|
||||
}
|
||||
|
||||
protected Map<String,Object> formatExplainSqlField(List<Map<String, Object>> records){
|
||||
Map<String, Object> resultMap =new HashMap<>();
|
||||
if(Func.isEmpty(records)){
|
||||
return resultMap;
|
||||
}
|
||||
Set<String> keys=new HashSet<>();
|
||||
|
||||
List<FormFieldEntity> fieldList = new ArrayList<>();
|
||||
List<FormFieldDictEntity> dictList = new ArrayList<>();
|
||||
List<FormFieldQueryEntity> queryList = new ArrayList<>();
|
||||
List<FormFieldWebEntity> webList = new ArrayList<>();
|
||||
|
||||
|
||||
for(Map<String, Object> dataMap:records){
|
||||
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
if(keys.contains(key)){
|
||||
continue;
|
||||
}
|
||||
keys.add(key);
|
||||
//根据value来封装类型
|
||||
String finaiFieldCode=key;
|
||||
|
||||
JeeLowCodeFieldTypeEnum jeeLowCodeFieldTypeEnum= JeeLowCodeFieldTypeEnum.STRING;
|
||||
//其他类型特殊处理
|
||||
if(value instanceof Long){
|
||||
jeeLowCodeFieldTypeEnum=JeeLowCodeFieldTypeEnum.BIGINT;
|
||||
}else if(value instanceof Integer){
|
||||
jeeLowCodeFieldTypeEnum=JeeLowCodeFieldTypeEnum.INTEGER;
|
||||
}else if((value instanceof Date) || (value instanceof java.util.Date)){
|
||||
jeeLowCodeFieldTypeEnum=JeeLowCodeFieldTypeEnum.DATETIME;
|
||||
}else if(value instanceof BigDecimal){
|
||||
jeeLowCodeFieldTypeEnum=JeeLowCodeFieldTypeEnum.BIGDECIMAL;
|
||||
}
|
||||
|
||||
//构建基础的
|
||||
FormFieldEntity fieldEntity = new FormFieldEntity();
|
||||
fieldEntity.setFieldCode(finaiFieldCode);
|
||||
fieldEntity.setFieldType(jeeLowCodeFieldTypeEnum.getFieldType());
|
||||
fieldList.add(fieldEntity);
|
||||
|
||||
FormFieldDictEntity fieldDictEntity = new FormFieldDictEntity();
|
||||
fieldDictEntity.setFieldCode(finaiFieldCode);
|
||||
dictList.add(fieldDictEntity);
|
||||
|
||||
FormFieldQueryEntity formFieldQueryEntity = new FormFieldQueryEntity();
|
||||
formFieldQueryEntity.setFieldCode(finaiFieldCode);
|
||||
queryList.add(formFieldQueryEntity);
|
||||
|
||||
FormFieldWebEntity formFieldWebEntity = new FormFieldWebEntity();
|
||||
formFieldWebEntity.setFieldCode(finaiFieldCode);
|
||||
webList.add(formFieldWebEntity);
|
||||
}
|
||||
}
|
||||
resultMap.put("fieldList", fieldList);
|
||||
resultMap.put("dictList", dictList);
|
||||
resultMap.put("queryList", queryList);
|
||||
resultMap.put("webList", webList);
|
||||
return resultMap;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.jeelowcode.core.framework.controller;
|
||||
|
||||
import com.jeelowcode.framework.constants.FrameErrorCodeConstants;
|
||||
import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
|
||||
import com.jeelowcode.core.framework.entity.FormButtonEntity;
|
||||
import com.jeelowcode.core.framework.service.IFormButtonService;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.core.framework.params.vo.PageVo;
|
||||
import com.jeelowcode.framework.utils.model.global.BaseWebResult;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Tag(name = "低代码框架-Button增强接口")
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(JeeLowCodeBaseConstant.REQUEST_URL_START+"/enhance/button")
|
||||
public class ButtonController extends BaseController {
|
||||
|
||||
private final IFormButtonService buttonService;
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:button')")
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(tags = "Button增强",summary = "Js增强-详情")
|
||||
public BaseWebResult<FormButtonEntity> jsDetail(@RequestParam Long id){
|
||||
return BaseWebResult.success(buttonService.getById(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:button')")
|
||||
@PostMapping("/save")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(tags = "Button增强",summary = "新增")
|
||||
public BaseWebResult save(@RequestBody FormButtonEntity model) {
|
||||
//编号唯一
|
||||
String buttonCode = model.getButtonCode();
|
||||
LambdaQueryWrapper<FormButtonEntity> wrapper=new LambdaQueryWrapper<>();
|
||||
wrapper.eq(FormButtonEntity::getDbformId,model.getDbformId());
|
||||
wrapper.eq(FormButtonEntity::getButtonCode,buttonCode);
|
||||
long count = buttonService.count(wrapper);
|
||||
if(count>0){
|
||||
return BaseWebResult.error(FrameErrorCodeConstants.FRAME_CORE_EXIT);
|
||||
}
|
||||
|
||||
|
||||
buttonService.save(model);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:button')")
|
||||
@PutMapping("/update")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "Button增强",summary = "修改")
|
||||
public BaseWebResult update(@RequestBody FormButtonEntity model) {
|
||||
//编号唯一
|
||||
String buttonCode = model.getButtonCode();
|
||||
LambdaQueryWrapper<FormButtonEntity> wrapper=new LambdaQueryWrapper<>();
|
||||
wrapper.eq(FormButtonEntity::getDbformId,model.getDbformId());
|
||||
wrapper.eq(FormButtonEntity::getButtonCode,buttonCode);
|
||||
wrapper.ne(FormButtonEntity::getId,model.getId());
|
||||
long count = buttonService.count(wrapper);
|
||||
if(count>0){
|
||||
return BaseWebResult.error(FrameErrorCodeConstants.FRAME_CORE_EXIT);
|
||||
}
|
||||
|
||||
buttonService.updateById(model);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:button')")
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "Button增强",summary = "删除(逻辑删除)")
|
||||
public BaseWebResult del(@RequestBody List<Long> ids) {
|
||||
buttonService.removeByIds(ids);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:button')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "Button增强",summary = "获取列表")
|
||||
public BaseWebResult list(FormButtonEntity entity) {
|
||||
LambdaQueryWrapper<FormButtonEntity> wrapper=new LambdaQueryWrapper<>();
|
||||
wrapper.setEntity(entity);
|
||||
wrapper.orderByDesc(FormButtonEntity::getId);
|
||||
List<FormButtonEntity> dataList = buttonService.list(wrapper);
|
||||
return BaseWebResult.success(dataList);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:button')")
|
||||
@GetMapping("/page")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "Button增强",summary = "获取列表(分页)")
|
||||
public BaseWebResult page(FormButtonEntity entity, PageVo pageVo) {
|
||||
Page page = FuncWeb.getPage(pageVo.getPageNo(), pageVo.getPageSize());
|
||||
|
||||
LambdaQueryWrapper<FormButtonEntity> wrapper=new LambdaQueryWrapper<>();
|
||||
wrapper.setEntity(entity);
|
||||
wrapper.orderByDesc(FormButtonEntity::getId);
|
||||
IPage<FormButtonEntity> pages = buttonService.page(page, wrapper);
|
||||
return BaseWebResult.success(pages);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,483 @@
|
||||
|
||||
package com.jeelowcode.core.framework.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.jeelowcode.core.framework.entity.*;
|
||||
import com.jeelowcode.core.framework.params.model.ExplainFieldParam;
|
||||
import com.jeelowcode.framework.ai.platform.chat.ChatBaseRequest;
|
||||
import com.jeelowcode.framework.ai.platform.chat.ChatBaseResponse;
|
||||
import com.jeelowcode.framework.ai.platform.chat.tool.ChatMessage;
|
||||
import com.jeelowcode.framework.ai.platform.chat.tool.Choice;
|
||||
import com.jeelowcode.framework.ai.service.IChatService;
|
||||
import com.jeelowcode.framework.ai.service.PlatformType;
|
||||
import com.jeelowcode.framework.ai.service.factor.AiService;
|
||||
import com.jeelowcode.framework.ai.template.CreateTableTemplate;
|
||||
import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
|
||||
import com.jeelowcode.framework.utils.enums.YNEnum;
|
||||
import com.jeelowcode.framework.utils.model.global.BaseWebResult;
|
||||
import com.jeelowcode.core.framework.config.validate.DbFormCopyValidate;
|
||||
import com.jeelowcode.core.framework.config.validate.TableNameValidate;
|
||||
import com.jeelowcode.core.framework.params.DbFormAddOrUpdateParam;
|
||||
import com.jeelowcode.core.framework.params.DictLabelParam;
|
||||
import com.jeelowcode.core.framework.params.PageDbFormParam;
|
||||
import com.jeelowcode.core.framework.params.TreeParentParam;
|
||||
import com.jeelowcode.core.framework.params.model.AllTableModel;
|
||||
import com.jeelowcode.core.framework.params.model.ExplainDatasourceSqlModel;
|
||||
import com.jeelowcode.core.framework.params.model.ExplainSqlFieldModel;
|
||||
import com.jeelowcode.core.framework.params.vo.*;
|
||||
import com.jeelowcode.core.framework.params.vo.role.DbFormRoleButtonVo;
|
||||
import com.jeelowcode.core.framework.params.vo.role.DbFormRoleFieldVo;
|
||||
import com.jeelowcode.core.framework.params.vo.webconfig.WebConfigRoleFieldVo;
|
||||
import com.jeelowcode.core.framework.params.vo.webconfig.WebConfigVo;
|
||||
import com.jeelowcode.core.framework.service.IDbFormRoleService;
|
||||
import com.jeelowcode.core.framework.service.IFormService;
|
||||
import com.jeelowcode.core.framework.service.IFrameService;
|
||||
import com.jeelowcode.core.framework.service.IFrameSqlService;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.framework.constants.FrameErrorCodeConstants;
|
||||
import com.jeelowcode.framework.exception.JeeLowCodeMoreException;
|
||||
import com.jeelowcode.framework.plus.SqlHelper;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.wrapper.SqlInfoQueryWrapper;
|
||||
import com.jeelowcode.framework.tenant.annotation.JeeLowCodeTenantIgnore;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
|
||||
import com.jeelowcode.framework.utils.annotation.JeelowCodeValidate;
|
||||
import com.jeelowcode.framework.utils.enums.DbFormTypeEnum;
|
||||
import com.jeelowcode.framework.utils.enums.ParamEnum;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import com.jeelowcode.framework.utils.utils.JeeLowCodeUtils;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Tag(name = "低代码框架-框架接口")
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(JeeLowCodeBaseConstant.REQUEST_URL_START + "/dbform")
|
||||
public class DbFormController extends BaseController {
|
||||
|
||||
private final IFrameService frameService;
|
||||
|
||||
private final IFormService dbFormService;
|
||||
|
||||
private final IJeeLowCodeAdapter jeeLowCodeAdapter;
|
||||
|
||||
private final IFrameSqlService sqlService;
|
||||
|
||||
private final IDbFormRoleService dbFormRoleService;
|
||||
|
||||
private final AiService aiService;
|
||||
|
||||
@JeelowCodeValidate(title = "自定义校验-表名是否正确", validateClass = TableNameValidate.class)
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:create')")
|
||||
@PostMapping("/save")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(tags = "表单开发",summary = "表单开发 - 保存")
|
||||
public BaseWebResult saveDbFormConfig(@RequestBody DbFormAddOrUpdateParam param, HttpServletRequest req) {
|
||||
//基本信息校验完成
|
||||
dbFormService.saveDbFormConfig(param);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:update')")
|
||||
@PutMapping("/update")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(tags = "表单开发",summary = "表单开发 - 修改")
|
||||
public BaseWebResult updateDbFormConfig(@RequestBody DbFormAddOrUpdateParam param) {
|
||||
dbFormService.updateDbFormConfig(param);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:delete')")
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "表单开发",summary = "表单开发 - 删除")
|
||||
public BaseWebResult deleteDbFormConfig(@RequestBody List<Long> dbFormIdList) {
|
||||
dbFormService.deleteDbFormConfig(dbFormIdList, true);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
// @PreAuthorize("@ss.hasPermission('jeelowcode:dbform:query')")
|
||||
@PostMapping("/detail")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(tags = "表单开发",summary = "表单开发 - 获取详情")
|
||||
public BaseWebResult getDetailDbFormConfig(Long dbFormId, @RequestBody List<String> typeList) {
|
||||
List<DbFormTypeEnum> enumList = typeList.stream()
|
||||
.map(type -> DbFormTypeEnum.getByType(type))
|
||||
.collect(Collectors.toList());
|
||||
DbFormConfigVo vo = dbFormService.getDetailDbFormConfig(dbFormId, enumList);
|
||||
return BaseWebResult.success(vo);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:query')")
|
||||
@PostMapping("/page")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@Operation(tags = "表单开发",summary = "表单开发 - 获取分页数据")
|
||||
public BaseWebResult getPageDbFormConfig(@RequestBody PageDbFormParam param, PageVo pageVo) {
|
||||
Page page = FuncWeb.getPage(pageVo.getPageNo(), pageVo.getPageSize());
|
||||
IPage<FormEntity> pages = dbFormService.getPageDbFormConfig(param, page);
|
||||
IPage<FormEntityPageVo> vopages = toVoBean(pages, FormEntityPageVo.class);
|
||||
List<FormEntityPageVo> records = vopages.getRecords();
|
||||
super.formatFormEntityPageVo(records,dbFormService);
|
||||
return BaseWebResult.success(vopages);
|
||||
}
|
||||
|
||||
|
||||
@JeelowCodeValidate(title = "判断表名是否合法", validateClass = DbFormCopyValidate.class)
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:create')")
|
||||
@GetMapping({"/copy/{dbformId}"})
|
||||
@ApiOperationSupport(order = 6)
|
||||
@Operation(tags = "表单开发",summary = "复制表")
|
||||
public BaseWebResult copy(@PathVariable("dbformId") Long dbformId, String tableName) {
|
||||
dbFormService.copyDbFormConfig(dbformId, tableName);
|
||||
return BaseWebResult.success("复制成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:sync')")
|
||||
@JeeLowCodeTenantIgnore
|
||||
@PostMapping({"/sync-db/{dbformId}"})
|
||||
@ApiOperationSupport(order = 7)
|
||||
@Operation(tags = "表单开发",summary = "同步数据库")
|
||||
public BaseWebResult syncDb(@PathVariable("dbformId") Long dbformId, String syncModel) {
|
||||
try {
|
||||
frameService.syncDb(dbformId, syncModel);
|
||||
} catch (Exception e) {
|
||||
throw new JeeLowCodeMoreException("同步失败", e.getMessage());
|
||||
}
|
||||
return BaseWebResult.success("同步完成");
|
||||
}
|
||||
|
||||
@GetMapping("/check/table")
|
||||
@JeeLowCodeTenantIgnore
|
||||
@ApiOperationSupport(order = 8)
|
||||
@Operation(tags = "表单开发",summary = "校验表明是否存在")
|
||||
public BaseWebResult checkTable(String tableName) {
|
||||
boolean flag = frameService.checkTable(tableName);
|
||||
return BaseWebResult.success(flag);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/get/web-config")
|
||||
@ApiOperationSupport(order = 9)
|
||||
@Operation(tags = "表单开发",summary = "获取页面信息配置")
|
||||
public BaseWebResult getWebConfig(@RequestParam("dbformId")Long dbformId) {
|
||||
WebConfigVo webConfig = dbFormService.getWebConfig(dbformId);
|
||||
//判断是否有租户字段权限
|
||||
Long tenantId = jeeLowCodeAdapter.getTenantId();
|
||||
if(Func.isNotEmpty(tenantId) && Func.notEquals(tenantId,"-1")){
|
||||
//字段权限->部分租户只能看到部分字段
|
||||
List<DbFormRoleFieldVo> roleFieldVoList = dbFormRoleService.listRoleField(tenantId, dbformId,false);
|
||||
if(Func.isNotEmpty(roleFieldVoList)){
|
||||
List<WebConfigRoleFieldVo> webConfigRoleFieldVoList = BeanUtil.copyToList(roleFieldVoList, WebConfigRoleFieldVo.class);
|
||||
webConfig.setWebConfigRoleFieldVoList(webConfigRoleFieldVoList);
|
||||
}
|
||||
//按钮权限->部分租户只能看到部分按钮
|
||||
List<DbFormRoleButtonVo> roleButtonVoList = dbFormRoleService.listRoleButton(tenantId, dbformId, false);
|
||||
if(Func.isNotEmpty(roleButtonVoList)){
|
||||
List<String> webConfigRoleButtonVoList = roleButtonVoList.stream()
|
||||
.map(DbFormRoleButtonVo::getButtonCode) // 提取 buttonCode
|
||||
.collect(Collectors.toList()); // 收集到新的列表中
|
||||
webConfig.setWebConfigRoleButtonVoList(webConfigRoleButtonVoList);
|
||||
}
|
||||
|
||||
}
|
||||
return BaseWebResult.success(webConfig);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("/get/dict-table-web-config/{dbformId}")
|
||||
@ApiOperationSupport(order = 10)
|
||||
@Operation(tags = "表单开发",summary = "获取字典表页面信息配置")
|
||||
public BaseWebResult getDictTableWebConfig(@PathVariable("dbformId") Long dbformId, HttpServletRequest req) {
|
||||
Map<String, Object> bodyParams = FuncWeb.getParameterBodyMap(req);
|
||||
|
||||
List<String> fieldList = JeeLowCodeUtils.getMap2List(bodyParams, ParamEnum.DICT_TABLE_FIELD.getCode());//自定义列 id,name,age,sex
|
||||
if (FuncBase.isEmpty(fieldList)) {//查字典数据
|
||||
return BaseWebResult.error(FrameErrorCodeConstants.FRAME_PARAM_NULL_ERROR);
|
||||
}
|
||||
//获取指定列配置
|
||||
WebConfigVo webConfig = dbFormService.getWebConfig(dbformId, fieldList);
|
||||
webConfig.setButtonList(null);
|
||||
|
||||
return BaseWebResult.success(webConfig);
|
||||
}
|
||||
|
||||
@PostMapping("/get/table-label")
|
||||
@ApiOperationSupport(order = 11)
|
||||
@Operation(tags = "表单开发",summary = "表字段回显")
|
||||
public BaseWebResult getTableLabel(HttpServletRequest req) {
|
||||
Map<String, Object> bodyParams = FuncWeb.getParameterBodyMap(req);
|
||||
List<DictLabelParam> labelParamList = (List<DictLabelParam>) bodyParams.get(ParamEnum.DICT_LABEL.getCode());
|
||||
|
||||
if (FuncBase.isEmpty(labelParamList)) {
|
||||
return BaseWebResult.error(FrameErrorCodeConstants.FRAME_PARAM_NULL_ERROR);
|
||||
}
|
||||
|
||||
for(DictLabelParam dictLabelParam:labelParamList){
|
||||
Long dbformId = dictLabelParam.getDbformId();
|
||||
String label = dictLabelParam.getLabel();
|
||||
List<String> fieldList = dictLabelParam.getFieldList();
|
||||
if(FuncBase.isNotEmpty(fieldList)){
|
||||
int ind = fieldList.indexOf(label);
|
||||
|
||||
FormFieldWebEntity formFieldWebEntity = dbFormService.getFieldWebEntity(dbformId, label);
|
||||
if(FuncBase.isNotEmpty(formFieldWebEntity)){
|
||||
String controlType = formFieldWebEntity.getControlType();
|
||||
switch (controlType){
|
||||
case "userSelect":
|
||||
String userFormatSql="(select username from system_users where id ="+label+") as "+label;
|
||||
fieldList.set(ind,userFormatSql);//子查询
|
||||
break;
|
||||
case "deptSelect":
|
||||
String deptormatSql="(select name from system_dept where id ="+label+") as "+label;
|
||||
fieldList.set(ind,deptormatSql);//子查询
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Map<String, List<Map<String, Object>>> resultMap = new ConcurrentHashMap<>();
|
||||
|
||||
ForkJoinPool pool = null;
|
||||
try {
|
||||
pool = FuncBase.jeelowcodeForkJoinPool();
|
||||
pool.submit(() -> labelParamList.parallelStream().forEach(labelParam ->{
|
||||
Long dbformId = labelParam.getDbformId();
|
||||
List<String> fieldList = labelParam.getFieldList();
|
||||
String code = labelParam.getCode();
|
||||
String label = labelParam.getLabel();
|
||||
List<String> dataList = labelParam.getDataList();
|
||||
List<Long> userIdList = labelParam.getUserIdList();//用户id
|
||||
List<Long> deptIdList = labelParam.getDeptIdList();//部门id
|
||||
|
||||
if (Func.isNotEmpty(dbformId)) { //自定义表
|
||||
String mapKey = dbformId + "&" + label;
|
||||
if (FuncBase.isEmpty(dataList)) {
|
||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||
resultMap.put(FuncBase.toStr(dbformId), resultList);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Map<String, Object>> resultList =new ArrayList<>();
|
||||
for(String dataId:dataList){
|
||||
Map<String, Object> params =new HashMap<>();
|
||||
params.put(ParamEnum.DICT_TABLE_FIELD.getCode(),fieldList);
|
||||
params.put(code,dataId);//id=1
|
||||
params.put(ParamEnum.PAGE_NO.getCode(),1);
|
||||
params.put(ParamEnum.PAGE_SIZE.getCode(),1000);
|
||||
params.put(ParamEnum.ALL_QUERY_FIELD.getCode(),"Y");
|
||||
ResultDataModel model = frameService.getDataList(dbformId, params);
|
||||
List<Map<String, Object>> tmpList = model.getRecords();
|
||||
if(Func.isEmpty(tmpList)){
|
||||
continue;
|
||||
}
|
||||
resultList.addAll(tmpList);
|
||||
}
|
||||
|
||||
resultMap.put(mapKey, resultList);
|
||||
}
|
||||
if (Func.isNotEmpty(userIdList)) {//用户表回显
|
||||
List<Map<String, Object>> userViewList = jeeLowCodeAdapter.getUserViewList(userIdList);
|
||||
resultMap.put("userList", userViewList);
|
||||
}
|
||||
if (Func.isNotEmpty(deptIdList)) {//部门表回显
|
||||
List<Map<String, Object>> deptViewList = jeeLowCodeAdapter.getDeptViewList(deptIdList);
|
||||
resultMap.put("deptList", deptViewList);
|
||||
}
|
||||
})).get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
} finally {
|
||||
if (pool != null) {
|
||||
pool.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
return BaseWebResult.success(resultMap);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/get/all-table")
|
||||
@ApiOperationSupport(order = 13)
|
||||
@Operation(tags = "表单开发",summary = "获取所有表名")
|
||||
public BaseWebResult getAllTable(String systemFlag,String onlyTableName,String dataSourcesCode) {
|
||||
if(Func.isNotEmpty(dataSourcesCode)){
|
||||
List<AllTableModel> list = dbFormService.getDataSourceTable(dataSourcesCode);
|
||||
return BaseWebResult.success(list);
|
||||
}
|
||||
List<AllTableModel> list = dbFormService.getAllTable(systemFlag,onlyTableName);
|
||||
|
||||
//只查表名
|
||||
boolean onlyTableNameFlag = Func.isNotEmpty(onlyTableName) && Func.equals(onlyTableName, YNEnum.Y.getCode());
|
||||
if (onlyTableNameFlag && list != null && !list.isEmpty()) {
|
||||
list.forEach(tableModel -> tableModel.setFieldModelList(null));
|
||||
}
|
||||
return BaseWebResult.success(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/clear-cache")
|
||||
@ApiOperationSupport(order = 14)
|
||||
@Operation(tags = "表单开发",summary = "清除缓存")
|
||||
public BaseWebResult clearCache() {
|
||||
dbFormService.cleanCache();
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PostMapping("/get/tree-parent")
|
||||
@ApiOperationSupport(order = 10)
|
||||
@Operation(tags = "表单开发",summary = "获取字典表页面信息配置")
|
||||
public BaseWebResult getTreeParentList( HttpServletRequest req) {
|
||||
Map<String, Object> bodyParams = FuncWeb.getParameterBodyMap(req);
|
||||
if(!bodyParams.containsKey(ParamEnum.TREE_PARENT.getCode())){
|
||||
return BaseWebResult.error(FrameErrorCodeConstants.FRAME_PARAM_NULL_ERROR);
|
||||
}
|
||||
|
||||
|
||||
List<TreeParentParam> paramList = (List<TreeParentParam>) bodyParams.get(ParamEnum.TREE_PARENT.getCode());
|
||||
|
||||
Map<String,List<Map<String, Object>>> resultMap=new HashMap<>();
|
||||
paramList.stream().forEach(param ->{
|
||||
Long dbformId = param.getDbformId();
|
||||
List<Map<String, Object>> resultDataMapList = dbFormService.getTreeParentList(dbformId, param);
|
||||
resultMap.put(dbformId.toString(),resultDataMapList);
|
||||
});
|
||||
return BaseWebResult.success(resultMap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:create')")
|
||||
@PostMapping("/explain/datasource-sql")
|
||||
@ApiOperationSupport(order = 11)
|
||||
@Operation(tags = "表单开发",summary = "解释数据源SQL的运行结果")
|
||||
public BaseWebResult explainDatasourceSql(@RequestBody ExplainDatasourceSqlModel model) {
|
||||
Page page = FuncWeb.getPage(1, 10);
|
||||
Map<String, Object> params=new HashMap<>();
|
||||
SqlInfoQueryWrapper.Wrapper queryWrapper = SqlHelper.getQueryWrapper();
|
||||
//处理占位符参数
|
||||
model.setExplainSql(Func.replaceParam(model.getExplainSql(), params, null, jeeLowCodeAdapter));
|
||||
queryWrapper.setTableSql(model.getExplainSql());//sql
|
||||
if(Func.isNotEmpty(model.getDataSourcesCode())){
|
||||
queryWrapper.setDataSourceType(model.getDataSourcesCode());
|
||||
queryWrapper.setTenantIgnore(true);//外部数据源 直接忽略多租户
|
||||
}
|
||||
|
||||
try{
|
||||
IPage<Map<String, Object>> pages = sqlService.getDataIPageByPlus(page, queryWrapper,params);
|
||||
return BaseWebResult.success(pages);
|
||||
}catch (Exception e){
|
||||
throw new JeeLowCodeMoreException("SQL执行错误",e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:create')")
|
||||
@PostMapping("/explain/sqlfield")
|
||||
@ApiOperationSupport(order = 11)
|
||||
@Operation(tags = "表单开发",summary = "解释数据源SQL字段类型")
|
||||
public BaseWebResult explainSqlField(@RequestBody ExplainFieldParam param) {
|
||||
Map<String, Object> resultMap =new HashMap<>();
|
||||
List<ExplainSqlFieldModel> modelList = param.getModelList();
|
||||
if(Func.isNotEmpty(modelList)){//拖拉形式
|
||||
resultMap = dbFormService.explainSqlField(modelList);
|
||||
return BaseWebResult.success(resultMap);
|
||||
}
|
||||
//自定义sql,从运行结果来解析,保证能运行出结果
|
||||
Page page = FuncWeb.getPage(1, 10);
|
||||
Map<String, Object> params=new HashMap<>();
|
||||
SqlInfoQueryWrapper.Wrapper queryWrapper = SqlHelper.getQueryWrapper();
|
||||
//处理占位符参数
|
||||
param.setExplainSql(Func.replaceParam(param.getExplainSql(), params, null, jeeLowCodeAdapter));
|
||||
queryWrapper.setTableSql(param.getExplainSql());//sql
|
||||
if(Func.isNotEmpty(param.getDataSourcesCode())){
|
||||
queryWrapper.setDataSourceType(param.getDataSourcesCode());
|
||||
queryWrapper.setTenantIgnore(true);//外部数据源 直接忽略多租户
|
||||
}
|
||||
try{
|
||||
IPage<Map<String, Object>> pages = sqlService.getDataIPageByPlus(page, queryWrapper,params);
|
||||
List<Map<String, Object>> records = pages.getRecords();
|
||||
resultMap = super.formatExplainSqlField(records);
|
||||
return BaseWebResult.success(resultMap);
|
||||
}catch (Exception e){
|
||||
}
|
||||
return BaseWebResult.success(resultMap);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:create')")
|
||||
@GetMapping("/get/not-in-dbform-tables")
|
||||
@ApiOperationSupport(order = 11)
|
||||
@Operation(tags = "表单开发",summary = "获取未在表单开发里面的表")
|
||||
public BaseWebResult getNotInDbformTables() {
|
||||
List<NotInDbformTablesVo> voList = dbFormService.getNotInDbformTables();
|
||||
return BaseWebResult.success(voList);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:create')")
|
||||
@GetMapping("/get/tables-field")
|
||||
@ApiOperationSupport(order = 11)
|
||||
@Operation(tags = "表单开发",summary = "获取表字段")
|
||||
public BaseWebResult getTableField(String tableName) {
|
||||
List<TableFieldModelVo> voList = dbFormService.getTableFieldComment(tableName);
|
||||
return BaseWebResult.success(voList);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:create')")
|
||||
@GetMapping("/ai/create-table")
|
||||
@ApiOperationSupport(order = 12)
|
||||
@Operation(tags = "表单开发",summary = "AI自动生成表")
|
||||
public BaseWebResult aiCreateTable(String prompt) {
|
||||
|
||||
IChatService chatService = aiService.getChatService(PlatformType.KIMI);
|
||||
|
||||
//有时候生成失败,重试3次
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try{
|
||||
ChatBaseRequest chatBaseRequest = ChatBaseRequest.builder()
|
||||
.messages(CreateTableTemplate.getMessageTemplateList())
|
||||
.message(ChatMessage.withUser(prompt))
|
||||
.build();
|
||||
ChatBaseResponse chatBaseResponse = chatService.chatCompletion(chatBaseRequest);
|
||||
List<Choice> choices = chatBaseResponse.getChoices();
|
||||
if(FuncBase.isEmpty(choices)){
|
||||
continue;
|
||||
}
|
||||
Choice choice = choices.get(0);
|
||||
ChatMessage message = choice.getMessage();
|
||||
if(FuncBase.isEmpty(message)){
|
||||
continue;
|
||||
}
|
||||
String content = message.getContent();
|
||||
CreateTableTemplate.RspModel rspModel = FuncBase.json2Bean(content, CreateTableTemplate.RspModel.class);
|
||||
return BaseWebResult.success(rspModel);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return BaseWebResult.error(FrameErrorCodeConstants.FRAM_SELF_ERROR.getCode(),"生成失败");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
|
||||
package com.jeelowcode.core.framework.controller;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import com.jeelowcode.framework.utils.model.global.BaseWebResult;
|
||||
import com.jeelowcode.core.framework.params.DataUniqueParam;
|
||||
import com.jeelowcode.core.framework.service.IFormService;
|
||||
import com.jeelowcode.core.framework.service.IFrameSqlService;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.framework.constants.FrameErrorCodeConstants;
|
||||
import com.jeelowcode.framework.plus.SqlHelper;
|
||||
import com.jeelowcode.framework.plus.build.buildmodel.wrapper.SqlInfoQueryWrapper;
|
||||
import com.jeelowcode.framework.utils.enums.JeeLowCodeFieldTypeEnum;
|
||||
import com.jeelowcode.framework.utils.model.ResultDataModel;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Tag(name = "低代码框架-框架接口-数据相关")
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(JeeLowCodeBaseConstant.REQUEST_URL_START + "/dbform-data")
|
||||
public class DbFormDataController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IFormService formService;
|
||||
|
||||
@Autowired
|
||||
private IFrameSqlService sqlService;
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform-data:query:'+#dbformId)")//根据表id来判断是否有权限访问
|
||||
@PostMapping({"/list/{dbformId}"})
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(tags = "表单开发",summary = "获取表数据列表")
|
||||
public BaseWebResult getDataList(@PathVariable("dbformId") Long dbformId, HttpServletRequest req) {//id,name id,age,
|
||||
Map<String, Object> params = FuncWeb.getParameterBodyMap(req);
|
||||
ResultDataModel resultDataModel = super.getDataPage(dbformId, params);
|
||||
return BaseWebResult.success(resultDataModel);
|
||||
}
|
||||
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform-data:query:'+#dbformId)")//根据表id来判断是否有权限访问
|
||||
@PostMapping({"/summary/{dbformId}"})
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "表单开发",summary = "获取表数据统计")
|
||||
public BaseWebResult getDataSummary(@PathVariable("dbformId") Long dbformId, HttpServletRequest req) {
|
||||
Map<String, Object> params = FuncWeb.getParameterBodyMap(req);
|
||||
Map map = super.getSummaryData(dbformId, params);
|
||||
return BaseWebResult.success(map);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform-data:query:'+#dbformId)")//根据表id来判断是否有权限访问
|
||||
@PostMapping({"/detail/{dbformId}/{dataId}"})
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(tags = "表单开发",summary = "获取表数据详情")
|
||||
public BaseWebResult getDataDetail(@PathVariable("dbformId") Long dbformId, @PathVariable("dataId") Long dataId, HttpServletRequest req) {
|
||||
Map<String, Object> params = FuncWeb.getParameterBodyMap(req);
|
||||
ResultDataModel resultDataModel = super.getDataDetail(dbformId, dataId, params);
|
||||
|
||||
if (FuncBase.isEmpty(resultDataModel) || FuncBase.isEmpty(resultDataModel.getRecords())) {
|
||||
return BaseWebResult.successNull();
|
||||
}
|
||||
return BaseWebResult.success(resultDataModel.getRecords().get(0));
|
||||
}
|
||||
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform-data:create:'+#dbformId)")//根据表id来判断是否有权限访问
|
||||
@PostMapping({"/save/{dbformId}"})
|
||||
@ApiOperationSupport(order = 5)
|
||||
@Operation(tags = "表单开发",summary = "新增表数据")
|
||||
public BaseWebResult addData(@PathVariable("dbformId") Long dbformId, @RequestBody JSONObject jsonObject) {
|
||||
String id = super.addJsonData(dbformId, jsonObject);
|
||||
return BaseWebResult.success(id);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform-data:create:'+#dbformId)")//根据表id来判断是否有权限访问
|
||||
@PostMapping({"/save/batch/{dbformId}"})
|
||||
@ApiOperationSupport(order = 5)
|
||||
@Operation(tags = "表单开发",summary = "新增表数据-批量新增")
|
||||
public BaseWebResult addBatchData(@PathVariable("dbformId") Long dbformId, @RequestBody List<JSONObject> jsonList) {
|
||||
List<String> idList = super.addJsonData(dbformId, jsonList);
|
||||
return BaseWebResult.success(idList);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform-data:update:'+#dbformId)")//根据表id来判断是否有权限访问
|
||||
@PutMapping({"/edit/{dbformId}"})
|
||||
@ApiOperationSupport(order = 6)
|
||||
@Operation(tags = "表单开发",summary = "编辑表数据")
|
||||
public BaseWebResult editData(@PathVariable("dbformId") Long dbformId, @RequestBody JSONObject jsonObject) {
|
||||
super.editJsonData(dbformId,jsonObject);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform-data:update:'+#dbformId)")//根据表id来判断是否有权限访问
|
||||
@PutMapping({"/edit/batch/{dbformId}"})
|
||||
@ApiOperationSupport(order = 6)
|
||||
@Operation(tags = "表单开发",summary = "编辑表数据-批量")
|
||||
public BaseWebResult editBatchData(@PathVariable("dbformId") Long dbformId, @RequestBody List<JSONObject> jsonObjectList) {
|
||||
super.editJsonData(dbformId,jsonObjectList);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform-data:delete:'+#dbformId)")//根据表id来判断是否有权限访问
|
||||
@DeleteMapping({"/delete/{dbformId}"})
|
||||
@ApiOperationSupport(order = 7)
|
||||
@Operation(tags = "表单开发",summary = "根据id删除数据")
|
||||
public BaseWebResult delData(@PathVariable("dbformId") Long dbformId, @RequestBody List<Long> dataIdList) {
|
||||
super.deleteDataById(dbformId,dataIdList);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PostMapping({"/unique/{dbformId}"})
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(tags = "表单开发",summary = "校验数据是否唯一")
|
||||
public BaseWebResult dataUnique(@PathVariable("dbformId") Long dbformId,@RequestBody DataUniqueParam param) {
|
||||
String fieldCode = param.getFieldCode();
|
||||
Long dataId = param.getDataId();
|
||||
String fieldVal = param.getFieldVal();
|
||||
if(Func.isEmpty(fieldCode) || Func.isEmpty(fieldVal)){
|
||||
return BaseWebResult.error(FrameErrorCodeConstants.FRAME_PARAM_NULL_ERROR);
|
||||
}
|
||||
|
||||
//表名称
|
||||
String tableName = formService.getTableName(dbformId);
|
||||
boolean isExist = formService.fieldCodeIsExist(dbformId, fieldCode);
|
||||
if(!isExist){
|
||||
return BaseWebResult.success(true);
|
||||
}
|
||||
JeeLowCodeFieldTypeEnum fieldTypeEnum = formService.getFieldTypeEnum(dbformId, fieldCode);
|
||||
|
||||
SqlInfoQueryWrapper.Wrapper wrapper = SqlHelper.getQueryWrapper()
|
||||
.setTableName(tableName)
|
||||
.select("id")
|
||||
.setWhere(where -> {
|
||||
where.eq(fieldCode, Func.getfieldValObj(fieldTypeEnum,fieldVal));
|
||||
where.ne("id", dataId);
|
||||
})
|
||||
.build();
|
||||
List<Map<String, Object>> dataMapList = sqlService.getDataListByPlus(wrapper);
|
||||
return BaseWebResult.success(Func.isNotEmpty(dataMapList));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
|
||||
package com.jeelowcode.core.framework.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.JeeLowCodeAnnoaionAspectjSQL;
|
||||
import com.jeelowcode.core.framework.config.aspect.enhance.JeeLowCodeAnnotationAspectjJAVA;
|
||||
import com.jeelowcode.core.framework.entity.EnhanceJavaEntity;
|
||||
import com.jeelowcode.core.framework.entity.EnhanceJsEntity;
|
||||
import com.jeelowcode.core.framework.entity.EnhanceSqlEntity;
|
||||
import com.jeelowcode.core.framework.params.vo.PageVo;
|
||||
import com.jeelowcode.core.framework.service.IEnhanceJavaService;
|
||||
import com.jeelowcode.core.framework.service.IEnhanceJsService;
|
||||
import com.jeelowcode.core.framework.service.IEnhanceSqlService;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.framework.constants.FrameErrorCodeConstants;
|
||||
import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
|
||||
import com.jeelowcode.framework.utils.annotation.ApiDecryptAes;
|
||||
import com.jeelowcode.framework.utils.annotation.ApiEncryptAes;
|
||||
import com.jeelowcode.framework.utils.component.redis.JeeLowCodeRedisUtils;
|
||||
import com.jeelowcode.framework.utils.constant.JeeRedisConstants;
|
||||
import com.jeelowcode.framework.utils.model.global.BaseWebResult;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Tag(name = "低代码框架-增强接口")
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(JeeLowCodeBaseConstant.REQUEST_URL_START + "/enhance")
|
||||
public class DbFormEnhanceController extends BaseController {
|
||||
|
||||
private final IEnhanceJavaService javaService;
|
||||
|
||||
private final JeeLowCodeRedisUtils jeeLowCodeRedisUtils;
|
||||
|
||||
private final IEnhanceJsService enhanceJsService;
|
||||
|
||||
private final IJeeLowCodeAdapter adapter;
|
||||
|
||||
private final IEnhanceSqlService sqlService;
|
||||
|
||||
//-------------------- java 增强相关------------------------------
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:java')")
|
||||
@GetMapping("/java/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(tags = "JAVA增强",summary = "Java增强-详情")
|
||||
public BaseWebResult<EnhanceJavaEntity> javaDetail(@RequestParam Long id) {
|
||||
return BaseWebResult.success(javaService.getById(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:java')")
|
||||
@PostMapping("/java/save")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(tags = "JAVA增强",summary = "新增")
|
||||
public BaseWebResult javaSave(@RequestBody EnhanceJavaEntity model) {
|
||||
javaService.saveEnhanceJava(model);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:java')")
|
||||
@PutMapping("/java/update")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "JAVA增强",summary = "修改")
|
||||
public BaseWebResult javaUpdate(@RequestBody EnhanceJavaEntity model) {
|
||||
javaService.updateEnhanceJava(model);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:java')")
|
||||
@DeleteMapping("/java/delete")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(tags = "JAVA增强",summary = "删除(逻辑删除)")
|
||||
public BaseWebResult javaDel(@RequestBody List<Long> ids) {
|
||||
|
||||
List<EnhanceJavaEntity> enhanceJavaEntities = javaService.listByIds(ids);
|
||||
enhanceJavaEntities.stream().forEach(entity->{
|
||||
JeeLowCodeAnnotationAspectjJAVA.deletePlugins(entity);
|
||||
});
|
||||
|
||||
javaService.removeByIds(ids);
|
||||
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:java')")
|
||||
@GetMapping("/java/page")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@Operation(tags = "JAVA增强",summary = "获取列表(分页)")
|
||||
public BaseWebResult javaPage(EnhanceJavaEntity entity, PageVo pageVo,String column,String order) {
|
||||
Page page = FuncWeb.getPage(pageVo.getPageNo(), pageVo.getPageSize());
|
||||
|
||||
LambdaQueryWrapper<EnhanceJavaEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.setEntity(entity);
|
||||
if(Func.isNotEmpty(column)){
|
||||
if(Func.equals(order.toUpperCase(),"ASC")){
|
||||
wrapper.orderByAsc(EnhanceJavaEntity::getButtonCode);
|
||||
}else{
|
||||
wrapper.orderByDesc(EnhanceJavaEntity::getButtonCode);
|
||||
}
|
||||
}else{//默认按id排序
|
||||
wrapper.orderByDesc(EnhanceJavaEntity::getId);
|
||||
}
|
||||
IPage<EnhanceJavaEntity> pages = javaService.page(page, wrapper);
|
||||
return BaseWebResult.success(pages);
|
||||
}
|
||||
|
||||
//-------------------- js 增强相关------------------------------
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:web')")
|
||||
@PostMapping("/js/unlock/{dbformId}")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(tags = "Js增强",summary = "Js增强-解锁")
|
||||
public BaseWebResult unlock(@PathVariable("dbformId") Long dbformId, @RequestParam String type) {
|
||||
|
||||
String redisKey = String.format(JeeRedisConstants.ENHANCE_JS_LOCK,dbformId+":"+type);
|
||||
if (jeeLowCodeRedisUtils.hasKey(redisKey)) {
|
||||
jeeLowCodeRedisUtils.del(redisKey);
|
||||
}
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
|
||||
//返回数据加密
|
||||
@ApiEncryptAes
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:web')")
|
||||
@GetMapping("/js/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(tags = "Js增强",summary = "Js增强-详情")
|
||||
public BaseWebResult jsDetail(@RequestParam Long dbformId,
|
||||
@RequestParam String type,
|
||||
@RequestParam String lock){
|
||||
if (FuncBase.isNotEmpty(lock) && FuncBase.equals(lock, "true")) {
|
||||
String redisKey = String.format(JeeRedisConstants.ENHANCE_JS_LOCK,dbformId+":"+type);
|
||||
if (jeeLowCodeRedisUtils.hasKey(redisKey)) {
|
||||
String lockMapStr = (String)jeeLowCodeRedisUtils.get(redisKey);
|
||||
Map lockMap = Func.json2Bean(lockMapStr, Map.class);
|
||||
//返回锁定信息
|
||||
return BaseWebResult.error(FrameErrorCodeConstants.FRAME_ENHANCE_ERROR,lockMap);
|
||||
}
|
||||
|
||||
String userName = adapter.getOnlineUserName();
|
||||
|
||||
String timeStr = DateUtil.now();
|
||||
//存储锁定信息
|
||||
Map<String,Object> lockMap=new HashMap<>();
|
||||
lockMap.put("userName",userName);
|
||||
lockMap.put("timeStr",timeStr);
|
||||
jeeLowCodeRedisUtils.set(redisKey, Func.json2Str(lockMap));//上锁
|
||||
}
|
||||
return BaseWebResult.success(enhanceJsService.getDbFormEnhanceJsDetail(dbformId,type));
|
||||
}
|
||||
|
||||
//解密body数据
|
||||
@ApiDecryptAes
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:web')")
|
||||
@PostMapping("/js/save")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(tags = "Js增强",summary = "js增强-新增")
|
||||
public BaseWebResult save(@RequestBody EnhanceJsEntity model) {
|
||||
enhanceJsService.saveEnhanceJs(model);
|
||||
return BaseWebResult.success(model.getId());
|
||||
}
|
||||
|
||||
//解密body数据
|
||||
@ApiDecryptAes
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:web')")
|
||||
@PutMapping("/js/update")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "Js增强",summary = "js增强-修改")
|
||||
public BaseWebResult update(@RequestBody EnhanceJsEntity model) {
|
||||
enhanceJsService.updateEnhanceJs(model);
|
||||
return BaseWebResult.success(model.getId());
|
||||
}
|
||||
|
||||
//-------------------- sql 增强相关------------------------------
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:sql')")
|
||||
@GetMapping("/sql/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(tags = "Sql增强",summary = "详情")
|
||||
public BaseWebResult<EnhanceSqlEntity> sqlDetail(@RequestParam Long id){
|
||||
return BaseWebResult.success(sqlService.getById(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:sql')")
|
||||
@PostMapping("/sql/save")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(tags = "Sql增强",summary = "新增")
|
||||
public BaseWebResult sqlSave(@RequestBody EnhanceSqlEntity model) {
|
||||
sqlService.saveEnhanceSql(model);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:sql')")
|
||||
@PutMapping("/sql/update")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "Sql增强",summary = "修改")
|
||||
public BaseWebResult sqlUpdate(@RequestBody EnhanceSqlEntity model) {
|
||||
sqlService.updateEnhanceSql(model);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:sql')")
|
||||
@DeleteMapping("/sql/delete")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "Sql增强",summary = "删除(逻辑删除)")
|
||||
public BaseWebResult sqlDel(@RequestBody List<Long> ids) {
|
||||
List<EnhanceSqlEntity> enhanceSqlEntities = sqlService.listByIds(ids);
|
||||
enhanceSqlEntities.stream().forEach(
|
||||
e ->{
|
||||
JeeLowCodeAnnoaionAspectjSQL.removePlugin(e);
|
||||
}
|
||||
);
|
||||
sqlService.removeByIds(ids);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:sql')")
|
||||
@GetMapping("/sql/list")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "Sql增强",summary = "获取列表")
|
||||
public BaseWebResult sqlList(EnhanceSqlEntity entity) {
|
||||
LambdaQueryWrapper<EnhanceSqlEntity> wrapper=new LambdaQueryWrapper<>();
|
||||
wrapper.setEntity(entity);
|
||||
wrapper.orderByDesc(EnhanceSqlEntity::getId);
|
||||
List<EnhanceSqlEntity> dataList = sqlService.list(wrapper);
|
||||
return BaseWebResult.success(dataList);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:sql')")
|
||||
@GetMapping("/sql/page")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "Sql增强",summary = "获取列表(分页)")
|
||||
public BaseWebResult sqlPage(EnhanceSqlEntity entity, PageVo pageVo,String column,String order) {
|
||||
Page page = FuncWeb.getPage(pageVo.getPageNo(), pageVo.getPageSize());
|
||||
|
||||
LambdaQueryWrapper<EnhanceSqlEntity> wrapper=new LambdaQueryWrapper<>();
|
||||
wrapper.setEntity(entity);
|
||||
if(Func.isNotEmpty(column)){
|
||||
if(Func.equals(order.toUpperCase(),"ASC")){
|
||||
wrapper.orderByAsc(EnhanceSqlEntity::getButtonCode);
|
||||
}else{
|
||||
wrapper.orderByDesc(EnhanceSqlEntity::getButtonCode);
|
||||
}
|
||||
}else{//默认按id排序
|
||||
wrapper.orderByDesc(EnhanceSqlEntity::getId);
|
||||
}
|
||||
IPage<EnhanceSqlEntity> pages = sqlService.page(page, wrapper);
|
||||
return BaseWebResult.success(pages);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
|
||||
package com.jeelowcode.core.framework.controller;
|
||||
|
||||
import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
|
||||
import com.jeelowcode.core.framework.params.vo.role.DbFormRoleButtonVo;
|
||||
import com.jeelowcode.core.framework.params.vo.role.DbFormRoleDataRuleVo;
|
||||
import com.jeelowcode.core.framework.params.vo.role.DbFormRoleDataTenantVo;
|
||||
import com.jeelowcode.core.framework.params.vo.role.DbFormRoleFieldVo;
|
||||
import com.jeelowcode.core.framework.service.IDbFormRoleService;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
|
||||
import com.jeelowcode.framework.utils.model.global.BaseWebResult;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "低代码框架-表单开发-权限接口")
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping(JeeLowCodeBaseConstant.REQUEST_URL_START + "/dbform-role")
|
||||
public class DbFormRoleController extends BaseController {
|
||||
|
||||
private final IDbFormRoleService dbFormRoleService;
|
||||
|
||||
private final IJeeLowCodeAdapter jeeLowCodeAdapter;
|
||||
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:role')")
|
||||
@PostMapping("/save-field")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(tags = "表单开发",summary = "新增/修改 字段权限")
|
||||
public BaseWebResult saveRoleField(@RequestBody List<DbFormRoleFieldVo> voList) {
|
||||
dbFormRoleService.saveOrUpdateRoleField(voList);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
//@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:role')")
|
||||
@PostMapping("/list-field")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(tags = "表单开发",summary = "列表 字段权限")
|
||||
public BaseWebResult listRoleField(Long tenantId,Long dbFormId) {
|
||||
List<DbFormRoleFieldVo> list = dbFormRoleService.listRoleField(tenantId, dbFormId);
|
||||
return BaseWebResult.success(list);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:role')")
|
||||
@PostMapping("/save-button")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "表单开发",summary = "新增/修改 按钮权限")
|
||||
public BaseWebResult saveRoleButton(@RequestBody List<DbFormRoleButtonVo> voList) {
|
||||
dbFormRoleService.saveOrUpdateRoleButton(voList);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
//@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:role')")
|
||||
@PostMapping("/list-button")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(tags = "表单开发",summary = "列表 字段权限")
|
||||
public BaseWebResult listRoleButton(Long tenantId,Long dbFormId) {
|
||||
List<DbFormRoleButtonVo> list = dbFormRoleService.listRoleButton(tenantId, dbFormId);
|
||||
return BaseWebResult.success(list);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:role')")
|
||||
@PostMapping("/save-data-rule")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "表单开发",summary = "新增/修改 数据权限-规则")
|
||||
public BaseWebResult saveRoleDataRule(@RequestBody DbFormRoleDataRuleVo vo) {
|
||||
dbFormRoleService.saveOrUpdateRoleDataRule(vo);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:role')")
|
||||
@DeleteMapping("/del-data-rule")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "表单开发",summary = "删除 数据权限-规则")
|
||||
public BaseWebResult delRoleDataRule(Long ruleId) {
|
||||
dbFormRoleService.delRoleDataRule(ruleId);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:role')")
|
||||
@PostMapping("/save-data-tenant")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "表单开发",summary = "新增/修改 数据权限-租户数据")
|
||||
public BaseWebResult saveRoleDataTenant(@RequestBody List<DbFormRoleDataTenantVo> voList) {
|
||||
dbFormRoleService.saveOrUpdateRoleDataTenant(voList);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
|
||||
//@PreAuthorize("@ss.hasPermission('jeelowcode:dbform:role')")
|
||||
@PostMapping("/list-data")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(tags = "表单开发",summary = "列表 数据权限")
|
||||
public BaseWebResult listRoleData(Long tenantId,Long dbFormId) {
|
||||
List<DbFormRoleDataRuleVo> list = dbFormRoleService.listRoleData(tenantId, dbFormId);
|
||||
return BaseWebResult.success(list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
|
||||
package com.jeelowcode.core.framework.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.jeelowcode.framework.global.JeeLowCodeBaseConstant;
|
||||
import com.jeelowcode.core.framework.entity.DesformEntity;
|
||||
import com.jeelowcode.core.framework.params.DesFormAddOrUpdateParam;
|
||||
import com.jeelowcode.core.framework.params.PageDesFormParam;
|
||||
import com.jeelowcode.core.framework.service.IDesFormService;
|
||||
import com.jeelowcode.core.framework.utils.Func;
|
||||
import com.jeelowcode.core.framework.utils.FuncWeb;
|
||||
import com.jeelowcode.framework.constants.FrameErrorCodeConstants;
|
||||
import com.jeelowcode.framework.utils.adapter.IJeeLowCodeAdapter;
|
||||
import com.jeelowcode.framework.utils.annotation.ApiDecryptAes;
|
||||
import com.jeelowcode.framework.utils.annotation.ApiEncryptAes;
|
||||
import com.jeelowcode.framework.utils.constant.JeeLowCodeConstant;
|
||||
import com.jeelowcode.framework.utils.constant.JeeRedisConstants;
|
||||
import com.jeelowcode.framework.utils.component.redis.JeeLowCodeRedisUtils;
|
||||
import com.jeelowcode.framework.utils.enums.YNEnum;
|
||||
import com.jeelowcode.framework.utils.utils.FuncBase;
|
||||
import com.jeelowcode.framework.utils.model.global.BaseWebResult;
|
||||
import com.jeelowcode.core.framework.params.vo.DesformEntityVo;
|
||||
import com.jeelowcode.core.framework.params.vo.PageVo;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Tag(name = "低代码框架-表单设计器接口")
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping( JeeLowCodeBaseConstant.REQUEST_URL_START+"/desform")
|
||||
public class DesFormController extends BaseController {
|
||||
|
||||
private final IDesFormService desFormService;
|
||||
|
||||
private final JeeLowCodeRedisUtils jeeLowCodeRedisUtils;
|
||||
|
||||
private final IJeeLowCodeAdapter adapter;
|
||||
|
||||
|
||||
@PostMapping("/unlock/{desFormId}")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(tags = "自定义表单",summary = "表单设计增强-解锁")
|
||||
public BaseWebResult unlock(@PathVariable("desFormId") Long desFormId) {
|
||||
String redisKey = String.format(JeeRedisConstants.ENHANCE_DESFORM_LOCK,String.valueOf(desFormId));
|
||||
if (jeeLowCodeRedisUtils.hasKey(redisKey)) {
|
||||
jeeLowCodeRedisUtils.del(redisKey);
|
||||
}
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:desform:create')")
|
||||
@ApiDecryptAes//解密
|
||||
@PostMapping("/save")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(tags = "自定义表单",summary = "表单设计器 - 保存")
|
||||
public BaseWebResult saveDesForm(@RequestBody DesFormAddOrUpdateParam param) {
|
||||
param.setIsHide(YNEnum.N.getCode());
|
||||
Long id = desFormService.saveDesForm(param);
|
||||
return BaseWebResult.success(id);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:desform:update')")
|
||||
@ApiDecryptAes//解密
|
||||
@PutMapping("/update")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(tags = "自定义表单",summary = "表单设计器 - 修改")
|
||||
public BaseWebResult updateDesForm(@RequestBody DesFormAddOrUpdateParam param) {
|
||||
desFormService.updateDesForm(param);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermission('jeelowcode:desform:delete')")
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(tags = "自定义表单",summary = "表单设计器 - 删除")
|
||||
public BaseWebResult delDesForm(@RequestBody List<Long> ids) {
|
||||
desFormService.removeByIds(ids);
|
||||
return BaseWebResult.success("成功");
|
||||
}
|
||||
|
||||
//返回数据加密
|
||||
@ApiEncryptAes
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(tags = "自定义表单",summary = "表单设计器 - 获取详情")
|
||||
public BaseWebResult getDetailDesForm(Long desFormId,String lock) {
|
||||
if (FuncBase.isNotEmpty(lock) && FuncBase.equals(lock, "true")) {
|
||||
String redisKey = String.format(JeeRedisConstants.ENHANCE_DESFORM_LOCK,String.valueOf(desFormId));
|
||||
if (jeeLowCodeRedisUtils.hasKey(redisKey)) {
|
||||
String lockMapStr = (String)jeeLowCodeRedisUtils.get(redisKey);
|
||||
Map lockMap = Func.json2Bean(lockMapStr, Map.class);
|
||||
//返回锁定信息
|
||||
return BaseWebResult.error(FrameErrorCodeConstants.FRAME_ENHANCE_ERROR,lockMap);
|
||||
}
|
||||
|
||||
String userName = adapter.getOnlineUserName();
|
||||
String timeStr = DateUtil.now();
|
||||
//存储锁定信息
|
||||
Map<String,Object> lockMap=new HashMap<>();
|
||||
lockMap.put("userName",userName);
|
||||
lockMap.put("timeStr",timeStr);
|
||||
jeeLowCodeRedisUtils.set(redisKey, Func.json2Str(lockMap));//上锁
|
||||
}
|
||||
|
||||
DesformEntity desformEntity = desFormService.getById(desFormId);
|
||||
return BaseWebResult.success(desformEntity);
|
||||
}
|
||||
|
||||
@PostMapping("/page")
|
||||
@ApiOperationSupport(order = 6)
|
||||
@Operation(tags = "自定义表单",summary = "获取列表")
|
||||
public BaseWebResult page(PageDesFormParam param, PageVo pageVo) {
|
||||
|
||||
LambdaQueryWrapper<DesformEntity> wrapper=new LambdaQueryWrapper<>();
|
||||
wrapper.eq(FuncBase.isNotEmpty(param.getId()),DesformEntity::getId,param.getId());
|
||||
wrapper.eq(FuncBase.isNotEmpty(param.getGroupDesformId()),DesformEntity::getGroupDesformId,param.getGroupDesformId());
|
||||
wrapper.eq(FuncBase.isNotEmpty(param.getIsOpen()), DesformEntity::getIsOpen, param.getIsOpen());
|
||||
wrapper.eq(FuncBase.isNotEmpty(param.getIsTemplate()), DesformEntity::getIsTemplate, param.getIsTemplate());
|
||||
wrapper.and(subWrapper->{
|
||||
subWrapper.ne(DesformEntity::getIsHide, YNEnum.Y.getCode()).or()
|
||||
.isNull(DesformEntity::getIsHide);
|
||||
} );
|
||||
wrapper.like(FuncBase.isNotEmpty(param.getDesformName()),DesformEntity::getDesformName,param.getDesformName());
|
||||
wrapper.orderByDesc(DesformEntity::getId);
|
||||
|
||||
IPage<DesformEntityVo> resultList=new Page<>();
|
||||
if(Func.isEmpty(pageVo) || Func.isEmpty(pageVo.getPageSize()) || Func.equals(JeeLowCodeConstant.NOT_PAGE,pageVo.getPageSize())){
|
||||
List<DesformEntity> dataList = desFormService.list(wrapper);
|
||||
resultList.setRecords(toVoBean(dataList, DesformEntityVo.class));
|
||||
resultList.setTotal(dataList.size());
|
||||
resultList.setCurrent(1L);
|
||||
resultList.setPages(1L);
|
||||
resultList.setSize(JeeLowCodeConstant.NOT_PAGE);
|
||||
}else{
|
||||
Page page = FuncWeb.getPage(pageVo.getPageNo(), pageVo.getPageSize());
|
||||
IPage<DesformEntity> pages = desFormService.page(page, wrapper);
|
||||
resultList = toVoBean(pages, DesformEntityVo.class);
|
||||
}
|
||||
|
||||
return BaseWebResult.success(resultList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/get/template")
|
||||
@ApiOperationSupport(order = 6)
|
||||
@Operation(tags = "自定义表单",summary = "获取模板")
|
||||
public BaseWebResult getTemplate() {
|
||||
LambdaQueryWrapper<DesformEntity> wrapper=new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DesformEntity::getIsTemplate, YNEnum.Y.getCode());
|
||||
List<DesformEntity> templateList = desFormService.list(wrapper);
|
||||
return BaseWebResult.success(templateList);
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user