初始代码
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<parent>
|
||||
<artifactId>yunzhupaas-visualdev-base</artifactId>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<version>5.2.0-RELEASE</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>yunzhupaas-visualdev-base-biz</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-visualdev-base-entity</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- Generator模板引擎 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
</dependency>
|
||||
<!-- 代码生成 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-visualdev-generater-entity</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.dynamic-sql</groupId>
|
||||
<artifactId>mybatis-dynamic-sql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-system-biz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-common-security</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.yunzhupaas.base.mapper;
|
||||
|
||||
import com.yunzhupaas.base.entity.BillNumEntity;
|
||||
|
||||
/**
|
||||
* 单据递增序号
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v5.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/9/4 9:26:52
|
||||
*/
|
||||
public interface BillNumMapper extends SuperMapper<BillNumEntity> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yunzhupaas.base.mapper;
|
||||
|
||||
import com.yunzhupaas.base.entity.FilterEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface FilterMapper extends SuperMapper<FilterEntity> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.yunzhupaas.base.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.mybatis.dynamic.sql.util.mybatis3.*;
|
||||
|
||||
/**
|
||||
* mybatis3 表单mapper对象
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.5
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2022/9/27
|
||||
*/
|
||||
@Mapper
|
||||
public interface FlowFormDataMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper, CommonSelectMapper,
|
||||
CommonUpdateMapper {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.yunzhupaas.base.mapper;
|
||||
|
||||
import com.yunzhupaas.base.entity.FlowFormRelationEntity;
|
||||
|
||||
/**
|
||||
* 流程表单关联
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.2
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/6/30 18:00
|
||||
*/
|
||||
public interface FlowFormRelationMapper extends SuperMapper<FlowFormRelationEntity> {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.yunzhupaas.base.mapper;
|
||||
|
||||
import com.yunzhupaas.base.entity.VisualAliasEntity;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v5.0.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/4/13 14:03:56
|
||||
*/
|
||||
public interface VisualAliasMapper extends SuperMapper<VisualAliasEntity> {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.yunzhupaas.base.mapper;
|
||||
|
||||
|
||||
import com.yunzhupaas.base.mapper.SuperMapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @author 云筑产品开发平台组
|
||||
* @date 2024/3/16
|
||||
*/
|
||||
public interface VisualdevMapper extends SuperMapper<VisualdevEntity> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.yunzhupaas.base.mapper;
|
||||
|
||||
|
||||
import com.yunzhupaas.base.entity.VisualdevReleaseEntity;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/3/16
|
||||
*/
|
||||
public interface VisualdevReleaseMapper extends SuperMapper<VisualdevReleaseEntity> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.yunzhupaas.base.mapper;
|
||||
|
||||
import com.yunzhupaas.base.entity.VisualdevShortLinkEntity;
|
||||
|
||||
/**
|
||||
* 在线表单外链mapper
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.2
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/12/30 11:30:09
|
||||
*/
|
||||
public interface VisualdevShortLinkMapper extends SuperMapper<VisualdevShortLinkEntity> {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.yunzhupaas.base.service;
|
||||
|
||||
import com.yunzhupaas.base.entity.BillNumEntity;
|
||||
|
||||
/**
|
||||
* 单据递增序号
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v5.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/9/4 9:26:33
|
||||
*/
|
||||
public interface BillNumService extends SuperService<BillNumEntity> {
|
||||
|
||||
void saveBillNum(BillNumEntity entity);
|
||||
|
||||
BillNumEntity getBillNum(String ruleId, String visualId, String flowId);
|
||||
|
||||
void removeByRuleId(String ruleId, String visualId, String flowId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.yunzhupaas.base.service;
|
||||
import com.yunzhupaas.base.entity.FilterEntity;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.model.filter.RuleInfo;
|
||||
import org.mybatis.dynamic.sql.SqlTable;
|
||||
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
|
||||
import org.mybatis.dynamic.sql.select.SelectModel;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public interface FilterService extends SuperService<FilterEntity> {
|
||||
void saveRuleList(String moduleId, VisualdevEntity visualdevEntity, Integer app, Integer pc, Map<String,String> tableMap);
|
||||
|
||||
void updateRuleList(String moduleId, VisualdevEntity columnData, Integer app, Integer pc, Map<String,String> tableMap);
|
||||
|
||||
|
||||
void handleWhereCondition(SqlTable sqlTable, QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where, String id, Map<String,SqlTable> subSqlTableMap, String databaseProductName, Map<String,Object> params);
|
||||
|
||||
void handleWhereCondition(SqlTable sqlTable, QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where, String id, Map<String,SqlTable> subSqlTableMap, String databaseProductName);
|
||||
|
||||
// 获取过滤配置
|
||||
List<RuleInfo> getCondition(String id);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yunzhupaas.base.service;
|
||||
|
||||
import com.yunzhupaas.base.entity.FlowFormRelationEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 流程表单关联
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.2
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/6/30 18:01
|
||||
*/
|
||||
public interface FlowFormRelationService extends SuperService<FlowFormRelationEntity> {
|
||||
/**
|
||||
* 根据流程id保存关联表单
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/10/26
|
||||
*/
|
||||
void saveFlowIdByFormIds(String flowId, List<String> formIds);
|
||||
|
||||
/**
|
||||
* 根据表单id查询是否存在引用
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/10/26
|
||||
*/
|
||||
List<FlowFormRelationEntity> getListByFormId(String formId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.yunzhupaas.base.service;
|
||||
|
||||
import com.yunzhupaas.base.model.ai.VisualAiModel;
|
||||
|
||||
/**
|
||||
* 在线开发ai接口
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v5.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/12/2 10:10:10
|
||||
*/
|
||||
public interface VisualAiService {
|
||||
|
||||
/**
|
||||
* ai生成表单模板
|
||||
*
|
||||
* @param keyword
|
||||
*/
|
||||
VisualAiModel form(String keyword);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.yunzhupaas.base.service;
|
||||
|
||||
import com.yunzhupaas.base.entity.VisualAliasEntity;
|
||||
import com.yunzhupaas.base.model.VisualAliasForm;
|
||||
import com.yunzhupaas.base.util.common.AliasModel;
|
||||
import com.yunzhupaas.model.visualJson.TableModel;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v5.0.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/4/13 14:05:19
|
||||
*/
|
||||
public interface VisualAliasService extends SuperService<VisualAliasEntity> {
|
||||
|
||||
List<VisualAliasEntity> getList(String visualId);
|
||||
|
||||
/**
|
||||
* 获取表 别名列表
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
List<TableModel> getAliasInfo(String id);
|
||||
|
||||
/**
|
||||
* 保存或者修改表别名列表
|
||||
*
|
||||
* @param id
|
||||
* @param form
|
||||
*/
|
||||
void aliasSave(String id, VisualAliasForm form);
|
||||
|
||||
/**
|
||||
* 获取全字段别名,系统字段自动驼峰
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Map<String, AliasModel> getAllFiledsAlias(String id);
|
||||
|
||||
/**
|
||||
* 复制命名规范
|
||||
* @param visualId
|
||||
* @param uuid
|
||||
* @return
|
||||
*/
|
||||
void copy(String visualId,String uuid);
|
||||
|
||||
/**
|
||||
* 复制单个对象
|
||||
* @param visualId
|
||||
* @param copy
|
||||
* @return
|
||||
*/
|
||||
void copyEntity(VisualAliasEntity copy,String visualId);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param visualId
|
||||
*/
|
||||
void removeByVisualId(String visualId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.yunzhupaas.base.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.yunzhupaas.base.entity.VisualdevReleaseEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @author 云筑产品开发平台组
|
||||
* @date 2024/3/16
|
||||
*/
|
||||
public interface VisualdevReleaseService extends SuperService<VisualdevReleaseEntity> {
|
||||
|
||||
long beenReleased(String id);
|
||||
|
||||
List<VisualdevReleaseEntity> selectorList();
|
||||
|
||||
List<VisualdevReleaseEntity> selectByIds(List<String> ids, SFunction<VisualdevReleaseEntity, ?>... columns);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.yunzhupaas.base.service;
|
||||
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.model.PaginationVisualdev;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.model.visualJson.TableFields;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/3/16
|
||||
*/
|
||||
public interface VisualdevService extends SuperService<VisualdevEntity> {
|
||||
|
||||
List<VisualdevEntity> getList(PaginationVisualdev paginationVisualdev);
|
||||
|
||||
List<VisualdevEntity> getPageList(PaginationVisualdev paginationVisualdev);
|
||||
|
||||
List<VisualdevEntity> getList();
|
||||
|
||||
VisualdevEntity getInfo(String id);
|
||||
|
||||
/**
|
||||
* 获取已发布的版本, 若未发布获取当前版本
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
VisualdevEntity getReleaseInfo(String id);
|
||||
|
||||
/**
|
||||
* 获取动态设计子表名和实际库表名的对应
|
||||
*
|
||||
* @param formData
|
||||
* @return
|
||||
*/
|
||||
Map<String, String> getTableMap(String formData);
|
||||
|
||||
Boolean create(VisualdevEntity entity);
|
||||
|
||||
boolean update(String id, VisualdevEntity entity) throws Exception;
|
||||
|
||||
/**
|
||||
* 根据encode判断是否有相同值
|
||||
*
|
||||
* @param encode
|
||||
* @return
|
||||
*/
|
||||
Integer getObjByEncode(String encode, Integer type);
|
||||
|
||||
/**
|
||||
* 根据name判断是否有相同值
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
Integer getCountByName(String name, Integer type);
|
||||
|
||||
/**
|
||||
* 无表生成有表
|
||||
*
|
||||
* @param entity
|
||||
*/
|
||||
void createTable(VisualdevEntity entity) throws WorkFlowException;
|
||||
|
||||
Boolean getPrimaryDbField(String linkId, String table) throws Exception;
|
||||
|
||||
List<VisualdevEntity> selectorList();
|
||||
|
||||
/**
|
||||
* 获取关联表单字段列表
|
||||
*
|
||||
* @param entity
|
||||
*/
|
||||
List<TableFields> storedFieldList(VisualdevEntity entity);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.yunzhupaas.base.service;
|
||||
|
||||
import com.yunzhupaas.base.entity.VisualdevShortLinkEntity;
|
||||
|
||||
/**
|
||||
* 在线表单外链service
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.2
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/12/30 11:30:57
|
||||
*/
|
||||
public interface VisualdevShortLinkService extends SuperService<VisualdevShortLinkEntity> {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.yunzhupaas.base.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.yunzhupaas.base.entity.BillNumEntity;
|
||||
import com.yunzhupaas.base.mapper.BillNumMapper;
|
||||
import com.yunzhupaas.base.service.BillNumService;
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 单据递增序号
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v5.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/9/4 9:28:31
|
||||
*/
|
||||
@Service
|
||||
public class BillNumServiceImpl extends SuperServiceImpl<BillNumMapper, BillNumEntity> implements BillNumService {
|
||||
|
||||
public void saveBillNum(BillNumEntity entity) {
|
||||
if (entity.getId() == null) {
|
||||
entity.setId(RandomUtil.uuId());
|
||||
}
|
||||
this.saveOrUpdate(entity);
|
||||
}
|
||||
|
||||
public BillNumEntity getBillNum(String ruleId, String visualId, String flowId) {
|
||||
QueryWrapper<BillNumEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(BillNumEntity::getRuleId, ruleId);
|
||||
queryWrapper.lambda().eq(BillNumEntity::getVisualId, visualId);
|
||||
if (StringUtil.isNotEmpty(flowId)) {
|
||||
queryWrapper.lambda().eq(BillNumEntity::getFlowId, flowId);
|
||||
} else {
|
||||
queryWrapper.lambda().isNull(BillNumEntity::getFlowId);
|
||||
}
|
||||
List<BillNumEntity> list = this.list(queryWrapper);
|
||||
if (list.size() > 0) {
|
||||
BillNumEntity billNumEntity = list.stream().findFirst().orElse(null);
|
||||
return billNumEntity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByRuleId(String ruleId, String visualId, String flowId) {
|
||||
QueryWrapper<BillNumEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(BillNumEntity::getRuleId, ruleId);
|
||||
queryWrapper.lambda().eq(BillNumEntity::getVisualId, visualId);
|
||||
if (StringUtil.isNotEmpty(flowId)) {
|
||||
queryWrapper.lambda().eq(BillNumEntity::getFlowId, flowId);
|
||||
} else {
|
||||
queryWrapper.lambda().isNull(BillNumEntity::getFlowId);
|
||||
}
|
||||
this.remove(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
package com.yunzhupaas.base.service.impl;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.yunzhupaas.base.entity.FilterEntity;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.mapper.FilterMapper;
|
||||
import com.yunzhupaas.base.model.filter.RuleInfo;
|
||||
import com.yunzhupaas.base.service.FilterService;
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import com.yunzhupaas.base.util.OnlineFilterUtil;
|
||||
import com.yunzhupaas.database.util.DbTypeUtil;
|
||||
import com.yunzhupaas.database.util.DynamicDataSourceUtil;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import com.yunzhupaas.util.context.RequestContext;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.mybatis.dynamic.sql.AndOrCriteriaGroup;
|
||||
import org.mybatis.dynamic.sql.DerivedColumn;
|
||||
import org.mybatis.dynamic.sql.SqlBuilder;
|
||||
import org.mybatis.dynamic.sql.SqlTable;
|
||||
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
|
||||
import org.mybatis.dynamic.sql.select.SelectModel;
|
||||
import org.mybatis.dynamic.sql.where.WhereModel;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class FilterServiceImpl extends SuperServiceImpl<FilterMapper, FilterEntity> implements FilterService {
|
||||
|
||||
@Override
|
||||
public void saveRuleList(String moduleId, VisualdevEntity visualdevEntity, Integer app, Integer pc, Map<String, String> tableMap) {
|
||||
if (MapUtils.isEmpty(tableMap)) return;
|
||||
String columnData = visualdevEntity.getColumnData();
|
||||
String appColumnData = visualdevEntity.getAppColumnData();
|
||||
|
||||
if (columnData == null || columnData.length() == 0) {
|
||||
columnData = "{}";
|
||||
}
|
||||
if (appColumnData == null || appColumnData.length() == 0) {
|
||||
appColumnData = "{}";
|
||||
}
|
||||
Map config = JsonUtil.getJsonToBean(columnData, Map.class);
|
||||
String ruleList = JSONUtil.toJsonStr(config.get("ruleList"));
|
||||
Map configApp = JsonUtil.getJsonToBean(appColumnData, Map.class);
|
||||
String ruleListApp = JSONUtil.toJsonStr(configApp.get("ruleListApp"));
|
||||
FilterEntity entity = new FilterEntity();
|
||||
entity.setId(RandomUtil.uuId());
|
||||
entity.setModuleId(moduleId);
|
||||
replaceRealValue(app, pc, tableMap, ruleList, ruleListApp, entity);
|
||||
entity.setCreatorTime(new Date());
|
||||
entity.setLastModifyTime(new Date());
|
||||
this.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRuleList(String moduleId, VisualdevEntity visualdevEntity, Integer app, Integer pc, Map<String, String> tableMap) {
|
||||
if (MapUtils.isEmpty(tableMap)) return;
|
||||
String columnData = visualdevEntity.getColumnData();
|
||||
String appColumnData = visualdevEntity.getAppColumnData();
|
||||
if (columnData == null || columnData.length() == 0) {
|
||||
columnData = "{}";
|
||||
}
|
||||
if (appColumnData == null || appColumnData.length() == 0) {
|
||||
appColumnData = "{}";
|
||||
}
|
||||
|
||||
Map config = JsonUtil.getJsonToBean(columnData, Map.class);
|
||||
String ruleList = JSONUtil.toJsonStr(config.get("ruleList"));
|
||||
Map configApp = JsonUtil.getJsonToBean(appColumnData, Map.class);
|
||||
String ruleListApp = JSONUtil.toJsonStr(configApp.get("ruleListApp"));
|
||||
|
||||
List<FilterEntity> list = this.getBaseMapper()
|
||||
.selectList(new QueryWrapper<FilterEntity>().lambda().eq(FilterEntity::getModuleId, moduleId));
|
||||
if (list == null || list.size() == 0) {
|
||||
this.saveRuleList(moduleId, visualdevEntity, app, pc, tableMap);
|
||||
} else {
|
||||
FilterEntity entity = list.get(0);
|
||||
replaceRealValue(app, pc, tableMap, ruleList, ruleListApp, entity);
|
||||
entity.setLastModifyTime(new Date());
|
||||
this.updateById(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把子表的表名换成实际数据库表名
|
||||
*
|
||||
* @param app 是否更新app配置
|
||||
* @param pc 是否更新pc配置
|
||||
* @param tableMap 虚拟表名和实际表名映射
|
||||
* @param ruleList pc配置
|
||||
* @param ruleListApp app配置
|
||||
* @param entity 更新的数据
|
||||
*/
|
||||
private void replaceRealValue(Integer app, Integer pc, Map<String, String> tableMap, String ruleList, String ruleListApp, FilterEntity entity) {
|
||||
if (app == 1 && StringUtils.isNotBlank(ruleListApp)) {
|
||||
for (String key : tableMap.keySet()) {
|
||||
ruleListApp = ruleListApp.replaceAll(key, tableMap.get(key));
|
||||
}
|
||||
|
||||
entity.setConfigApp(ruleListApp);
|
||||
}
|
||||
if (pc == 1 && StringUtils.isNotBlank(ruleList)) {
|
||||
for (String key : tableMap.keySet()) {
|
||||
ruleList = ruleList.replaceAll(key, tableMap.get(key));
|
||||
}
|
||||
entity.setConfig(ruleList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleWhereCondition(SqlTable sqlTable, QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where, String id, Map<String, SqlTable> subSqlTableMap, String databaseProductName, Map<String, Object> params) {
|
||||
try {
|
||||
DynamicDataSourceUtil.switchToDataSource(null);
|
||||
List<RuleInfo> ruleInfos = this.getCondition(id);
|
||||
|
||||
QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder whereFilter = SqlBuilder.select(sqlTable.allColumns()).from(sqlTable).where();
|
||||
|
||||
for (int i = 0; i < ruleInfos.size(); i++) {
|
||||
RuleInfo info = ruleInfos.get(i);
|
||||
OnlineFilterUtil genUtil = JsonUtil.getJsonToBean(info, OnlineFilterUtil.class);
|
||||
genUtil.setDbType(DbTypeUtil.getDbEncodeByProductName(databaseProductName));
|
||||
genUtil.setSubSqlTableMap(subSqlTableMap);
|
||||
genUtil.setParams(params);
|
||||
genUtil.solveValue(whereFilter, sqlTable);
|
||||
}
|
||||
|
||||
Method method = whereFilter.getClass().getDeclaredMethod("buildWhereModel");
|
||||
method.setAccessible(true);
|
||||
WhereModel invoke = (WhereModel) method.invoke(whereFilter);
|
||||
List<AndOrCriteriaGroup> groupList = invoke.subCriteria();
|
||||
where.and(DerivedColumn.of("1"), SqlBuilder.isEqualTo(1), groupList);
|
||||
|
||||
|
||||
} catch (Exception ignored) {
|
||||
} finally {
|
||||
DynamicDataSourceUtil.clearSwitchDataSource();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 在线过滤查询
|
||||
*
|
||||
* @param sqlTable
|
||||
* @param where
|
||||
* @param id
|
||||
* @param subSqlTableMap
|
||||
* @param databaseProductName
|
||||
*/
|
||||
@Override
|
||||
public void handleWhereCondition(SqlTable sqlTable, QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where, String id, Map<String, SqlTable> subSqlTableMap, String databaseProductName) {
|
||||
this.handleWhereCondition(sqlTable, where, id, subSqlTableMap, databaseProductName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取过滤配置
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<RuleInfo> getCondition(String id) {
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
QueryWrapper<FilterEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(FilterEntity::getModuleId, id);
|
||||
FilterEntity entity = this.getOne(wrapper);
|
||||
// 获取app端还是web端
|
||||
String config;
|
||||
boolean isApp = !RequestContext.isOrignPc();
|
||||
if (isApp) {
|
||||
config = entity.getConfigApp();
|
||||
} else {
|
||||
config = entity.getConfig();
|
||||
}
|
||||
|
||||
List<RuleInfo> ruleInfos = new ArrayList<>();
|
||||
if (StringUtils.isNoneBlank(config)) {
|
||||
ruleInfos = JsonUtil.getJsonToList(config, RuleInfo.class);
|
||||
}
|
||||
|
||||
return ruleInfos;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.yunzhupaas.base.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.yunzhupaas.base.entity.FlowFormRelationEntity;
|
||||
import com.yunzhupaas.base.mapper.FlowFormRelationMapper;
|
||||
import com.yunzhupaas.base.service.FlowFormRelationService;
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 流程表单关联
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.2
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/6/30 18:01
|
||||
*/
|
||||
@Service
|
||||
public class FlowFormRelationServiceImpl extends SuperServiceImpl<FlowFormRelationMapper, FlowFormRelationEntity> implements FlowFormRelationService {
|
||||
|
||||
@Override
|
||||
public void saveFlowIdByFormIds(String flowId, List<String> formIds) {
|
||||
QueryWrapper<FlowFormRelationEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(FlowFormRelationEntity::getFlowId, flowId);
|
||||
List<FlowFormRelationEntity> list = this.list(queryWrapper);
|
||||
this.removeBatchByIds(list);
|
||||
if (CollectionUtils.isNotEmpty(formIds)) {
|
||||
for (String formId : formIds) {
|
||||
FlowFormRelationEntity entity = new FlowFormRelationEntity();
|
||||
entity.setFlowId(flowId);
|
||||
entity.setId(RandomUtil.uuId());
|
||||
entity.setFormId(formId);
|
||||
this.save(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FlowFormRelationEntity> getListByFormId(String formId) {
|
||||
QueryWrapper<FlowFormRelationEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(FlowFormRelationEntity::getFormId, formId);
|
||||
List<FlowFormRelationEntity> list = this.list(queryWrapper);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.yunzhupaas.base.service.impl;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.yunzhupaas.base.model.ai.VisualAiModel;
|
||||
import com.yunzhupaas.base.service.VisualAiService;
|
||||
import com.yunzhupaas.constant.GenerateConstant;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.constants.AiConstants;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.model.ai.AiFormFieldModel;
|
||||
import com.yunzhupaas.model.ai.AiFormModel;
|
||||
import com.yunzhupaas.service.OpenAiService;
|
||||
import com.yunzhupaas.util.AiLimitUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.UserProvider;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 在线开发ai实现
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v5.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/12/2 10:05:25
|
||||
*/
|
||||
@Service
|
||||
public class VisualAiServiceImpl implements VisualAiService {
|
||||
@Autowired
|
||||
private OpenAiService openAiService;
|
||||
|
||||
@Override
|
||||
public VisualAiModel form(String keyword) {
|
||||
if(!AiLimitUtil.tryAcquire(UserProvider.getUser().getUserId())){
|
||||
throw new DataException(MsgCode.SYS182.get());
|
||||
}
|
||||
VisualAiModel visualAiModel = new VisualAiModel();
|
||||
List<AiFormModel> aiModelList = new ArrayList<>();
|
||||
List<AiFormModel> list = openAiService.generatorModelVO(keyword);
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
AiFormModel aiFormModel = list.get(i);
|
||||
if (Objects.equals(0, i)) {
|
||||
String enCode = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, aiFormModel.getTableName());
|
||||
visualAiModel.setFullName(aiFormModel.getTableTitle());
|
||||
visualAiModel.setEnCode(enCode);
|
||||
aiFormModel.setIsMain(true);
|
||||
} else {
|
||||
aiFormModel.setIsMain(false);
|
||||
}
|
||||
List<AiFormFieldModel> fields = new ArrayList<>();
|
||||
List<AiFormFieldModel> fieldList = aiFormModel.getFields();
|
||||
if (CollectionUtils.isNotEmpty(fieldList)) {
|
||||
int index = 1;
|
||||
for (int j = 0; j < fieldList.size(); j++) {
|
||||
AiFormFieldModel aiFormFieldModel = fieldList.get(j);
|
||||
String fieldName = aiFormFieldModel.getFieldName();
|
||||
String yunzhupaasKey = aiFormFieldModel.getFieldComponent();
|
||||
if (containsChinese(fieldName) || GenerateConstant.containKeyword(fieldName)) {
|
||||
String formatIndex = String.format("%03d", index);
|
||||
String suffix = "_num" + formatIndex;
|
||||
aiFormFieldModel.setFieldName(yunzhupaasKey + suffix);
|
||||
index++;
|
||||
}
|
||||
List<String> yunzhupaasKeyList = new ArrayList<>();
|
||||
for (String s : AiConstants.GEN_MODEL_COMPNENT.split("-")) {
|
||||
if (StringUtil.isNotBlank(s)) yunzhupaasKeyList.add(s.trim());
|
||||
}
|
||||
if (!yunzhupaasKeyList.contains(yunzhupaasKey)) {
|
||||
aiFormFieldModel.setFieldComponent(YunzhupaasKeyConsts.COM_INPUT);
|
||||
}
|
||||
//子表控件处理
|
||||
if (!aiFormModel.getIsMain()) {
|
||||
//子表不能有单选框,多选框-调整成下拉框
|
||||
List<String> childNotRadio = new ArrayList<>();
|
||||
childNotRadio.add(YunzhupaasKeyConsts.RADIO);
|
||||
childNotRadio.add(YunzhupaasKeyConsts.CHECKBOX);
|
||||
//子表不能有的其他控件
|
||||
List<String> childNotOther = new ArrayList<>();
|
||||
childNotOther.add(YunzhupaasKeyConsts.TEXTAREA);
|
||||
childNotOther.add(YunzhupaasKeyConsts.LINK);
|
||||
childNotOther.add(YunzhupaasKeyConsts.BUTTON);
|
||||
childNotOther.add(YunzhupaasKeyConsts.ALERT);
|
||||
childNotOther.add(YunzhupaasKeyConsts.BARCODE);
|
||||
childNotOther.add(YunzhupaasKeyConsts.QR_CODE);
|
||||
childNotOther.add(YunzhupaasKeyConsts.EDITOR);
|
||||
if (childNotRadio.contains(yunzhupaasKey)) {
|
||||
aiFormFieldModel.setFieldComponent(YunzhupaasKeyConsts.SELECT);
|
||||
} else if (childNotOther.contains(yunzhupaasKey)) {
|
||||
aiFormFieldModel.setFieldComponent(YunzhupaasKeyConsts.COM_INPUT);
|
||||
}
|
||||
}
|
||||
|
||||
if (containsKeyWord(aiFormFieldModel.getFieldName())) {
|
||||
fields.add(aiFormFieldModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
aiFormModel.setFields(fields);
|
||||
aiModelList.add(aiFormModel);
|
||||
}
|
||||
}
|
||||
visualAiModel.setAiModelList(aiModelList);
|
||||
return visualAiModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否包含中文(字段空或者包含中文字段名称重命名)
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
private static boolean containsChinese(String str) {
|
||||
if (StringUtil.isEmpty(str)) return true;
|
||||
Pattern pattern = Pattern.compile("[\u4E00-\u9FA5]");
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
return matcher.find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段是否包含特定(用于过滤掉不要的字段如:以_fk结尾是外键,本系统内已自动生成外键)
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
private static boolean containsKeyWord(String str) {
|
||||
if (str.toLowerCase().endsWith("_fk")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
package com.yunzhupaas.base.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.yunzhupaas.base.entity.VisualAliasEntity;
|
||||
import com.yunzhupaas.base.entity.VisualdevReleaseEntity;
|
||||
import com.yunzhupaas.base.mapper.VisualAliasMapper;
|
||||
import com.yunzhupaas.base.model.VisualAliasForm;
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import com.yunzhupaas.base.service.VisualAliasService;
|
||||
import com.yunzhupaas.base.service.VisualdevReleaseService;
|
||||
import com.yunzhupaas.base.util.common.AliasModel;
|
||||
import com.yunzhupaas.constant.GenerateConstant;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.model.visualJson.TableFields;
|
||||
import com.yunzhupaas.model.visualJson.TableModel;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.UserProvider;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v5.0.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/4/13 14:05:48
|
||||
*/
|
||||
@Service
|
||||
public class VisualAliasServiceImpl extends SuperServiceImpl<VisualAliasMapper, VisualAliasEntity> implements VisualAliasService {
|
||||
@Autowired
|
||||
private VisualdevReleaseService visualdevReleaseService;
|
||||
|
||||
|
||||
@Override
|
||||
public List<VisualAliasEntity> getList(String visualId) {
|
||||
QueryWrapper<VisualAliasEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(VisualAliasEntity::getVisualId, visualId);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableModel> getAliasInfo(String id) {
|
||||
VisualdevReleaseEntity visualdevEntity = visualdevReleaseService.getById(id);
|
||||
List<TableModel> tableModels = JsonUtil.getJsonToList(visualdevEntity.getVisualTables(), TableModel.class);
|
||||
List<VisualAliasEntity> list = this.getList(id);
|
||||
for (TableModel tableModel : tableModels) {
|
||||
tableModel.setComment(tableModel.getTableName());
|
||||
VisualAliasEntity tableAlias = list.stream().filter(t -> tableModel.getTable().equals(t.getTableName()) && t.getFieldName() == null).findFirst().orElse(null);
|
||||
if (tableAlias != null) {
|
||||
tableModel.setAliasName(tableAlias.getAliasName());
|
||||
}
|
||||
List<TableFields> fields = tableModel.getFields();
|
||||
List<TableFields> newFields = fields.stream().filter(t -> !GenerateConstant.SYS_KEYWORD.contains(t.getField().toLowerCase())).collect(Collectors.toList());
|
||||
for (TableFields field : newFields) {
|
||||
VisualAliasEntity fieldAlias = list.stream().filter(t -> tableModel.getTable().equals(t.getTableName()) && t.getFieldName() != null
|
||||
&& field.getField().equals(t.getFieldName())).findFirst().orElse(null);
|
||||
if (fieldAlias != null) {
|
||||
field.setAliasName(fieldAlias.getAliasName());
|
||||
}
|
||||
}
|
||||
tableModel.setFields(newFields);
|
||||
}
|
||||
return tableModels;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void aliasSave(String id, VisualAliasForm form) {
|
||||
List<TableModel> tableList = form.getTableList();
|
||||
List<VisualAliasEntity> list = this.getList(id);
|
||||
List<String> tableNameList = new ArrayList<>();
|
||||
List<String> listKeyword = GenerateConstant.getAllKeyWord();
|
||||
String regex = "[a-zA-Z_][a-zA-Z0-9_]*";
|
||||
for (TableModel tableModel : tableList) {
|
||||
VisualAliasEntity tableAlias = list.stream().filter(t -> tableModel.getTable().equals(t.getTableName()) && t.getFieldName() == null).findFirst().orElse(null);
|
||||
if (StringUtil.isNotEmpty(tableModel.getAliasName())) {
|
||||
if (tableNameList.contains(tableModel.getAliasName())) {
|
||||
throw new DataException(tableModel.getAliasName() + MsgCode.VS018.get());
|
||||
} else {
|
||||
tableNameList.add(tableModel.getAliasName());
|
||||
}
|
||||
|
||||
if (listKeyword.contains(tableModel.getAliasName().toLowerCase())) {
|
||||
throw new DataException(MsgCode.SYS128.get(tableModel.getTable() + "-" + tableModel.getAliasName()));
|
||||
}
|
||||
|
||||
if (!tableModel.getAliasName().matches(regex)) {
|
||||
throw new DataException(MsgCode.VS021.get(tableModel.getTable()));
|
||||
}
|
||||
if (twoCharactesUpperCase(tableModel.getAliasName())) {
|
||||
throw new DataException(MsgCode.VS026.get());
|
||||
}
|
||||
if (tableAlias != null) {
|
||||
tableAlias.setAliasName(tableModel.getAliasName());
|
||||
} else {
|
||||
tableAlias = new VisualAliasEntity();
|
||||
tableAlias.setId(RandomUtil.uuId());
|
||||
tableAlias.setVisualId(id);
|
||||
tableAlias.setTableName(tableModel.getTable());
|
||||
tableAlias.setAliasName(tableModel.getAliasName());
|
||||
}
|
||||
this.saveOrUpdate(tableAlias);
|
||||
} else if (tableAlias != null) {
|
||||
this.removeById(tableAlias);
|
||||
}
|
||||
List<String> fieldNameList = new ArrayList<>();
|
||||
for (TableFields field : tableModel.getFields()) {
|
||||
VisualAliasEntity fieldAlias = list.stream().filter(t -> tableModel.getTable().equals(t.getTableName()) && t.getFieldName() != null
|
||||
&& field.getField().equals(t.getFieldName())).findFirst().orElse(null);
|
||||
if (StringUtil.isNotEmpty(field.getAliasName())) {
|
||||
if (listKeyword.contains(field.getAliasName().toLowerCase())) {
|
||||
throw new DataException(MsgCode.SYS128.get(field.getField() + "-" + field.getAliasName()));
|
||||
}
|
||||
if (!field.getAliasName().matches(regex)) {
|
||||
throw new DataException(MsgCode.VS021.get(field.getField()));
|
||||
}
|
||||
if (twoCharactesUpperCase(field.getAliasName())) {
|
||||
throw new DataException(MsgCode.VS026.get());
|
||||
}
|
||||
if (fieldNameList.contains(field.getAliasName())) {
|
||||
throw new DataException(field.getAliasName() + MsgCode.VS020.get());
|
||||
} else {
|
||||
fieldNameList.add(field.getAliasName());
|
||||
}
|
||||
if (fieldAlias != null) {
|
||||
fieldAlias.setAliasName(field.getAliasName());
|
||||
} else {
|
||||
fieldAlias = new VisualAliasEntity();
|
||||
fieldAlias.setId(RandomUtil.uuId());
|
||||
fieldAlias.setVisualId(id);
|
||||
fieldAlias.setTableName(tableModel.getTable());
|
||||
fieldAlias.setFieldName(field.getField());
|
||||
fieldAlias.setAliasName(field.getAliasName());
|
||||
}
|
||||
this.saveOrUpdate(fieldAlias);
|
||||
} else if (fieldAlias != null) {
|
||||
this.removeById(fieldAlias);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, AliasModel> getAllFiledsAlias(String id) {
|
||||
Map<String, AliasModel> tableMap = new HashMap<>();
|
||||
VisualdevReleaseEntity visualdevEntity = visualdevReleaseService.getById(id);
|
||||
List<TableModel> tableModels = JsonUtil.getJsonToList(visualdevEntity.getVisualTables(), TableModel.class);
|
||||
List<VisualAliasEntity> list = this.getList(id);
|
||||
for (TableModel tableModel : tableModels) {
|
||||
AliasModel aliasModel = new AliasModel();
|
||||
aliasModel.setTableName(tableModel.getTable());
|
||||
VisualAliasEntity tableAlias = list.stream().filter(t -> tableModel.getTable().equals(t.getTableName()) && t.getFieldName() == null).findFirst().orElse(null);
|
||||
if (tableAlias != null) {
|
||||
aliasModel.setAliasName(tableAlias.getAliasName());
|
||||
} else {
|
||||
aliasModel.setAliasName(tableModel.getTable());
|
||||
}
|
||||
List<TableFields> fields = tableModel.getFields();
|
||||
Map<String, String> fieldMap = new HashMap<>();
|
||||
for (TableFields field : fields) {
|
||||
VisualAliasEntity fieldAlias = list.stream().filter(t -> tableModel.getTable().equals(t.getTableName()) && t.getFieldName() != null
|
||||
&& field.getField().equals(t.getFieldName())).findFirst().orElse(null);
|
||||
if (fieldAlias != null) {
|
||||
fieldMap.put(field.getField(), fieldAlias.getAliasName());
|
||||
}
|
||||
//系统字段-以驼峰形式给别名
|
||||
else if (GenerateConstant.SYS_KEYWORD.contains(field.getField().toLowerCase())) {
|
||||
String name = field.getField().toLowerCase();
|
||||
name = name.startsWith("f_") ? name.substring(2) : name;
|
||||
String fieldAliasName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
|
||||
fieldMap.put(field.getField(), fieldAliasName);
|
||||
} else {
|
||||
String name = field.getField();
|
||||
String fieldAliasName = twoToLowerCase(name);
|
||||
fieldMap.put(field.getField(), fieldAliasName);
|
||||
}
|
||||
}
|
||||
aliasModel.setFieldsMap(fieldMap);
|
||||
tableMap.put(tableModel.getTable(), aliasModel);
|
||||
}
|
||||
return tableMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy(String visualId, String uuid) {
|
||||
List<VisualAliasEntity> list = this.getList(visualId);
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
for (VisualAliasEntity entity : list) {
|
||||
VisualAliasEntity copy = BeanUtil.copyProperties(entity, VisualAliasEntity.class);
|
||||
copyEntity(copy, uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyEntity(VisualAliasEntity copy, String visualId) {
|
||||
copy.setId(RandomUtil.uuId());
|
||||
copy.setVisualId(visualId);
|
||||
copy.setCreatorTime(new Date());
|
||||
copy.setCreatorUserId(UserProvider.getUser().getUserId());
|
||||
copy.setLastModifyUserId(null);
|
||||
copy.setLastModifyTime(null);
|
||||
this.save(copy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByVisualId(String visualId) {
|
||||
QueryWrapper<VisualAliasEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(VisualAliasEntity::getVisualId, visualId);
|
||||
this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断前两字母是否大写
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean twoCharactesUpperCase(String name) {
|
||||
if (StringUtil.isEmpty(name)) {
|
||||
return false;
|
||||
}
|
||||
if (name.length() == 1) {
|
||||
return Character.isUpperCase(name.charAt(0));
|
||||
}
|
||||
if (name.length() >= 2) {
|
||||
return Character.isUpperCase(name.charAt(0)) || Character.isUpperCase(name.charAt(1));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 两字母强制小写前
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String twoToLowerCase(String name) {
|
||||
if (StringUtil.isEmpty(name)) {
|
||||
return name;
|
||||
}
|
||||
name = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
|
||||
if (name.length() <= 2) {
|
||||
return name.toLowerCase();
|
||||
}
|
||||
if (name.length() > 2) {
|
||||
return name.substring(0, 2).toLowerCase() + name.substring(2);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.yunzhupaas.base.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.yunzhupaas.base.entity.VisualdevReleaseEntity;
|
||||
import com.yunzhupaas.base.mapper.VisualdevReleaseMapper;
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import com.yunzhupaas.base.service.VisualdevReleaseService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/3/16
|
||||
*/
|
||||
@Service
|
||||
public class VisualdevReleaseServiceImpl extends SuperServiceImpl<VisualdevReleaseMapper, VisualdevReleaseEntity> implements VisualdevReleaseService {
|
||||
|
||||
@Override
|
||||
public long beenReleased(String id) {
|
||||
QueryWrapper<VisualdevReleaseEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(VisualdevReleaseEntity::getId, id);
|
||||
return this.count(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VisualdevReleaseEntity> selectorList() {
|
||||
QueryWrapper<VisualdevReleaseEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().select(
|
||||
VisualdevReleaseEntity::getId,
|
||||
VisualdevReleaseEntity::getFullName,
|
||||
VisualdevReleaseEntity::getWebType,
|
||||
VisualdevReleaseEntity::getType,
|
||||
VisualdevReleaseEntity::getCategory);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VisualdevReleaseEntity> selectByIds(List<String> ids, SFunction<VisualdevReleaseEntity, ?>... columns) {
|
||||
QueryWrapper<VisualdevReleaseEntity> queryWrapper = new QueryWrapper<>();
|
||||
if (columns != null) {
|
||||
queryWrapper.lambda().select(columns);
|
||||
} else {
|
||||
queryWrapper.lambda().select(
|
||||
VisualdevReleaseEntity::getId,
|
||||
VisualdevReleaseEntity::getFullName,
|
||||
VisualdevReleaseEntity::getWebType,
|
||||
VisualdevReleaseEntity::getType,
|
||||
VisualdevReleaseEntity::getCategory);
|
||||
}
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,519 @@
|
||||
package com.yunzhupaas.base.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.entity.VisualdevReleaseEntity;
|
||||
import com.yunzhupaas.base.mapper.VisualdevMapper;
|
||||
import com.yunzhupaas.base.model.PaginationVisualdev;
|
||||
import com.yunzhupaas.base.model.dbtable.vo.DbFieldVO;
|
||||
import com.yunzhupaas.base.model.form.VisualTableModel;
|
||||
import com.yunzhupaas.base.service.*;
|
||||
import com.yunzhupaas.base.util.ConcurrencyUtils;
|
||||
import com.yunzhupaas.base.util.VisualDevTableCre;
|
||||
import com.yunzhupaas.base.util.VisualUtils;
|
||||
import com.yunzhupaas.constant.YunzhupaasConst;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.database.constant.DbAliasConst;
|
||||
import com.yunzhupaas.database.model.dbfield.DbFieldModel;
|
||||
import com.yunzhupaas.database.model.dbfield.base.DbFieldModelBase;
|
||||
import com.yunzhupaas.database.model.dbtable.DbTableFieldModel;
|
||||
import com.yunzhupaas.database.model.entity.DbLinkEntity;
|
||||
import com.yunzhupaas.database.util.DataSourceUtil;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.model.OnlineDevData;
|
||||
import com.yunzhupaas.model.visualJson.*;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormAllModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormEnum;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormMastTableModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.RecursionForm;
|
||||
import com.yunzhupaas.model.visualJson.config.ConfigModel;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.UserProvider;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/3/16
|
||||
*/
|
||||
@Service
|
||||
public class VisualdevServiceImpl extends SuperServiceImpl<VisualdevMapper, VisualdevEntity>
|
||||
implements VisualdevService {
|
||||
|
||||
@Autowired
|
||||
private VisualDevTableCre visualDevTableCreUtil;
|
||||
@Autowired
|
||||
private ConcurrencyUtils concurrencyUtils;
|
||||
@Autowired
|
||||
private DbTableServiceImpl dbTableService;
|
||||
@Autowired
|
||||
private DbLinkService dblinkService;
|
||||
@Autowired
|
||||
private DataSourceUtil dataSourceUtil;
|
||||
@Autowired
|
||||
private FilterService filterService;
|
||||
@Autowired
|
||||
private VisualdevReleaseService visualdevReleaseService;
|
||||
|
||||
@Override
|
||||
public List<VisualdevEntity> getList(PaginationVisualdev paginationVisualdev) {
|
||||
// 定义变量判断是否需要使用修改时间倒序
|
||||
boolean flag = false;
|
||||
QueryWrapper<VisualdevEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().select(VisualdevEntity::getId, VisualdevEntity::getCategory, VisualdevEntity::getEnCode,
|
||||
VisualdevEntity::getFullName,
|
||||
VisualdevEntity::getCreatorTime, VisualdevEntity::getCreatorUserId, VisualdevEntity::getLastModifyTime,
|
||||
VisualdevEntity::getLastModifyUserId,
|
||||
VisualdevEntity::getEnabledMark, VisualdevEntity::getSortCode, VisualdevEntity::getState,
|
||||
VisualdevEntity::getType,
|
||||
VisualdevEntity::getWebType, VisualdevEntity::getVisualTables, VisualdevEntity::getPlatformRelease);
|
||||
|
||||
if (!StringUtil.isEmpty(paginationVisualdev.getKeyword())) {
|
||||
flag = true;
|
||||
queryWrapper.lambda().and(t -> t.like(VisualdevEntity::getFullName, paginationVisualdev.getKeyword())
|
||||
.or().like(VisualdevEntity::getEnCode, paginationVisualdev.getKeyword()));
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotEmpty(paginationVisualdev.getType())) {
|
||||
queryWrapper.lambda().eq(VisualdevEntity::getType, paginationVisualdev.getType());
|
||||
}
|
||||
|
||||
if (StringUtil.isNotEmpty(paginationVisualdev.getCategory())) {
|
||||
flag = true;
|
||||
queryWrapper.lambda().eq(VisualdevEntity::getCategory, paginationVisualdev.getCategory());
|
||||
}
|
||||
|
||||
// ---功能类型查询
|
||||
if (paginationVisualdev.getWebType() != null) {// 普通表单
|
||||
flag = true;
|
||||
queryWrapper.lambda().eq(VisualdevEntity::getWebType, paginationVisualdev.getWebType());
|
||||
}
|
||||
|
||||
// 状态
|
||||
if (StringUtil.isNotEmpty(paginationVisualdev.getIsRelease())) {
|
||||
flag = true;
|
||||
List<String> releaseList = Arrays.asList(paginationVisualdev.getIsRelease().split(","));
|
||||
if (releaseList.size() > 1) {
|
||||
List<Integer> jsonToList = JsonUtil.getJsonToList(releaseList, Integer.class);
|
||||
queryWrapper.lambda().in(VisualdevEntity::getState, jsonToList);
|
||||
} else if (releaseList.size() == 1) {
|
||||
queryWrapper.lambda().eq(VisualdevEntity::getState, paginationVisualdev.getIsRelease());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 排序
|
||||
queryWrapper.lambda().orderByAsc(VisualdevEntity::getSortCode).orderByDesc(VisualdevEntity::getCreatorTime);
|
||||
if (flag) {
|
||||
queryWrapper.lambda().orderByDesc(VisualdevEntity::getLastModifyTime);
|
||||
}
|
||||
Page<VisualdevEntity> page = new Page<>(paginationVisualdev.getCurrentPage(),
|
||||
paginationVisualdev.getPageSize());
|
||||
IPage<VisualdevEntity> userPage = this.page(page, queryWrapper);
|
||||
return paginationVisualdev.setData(userPage.getRecords(), page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VisualdevEntity> getPageList(PaginationVisualdev paginationVisualdev) {
|
||||
QueryWrapper<VisualdevReleaseEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().select(
|
||||
VisualdevReleaseEntity::getId,
|
||||
VisualdevReleaseEntity::getFullName,
|
||||
VisualdevReleaseEntity::getType,
|
||||
VisualdevReleaseEntity::getEnCode);
|
||||
// 1-集成助手,查询列表, 2-流程表单查询,纯表单和列表
|
||||
if (paginationVisualdev.getWebType() != null) {
|
||||
List<Integer> webType = ImmutableList.of(1, 2, 4);
|
||||
if (Objects.equals(paginationVisualdev.getWebType(), 1)) {
|
||||
webType = ImmutableList.of(2);
|
||||
} else if (Objects.equals(paginationVisualdev.getWebType(), 2)) {
|
||||
webType = ImmutableList.of(1, 2);
|
||||
}
|
||||
queryWrapper.lambda().in(VisualdevReleaseEntity::getWebType, webType);
|
||||
}
|
||||
if (!StringUtil.isEmpty(paginationVisualdev.getKeyword())) {
|
||||
queryWrapper.lambda().like(VisualdevReleaseEntity::getFullName, paginationVisualdev.getKeyword());
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(paginationVisualdev.getType())) {
|
||||
queryWrapper.lambda().eq(VisualdevReleaseEntity::getType, paginationVisualdev.getType());
|
||||
}
|
||||
if (StringUtil.isNotEmpty(paginationVisualdev.getCategory())) {
|
||||
queryWrapper.lambda().eq(VisualdevReleaseEntity::getCategory, paginationVisualdev.getCategory());
|
||||
}
|
||||
// 排序
|
||||
queryWrapper.lambda().orderByAsc(VisualdevReleaseEntity::getSortCode)
|
||||
.orderByDesc(VisualdevReleaseEntity::getCreatorTime);
|
||||
Page<VisualdevReleaseEntity> page = new Page<>(paginationVisualdev.getCurrentPage(),
|
||||
paginationVisualdev.getPageSize());
|
||||
IPage<VisualdevReleaseEntity> userPage = visualdevReleaseService.page(page, queryWrapper);
|
||||
List<VisualdevEntity> list = JsonUtil.getJsonToList(userPage.getRecords(), VisualdevEntity.class);
|
||||
return paginationVisualdev.setData(list, page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VisualdevEntity> getList() {
|
||||
QueryWrapper<VisualdevEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().orderByAsc(VisualdevEntity::getSortCode).orderByDesc(VisualdevEntity::getCreatorTime);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisualdevEntity getInfo(String id) {
|
||||
if (StringUtil.isBlank(id))
|
||||
return null;
|
||||
QueryWrapper<VisualdevEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(VisualdevEntity::getId, id);
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisualdevEntity getReleaseInfo(String id) {
|
||||
VisualdevReleaseEntity visualdevReleaseEntity = visualdevReleaseService.getById(id);
|
||||
VisualdevEntity visualdevEntity = null;
|
||||
if (visualdevReleaseEntity != null) {
|
||||
visualdevEntity = JsonUtil.getJsonToBean(visualdevReleaseEntity, VisualdevEntity.class);
|
||||
}
|
||||
if (visualdevEntity == null) {
|
||||
visualdevEntity = getById(id);
|
||||
}
|
||||
return visualdevEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getTableMap(String formData) {
|
||||
Map<String, String> tableMap = new HashMap<>();
|
||||
if (StringUtil.isEmpty(formData)) {
|
||||
return tableMap;
|
||||
}
|
||||
FormDataModel formDataModel = JsonUtil.getJsonToBean(formData, FormDataModel.class);
|
||||
String fields = formDataModel.getFields();
|
||||
List<FieLdsModel> list = JsonUtil.getJsonToList(fields, FieLdsModel.class);
|
||||
list.forEach(item -> {
|
||||
this.solveTableName(item, tableMap);
|
||||
});
|
||||
return tableMap;
|
||||
}
|
||||
|
||||
private void solveTableName(FieLdsModel item, Map tableMap) {
|
||||
ConfigModel config = item.getConfig();
|
||||
if (config != null) {
|
||||
List<FieLdsModel> children = config.getChildren();
|
||||
if ("table".equals(config.getYunzhupaasKey())) {
|
||||
if (children != null && children.size() > 0) {
|
||||
FieLdsModel fieLdsModel = children.get(0);
|
||||
String parentVModel = item.getVModel();
|
||||
String relationTable = fieLdsModel.getConfig().getRelationTable();
|
||||
if (StringUtil.isNotBlank(relationTable)) {
|
||||
tableMap.put(parentVModel, relationTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (children != null) {
|
||||
children.forEach(item2 -> {
|
||||
this.solveTableName(item2, tableMap);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public Boolean create(VisualdevEntity entity) {
|
||||
if (StringUtil.isEmpty(entity.getId())) {
|
||||
entity.setId(RandomUtil.uuId());
|
||||
}
|
||||
if (OnlineDevData.FORM_TYPE_DEV.equals(entity.getType())) {
|
||||
FormDataModel formDataModel = JsonUtil.getJsonToBean(entity.getFormData(), FormDataModel.class);
|
||||
if (formDataModel != null) {
|
||||
// 是否开启安全锁
|
||||
int primaryKeyPolicy = formDataModel.getPrimaryKeyPolicy();
|
||||
|
||||
// 判断是否要创表
|
||||
List<TableModel> tableModels = JsonUtil.getJsonToList(entity.getVisualTables(), TableModel.class);
|
||||
// 有表
|
||||
if (tableModels.size() > 0) {
|
||||
Map<String, String> tableMap = this.getTableMap(entity.getFormData());
|
||||
// 保存app,pc过滤配置
|
||||
filterService.saveRuleList(entity.getId(), entity, 1, 1, tableMap);
|
||||
|
||||
for (TableModel tableModel : tableModels) {
|
||||
Boolean isAutoIncre = this.getPrimaryDbField(entity.getDbLinkId(), tableModel.getTable());
|
||||
// 1:雪花ID 2:自增ID
|
||||
if (primaryKeyPolicy == 1) {
|
||||
if (isAutoIncre != null && isAutoIncre) {
|
||||
throw new WorkFlowException(MsgCode.VS022.get(tableModel.getTable()));
|
||||
}
|
||||
} else if (primaryKeyPolicy == 2) {
|
||||
if (isAutoIncre == null || !isAutoIncre) {
|
||||
throw new WorkFlowException(MsgCode.VS023.get(tableModel.getTable()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
String tableJsonMap = addDbFileds(entity.getDbLinkId(), tableModels, formDataModel);
|
||||
if (StringUtil.isNotEmpty(tableJsonMap)) {
|
||||
entity.setVisualTables(tableJsonMap);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entity.setEnabledMark(0);
|
||||
entity.setState(0);
|
||||
entity.setCreatorTime(new Date());
|
||||
entity.setCreatorUserId(UserProvider.getLoginUserId());
|
||||
entity.setLastModifyTime(null);
|
||||
entity.setLastModifyUserId(null);
|
||||
this.setIgnoreLogicDelete().removeById(entity.getId());
|
||||
boolean result = this.setIgnoreLogicDelete().saveOrUpdate(entity);
|
||||
this.clearIgnoreLogicDelete();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库表,添加字段
|
||||
*
|
||||
* @param dbLinkId 数据链接id
|
||||
* @param visualTables 表列表
|
||||
* @param formDataModel 表单属性
|
||||
* @throws Exception
|
||||
*/
|
||||
private String addDbFileds(String dbLinkId, List<TableModel> visualTables, FormDataModel formDataModel)
|
||||
throws Exception {
|
||||
if (CollectionUtils.isEmpty(visualTables))
|
||||
return null;
|
||||
|
||||
List<Map<String, Object>> tableJsonMap = new ArrayList<>();
|
||||
Boolean concurrencyLock = formDataModel.getConcurrencyLock();
|
||||
Boolean logicalDelete = formDataModel.getLogicalDelete();
|
||||
// 在各个表创建多租户字段强
|
||||
for (TableModel tableModel : visualTables) {
|
||||
boolean isMainTable = tableModel.getTypeId().equals("1");
|
||||
List<DbFieldModel> dbFieldModelList = dbTableService.getFieldList(dbLinkId, tableModel.getTable());
|
||||
List<DbFieldModelBase> fieldList = JsonUtil.getJsonToList(dbFieldModelList, DbFieldModelBase.class);
|
||||
List<DbFieldModel> addList = new ArrayList<>();
|
||||
DbLinkEntity dbLink = dblinkService.getInfo(dbLinkId);
|
||||
String type = dbLink != null ? dbLink.getDbType() : dataSourceUtil.getDbType();
|
||||
concurrencyUtils.createTenantId(fieldList, type, addList);
|
||||
if (logicalDelete) {
|
||||
concurrencyUtils.creDeleteMark(fieldList, type, addList);
|
||||
}
|
||||
if (isMainTable && concurrencyLock) {
|
||||
concurrencyUtils.createVersion(fieldList, type, addList);
|
||||
}
|
||||
if (isMainTable) {
|
||||
// 流程字段强制生成
|
||||
concurrencyUtils.createFlowEngine(fieldList, type, addList);
|
||||
concurrencyUtils.createFlowTaskId(fieldList, type, addList);
|
||||
}
|
||||
concurrencyUtils.addFileds(tableModel.getTable(), dbLinkId, addList);
|
||||
List<DbFieldVO> voList = new ArrayList<>();
|
||||
List<DbFieldModelBase> listAll = new ArrayList<>();
|
||||
listAll.addAll(fieldList);
|
||||
listAll.addAll(addList);
|
||||
for (DbFieldModelBase item : listAll) {
|
||||
DbFieldVO tableFields = new DbFieldVO();
|
||||
tableFields.setField(item.getField());
|
||||
tableFields.setFieldName(item.getComment());
|
||||
tableFields.setDataType(item.getDataType());
|
||||
tableFields.setDataLength(item.getLength());
|
||||
tableFields.setPrimaryKey(DbAliasConst.PRIMARY_KEY.getNum(item.getIsPrimaryKey()));
|
||||
tableFields.setAllowNull(DbAliasConst.ALLOW_NULL.getNum(item.getNullSign()));
|
||||
tableFields.setAutoIncrement(DbAliasConst.AUTO_INCREMENT.getNum(item.getIsAutoIncrement()));
|
||||
tableFields.setIdentity(DbAliasConst.AUTO_INCREMENT.getNum(item.getIsAutoIncrement()));
|
||||
voList.add(tableFields);
|
||||
}
|
||||
Map<String, Object> stringObjectMap = JsonUtil.entityToMap(tableModel);
|
||||
stringObjectMap.put("fields", voList);
|
||||
tableJsonMap.add(stringObjectMap);
|
||||
}
|
||||
return JsonUtil.getObjectToString(tableJsonMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(String id, VisualdevEntity entity) throws Exception {
|
||||
entity.setId(id);
|
||||
entity.setLastModifyUserId(UserProvider.getUser().getUserId());
|
||||
if (OnlineDevData.FORM_TYPE_DEV.equals(entity.getType())) {
|
||||
// 代码生成修改时就要生成字段
|
||||
FormDataModel formDataModel = JsonUtil.getJsonToBean(entity.getFormData(), FormDataModel.class);
|
||||
if (formDataModel != null) {
|
||||
int primaryKeyPolicy = formDataModel.getPrimaryKeyPolicy();
|
||||
// 判断是否要创表
|
||||
List<TableModel> visualTables = JsonUtil.getJsonToList(entity.getVisualTables(), TableModel.class);
|
||||
// 有表
|
||||
if (visualTables.size() > 0) {
|
||||
if (formDataModel != null) {
|
||||
try {
|
||||
// 字段强制生成
|
||||
String tableJsonMap = addDbFileds(entity.getDbLinkId(), visualTables, formDataModel);
|
||||
if (StringUtil.isNotEmpty(tableJsonMap)) {
|
||||
entity.setVisualTables(tableJsonMap);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 判断自增是否匹配
|
||||
concurrencyUtils.checkAutoIncrement(primaryKeyPolicy, entity.getDbLinkId(), visualTables);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getObjByEncode(String encode, Integer type) {
|
||||
QueryWrapper<VisualdevEntity> visualWrapper = new QueryWrapper<>();
|
||||
visualWrapper.lambda().eq(VisualdevEntity::getEnCode, encode).eq(VisualdevEntity::getType, type);
|
||||
Integer count = (int) this.count(visualWrapper);
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCountByName(String name, Integer type) {
|
||||
QueryWrapper<VisualdevEntity> visualWrapper = new QueryWrapper<>();
|
||||
visualWrapper.lambda().eq(VisualdevEntity::getFullName, name).eq(VisualdevEntity::getType, type);
|
||||
Integer count = (int) this.count(visualWrapper);
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTable(VisualdevEntity entity) throws WorkFlowException {
|
||||
FormDataModel formDataModel = JsonUtil.getJsonToBean(entity.getFormData(), FormDataModel.class);
|
||||
// 是否开启安全锁
|
||||
Boolean concurrencyLock = formDataModel.getConcurrencyLock();
|
||||
int primaryKeyPolicy = formDataModel.getPrimaryKeyPolicy();
|
||||
Boolean logicalDelete = formDataModel.getLogicalDelete();
|
||||
|
||||
Map<String, Object> formMap = JsonUtil.stringToMap(entity.getFormData());
|
||||
List<FieLdsModel> list = JsonUtil.getJsonToList(formMap.get("fields"), FieLdsModel.class);
|
||||
JSONArray formJsonArray = JsonUtil.getJsonToJsonArray(String.valueOf(formMap.get("fields")));
|
||||
List<TableModel> visualTables = JsonUtil.getJsonToList(entity.getVisualTables(), TableModel.class);
|
||||
|
||||
List<FormAllModel> formAllModel = new ArrayList<>();
|
||||
RecursionForm recursionForm = new RecursionForm();
|
||||
recursionForm.setTableModelList(visualTables);
|
||||
recursionForm.setList(list);
|
||||
FormCloumnUtil.recursionForm(recursionForm, formAllModel);
|
||||
|
||||
String tableName = "mt" + RandomUtil.uuId();
|
||||
|
||||
String dbLinkId = entity.getDbLinkId();
|
||||
VisualTableModel model = new VisualTableModel(formJsonArray, formAllModel, tableName, dbLinkId,
|
||||
entity.getFullName(), concurrencyLock, primaryKeyPolicy, logicalDelete);
|
||||
List<TableModel> tableModelList = visualDevTableCreUtil.tableList(model);
|
||||
formMap.put("fields", formJsonArray);
|
||||
// 更新
|
||||
entity.setFormData(JsonUtil.getObjectToString(formMap));
|
||||
entity.setVisualTables(JsonUtil.getObjectToString(tableModelList));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getPrimaryDbField(String linkId, String table) throws Exception {
|
||||
DbTableFieldModel dbTableModel = dbTableService.getDbTableModel(linkId, table);
|
||||
List<DbFieldModel> data = dbTableModel.getDbFieldModelList();
|
||||
DbFieldModel dbFieldModel = data.stream().filter(DbFieldModel::getIsPrimaryKey).findFirst().orElse(null);
|
||||
if (dbFieldModel != null) {
|
||||
return dbFieldModel.getIsAutoIncrement() != null && dbFieldModel.getIsAutoIncrement();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VisualdevEntity> selectorList() {
|
||||
QueryWrapper<VisualdevEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().select(
|
||||
VisualdevEntity::getId,
|
||||
VisualdevEntity::getFullName,
|
||||
VisualdevEntity::getWebType,
|
||||
VisualdevEntity::getType,
|
||||
VisualdevEntity::getCategory);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableFields> storedFieldList(VisualdevEntity entity) {
|
||||
List<TableFields> resultList = new ArrayList<>();
|
||||
if (entity != null) {
|
||||
// 是否存在关联数据库
|
||||
try {
|
||||
DbLinkEntity linkEntity = null;
|
||||
if (StringUtil.isNotEmpty(entity.getDbLinkId())) {
|
||||
linkEntity = dblinkService.getInfo(entity.getDbLinkId());
|
||||
}
|
||||
// 获取主表
|
||||
List<TableModel> listTable = JsonUtil.getJsonToList(entity.getVisualTables(), TableModel.class);
|
||||
String mainTable = listTable.stream().filter(t -> "1".equals(t.getTypeId())).findFirst().orElse(null)
|
||||
.getTable();
|
||||
// 获取主键
|
||||
String pKeyName = VisualUtils.getpKey(linkEntity, mainTable);
|
||||
resultList.add(new TableFields(pKeyName, "表单主键"));
|
||||
FormDataModel formData = JsonUtil.getJsonToBean(entity.getFormData(), FormDataModel.class);
|
||||
List<FieLdsModel> list = JsonUtil.getJsonToList(formData.getFields(), FieLdsModel.class);
|
||||
List<FormAllModel> formAllModel = new ArrayList<>();
|
||||
RecursionForm recursionForm = new RecursionForm();
|
||||
recursionForm.setTableModelList(JsonUtil.getJsonToList(entity.getVisualTables(), TableModel.class));
|
||||
recursionForm.setList(list);
|
||||
FormCloumnUtil.recursionForm(recursionForm, formAllModel);
|
||||
List<FormAllModel> mast = formAllModel.stream()
|
||||
.filter(t -> FormEnum.mast.getMessage().equals(t.getYunzhupaasKey()))
|
||||
.collect(Collectors.toList());
|
||||
// 列表子表数据
|
||||
List<FormAllModel> mastTable = formAllModel.stream()
|
||||
.filter(t -> FormEnum.mastTable.getMessage().equals(t.getYunzhupaasKey()))
|
||||
.collect(Collectors.toList());
|
||||
for (FormAllModel item : mast) {
|
||||
FieLdsModel fieLdsModel = item.getFormColumnModel().getFieLdsModel();
|
||||
addField(fieLdsModel.getVModel(), fieLdsModel, resultList);
|
||||
}
|
||||
for (FormAllModel item : mastTable) {
|
||||
FormMastTableModel formMastTableModel = item.getFormMastTableModel();
|
||||
FieLdsModel fieLdsModel = formMastTableModel.getMastTable().getFieLdsModel();
|
||||
addField(formMastTableModel.getVModel(), fieLdsModel, resultList);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加字段(统一过滤条件)
|
||||
*
|
||||
* @param realVmodel
|
||||
* @param fieLdsModel
|
||||
* @param resultList
|
||||
*/
|
||||
private static void addField(String realVmodel, FieLdsModel fieLdsModel, List<TableFields> resultList) {
|
||||
List<String> list = Arrays.asList(YunzhupaasKeyConsts.COM_INPUT, YunzhupaasKeyConsts.BILLRULE);
|
||||
if (StringUtil.isNotEmpty(fieLdsModel.getVModel())
|
||||
&& list.contains(fieLdsModel.getConfig().getYunzhupaasKey())) {
|
||||
resultList.add(new TableFields(realVmodel + YunzhupaasConst.FIELD_SUFFIX_YUNZHUPAASID,
|
||||
fieLdsModel.getConfig().getLabel()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.yunzhupaas.base.service.impl;
|
||||
|
||||
import com.yunzhupaas.base.entity.VisualdevShortLinkEntity;
|
||||
import com.yunzhupaas.base.mapper.VisualdevShortLinkMapper;
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import com.yunzhupaas.base.service.VisualdevShortLinkService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 在线表单外链service实现
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.2
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/12/30 11:31:45
|
||||
*/
|
||||
@Service
|
||||
public class VisualdevShortLinkServiceImpl extends SuperServiceImpl<VisualdevShortLinkMapper, VisualdevShortLinkEntity> implements VisualdevShortLinkService {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.database.model.dbfield.DbFieldModel;
|
||||
import com.yunzhupaas.database.model.dbfield.base.DbFieldModelBase;
|
||||
import com.yunzhupaas.database.model.dbtable.DbTableFieldModel;
|
||||
import com.yunzhupaas.database.source.DbBase;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.model.visualJson.TableModel;
|
||||
import com.yunzhupaas.util.TableFeildsEnum;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ConcurrencyUtils {
|
||||
|
||||
@Autowired
|
||||
private ServiceBaseUtil serviceUtil;
|
||||
|
||||
/**
|
||||
* 根据枚举获取字段对象
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/1/14
|
||||
*/
|
||||
public static DbFieldModel getDbFieldModel(TableFeildsEnum tableFeildsEnum, boolean isUpperCase, boolean isLowerCase) {
|
||||
DbFieldModel dbFieldModel = new DbFieldModel();
|
||||
BeanUtil.copyProperties(tableFeildsEnum, dbFieldModel);
|
||||
String field = dbFieldModel.getField();
|
||||
field = isUpperCase ? field.toUpperCase() : isLowerCase ? field.toLowerCase() : field;
|
||||
dbFieldModel.setField(field);
|
||||
dbFieldModel.setIsPrimaryKey(tableFeildsEnum.getPrimaryKey());
|
||||
//设置租户字段默认值
|
||||
if (TableFeildsEnum.TENANTID.equals(tableFeildsEnum)) {
|
||||
dbFieldModel.setDefaultValue("0");
|
||||
}
|
||||
return dbFieldModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建锁字段
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void createVersion(List<DbFieldModelBase> fieldList, String type, List<DbFieldModel> addList) {
|
||||
addFeild(TableFeildsEnum.VERSION, fieldList, type, addList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建flowTaskId
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void createFlowTaskId(List<DbFieldModelBase> fieldList, String type, List<DbFieldModel> addList) {
|
||||
addFeild(TableFeildsEnum.FLOWTASKID, fieldList, type, addList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建租户id
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void createTenantId(List<DbFieldModelBase> fieldList, String type, List<DbFieldModel> addList) {
|
||||
addFeild(TableFeildsEnum.TENANTID, fieldList, type, addList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建删除字段
|
||||
*
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/1/14
|
||||
*/
|
||||
public void creDeleteMark(List<DbFieldModelBase> fieldList, String type, List<DbFieldModel> addList) {
|
||||
addFeild(TableFeildsEnum.DELETEMARK, fieldList, type, addList);
|
||||
addFeild(TableFeildsEnum.DELETETIME, fieldList, type, addList);
|
||||
addFeild(TableFeildsEnum.DELETEUSERID, fieldList, type, addList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建流程引擎id字段
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/1/7
|
||||
*/
|
||||
public void createFlowEngine(List<DbFieldModelBase> fieldList, String type, List<DbFieldModel> addList) {
|
||||
addFeild(TableFeildsEnum.FLOWID, fieldList, type, addList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增字段通用方法
|
||||
*
|
||||
* @param tableFeildsEnum
|
||||
* @throws Exception
|
||||
*/
|
||||
private void addFeild(TableFeildsEnum tableFeildsEnum, List<DbFieldModelBase> fieldList, String type, List<DbFieldModel> fieldOneList) {
|
||||
boolean isUpperCase = (DbBase.DM.equals(type) || DbBase.ORACLE.equals(type));
|
||||
boolean isLowerCase = (DbBase.POSTGRE_SQL.equals(type) || DbBase.KINGBASE_ES.equals(type));
|
||||
DbFieldModelBase dbFieldModel = fieldList.stream().filter(f -> f.getField().equalsIgnoreCase(tableFeildsEnum.getField())).findFirst().orElse(null);
|
||||
boolean hasVersion = dbFieldModel != null;
|
||||
if (!hasVersion) {
|
||||
DbFieldModel dbTableModel1 = this.getDbFieldModel(tableFeildsEnum, isUpperCase, isLowerCase);
|
||||
fieldOneList.add(dbTableModel1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断表是否是自增id
|
||||
*
|
||||
* @param primaryKeyPolicy
|
||||
* @param dbLinkId
|
||||
* @param tableList
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean checkAutoIncrement(int primaryKeyPolicy, String dbLinkId, List<TableModel> tableList) throws Exception {
|
||||
boolean isIncre = primaryKeyPolicy == 2;
|
||||
String strategy = primaryKeyPolicy == 1 ? "[雪花ID]" : "[自增长id]";
|
||||
for (TableModel tableModel : tableList) {
|
||||
List<DbFieldModel> data = serviceUtil.getFieldList(dbLinkId, tableModel.getTable());
|
||||
DbFieldModel dbFieldModel = data.stream().filter(DbFieldModel::getIsPrimaryKey).findFirst().orElse(null);
|
||||
if (dbFieldModel == null) {
|
||||
throw new WorkFlowException(MsgCode.FM011.get(tableModel.getTable()));
|
||||
}
|
||||
if (!isIncre == (dbFieldModel.getIsAutoIncrement() != null && dbFieldModel.getIsAutoIncrement())) {
|
||||
throw new WorkFlowException(MsgCode.FM012.get(strategy, tableModel.getTable()));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行字段添加
|
||||
* @param table
|
||||
* @param linkId
|
||||
* @param addList
|
||||
* @throws Exception
|
||||
*/
|
||||
public void addFileds(String table, String linkId, List<DbFieldModel> addList) throws Exception {
|
||||
if (CollectionUtils.isNotEmpty(addList)) {
|
||||
DbTableFieldModel dbTableFieldModel = new DbTableFieldModel();
|
||||
dbTableFieldModel.setDbFieldModelList(addList);
|
||||
dbTableFieldModel.setUpdateNewTable(table);
|
||||
dbTableFieldModel.setUpdateOldTable(table);
|
||||
dbTableFieldModel.setDbLinkId(linkId);
|
||||
serviceUtil.addField(dbTableFieldModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.yunzhupaas.util.DateUtil;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 时间格式 常量
|
||||
*/
|
||||
public class DateTimeFormatConstant {
|
||||
public static String YEAR = "yyyy";
|
||||
public static String YEAR_MOnTH = "yyyy-MM";
|
||||
public static String YEAR_MOnTH_DATE = "yyyy-MM-dd";
|
||||
public static String YEAR_MOnTH_DHM = "yyyy-MM-dd HH:mm";
|
||||
public static String YEAR_MOnTH_DHMS = "yyyy-MM-dd HH:mm:ss";
|
||||
public static String HOUR_MINUTE = "HH:mm";
|
||||
public static String HOUR_MINUTE_SECOND = "HH:mm:ss";
|
||||
|
||||
/**
|
||||
* 时间格式忽略大小写
|
||||
*
|
||||
* @param otherFormat
|
||||
* @return 返回固定格式
|
||||
*/
|
||||
public static String getFormat(String otherFormat) {
|
||||
if (YEAR.equalsIgnoreCase(otherFormat)) {
|
||||
return YEAR;
|
||||
}
|
||||
if (YEAR_MOnTH.equalsIgnoreCase(otherFormat)) {
|
||||
return YEAR_MOnTH;
|
||||
}
|
||||
if (YEAR_MOnTH_DATE.equalsIgnoreCase(otherFormat)) {
|
||||
return YEAR_MOnTH_DATE;
|
||||
}
|
||||
if (YEAR_MOnTH_DHM.equalsIgnoreCase(otherFormat)) {
|
||||
return YEAR_MOnTH_DHM;
|
||||
}
|
||||
if (YEAR_MOnTH_DHMS.equalsIgnoreCase(otherFormat)) {
|
||||
return YEAR_MOnTH_DHMS;
|
||||
}
|
||||
if (HOUR_MINUTE.equalsIgnoreCase(otherFormat)) {
|
||||
return HOUR_MINUTE;
|
||||
}
|
||||
if (HOUR_MINUTE_SECOND.equalsIgnoreCase(otherFormat)) {
|
||||
return HOUR_MINUTE_SECOND;
|
||||
}
|
||||
return otherFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据库查询时间字段-转换成long
|
||||
* 不同数据库查询结果的对象不同
|
||||
*
|
||||
* @param dateObj
|
||||
* @return long
|
||||
*/
|
||||
public static Long getDateObjToLong(Object dateObj) {
|
||||
LocalDateTime dateTime = null;
|
||||
if (ObjectUtil.isNotEmpty(dateObj)) {
|
||||
if (dateObj instanceof LocalDateTime) {
|
||||
dateTime = (LocalDateTime) dateObj;
|
||||
} else if (dateObj instanceof Timestamp) {
|
||||
dateTime = ((Timestamp) dateObj).toLocalDateTime();
|
||||
} else if (dateObj instanceof Long) {
|
||||
dateTime = LocalDateTimeUtil.of(new Date(Long.parseLong(dateObj.toString())));
|
||||
} else {
|
||||
dateTime = LocalDateTimeUtil.of(cn.hutool.core.date.DateUtil.parse(dateObj.toString()));
|
||||
}
|
||||
}
|
||||
return dateTime != null ? DateUtil.localDateTime2Millis(dateTime) : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,121 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.ActionResultCode;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.ServletUtil;
|
||||
import com.yunzhupaas.util.wxutil.HttpUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 流程表单 http请求处理表单
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.5
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/10/21
|
||||
*/
|
||||
@Component
|
||||
public class FlowFormHttpReqUtils {
|
||||
|
||||
private static ConfigValueUtil configValueUtil;
|
||||
|
||||
@Autowired
|
||||
public void setConfigValueUtil(ConfigValueUtil configValueUtil) {
|
||||
FlowFormHttpReqUtils.configValueUtil = configValueUtil;
|
||||
}
|
||||
|
||||
public Map<String, Object> info(VisualdevEntity visualdevEntity, String id, String token) {
|
||||
String requestURL = this.getReqURL(visualdevEntity, id);
|
||||
JSONObject jsonObject = HttpUtil.httpRequest(requestURL, "GET", null, token);
|
||||
ActionResult actionResult = JSON.toJavaObject(jsonObject, ActionResult.class);
|
||||
if (actionResult == null) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
Object data = actionResult.getData();
|
||||
return data != null ? JsonUtil.entityToMap(data) : new HashMap<>();
|
||||
}
|
||||
|
||||
public boolean isUpdate(VisualdevEntity visualdevEntity, String id, String token) {
|
||||
String requestURL = this.getReqURL(visualdevEntity, id);
|
||||
JSONObject jsonObject = HttpUtil.httpRequest(requestURL, "GET", null, token);
|
||||
ActionResult actionResult = JSON.toJavaObject(jsonObject, ActionResult.class);
|
||||
return actionResult != null && actionResult.getData() != null;
|
||||
}
|
||||
|
||||
public void create(VisualdevEntity visualdevEntity, String id, String token, Map<String, Object> map) throws WorkFlowException {
|
||||
String requestURL = this.getReqURL(visualdevEntity, id);
|
||||
map.remove("id");
|
||||
JSONObject jsonObject = HttpUtil.httpRequest(requestURL, "POST", JsonUtil.getObjectToString(map), token);
|
||||
ActionResult actionResult = JSON.toJavaObject(jsonObject, ActionResult.class);
|
||||
boolean b = actionResult != null && ActionResultCode.Success.getCode().equals(actionResult.getCode());
|
||||
if (!b) {
|
||||
String msg = actionResult != null ? actionResult.getMsg() : MsgCode.FM001.get();
|
||||
throw new WorkFlowException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(VisualdevEntity visualdevEntity, String id, String token, Map<String, Object> map) throws WorkFlowException {
|
||||
String requestURL = this.getReqURL(visualdevEntity, id);
|
||||
JSONObject jsonObject = HttpUtil.httpRequest(requestURL, "PUT", JsonUtil.getObjectToString(map), token);
|
||||
ActionResult actionResult = JSON.toJavaObject(jsonObject, ActionResult.class);
|
||||
boolean b = actionResult != null && ActionResultCode.Success.getCode().equals(actionResult.getCode());
|
||||
if (!b) {
|
||||
String msg = actionResult != null ? actionResult.getMsg() : MsgCode.FM001.get();
|
||||
throw new WorkFlowException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveOrUpdate(VisualdevEntity visualdevEntity, String id, String token, Map<String, Object> map) throws WorkFlowException {
|
||||
boolean update = this.isUpdate(visualdevEntity, id, token);
|
||||
if (update) {
|
||||
this.update(visualdevEntity, id, token, map);
|
||||
} else {
|
||||
this.create(visualdevEntity, id, token, map);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getReqURL(VisualdevEntity visualdevEntity, String id) {
|
||||
HttpServletRequest request = ServletUtil.getRequest();
|
||||
//请求来源
|
||||
String requestURL = visualdevEntity.getInterfaceUrl();
|
||||
boolean isHttp = requestURL.toLowerCase().startsWith("http");
|
||||
if (!isHttp) {
|
||||
//补全(内部)
|
||||
requestURL = configValueUtil.getApiDomain() + requestURL;
|
||||
}
|
||||
return requestURL + "/" + id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param visualdevEntity
|
||||
* @param id
|
||||
* @param token
|
||||
* @throws WorkFlowException
|
||||
*/
|
||||
public void delete(VisualdevEntity visualdevEntity, String id, String token) throws WorkFlowException {
|
||||
String requestURL = this.getReqURL(visualdevEntity, id) + "?forceDel=true";
|
||||
JSONObject jsonObject = HttpUtil.httpRequest(requestURL, "DELETE", null, token);
|
||||
ActionResult actionResult = JSON.toJavaObject(jsonObject, ActionResult.class);
|
||||
boolean b = actionResult != null && ActionResultCode.Success.getCode().equals(actionResult.getCode());
|
||||
if (!b) {
|
||||
String msg = actionResult != null ? actionResult.getMsg() : MsgCode.FM001.get();
|
||||
throw new WorkFlowException(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,482 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.mapper.FlowFormDataMapper;
|
||||
import com.yunzhupaas.base.model.CheckFormModel;
|
||||
import com.yunzhupaas.base.model.ColumnDataModel;
|
||||
import com.yunzhupaas.base.model.OnlineImport.ImportDataModel;
|
||||
import com.yunzhupaas.base.model.OnlineImport.ImportFormCheckUniqueModel;
|
||||
import com.yunzhupaas.base.model.VisualConst;
|
||||
import com.yunzhupaas.base.model.form.FormCheckModel;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.database.model.entity.DbLinkEntity;
|
||||
import com.yunzhupaas.database.util.ConnUtil;
|
||||
import com.yunzhupaas.database.util.DynamicDataSourceUtil;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.i18n.util.I18nUtil;
|
||||
import com.yunzhupaas.model.visualJson.FieLdsModel;
|
||||
import com.yunzhupaas.model.visualJson.FormDataModel;
|
||||
import com.yunzhupaas.model.visualJson.TableFields;
|
||||
import com.yunzhupaas.model.visualJson.TableModel;
|
||||
import com.yunzhupaas.model.visualJson.config.ConfigModel;
|
||||
import com.yunzhupaas.onlinedev.model.VisualErrInfo;
|
||||
import com.yunzhupaas.util.FlowFormConstant;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.TableFeildsEnum;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
import lombok.Cleanup;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.mybatis.dynamic.sql.AndOrCriteriaGroup;
|
||||
import org.mybatis.dynamic.sql.BasicColumn;
|
||||
import org.mybatis.dynamic.sql.SqlBuilder;
|
||||
import org.mybatis.dynamic.sql.SqlTable;
|
||||
import org.mybatis.dynamic.sql.render.RenderingStrategies;
|
||||
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
|
||||
import org.mybatis.dynamic.sql.select.SelectModel;
|
||||
import org.mybatis.dynamic.sql.select.join.EqualTo;
|
||||
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 验证表单数据
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.2
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/5/25
|
||||
*/
|
||||
@Component
|
||||
public class FormCheckUtils {
|
||||
public static final List<String> LINK_ALLOW_KEY = Arrays.asList("alert", "card", "collapse", "collapseItem",
|
||||
"colorPicker", "datePicker", "divider", "editor",
|
||||
"groupTitle", "iframe", "input", "inputNumber", "link", "location", "rate", "row", "slider", "stepItem",
|
||||
"steps", "switch", "tab", "tabItem", "table", "tableGrid",
|
||||
"tableGridTd", "tableGridTr", "text", "textarea", "timePicker");
|
||||
@Autowired
|
||||
private FlowFormDataUtil flowDataUtil;
|
||||
@Autowired
|
||||
private FlowFormDataMapper flowFormDataMapper;
|
||||
|
||||
public String checkForm(CheckFormModel checkFormModel) {
|
||||
List<FieLdsModel> formFieldList = checkFormModel.getFormFieldList();
|
||||
Map<String, Object> dataMap = checkFormModel.getDataMap();
|
||||
DbLinkEntity linkEntity = checkFormModel.getLinkEntity();
|
||||
List<TableModel> tableModelList = checkFormModel.getTableModelList();
|
||||
VisualdevEntity visualdevEntity = checkFormModel.getVisualdevEntity();
|
||||
String id = checkFormModel.getId();
|
||||
Boolean isTransfer = checkFormModel.getIsTransfer();
|
||||
|
||||
FormDataModel formData = JsonUtil.getJsonToBean(visualdevEntity.getFormData(), FormDataModel.class);
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(visualdevEntity.getColumnData(),
|
||||
ColumnDataModel.class);
|
||||
boolean inlineEdit = columnDataModel != null && columnDataModel.getType() != null
|
||||
&& columnDataModel.getType() == 4;
|
||||
boolean logicalDelete = formData.getLogicalDelete();
|
||||
|
||||
List<FieLdsModel> fields = new ArrayList<>();
|
||||
FormPublicUtils.recursionFieldsExceptChild(fields, formFieldList);
|
||||
try {
|
||||
// 切换数据源
|
||||
DynamicDataSourceUtil.switchToDataSource(linkEntity);
|
||||
@Cleanup
|
||||
Connection conn = ConnUtil.getConnOrDefault(linkEntity);
|
||||
String dbType = conn.getMetaData().getDatabaseProductName().trim();
|
||||
// 业务主键判断
|
||||
VisualErrInfo visualErrInfo = this.checkBusinessKey(fields, dataMap, tableModelList, formData, id);
|
||||
if (ObjectUtil.isNotEmpty(visualErrInfo) && StringUtil.isNotEmpty(visualErrInfo.getErrMsg())) {
|
||||
return visualErrInfo.getErrMsg();
|
||||
}
|
||||
// 唯一和非空判断
|
||||
List<FormCheckModel> formCheckModels = new ArrayList<>();
|
||||
for (FieLdsModel fieLdsModel : fields) {
|
||||
ConfigModel config = fieLdsModel.getConfig();
|
||||
if (checkFormModel.getIsLink() && !LINK_ALLOW_KEY.contains(config.getYunzhupaasKey())) {
|
||||
continue;
|
||||
}
|
||||
Object o = dataMap.get(fieLdsModel.getVModel());
|
||||
if (config.isRequired() && !inlineEdit && !isTransfer) {
|
||||
if (ObjectUtil.isEmpty(o) || StringUtil.isEmpty(o.toString().trim())) {
|
||||
return I18nUtil.getMessageStr(config.getLabelI18nCode(), config.getLabel())
|
||||
+ MsgCode.VS015.get();
|
||||
}
|
||||
}
|
||||
if (YunzhupaasKeyConsts.COM_INPUT.equals(config.getYunzhupaasKey()) && config.getUnique()) {
|
||||
o = ObjectUtil.isEmpty(o) ? null : String.valueOf(o).trim();
|
||||
dataMap.put(fieLdsModel.getVModel(), o);
|
||||
String tableName = fieLdsModel.getConfig().getTableName();
|
||||
// 验证唯一
|
||||
SqlTable sqlTable = SqlTable.of(tableName);
|
||||
String key = flowDataUtil.getTableKey(conn, tableName);
|
||||
String vModelThis = fieLdsModel.getVModel();
|
||||
|
||||
String foriegKey = "";
|
||||
String columnName = "";
|
||||
boolean isMain = true;
|
||||
TableModel mainTableModel = new TableModel();
|
||||
TableModel tableModel = new TableModel();
|
||||
for (TableModel item : tableModelList) {
|
||||
if (Objects.equals(item.getTypeId(), "1")) {
|
||||
mainTableModel = item;
|
||||
}
|
||||
|
||||
if (StringUtil.isNotEmpty(fieLdsModel.getConfig().getRelationTable())) {
|
||||
// 子表判断
|
||||
if (fieLdsModel.getConfig().getRelationTable().equals(item.getTable())) {
|
||||
tableModel = item;
|
||||
}
|
||||
} else {
|
||||
// 主副表判断
|
||||
if (fieLdsModel.getConfig().getTableName().equals(item.getTable())) {
|
||||
tableModel = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tableModel != null) {
|
||||
String fieldName = vModelThis;
|
||||
if (!"1".equals(tableModel.getTypeId()) && vModelThis.contains("_yunzhupaas_")) {
|
||||
fieldName = vModelThis.split("_yunzhupaas_")[1];
|
||||
isMain = false;
|
||||
foriegKey = tableModel.getTableField();
|
||||
}
|
||||
String finalFieldName = fieldName;
|
||||
TableFields tableFields = tableModel.getFields().stream()
|
||||
.filter(t -> t.getField().equals(finalFieldName)).findFirst().orElse(null);
|
||||
if (tableFields != null) {
|
||||
columnName = StringUtil.isNotEmpty(tableFields.getField()) ? tableFields.getField()
|
||||
: fieldName;
|
||||
}
|
||||
}
|
||||
|
||||
List<BasicColumn> selectKey = new ArrayList<>();
|
||||
selectKey.add(sqlTable.column(columnName));
|
||||
selectKey.add(sqlTable.column(key));
|
||||
if (StringUtil.isNotEmpty(foriegKey)) {
|
||||
String finalForiegKey = foriegKey;
|
||||
TableFields tableFields = tableModel.getFields().stream()
|
||||
.filter(t -> t.getField().equals(finalForiegKey)).findFirst().orElse(null);
|
||||
if (tableFields != null) {
|
||||
foriegKey = StringUtil.isNotEmpty(tableFields.getField()) ? tableFields.getField()
|
||||
: finalForiegKey;
|
||||
}
|
||||
selectKey.add(sqlTable.column(foriegKey));
|
||||
}
|
||||
|
||||
SqlTable sqlMainTable = SqlTable.of(mainTableModel.getTable());
|
||||
String taskIdField = TableFeildsEnum.FLOWTASKID.getField();
|
||||
if (dbType.contains("Oracle") || dbType.contains("DM DBMS")) {
|
||||
taskIdField = TableFeildsEnum.FLOWTASKID.getField().toUpperCase();
|
||||
}
|
||||
if (dataMap.get(FlowFormConstant.FLOWID) != null
|
||||
&& StringUtil.isNotEmpty(dataMap.get(FlowFormConstant.FLOWID).toString())) {
|
||||
selectKey.add(sqlMainTable.column(taskIdField));
|
||||
}
|
||||
QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where;
|
||||
// 是否主表
|
||||
if (isMain) {
|
||||
where = SqlBuilder
|
||||
.select(selectKey)
|
||||
.from(sqlTable)
|
||||
.where();
|
||||
} else {
|
||||
where = SqlBuilder
|
||||
.select(selectKey)
|
||||
.from(sqlMainTable)
|
||||
.leftJoin(sqlTable)
|
||||
.on(sqlTable.column(tableModel.getTableField()),
|
||||
new EqualTo(sqlMainTable.column(tableModel.getRelationField())))
|
||||
.where();
|
||||
}
|
||||
if (ObjectUtil.isEmpty(o)) {
|
||||
where.and(sqlTable.column(columnName), SqlBuilder.isNull());
|
||||
} else {
|
||||
where.and(sqlTable.column(columnName), SqlBuilder.isEqualTo(o.toString()));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(id)) {
|
||||
TableFields mainKeyModel = mainTableModel.getFields().stream()
|
||||
.filter(t -> Objects.equals(t.getPrimaryKey(), 1)
|
||||
&& !t.getField().equalsIgnoreCase(TableFeildsEnum.TENANTID.getField()))
|
||||
.findFirst().orElse(null);
|
||||
Object realId = id;
|
||||
if (VisualConst.DB_INT_ALL.contains(mainKeyModel.getDataType().toLowerCase())) {
|
||||
realId = Long.parseLong(id);
|
||||
}
|
||||
where.and(sqlTable.column(mainKeyModel.getField()), SqlBuilder.isNotEqualTo(realId));
|
||||
}
|
||||
if (logicalDelete) {
|
||||
where.and(sqlMainTable.column(TableFeildsEnum.DELETEMARK.getField()), SqlBuilder.isNull());
|
||||
}
|
||||
// 是流程
|
||||
if (dataMap.get(FlowFormConstant.FLOWID) != null
|
||||
&& StringUtil.isNotEmpty(dataMap.get(FlowFormConstant.FLOWID).toString())) {
|
||||
where.and(sqlMainTable.column(TableFeildsEnum.FLOWID.getField()),
|
||||
SqlBuilder.isEqualTo(dataMap.get(FlowFormConstant.FLOWID)));
|
||||
} else {
|
||||
where.and(sqlMainTable.column(TableFeildsEnum.FLOWID.getField()), SqlBuilder.isNull());
|
||||
}
|
||||
|
||||
SelectStatementProvider render = where.build().render(RenderingStrategies.MYBATIS3);
|
||||
FormCheckModel formCheckModel = new FormCheckModel();
|
||||
formCheckModel.setLabel(I18nUtil.getMessageStr(fieLdsModel.getConfig().getLabelI18nCode(),
|
||||
fieLdsModel.getConfig().getLabel()));
|
||||
formCheckModel.setStatementProvider(render);
|
||||
formCheckModels.add(formCheckModel);
|
||||
}
|
||||
}
|
||||
|
||||
// 主副表数据库判重
|
||||
for (FormCheckModel formCheckModel : formCheckModels) {
|
||||
int count = flowFormDataMapper.selectManyMappedRows(formCheckModel.getStatementProvider()).size();
|
||||
if (count > 0) {
|
||||
return formCheckModel.getLabel() + MsgCode.EXIST103.get();
|
||||
}
|
||||
}
|
||||
|
||||
// 子表当前表单数据判重
|
||||
List<FieLdsModel> childFieldList = fields.stream()
|
||||
.filter(f -> YunzhupaasKeyConsts.CHILD_TABLE.equals(f.getConfig().getYunzhupaasKey()))
|
||||
.collect(Collectors.toList());
|
||||
for (FieLdsModel fieLdsModel : childFieldList) {
|
||||
List<Map<String, Object>> childMapList = (List) dataMap.get(fieLdsModel.getVModel());
|
||||
if (ObjectUtil.isEmpty(childMapList))
|
||||
continue;
|
||||
String tableName = I18nUtil.getMessageStr(fieLdsModel.getConfig().getLabelI18nCode(),
|
||||
fieLdsModel.getConfig().getLabel());
|
||||
for (FieLdsModel childField : fieLdsModel.getConfig().getChildren()) {
|
||||
ConfigModel config = childField.getConfig();
|
||||
if (checkFormModel.getIsLink() && !LINK_ALLOW_KEY.contains(config.getYunzhupaasKey())) {
|
||||
continue;
|
||||
}
|
||||
// 判断为空
|
||||
if (config.isRequired() && !inlineEdit && !isTransfer) {
|
||||
for (Map<String, Object> item : childMapList) {
|
||||
Object o = item.get(childField.getVModel());
|
||||
if (ObjectUtil.isEmpty(o) || StringUtil.isEmpty(o.toString().trim())) {
|
||||
return tableName + "-"
|
||||
+ I18nUtil.getMessageStr(config.getLabelI18nCode(), config.getLabel())
|
||||
+ MsgCode.VS015.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
// 判断唯一
|
||||
if (YunzhupaasKeyConsts.COM_INPUT.equals(config.getYunzhupaasKey()) && config.getUnique()) {
|
||||
List<String> childValues = childMapList.stream()
|
||||
.filter(ChildTbMap -> ChildTbMap.get(childField.getVModel()) != null)
|
||||
.map(ChildTbMap -> String.valueOf(ChildTbMap.get(childField.getVModel())).trim())
|
||||
.collect(Collectors.toList());
|
||||
if (childValues.size() > 0) {
|
||||
HashSet<String> child = new HashSet<>(childValues);
|
||||
if (child.size() != childValues.size()) {
|
||||
return tableName + "-"
|
||||
+ I18nUtil.getMessageStr(config.getLabelI18nCode(), config.getLabel())
|
||||
+ MsgCode.EXIST103.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
DynamicDataSourceUtil.clearSwitchDataSource();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getCount(Object id, SqlTable sqlTable, TableModel tableModel, DbLinkEntity linkEntity) {
|
||||
try {
|
||||
DynamicDataSourceUtil.switchToDataSource(linkEntity);
|
||||
@Cleanup
|
||||
Connection conn = ConnUtil.getConnOrDefault(linkEntity);
|
||||
String dbType = conn.getMetaData().getDatabaseProductName().trim();
|
||||
String key = flowDataUtil.getKey(tableModel, dbType);
|
||||
String flowTaskId = flowDataUtil.getFlowTaskId(tableModel, dbType);
|
||||
List<AndOrCriteriaGroup> groupList = new ArrayList<>();
|
||||
groupList.add(SqlBuilder.or(sqlTable.column(flowTaskId), SqlBuilder.isEqualTo(id.toString())));
|
||||
|
||||
SelectStatementProvider countRender = SqlBuilder
|
||||
.select(sqlTable.column(key))
|
||||
.from(sqlTable)
|
||||
.where(sqlTable.column(key), SqlBuilder.isEqualTo(id), groupList)
|
||||
.build().render(RenderingStrategies.MYBATIS3);
|
||||
Map<String, Object> map = flowFormDataMapper.selectOneMappedRow(countRender);
|
||||
if (MapUtils.isNotEmpty(map)) {
|
||||
if (Objects.nonNull(map.get(key))) {
|
||||
return map.get(key).toString();
|
||||
}
|
||||
}
|
||||
} catch (DataException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SQLException sqlException) {
|
||||
sqlException.printStackTrace();
|
||||
} finally {
|
||||
DynamicDataSourceUtil.clearSwitchDataSource();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务主键 判断
|
||||
*
|
||||
* @param fields
|
||||
* @param data
|
||||
* @param tableList
|
||||
* @param formData
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public VisualErrInfo checkBusinessKey(List<FieLdsModel> fields, Map<String, Object> data,
|
||||
List<TableModel> tableList, FormDataModel formData, String id) {
|
||||
Boolean logicalDelete = formData.getLogicalDelete();
|
||||
if (formData.isUseBusinessKey()) {
|
||||
List<String> businessKeyList = Arrays.asList(formData.getBusinessKeyList());
|
||||
if (CollectionUtils.isEmpty(businessKeyList))
|
||||
return null;
|
||||
TableModel mainTable = tableList.stream().filter(t -> t.getTypeId().equals("1")).findFirst().orElse(null);
|
||||
TableFields mainFields = mainTable.getFields().stream().filter(t -> Objects.equals(t.getPrimaryKey(), 1)
|
||||
&& !t.getField().equalsIgnoreCase(TableFeildsEnum.TENANTID.getField())).findFirst().orElse(null);
|
||||
|
||||
SqlTable sqlTable = SqlTable.of(mainTable.getTable());
|
||||
String mainKey = mainFields.getField();
|
||||
String taskIdField = TableFeildsEnum.FLOWTASKID.getField();
|
||||
TableFields taskIdFielde = mainTable.getFields().stream()
|
||||
.filter(t -> TableFeildsEnum.FLOWTASKID.getField().equalsIgnoreCase(t.getField())).findFirst()
|
||||
.orElse(null);
|
||||
if (ObjectUtil.isNotEmpty(taskIdFielde)) {
|
||||
taskIdField = taskIdFielde.getField();
|
||||
}
|
||||
List<BasicColumn> selectKey = new ArrayList<>();
|
||||
selectKey.add(sqlTable.column(mainKey));
|
||||
if (data.get(FlowFormConstant.FLOWID) != null
|
||||
&& StringUtil.isNotEmpty(data.get(FlowFormConstant.FLOWID).toString())) {
|
||||
selectKey.add(sqlTable.column(taskIdField));
|
||||
}
|
||||
QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where = SqlBuilder.select(selectKey)
|
||||
.from(sqlTable).where();
|
||||
|
||||
for (FieLdsModel fieLdsModel : fields) {
|
||||
String fieldName = fieLdsModel.getVModel();
|
||||
Object o = data.get(fieldName);
|
||||
if (businessKeyList.contains(fieldName)) {
|
||||
if (ObjectUtil.isEmpty(o)) {
|
||||
where.and(sqlTable.column(fieldName), SqlBuilder.isNull());
|
||||
} else {
|
||||
o = o instanceof List ? JsonUtil.getObjectToString(o) : o;
|
||||
if (YunzhupaasKeyConsts.DateSelect.contains(fieLdsModel.getConfig().getYunzhupaasKey())) {
|
||||
try {
|
||||
o = new Date((Long) o);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
String format = fieLdsModel.getFormat();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
||||
o = sdf.parse(String.valueOf(o));
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
where.and(sqlTable.column(fieldName), SqlBuilder.isEqualTo(o));
|
||||
}
|
||||
}
|
||||
}
|
||||
// 更新跳过本条数据
|
||||
if (StringUtils.isNotEmpty(id)) {
|
||||
Object realId = id;
|
||||
if (VisualConst.DB_INT_ALL.contains(mainFields.getDataType().toLowerCase())) {
|
||||
realId = Long.parseLong(id);
|
||||
}
|
||||
where.and(sqlTable.column(mainKey), SqlBuilder.isNotEqualTo(realId));
|
||||
}
|
||||
// 流程数据过滤
|
||||
if (data.get(FlowFormConstant.FLOWID) != null
|
||||
&& StringUtil.isNotEmpty(data.get(FlowFormConstant.FLOWID).toString())) {
|
||||
where.and(sqlTable.column(TableFeildsEnum.FLOWID.getField()),
|
||||
SqlBuilder.isEqualTo(data.get(FlowFormConstant.FLOWID)));
|
||||
} else {
|
||||
where.and(sqlTable.column(TableFeildsEnum.FLOWID.getField()), SqlBuilder.isNull());
|
||||
}
|
||||
// 逻辑删除
|
||||
if (logicalDelete) {
|
||||
where.and(sqlTable.column(TableFeildsEnum.DELETEMARK.getField()), SqlBuilder.isNull());
|
||||
}
|
||||
SelectStatementProvider render = where.build().render(RenderingStrategies.MYBATIS3);
|
||||
List<Map<String, Object>> maps;
|
||||
try {
|
||||
maps = flowFormDataMapper.selectManyMappedRows(render);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
int count = maps.size();
|
||||
if (count > 0) {
|
||||
VisualErrInfo visualErrInfo = VisualErrInfo.builder().errMsg(formData.getBusinessKeyTip()).build();
|
||||
if (ObjectUtil.isNotEmpty(maps.get(0).get(mainKey))) {
|
||||
visualErrInfo.setId(maps.get(0).get(mainKey).toString());
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(maps.get(0).get(taskIdField))) {
|
||||
visualErrInfo.setFlowTaskId(maps.get(0).get(taskIdField).toString());
|
||||
}
|
||||
return visualErrInfo;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断excel表内业务主键是否重复
|
||||
*
|
||||
* @param formData
|
||||
* @param resultMap
|
||||
* @param uniqueModel
|
||||
* @return
|
||||
*/
|
||||
public String checkBusinessKeyExcel(FormDataModel formData, Map<String, Object> resultMap,
|
||||
ImportFormCheckUniqueModel uniqueModel) {
|
||||
List<String> businessKeyList = Arrays.asList(formData.getBusinessKeyList());
|
||||
List<Map<String, Object>> successList = uniqueModel.getImportDataModel().stream()
|
||||
.map(ImportDataModel::getResultData).collect(Collectors.toList());
|
||||
if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(successList)) {
|
||||
boolean exists = false;
|
||||
for (int uniqueIndex = 0; uniqueIndex < successList.size(); uniqueIndex++) {
|
||||
Map<String, Object> indexMap = successList.get(uniqueIndex);
|
||||
boolean hasB = false;
|
||||
for (String fieldsKey : businessKeyList) {
|
||||
if ((resultMap.get(fieldsKey) == null && indexMap.get(fieldsKey) == null)
|
||||
|| (resultMap.get(fieldsKey) != null
|
||||
&& resultMap.get(fieldsKey).equals(indexMap.get(fieldsKey)))) {
|
||||
hasB = true;
|
||||
} else {
|
||||
// 有一个没匹配上就跳出循环
|
||||
hasB = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasB) {
|
||||
exists = true;
|
||||
if (uniqueModel.isUpdate()) {
|
||||
uniqueModel.getImportDataModel().get(uniqueIndex).setResultData(resultMap);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (exists) {
|
||||
return formData.getBusinessKeyTip();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FormExecelUtils {
|
||||
/**
|
||||
* 合并子表数据
|
||||
*
|
||||
* @param excelDataList
|
||||
* @param selectKey
|
||||
* @return
|
||||
* @throws WorkFlowException
|
||||
*/
|
||||
public static List<Map<String, Object>> dataMergeChildTable(List<Map> excelDataList, List<String> selectKey)
|
||||
throws WorkFlowException {
|
||||
List<Map<String, Object>> results = new ArrayList<>();
|
||||
Set<String> tablefield1 = selectKey.stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(YunzhupaasKeyConsts.CHILD_TABLE_PREFIX))
|
||||
.map(s -> s.substring(0, s.indexOf("-"))).collect(Collectors.toSet());
|
||||
List<Map<String, Object>> allDataList = new ArrayList<>();
|
||||
|
||||
for (int z = 0; z < excelDataList.size(); z++) {
|
||||
Map<String, Object> dataMap = new HashMap<>(16);
|
||||
Map m = excelDataList.get(z);
|
||||
List excelEntrySet = new ArrayList<>(m.entrySet());
|
||||
// 取出的数据最后一行 不带行标签
|
||||
int resultsize = z == excelDataList.size() - 1 ? excelEntrySet.size()
|
||||
: m.containsKey("excelRowNum") ? excelEntrySet.size() - 1 : excelEntrySet.size();
|
||||
if (resultsize < selectKey.size()) {
|
||||
throw new WorkFlowException(MsgCode.VS407.get());
|
||||
}
|
||||
for (int e = 0; e < resultsize; e++) {
|
||||
Map.Entry o = (Map.Entry) excelEntrySet.get(e);
|
||||
String entryKey = o.getKey().toString();
|
||||
String substring = entryKey.substring(entryKey.lastIndexOf("(") + 1, entryKey.lastIndexOf(")"));
|
||||
boolean contains = selectKey.contains(substring);
|
||||
if (!contains) {
|
||||
throw new WorkFlowException(MsgCode.VS407.get());
|
||||
}
|
||||
dataMap.put(substring, o.getValue());
|
||||
}
|
||||
allDataList.add(dataMap);
|
||||
}
|
||||
|
||||
// 存放在主表数据的下标位置
|
||||
List<Map<String, List<Map<String, Object>>>> IndexMap = new ArrayList<>();
|
||||
// Map<Integer, Map<String, List<Map<String, Object>>>> IndexMap = new
|
||||
// TreeMap<>();
|
||||
Map<String, List<Map<String, Object>>> childrenTabMap = new HashMap<>();
|
||||
for (String tab : tablefield1) {
|
||||
childrenTabMap.put(tab, new ArrayList<>());
|
||||
}
|
||||
|
||||
for (int t = 0; t < allDataList.size(); t++) {
|
||||
boolean isLast = t == allDataList.size() - 1;
|
||||
// 是否需要合并
|
||||
boolean needTogether = true;
|
||||
// 这条数据是否需要添加
|
||||
boolean needAdd = true;
|
||||
Map<String, Object> dataMap = allDataList.get(t);
|
||||
// 首条数据不合并
|
||||
if (t > 0) {
|
||||
List<Map.Entry<String, Object>> tablefield2 = dataMap.entrySet().stream()
|
||||
.filter(e -> !e.getKey().toLowerCase().startsWith(YunzhupaasKeyConsts.CHILD_TABLE_PREFIX))
|
||||
.collect(Collectors.toList());
|
||||
// 如果除子表外都为空 则需要合并
|
||||
Map.Entry<String, Object> entry = tablefield2.stream().filter(ta -> ta.getValue() != null).findFirst()
|
||||
.orElse(null);
|
||||
if (entry == null) {
|
||||
needTogether = false;
|
||||
needAdd = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 合并子表里的字段
|
||||
for (String tab : tablefield1) {
|
||||
Map<String, Object> childObjMap = new HashMap<>(16);
|
||||
// 该条数据下的子表字段
|
||||
List<Map.Entry<String, Object>> childList = dataMap.entrySet().stream()
|
||||
.filter(e -> e.getKey().startsWith(tab)).collect(Collectors.toList());
|
||||
for (Map.Entry<String, Object> entry : childList) {
|
||||
String childFieldName = entry.getKey().replace(tab + "-", "");
|
||||
childObjMap.put(childFieldName, entry.getValue());
|
||||
}
|
||||
List<Map<String, Object>> mapList = childrenTabMap.get(tab);
|
||||
if (MapUtils.isNotEmpty(childObjMap)) {
|
||||
boolean b = childObjMap.values().stream().anyMatch(v -> v != null);
|
||||
if (b) {
|
||||
mapList.add(childObjMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (needTogether && t != 0) {
|
||||
Map<String, List<Map<String, Object>>> c = new HashMap<>(childrenTabMap);
|
||||
Map<String, List<Map<String, Object>>> b = new HashMap<>();
|
||||
|
||||
for (String tab : tablefield1) {
|
||||
// 去掉最后一个 放到下条数据里
|
||||
List<Map<String, Object>> mapList = c.get(tab);
|
||||
Map<String, Object> map = mapList.get(mapList.size() - 1);
|
||||
List<Map<String, Object>> aList = new ArrayList<>();
|
||||
aList.add(map);
|
||||
mapList.remove(mapList.size() - 1);
|
||||
childrenTabMap.put(tab, aList);
|
||||
b.put(tab, mapList);
|
||||
}
|
||||
IndexMap.add(b);
|
||||
if (isLast) {
|
||||
IndexMap.add(childrenTabMap);
|
||||
}
|
||||
} else {
|
||||
if (isLast) {
|
||||
IndexMap.add(childrenTabMap);
|
||||
}
|
||||
}
|
||||
if (needAdd) {
|
||||
Map<String, Object> m = new HashMap<>();
|
||||
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
|
||||
if (!entry.getKey().contains("-")) {
|
||||
m.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
results.add(m);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理结果
|
||||
for (int r = 0; r < results.size(); r++) {
|
||||
Map<String, List<Map<String, Object>>> entry = IndexMap.get(r);
|
||||
Map<String, Object> map = results.get(r);
|
||||
for (Map.Entry<String, List<Map<String, Object>>> entry1 : entry.entrySet()) {
|
||||
String tableField = entry1.getKey();
|
||||
Object tableField1 = map.get(tableField);
|
||||
List<Map<String, Object>> value1 = entry1.getValue();
|
||||
if (tableField1 != null) {
|
||||
List<Map<String, Object>> tfMap = (List<Map<String, Object>>) tableField1;
|
||||
value1.addAll(tfMap);
|
||||
}
|
||||
map.put(tableField, value1);
|
||||
}
|
||||
results.set(r, map);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.yunzhupaas.database.util.DynamicDataSourceUtil;
|
||||
import com.yunzhupaas.message.model.websocket.onconnettion.OnLineModel;
|
||||
import com.yunzhupaas.model.visualJson.FieLdsModel;
|
||||
import com.yunzhupaas.permission.entity.PositionEntity;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.util.DateUtil;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Clob;
|
||||
import java.util.*;
|
||||
|
||||
import static com.yunzhupaas.util.Constants.ADMIN_KEY;
|
||||
|
||||
/**
|
||||
* 在线详情编辑工具类
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.2
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/10/27
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class FormInfoUtils {
|
||||
@Autowired
|
||||
private ServiceBaseUtil serviceUtil;
|
||||
|
||||
/**
|
||||
* 转换数据格式(编辑页)
|
||||
*
|
||||
* @param modelList 控件
|
||||
* @param dataMap 数据
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> swapDataInfoType(List<FieLdsModel> modelList, Map<String, Object> dataMap) {
|
||||
dataMap = Optional.ofNullable(dataMap).orElse(new HashMap<>());
|
||||
try {
|
||||
DynamicDataSourceUtil.switchToDataSource(null);
|
||||
List<String> systemConditions = new ArrayList() {
|
||||
{
|
||||
add(YunzhupaasKeyConsts.CURRORGANIZE);
|
||||
add(YunzhupaasKeyConsts.CURRDEPT);
|
||||
add(YunzhupaasKeyConsts.CURRPOSITION);
|
||||
}
|
||||
};
|
||||
List<String> nullIsList = new ArrayList() {
|
||||
{
|
||||
add(YunzhupaasKeyConsts.UPLOADFZ);
|
||||
add(YunzhupaasKeyConsts.UPLOADIMG);
|
||||
}
|
||||
};
|
||||
for (FieLdsModel swapDataVo : modelList) {
|
||||
String yunzhupaasKey = swapDataVo.getConfig().getYunzhupaasKey();
|
||||
String vModel = swapDataVo.getVModel();
|
||||
|
||||
// clob字段转换
|
||||
FormInfoUtils.swapClob(dataMap, vModel);
|
||||
// 获取原字段数据
|
||||
FormPublicUtils.relationGetYunzhupaasId(dataMap, yunzhupaasKey, dataMap.get(vModel), vModel);
|
||||
|
||||
Object value = dataMap.get(vModel);
|
||||
if (value == null || ObjectUtil.isEmpty(value)) {
|
||||
if (systemConditions.contains(yunzhupaasKey)) {
|
||||
dataMap.put(vModel, " ");
|
||||
}
|
||||
if (nullIsList.contains(yunzhupaasKey)) {
|
||||
dataMap.put(vModel, Collections.emptyList());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
switch (yunzhupaasKey) {
|
||||
case YunzhupaasKeyConsts.UPLOADFZ:
|
||||
case YunzhupaasKeyConsts.UPLOADIMG:
|
||||
// 数据传递-乱塞有bug强行置空
|
||||
List<Map<String, Object>> fileList = new ArrayList<>();
|
||||
try {
|
||||
fileList = JsonUtil.getJsonToListMap(dataMap.get(vModel).toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
dataMap.put(vModel, fileList);
|
||||
break;
|
||||
case YunzhupaasKeyConsts.DATE:
|
||||
Long dateTime = DateTimeFormatConstant.getDateObjToLong(dataMap.get(vModel));
|
||||
dataMap.put(vModel, dateTime != null ? dateTime : dataMap.get(vModel));
|
||||
break;
|
||||
case YunzhupaasKeyConsts.CREATETIME:
|
||||
case YunzhupaasKeyConsts.MODIFYTIME:
|
||||
String pattern = DateTimeFormatConstant.YEAR_MOnTH_DHMS;
|
||||
Long time = DateTimeFormatConstant.getDateObjToLong(dataMap.get(vModel));
|
||||
dataMap.put(vModel, time != null ? DateUtil.dateToString(new Date(time), pattern) : "");
|
||||
break;
|
||||
case YunzhupaasKeyConsts.SWITCH:
|
||||
case YunzhupaasKeyConsts.SLIDER:
|
||||
case YunzhupaasKeyConsts.RATE:
|
||||
case YunzhupaasKeyConsts.CALCULATE:
|
||||
case YunzhupaasKeyConsts.NUM_INPUT:
|
||||
dataMap.put(vModel, value != null ? new BigDecimal(String.valueOf(value)) : null);
|
||||
break;
|
||||
case YunzhupaasKeyConsts.CURRPOSITION:
|
||||
PositionEntity positionEntity = serviceUtil.getPositionInfo(String.valueOf(value));
|
||||
dataMap.put(vModel, Objects.nonNull(positionEntity) ? positionEntity.getFullName() : value);
|
||||
break;
|
||||
|
||||
case YunzhupaasKeyConsts.CREATEUSER:
|
||||
case YunzhupaasKeyConsts.MODIFYUSER:
|
||||
UserEntity userEntity = serviceUtil.getUserInfo(String.valueOf(value));
|
||||
String userValue = Objects.nonNull(userEntity)
|
||||
? userEntity.getAccount().equalsIgnoreCase(ADMIN_KEY)
|
||||
? "管理员/" + ADMIN_KEY
|
||||
: userEntity.getRealName() + "/" + userEntity.getAccount()
|
||||
: String.valueOf(value);
|
||||
dataMap.put(vModel, userValue);
|
||||
break;
|
||||
case YunzhupaasKeyConsts.CURRORGANIZE:
|
||||
String currentOrganizeName = serviceUtil.getCurrentOrganizeName(value,
|
||||
swapDataVo.getShowLevel());
|
||||
dataMap.put(vModel, currentOrganizeName);
|
||||
break;
|
||||
case YunzhupaasKeyConsts.COM_INPUT:
|
||||
if (dataMap.get(vModel) != null) {
|
||||
dataMap.put(vModel, String.valueOf(dataMap.get(vModel)));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
dataMap.put(vModel, FormPublicUtils.getDataConversion(value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
DynamicDataSourceUtil.clearSwitchDataSource();
|
||||
}
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public static void swapClob(Map<String, Object> map, String key) {
|
||||
if (map != null && map.get(key) != null && map.get(key) instanceof Clob) {
|
||||
Clob clob = (Clob) map.get(key);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// 获取CLOB字段的内容长度
|
||||
int length = 0;
|
||||
// 以流的形式读取CLOB字段的内容
|
||||
try (java.io.Reader reader = clob.getCharacterStream()) {
|
||||
length = (int) clob.length();
|
||||
char[] buffer = new char[length];
|
||||
int bytesRead;
|
||||
// 逐个字符读取并添加到字符串构建器中
|
||||
while ((bytesRead = reader.read(buffer)) != -1) {
|
||||
sb.append(buffer, 0, bytesRead);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
map.put(key, sb.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,466 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.yunzhupaas.model.visualJson.FieLdsModel;
|
||||
import com.yunzhupaas.model.visualJson.config.ConfigModel;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 在线开发公用
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/7/28
|
||||
*/
|
||||
public class FormPublicUtils {
|
||||
|
||||
/**
|
||||
* 递归控件,除子表外控件全部提到同级
|
||||
* 取子集,子表不外提
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static void recursionFieldsExceptChild(List<FieLdsModel> allFields, List<FieLdsModel> fieLdsModelList) {
|
||||
for (FieLdsModel fieLdsModel : fieLdsModelList) {
|
||||
ConfigModel config = fieLdsModel.getConfig();
|
||||
String yunzhupaasKey = config.getYunzhupaasKey();
|
||||
if (YunzhupaasKeyConsts.CHILD_TABLE.equals(yunzhupaasKey)) {
|
||||
allFields.add(fieLdsModel);
|
||||
continue;
|
||||
} else {
|
||||
if (config.getChildren() != null) {
|
||||
recursionFieldsExceptChild(allFields, config.getChildren());
|
||||
} else {
|
||||
if (yunzhupaasKey == null) {
|
||||
continue;
|
||||
}
|
||||
allFields.add(fieLdsModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换时间格式
|
||||
*
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
public static String getTimeFormat(String time) {
|
||||
String result;
|
||||
switch (time.length()) {
|
||||
case 16:
|
||||
result = time + ":00";
|
||||
break;
|
||||
case 19:
|
||||
result = time;
|
||||
break;
|
||||
case 21:
|
||||
result = time.substring(0, time.length() - 2);
|
||||
break;
|
||||
case 10:
|
||||
result = time + " 00:00:00";
|
||||
break;
|
||||
case 8:
|
||||
result = "2000-01-01 " + time;
|
||||
break;
|
||||
case 7:
|
||||
result = time + "-01 00:00:00";
|
||||
break;
|
||||
case 4:
|
||||
result = time + "-01-01 00:00:00";
|
||||
break;
|
||||
default:
|
||||
result = "";
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getLastTimeFormat(String time) {
|
||||
String result;
|
||||
switch (time.length()) {
|
||||
case 16:
|
||||
result = time + ":00";
|
||||
break;
|
||||
case 19:
|
||||
result = time;
|
||||
break;
|
||||
case 10:
|
||||
result = time + " 23:59:59";
|
||||
break;
|
||||
case 8:
|
||||
result = "2000-01-01 " + time;
|
||||
break;
|
||||
case 7:
|
||||
// 获取月份最后一天
|
||||
String[] split = time.split("-");
|
||||
Calendar cale = Calendar.getInstance();
|
||||
cale.set(Calendar.YEAR, Integer.valueOf(split[0]));// 赋值年份
|
||||
cale.set(Calendar.MONTH, Integer.valueOf(split[1]) - 1);// 赋值月份
|
||||
int lastDay = cale.getActualMaximum(Calendar.DAY_OF_MONTH);// 获取月最大天数
|
||||
cale.set(Calendar.DAY_OF_MONTH, lastDay);// 设置日历中月份的最大天数
|
||||
cale.set(Calendar.HOUR_OF_DAY, 23);
|
||||
cale.set(Calendar.SECOND, 59);
|
||||
cale.set(Calendar.MINUTE, 59);
|
||||
result = DateUtil.daFormatHHMMSS(cale.getTime().getTime());
|
||||
break;
|
||||
case 4:
|
||||
result = time + "-12-31 23:59:59";
|
||||
break;
|
||||
default:
|
||||
result = "";
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断时间是否在设置范围内
|
||||
*
|
||||
* @param swapDataVo
|
||||
* @param format
|
||||
* @param value
|
||||
* @param data
|
||||
* @param yunzhupaasKey
|
||||
* @return
|
||||
*/
|
||||
public static boolean dateTimeCondition(FieLdsModel swapDataVo, String format, Object value,
|
||||
Map<String, Object> data, String yunzhupaasKey) {
|
||||
long valueTimeLong;
|
||||
// 输入值转long
|
||||
if (value instanceof String) {
|
||||
valueTimeLong = cn.hutool.core.date.DateUtil.parse(String.valueOf(value), format).getTime();
|
||||
} else {
|
||||
// 输入值按格式补全
|
||||
String timeFormat = getTimeFormat(String.valueOf(value));
|
||||
valueTimeLong = DateUtil.stringToDate(timeFormat).getTime();
|
||||
}
|
||||
boolean timeHasRangeError = false;
|
||||
// 开始时间判断
|
||||
if (swapDataVo.getConfig().getStartTimeRule()) {
|
||||
String startTimeValue = swapDataVo.getConfig().getStartTimeValue();
|
||||
String startTimeType = swapDataVo.getConfig().getStartTimeType();
|
||||
String startTimeTarget = swapDataVo.getConfig().getStartTimeTarget();
|
||||
String startTimeRelationField = swapDataVo.getConfig().getStartRelationField();
|
||||
// 根据类型获取开始时间戳
|
||||
long startTimeLong = getDateTimeLong(data, yunzhupaasKey, startTimeValue, startTimeType, startTimeTarget,
|
||||
startTimeRelationField, format);
|
||||
if (startTimeLong != 0 && valueTimeLong < startTimeLong) {
|
||||
timeHasRangeError = true;
|
||||
}
|
||||
}
|
||||
// 结束时间判断
|
||||
if (swapDataVo.getConfig().getEndTimeRule()) {
|
||||
String endTimeValue = swapDataVo.getConfig().getEndTimeValue();
|
||||
String endTimeType = swapDataVo.getConfig().getEndTimeType();
|
||||
String endTimeTarget = swapDataVo.getConfig().getEndTimeTarget();
|
||||
String endTimeRelationField = swapDataVo.getConfig().getEndRelationField();
|
||||
// 根据类型获取开始时间戳
|
||||
long endTimeLong = getDateTimeLong(data, yunzhupaasKey, endTimeValue, endTimeType, endTimeTarget,
|
||||
endTimeRelationField, format);
|
||||
if (endTimeLong != 0 && valueTimeLong > endTimeLong) {
|
||||
timeHasRangeError = true;
|
||||
}
|
||||
}
|
||||
return timeHasRangeError;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类型获取时间戳
|
||||
*
|
||||
* @param data
|
||||
* @param yunzhupaasKey
|
||||
* @param timeValue
|
||||
* @param timeType
|
||||
* @param timeTarget
|
||||
* @return
|
||||
*/
|
||||
public static long getDateTimeLong(Map<String, Object> data, String yunzhupaasKey, String timeValue,
|
||||
String timeType, String timeTarget,
|
||||
String stringimeRelationField, String format) {
|
||||
if (StringUtil.isEmpty(timeValue)) {
|
||||
timeValue = "0";
|
||||
}
|
||||
long startTimeLong = 0;
|
||||
// 当前格式的当前时间戳
|
||||
long timestampInMillis = new Date().getTime();
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
||||
String s = sdf.format(new Date());
|
||||
timestampInMillis = sdf.parse(s).getTime();
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
switch (timeType) {
|
||||
case "1":// 特定时间
|
||||
if (YunzhupaasKeyConsts.DATE.equals(yunzhupaasKey)) {
|
||||
startTimeLong = Long.parseLong(timeValue);
|
||||
} else {
|
||||
String newDateStr = DateUtil.daFormat(new Date()) + " " + timeValue
|
||||
+ (timeValue.length() > 6 ? "" : ":00");
|
||||
startTimeLong = DateUtil.stringToDate(newDateStr).getTime();
|
||||
}
|
||||
break;
|
||||
case "2":// 表单字段
|
||||
if (stringimeRelationField != null) {
|
||||
String fieldValue = "";
|
||||
if (stringimeRelationField.toLowerCase().contains(YunzhupaasKeyConsts.CHILD_TABLE_PREFIX)) {// 子
|
||||
String[] split = stringimeRelationField.split("-");
|
||||
fieldValue = data.get(split[1]) != null ? data.get(split[1]).toString() : "";
|
||||
} else {// 主副
|
||||
Map<String, Object> mainAndMast = data.get("mainAndMast") != null
|
||||
? JsonUtil.entityToMap(data.get("mainAndMast"))
|
||||
: data;
|
||||
fieldValue = mainAndMast.get(stringimeRelationField) != null
|
||||
? mainAndMast.get(stringimeRelationField).toString()
|
||||
: "";
|
||||
}
|
||||
if (StringUtil.isNotEmpty(fieldValue)) {
|
||||
String timeFormat = getTimeFormat(fieldValue);
|
||||
startTimeLong = cn.hutool.core.date.DateUtil.parse(timeFormat, "yyyy-MM-dd HH:mm:ss").getTime();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "3":// 填写当前时间
|
||||
startTimeLong = timestampInMillis;
|
||||
break;
|
||||
case "4":// 当前时间前
|
||||
Calendar caledel = Calendar.getInstance();
|
||||
caledel.setTimeInMillis(timestampInMillis);
|
||||
if (YunzhupaasKeyConsts.DATE.equals(yunzhupaasKey)) {
|
||||
switch (timeTarget) {
|
||||
case "1":// 年
|
||||
caledel.set(Calendar.YEAR, caledel.get(Calendar.YEAR) - Integer.valueOf(timeValue));// 赋值年份
|
||||
break;
|
||||
case "2":// 月
|
||||
caledel.set(Calendar.MONTH, caledel.get(Calendar.MONTH) - Integer.valueOf(timeValue));
|
||||
break;
|
||||
case "3":// 日
|
||||
caledel.set(Calendar.DAY_OF_MONTH,
|
||||
caledel.get(Calendar.DAY_OF_MONTH) - Integer.valueOf(timeValue));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (timeTarget) {
|
||||
case "1":// 时
|
||||
caledel.set(Calendar.HOUR_OF_DAY,
|
||||
caledel.get(Calendar.HOUR_OF_DAY) - Integer.valueOf(timeValue));
|
||||
break;
|
||||
case "2":// 分
|
||||
caledel.set(Calendar.MINUTE, caledel.get(Calendar.MINUTE) - Integer.valueOf(timeValue));
|
||||
break;
|
||||
case "3":// 秒
|
||||
caledel.set(Calendar.SECOND, caledel.get(Calendar.SECOND) - Integer.valueOf(timeValue));
|
||||
break;
|
||||
}
|
||||
}
|
||||
startTimeLong = caledel.getTime().getTime();
|
||||
break;
|
||||
case "5":// 当前时间后
|
||||
Calendar cale = Calendar.getInstance();
|
||||
cale.setTimeInMillis(timestampInMillis);
|
||||
if (YunzhupaasKeyConsts.DATE.equals(yunzhupaasKey)) {
|
||||
switch (timeTarget) {
|
||||
case "1":// 年
|
||||
cale.set(Calendar.YEAR, cale.get(Calendar.YEAR) + Integer.valueOf(timeValue));// 赋值年份
|
||||
break;
|
||||
case "2":// 月
|
||||
cale.set(Calendar.MONTH, cale.get(Calendar.MONTH) + Integer.valueOf(timeValue));
|
||||
break;
|
||||
case "3":// 日
|
||||
cale.set(Calendar.DAY_OF_MONTH,
|
||||
cale.get(Calendar.DAY_OF_MONTH) + Integer.valueOf(timeValue));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (timeTarget) {
|
||||
case "1":// 时
|
||||
cale.set(Calendar.HOUR_OF_DAY, cale.get(Calendar.HOUR_OF_DAY) + Integer.valueOf(timeValue));
|
||||
break;
|
||||
case "2":// 分
|
||||
cale.set(Calendar.MINUTE, cale.get(Calendar.MINUTE) + Integer.valueOf(timeValue));
|
||||
break;
|
||||
case "3":// 秒
|
||||
cale.set(Calendar.SECOND, cale.get(Calendar.SECOND) + Integer.valueOf(timeValue));
|
||||
break;
|
||||
}
|
||||
}
|
||||
startTimeLong = cale.getTime().getTime();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return startTimeLong;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转数组
|
||||
*
|
||||
* @param value 值
|
||||
* @return
|
||||
*/
|
||||
public static Object getDataConversion(Object value) {
|
||||
if (value instanceof Integer || value instanceof Long || value instanceof Float || value instanceof Double
|
||||
|| value instanceof BigDecimal)
|
||||
return value;
|
||||
Object dataValue = getDataConversion(null, value, false, "/");
|
||||
return dataValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转数组
|
||||
*
|
||||
* @param redis 转换对象
|
||||
* @param value 值
|
||||
* @return
|
||||
*/
|
||||
public static Object getDataConversion(Map<String, Object> redis, Object value, boolean isMultiple,
|
||||
String separator) {
|
||||
Object dataValue = value;
|
||||
boolean iszhuanhuan = redis != null;
|
||||
try {
|
||||
List<List> list = JsonUtil.getJsonToList(String.valueOf(value), List.class);
|
||||
dataValue = list;
|
||||
if (iszhuanhuan) {
|
||||
// 一级分隔符
|
||||
StringJoiner joiner = new StringJoiner(",");
|
||||
for (List listChild : list) {
|
||||
StringJoiner aa = new StringJoiner(separator);
|
||||
for (Object object : listChild) {
|
||||
String value1 = redis.get(String.valueOf(object)) != null
|
||||
? String.valueOf(redis.get(String.valueOf(object)))
|
||||
: "";
|
||||
if (StringUtil.isNotEmpty(value1)) {
|
||||
aa.add(value1);
|
||||
}
|
||||
}
|
||||
joiner.add(aa.toString());
|
||||
}
|
||||
dataValue = joiner.toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
List<String> list = JsonUtil.getJsonToList(String.valueOf(value), String.class);
|
||||
dataValue = list;
|
||||
if (iszhuanhuan) {
|
||||
if (isMultiple) {// 一级分隔符
|
||||
separator = ",";
|
||||
}
|
||||
StringJoiner joiner = new StringJoiner(separator);
|
||||
for (Object listChild : list) {
|
||||
String value1 = redis.get(String.valueOf(listChild)) != null
|
||||
? String.valueOf(redis.get(String.valueOf(listChild)))
|
||||
: "";
|
||||
if (StringUtil.isNotEmpty(value1)) {
|
||||
joiner.add(value1);
|
||||
}
|
||||
}
|
||||
dataValue = joiner.toString();
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
dataValue = String.valueOf(value);
|
||||
if (iszhuanhuan) {
|
||||
dataValue = redis.get(String.valueOf(value)) != null
|
||||
? String.valueOf(redis.get(String.valueOf(value)))
|
||||
: "";
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给列表数据添加id
|
||||
*
|
||||
* @param dataList
|
||||
* @param key
|
||||
*/
|
||||
public static List<Map<String, Object>> addIdToList(List<Map<String, Object>> dataList, String key) {
|
||||
return dataList.stream().map(data -> {
|
||||
data.put(FlowFormConstant.ID, data.get(key));
|
||||
String flwoId = null;
|
||||
if (data.get(TableFeildsEnum.FLOWID.getField()) != null) {
|
||||
flwoId = String.valueOf(data.get(TableFeildsEnum.FLOWID.getField()));
|
||||
}
|
||||
if (data.get(TableFeildsEnum.FLOWID.getField().toUpperCase()) != null) {
|
||||
flwoId = String.valueOf(data.get(TableFeildsEnum.FLOWID.getField().toUpperCase()));
|
||||
}
|
||||
data.put(FlowFormConstant.FLOWID, flwoId);
|
||||
String flowTaskId = null;
|
||||
if (data.get(TableFeildsEnum.FLOWTASKID.getField()) != null) {
|
||||
flowTaskId = String.valueOf(data.get(TableFeildsEnum.FLOWTASKID.getField()));
|
||||
}
|
||||
if (data.get(TableFeildsEnum.FLOWTASKID.getField().toUpperCase()) != null) {
|
||||
flowTaskId = String.valueOf(data.get(TableFeildsEnum.FLOWTASKID.getField().toUpperCase()));
|
||||
}
|
||||
data.put(FlowFormConstant.FLOWTASKID, flowTaskId);
|
||||
|
||||
return data;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联表单获取原字段数据(数据类型也要转换)
|
||||
*
|
||||
* @param dataMap
|
||||
* @param yunzhupaasKey
|
||||
* @param obj
|
||||
* @param vModel
|
||||
*/
|
||||
public static void relationGetYunzhupaasId(Map<String, Object> dataMap, String yunzhupaasKey, Object obj,
|
||||
String vModel) {
|
||||
String vModelyunzhupaasId = vModel + "_yunzhupaasId";
|
||||
switch (yunzhupaasKey) {
|
||||
case YunzhupaasKeyConsts.CREATETIME:
|
||||
case YunzhupaasKeyConsts.MODIFYTIME:
|
||||
case YunzhupaasKeyConsts.DATE:
|
||||
Long dateTime = DateTimeFormatConstant.getDateObjToLong(dataMap.get(vModel));
|
||||
dataMap.put(vModelyunzhupaasId, dateTime != null ? dateTime : dataMap.get(vModel));
|
||||
break;
|
||||
case YunzhupaasKeyConsts.CHILD_TABLE:
|
||||
break;
|
||||
case YunzhupaasKeyConsts.SWITCH:
|
||||
case YunzhupaasKeyConsts.SLIDER:
|
||||
case YunzhupaasKeyConsts.RATE:
|
||||
case YunzhupaasKeyConsts.CALCULATE:
|
||||
case YunzhupaasKeyConsts.NUM_INPUT:
|
||||
dataMap.put(vModelyunzhupaasId,
|
||||
ObjectUtil.isNotEmpty(obj) ? new BigDecimal(String.valueOf(obj)) : dataMap.get(vModel));
|
||||
break;
|
||||
default:
|
||||
dataMap.put(vModelyunzhupaasId, obj);
|
||||
break;
|
||||
}
|
||||
if (YunzhupaasKeyConsts.getArraysKey().contains(yunzhupaasKey) && obj != null) {
|
||||
String o = String.valueOf(obj);
|
||||
try {
|
||||
List<List> jsonToList = JsonUtil.getJsonToList(o, List.class);
|
||||
List<Object> res = new ArrayList<>();
|
||||
for (List listChild : jsonToList) {
|
||||
List<Object> res2 = new ArrayList<>();
|
||||
for (Object object : listChild) {
|
||||
if (object != null && StringUtil.isNotEmpty(String.valueOf(object))) {
|
||||
res2.add(object);
|
||||
}
|
||||
}
|
||||
res.add(res2);
|
||||
}
|
||||
dataMap.put(vModelyunzhupaasId, res);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
List<Object> jsonToList = JsonUtil.getJsonToList(o, Object.class);
|
||||
dataMap.put(vModelyunzhupaasId, jsonToList);
|
||||
} catch (Exception e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,751 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.yunzhupaas.database.source.DbBase;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.mybatis.dynamic.sql.AndOrCriteriaGroup;
|
||||
import org.mybatis.dynamic.sql.SqlBuilder;
|
||||
import org.mybatis.dynamic.sql.SqlTable;
|
||||
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
|
||||
import org.mybatis.dynamic.sql.select.SelectModel;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class OnlineFilterUtil {
|
||||
/**
|
||||
* 表字段名和对应的表对象映射
|
||||
*/
|
||||
Map<String, SqlTable> subSqlTableMap;
|
||||
/**
|
||||
* 额外参数
|
||||
*/
|
||||
Map<String, Object> params;
|
||||
/**
|
||||
* 字段说明
|
||||
*/
|
||||
private String fieldName;
|
||||
/**
|
||||
* 运算符
|
||||
*/
|
||||
private String operator;
|
||||
/**
|
||||
* 逻辑拼接符号
|
||||
*/
|
||||
private String logic;
|
||||
/**
|
||||
* 组件标识
|
||||
*/
|
||||
private String yunzhupaasKey;
|
||||
/**
|
||||
* 字段key
|
||||
*/
|
||||
private String field;
|
||||
/**
|
||||
* 自定义的值
|
||||
*/
|
||||
private String fieldValue;
|
||||
/**
|
||||
* 自定义的值2
|
||||
*/
|
||||
private String fieldValue2;
|
||||
|
||||
private List<String> selectIgnore;
|
||||
|
||||
/**
|
||||
* 显示类型
|
||||
*/
|
||||
private String showLevel;
|
||||
|
||||
/**
|
||||
* 数据库类型
|
||||
*/
|
||||
private String dbType;
|
||||
/**
|
||||
* 日期格式
|
||||
*/
|
||||
private String format;
|
||||
|
||||
/**
|
||||
* 数字精度
|
||||
*/
|
||||
private String precision;
|
||||
|
||||
/**
|
||||
* @param where where对象
|
||||
* @param sqlTable sql表对象,默认传主表
|
||||
* @return
|
||||
*/
|
||||
public QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder solveValue(
|
||||
QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where, SqlTable sqlTable) {
|
||||
|
||||
if (!this.preHandle())
|
||||
return where;
|
||||
|
||||
MyType myType = myControl(yunzhupaasKey);
|
||||
if (fieldValue == null) {
|
||||
fieldValue = "";
|
||||
}
|
||||
try {
|
||||
ArrayList splitKey = new ArrayList<String>() {
|
||||
{
|
||||
add(YunzhupaasKeyConsts.DATE);
|
||||
add(YunzhupaasKeyConsts.TIME);
|
||||
add(YunzhupaasKeyConsts.NUM_INPUT);
|
||||
add(YunzhupaasKeyConsts.CREATETIME);
|
||||
add(YunzhupaasKeyConsts.MODIFYTIME);
|
||||
}
|
||||
};
|
||||
|
||||
if (splitKey.contains(yunzhupaasKey) && "between".equals(operator)) {
|
||||
List<String> data = JsonUtil.getJsonToList(fieldValue, String.class);
|
||||
fieldValue = data.get(0);
|
||||
fieldValue2 = data.get(1);
|
||||
}
|
||||
selectIgnore = new ArrayList<String>() {
|
||||
{
|
||||
add(YunzhupaasKeyConsts.COMSELECT);
|
||||
add(YunzhupaasKeyConsts.ADDRESS);
|
||||
add(YunzhupaasKeyConsts.CASCADER);
|
||||
add(YunzhupaasKeyConsts.CHECKBOX);
|
||||
add(YunzhupaasKeyConsts.DEPSELECT);
|
||||
}
|
||||
};
|
||||
|
||||
String fieldKey = "";
|
||||
// 替换子表的sqlTable
|
||||
if (field.indexOf("-") > 0) {
|
||||
fieldKey = field.split("-")[0];
|
||||
sqlTable = this.subSqlTableMap.get(fieldKey);
|
||||
field = field.split("-")[1];
|
||||
}
|
||||
// 替换副表的字段
|
||||
if (field.indexOf("_yunzhupaas_") > 0) {
|
||||
|
||||
sqlTable = this.subSqlTableMap.get(field);
|
||||
field = field.split("_yunzhupaas_")[1];
|
||||
}
|
||||
|
||||
myType.judge(where, sqlTable, field);
|
||||
return where;
|
||||
} catch (Exception e) {
|
||||
return where;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 前置异常或边界情况处理
|
||||
*/
|
||||
private boolean preHandle() {
|
||||
if (params != null) {
|
||||
// 判断是否只需处理子副表,忽略主表
|
||||
Boolean onlySubTable = (Boolean) params.get("onlySubTable");
|
||||
// 如果是主表
|
||||
if (onlySubTable && !field.contains("_yunzhupaas_") && !field.contains("-")) {
|
||||
return false;
|
||||
}
|
||||
// 不拼接副表
|
||||
if (onlySubTable && field.contains("_yunzhupaas_")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断控件的所属类型
|
||||
*
|
||||
* @param yunzhupaasKey 控件标识
|
||||
* @return 控件类型
|
||||
*/
|
||||
public MyType myControl(String yunzhupaasKey) {
|
||||
MyType myType;
|
||||
switch (yunzhupaasKey) {
|
||||
case YunzhupaasKeyConsts.COM_INPUT:
|
||||
case YunzhupaasKeyConsts.TEXTAREA:
|
||||
case YunzhupaasKeyConsts.BILLRULE:
|
||||
case YunzhupaasKeyConsts.POPUPTABLESELECT:
|
||||
case YunzhupaasKeyConsts.RELATIONFORM:
|
||||
case YunzhupaasKeyConsts.RELATIONFORM_ATTR:
|
||||
case YunzhupaasKeyConsts.POPUPSELECT:
|
||||
case YunzhupaasKeyConsts.POPUPSELECT_ATTR:
|
||||
myType = new BasicControl();
|
||||
break;
|
||||
case YunzhupaasKeyConsts.CALCULATE:
|
||||
case YunzhupaasKeyConsts.NUM_INPUT:
|
||||
myType = new NumControl();
|
||||
break;
|
||||
case YunzhupaasKeyConsts.DATE:
|
||||
case YunzhupaasKeyConsts.CREATETIME:
|
||||
case YunzhupaasKeyConsts.MODIFYTIME:
|
||||
myType = new DateControl();
|
||||
break;
|
||||
case YunzhupaasKeyConsts.TIME:
|
||||
myType = new TimeControl();
|
||||
break;
|
||||
default:
|
||||
myType = new SelectControl();
|
||||
}
|
||||
return myType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 基础类型
|
||||
*/
|
||||
class BasicControl extends MyType {
|
||||
|
||||
@Override
|
||||
void judge(QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where, SqlTable sqlTable, String field) {
|
||||
if ("&&".equals(logic)) {
|
||||
switch (operator) {
|
||||
case "null":
|
||||
List<AndOrCriteriaGroup> group = new ArrayList<>();
|
||||
group.add(SqlBuilder.or(sqlTable.column(field), SqlBuilder.isEqualTo("")));
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNull(), group);
|
||||
break;
|
||||
case "notNull":
|
||||
List<AndOrCriteriaGroup> group2 = new ArrayList<>();
|
||||
group2.add(SqlBuilder.and(sqlTable.column(field), SqlBuilder.isNotEqualTo("")));
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotNull(), group2);
|
||||
break;
|
||||
case "==":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isEqualTo(fieldValue));
|
||||
break;
|
||||
case "<>":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotEqualTo(fieldValue));
|
||||
break;
|
||||
case "like":
|
||||
convertSqlServerLike();
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLike("%" + fieldValue + "%"));
|
||||
break;
|
||||
case "notLike":
|
||||
convertSqlServerLike();
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotLike("%" + fieldValue + "%"));
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
switch (operator) {
|
||||
case "null":
|
||||
List<AndOrCriteriaGroup> group = new ArrayList<>();
|
||||
group.add(SqlBuilder.or(sqlTable.column(field), SqlBuilder.isEqualTo("")));
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNull(), group);
|
||||
break;
|
||||
case "notNull":
|
||||
List<AndOrCriteriaGroup> group2 = new ArrayList<>();
|
||||
group2.add(SqlBuilder.and(sqlTable.column(field), SqlBuilder.isNotEqualTo("")));
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotNull(), group2);
|
||||
break;
|
||||
case "==":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isEqualTo(fieldValue));
|
||||
break;
|
||||
case "<>":
|
||||
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotEqualTo(fieldValue));
|
||||
|
||||
break;
|
||||
case "like":
|
||||
convertSqlServerLike();
|
||||
where.or(sqlTable.column(field), SqlBuilder.isLike("%" + fieldValue + "%"));
|
||||
break;
|
||||
case "notLike":
|
||||
convertSqlServerLike();
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotLike("%" + fieldValue + "%"));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NumControl extends MyType {
|
||||
@Override
|
||||
void judge(QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where, SqlTable sqlTable, String field) {
|
||||
// 转换数字类型;
|
||||
BigDecimal num1 = null;
|
||||
BigDecimal num2 = null;
|
||||
if (StringUtil.isNotEmpty(fieldValue)) {
|
||||
num1 = new BigDecimal(fieldValue);
|
||||
}
|
||||
if (StringUtil.isNotEmpty(fieldValue2)) {
|
||||
num2 = new BigDecimal(fieldValue2);
|
||||
}
|
||||
// 精度处理
|
||||
String fieldPrecisionValue;
|
||||
String fieldPrecisionValue2;
|
||||
if (StringUtils.isNotBlank(precision)) {
|
||||
String yunzhupaasNum = "0." + StringUtils.repeat("0", Integer.parseInt(precision));
|
||||
DecimalFormat numFormat = new DecimalFormat(yunzhupaasNum);
|
||||
fieldPrecisionValue = numFormat.format(new BigDecimal(fieldValue));
|
||||
num1 = new BigDecimal(fieldPrecisionValue);
|
||||
if (fieldValue2 != null) {
|
||||
fieldPrecisionValue2 = numFormat.format(new BigDecimal(fieldValue2));
|
||||
num2 = new BigDecimal(fieldPrecisionValue2);
|
||||
}
|
||||
}
|
||||
|
||||
if ("&&".equals(logic)) {
|
||||
switch (operator) {
|
||||
case "null":
|
||||
List<AndOrCriteriaGroup> group = new ArrayList<>();
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNull(), group);
|
||||
break;
|
||||
case "notNull":
|
||||
List<AndOrCriteriaGroup> group2 = new ArrayList<>();
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotNull(), group2);
|
||||
break;
|
||||
case "==":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isEqualTo(num1));
|
||||
break;
|
||||
case "<>":
|
||||
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotEqualTo(num1));
|
||||
|
||||
break;
|
||||
case ">":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isGreaterThan(num1));
|
||||
|
||||
break;
|
||||
case "<":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLessThan(num1));
|
||||
break;
|
||||
case ">=":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isGreaterThanOrEqualTo(num1));
|
||||
break;
|
||||
case "<=":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLessThanOrEqualTo(num1));
|
||||
break;
|
||||
case "between":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isGreaterThanOrEqualTo(num1));
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLessThanOrEqualTo(num2));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (operator) {
|
||||
case "null":
|
||||
List<AndOrCriteriaGroup> group = new ArrayList<>();
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNull(), group);
|
||||
break;
|
||||
case "notNull":
|
||||
List<AndOrCriteriaGroup> group2 = new ArrayList<>();
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotNull(), group2);
|
||||
break;
|
||||
case "==":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isEqualTo(num1));
|
||||
break;
|
||||
case "<>":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotEqualTo(num1));
|
||||
|
||||
break;
|
||||
case ">":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isGreaterThan(num1));
|
||||
break;
|
||||
case "<":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isLessThan(num1));
|
||||
break;
|
||||
case ">=":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isGreaterThanOrEqualTo(num1));
|
||||
break;
|
||||
case "<=":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isLessThanOrEqualTo(num1));
|
||||
break;
|
||||
case "between":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isGreaterThanOrEqualTo(num1));
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLessThanOrEqualTo(num2));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DateControl extends MyType {
|
||||
@Override
|
||||
void judge(QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where, SqlTable sqlTable, String field) {
|
||||
Long time = null;
|
||||
Long time2 = null;
|
||||
Date date = new Date();
|
||||
Date date2 = new Date();
|
||||
if (StringUtils.isNoneBlank(fieldValue)) {
|
||||
time = Long.valueOf(fieldValue);
|
||||
date = new Date(time);
|
||||
}
|
||||
if (StringUtils.isNoneBlank(fieldValue2)) {
|
||||
time2 = Long.valueOf(fieldValue2);
|
||||
// 日期类型的要加上当天的23:59:59
|
||||
if (YunzhupaasKeyConsts.DATE.equals(yunzhupaasKey)) {
|
||||
date2 = new Date(time2 + 60 * 60 * 24 * 1000 - 1000);
|
||||
} else {
|
||||
date2 = new Date(time2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ("&&".equals(logic)) {
|
||||
switch (operator) {
|
||||
case "null":
|
||||
List<AndOrCriteriaGroup> group = new ArrayList<>();
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNull(), group);
|
||||
break;
|
||||
case "notNull":
|
||||
List<AndOrCriteriaGroup> group2 = new ArrayList<>();
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotNull(), group2);
|
||||
break;
|
||||
case "==":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isEqualTo(date));
|
||||
break;
|
||||
case "<>":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotEqualTo(date));
|
||||
break;
|
||||
case ">":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isGreaterThan(date));
|
||||
break;
|
||||
case "<":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLessThan(date));
|
||||
break;
|
||||
case ">=":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isGreaterThanOrEqualTo(date));
|
||||
break;
|
||||
case "<=":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLessThanOrEqualTo(date));
|
||||
break;
|
||||
case "between":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isGreaterThanOrEqualTo(date));
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLessThanOrEqualTo(date2));
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
switch (operator) {
|
||||
case "null":
|
||||
List<AndOrCriteriaGroup> group = new ArrayList<>();
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNull(), group);
|
||||
break;
|
||||
case "notNull":
|
||||
List<AndOrCriteriaGroup> group2 = new ArrayList<>();
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotNull(), group2);
|
||||
break;
|
||||
case "==":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isEqualTo(date));
|
||||
break;
|
||||
case "<>":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotEqualTo(date));
|
||||
break;
|
||||
case ">":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isGreaterThan(date));
|
||||
break;
|
||||
case "<":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isLessThan(date));
|
||||
break;
|
||||
case ">=":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isGreaterThanOrEqualTo(date));
|
||||
break;
|
||||
case "<=":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isLessThanOrEqualTo(date));
|
||||
break;
|
||||
case "between":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isGreaterThanOrEqualTo(date));
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLessThanOrEqualTo(date2));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TimeControl extends MyType {
|
||||
@Override
|
||||
void judge(QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where, SqlTable sqlTable, String field) {
|
||||
if ("&&".equals(logic)) {
|
||||
switch (operator) {
|
||||
case "null":
|
||||
List<AndOrCriteriaGroup> group = new ArrayList<>();
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNull(), group);
|
||||
break;
|
||||
case "notNull":
|
||||
List<AndOrCriteriaGroup> group2 = new ArrayList<>();
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotNull(), group2);
|
||||
break;
|
||||
case "==":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isEqualTo(fieldValue));
|
||||
break;
|
||||
case "<>":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotEqualTo(fieldValue));
|
||||
break;
|
||||
case ">":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isGreaterThan(fieldValue));
|
||||
break;
|
||||
case "<":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLessThan(fieldValue));
|
||||
break;
|
||||
case ">=":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isGreaterThanOrEqualTo(fieldValue));
|
||||
break;
|
||||
case "<=":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLessThanOrEqualTo(fieldValue));
|
||||
break;
|
||||
case "between":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isGreaterThanOrEqualTo(fieldValue));
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLessThanOrEqualTo(fieldValue2));
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
switch (operator) {
|
||||
case "null":
|
||||
List<AndOrCriteriaGroup> group = new ArrayList<>();
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNull(), group);
|
||||
break;
|
||||
case "notNull":
|
||||
List<AndOrCriteriaGroup> group2 = new ArrayList<>();
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotNull(), group2);
|
||||
break;
|
||||
case "==":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isEqualTo(fieldValue));
|
||||
break;
|
||||
case "<>":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotEqualTo(fieldValue));
|
||||
break;
|
||||
case ">":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isGreaterThan(fieldValue));
|
||||
break;
|
||||
case "<":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isLessThan(fieldValue));
|
||||
break;
|
||||
case ">=":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isGreaterThanOrEqualTo(fieldValue));
|
||||
break;
|
||||
case "<=":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isLessThanOrEqualTo(fieldValue));
|
||||
break;
|
||||
case "between":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isGreaterThanOrEqualTo(fieldValue));
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLessThanOrEqualTo(fieldValue2));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下拉控件类型
|
||||
*/
|
||||
class SelectControl extends MyType {
|
||||
@Override
|
||||
void judge(QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where, SqlTable sqlTable, String field) {
|
||||
List list = new ArrayList<>();
|
||||
|
||||
if (selectIgnore.contains(yunzhupaasKey) && StringUtils.isBlank(fieldValue)) {
|
||||
fieldValue = "[]";
|
||||
}
|
||||
if ("&&".equals(logic)) {
|
||||
switch (operator) {
|
||||
case "null":
|
||||
List<AndOrCriteriaGroup> group = new ArrayList<>();
|
||||
if (!DbBase.ORACLE.equals(dbType)) {
|
||||
group.add(SqlBuilder.or(sqlTable.column(field), SqlBuilder.isEqualTo("")));
|
||||
}
|
||||
group.add(SqlBuilder.or(sqlTable.column(field), SqlBuilder.isEqualTo("[]")));
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNull(), group);
|
||||
break;
|
||||
case "notNull":
|
||||
List<AndOrCriteriaGroup> group2 = new ArrayList<>();
|
||||
if (!DbBase.ORACLE.equals(dbType)) {
|
||||
group2.add(SqlBuilder.and(sqlTable.column(field), SqlBuilder.isNotEqualTo("")));
|
||||
}
|
||||
group2.add(SqlBuilder.and(sqlTable.column(field), SqlBuilder.isNotEqualTo("[]")));
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotNull(), group2);
|
||||
break;
|
||||
case "==":
|
||||
convertSqlServerLike();
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLike(fieldValue));
|
||||
break;
|
||||
case "<>":
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotLike(fieldValue));
|
||||
break;
|
||||
case "like":
|
||||
convertSqlServerLike();
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLike("%" + fieldValue + "%"));
|
||||
break;
|
||||
case "notLike":
|
||||
convertSqlServerLike();
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotLike("%" + fieldValue + "%"));
|
||||
break;
|
||||
case "in":
|
||||
List<String> dataList = this.solveListValue(fieldValue);
|
||||
if (dataList.size() > 0) {
|
||||
List<AndOrCriteriaGroup> group3 = new ArrayList<>();
|
||||
String valueFirst = "";
|
||||
for (int i = 0; i < dataList.size(); i++) {
|
||||
String value = dataList.get(i);
|
||||
value = convertSqlServerLike(value);
|
||||
AndOrCriteriaGroup condition = null;
|
||||
if (i == 0) {
|
||||
valueFirst = value;
|
||||
} else {
|
||||
condition = SqlBuilder.or(sqlTable.column(field),
|
||||
SqlBuilder.isLike("%" + value + "%"));
|
||||
group3.add(condition);
|
||||
}
|
||||
|
||||
}
|
||||
where.and(sqlTable.column(field), SqlBuilder.isLike("%" + valueFirst + "%"), group3);
|
||||
}
|
||||
if (YunzhupaasKeyConsts.CASCADER.equals(yunzhupaasKey)
|
||||
|| YunzhupaasKeyConsts.COMSELECT.equals(yunzhupaasKey)
|
||||
|| YunzhupaasKeyConsts.ADDRESS.equals(yunzhupaasKey)) {
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotNull());
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotEqualTo("[]"));
|
||||
}
|
||||
break;
|
||||
case "notIn":
|
||||
List<String> dataList2 = this.solveListValue(fieldValue);
|
||||
if (dataList2.size() > 0) {
|
||||
for (int i = 0; i < dataList2.size(); i++) {
|
||||
String value = dataList2.get(i);
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotLike("%" + value + "%"));
|
||||
}
|
||||
}
|
||||
if (YunzhupaasKeyConsts.CASCADER.equals(yunzhupaasKey)
|
||||
|| YunzhupaasKeyConsts.COMSELECT.equals(yunzhupaasKey)
|
||||
|| YunzhupaasKeyConsts.ADDRESS.equals(yunzhupaasKey)) {
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotNull());
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotEqualTo("[]"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
switch (operator) {
|
||||
case "null":
|
||||
List<AndOrCriteriaGroup> group = new ArrayList<>();
|
||||
if (!DbBase.ORACLE.equals(dbType)) {
|
||||
group.add(SqlBuilder.or(sqlTable.column(field), SqlBuilder.isEqualTo("")));
|
||||
}
|
||||
group.add(SqlBuilder.or(sqlTable.column(field), SqlBuilder.isEqualTo("[]")));
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNull(), group);
|
||||
break;
|
||||
case "notNull":
|
||||
List<AndOrCriteriaGroup> group2 = new ArrayList<>();
|
||||
if (!DbBase.ORACLE.equals(dbType)) {
|
||||
group2.add(SqlBuilder.and(sqlTable.column(field), SqlBuilder.isNotEqualTo("")));
|
||||
}
|
||||
group2.add(SqlBuilder.and(sqlTable.column(field), SqlBuilder.isNotEqualTo("[]")));
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotNull(), group2);
|
||||
break;
|
||||
case "==":
|
||||
where.or(sqlTable.column(field), SqlBuilder.isEqualTo(fieldValue));
|
||||
break;
|
||||
case "<>":
|
||||
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotEqualTo(fieldValue));
|
||||
break;
|
||||
case "like":
|
||||
convertSqlServerLike();
|
||||
where.or(sqlTable.column(field), SqlBuilder.isLike("%" + fieldValue + "%"));
|
||||
break;
|
||||
case "notLike":
|
||||
convertSqlServerLike();
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotLike("%" + fieldValue + "%"));
|
||||
break;
|
||||
case "in":
|
||||
if (selectIgnore.contains(yunzhupaasKey)) {
|
||||
convertSqlServerLike();
|
||||
where.or(sqlTable.column(field), SqlBuilder.isLike(fieldValue));
|
||||
} else {
|
||||
if (list.size() > 0) {
|
||||
where.or(sqlTable.column(field), SqlBuilder.isIn(list));
|
||||
}
|
||||
|
||||
}
|
||||
if (YunzhupaasKeyConsts.CASCADER.equals(yunzhupaasKey)
|
||||
|| YunzhupaasKeyConsts.COMSELECT.equals(yunzhupaasKey)
|
||||
|| YunzhupaasKeyConsts.ADDRESS.equals(yunzhupaasKey)) {
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotNull());
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotEqualTo("[]"));
|
||||
}
|
||||
break;
|
||||
case "notIn":
|
||||
if (selectIgnore.contains(yunzhupaasKey)) {
|
||||
List<String> data = JsonUtil.getJsonToList(fieldValue, String.class);
|
||||
if (data.size() > 0) {
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotLike(data));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (list != null && list.size() > 0) {
|
||||
where.or(sqlTable.column(field), SqlBuilder.isNotIn(list));
|
||||
}
|
||||
|
||||
}
|
||||
if (YunzhupaasKeyConsts.CASCADER.equals(yunzhupaasKey)
|
||||
|| YunzhupaasKeyConsts.COMSELECT.equals(yunzhupaasKey)
|
||||
|| YunzhupaasKeyConsts.ADDRESS.equals(yunzhupaasKey)) {
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotNull());
|
||||
where.and(sqlTable.column(field), SqlBuilder.isNotEqualTo("[]"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<String> solveListValue(String fieldValue) {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
try {
|
||||
List<List> list = JsonUtil.getJsonToList(fieldValue, List.class);
|
||||
for (List listSub : list) {
|
||||
result.add(JSONArray.toJSONString(listSub));
|
||||
// 组织选择需要取最后每个数组最后一个
|
||||
String value = (String) listSub.get(listSub.size() - 1);
|
||||
result.add(value);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
List<String> list = JsonUtil.getJsonToList(fieldValue, String.class);
|
||||
result.add(JSONArray.toJSONString(list));
|
||||
result.addAll(list);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private abstract class MyType {
|
||||
abstract void judge(QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where, SqlTable sqlTable,
|
||||
String field);
|
||||
}
|
||||
|
||||
/**
|
||||
* SQLSERVER数据库 like括号语法
|
||||
*
|
||||
* @param val
|
||||
* @return
|
||||
*/
|
||||
private String convertSqlServerLike(String val) {
|
||||
if (DbBase.SQL_SERVER.equals(dbType)) {
|
||||
val = val.replaceAll("\\[", "[[]");
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
private void convertSqlServerLike() {
|
||||
if (DbBase.SQL_SERVER.equals(dbType)) {
|
||||
fieldValue = convertSqlServerLike(fieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import com.yunzhupaas.base.model.read.ReadEnum;
|
||||
import com.yunzhupaas.base.model.read.ReadListVO;
|
||||
import com.yunzhupaas.base.model.read.ReadModel;
|
||||
import com.yunzhupaas.util.FileUtil;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import lombok.Cleanup;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/8/20
|
||||
*/
|
||||
@Slf4j
|
||||
public class ReadFile {
|
||||
|
||||
|
||||
/**
|
||||
* 预览代码
|
||||
*
|
||||
* @param codePath
|
||||
* @return
|
||||
*/
|
||||
public static List<ReadListVO> priviewCode(String codePath) {
|
||||
File fileAll = new File(com.yunzhupaas.util.XSSEscape.escapePath(codePath));
|
||||
List<File> fileList = new ArrayList<>();
|
||||
if (fileAll.exists()) {
|
||||
FileUtil.getFile(fileAll, fileList);
|
||||
}
|
||||
Map<String, List<ReadModel>> data = new LinkedHashMap<>();
|
||||
for (int i = fileList.size() - 1; i >= 0; i--) {
|
||||
File file = fileList.get(i);
|
||||
String path = file.getAbsolutePath();
|
||||
ReadEnum readEnum = ReadEnum.getMessage(path);
|
||||
if (readEnum != null) {
|
||||
ReadModel readModel = new ReadModel();
|
||||
String fileContent = readFile(file);
|
||||
readModel.setFileContent(fileContent);
|
||||
readModel.setFileName(file.getName());
|
||||
readModel.setFileType(readEnum.getMessage());
|
||||
readModel.setId(RandomUtil.uuId());
|
||||
String folderName = FileUtil.getFileType(file);
|
||||
readModel.setFolderName(folderName);
|
||||
List<ReadModel> readModelList = data.get(readEnum.getMessage()) != null ? data.get(readEnum.getMessage()) : new ArrayList<>();
|
||||
readModelList.add(readModel);
|
||||
data.put(readEnum.getMessage(), readModelList);
|
||||
}
|
||||
}
|
||||
List<ReadListVO> list = new ArrayList<>();
|
||||
for (String fileName : data.keySet()) {
|
||||
ReadListVO listVO = new ReadListVO();
|
||||
listVO.setFileName(fileName);
|
||||
listVO.setChildren(data.get(fileName));
|
||||
listVO.setId(RandomUtil.uuId());
|
||||
list.add(listVO);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 读取指定目录下的文件
|
||||
*
|
||||
* @param path 文件的路径
|
||||
* @return 文件内容
|
||||
*/
|
||||
private static String readFile(File path) {
|
||||
String fileRead = "";
|
||||
try {
|
||||
//创建一个输入流对象
|
||||
@Cleanup InputStream is = new FileInputStream(path);
|
||||
@Cleanup ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int n;
|
||||
while ((n = is.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, n);
|
||||
}
|
||||
//释放资源
|
||||
is.close();
|
||||
fileRead = out.toString();
|
||||
} catch (IOException e) {
|
||||
log.error("代码生成器读取文件报错:" + e.getMessage());
|
||||
}
|
||||
return fileRead;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,275 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.yunzhupaas.base.Page;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.service.*;
|
||||
import com.yunzhupaas.database.model.dbfield.DbFieldModel;
|
||||
import com.yunzhupaas.database.model.dbfield.base.DbFieldModelBase;
|
||||
import com.yunzhupaas.database.model.dbtable.DbTableFieldModel;
|
||||
import com.yunzhupaas.database.model.entity.DbLinkEntity;
|
||||
import com.yunzhupaas.permission.entity.*;
|
||||
import com.yunzhupaas.permission.model.user.vo.UserByRoleVO;
|
||||
import com.yunzhupaas.permission.service.*;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.enums.DictionaryDataEnum;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.yunzhupaas.util.Constants.ADMIN_KEY;
|
||||
|
||||
/**
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2022/4/9 13:28
|
||||
*/
|
||||
@Component
|
||||
@DS("")
|
||||
public class ServiceBaseUtil {
|
||||
|
||||
@Autowired
|
||||
private DbLinkService dblinkService;
|
||||
@Autowired
|
||||
private DbTableService dbTableService;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataService;
|
||||
@Autowired
|
||||
private DictionaryTypeService dictionaryTypeService;
|
||||
@Autowired
|
||||
private UserRelationService userRelationService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
@Autowired
|
||||
private OrganizeService organizeService;
|
||||
@Autowired
|
||||
private PositionService positionService;
|
||||
@Autowired
|
||||
private BillRuleService billRuleService;
|
||||
@Autowired
|
||||
private DataInterfaceService dataInterfaceService;
|
||||
|
||||
//--------------------------------数据连接------------------------------
|
||||
public DbLinkEntity getDbLink(String dbLink) {
|
||||
DbLinkEntity link = StringUtil.isNotEmpty(dbLink) ? dblinkService.getInfo(dbLink) : null;
|
||||
return link;
|
||||
}
|
||||
|
||||
public void createTable(List<DbTableFieldModel> dbTable) throws Exception {
|
||||
for (DbTableFieldModel dbTableFieldModel : dbTable) {
|
||||
dbTableService.createTable(dbTableFieldModel);
|
||||
}
|
||||
}
|
||||
|
||||
public void addField(DbTableFieldModel dbTable) throws Exception {
|
||||
dbTableService.addField(dbTable);
|
||||
}
|
||||
|
||||
public List<DbFieldModelBase> getDbTableModel(String linkId, String table) throws Exception {
|
||||
List<DbFieldModel> dbFieldModelList = dbTableService.getDbTableModel(linkId, table).getDbFieldModelList();
|
||||
List<DbFieldModelBase> list = JsonUtil.getJsonToList(dbFieldModelList, DbFieldModelBase.class);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有字段
|
||||
*
|
||||
* @param linkId 链接名
|
||||
* @param table 表名
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public List<DbFieldModel> getFieldList(String linkId, String table) throws Exception {
|
||||
return dbTableService.getFieldList(linkId, table);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------数据字典------------------------------
|
||||
public List<DictionaryDataEntity> getDiList() {
|
||||
List<DictionaryDataEntity> dictionList = dictionaryDataService.getList(dictionaryTypeService.getInfoByEnCode(DictionaryDataEnum.FLOWWOEK_ENGINE.getDictionaryTypeId()).getId());
|
||||
return dictionList;
|
||||
}
|
||||
|
||||
public List<DictionaryDataEntity> getDictionName(List<String> id) {
|
||||
List<DictionaryDataEntity> dictionList = dictionaryDataService.getDictionName(id);
|
||||
return dictionList;
|
||||
}
|
||||
|
||||
//--------------------------------用户关系表------------------------------
|
||||
public List<UserRelationEntity> getListByUserIdAll(List<String> id) {
|
||||
List<UserRelationEntity> list = userRelationService.getListByUserIdAll(id);
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<UserRelationEntity> getListByObjectIdAll(List<String> id) {
|
||||
List<UserRelationEntity> list = userRelationService.getListByObjectIdAll(id);
|
||||
return list;
|
||||
}
|
||||
|
||||
public String getAdmin() {
|
||||
UserEntity admin = userService.getUserByAccount(ADMIN_KEY);
|
||||
return admin.getId();
|
||||
}
|
||||
|
||||
//--------------------------------用户------------------------------
|
||||
public List<UserEntity> getUserName(List<String> id) {
|
||||
List<UserEntity> list = getUserName(id, false);
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<UserEntity> getListByManagerId(String managerId) {
|
||||
List<UserEntity> list = StringUtil.isNotEmpty(managerId) ? userService.getListByManagerId(managerId, null) : new ArrayList<>();
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<UserEntity> getUserName(List<String> id, boolean enableMark) {
|
||||
List<UserEntity> list = userService.getUserName(id);
|
||||
if (enableMark) {
|
||||
list = list.stream().filter(t -> t.getEnabledMark() != 0).collect(Collectors.toList());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<UserEntity> getUserName(List<String> id, Pagination pagination) {
|
||||
List<UserEntity> list = userService.getUserName(id, pagination);
|
||||
return list;
|
||||
}
|
||||
|
||||
public UserEntity getUserInfo(String id) {
|
||||
UserEntity entity = null;
|
||||
if (StringUtil.isNotEmpty(id)) {
|
||||
entity = id.equalsIgnoreCase(ADMIN_KEY) ? userService.getUserByAccount(id) : userService.getInfo(id);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
public UserEntity getByRealName(String realName) {
|
||||
UserEntity entity = StringUtil.isNotEmpty(realName) ? userService.getByRealName(realName) : null;
|
||||
return entity;
|
||||
}
|
||||
|
||||
public List<UserByRoleVO> getListByAuthorize(String organizeId) {
|
||||
List<UserByRoleVO> list = userService.getListByAuthorize(organizeId, new Page());
|
||||
return list;
|
||||
}
|
||||
|
||||
//--------------------------------单据规则------------------------------
|
||||
public String getBillNumber(String enCode) {
|
||||
String billNo = "";
|
||||
try {
|
||||
billNo = billRuleService.getBillNumber(enCode, false);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return billNo;
|
||||
}
|
||||
|
||||
public void useBillNumber(String enCode) {
|
||||
billRuleService.useBillNumber(enCode);
|
||||
}
|
||||
|
||||
//--------------------------------角色------------------------------
|
||||
public List<RoleEntity> getListByIds(List<String> id) {
|
||||
List<RoleEntity> list = roleService.getListByIds(id, null, false);
|
||||
return list;
|
||||
}
|
||||
|
||||
//--------------------------------组织------------------------------
|
||||
public List<OrganizeEntity> getOrganizeName(List<String> id) {
|
||||
List<OrganizeEntity> list = organizeService.getOrganizeName(id);
|
||||
return list;
|
||||
}
|
||||
|
||||
public OrganizeEntity getOrganizeInfo(String id) {
|
||||
OrganizeEntity entity = StringUtil.isNotEmpty(id) ? organizeService.getInfo(id) : null;
|
||||
return entity;
|
||||
}
|
||||
|
||||
public OrganizeEntity getOrganizeFullName(String fullName) {
|
||||
OrganizeEntity entity = organizeService.getByFullName(fullName);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public List<OrganizeEntity> getOrganizeId(String organizeId) {
|
||||
List<OrganizeEntity> organizeList = new ArrayList<>();
|
||||
organizeService.getOrganizeId(organizeId, organizeList);
|
||||
Collections.reverse(organizeList);
|
||||
return organizeList;
|
||||
}
|
||||
|
||||
public List<OrganizeEntity> getDepartmentAll(String organizeId) {
|
||||
List<OrganizeEntity> departmentAll = organizeService.getDepartmentAll(organizeId);
|
||||
return departmentAll;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前组织名称(all-显示组织名,else 显示部门名)
|
||||
*
|
||||
* @param obj
|
||||
* @param showLevel
|
||||
* @return
|
||||
*/
|
||||
public String getCurrentOrganizeName(Object obj, String showLevel) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
String value = String.valueOf(obj);
|
||||
String orgName = "";
|
||||
if (value != null) {
|
||||
String orgId = "";
|
||||
try {
|
||||
List<String> jsonToList = JsonUtil.getJsonToList(value, String.class);
|
||||
orgId = jsonToList.get(jsonToList.size() - 1);
|
||||
} catch (Exception e) {
|
||||
orgId = value;
|
||||
}
|
||||
OrganizeEntity organizeEntity = this.getOrganizeInfo(orgId);
|
||||
if ("all".equals(showLevel)) {
|
||||
if (organizeEntity != null) {
|
||||
List<OrganizeEntity> organizeList = this.getOrganizeId(organizeEntity.getId());
|
||||
orgName = organizeList.stream().map(OrganizeEntity::getFullName).collect(Collectors.joining("/"));
|
||||
}
|
||||
} else {
|
||||
if (organizeEntity != null && "department".equals(organizeEntity.getCategory())) {
|
||||
orgName = organizeEntity.getFullName();
|
||||
} else {
|
||||
orgName = " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
return orgName;
|
||||
}
|
||||
|
||||
//--------------------------------岗位------------------------------
|
||||
public List<PositionEntity> getPositionName(List<String> id) {
|
||||
List<PositionEntity> list = positionService.getPositionName(id, false);
|
||||
return list;
|
||||
}
|
||||
|
||||
public PositionEntity getPositionFullName(String fullName) {
|
||||
PositionEntity entity = positionService.getByFullName(fullName);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public PositionEntity getPositionInfo(String id) {
|
||||
PositionEntity entity = StringUtil.isNotEmpty(id) ? positionService.getInfo(id) : null;
|
||||
return entity;
|
||||
}
|
||||
|
||||
//--------------------------------远端------------------------------
|
||||
public void infoToId(String interId, Map<String, String> parameterMap) {
|
||||
dataInterfaceService.infoToId(interId, null, parameterMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.yunzhupaas.base.entity.BillNumEntity;
|
||||
import com.yunzhupaas.base.service.BillNumService;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.model.visualJson.FieLdsModel;
|
||||
import com.yunzhupaas.model.visualJson.config.ConfigModel;
|
||||
import com.yunzhupaas.model.visualJson.config.PrefixSuffixModel;
|
||||
import com.yunzhupaas.model.visualJson.config.RuleConfig;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
import lombok.Synchronized;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
public class VisualBillUtil {
|
||||
@Autowired
|
||||
private BillNumService billNumService;
|
||||
|
||||
@Synchronized
|
||||
public Object getBillNumber(String visualId, FieLdsModel fieLdsModel, Map<String, Object> data, Object thisValue) {
|
||||
String yunzhupaasKey = fieLdsModel.getConfig().getYunzhupaasKey();
|
||||
if (YunzhupaasKeyConsts.BILLRULE.equals(yunzhupaasKey) && fieLdsModel.getConfig().getRuleType() != null
|
||||
&& Objects.equals(fieLdsModel.getConfig().getRuleType(), 2) && ObjectUtil.isEmpty(thisValue)) {
|
||||
ConfigModel config = fieLdsModel.getConfig();
|
||||
RuleConfig ruleConfig = config.getRuleConfig();
|
||||
Integer type = ruleConfig.getType();
|
||||
String flowId = null;
|
||||
if (data.get(FlowFormConstant.FLOWID) != null
|
||||
&& StringUtil.isNotEmpty(data.get(FlowFormConstant.FLOWID).toString())) {
|
||||
flowId = data.get(FlowFormConstant.FLOWID).toString();
|
||||
}
|
||||
|
||||
StringBuilder strNumber = new StringBuilder();
|
||||
// 前缀
|
||||
String preFixStr = setPreSuffFix(data, ruleConfig.getPrefixList());
|
||||
if (StringUtil.isNotEmpty(preFixStr) && preFixStr.length() > 100) {
|
||||
throw new DataException(MsgCode.VS027.get(config.getLabel()));
|
||||
}
|
||||
strNumber.append(preFixStr);
|
||||
|
||||
String ruleId = config.getFormId();
|
||||
BillNumEntity billNum = billNumService.getBillNum(ruleId, visualId, flowId);
|
||||
switch (type) {
|
||||
case 2:
|
||||
// 随机数编号
|
||||
if (ObjectUtil.equal(ruleConfig.getRandomType(), 1)) {
|
||||
strNumber.append(cn.hutool.core.util.RandomUtil.randomNumbers(ruleConfig.getRandomDigit()));
|
||||
} else {
|
||||
strNumber.append(cn.hutool.core.util.RandomUtil.randomStringUpper(ruleConfig.getRandomDigit()));
|
||||
}
|
||||
if (billNum != null) {
|
||||
billNumService.removeByRuleId(ruleId, visualId, flowId);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
// UUID
|
||||
strNumber.append(IdUtil.randomUUID().toUpperCase());
|
||||
if (billNum != null) {
|
||||
billNumService.removeByRuleId(ruleId, visualId, flowId);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// 时间格式
|
||||
RuleConfig rule = BeanUtil.copyProperties(ruleConfig, RuleConfig.class);
|
||||
rule.setRandomDigit(null);
|
||||
rule.setRandomType(null);
|
||||
String ruleJosn = JsonUtil.getObjectToString(rule);
|
||||
|
||||
String dateFormat = getTimeFormat(ruleConfig.getDateFormat());
|
||||
String dateValue = "no".equals(dateFormat) ? "" : DateUtil.dateNow(dateFormat);
|
||||
// 获取位数最大值
|
||||
Integer digit = ruleConfig.getDigit();
|
||||
StringBuilder maxStr = new StringBuilder();
|
||||
for (int i = 0; i < digit; i++) {
|
||||
maxStr.append("9");
|
||||
}
|
||||
Integer maxValue = Integer.parseInt(maxStr.toString());
|
||||
// 起始值
|
||||
Integer startNumber = Integer.parseInt(ruleConfig.getStartNumber());
|
||||
Integer thisNum = 0;
|
||||
|
||||
// 处理流水号归0
|
||||
if (billNum != null) {
|
||||
if (ruleJosn.equals(billNum.getRuleConfig())) {
|
||||
String dateValueOld = billNum.getDateValue();
|
||||
// 判断时间值是否一致,一致流水号递增,不一致则重置流水号
|
||||
if (StringUtil.isEmpty(dateValueOld) || dateValueOld.equals(dateValue)) {
|
||||
thisNum = billNum.getNum() + 1;
|
||||
if (startNumber + thisNum > maxValue) {
|
||||
thisNum = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
billNum = new BillNumEntity();
|
||||
}
|
||||
billNum.setRuleId(ruleId);
|
||||
billNum.setVisualId(visualId);
|
||||
billNum.setFlowId(flowId);
|
||||
billNum.setDateValue(dateValue);
|
||||
billNum.setNum(thisNum);
|
||||
billNum.setRuleConfig(ruleJosn);
|
||||
billNumService.saveBillNum(billNum);
|
||||
|
||||
if (!"no".equals(dateValue)) {
|
||||
strNumber.append(dateValue);
|
||||
}
|
||||
strNumber.append(
|
||||
PadUtil.padRight(String.valueOf(startNumber + thisNum), ruleConfig.getDigit(), '0'));
|
||||
break;
|
||||
}
|
||||
// 后缀
|
||||
String suffFixStr = setPreSuffFix(data, ruleConfig.getSuffixList());
|
||||
if (StringUtil.isNotEmpty(suffFixStr) && suffFixStr.length() > 100) {
|
||||
throw new DataException(MsgCode.VS027.get(config.getLabel()));
|
||||
}
|
||||
strNumber.append(suffFixStr);
|
||||
return strNumber.toString();
|
||||
} else {
|
||||
return thisValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时间格式
|
||||
*
|
||||
* @param dateFor
|
||||
* @return
|
||||
*/
|
||||
private static String getTimeFormat(String dateFor) {
|
||||
String dateForValue = "no";
|
||||
if (StringUtil.isEmpty(dateFor)) {
|
||||
return dateForValue;
|
||||
}
|
||||
switch (dateFor) {
|
||||
case "YYYY":
|
||||
dateForValue = "yyyy";
|
||||
break;
|
||||
case "YYYYMM":
|
||||
dateForValue = "yyyyMM";
|
||||
break;
|
||||
case "YYYYMMDD":
|
||||
dateForValue = "yyyyMMdd";
|
||||
break;
|
||||
case "YYYYMMDDHH":
|
||||
dateForValue = "yyyyMMddHH";
|
||||
break;
|
||||
case "YYYYMMDDHHmm":
|
||||
dateForValue = "yyyyMMddHHmm";
|
||||
break;
|
||||
case "YYYYMMDDHHmmss":
|
||||
dateForValue = "yyyyMMddHHmmss";
|
||||
break;
|
||||
case "YYYYMMDDHHmmssSSS":
|
||||
dateForValue = "yyyyMMddHHmmssSSS";
|
||||
break;
|
||||
}
|
||||
return dateForValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置前后缀的值
|
||||
*
|
||||
* @param data
|
||||
* @param list
|
||||
*/
|
||||
private static String setPreSuffFix(Map<String, Object> data, List<PrefixSuffixModel> list) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
for (PrefixSuffixModel prefix : list) {
|
||||
// sourtype = 2自定义,1表单字段
|
||||
if (Objects.equals(prefix.getSourceType(), 2)) {
|
||||
sb.append(prefix.getRelationField());
|
||||
} else {
|
||||
if (StringUtil.isNotEmpty(prefix.getRelationField())
|
||||
&& data.get(prefix.getRelationField()) != null) {
|
||||
sb.append(data.get(prefix.getRelationField()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,376 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yunzhupaas.base.model.dbtable.vo.DbFieldVO;
|
||||
import com.yunzhupaas.base.model.form.VisualTableModel;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.database.constant.DbFieldConst;
|
||||
import com.yunzhupaas.database.datatype.viewshow.constant.DtViewConst;
|
||||
import com.yunzhupaas.database.model.dbfield.DbFieldModel;
|
||||
import com.yunzhupaas.database.model.dbtable.DbTableFieldModel;
|
||||
import com.yunzhupaas.database.model.entity.DbLinkEntity;
|
||||
import com.yunzhupaas.database.source.DbBase;
|
||||
import com.yunzhupaas.database.util.DataSourceUtil;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.model.visualJson.FieLdsModel;
|
||||
import com.yunzhupaas.model.visualJson.TableFields;
|
||||
import com.yunzhupaas.model.visualJson.TableModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormAllModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormColumnTableModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormEnum;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.TableFeildsEnum;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2022/3/25 9:30
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class VisualDevTableCre {
|
||||
@Autowired
|
||||
private ServiceBaseUtil serviceUtil;
|
||||
@Autowired
|
||||
private DataSourceUtil dataSourceUtil;
|
||||
|
||||
/**
|
||||
* 表单赋值tableName
|
||||
*
|
||||
* @param jsonArray
|
||||
* @param tableModels
|
||||
*/
|
||||
private void fieldsTableName(JSONArray jsonArray, List<TableModel> tableModels) {
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
|
||||
String yunzhupaaskey = jsonObject.getJSONObject("__config__").getString("yunzhupaasKey");
|
||||
List<String> childrenListAll = new ArrayList() {
|
||||
{
|
||||
add(FormEnum.card.getMessage());
|
||||
add(FormEnum.row.getMessage());
|
||||
add(FormEnum.tab.getMessage());
|
||||
add(FormEnum.collapse.getMessage());
|
||||
add(FormEnum.collapseItem.getMessage());
|
||||
add(FormEnum.tabItem.getMessage());
|
||||
add(FormEnum.tableGrid.getMessage());
|
||||
add(FormEnum.tableGridTr.getMessage());
|
||||
add(FormEnum.tableGridTd.getMessage());
|
||||
add(FormEnum.STEPS.getMessage());
|
||||
add(FormEnum.STEP_ITEM.getMessage());
|
||||
}
|
||||
};
|
||||
if (childrenListAll.contains(yunzhupaaskey) || StringUtil.isEmpty(yunzhupaaskey)) {
|
||||
JSONArray childArray = jsonObject.getJSONObject("__config__").getJSONArray("children");
|
||||
this.fieldsTableName(childArray, tableModels);
|
||||
jsonObject.getJSONObject("__config__").put("children", childArray);
|
||||
} else if (FormEnum.table.getMessage().equals(yunzhupaaskey)) {
|
||||
JSONArray childrenList = new JSONArray();
|
||||
JSONArray children = jsonObject.getJSONObject("__config__").getJSONArray("children");
|
||||
String tableModel = "";
|
||||
for (int k = 0; k < children.size(); k++) {
|
||||
JSONObject childrenObject = (JSONObject) children.get(k);
|
||||
this.fieldsModel(childrenObject, tableModels);
|
||||
if (StringUtil.isEmpty(tableModel)) {
|
||||
tableModel = childrenObject.getJSONObject("__config__").getString("relationTable");
|
||||
}
|
||||
childrenList.add(childrenObject);
|
||||
}
|
||||
jsonObject.getJSONObject("__config__").put("tableName", tableModel);
|
||||
jsonObject.getJSONObject("__config__").put("children", childrenList);
|
||||
} else {
|
||||
this.fieldsModel(jsonObject, tableModels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 赋值table
|
||||
*
|
||||
* @param jsonObject
|
||||
* @param tableModels
|
||||
*/
|
||||
private TableModel fieldsModel(JSONObject jsonObject, List<TableModel> tableModels) {
|
||||
String vModel = jsonObject.getString("__vModel__");
|
||||
String relationField = StringUtil.isNotEmpty(jsonObject.getString("relationField"))
|
||||
? jsonObject.getString("relationField")
|
||||
: "";
|
||||
String yunzhupaaskey = jsonObject.getJSONObject("__config__").getString("yunzhupaasKey");
|
||||
TableModel tableName = tableModels.stream().filter(t -> "1".equals(t.getTypeId())).findFirst().orElse(null);
|
||||
if (tableName != null) {
|
||||
jsonObject.getJSONObject("__config__").put("tableName", tableName.getTable());
|
||||
}
|
||||
List<TableModel> childTableAll = tableModels.stream().filter(t -> "0".equals(t.getTypeId()))
|
||||
.collect(Collectors.toList());
|
||||
TableModel childTableaa = childTableAll.stream()
|
||||
.filter(t -> t.getFields().stream().filter(k -> k.getField().equals(vModel)).count() > 0).findFirst()
|
||||
.orElse(null);
|
||||
if (childTableaa != null) {
|
||||
jsonObject.getJSONObject("__config__").put("relationTable", childTableaa.getTable());
|
||||
}
|
||||
if (FormEnum.relationFormAttr.getMessage().equals(yunzhupaaskey)
|
||||
|| FormEnum.popupAttr.getMessage().equals(yunzhupaaskey)) {
|
||||
if (StringUtil.isNotEmpty(relationField)) {
|
||||
Boolean isSubTable = jsonObject.getJSONObject("__config__").getBooleanValue("isSubTable");
|
||||
String model = relationField.split("_yunzhupaasTable_")[0];
|
||||
jsonObject.put("relationField",
|
||||
model + "_yunzhupaasTable_" + tableName.getTable() + (isSubTable ? "0" : "1"));
|
||||
}
|
||||
}
|
||||
if (YunzhupaasKeyConsts.BILLRULE.equals(yunzhupaaskey)) {
|
||||
if (StringUtil.isNotEmpty(relationField)) {
|
||||
Boolean isSubTable = jsonObject.getJSONObject("__config__").getBooleanValue("isSubTable");
|
||||
String model = relationField.split("_yunzhupaasTable_")[0];
|
||||
jsonObject.put("relationField",
|
||||
model + "_yunzhupaasTable_" + tableName.getTable() + (isSubTable ? "0" : "1"));
|
||||
}
|
||||
}
|
||||
return childTableaa;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<TableModel> tableList(VisualTableModel visualTableModel) throws WorkFlowException {
|
||||
JSONArray jsonArray = visualTableModel.getJsonArray();
|
||||
List<FormAllModel> formAllModel = visualTableModel.getFormAllModel();
|
||||
String table = visualTableModel.getTable();
|
||||
String linkId = visualTableModel.getLinkId();
|
||||
String fullName = visualTableModel.getFullName();
|
||||
int primaryKey = visualTableModel.getPrimaryKey();
|
||||
List<TableModel> tableModelList = new LinkedList<>();
|
||||
Map<String, String> tableNameList = new HashMap<>();
|
||||
DbLinkEntity dbLink = serviceUtil.getDbLink(linkId);
|
||||
String type = dbLink != null ? dbLink.getDbType() : dataSourceUtil.getDbType();
|
||||
boolean isUpperCase = (DbBase.DM.equals(type) || DbBase.ORACLE.equals(type));
|
||||
boolean isLowerCase = (DbBase.POSTGRE_SQL.equals(type) || DbBase.KINGBASE_ES.equals(type));
|
||||
table = tableName(table, isUpperCase, isLowerCase);
|
||||
|
||||
String relationField = tableName(TableFeildsEnum.FID.getField(), isUpperCase, isLowerCase);
|
||||
String tableField = tableName(TableFeildsEnum.FOREIGN.getField(), isUpperCase, isLowerCase);
|
||||
try {
|
||||
List<DbFieldModel> fieldList = new ArrayList<>();
|
||||
Map<String, List<DbFieldModel>> tableListAll = new HashMap<>();
|
||||
for (FormAllModel model : formAllModel) {
|
||||
if (FormEnum.mast.getMessage().equals(model.getYunzhupaasKey())) {
|
||||
FieLdsModel fieLdsModel = model.getFormColumnModel().getFieLdsModel();
|
||||
this.fieldList(fieLdsModel, table, fieldList);
|
||||
} else if (FormEnum.table.getMessage().equals(model.getYunzhupaasKey())) {
|
||||
String tableName = "ct" + RandomUtil.uuId();
|
||||
FormColumnTableModel fieLdsModel = model.getChildList();
|
||||
List<DbFieldModel> tableList = new ArrayList<>();
|
||||
String tableModel = fieLdsModel.getTableModel();
|
||||
List<FieLdsModel> fieldsList = fieLdsModel.getChildList().stream().map(t -> t.getFieLdsModel())
|
||||
.collect(Collectors.toList());
|
||||
for (FieLdsModel tableFieLdsModel : fieldsList) {
|
||||
this.fieldList(tableFieLdsModel, tableName, tableList);
|
||||
}
|
||||
this.dbTableField(tableList, true, primaryKey, isLowerCase, tableField, relationField);
|
||||
tableNameList.put(tableModel, tableName);
|
||||
tableListAll.put(tableModel, tableList);
|
||||
}
|
||||
}
|
||||
|
||||
this.dbTableField(fieldList, false, primaryKey, isLowerCase, tableField, relationField);
|
||||
fieldList.add(ConcurrencyUtils.getDbFieldModel(TableFeildsEnum.TENANTID, isUpperCase, isLowerCase));
|
||||
fieldList.add(ConcurrencyUtils.getDbFieldModel(TableFeildsEnum.FLOWID, isUpperCase, isLowerCase));
|
||||
fieldList.add(ConcurrencyUtils.getDbFieldModel(TableFeildsEnum.VERSION, isUpperCase, isLowerCase));
|
||||
fieldList.add(ConcurrencyUtils.getDbFieldModel(TableFeildsEnum.FLOWTASKID, isUpperCase, isLowerCase));
|
||||
if (visualTableModel.getLogicalDelete()) {// 删除标志字段
|
||||
fieldList.add(ConcurrencyUtils.getDbFieldModel(TableFeildsEnum.DELETEMARK, isUpperCase, isLowerCase));
|
||||
fieldList.add(ConcurrencyUtils.getDbFieldModel(TableFeildsEnum.DELETETIME, isUpperCase, isLowerCase));
|
||||
fieldList.add(ConcurrencyUtils.getDbFieldModel(TableFeildsEnum.DELETEUSERID, isUpperCase, isLowerCase));
|
||||
}
|
||||
List<DbTableFieldModel> dbTableList = new ArrayList<>();
|
||||
// 创建子表
|
||||
for (String key : tableListAll.keySet()) {
|
||||
String tableName = tableName(tableNameList.get(key), isUpperCase, isLowerCase);
|
||||
List<DbFieldModel> datableList = tableListAll.get(key);
|
||||
datableList.add(ConcurrencyUtils.getDbFieldModel(TableFeildsEnum.TENANTID, isUpperCase, isLowerCase));
|
||||
if (visualTableModel.getLogicalDelete()) {// 删除标志字段
|
||||
datableList.add(
|
||||
ConcurrencyUtils.getDbFieldModel(TableFeildsEnum.DELETEMARK, isUpperCase, isLowerCase));
|
||||
datableList.add(
|
||||
ConcurrencyUtils.getDbFieldModel(TableFeildsEnum.DELETETIME, isUpperCase, isLowerCase));
|
||||
datableList.add(
|
||||
ConcurrencyUtils.getDbFieldModel(TableFeildsEnum.DELETEUSERID, isUpperCase, isLowerCase));
|
||||
}
|
||||
DbTableFieldModel dbTable = this.dbTable(linkId, tableName, datableList, true, fullName);
|
||||
dbTableList.add(dbTable);
|
||||
this.tableModel(tableModelList, datableList, tableName, table, true, tableField, relationField);
|
||||
}
|
||||
this.tableModel(tableModelList, fieldList, table, table, false, tableField, relationField);
|
||||
DbTableFieldModel dbTable = this.dbTable(linkId, table, fieldList, false, fullName);
|
||||
dbTableList.add(dbTable);
|
||||
serviceUtil.createTable(dbTableList);
|
||||
this.fieldsTableName(jsonArray, tableModelList);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("表新增错误:{}", e.getMessage());
|
||||
throw new WorkFlowException(MsgCode.FM013.get(e.getMessage()), e);
|
||||
}
|
||||
return tableModelList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 表名
|
||||
*
|
||||
* @param tableName
|
||||
* @param isUpperCase
|
||||
* @param isLowerCase
|
||||
* @return
|
||||
*/
|
||||
private String tableName(String tableName, boolean isUpperCase, boolean isLowerCase) {
|
||||
String resultName = isUpperCase ? tableName.toUpperCase() : isLowerCase ? tableName.toLowerCase() : tableName;
|
||||
return resultName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表单字段
|
||||
*
|
||||
* @param fieLdsModel
|
||||
* @param tableList
|
||||
*/
|
||||
private void fieldList(FieLdsModel fieLdsModel, String table, List<DbFieldModel> tableList) {
|
||||
String vmodel = fieLdsModel.getVModel();
|
||||
String lable = fieLdsModel.getConfig().getLabel();
|
||||
String yunzhupaaskey = fieLdsModel.getConfig().getYunzhupaasKey();
|
||||
fieLdsModel.getConfig().setTableName(table);
|
||||
if (StringUtil.isNotEmpty(vmodel)) {
|
||||
DbFieldModel fieldForm = new DbFieldModel();
|
||||
fieldForm.setNullSign(DbFieldConst.NULL);
|
||||
fieldForm.setDataType(DtViewConst.VARCHAR);
|
||||
fieldForm.setLength("255");
|
||||
fieldForm.setIsPrimaryKey(false);
|
||||
if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
|
||||
if (YunzhupaasKeyConsts.getTextField().contains(yunzhupaaskey)) {
|
||||
fieldForm.setDataType(DtViewConst.TEXT);
|
||||
}
|
||||
List<String> date = new ArrayList() {
|
||||
{
|
||||
add(YunzhupaasKeyConsts.MODIFYTIME);
|
||||
add(YunzhupaasKeyConsts.CREATETIME);
|
||||
add(YunzhupaasKeyConsts.DATE);
|
||||
}
|
||||
};
|
||||
if (date.contains(yunzhupaaskey)) {
|
||||
fieldForm.setDataType(DtViewConst.DATE_TIME);
|
||||
}
|
||||
if (YunzhupaasKeyConsts.NUM_INPUT.equals(yunzhupaaskey)
|
||||
|| YunzhupaasKeyConsts.CALCULATE.equals(yunzhupaaskey)
|
||||
|| YunzhupaasKeyConsts.SLIDER.equals(yunzhupaaskey)) {
|
||||
fieldForm.setDataType(DtViewConst.DECIMAL);
|
||||
String precision = "15";
|
||||
if (fieLdsModel.getPrecision() != null) {
|
||||
precision = String.valueOf(fieLdsModel.getPrecision());
|
||||
}
|
||||
fieldForm.setLength("38," + precision);
|
||||
// mysql 最大长度65,Oracle和postgresql最大长度38,精度0-最大长度内取值,当前系统默认给15最大
|
||||
}
|
||||
|
||||
if (YunzhupaasKeyConsts.RATE.equals(yunzhupaaskey)) {
|
||||
fieldForm.setDataType(DtViewConst.DECIMAL);
|
||||
fieldForm.setLength("38,1");
|
||||
}
|
||||
|
||||
if (YunzhupaasKeyConsts.LOCATION.equals(yunzhupaaskey)) {
|
||||
fieldForm.setLength("500");
|
||||
}
|
||||
fieldForm.setField(vmodel);
|
||||
fieldForm.setComment(lable);
|
||||
tableList.add(fieldForm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建主外键字段
|
||||
*
|
||||
* @param tableList
|
||||
* @param isforeign
|
||||
*/
|
||||
private void dbTableField(List<DbFieldModel> tableList, boolean isforeign, int primaryKey,
|
||||
boolean isPostgreOrKingbase, String tableField, String relationField) {
|
||||
// 是否自增 true自增
|
||||
boolean autoPrimaryKey = primaryKey == 2;
|
||||
String dataType = autoPrimaryKey ? isPostgreOrKingbase ? DtViewConst.INT : DtViewConst.BIGINT
|
||||
: DtViewConst.VARCHAR;
|
||||
DbFieldModel tableKey = new DbFieldModel();
|
||||
tableKey.setNullSign(DbFieldConst.NOT_NULL);
|
||||
tableKey.setDataType(dataType);
|
||||
tableKey.setLength(TableFeildsEnum.FID.getLength());
|
||||
tableKey.setIsPrimaryKey(true);
|
||||
tableKey.setField(relationField);
|
||||
tableKey.setIsAutoIncrement(autoPrimaryKey);
|
||||
tableKey.setComment(TableFeildsEnum.FID.getComment());
|
||||
tableList.add(tableKey);
|
||||
if (isforeign) {
|
||||
DbFieldModel tableForeignKey = new DbFieldModel();
|
||||
tableForeignKey.setNullSign(DbFieldConst.NULL);
|
||||
tableForeignKey.setDataType(dataType);
|
||||
tableForeignKey.setLength(TableFeildsEnum.FOREIGN.getLength());
|
||||
tableForeignKey.setIsPrimaryKey(false);
|
||||
tableForeignKey.setField(tableField);
|
||||
tableForeignKey.setComment(TableFeildsEnum.FOREIGN.getComment());
|
||||
tableList.add(tableForeignKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装字段list
|
||||
*
|
||||
* @param tableModelList
|
||||
* @param dbtable
|
||||
* @param table
|
||||
* @param mastTable
|
||||
* @param isforeign
|
||||
*/
|
||||
private void tableModel(List<TableModel> tableModelList, List<DbFieldModel> dbtable, String table, String mastTable,
|
||||
boolean isforeign, String tableField, String relationField) {
|
||||
TableModel tableModel = new TableModel();
|
||||
tableModel.setRelationField(isforeign ? relationField : "");
|
||||
tableModel.setRelationTable(isforeign ? mastTable : "");
|
||||
tableModel.setTable(table);
|
||||
tableModel.setComment(isforeign ? "子表" : "主表");
|
||||
tableModel.setTableField(isforeign ? tableField : "");
|
||||
tableModel.setTypeId(isforeign ? "0" : "1");
|
||||
List<DbFieldVO> voList = dbtable.stream().map(DbFieldVO::new).collect(Collectors.toList());
|
||||
tableModel.setFields(JsonUtil.getJsonToList(voList, TableFields.class));
|
||||
tableModelList.add(tableModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装创表字段
|
||||
*
|
||||
* @param linkId
|
||||
* @param tableName
|
||||
* @param tableFieldList
|
||||
* @param isforeign
|
||||
* @return
|
||||
*/
|
||||
private DbTableFieldModel dbTable(String linkId, String tableName, List<DbFieldModel> tableFieldList,
|
||||
boolean isforeign, String fullName) {
|
||||
DbTableFieldModel dbTable = new DbTableFieldModel();
|
||||
dbTable.setDbLinkId(linkId);
|
||||
dbTable.setTable(tableName);
|
||||
dbTable.setDbFieldModelList(tableFieldList);
|
||||
String s = isforeign ? "子表" : "主表";
|
||||
if (fullName.contains("&")) {// 自动生成表备注的时候带&符号创建不成功问题
|
||||
fullName = fullName.replace("&", " ");
|
||||
}
|
||||
dbTable.setComment(String.format("%s-%s", fullName, s));
|
||||
return dbTable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,514 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import com.yunzhupaas.base.entity.ModuleDataAuthorizeSchemeEntity;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.model.ColumnDataModel;
|
||||
import com.yunzhupaas.base.model.Template6.BtnData;
|
||||
import com.yunzhupaas.base.model.Template6.ColumnListField;
|
||||
import com.yunzhupaas.base.model.VisualDevPubModel;
|
||||
import com.yunzhupaas.base.model.VisualWebTypeEnum;
|
||||
import com.yunzhupaas.base.model.online.AuthFlieds;
|
||||
import com.yunzhupaas.base.model.online.PerColModels;
|
||||
import com.yunzhupaas.base.model.online.VisualMenuModel;
|
||||
import com.yunzhupaas.base.util.common.DataControlUtils;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.constant.PermissionConst;
|
||||
import com.yunzhupaas.emnus.SearchMethodEnum;
|
||||
import com.yunzhupaas.model.OnlineDevData;
|
||||
import com.yunzhupaas.model.visualJson.*;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormAllModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormColumnModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormEnum;
|
||||
import com.yunzhupaas.model.visualJson.analysis.RecursionForm;
|
||||
import com.yunzhupaas.model.visualJson.config.ConfigModel;
|
||||
import com.yunzhupaas.permission.model.authorize.AuthorizeConditionEnum;
|
||||
import com.yunzhupaas.permission.model.authorize.ConditionModel;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/3/16
|
||||
*/
|
||||
public class VisualUtil {
|
||||
|
||||
public static List<String> symbol = new ArrayList() {
|
||||
{
|
||||
add(AuthorizeConditionEnum.USER.getCondition());
|
||||
add(AuthorizeConditionEnum.ORGANIZE.getCondition());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @return
|
||||
* @Description 删除F_, 且全转小写
|
||||
*/
|
||||
public static VisualdevEntity delfKey(VisualdevEntity entity) {
|
||||
|
||||
List<TableModel> list = JsonUtil.getJsonToList(entity.getVisualTables(), TableModel.class);
|
||||
|
||||
for (TableModel tableModel : list) {
|
||||
List<TableFields> fields = tableModel.getFields();
|
||||
if (StringUtil.isNotEmpty(tableModel.getTableField())
|
||||
&& "f_".equalsIgnoreCase(tableModel.getTableField().substring(0, 2))) {
|
||||
tableModel.setTableField(tableModel.getTableField().substring(2).toLowerCase());
|
||||
}
|
||||
if (StringUtil.isNotEmpty(tableModel.getRelationField())
|
||||
&& "f_".equalsIgnoreCase(tableModel.getRelationField().substring(0, 2))) {
|
||||
tableModel.setRelationField(tableModel.getRelationField().substring(2).toLowerCase());
|
||||
}
|
||||
for (TableFields tableFields : fields) {
|
||||
String feild = tableFields.getField().toLowerCase();
|
||||
if ("f_".equals(feild.substring(0, 2))) {
|
||||
tableFields.setField(feild.substring(2).toLowerCase());
|
||||
} else {
|
||||
tableFields.setField(feild.toLowerCase());
|
||||
}
|
||||
tableModel.setFields(fields);
|
||||
}
|
||||
}
|
||||
entity.setVisualTables(JsonUtil.getObjectToString(list));
|
||||
|
||||
// 取出列表数据中的查询列表和数据列表
|
||||
Map<String, Object> columnDataMap = JsonUtil.stringToMap(entity.getColumnData());
|
||||
if (columnDataMap != null) {
|
||||
for (Map.Entry<String, Object> entry : columnDataMap.entrySet()) {
|
||||
if ("searchList".equals(entry.getKey())) {
|
||||
List<FieLdsModel> fieLdsModelList = JsonUtil.getJsonToList(entry.getValue(), FieLdsModel.class);
|
||||
for (FieLdsModel fieLdsModel : fieLdsModelList) {
|
||||
String vModel = fieLdsModel.getVModel().toLowerCase();
|
||||
String modelStr = fieLdsModel.getVModel();
|
||||
// 去除F_
|
||||
if (!StringUtil.isEmpty(vModel) && "f_".equals(vModel.substring(0, 2))) {
|
||||
fieLdsModel.setVModel(modelStr.substring(2).toLowerCase());
|
||||
} else if (!StringUtil.isEmpty(vModel)) {
|
||||
fieLdsModel.setVModel(modelStr.toLowerCase());
|
||||
}
|
||||
|
||||
}
|
||||
entry.setValue(fieLdsModelList);
|
||||
}
|
||||
if ("columnList".equals(entry.getKey())) {
|
||||
List<ColumnListField> columnListFields = JsonUtil.getJsonToList(entry.getValue(),
|
||||
ColumnListField.class);
|
||||
for (ColumnListField columnListField : columnListFields) {
|
||||
String prop = columnListField.getProp().toLowerCase();
|
||||
String modelStr = columnListField.getProp();
|
||||
// 去除F_
|
||||
if (!StringUtil.isEmpty(prop) && "f_".equals(prop.substring(0, 2))) {
|
||||
columnListField.setProp(modelStr.substring(2).toLowerCase());
|
||||
} else if (!StringUtil.isEmpty(prop)) {
|
||||
columnListField.setProp(modelStr.toLowerCase());
|
||||
}
|
||||
}
|
||||
entry.setValue(columnListFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entity.setColumnData(JsonUtil.getObjectToString(columnDataMap));
|
||||
|
||||
Map<String, Object> formData = JsonUtil.stringToMap(entity.getFormData());
|
||||
|
||||
List<FieLdsModel> modelList = JsonUtil.getJsonToList(formData.get("fields").toString(), FieLdsModel.class);
|
||||
for (FieLdsModel fieLdsModel : modelList) {
|
||||
// 去除F_
|
||||
if (!StringUtil.isEmpty(fieLdsModel.getVModel())) {
|
||||
if ("f_".equals(fieLdsModel.getVModel().substring(0, 2).toLowerCase())) {
|
||||
String modelStr = fieLdsModel.getVModel();
|
||||
fieLdsModel.setVModel(modelStr.substring(2).toLowerCase());
|
||||
} else {
|
||||
String modelStr = fieLdsModel.getVModel();
|
||||
fieLdsModel.setVModel(modelStr.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
ConfigModel configModel = fieLdsModel.getConfig();
|
||||
// 子表
|
||||
if ("table".equals(configModel.getYunzhupaasKey())) {
|
||||
List<FieLdsModel> childlist = JsonUtil.getJsonToList(configModel.getChildren(), FieLdsModel.class);
|
||||
for (FieLdsModel childmodel : childlist) {
|
||||
// 前台界面的属性去掉前2个
|
||||
if (StringUtil.isNotEmpty(childmodel.getVModel())) {
|
||||
if ("f_".equals(childmodel.getVModel().substring(0, 2).toLowerCase())) {
|
||||
String vmodel = childmodel.getVModel().substring(2).toLowerCase();
|
||||
childmodel.setVModel(vmodel);
|
||||
} else {
|
||||
String vmodel = childmodel.getVModel().toLowerCase();
|
||||
childmodel.setVModel(vmodel);
|
||||
}
|
||||
}
|
||||
}
|
||||
fieLdsModel.getConfig().setChildren(childlist);
|
||||
}
|
||||
}
|
||||
formData.put("fields", JsonUtil.getObjectToString(modelList));
|
||||
entity.setFormData(JsonUtil.getObjectToString(formData));
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static VisualMenuModel getVisual(VisualdevEntity visualdevEntity, VisualDevPubModel visualDevPubModel) {
|
||||
VisualMenuModel visualMenuModel = new VisualMenuModel();
|
||||
visualMenuModel.setFullName(visualdevEntity.getFullName());
|
||||
visualMenuModel.setEncode(visualdevEntity.getEnCode());
|
||||
|
||||
if (!VisualWebTypeEnum.DATA_VIEW.getType().equals(visualdevEntity.getWebType())) {// 数据视图不解析formdata
|
||||
FormDataModel formDataModel = JsonUtil.getJsonToBean(visualdevEntity.getFormData(), FormDataModel.class);
|
||||
// 递归封装表单数据
|
||||
List<FormAllModel> formAllModel = new ArrayList<>();
|
||||
RecursionForm recursionForm = new RecursionForm();
|
||||
List<TableModel> tableModels = JsonUtil.getJsonToList(visualdevEntity.getVisualTables(), TableModel.class);
|
||||
TableModel tableModel = tableModels.stream().filter(t -> t.getTypeId().equals("1")).findFirst()
|
||||
.orElse(null);
|
||||
recursionForm.setTableModelList(tableModels);
|
||||
recursionForm.setList(JsonUtil.getJsonToList(formDataModel.getFields(), FieLdsModel.class));
|
||||
FormCloumnUtil.recursionForm(recursionForm, formAllModel);
|
||||
|
||||
// 主表数据
|
||||
List<FormAllModel> mast = formAllModel.stream()
|
||||
.filter(t -> FormEnum.mast.getMessage().equals(t.getYunzhupaasKey())).collect(Collectors.toList());
|
||||
// 列表子表数据
|
||||
List<FormAllModel> mastTable = formAllModel.stream()
|
||||
.filter(t -> FormEnum.mastTable.getMessage().equals(t.getYunzhupaasKey()))
|
||||
.collect(Collectors.toList());
|
||||
// 子表
|
||||
List<FormAllModel> childTable = formAllModel.stream()
|
||||
.filter(t -> FormEnum.table.getMessage().equals(t.getYunzhupaasKey())).collect(Collectors.toList());
|
||||
|
||||
String mainTableName = tableModel.getTable();
|
||||
List<AuthFlieds> allColumnDataList = new ArrayList<>();
|
||||
mast.stream().forEach(formModel -> {
|
||||
String vModel = formModel.getFormColumnModel().getFieLdsModel().getVModel();
|
||||
String tableName = formModel.getFormColumnModel().getFieLdsModel().getConfig().getTableName();
|
||||
if (StringUtil.isNotEmpty(vModel)) {
|
||||
String label = formModel.getFormColumnModel().getFieLdsModel().getConfig().getLabel();
|
||||
AuthFlieds authFlieds = AuthFlieds.builder().encode(vModel).fullName(label).status(false).rule(0)
|
||||
.bindTableName(tableName)
|
||||
.yunzhupaasKey(
|
||||
formModel.getFormColumnModel().getFieLdsModel().getConfig().getYunzhupaasKey())
|
||||
.build();
|
||||
allColumnDataList.add(authFlieds);
|
||||
}
|
||||
});
|
||||
mastTable.stream().forEach(formModel -> {
|
||||
String vModel = formModel.getFormMastTableModel().getMastTable().getFieLdsModel().getVModel();
|
||||
String tableName = formModel.getFormMastTableModel().getMastTable().getFieLdsModel().getConfig()
|
||||
.getTableName();
|
||||
if (StringUtil.isNotEmpty(vModel)) {
|
||||
String label = formModel.getFormMastTableModel().getMastTable().getFieLdsModel().getConfig()
|
||||
.getLabel();
|
||||
AuthFlieds authFlieds = AuthFlieds.builder().encode(vModel).fullName(label).status(false).rule(1)
|
||||
.bindTableName(tableName)
|
||||
.yunzhupaasKey(formModel.getFormMastTableModel().getMastTable().getFieLdsModel().getConfig()
|
||||
.getYunzhupaasKey())
|
||||
.build();
|
||||
allColumnDataList.add(authFlieds);
|
||||
}
|
||||
});
|
||||
|
||||
childTable.stream().forEach(formModel -> {
|
||||
String vModel = formModel.getChildList().getTableModel();
|
||||
String tableName = formModel.getChildList().getTableName();
|
||||
String label = formModel.getChildList().getLabel();
|
||||
if (StringUtil.isNotEmpty(vModel)) {
|
||||
AuthFlieds authFlieds = AuthFlieds.builder().encode(vModel).fullName(label).status(false).rule(0)
|
||||
.yunzhupaasKey(formModel.getYunzhupaasKey()).bindTableName(tableName).build();
|
||||
allColumnDataList.add(authFlieds);
|
||||
}
|
||||
List<FormColumnModel> childList = formModel.getChildList().getChildList();
|
||||
for (FormColumnModel columnModel : childList) {
|
||||
String childlabel = columnModel.getFieLdsModel().getConfig().getLabel();
|
||||
String childvModel = columnModel.getFieLdsModel().getVModel();
|
||||
if (StringUtil.isNotEmpty(childvModel)) {
|
||||
AuthFlieds authFlieds = AuthFlieds.builder().encode(vModel + "-" + childvModel)
|
||||
.fullName(label + "-" + childlabel).status(false).bindTableName(tableName).rule(2)
|
||||
.childTableKey(vModel)
|
||||
.yunzhupaasKey(columnModel.getFieLdsModel().getConfig().getYunzhupaasKey()).build();
|
||||
allColumnDataList.add(authFlieds);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 分配对应权限
|
||||
if (1 == visualDevPubModel.getPc()) {
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(visualdevEntity.getColumnData(),
|
||||
ColumnDataModel.class);
|
||||
visualMenuModel.setPcPerCols(new PerColModels());
|
||||
if (Objects.nonNull(columnDataModel)) {
|
||||
visualMenuModel
|
||||
.setPcPerCols(fillPermission(columnDataModel, allColumnDataList, true, mainTableName));
|
||||
}
|
||||
}
|
||||
|
||||
if (1 == visualDevPubModel.getApp()) {
|
||||
ColumnDataModel appColumnDataModel = JsonUtil.getJsonToBean(visualdevEntity.getAppColumnData(),
|
||||
ColumnDataModel.class);
|
||||
visualMenuModel.setAppPerCols(new PerColModels());
|
||||
if (Objects.nonNull(appColumnDataModel)) {
|
||||
visualMenuModel
|
||||
.setAppPerCols(fillPermission(appColumnDataModel, allColumnDataList, false, mainTableName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
visualMenuModel.setFullName(visualdevEntity.getFullName());
|
||||
visualMenuModel.setEncode(visualdevEntity.getEnCode());
|
||||
visualMenuModel.setId(visualdevEntity.getId());
|
||||
return visualMenuModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充权限字段
|
||||
*
|
||||
* @param columnDataModel
|
||||
* @param allColumnDataList
|
||||
* @param isPC
|
||||
* @return
|
||||
*/
|
||||
private static PerColModels fillPermission(ColumnDataModel columnDataModel, List<AuthFlieds> allColumnDataList,
|
||||
Boolean isPC, String mainTable) {
|
||||
PerColModels perColModel = new PerColModels();
|
||||
|
||||
List<ColumnListField> columnListFields = JsonUtil.getJsonToList(columnDataModel.getDefaultColumnList(),
|
||||
ColumnListField.class);
|
||||
// 副表正则
|
||||
String reg = "^[yunzhupaas_]\\S*_yunzhupaas\\S*";
|
||||
|
||||
// 按钮
|
||||
if (columnDataModel != null && columnDataModel.getUseBtnPermission()) {
|
||||
perColModel.setButtonPermission(getAuthFiledList(isPC, columnDataModel));
|
||||
}
|
||||
// 列表
|
||||
if (columnDataModel.getUseColumnPermission() && columnListFields != null) {
|
||||
List<AuthFlieds> colAuthFileds = columnListFields.stream().map(col -> {
|
||||
boolean matches = col.getProp().toLowerCase().matches(reg);
|
||||
String childTableKey = "";
|
||||
int rule = 0;
|
||||
String tableName;
|
||||
if (col.getConfig() == null) {
|
||||
tableName = mainTable;
|
||||
} else {
|
||||
tableName = col.getConfig().getRelationTable() != null ? col.getConfig().getRelationTable()
|
||||
: StringUtil.isNotEmpty(col.getConfig().getTableName()) ? col.getConfig().getTableName()
|
||||
: mainTable;
|
||||
}
|
||||
if (matches) {
|
||||
rule = 1;
|
||||
} else {
|
||||
rule = col.getProp().toLowerCase().contains(YunzhupaasKeyConsts.CHILD_TABLE_PREFIX) ? 2 : 0;
|
||||
childTableKey = col.getProp().toLowerCase().contains(YunzhupaasKeyConsts.CHILD_TABLE_PREFIX)
|
||||
? col.getProp().substring(0, col.getProp().indexOf("-"))
|
||||
: null;
|
||||
}
|
||||
return AuthFlieds.builder().encode(col.getProp()).fullName(col.getLabel()).status(col.getChecked())
|
||||
.rule(rule).bindTableName(tableName).childTableKey(childTableKey).build();
|
||||
}).collect(Collectors.toList());
|
||||
perColModel.setListPermission(colAuthFileds);
|
||||
}
|
||||
|
||||
// 表单
|
||||
if (columnDataModel.getUseFormPermission()) {
|
||||
List<AuthFlieds> formAuthList = allColumnDataList.stream().map(colFlied -> {
|
||||
return AuthFlieds.builder().encode(colFlied.getEncode()).fullName(colFlied.getFullName()).status(true)
|
||||
.rule(colFlied.getRule()).childTableKey(colFlied.getChildTableKey())
|
||||
.bindTableName(colFlied.getBindTableName()).build();
|
||||
}).collect(Collectors.toList());
|
||||
perColModel.setFormPermission(formAuthList);
|
||||
}
|
||||
|
||||
// 数据权限
|
||||
if (columnDataModel.getUseDataPermission() && columnListFields != null) {
|
||||
List<AuthFlieds> dataAuthFileds = new LinkedList<>();
|
||||
List<ColumnListField> mainColFieldList = columnListFields.stream()
|
||||
.filter(col -> !col.getProp().toLowerCase().matches(reg)
|
||||
&& !col.getProp().toLowerCase().contains(YunzhupaasKeyConsts.CHILD_TABLE_PREFIX))
|
||||
.collect(Collectors.toList());
|
||||
// 先取状态
|
||||
// mainColFieldList=
|
||||
// mainColFieldList.stream().filter(field->field.getChecked()).collect(Collectors.toList());
|
||||
// 去重
|
||||
mainColFieldList = mainColFieldList.stream()
|
||||
.filter(DataControlUtils.distinctByKey(data -> data.getYunzhupaasKey()))
|
||||
.collect(Collectors.toList());
|
||||
for (ColumnListField field : mainColFieldList) {
|
||||
String tableName = StringUtils.isNotEmpty(field.getConfig().getTableName())
|
||||
? field.getConfig().getTableName()
|
||||
: mainTable;
|
||||
if (YunzhupaasKeyConsts.CREATEUSER.equals(field.getYunzhupaasKey())) {
|
||||
AuthFlieds authFlied1 = AuthFlieds.builder().encode(field.getProp()).fullName(field.getLabel())
|
||||
.status(field.getChecked()).yunzhupaasKey(field.getYunzhupaasKey()).rule(0)
|
||||
.bindTableName(tableName).AuthCondition(AuthorizeConditionEnum.USER.getCondition())
|
||||
.id(RandomUtil.uuId()).build();
|
||||
AuthFlieds authFlied2 = AuthFlieds.builder().encode(field.getProp()).fullName(field.getLabel())
|
||||
.status(field.getChecked()).yunzhupaasKey(field.getYunzhupaasKey()).rule(0)
|
||||
.bindTableName(tableName).AuthCondition(AuthorizeConditionEnum.USERANDUNDER.getCondition())
|
||||
.id(RandomUtil.uuId()).build();
|
||||
dataAuthFileds.add(authFlied1);
|
||||
dataAuthFileds.add(authFlied2);
|
||||
} else if (YunzhupaasKeyConsts.CURRORGANIZE.equals(field.getYunzhupaasKey())) {
|
||||
AuthFlieds authFlied1 = AuthFlieds.builder().encode(field.getProp()).fullName(field.getLabel())
|
||||
.status(field.getChecked()).bindTableName(tableName)
|
||||
.yunzhupaasKey(field.getYunzhupaasKey()).rule(0)
|
||||
.AuthCondition(AuthorizeConditionEnum.ORGANIZE.getCondition())
|
||||
.id(RandomUtil.uuId()).build();
|
||||
AuthFlieds authFlied2 = AuthFlieds.builder().encode(field.getProp()).fullName(field.getLabel())
|
||||
.status(field.getChecked()).bindTableName(tableName)
|
||||
.yunzhupaasKey(field.getYunzhupaasKey()).rule(0)
|
||||
.AuthCondition(AuthorizeConditionEnum.ORGANIZEANDUNDER.getCondition())
|
||||
.id(RandomUtil.uuId()).build();
|
||||
AuthFlieds authFlied3 = AuthFlieds.builder().encode(field.getProp()).fullName(field.getLabel())
|
||||
.status(field.getChecked()).bindTableName(tableName)
|
||||
.yunzhupaasKey(field.getYunzhupaasKey()).rule(0)
|
||||
.AuthCondition(AuthorizeConditionEnum.BRANCHMANAGEORG.getCondition())
|
||||
.id(RandomUtil.uuId()).build();
|
||||
// AuthFlieds authFlied4 =
|
||||
// AuthFlieds.builder().encode(field.getProp()).fullName(field.getLabel()).status(field.getChecked()).bindTableName(tableName)
|
||||
// .yunzhupaasKey(field.getYunzhupaasKey()).rule(0).AuthCondition(AuthorizeConditionEnum.BRANCHMANAGEORGANIZEUNDER.getCondition())
|
||||
// .id(RandomUtil.uuId()).build();
|
||||
dataAuthFileds.add(authFlied1);
|
||||
dataAuthFileds.add(authFlied2);
|
||||
dataAuthFileds.add(authFlied3);
|
||||
// dataAuthFileds.add(authFlied4);
|
||||
}
|
||||
}
|
||||
perColModel.setDataPermission(dataAuthFileds);
|
||||
// 权限方案生成对象列表
|
||||
List<AuthFlieds> schemeAuthList = new ArrayList<>(dataAuthFileds);
|
||||
List<ModuleDataAuthorizeSchemeEntity> dataPermissionScheme = new ArrayList<>();
|
||||
for (AuthFlieds authFlieds : schemeAuthList) {
|
||||
String conditionSymbol = symbol.contains(authFlieds.getAuthCondition())
|
||||
? SearchMethodEnum.Equal.getSymbol()
|
||||
: SearchMethodEnum.Included.getSymbol();
|
||||
ModuleDataAuthorizeSchemeEntity schemeEntity = new ModuleDataAuthorizeSchemeEntity();
|
||||
schemeEntity.setFullName(getSchemeNameByCondition(authFlieds.getAuthCondition()));
|
||||
schemeEntity.setEnCode(RandomUtil.uuId());
|
||||
SearchMethodEnum searchMethod = SearchMethodEnum.getSearchMethod(conditionSymbol);
|
||||
String name = searchMethod != null ? searchMethod.getMessage() : "";
|
||||
String conditionText = "【{" + authFlieds.getFullName() + "} " + "{" + name + "}" + " {"
|
||||
+ authFlieds.getAuthCondition() + "}" + "】";
|
||||
List<ConditionModel> conditionModels = new ArrayList<>();
|
||||
ConditionModel conditionModel = new ConditionModel();
|
||||
conditionModel.setLogic(SearchMethodEnum.And.getSymbol());
|
||||
ConditionModel.ConditionItemModel conditionItemModel = conditionModel.new ConditionItemModel();
|
||||
conditionItemModel.setField(authFlieds.getEncode());
|
||||
conditionItemModel.setId(authFlieds.getId());
|
||||
conditionItemModel.setOp(conditionSymbol);
|
||||
conditionItemModel.setFieldRule(String.valueOf(authFlieds.getRule()));
|
||||
conditionItemModel.setValue(authFlieds.getAuthCondition());
|
||||
conditionItemModel.setConditionText(authFlieds.getAuthCondition());
|
||||
conditionItemModel.setType("Varchar");
|
||||
conditionItemModel.setBindTable(authFlieds.getBindTableName());
|
||||
List<ConditionModel.ConditionItemModel> groups = new ArrayList<>();
|
||||
groups.add(conditionItemModel);
|
||||
conditionModel.setGroups(groups);
|
||||
conditionModels.add(conditionModel);
|
||||
schemeEntity.setConditionJson(JsonUtil.getObjectToString(conditionModels));
|
||||
schemeEntity.setConditionText(conditionText);
|
||||
schemeEntity.setEnabledMark(1);
|
||||
schemeEntity
|
||||
.setDescription(authFlieds.getRule() + "_" + authFlieds.getEncode() + "_" + conditionSymbol);
|
||||
schemeEntity.setMatchLogic("and");// 添加方案时默认数据权限方案分组匹配逻辑为and
|
||||
schemeEntity.setSortCode(-9527l);
|
||||
dataPermissionScheme.add(schemeEntity);
|
||||
}
|
||||
// 数据权限方案
|
||||
perColModel.setDataPermissionScheme(dataPermissionScheme);
|
||||
}
|
||||
return perColModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统按钮集合
|
||||
*
|
||||
* @param isPC 是否pc端
|
||||
* @return
|
||||
*/
|
||||
private static List<AuthFlieds> getAuthFiledList(Boolean isPC, ColumnDataModel columnDataModel) {
|
||||
List<AuthFlieds> btnList = new ArrayList<>(6);
|
||||
String btnValues = AuthPerConfirm(columnDataModel);
|
||||
btnList.add(AuthFlieds.builder().fullName("新增").encode(PermissionConst.BTN_ADD).status(false).build());
|
||||
btnList.add(AuthFlieds.builder().fullName("编辑").encode(PermissionConst.BTN_EDIT).status(false).build());
|
||||
btnList.add(AuthFlieds.builder().fullName("删除").encode(PermissionConst.BTN_REMOVE).status(false).build());
|
||||
btnList.add(AuthFlieds.builder().fullName("详情").encode(PermissionConst.BTN_DETAIL).status(false).build());
|
||||
// pc端 按钮
|
||||
if (isPC) {
|
||||
btnList.add(AuthFlieds.builder().fullName("导入").encode(PermissionConst.BTN_UPLOAD).status(false).build());
|
||||
btnList.add(AuthFlieds.builder().fullName("导出").encode(PermissionConst.BTN_DOWNLOAD).status(false).build());
|
||||
btnList.add(AuthFlieds.builder().fullName("批量删除").encode(PermissionConst.BTN_BATCHREMOVE).status(false)
|
||||
.build());
|
||||
btnList.add(
|
||||
AuthFlieds.builder().fullName("批量打印").encode(PermissionConst.BTN_BATCHPRINT).status(false).build());
|
||||
}
|
||||
btnList.stream().filter(btn -> btnValues.contains(btn.getEncode().replace("btn_", "")))
|
||||
.forEach(btn -> btn.setStatus(true));
|
||||
// 自定义按钮区
|
||||
List<BtnData> CustomBtnList = JsonUtil.getJsonToList(columnDataModel.getCustomBtnsList(), BtnData.class);
|
||||
if (Objects.nonNull(CustomBtnList)) {
|
||||
List<AuthFlieds> CustomBtnAuth = CustomBtnList.stream().map(
|
||||
cus -> AuthFlieds.builder().fullName(cus.getLabel()).encode(cus.getValue()).status(true).build())
|
||||
.collect(Collectors.toList());
|
||||
btnList.addAll(CustomBtnAuth);
|
||||
}
|
||||
return btnList;
|
||||
}
|
||||
|
||||
private static String AuthPerConfirm(ColumnDataModel columnDataModel) {
|
||||
List<BtnData> btnDataList = new ArrayList<>();
|
||||
List<BtnData> BtnList = JsonUtil.getJsonToList(columnDataModel.getBtnsList(), BtnData.class);
|
||||
List<BtnData> ColumnBtnList = JsonUtil.getJsonToList(columnDataModel.getColumnBtnsList(), BtnData.class);
|
||||
|
||||
btnDataList.addAll(BtnList);
|
||||
btnDataList.addAll(ColumnBtnList);
|
||||
|
||||
String btnValue = btnDataList.stream().filter(t -> t.isShow()).map(btn -> btn.getValue())
|
||||
.collect(Collectors.joining(","));
|
||||
return btnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检验是否可发布
|
||||
*
|
||||
* @param entity
|
||||
* @param Action
|
||||
* @return
|
||||
*/
|
||||
public static String checkPublishVisualModel(VisualdevEntity entity, String Action) {
|
||||
String errorMsg = null;
|
||||
if (OnlineDevData.FORM_TYPE_DEV.equals(entity.getType())) {
|
||||
// 数据视图没有formdata
|
||||
if (!VisualWebTypeEnum.DATA_VIEW.getType().equals(entity.getWebType())) {
|
||||
FormDataModel formDataModel = JsonUtil.getJsonToBean(entity.getFormData(), FormDataModel.class);
|
||||
errorMsg = formDataModel == null ? MsgCode.VS401.get() + Action + "!" : null;
|
||||
}
|
||||
if (StringUtil.isNotEmpty(errorMsg)) {
|
||||
return errorMsg;
|
||||
}
|
||||
if (VisualWebTypeEnum.FORM_LIST.getType().equals(entity.getWebType())
|
||||
|| VisualWebTypeEnum.DATA_VIEW.getType().equals(entity.getWebType())) {
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(entity.getColumnData(), ColumnDataModel.class);
|
||||
errorMsg = columnDataModel == null ? MsgCode.VS402.get() + Action + "!" : null;
|
||||
}
|
||||
}
|
||||
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
private static String getSchemeNameByCondition(String condition) {
|
||||
String name = "default";
|
||||
AuthorizeConditionEnum byMessage = AuthorizeConditionEnum.getByMessage(condition);
|
||||
if (byMessage != null) {
|
||||
name = byMessage.getMessage();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,649 @@
|
||||
package com.yunzhupaas.base.util;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.xuyanwu.spring.file.storage.FileInfo;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.model.ColumnDataModel;
|
||||
import com.yunzhupaas.base.model.ExportSelectedModel;
|
||||
import com.yunzhupaas.base.model.Template6.ColumnListField;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.database.model.dbtable.JdbcTableModel;
|
||||
import com.yunzhupaas.database.model.interfaces.DbSourceOrDbLink;
|
||||
import com.yunzhupaas.excel.ExcelExportStyler;
|
||||
import com.yunzhupaas.excel.ExcelHelper;
|
||||
import com.yunzhupaas.model.ExcelModel;
|
||||
import com.yunzhupaas.model.visualJson.FieLdsModel;
|
||||
import com.yunzhupaas.model.visualJson.FormDataModel;
|
||||
import com.yunzhupaas.model.visualJson.config.HeaderModel;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.util.context.SpringContext;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
import lombok.Cleanup;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 可视化工具类
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024年3月13日16:37:40
|
||||
*/
|
||||
@Slf4j
|
||||
public class VisualUtils {
|
||||
|
||||
private static ConfigValueUtil configValueUtil = SpringContext.getBean(ConfigValueUtil.class);
|
||||
|
||||
private static FileInfo getFileInfo(MultipartFile multipartFile, String fileName) {
|
||||
String temporaryFilePath = configValueUtil.getTemporaryFilePath();
|
||||
FileInfo fileInfo = FileUploadUtils.uploadFile(multipartFile, temporaryFilePath, fileName);
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除多级嵌套控件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List<FieLdsModel> deleteMoreVmodel(FieLdsModel model) {
|
||||
if ("".equals(model.getVModel()) && model.getConfig().getChildren() != null) {
|
||||
List<FieLdsModel> childModelList = JsonUtil.getJsonToList(model.getConfig().getChildren(),
|
||||
FieLdsModel.class);
|
||||
return childModelList;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回主键名称
|
||||
*
|
||||
* @param dbSourceOrDbLink
|
||||
* @param mainTable
|
||||
* @return
|
||||
*/
|
||||
public static String getpKey(DbSourceOrDbLink dbSourceOrDbLink, String mainTable) throws SQLException {
|
||||
String pKeyName = "f_id";
|
||||
// catalog 数据库名
|
||||
String tmpKey = JdbcTableModel.getPrimaryExculde(dbSourceOrDbLink, mainTable,
|
||||
configValueUtil.getMultiTenantColumn());
|
||||
if (StrUtil.isNotEmpty(tmpKey)) {
|
||||
pKeyName = tmpKey;
|
||||
}
|
||||
return pKeyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出在线开发的表格
|
||||
*
|
||||
* @param visualdevEntity
|
||||
* @param list
|
||||
* @param keys
|
||||
* @param sheetName
|
||||
* @param excelModel
|
||||
* @return
|
||||
*/
|
||||
public static DownloadVO createModelExcel(VisualdevEntity visualdevEntity, List<Map<String, Object>> list,
|
||||
Collection<String> keys, String sheetName, String preName, ExcelModel excelModel) {
|
||||
// 判断sheetName
|
||||
boolean SheetTitleWithField = !sheetName.equals("表单信息");
|
||||
DownloadVO vo = DownloadVO.builder().build();
|
||||
try {
|
||||
// 去除空数据
|
||||
List<Map<String, Object>> dataList = new ArrayList<>();
|
||||
for (Map<String, Object> map : list) {
|
||||
int i = 0;
|
||||
for (String key : keys) {
|
||||
// 子表
|
||||
if (key.toLowerCase().startsWith(YunzhupaasKeyConsts.CHILD_TABLE_PREFIX)) {
|
||||
String tableField = key.substring(0, key.indexOf("-"));
|
||||
String field = key.substring(key.indexOf("-") + 1);
|
||||
Object o = map.get(tableField);
|
||||
if (o != null) {
|
||||
List<Map<String, Object>> childList = (List<Map<String, Object>>) o;
|
||||
for (Map<String, Object> childMap : childList) {
|
||||
if (childMap.get(field) != null) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Object o = map.get(key);
|
||||
if (o != null) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (map.get("errorsInfo") != null) {
|
||||
i++;
|
||||
}
|
||||
if (i > 0) {
|
||||
dataList.add(map);
|
||||
}
|
||||
}
|
||||
|
||||
FormDataModel formDataModel = JsonUtil.getJsonToBean(visualdevEntity.getFormData(), FormDataModel.class);
|
||||
List<FieLdsModel> fieLdsModelList = JsonUtil.getJsonToList(formDataModel.getFields(), FieLdsModel.class);
|
||||
// 递归
|
||||
List<FieLdsModel> allFields = new ArrayList<>();
|
||||
recursionFields(fieLdsModelList, allFields);
|
||||
|
||||
Map<String, String> mainMap = new HashMap<>();
|
||||
allFields.stream().filter(a -> !a.getConfig().getYunzhupaasKey().equals(YunzhupaasKeyConsts.CHILD_TABLE))
|
||||
.forEach(m -> mainMap.put(m.getVModel(), m.getConfig().getLabel()));
|
||||
List<FieLdsModel> childFields = allFields.stream()
|
||||
.filter(a -> a.getConfig().getYunzhupaasKey().equals(YunzhupaasKeyConsts.CHILD_TABLE))
|
||||
.collect(Collectors.toList());
|
||||
// 创建导出属性对象
|
||||
List<ExportSelectedModel> allExportModelList = new ArrayList<>();
|
||||
for (String key : keys) {
|
||||
ExportSelectedModel exportSelectedModel = new ExportSelectedModel();
|
||||
if (key.toLowerCase().startsWith(YunzhupaasKeyConsts.CHILD_TABLE_PREFIX)) {
|
||||
String tableField = key.substring(0, key.indexOf("-"));
|
||||
String field = key.substring(key.indexOf("-") + 1);
|
||||
FieLdsModel childTableModel = childFields.stream().filter(t -> tableField.equals(t.getVModel()))
|
||||
.findFirst().orElse(null);
|
||||
FieLdsModel fieldKey = childTableModel.getConfig().getChildren().stream()
|
||||
.filter(t -> field.equals(t.getVModel())).findFirst().orElse(null);
|
||||
String label = fieldKey.getConfig().getLabel();
|
||||
exportSelectedModel.setTableField(tableField);
|
||||
exportSelectedModel.setField(field);
|
||||
exportSelectedModel.setLabel(label);
|
||||
ExportSelectedModel childModel = allExportModelList.stream()
|
||||
.filter(t -> tableField.equals(t.getTableField())).findFirst().orElse(null);
|
||||
List<ExportSelectedModel> childList;
|
||||
if (childModel != null) {
|
||||
childList = childModel.getSelectedModelList();
|
||||
childList.add(exportSelectedModel);
|
||||
} else {
|
||||
childList = new ArrayList<>();
|
||||
childList.add(exportSelectedModel);
|
||||
ExportSelectedModel newChild = new ExportSelectedModel();
|
||||
newChild.setTableField(childTableModel.getVModel());
|
||||
newChild.setSelectedModelList(childList);
|
||||
newChild.setLabel(childTableModel.getConfig().getLabel());
|
||||
allExportModelList.add(newChild);
|
||||
}
|
||||
} else {
|
||||
exportSelectedModel.setField(key);
|
||||
exportSelectedModel.setLabel(mainMap.get(key));
|
||||
allExportModelList.add(exportSelectedModel);
|
||||
}
|
||||
}
|
||||
|
||||
List<ExcelExportEntity> entitys = new ArrayList<>();
|
||||
if (sheetName.equals("错误报告")) {
|
||||
entitys.add(new ExcelExportEntity("异常原因", "errorsInfo", 30));
|
||||
}
|
||||
for (ExportSelectedModel selectModel : allExportModelList) {
|
||||
ExcelExportEntity exportEntity;
|
||||
if (StringUtil.isNotEmpty(selectModel.getTableField())) {
|
||||
exportEntity = new ExcelExportEntity(
|
||||
selectModel.getLabel() + "(" + selectModel.getTableField() + ")",
|
||||
selectModel.getTableField());
|
||||
// +"("+selectModel.getTableField()+"-"+m.getField()+")"
|
||||
exportEntity.setList(selectModel.getSelectedModelList().stream().map(m -> new ExcelExportEntity(m
|
||||
.getLabel()
|
||||
+ (SheetTitleWithField ? "(" + selectModel.getTableField() + "-" + m.getField() + ")" : ""),
|
||||
m.getField())).collect(Collectors.toList()));
|
||||
} else {
|
||||
// +"("+selectModel.getField()+")"
|
||||
exportEntity = new ExcelExportEntity(
|
||||
selectModel.getLabel() + (SheetTitleWithField ? "(" + selectModel.getField() + ")" : ""),
|
||||
selectModel.getField());
|
||||
}
|
||||
entitys.add(exportEntity);
|
||||
}
|
||||
|
||||
// 原数据和表头用于合并处理
|
||||
List<ExcelExportEntity> mergerEntitys = new ArrayList<>(entitys);
|
||||
List<Map<String, Object>> mergerList = new ArrayList<>(list);
|
||||
|
||||
// 复杂表头-表头和数据处理
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(visualdevEntity.getColumnData(),
|
||||
ColumnDataModel.class);
|
||||
List<HeaderModel> complexHeaderList = columnDataModel.getComplexHeaderList();
|
||||
if (!Objects.equals(columnDataModel.getType(), 3) && !Objects.equals(columnDataModel.getType(), 5)) {
|
||||
// 数据导出判断是否是行内
|
||||
boolean isLineEidtExport = SheetTitleWithField ? Objects.equals(columnDataModel.getType(), 4) : false;
|
||||
entitys = complexHeaderHandel(entitys, complexHeaderList, isLineEidtExport);
|
||||
dataList = complexHeaderDataHandel(dataList, complexHeaderList, isLineEidtExport);
|
||||
}
|
||||
|
||||
ExportParams exportParams = new ExportParams(null, sheetName);
|
||||
exportParams.setStyle(ExcelExportStyler.class);
|
||||
if (sheetName.equals("错误报告")) {
|
||||
exportParams.setFreezeCol(1);
|
||||
}
|
||||
@Cleanup
|
||||
Workbook workbook = new HSSFWorkbook();
|
||||
if (entitys.size() > 0) {
|
||||
if (dataList.size() == 0) {
|
||||
dataList.add(new HashMap<>());
|
||||
}
|
||||
workbook = ExcelExportUtil.exportExcel(exportParams, entitys, dataList);
|
||||
mergerVertical(workbook, mergerEntitys, mergerList);
|
||||
|
||||
ExcelHelper helper = new ExcelHelper();
|
||||
helper.init(workbook, exportParams, entitys, excelModel);
|
||||
helper.doPreHandle();
|
||||
helper.doPostHandle();
|
||||
}
|
||||
|
||||
String fileName = preName + ".xls";
|
||||
if (sheetName.equals("错误报告")) {
|
||||
fileName = preName + "_" + DateUtil.dateNow("yyyyMMddHHmmss") + ".xls";
|
||||
}
|
||||
MultipartFile multipartFile = ExcelUtil.workbookToCommonsMultipartFile(workbook, fileName);
|
||||
FileInfo fileInfo = getFileInfo(multipartFile, fileName);
|
||||
vo.setName(fileInfo.getFilename());
|
||||
vo.setUrl(UploaderUtil.uploaderFile(fileInfo.getFilename() + "#" + "Temporary") + "&name=" + fileName);
|
||||
} catch (Exception e) {
|
||||
log.error("信息导出Excel错误:{}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
public static void recursionFields(List<FieLdsModel> fieLdsModelList, List<FieLdsModel> allFields) {
|
||||
for (FieLdsModel fieLdsModel : fieLdsModelList) {
|
||||
if (YunzhupaasKeyConsts.CHILD_TABLE.equals(fieLdsModel.getConfig().getYunzhupaasKey())) {
|
||||
allFields.add(fieLdsModel);
|
||||
} else {
|
||||
if (fieLdsModel.getConfig().getChildren() != null) {
|
||||
recursionFields(fieLdsModel.getConfig().getChildren(), allFields);
|
||||
} else {
|
||||
if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
|
||||
allFields.add(fieLdsModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 视图导出
|
||||
*
|
||||
* @param columnData
|
||||
* @param list
|
||||
* @param keys
|
||||
* @param sheetName
|
||||
* @param excelModel
|
||||
* @return
|
||||
*/
|
||||
public static DownloadVO createModelExcelApiData(String columnData, List<Map<String, Object>> list,
|
||||
Collection<String> keys, String sheetName, String preName, ExcelModel excelModel) {
|
||||
|
||||
// 判断sheetName
|
||||
DownloadVO vo = DownloadVO.builder().build();
|
||||
try {
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData, ColumnDataModel.class);
|
||||
List<ColumnListField> columnListAll = JsonUtil.getJsonToList(columnDataModel.getColumnList(),
|
||||
ColumnListField.class);
|
||||
List<ExcelExportEntity> entitys = new ArrayList<>();
|
||||
if (sheetName.equals("错误报告")) {
|
||||
entitys.add(new ExcelExportEntity("异常原因", "errorsInfo"));
|
||||
}
|
||||
for (ColumnListField selectModel : columnListAll) {
|
||||
if (keys.contains(selectModel.getProp())) {
|
||||
ExcelExportEntity exportEntity = new ExcelExportEntity(selectModel.getLabel());
|
||||
exportEntity.setKey(selectModel.getProp());
|
||||
exportEntity.setName(selectModel.getLabel());
|
||||
entitys.add(exportEntity);
|
||||
}
|
||||
}
|
||||
// 原数据和表头用于合并处理
|
||||
List<ExcelExportEntity> mergerEntitys = new ArrayList<>(entitys);
|
||||
List<Map<String, Object>> mergerList = new ArrayList<>(list);
|
||||
|
||||
// 复杂表头-表头和数据处理
|
||||
List<HeaderModel> complexHeaderList = columnDataModel.getComplexHeaderList();
|
||||
if (!Objects.equals(columnDataModel.getType(), 3) && !Objects.equals(columnDataModel.getType(), 5)) {
|
||||
entitys = complexHeaderHandel(entitys, complexHeaderList, false);
|
||||
list = complexHeaderDataHandel(list, complexHeaderList, false);
|
||||
}
|
||||
|
||||
ExportParams exportParams = new ExportParams(null, sheetName);
|
||||
exportParams.setStyle(ExcelExportStyler.class);
|
||||
if (sheetName.equals("错误报告")) {
|
||||
exportParams.setFreezeCol(1);
|
||||
}
|
||||
exportParams.setStyle(ExcelExportStyler.class);
|
||||
@Cleanup
|
||||
Workbook workbook = new HSSFWorkbook();
|
||||
if (entitys.size() > 0) {
|
||||
if (list.size() == 0) {
|
||||
list.add(new HashMap<>());
|
||||
}
|
||||
workbook = ExcelExportUtil.exportExcel(exportParams, entitys, list);
|
||||
|
||||
mergerVertical(workbook, mergerEntitys, mergerList);
|
||||
|
||||
ExcelHelper helper = new ExcelHelper();
|
||||
helper.init(workbook, exportParams, entitys, excelModel);
|
||||
helper.doPreHandle();
|
||||
helper.doPostHandle();
|
||||
}
|
||||
String fileName = preName + DateUtil.dateNow("yyyyMMddHHmmss") + ".xls";
|
||||
MultipartFile multipartFile = ExcelUtil.workbookToCommonsMultipartFile(workbook, fileName);
|
||||
FileInfo fileInfo = getFileInfo(multipartFile, fileName);
|
||||
vo.setName(fileInfo.getFilename());
|
||||
vo.setUrl(UploaderUtil.uploaderFile(fileInfo.getFilename() + "#" + "Temporary") + "&name=" + fileName);
|
||||
} catch (Exception e) {
|
||||
log.error("信息导出Excel错误:{}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
public static String exampleExcelMessage(FieLdsModel model) {
|
||||
String value = "";
|
||||
String yunzhupaasKey = model.getConfig().getYunzhupaasKey();
|
||||
boolean multiple = model.getMultiple();
|
||||
if (YunzhupaasKeyConsts.CHECKBOX.equals(yunzhupaasKey)) {
|
||||
value = "选项一,选项二";
|
||||
} else if (YunzhupaasKeyConsts.SELECT.equals(yunzhupaasKey)) {
|
||||
value = multiple ? "选项一,选项二" : "";
|
||||
} else if (YunzhupaasKeyConsts.CASCADER.equals(yunzhupaasKey)) {
|
||||
value = multiple ? "选项1/选项1-1,选项2/选项2-1" : "选项1/选项1-1";
|
||||
} else if (YunzhupaasKeyConsts.DATE.equals(yunzhupaasKey)) {
|
||||
value = model.getFormat();
|
||||
} else if (YunzhupaasKeyConsts.TIME.equals(yunzhupaasKey)) {
|
||||
value = model.getFormat();
|
||||
} else if (YunzhupaasKeyConsts.COMSELECT.equals(yunzhupaasKey)) {
|
||||
value = multiple ? "公司名称/部门名称,公司名称1/部门名称1" : "公司名称/部门名称";
|
||||
} else if (YunzhupaasKeyConsts.DEPSELECT.equals(yunzhupaasKey)) {
|
||||
value = multiple ? "部门名称/部门编码,部门名称1/部门编码1" : "部门名称/部门编码";
|
||||
} else if (YunzhupaasKeyConsts.POSSELECT.equals(yunzhupaasKey)) {
|
||||
value = multiple ? "岗位名称/岗位编码,岗位名称1/岗位编码1" : "岗位名称/岗位编码";
|
||||
} else if (YunzhupaasKeyConsts.USERSELECT.equals(yunzhupaasKey)) {
|
||||
value = multiple ? "姓名/账号,姓名1/账号1" : "姓名/账号";
|
||||
} else if (YunzhupaasKeyConsts.ROLESELECT.equals(yunzhupaasKey)) {
|
||||
value = multiple ? "角色名称/角色编码,角色名称1/角色编码1" : "角色名称/角色编码";
|
||||
} else if (YunzhupaasKeyConsts.GROUPSELECT.equals(yunzhupaasKey)) {
|
||||
value = multiple ? "分组名称/分组编码,分组名称1/分组编码1" : "分组名称/分组编码";
|
||||
} else if (YunzhupaasKeyConsts.CUSTOMUSERSELECT.equals(yunzhupaasKey)) {
|
||||
value = multiple ? "姓名/账号,公司名称,部门名称/部门编码,岗位名称/岗位编码,角色名称/角色编码,分组名称/分组编码" : "姓名/账号";
|
||||
} else if (YunzhupaasKeyConsts.TREESELECT.equals(yunzhupaasKey)) {
|
||||
value = multiple ? "选项1,选项2" : "选项1";
|
||||
} else if (YunzhupaasKeyConsts.ADDRESS.equals(yunzhupaasKey)) {
|
||||
// 0 省 1 省市 2 省市区 3 省市区
|
||||
Integer level = model.getLevel();
|
||||
if (level == 0) {
|
||||
value = multiple ? "省,省1" : "省";
|
||||
}
|
||||
if (level == 1) {
|
||||
value = multiple ? "省/市,省1/市1" : "省/市";
|
||||
}
|
||||
if (level == 2) {
|
||||
value = multiple ? "省/市/区,省1/市1/区1" : "省/市/区";
|
||||
}
|
||||
if (level == 3) {
|
||||
value = multiple ? "省/市/区/街道,省1/市1/区1/街道1" : "省/市/区/街道";
|
||||
}
|
||||
} else {
|
||||
value = "";
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 复杂表头表头处理--代码生成
|
||||
*
|
||||
* @param dataList
|
||||
* @param complexHeaderList
|
||||
* @return
|
||||
*/
|
||||
public static List<ExcelExportEntity> complexHeaderHandel(List<ExcelExportEntity> dataList,
|
||||
List<HeaderModel> complexHeaderList, boolean isLineEidtExport) {
|
||||
List<String> complexHeaderListStr = new ArrayList<>();
|
||||
complexHeaderList.forEach(item -> complexHeaderListStr.addAll(item.getChildColumns()));
|
||||
Map<String, Integer> complexMap1 = new HashMap<>();
|
||||
List<ExcelExportEntity> dataListRes = new ArrayList<>();
|
||||
int n = 0;// 记录新数组下标用的,(dataListRes.add的地方就要n++)
|
||||
for (ExcelExportEntity entity : dataList) {
|
||||
String entityKey = isLineEidtExport ? entity.getKey().toString().split("_name")[0]
|
||||
: entity.getKey().toString();
|
||||
if (complexHeaderListStr.contains(entityKey)) {
|
||||
for (HeaderModel item : complexHeaderList) {
|
||||
if (item.getChildColumns() != null && item.getChildColumns().size() > 0
|
||||
&& item.getChildColumns().contains(entityKey)) {
|
||||
ExcelExportEntity export;
|
||||
if (complexMap1.get(item.getId()) == null) {
|
||||
complexMap1.put(item.getId(), n);
|
||||
export = new ExcelExportEntity(item.getFullName() + "(" + item.getId() + ")", item.getId());
|
||||
List<ExcelExportEntity> list = new ArrayList<>();
|
||||
export.setList(list);
|
||||
dataListRes.add(export);
|
||||
n++;
|
||||
} else {
|
||||
export = dataListRes.get(complexMap1.get(item.getId()));
|
||||
}
|
||||
List<ExcelExportEntity> list = export.getList() != null ? export.getList() : new ArrayList<>();
|
||||
list.add(entity);
|
||||
export.setList(list);
|
||||
dataListRes.set(complexMap1.get(item.getId()), export);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dataListRes.add(entity);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
return dataListRes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 复杂表头数据处理
|
||||
*
|
||||
* @param dataListRes
|
||||
* @param complexHeaderList
|
||||
* @return
|
||||
*/
|
||||
public static List<Map<String, Object>> complexHeaderDataHandel(List<Map<String, Object>> dataListRes,
|
||||
List<HeaderModel> complexHeaderList, boolean isLineEidtExport) {
|
||||
List<String> complexHeaderListStr = new ArrayList<>();
|
||||
complexHeaderList.forEach(item -> complexHeaderListStr.addAll(item.getChildColumns()));
|
||||
List<String> complexMap1 = new ArrayList<>();
|
||||
List<Map<String, Object>> dataList = new ArrayList<>(dataListRes);
|
||||
for (Map<String, Object> map : dataList) {
|
||||
Set<String> keyset = new HashSet<>(map.keySet());
|
||||
for (String key : keyset) {
|
||||
String keyName = isLineEidtExport ? key.split("_name")[0] : key;
|
||||
if (complexHeaderListStr.contains(keyName)) {
|
||||
for (HeaderModel item : complexHeaderList) {
|
||||
if (item.getChildColumns().contains(keyName)) {
|
||||
if (complexMap1.contains(item.getId())) {
|
||||
List<Object> list1 = (List<Object>) map.get(item.getId());
|
||||
Map<String, Object> obj = list1 != null && list1.get(0) != null
|
||||
? (Map<String, Object>) list1.get(0)
|
||||
: new HashMap<>();
|
||||
obj.put(key, map.get(key));
|
||||
map.put(item.getId(), new ArrayList() {
|
||||
{
|
||||
add(obj);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
complexMap1.add(item.getId());
|
||||
Map<String, Object> obj = new HashMap<>();
|
||||
obj.put(key, map.get(key));
|
||||
map.put(item.getId(), new ArrayList() {
|
||||
{
|
||||
add(obj);
|
||||
}
|
||||
});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 复杂表头表头处理--在线开发
|
||||
*
|
||||
* @param dataList
|
||||
* @param complexHeaderList
|
||||
* @return
|
||||
*/
|
||||
public static List<Map<String, Object>> complexHeaderHandelOnline(List<Map<String, Object>> dataList,
|
||||
List<HeaderModel> complexHeaderList) {
|
||||
List<String> complexHeaderListStr = new ArrayList<>();
|
||||
complexHeaderList.forEach(item -> complexHeaderListStr.addAll(item.getChildColumns()));
|
||||
List<Object> uploadColumn = dataList.stream().map(t -> t.get("id")).collect(Collectors.toList());
|
||||
Map<String, Integer> complexMap1 = new HashMap<>();
|
||||
List<Map<String, Object>> dataListRes = new ArrayList<>();
|
||||
int n = 0;// 记录新数组下标用的,(dataListRes.add的地方就要n++)
|
||||
for (HeaderModel item : complexHeaderList) {
|
||||
if (item.getChildColumns().size() > 0) {
|
||||
List<String> complexHasColumn = item.getChildColumns().stream().filter(t -> uploadColumn.contains(t))
|
||||
.collect(Collectors.toList());
|
||||
// 判断复杂表头的字段是否有可导入字段--没有的话不生成复杂表头
|
||||
if (complexHasColumn.size() > 0) {
|
||||
complexMap1.put(item.getId(), n);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", item.getId());
|
||||
map.put("fullName", item.getFullName());
|
||||
map.put("yunzhupaasKey", "complexHeader");
|
||||
dataListRes.add(map);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Map<String, Object> entity : dataList) {
|
||||
if (complexHeaderListStr.contains(entity.get("id"))) {
|
||||
for (HeaderModel item : complexHeaderList) {
|
||||
if (item.getChildColumns().contains(entity.get("id"))) {
|
||||
Map<String, Object> map = dataListRes.get(complexMap1.get(item.getId()));
|
||||
List<Map<String, Object>> listmap = new ArrayList<>();
|
||||
if (map.get("children") == null) {
|
||||
listmap.add(entity);
|
||||
} else {
|
||||
listmap = (List<Map<String, Object>>) map.get("children");
|
||||
listmap.add(entity);
|
||||
}
|
||||
map.put("children", listmap);
|
||||
dataListRes.set(complexMap1.get(item.getId()), map);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dataListRes.add(entity);
|
||||
}
|
||||
}
|
||||
return dataListRes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 复杂表头数据导入处理--在线开发
|
||||
*
|
||||
* @param dataList
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public static List<Map<String, Object>> complexImportsDataOnline(List<Map<String, Object>> dataList,
|
||||
VisualdevEntity entity) {
|
||||
List<Map<String, Object>> listRes = new ArrayList<>();
|
||||
// 复杂表头-表头和数据处理
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(entity.getColumnData(), ColumnDataModel.class);
|
||||
List<HeaderModel> complexHeaderList = columnDataModel.getComplexHeaderList();
|
||||
if (!Objects.equals(columnDataModel.getType(), 3) && !Objects.equals(columnDataModel.getType(), 5)) {
|
||||
for (Map<String, Object> mapone : dataList) {
|
||||
for (HeaderModel item : complexHeaderList) {
|
||||
Object remove = mapone.remove(item.getId());
|
||||
if (remove != null) {
|
||||
List<Map<String, Object>> listC = (List<Map<String, Object>>) remove;
|
||||
if (listC.size() > 0) {
|
||||
mapone.putAll(listC.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
listRes.add(mapone);
|
||||
}
|
||||
} else {
|
||||
listRes = dataList;
|
||||
}
|
||||
return listRes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单元格垂直合并
|
||||
*
|
||||
* @param workbook
|
||||
* @param entityList
|
||||
* @param dataList
|
||||
*/
|
||||
public static void mergerVertical(Workbook workbook, List<ExcelExportEntity> entityList,
|
||||
List<Map<String, Object>> dataList) {
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
// 当前行
|
||||
int firstRow = 0;
|
||||
int lastRow = 0;
|
||||
for (Map<String, Object> obj : dataList) {
|
||||
// 取出子表最大数量
|
||||
int size = 1;
|
||||
// 判断有无子表
|
||||
List<ExcelExportEntity> hasChildList = entityList.stream()
|
||||
.filter(t -> t.getKey().toString().toLowerCase().contains(YunzhupaasKeyConsts.CHILD_TABLE_PREFIX))
|
||||
.collect(Collectors.toList());
|
||||
if (hasChildList.size() > 0) {
|
||||
for (ExcelExportEntity item : hasChildList) {
|
||||
String key = String.valueOf(item.getKey());
|
||||
if (obj.get(key) instanceof List) {
|
||||
List arr = (List) obj.get(key);
|
||||
if (arr.size() > size) {
|
||||
size = arr.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 标题行数量
|
||||
int headSize = 1;
|
||||
List<ExcelExportEntity> collect = entityList.stream().filter(t -> t.getList() != null)
|
||||
.collect(Collectors.toList());
|
||||
if (collect.size() >= 1) {
|
||||
headSize = 2;
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
firstRow = lastRow == 0 ? headSize : lastRow + 1;
|
||||
lastRow = firstRow;
|
||||
continue;
|
||||
} else {
|
||||
firstRow = lastRow == 0 ? headSize : lastRow + 1;
|
||||
lastRow = firstRow + size - 1;
|
||||
}
|
||||
|
||||
int m = 0;
|
||||
for (int n = 0; n < entityList.size(); n++) {
|
||||
ExcelExportEntity export = entityList.get(n);
|
||||
if (export.getList() == null && firstRow != lastRow) {
|
||||
sheet.addMergedRegionUnsafe(new CellRangeAddress(firstRow, lastRow, m, m));
|
||||
}
|
||||
// 计算子表字段个数
|
||||
if (export.getList() != null) {
|
||||
m = m + export.getList().size();
|
||||
} else {
|
||||
m++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.yunzhupaas.base.util.app;
|
||||
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.model.DownloadCodeForm;
|
||||
import com.yunzhupaas.base.model.Template7.Template7Model;
|
||||
import com.yunzhupaas.base.util.common.AliasModel;
|
||||
import com.yunzhupaas.database.model.entity.DbLinkEntity;
|
||||
import com.yunzhupaas.database.util.DataSourceUtil;
|
||||
import com.yunzhupaas.model.visualJson.FormDataModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/10/25
|
||||
*/
|
||||
@Data
|
||||
public class AppGenModel {
|
||||
/**
|
||||
* 文件夹名字
|
||||
*/
|
||||
private String fileName;
|
||||
/**
|
||||
* 实体对象
|
||||
*/
|
||||
private VisualdevEntity entity;
|
||||
/**
|
||||
* 下载对象
|
||||
*/
|
||||
private DownloadCodeForm downloadCodeForm;
|
||||
/**
|
||||
* 表单对象
|
||||
*/
|
||||
private FormDataModel model;
|
||||
/**
|
||||
* 模板文件
|
||||
*/
|
||||
private String templatePath;
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private String pKeyName;
|
||||
/**
|
||||
* 本地数据源
|
||||
*/
|
||||
private DataSourceUtil dataSourceUtil;
|
||||
/**
|
||||
* 数据连接
|
||||
*/
|
||||
private DbLinkEntity linkEntity;
|
||||
/**
|
||||
* 个人信息
|
||||
*/
|
||||
private UserInfo userInfo;
|
||||
/**
|
||||
* 生成文件名字
|
||||
*/
|
||||
private String className;
|
||||
/**
|
||||
* 数据库表
|
||||
*/
|
||||
private String table;
|
||||
/**
|
||||
* 生成路径
|
||||
*/
|
||||
private String serviceDirectory;
|
||||
/**
|
||||
* 模板路径
|
||||
*/
|
||||
private String templateCodePath;
|
||||
|
||||
private Boolean groupTable;
|
||||
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 代码生成基础信息
|
||||
*/
|
||||
private Template7Model template7Model;
|
||||
|
||||
/**
|
||||
* 命名规范映射
|
||||
*/
|
||||
private Map<String, AliasModel> tableAliseMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,724 @@
|
||||
package com.yunzhupaas.base.util.app;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.model.ColumnDataModel;
|
||||
import com.yunzhupaas.base.model.DownloadCodeForm;
|
||||
import com.yunzhupaas.base.model.Template6.BtnData;
|
||||
import com.yunzhupaas.base.model.Template6.ColumnListField;
|
||||
import com.yunzhupaas.base.model.Template7.Template7Model;
|
||||
import com.yunzhupaas.base.model.VisualWebTypeEnum;
|
||||
import com.yunzhupaas.base.util.common.AliasModel;
|
||||
import com.yunzhupaas.base.util.common.DataControlUtils;
|
||||
import com.yunzhupaas.base.util.common.GenerateCommon;
|
||||
import com.yunzhupaas.base.util.common.SuperQueryUtil;
|
||||
import com.yunzhupaas.database.model.superQuery.SuperJsonModel;
|
||||
import com.yunzhupaas.i18n.util.I18nUtil;
|
||||
import com.yunzhupaas.model.visualJson.*;
|
||||
import com.yunzhupaas.model.visualJson.analysis.*;
|
||||
import com.yunzhupaas.model.visualJson.config.ConfigModel;
|
||||
import com.yunzhupaas.model.visualJson.config.TabConfigModel;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.XSSEscape;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
import lombok.Cleanup;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class AppGenUtil {
|
||||
|
||||
// +-----------------------------界面2021.8.13------------------------------------------------------------
|
||||
|
||||
private List<String> noShow = ImmutableList.of(YunzhupaasKeyConsts.CALCULATE);
|
||||
|
||||
public void htmlTemplates(AppGenModel appGenModel) throws IOException {
|
||||
Map<String, Object> map = new HashMap<>(16);
|
||||
VisualdevEntity entity = appGenModel.getEntity();
|
||||
DownloadCodeForm downloadCodeForm = appGenModel.getDownloadCodeForm();
|
||||
List<FormAllModel> formAllModel = new ArrayList<>();
|
||||
boolean isView = isView(appGenModel);
|
||||
Map<String, String> tableNameAll = new HashMap<>();
|
||||
if (!isView) {
|
||||
tableNameAll.putAll(this.forDataMode(appGenModel, formAllModel));
|
||||
}
|
||||
|
||||
FormDataModel model = appGenModel.getModel();
|
||||
List<FormAllModel> mast = this.mast(formAllModel);
|
||||
List<Map<String, Object>> child = new ArrayList<>();
|
||||
this.childModel(formAllModel, child, tableNameAll);
|
||||
this.mastTableModel(formAllModel, map, tableNameAll);
|
||||
this.templateJson(formAllModel);
|
||||
map.put("moduleId", appGenModel.getEntity().getId());
|
||||
map.put("children", child);
|
||||
map.put("groupTable", appGenModel.getGroupTable());
|
||||
map.put("type", appGenModel.getType());
|
||||
map.put("fields", mast);
|
||||
map.put("package", "com.yunzhupaas");
|
||||
map.put("isModel", "true");
|
||||
map.put("labelSuffix", model.getLabelSuffix());
|
||||
map.put("flowEnCode", entity.getEnCode());
|
||||
map.put("flowId", entity.getId());
|
||||
map.put("webType", entity.getWebType());
|
||||
map.put("isFlow", Objects.equals(downloadCodeForm.getEnableFlow(), 1));
|
||||
map.put("module", model.getAreasName());
|
||||
map.put("className", DataControlUtils.captureName(model.getClassName()));
|
||||
this.formData(map, appGenModel, formAllModel);
|
||||
|
||||
List<String> getTemplate = this.getTemplate(appGenModel);
|
||||
Template7Model templateModel = appGenModel.getTemplate7Model();
|
||||
String path = templateModel.getServiceDirectory() + appGenModel.getFileName();
|
||||
|
||||
boolean type = this.isForm(appGenModel);
|
||||
this.htmlTemplates(map, getTemplate, path, DataControlUtils.initialLowercase(model.getClassName()),
|
||||
isView ? false : !type);
|
||||
|
||||
}
|
||||
|
||||
private void templateJson(List<FormAllModel> formAllModel) {
|
||||
for (FormAllModel model : formAllModel) {
|
||||
if (FormEnum.mast.getMessage().equals(model.getYunzhupaasKey())) {
|
||||
List<TemplateJsonModel> templateJsonAll = new ArrayList<>();
|
||||
templateJsonAll.addAll(model.getFormColumnModel().getFieLdsModel().getConfig().getTemplateJson());
|
||||
List<TemplateJsonModel> templateJsonModelList = JsonUtil.getJsonToList(
|
||||
model.getFormColumnModel().getFieLdsModel().getTemplateJson(), TemplateJsonModel.class);
|
||||
templateJsonAll.addAll(templateJsonModelList);
|
||||
model.getFormColumnModel().getFieLdsModel().getConfig().setTemplateJson(templateJsonAll);
|
||||
}
|
||||
|
||||
if (FormEnum.mastTable.getMessage().equals(model.getYunzhupaasKey())) {
|
||||
List<TemplateJsonModel> templateJsonAll = new ArrayList<>();
|
||||
templateJsonAll.addAll(
|
||||
model.getFormMastTableModel().getMastTable().getFieLdsModel().getConfig().getTemplateJson());
|
||||
List<TemplateJsonModel> templateJsonModelList = JsonUtil.getJsonToList(
|
||||
model.getFormMastTableModel().getMastTable().getFieLdsModel().getTemplateJson(),
|
||||
TemplateJsonModel.class);
|
||||
templateJsonAll.addAll(templateJsonModelList);
|
||||
model.getFormMastTableModel().getMastTable().getFieLdsModel().getConfig()
|
||||
.setTemplateJson(templateJsonAll);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板
|
||||
*
|
||||
* @param appGenModel
|
||||
* @return
|
||||
*/
|
||||
private List<String> getTemplate(AppGenModel appGenModel) {
|
||||
String template = this.tempPath(appGenModel);
|
||||
VisualdevEntity entity = appGenModel.getEntity();
|
||||
DownloadCodeForm downloadCodeForm = appGenModel.getDownloadCodeForm();
|
||||
boolean isView = isView(appGenModel);
|
||||
List<String> templates = new ArrayList<>();
|
||||
if (isView) {
|
||||
templates.add(template + File.separator + "app" + File.separator + "index.vue.vm");
|
||||
} else {
|
||||
boolean isType = !VisualWebTypeEnum.FORM.getType().equals(entity.getWebType());
|
||||
templates.add(template + File.separator + "app" + File.separator + "form.vue.vm");
|
||||
// 模板2
|
||||
if (VisualWebTypeEnum.FORM_LIST.getType().equals(entity.getWebType())) {
|
||||
ColumnDataModel appColumnDataModel = JsonUtil.getJsonToBean(entity.getColumnData(),
|
||||
ColumnDataModel.class);
|
||||
List<BtnData> columnBtnDataList = JsonUtil.getJsonToList(appColumnDataModel.getColumnBtnsList(),
|
||||
BtnData.class);
|
||||
boolean detail = columnBtnDataList.stream().filter(t -> "detail".equals(t.getValue())).count() > 0;
|
||||
if (downloadCodeForm.getEnableFlow() == 0 && isType && detail) {
|
||||
templates.add(template + File.separator + "app" + File.separator + "detail.vue.vm");
|
||||
}
|
||||
}
|
||||
// 除了模板4,其他都有index的模板
|
||||
boolean index = !(VisualWebTypeEnum.FORM.getType().equals(entity.getWebType())
|
||||
&& downloadCodeForm.getEnableFlow() != 1);
|
||||
if (index) {
|
||||
templates.add(template + File.separator + "app" + File.separator + "index.vue.vm");
|
||||
}
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件名
|
||||
*
|
||||
* @param path 路径
|
||||
* @param template 模板名称
|
||||
* @param className 文件名称
|
||||
* @return
|
||||
*/
|
||||
private String getFileNames(String path, String template, String className, boolean isIndex) {
|
||||
path = XSSEscape.escapePath(path);
|
||||
className = XSSEscape.escapePath(className);
|
||||
String pathName = className.substring(0, 1).toLowerCase() + className.substring(1);
|
||||
if (template.contains("index.vue.vm") || template.contains("detail.vue.vm")) {
|
||||
String indexHtmlPath = path + File.separator + "html" + File.separator + "app";
|
||||
indexHtmlPath += isIndex ? File.separator + "index" + File.separator + pathName : File.separator + pathName;
|
||||
File indexfile = new File(indexHtmlPath);
|
||||
if (!indexfile.exists()) {
|
||||
indexfile.mkdirs();
|
||||
}
|
||||
className = template.contains("index.vue.vm") ? "index" : "detail";
|
||||
return indexHtmlPath + File.separator + className + ".vue";
|
||||
}
|
||||
if (template.contains("form.vue.vm")) {
|
||||
String formHtmlPath = path + File.separator + "html" + File.separator + "app";
|
||||
formHtmlPath += isIndex ? File.separator + "form" + File.separator + pathName : File.separator + pathName;
|
||||
File formfile = new File(formHtmlPath);
|
||||
if (!formfile.exists()) {
|
||||
formfile.mkdirs();
|
||||
}
|
||||
className = isIndex ? "index" : "form";
|
||||
return formHtmlPath + File.separator + className + ".vue";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染html模板
|
||||
*
|
||||
* @param path 路径
|
||||
* @param object 模板数据
|
||||
* @param path 模板路径
|
||||
*/
|
||||
private void htmlTemplates(Object object, List<String> templates, String path, String className, boolean isIndex) {
|
||||
// 界面模板
|
||||
VelocityContext context = new VelocityContext();
|
||||
context.put("context", object);
|
||||
for (String template : templates) {
|
||||
// 渲染模板
|
||||
try {
|
||||
@Cleanup
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tpl = Velocity.getTemplate(template, Constants.UTF_8);
|
||||
tpl.merge(context, sw);
|
||||
String fileNames = getFileNames(path, template, className, isIndex);
|
||||
if (fileNames != null) {
|
||||
File file = new File(fileNames);
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
@Cleanup
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
IOUtils.write(sw.toString(), fos, Constants.UTF_8);
|
||||
IOUtils.closeQuietly(sw);
|
||||
IOUtils.closeQuietly(fos);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("渲染模板失败,表名:" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装主表数据
|
||||
*/
|
||||
private List<FormAllModel> mast(List<FormAllModel> formAllModel) {
|
||||
List<FormAllModel> mast = formAllModel.stream()
|
||||
.filter(t -> FormEnum.mast.getMessage().equals(t.getYunzhupaasKey())).collect(Collectors.toList());
|
||||
// 主表赋值
|
||||
for (int i = 0; i < mast.size(); i++) {
|
||||
FieLdsModel fieLdsModel = mast.get(i).getFormColumnModel().getFieLdsModel();
|
||||
this.model(fieLdsModel);
|
||||
String vmodel = fieLdsModel.getVModel();
|
||||
if (StringUtil.isEmpty(vmodel)) {
|
||||
mast.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
return mast;
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装mastTable数据
|
||||
*/
|
||||
private Map<String, List<FormAllModel>> mastTableModel(List<FormAllModel> formAllModel, Map<String, Object> map,
|
||||
Map<String, String> tableNameAll) {
|
||||
List<FormAllModel> mastTable = formAllModel.stream()
|
||||
.filter(t -> FormEnum.mastTable.getMessage().equals(t.getYunzhupaasKey())).collect(Collectors.toList());
|
||||
Map<String, List<FormAllModel>> mastListAll = mastTable.stream()
|
||||
.collect(Collectors.groupingBy(e -> e.getFormMastTableModel().getTable()));
|
||||
Map<String, String> mastTableNameAll = new HashMap<>();
|
||||
Map<String, List<FormAllModel>> mastTableList = new HashMap<>();
|
||||
// 表单主表
|
||||
for (String mastkey : mastListAll.keySet()) {
|
||||
List<FormAllModel> mastList = mastListAll.get(mastkey);
|
||||
for (FormAllModel fieLdsList : mastList) {
|
||||
FieLdsModel fieLdsModel = fieLdsList.getFormMastTableModel().getMastTable().getFieLdsModel();
|
||||
this.model(fieLdsModel);
|
||||
}
|
||||
mastListAll.put(mastkey, mastList);
|
||||
String tableName = tableNameAll.get(mastkey);
|
||||
String name = tableName.substring(0, 1).toUpperCase() + tableName.substring(1);
|
||||
mastTableNameAll.put(mastkey, name);
|
||||
mastTableList.put(tableName.toLowerCase(), mastList);
|
||||
}
|
||||
map.put("mastTableName", mastTableNameAll);
|
||||
map.put("tableName", tableNameAll);
|
||||
map.put("mastTable", mastTableList);
|
||||
return mastListAll;
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装子表数据
|
||||
*/
|
||||
private void childModel(List<FormAllModel> formAllModel, List<Map<String, Object>> child,
|
||||
Map<String, String> tableNameAll) {
|
||||
List<FormAllModel> table = formAllModel.stream()
|
||||
.filter(t -> FormEnum.table.getMessage().equals(t.getYunzhupaasKey())).collect(Collectors.toList());
|
||||
for (FormAllModel formModel : table) {
|
||||
FormColumnTableModel childList = formModel.getChildList();
|
||||
List<String> thousandsField = new ArrayList<>();
|
||||
List<String> summaryField = new ArrayList<>();
|
||||
Map<String, Object> summaryFieldName = new HashMap<>();
|
||||
String tableName = childList.getTableName();
|
||||
List<String> summaryFieldAll = JsonUtil.getJsonToList(childList.getSummaryField(), String.class);
|
||||
String name = tableNameAll.get(tableName);
|
||||
String className = name.substring(0, 1).toLowerCase() + name.substring(1);
|
||||
List<FormColumnModel> tableList = childList.getChildList();
|
||||
List<FormColumnModel> childFieldList = new ArrayList<>();
|
||||
for (int i = 0; i < tableList.size(); i++) {
|
||||
FormColumnModel columnModel = tableList.get(i);
|
||||
FieLdsModel fieLdsModel = columnModel.getFieLdsModel();
|
||||
ConfigModel config = fieLdsModel.getConfig();
|
||||
model(fieLdsModel);
|
||||
if (fieLdsModel.isThousands()) {
|
||||
thousandsField.add(fieLdsModel.getVModel());
|
||||
}
|
||||
if (!fieLdsModel.getConfig().getNoShow() && summaryFieldAll.contains(fieLdsModel.getVModel())) {
|
||||
summaryField.add(fieLdsModel.getVModel());
|
||||
summaryFieldName.put(fieLdsModel.getVModel(), config.getLabel());
|
||||
if (StringUtil.isNotEmpty(config.getLabelI18nCode())) {
|
||||
summaryFieldName.put(fieLdsModel.getVModel() + "_i18n", config.getLabelI18nCode());
|
||||
}
|
||||
}
|
||||
List<TemplateJsonModel> templateJsonAll = new ArrayList<>();
|
||||
templateJsonAll.addAll(fieLdsModel.getConfig().getTemplateJson());
|
||||
List<TemplateJsonModel> templateJsonModelList = JsonUtil.getJsonToList(fieLdsModel.getTemplateJson(),
|
||||
TemplateJsonModel.class);
|
||||
templateJsonAll.addAll(templateJsonModelList);
|
||||
for (TemplateJsonModel templateJsonModel : templateJsonAll) {
|
||||
if (StringUtil.isNotEmpty(templateJsonModel.getRelationField())
|
||||
&& Objects.equals(templateJsonModel.getSourceType(), 1)) {
|
||||
String[] fieldList = templateJsonModel.getRelationField().split("-");
|
||||
if (fieldList.length > 1) {
|
||||
templateJsonModel.setRelationField(className + "-" + fieldList[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (TemplateJsonModel templateJsonModel : templateJsonModelList) {
|
||||
if (StringUtil.isNotEmpty(templateJsonModel.getRelationField())
|
||||
&& Objects.equals(templateJsonModel.getSourceType(), 1)) {
|
||||
String[] fieldList = templateJsonModel.getRelationField().split("-");
|
||||
if (fieldList.length > 1) {
|
||||
templateJsonModel.setRelationField(className + "List-" + fieldList[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
fieLdsModel.setTemplateJson(JsonUtil.getObjectToString(templateJsonModelList));
|
||||
fieLdsModel.getConfig().setTemplateJson(templateJsonAll);
|
||||
// 修改弹窗的子表默认数据
|
||||
FieLdsModel childField = JsonUtil.getJsonToBean(fieLdsModel, FieLdsModel.class);
|
||||
ConfigModel configModel = JsonUtil.getJsonToBean(config, ConfigModel.class);
|
||||
Object defaultValue = configModel.getDefaultValue();
|
||||
if (defaultValue instanceof String) {
|
||||
defaultValue = "";
|
||||
} else if (defaultValue instanceof BigDecimal) {
|
||||
defaultValue = 0;
|
||||
} else if (defaultValue instanceof List) {
|
||||
defaultValue = new ArrayList<>();
|
||||
}
|
||||
configModel.setDefaultValue(defaultValue);
|
||||
childField.setConfig(configModel);
|
||||
FormColumnModel childColumn = new FormColumnModel();
|
||||
childColumn.setFieLdsModel(childField);
|
||||
childFieldList.add(childColumn);
|
||||
}
|
||||
childList.setThousandsField(thousandsField);
|
||||
childList.setSummaryField(JsonUtil.getObjectToString(summaryField));
|
||||
childList.setSummaryFieldName(JsonUtil.getObjectToString(summaryFieldName));
|
||||
childList.setChildList(tableList);
|
||||
childList.setChildFieldList(childFieldList);
|
||||
Map<String, Object> childs = JsonUtil.entityToMap(childList);
|
||||
childs.put("className", className);
|
||||
childs.put("children", childList);
|
||||
child.add(childs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装model数据
|
||||
*/
|
||||
private void model(FieLdsModel fieLdsModel) {
|
||||
ConfigModel configModel = fieLdsModel.getConfig();
|
||||
String yunzhupaasKey = configModel.getYunzhupaasKey();
|
||||
if (configModel.getDefaultValue() instanceof String) {
|
||||
configModel.setValueType("String");
|
||||
}
|
||||
if (configModel.getDefaultValue() == null) {
|
||||
configModel.setValueType("undefined");
|
||||
if (YunzhupaasKeyConsts.ADDRESS.equals(yunzhupaasKey)) {
|
||||
configModel.setDefaultValue(new ArrayList<>());
|
||||
configModel.setValueType(null);
|
||||
}
|
||||
}
|
||||
if (YunzhupaasKeyConsts.SWITCH.equals(yunzhupaasKey)) {
|
||||
if (configModel.getDefaultValue() instanceof Boolean) {
|
||||
Boolean defaultValue = (Boolean) configModel.getDefaultValue();
|
||||
configModel.setDefaultValue(defaultValue ? 1 : 0);
|
||||
}
|
||||
}
|
||||
if (YunzhupaasKeyConsts.TREESELECT.equals(yunzhupaasKey)) {
|
||||
configModel.setValueType(fieLdsModel.getMultiple() ? configModel.getValueType() : "undefined");
|
||||
}
|
||||
fieLdsModel.setConfig(configModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装页面数据
|
||||
*/
|
||||
private void formData(Map<String, Object> map, AppGenModel appGenModel, List<FormAllModel> formAllModel)
|
||||
throws IOException {
|
||||
FormDataModel model = appGenModel.getModel();
|
||||
// 界面
|
||||
map.put("formRef", model.getFormRef());
|
||||
map.put("hasConfirmAndAddBtn", false);
|
||||
map.put("formModel", model.getFormModel());
|
||||
map.put("size", model.getSize());
|
||||
map.put("labelPosition", model.getLabelPosition());
|
||||
map.put("labelWidth", model.getLabelWidth());
|
||||
map.put("formRules", model.getFormRules());
|
||||
map.put("gutter", model.getGutter());
|
||||
map.put("disabled", model.getDisabled());
|
||||
map.put("span", model.getSpan());
|
||||
map.put("formBtns", model.getFormBtns());
|
||||
map.put("idGlobal", model.getIdGlobal());
|
||||
map.put("popupType", model.getPopupType());
|
||||
map.put("form", formAllModel);
|
||||
|
||||
// 列表
|
||||
boolean isPage = this.isPage(appGenModel);
|
||||
boolean type = this.isForm(appGenModel);
|
||||
boolean isView = this.isView(appGenModel);
|
||||
if (isPage) {
|
||||
List<BtnData> columnList = new ArrayList<>();
|
||||
String page = "1";
|
||||
String sort = "";
|
||||
String defaultSidx = "";
|
||||
int pageSize = 20;
|
||||
boolean thousands = false;
|
||||
SuperJsonModel ruleQueryJson = new SuperJsonModel();
|
||||
VisualdevEntity entity = appGenModel.getEntity();
|
||||
if (StringUtil.isNotEmpty(entity.getColumnData())) {
|
||||
String columnData = entity.getColumnData();
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData, ColumnDataModel.class);
|
||||
page = columnDataModel.getHasPage() ? "0" : "1";
|
||||
sort = columnDataModel.getSort();
|
||||
pageSize = columnDataModel.getPageSize();
|
||||
defaultSidx = columnDataModel.getDefaultSidx();
|
||||
thousands = columnDataModel.isThousands();
|
||||
this.columnData(formAllModel, columnDataModel, map);
|
||||
List<BtnData> btns = StringUtil.isNotEmpty(columnDataModel.getBtnsList())
|
||||
? JsonUtil.getJsonToList(columnDataModel.getBtnsList(), BtnData.class)
|
||||
: new ArrayList<>();
|
||||
btns.addAll(StringUtil.isNotEmpty(columnDataModel.getColumnBtnsList())
|
||||
? JsonUtil.getJsonToList(columnDataModel.getColumnBtnsList(), BtnData.class)
|
||||
: new ArrayList<>());
|
||||
columnList.addAll(btns.stream().filter(t -> t.isShow()).collect(Collectors.toList()));
|
||||
ruleQueryJson = columnDataModel.getRuleListApp();
|
||||
Template7Model templateModel = appGenModel.getTemplate7Model();
|
||||
String path = templateModel.getServiceDirectory() + appGenModel.getFileName();
|
||||
boolean index = isView ? false : !type;
|
||||
String columnPath = path + File.separator + "html" + File.separator + "app" + File.separator
|
||||
+ (index ? "index" + File.separator : "")
|
||||
+ DataControlUtils.initialLowercase(model.getClassName()) + File.separator;
|
||||
File indexfile = new File(columnPath);
|
||||
if (!indexfile.exists()) {
|
||||
indexfile.mkdirs();
|
||||
}
|
||||
String jsonString = JSONObject.toJSONString(
|
||||
JsonUtil.getJsonToJsonArray(columnDataModel.getColumnList()),
|
||||
SerializerFeature.WriteMapNullValue, SerializerFeature.PrettyFormat);
|
||||
SuperQueryUtil.CreateJsFile(jsonString, columnPath + "columnList.js", "columnList");
|
||||
}
|
||||
// 合计千分位
|
||||
List<FormAllModel> mast = formAllModel.stream()
|
||||
.filter(t -> FormEnum.mast.getMessage().equals(t.getYunzhupaasKey())).collect(Collectors.toList());
|
||||
List<FormAllModel> mastTable = formAllModel.stream()
|
||||
.filter(t -> FormEnum.mastTable.getMessage().equals(t.getYunzhupaasKey()))
|
||||
.collect(Collectors.toList());
|
||||
List<String> thousandsField = GenerateCommon.getSummaryThousandList(mast, mastTable, 4);
|
||||
map.put("page", page);
|
||||
map.put("sort", sort);
|
||||
map.put("defaultSidx", defaultSidx);
|
||||
map.put("pageSize", pageSize);
|
||||
map.put("columnBtnsList", columnList);
|
||||
map.put("thousands", thousands);
|
||||
map.put("thousandsField", JsonUtil.getObjectToString(thousandsField));
|
||||
map.put("ruleQueryJson", JSONObject.toJSONString(ruleQueryJson));
|
||||
}
|
||||
// 共用
|
||||
String pKeyName = appGenModel.getPKeyName();
|
||||
map.put("pKeyName", pKeyName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装列表数据
|
||||
*/
|
||||
private void columnData(List<FormAllModel> formAllModel, ColumnDataModel columnDataModel, Map<String, Object> map) {
|
||||
List<FormAllModel> mast = formAllModel.stream()
|
||||
.filter(t -> FormEnum.mast.getMessage().equals(t.getYunzhupaasKey())).collect(Collectors.toList());
|
||||
List<FormAllModel> mastTable = formAllModel.stream()
|
||||
.filter(t -> FormEnum.mastTable.getMessage().equals(t.getYunzhupaasKey())).collect(Collectors.toList());
|
||||
// 显示数据
|
||||
List<ColumnListField> columnListAll = JsonUtil.getJsonToList(columnDataModel.getColumnList(),
|
||||
ColumnListField.class);
|
||||
Map<String, List<FormAllModel>> mastTableList = new HashMap<>();
|
||||
Map<String, List<ColumnListField>> childColumnList = new HashMap<>();
|
||||
List<ColumnListField> columnMastList = new ArrayList<>();
|
||||
for (ColumnListField columnList : columnListAll) {
|
||||
String prop = columnList.getProp();
|
||||
FormAllModel model = mastTable.stream().filter(t -> t.getFormMastTableModel().getVModel().equals(prop))
|
||||
.findFirst().orElse(null);
|
||||
if (model == null) {
|
||||
String[] split = prop.split("-");
|
||||
if (split.length == 1) {
|
||||
columnMastList.add(columnList);
|
||||
} else {
|
||||
List<ColumnListField> childList = childColumnList.get(split[0]) != null
|
||||
? childColumnList.get(split[0])
|
||||
: new ArrayList<>();
|
||||
String vModel = split[1];
|
||||
columnList.setVModel(vModel);
|
||||
childList.add(columnList);
|
||||
childColumnList.put(split[0], childList);
|
||||
}
|
||||
} else {
|
||||
FormMastTableModel formMastTableModel = model.getFormMastTableModel();
|
||||
String tableName = formMastTableModel.getTable();
|
||||
List<FormAllModel> columnListList = mastTableList.get(tableName) != null ? mastTableList.get(tableName)
|
||||
: new ArrayList<>();
|
||||
model.setFormMastTableModel(formMastTableModel);
|
||||
columnListList.add(model);
|
||||
mastTableList.put(tableName, columnListList);
|
||||
}
|
||||
}
|
||||
map.put("childColumnList", childColumnList);
|
||||
map.put("columnList", columnMastList);
|
||||
map.put("columnMastList", mastTableList);
|
||||
map.put("AppColumnList", columnDataModel.getColumnList());
|
||||
// 排序
|
||||
List<ColumnListField> sortListAll = columnListAll.stream().filter(t -> t.getSortable())
|
||||
.collect(Collectors.toList());
|
||||
List<ColumnListField> sortList = new ArrayList<>();
|
||||
for (int i = 0; i < sortListAll.size(); i++) {
|
||||
ColumnListField field = sortListAll.get(i);
|
||||
if (!noShow.contains(field.getYunzhupaasKey())) {
|
||||
sortList.add(field);
|
||||
}
|
||||
}
|
||||
map.put("sortList", sortList);
|
||||
map.put("defaultSortConfig", columnDataModel.getDefaultSortConfig());
|
||||
// 搜索
|
||||
List<FieLdsModel> searchVOListAll = JsonUtil.getJsonToList(columnDataModel.getSearchList(), FieLdsModel.class);
|
||||
List<FieLdsModel> searchVOList = new ArrayList<>();
|
||||
List<FieLdsModel> mastTableSearch = new ArrayList<>();
|
||||
List<FieLdsModel> childSearch = new ArrayList<>();
|
||||
List<FieLdsModel> mastSearch = new ArrayList<>();
|
||||
List<Map<String, Object>> searchAll = new LinkedList<>();
|
||||
List<Map<String, Object>> tabSearch = new LinkedList<>();
|
||||
int isTab = 0;
|
||||
for (FieLdsModel columnSearch : searchVOListAll) {
|
||||
List<TemplateJsonModel> templateJsonAll = new ArrayList<>();
|
||||
ConfigModel config = columnSearch.getConfig();
|
||||
templateJsonAll.addAll(config.getTemplateJson());
|
||||
List<TemplateJsonModel> templateJsonModelList = JsonUtil.getJsonToList(columnSearch.getTemplateJson(),
|
||||
TemplateJsonModel.class);
|
||||
templateJsonAll.addAll(templateJsonModelList);
|
||||
config.setTemplateJson(templateJsonAll);
|
||||
Map<String, Object> column = new HashMap<>();
|
||||
String vmodel = columnSearch.getId();
|
||||
boolean isMast = mast.stream()
|
||||
.filter(t -> vmodel.equals(t.getFormColumnModel().getFieLdsModel().getVModel())).count() > 0;
|
||||
boolean isMastTable = mastTable.stream().filter(t -> vmodel.equals(t.getFormMastTableModel().getVModel()))
|
||||
.count() > 0;
|
||||
Object value = columnSearch.getValue();
|
||||
if (value instanceof String) {
|
||||
config.setValueType("String");
|
||||
}
|
||||
if (isMast) {
|
||||
column.put("key", "mastSearch");
|
||||
mastSearch.add(columnSearch);
|
||||
} else if (isMastTable) {
|
||||
column.put("key", "mastTableSearch");
|
||||
mastTableSearch.add(columnSearch);
|
||||
} else {
|
||||
columnSearch.setVModel(vmodel.replaceAll("-", "_"));
|
||||
column.put("key", "childSearch");
|
||||
childSearch.add(columnSearch);
|
||||
}
|
||||
column.put("html", columnSearch);
|
||||
if (!noShow.contains(config.getYunzhupaasKey())) {
|
||||
searchVOList.add(columnSearch);
|
||||
searchAll.add(column);
|
||||
}
|
||||
}
|
||||
TabConfigModel tabConfig = ObjectUtil.isNotEmpty(columnDataModel.getTabConfig())
|
||||
? columnDataModel.getTabConfig()
|
||||
: new TabConfigModel();
|
||||
String fieldsModel = tabConfig.getRelationField();
|
||||
if (tabConfig.isOn() && StringUtil.isNotEmpty(fieldsModel)) {
|
||||
for (FormAllModel item : mast) {
|
||||
FieLdsModel fieLdsModel = item.getFormColumnModel().getFieLdsModel();
|
||||
if (fieLdsModel.getVModel().equals(fieldsModel)) {
|
||||
Map<String, Object> column = new HashMap<>();
|
||||
column.put("key", "tab");
|
||||
column.put("html", fieLdsModel);
|
||||
tabSearch.add(column);
|
||||
isTab++;
|
||||
}
|
||||
}
|
||||
for (FormAllModel item : mastTable) {
|
||||
FieLdsModel mastTableModel = item.getFormMastTableModel().getMastTable().getFieLdsModel();
|
||||
if (mastTableModel.getVModel().equals(fieldsModel)) {
|
||||
Map<String, Object> column = new HashMap<>();
|
||||
column.put("key", "tab");
|
||||
column.put("html", mastTableModel);
|
||||
tabSearch.add(column);
|
||||
isTab++;
|
||||
}
|
||||
}
|
||||
}
|
||||
map.put("tabSearch", tabSearch);
|
||||
map.put("hasAllTab", isTab > 0 ? tabConfig.isHasAllTab() : false);
|
||||
map.put("isTab", isTab > 0);
|
||||
|
||||
// 关键词搜索
|
||||
map.put("isKeyword", searchVOList.stream().filter(t -> t.getIsKeyword()).count() > 0);
|
||||
map.put("searchAll", searchAll);
|
||||
map.put("searchList", mastTableSearch);
|
||||
map.put("childSearch", childSearch);
|
||||
map.put("mastsearchList", mastSearch);
|
||||
map.put("useDataPermission",
|
||||
columnDataModel.getUseDataPermission() != null ? columnDataModel.getUseDataPermission() : false);
|
||||
map.put("useBtnPermission",
|
||||
columnDataModel.getUseBtnPermission() != null ? columnDataModel.getUseBtnPermission() : false);
|
||||
map.put("useFormPermission",
|
||||
columnDataModel.getUseFormPermission() != null ? columnDataModel.getUseFormPermission() : false);
|
||||
map.put("useColumnPermission",
|
||||
columnDataModel.getUseColumnPermission() != null ? columnDataModel.getUseColumnPermission() : false);
|
||||
}
|
||||
|
||||
// ----------------------------代码-------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 封装数据
|
||||
*
|
||||
* @param formAllModel
|
||||
*/
|
||||
private Map<String, String> forDataMode(AppGenModel appGenModel, List<FormAllModel> formAllModel) {
|
||||
VisualdevEntity entity = appGenModel.getEntity();
|
||||
// formTempJson
|
||||
FormDataModel formData = JsonUtil.getJsonToBean(entity.getFormData(), FormDataModel.class);
|
||||
List<FieLdsModel> list = JsonUtil.getJsonToList(formData.getFields(), FieLdsModel.class);
|
||||
List<TableModel> tableModelList = JsonUtil.getJsonToList(entity.getVisualTables(), TableModel.class);
|
||||
RecursionForm recursionForm = new RecursionForm(list, tableModelList);
|
||||
List<FormAllModel> formAllModelAll = new ArrayList<>();
|
||||
FormCloumnUtil.recursionFormGen(recursionForm, formAllModelAll);
|
||||
for (FormAllModel allModel : formAllModelAll) {
|
||||
boolean add = true;
|
||||
if (FormEnum.mast.getMessage().equals(allModel.getYunzhupaasKey())) {
|
||||
FieLdsModel fieLdsModel = allModel.getFormColumnModel().getFieLdsModel();
|
||||
add = !noShow.contains(fieLdsModel.getConfig().getYunzhupaasKey());
|
||||
if (ObjectUtil.isNotEmpty(fieLdsModel.getConfig().getTipLabel())) {
|
||||
String tipLabel = fieLdsModel.getConfig().getTipLabel().replaceAll("\n", " ");
|
||||
fieLdsModel.getConfig().setTipLabel(tipLabel);
|
||||
}
|
||||
}
|
||||
if (FormEnum.mastTable.getMessage().equals(allModel.getYunzhupaasKey())) {
|
||||
FieLdsModel fieLdsModel = allModel.getFormMastTableModel().getMastTable().getFieLdsModel();
|
||||
add = !noShow.contains(fieLdsModel.getConfig().getYunzhupaasKey());
|
||||
if (ObjectUtil.isNotEmpty(fieLdsModel.getConfig().getTipLabel())) {
|
||||
String tipLabel = fieLdsModel.getConfig().getTipLabel().replaceAll("\n", " ");
|
||||
fieLdsModel.getConfig().setTipLabel(tipLabel);
|
||||
}
|
||||
}
|
||||
if (FormEnum.table.getMessage().equals(allModel.getYunzhupaasKey())) {
|
||||
List<FormColumnModel> childListAll = allModel.getChildList().getChildList();
|
||||
List<FormColumnModel> childList = new ArrayList<>();
|
||||
for (int k = 0; k < childListAll.size(); k++) {
|
||||
FormColumnModel formColumnModel = childListAll.get(k);
|
||||
FieLdsModel fieLdsModel = formColumnModel.getFieLdsModel();
|
||||
if (ObjectUtil.isNotEmpty(fieLdsModel.getConfig().getTipLabel())) {
|
||||
String tipLabel = fieLdsModel.getConfig().getTipLabel().replaceAll("\n", " ");
|
||||
fieLdsModel.getConfig().setTipLabel(tipLabel);
|
||||
}
|
||||
if (!noShow.contains(fieLdsModel.getConfig().getYunzhupaasKey())) {
|
||||
childList.add(formColumnModel);
|
||||
}
|
||||
}
|
||||
allModel.getChildList().setChildList(childList);
|
||||
}
|
||||
if (add) {
|
||||
formAllModel.add(allModel);
|
||||
}
|
||||
}
|
||||
Map<String, String> tableNameAll = new HashMap<>();
|
||||
Map<String, AliasModel> tableAliseMap = appGenModel.getTableAliseMap();
|
||||
for (String key : tableAliseMap.keySet()) {
|
||||
tableNameAll.put(key, tableAliseMap.get(key).getAliasName());
|
||||
}
|
||||
return tableNameAll;
|
||||
}
|
||||
|
||||
private String tempPath(AppGenModel appGenModel) {
|
||||
String tempPath = appGenModel.getTemplatePath();
|
||||
VisualdevEntity entity = appGenModel.getEntity();
|
||||
DownloadCodeForm downloadCodeForm = appGenModel.getDownloadCodeForm();
|
||||
boolean isView = isView(appGenModel);
|
||||
if (isView) {
|
||||
tempPath = "TemplateCode2";
|
||||
} else {
|
||||
if (VisualWebTypeEnum.FORM.getType().equals(entity.getWebType())) {
|
||||
tempPath = downloadCodeForm.getEnableFlow() == 1 ? "TemplateCode5" : "TemplateCode4";
|
||||
} else if (VisualWebTypeEnum.FORM_LIST.getType().equals(entity.getWebType())) {
|
||||
tempPath = downloadCodeForm.getEnableFlow() == 1 ? "TemplateCode3" : "TemplateCode2";
|
||||
}
|
||||
}
|
||||
return tempPath;
|
||||
}
|
||||
|
||||
private boolean isPage(AppGenModel appGenModel) {
|
||||
VisualdevEntity entity = appGenModel.getEntity();
|
||||
boolean type = !VisualWebTypeEnum.FORM.getType().equals(entity.getWebType());
|
||||
return type;
|
||||
}
|
||||
|
||||
private boolean isForm(AppGenModel appGenModel) {
|
||||
VisualdevEntity entity = appGenModel.getEntity();
|
||||
boolean type = (VisualWebTypeEnum.FORM_LIST.getType().equals(entity.getWebType())
|
||||
&& appGenModel.getDownloadCodeForm().getEnableFlow() == 0);
|
||||
return type;
|
||||
}
|
||||
|
||||
private boolean isView(AppGenModel appGenModel) {
|
||||
VisualdevEntity entity = appGenModel.getEntity();
|
||||
boolean type = VisualWebTypeEnum.DATA_VIEW.getType().equals(entity.getWebType());
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.yunzhupaas.base.util.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 别名对象
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v5.0.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/4/16 11:21:03
|
||||
*/
|
||||
@Data
|
||||
public class AliasModel {
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
private String tableName;
|
||||
/**
|
||||
* 表别名
|
||||
*/
|
||||
private String aliasName;
|
||||
/**
|
||||
* 字段别名map
|
||||
*/
|
||||
private Map<String, String> fieldsMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
package com.yunzhupaas.base.util.common;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.yunzhupaas.model.visualJson.FieLdsModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormAllModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormColumnModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormColumnTableModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormEnum;
|
||||
import com.yunzhupaas.model.visualJson.config.RuleConfig;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 代码生成器数据处理工具类
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.2.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/8/26
|
||||
*/
|
||||
public class DataControlUtils {
|
||||
|
||||
/**
|
||||
* 将字符串的首字母转大写
|
||||
*
|
||||
* @param name 需要转换的字符串
|
||||
* @return
|
||||
*/
|
||||
public static String captureName(String name) {
|
||||
char[] ch = name.toCharArray();
|
||||
for (int i = 0; i < ch.length; i++) {
|
||||
if (i == 0) {
|
||||
ch[0] = Character.toUpperCase(ch[0]);
|
||||
}
|
||||
}
|
||||
StringBuffer a = new StringBuffer();
|
||||
a.append(ch);
|
||||
return a.toString();
|
||||
|
||||
}
|
||||
|
||||
public static String initialLowercase(String name) {
|
||||
char[] ch = name.toCharArray();
|
||||
for (int i = 0; i < ch.length; i++) {
|
||||
if (i == 0) {
|
||||
ch[0] = Character.toLowerCase(ch[0]);
|
||||
}
|
||||
}
|
||||
StringBuffer a = new StringBuffer();
|
||||
a.append(ch);
|
||||
return a.toString();
|
||||
}
|
||||
|
||||
public static String getPlaceholder(String yunzhupaasKey) {
|
||||
String placeholderName = "请选择";
|
||||
switch (yunzhupaasKey) {
|
||||
case YunzhupaasKeyConsts.BILLRULE:
|
||||
case YunzhupaasKeyConsts.MODIFYUSER:
|
||||
case YunzhupaasKeyConsts.CREATEUSER:
|
||||
case YunzhupaasKeyConsts.COM_INPUT:
|
||||
case YunzhupaasKeyConsts.TEXTAREA:
|
||||
placeholderName = "请输入";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return placeholderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 去重
|
||||
*
|
||||
* @param keyExtractor
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
||||
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
|
||||
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
||||
}
|
||||
|
||||
public static FieLdsModel setAbleIDs(FieLdsModel fieLdsModel) {
|
||||
if (fieLdsModel.getAbleDepIds() != null) {
|
||||
fieLdsModel.setAbleDepIds(JSONObject.toJSONString(fieLdsModel.getAbleDepIds()));
|
||||
}
|
||||
if (fieLdsModel.getAblePosIds() != null) {
|
||||
fieLdsModel.setAblePosIds(JSONObject.toJSONString(fieLdsModel.getAblePosIds()));
|
||||
}
|
||||
if (fieLdsModel.getAbleUserIds() != null) {
|
||||
fieLdsModel.setAbleUserIds(JSONObject.toJSONString(fieLdsModel.getAbleUserIds()));
|
||||
}
|
||||
if (fieLdsModel.getAbleRoleIds() != null) {
|
||||
fieLdsModel.setAbleRoleIds(JSONObject.toJSONString(fieLdsModel.getAbleRoleIds()));
|
||||
}
|
||||
if (fieLdsModel.getAbleGroupIds() != null) {
|
||||
fieLdsModel.setAbleGroupIds(JSONObject.toJSONString(fieLdsModel.getAbleGroupIds()));
|
||||
}
|
||||
if (fieLdsModel.getAbleIds() != null) {
|
||||
fieLdsModel.setAbleIds(JSONObject.toJSONString(fieLdsModel.getAbleIds()));
|
||||
}
|
||||
//model字段验证reg转换
|
||||
if (fieLdsModel.getConfig().getRegList() != null) {
|
||||
String o1 = JSONObject.toJSONString(JsonUtil.getObjectToString(fieLdsModel.getConfig().getRegList()));
|
||||
fieLdsModel.getConfig().setReg(o1);
|
||||
}
|
||||
return fieLdsModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单据规则配置获取
|
||||
* @param formAllModel
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, String> getBillRule(List<FormAllModel> formAllModel) {
|
||||
Map<String, String> billRuleMap = new HashMap<>();
|
||||
for (FormAllModel t : formAllModel) {
|
||||
if (FormEnum.mast.getMessage().equals(t.getYunzhupaasKey())) {
|
||||
FieLdsModel fieLdsModel = t.getFormColumnModel().getFieLdsModel();
|
||||
String ruleJson = getRuleJson(fieLdsModel);
|
||||
if (StringUtil.isNotEmpty(ruleJson)) {
|
||||
billRuleMap.put(fieLdsModel.getVModel(), ruleJson);
|
||||
}
|
||||
}
|
||||
if (FormEnum.mastTable.getMessage().equals(t.getYunzhupaasKey())) {
|
||||
FieLdsModel fieLdsModel = t.getFormMastTableModel().getMastTable().getFieLdsModel();
|
||||
String ruleJson = getRuleJson(fieLdsModel);
|
||||
if (StringUtil.isNotEmpty(ruleJson)) {
|
||||
billRuleMap.put(fieLdsModel.getVModel(), ruleJson);
|
||||
}
|
||||
}
|
||||
if (FormEnum.table.getMessage().equals(t.getYunzhupaasKey())) {
|
||||
FormColumnTableModel childModel = t.getChildList();
|
||||
String aliasLowName = childModel.getAliasLowName();
|
||||
List<FormColumnModel> childList = childModel.getChildList();
|
||||
for (FormColumnModel child : childList) {
|
||||
FieLdsModel fieLdsModel = child.getFieLdsModel();
|
||||
String ruleJson = getRuleJson(fieLdsModel);
|
||||
if (StringUtil.isNotEmpty(ruleJson)) {
|
||||
billRuleMap.put(aliasLowName + "_" + fieLdsModel.getVModel(), ruleJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return billRuleMap;
|
||||
}
|
||||
|
||||
private static String getRuleJson(FieLdsModel fieLdsModel) {
|
||||
Integer ruleType = fieLdsModel.getConfig().getRuleType();
|
||||
if (Objects.equals(ruleType, 2)) {
|
||||
RuleConfig ruleConfig = fieLdsModel.getConfig().getRuleConfig();
|
||||
if (ruleConfig != null) {
|
||||
return JsonUtil.getObjectToString(JsonUtil.getObjectToString(ruleConfig));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
package com.yunzhupaas.base.util.common;
|
||||
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.model.DownloadCodeForm;
|
||||
import com.yunzhupaas.base.model.form.DraftJsonModel;
|
||||
import com.yunzhupaas.base.model.form.FormDraftJsonModel;
|
||||
import com.yunzhupaas.model.OnlineDevData;
|
||||
import com.yunzhupaas.model.visualJson.FieLdsModel;
|
||||
import com.yunzhupaas.model.visualJson.FormCloumnUtil;
|
||||
import com.yunzhupaas.model.visualJson.FormDataModel;
|
||||
import com.yunzhupaas.model.visualJson.TableModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.*;
|
||||
import com.yunzhupaas.model.visualJson.config.ConfigModel;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 功能流程公共工具
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V5.2.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/8/25
|
||||
*/
|
||||
public class FunctionFormPublicUtil {
|
||||
|
||||
public static VisualdevEntity exportFlowFormJson(VisualdevEntity entity, GenerateParamModel generateParamModel) {
|
||||
VisualdevEntity visualdevEntity = new VisualdevEntity();
|
||||
// visualdevEntity.setId(entity.getId());
|
||||
visualdevEntity.setEnCode(entity.getEnCode());
|
||||
visualdevEntity.setFullName(entity.getFullName());
|
||||
visualdevEntity.setType(OnlineDevData.FORM_TYPE_SYS);
|
||||
visualdevEntity.setWebType(entity.getWebType());
|
||||
visualdevEntity.setCategory(entity.getCategory());
|
||||
visualdevEntity.setDescription(entity.getDescription());
|
||||
visualdevEntity.setSortCode(entity.getSortCode());
|
||||
visualdevEntity.setCreatorTime(entity.getCreatorTime());
|
||||
visualdevEntity.setCreatorUserId(entity.getCreatorUserId());
|
||||
visualdevEntity.setVisualTables(entity.getVisualTables());
|
||||
visualdevEntity.setDbLinkId(entity.getDbLinkId());
|
||||
// 填写默认url
|
||||
DownloadCodeForm downloadCodeForm = generateParamModel.getDownloadCodeForm();
|
||||
String appUrl = "/pages/apply/" + generateParamModel.getClassName();
|
||||
visualdevEntity.setAppUrlAddress(appUrl);
|
||||
String formFileName = "/Form.vue";
|
||||
String webUrl = "extend/" + generateParamModel.getClassName().toLowerCase() + formFileName;
|
||||
visualdevEntity.setUrlAddress(webUrl);
|
||||
String downloadClassName = generateParamModel.getClassName().substring(0, 1).toUpperCase()
|
||||
+ generateParamModel.getClassName().substring(1);
|
||||
String interfaceUrl = "/api/" + downloadCodeForm.getModule() + "/" + downloadClassName;
|
||||
visualdevEntity.setInterfaceUrl(interfaceUrl);
|
||||
|
||||
List<FormAllModel> formAllModel = new ArrayList<>();
|
||||
forDataMode(entity, formAllModel);
|
||||
List<FormAllModel> mastList = formAllModel.stream()
|
||||
.filter(t -> FormEnum.mast.getMessage().equals(t.getYunzhupaasKey())).collect(Collectors.toList());
|
||||
List<DraftJsonModel> tempJson = new ArrayList<>();
|
||||
for (FormAllModel mastModel : mastList) {
|
||||
FieLdsModel fieLdsModel = mastModel.getFormColumnModel().getFieLdsModel();
|
||||
String model = fieLdsModel.getVModel();
|
||||
ConfigModel config = fieLdsModel.getConfig();
|
||||
if (StringUtil.isNotEmpty(model)) {
|
||||
DraftJsonModel engineModel = new DraftJsonModel();
|
||||
String label = config.getLabel();
|
||||
engineModel.setFiledId(model);
|
||||
engineModel.setFiledName(label);
|
||||
engineModel.setRequired(config.isRequired());
|
||||
engineModel.setYunzhupaasKey(config.getYunzhupaasKey());
|
||||
engineModel.setMultiple(fieLdsModel.getMultiple());
|
||||
tempJson.add(engineModel);
|
||||
}
|
||||
}
|
||||
List<FormAllModel> tableList = formAllModel.stream()
|
||||
.filter(t -> FormEnum.table.getMessage().equals(t.getYunzhupaasKey())).collect(Collectors.toList());
|
||||
Map<String, AliasModel> tableListAll = generateParamModel.getTableAliseMap();
|
||||
for (FormAllModel model : tableList) {
|
||||
String table = model.getChildList().getTableName();
|
||||
String name = DataControlUtils.initialLowercase(tableListAll.get(table).getAliasName());
|
||||
FormColumnTableModel childList = model.getChildList();
|
||||
String label = childList.getLabel();
|
||||
boolean required = childList.isRequired();
|
||||
DraftJsonModel engineModel = new DraftJsonModel();
|
||||
engineModel.setFiledId(name + "List");
|
||||
engineModel.setFiledName(label);
|
||||
engineModel.setRequired(required);
|
||||
tempJson.add(engineModel);
|
||||
for (FormColumnModel columnModel : model.getChildList().getChildList()) {
|
||||
String vModel = columnModel.getFieLdsModel().getVModel();
|
||||
String childLable = columnModel.getFieLdsModel().getConfig().getLabel();
|
||||
ConfigModel config = columnModel.getFieLdsModel().getConfig();
|
||||
if (StringUtil.isNotEmpty(vModel)) {
|
||||
DraftJsonModel childModel = new DraftJsonModel();
|
||||
childModel.setFiledId(name + "List-" + vModel);
|
||||
childModel.setFiledName(label + "-" + childLable);
|
||||
childModel.setRequired(config.isRequired());
|
||||
childModel.setYunzhupaasKey(config.getYunzhupaasKey());
|
||||
childModel.setMultiple(columnModel.getFieLdsModel().getMultiple());
|
||||
tempJson.add(childModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<FormAllModel> mastTableList = formAllModel.stream()
|
||||
.filter(t -> FormEnum.mastTable.getMessage().equals(t.getYunzhupaasKey())).collect(Collectors.toList());
|
||||
for (FormAllModel mastTableModel : mastTableList) {
|
||||
FormMastTableModel formMastTableModel = mastTableModel.getFormMastTableModel();
|
||||
FieLdsModel fieLdsModel = formMastTableModel.getMastTable().getFieLdsModel();
|
||||
String model = formMastTableModel.getVModel();
|
||||
ConfigModel config = fieLdsModel.getConfig();
|
||||
if (StringUtil.isNotEmpty(model)) {
|
||||
DraftJsonModel engineModel = new DraftJsonModel();
|
||||
String label = config.getLabel();
|
||||
engineModel.setFiledId(model);
|
||||
engineModel.setFiledName(label);
|
||||
engineModel.setRequired(config.isRequired());
|
||||
engineModel.setYunzhupaasKey(config.getYunzhupaasKey());
|
||||
engineModel.setMultiple(fieLdsModel.getMultiple());
|
||||
tempJson.add(engineModel);
|
||||
}
|
||||
}
|
||||
FormDraftJsonModel draftJsonModel = new FormDraftJsonModel();
|
||||
String Tem = JsonUtil.getObjectToString(tempJson);
|
||||
visualdevEntity.setFormData(Tem);
|
||||
draftJsonModel.setDraftJson(Tem);
|
||||
draftJsonModel.setTableJson(entity.getVisualTables());
|
||||
return visualdevEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装数据
|
||||
*
|
||||
* @param entity
|
||||
* @param formAllModel
|
||||
*/
|
||||
private static void forDataMode(VisualdevEntity entity, List<FormAllModel> formAllModel) {
|
||||
// formTempJson
|
||||
FormDataModel formData = JsonUtil.getJsonToBean(entity.getFormData(), FormDataModel.class);
|
||||
List<FieLdsModel> list = JsonUtil.getJsonToList(formData.getFields(), FieLdsModel.class);
|
||||
List<TableModel> tableModelList = JsonUtil.getJsonToList(entity.getVisualTables(), TableModel.class);
|
||||
RecursionForm recursionForm = new RecursionForm(list, tableModelList);
|
||||
FormCloumnUtil.recursionForm(recursionForm, formAllModel);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,687 @@
|
||||
package com.yunzhupaas.base.util.common;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||
import com.baomidou.mybatisplus.generator.config.builder.CustomFile;
|
||||
import com.yunzhupaas.base.entity.SysConfigEntity;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.model.ColumnDataModel;
|
||||
import com.yunzhupaas.base.model.DownloadCodeForm;
|
||||
import com.yunzhupaas.base.model.Template6.ColumnListField;
|
||||
import com.yunzhupaas.base.model.Template7.Template7Model;
|
||||
import com.yunzhupaas.base.model.print.PrintOption;
|
||||
import com.yunzhupaas.base.service.PrintDevService;
|
||||
import com.yunzhupaas.constant.FileTypeConstant;
|
||||
import com.yunzhupaas.constant.GenerateConstant;
|
||||
import com.yunzhupaas.model.visualJson.FieLdsModel;
|
||||
import com.yunzhupaas.model.visualJson.TemplateJsonModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormAllModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormColumnModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormEnum;
|
||||
import com.yunzhupaas.model.visualJson.config.HeaderModel;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.util.context.SpringContext;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
import lombok.Cleanup;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.5.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/5/31
|
||||
*/
|
||||
public class GenerateCommon {
|
||||
public static final String IS_CLOUD = "single";
|
||||
|
||||
private static PrintDevService printDevService = SpringContext.getBean(PrintDevService.class);
|
||||
|
||||
public static String getLocalBasePath() {
|
||||
return FileUploadUtils.getLocalBasePath();
|
||||
}
|
||||
|
||||
public static String getPath(String type) {
|
||||
return FilePathUtil.getFilePath(type);
|
||||
}
|
||||
|
||||
public static List<PrintOption> getList(List<String> ids) {
|
||||
return printDevService.getPrintTemplateOptions(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取代码生成基础信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Template7Model getTemplate7Model(List<SysConfigEntity> list) {
|
||||
String author = "";
|
||||
String copyright = "";
|
||||
String version = "";
|
||||
for (SysConfigEntity item : list) {
|
||||
if ("companyName".equals(item.getFkey())) {
|
||||
author = item.getValue();
|
||||
}
|
||||
if ("copyright".equals(item.getFkey())) {
|
||||
copyright = item.getValue();
|
||||
}
|
||||
if ("sysVersion".equals(item.getFkey())) {
|
||||
version = item.getValue();
|
||||
}
|
||||
}
|
||||
Template7Model temModel = new Template7Model();
|
||||
temModel.setServiceDirectory(
|
||||
GenerateCommon.getLocalBasePath() + GenerateCommon.getPath(FileTypeConstant.CODETEMP));
|
||||
temModel.setCreateDate(DateUtil.daFormat(new Date()));
|
||||
temModel.setCreateUser(StringUtil.isNotEmpty(author) ? author : GenerateConstant.AUTHOR);
|
||||
temModel.setCopyright(StringUtil.isNotEmpty(copyright) ? copyright : GenerateConstant.COPYRIGHT);
|
||||
temModel.setVersion(StringUtil.isNotEmpty(version) ? version : GenerateConstant.VERSION);
|
||||
temModel.setDescription(GenerateConstant.DESCRIPTION);
|
||||
return temModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自定义文件(模板和生成路径)
|
||||
*
|
||||
* @param generateParamModel
|
||||
* @return
|
||||
*/
|
||||
public static List<CustomFile> getCustomFileList(GenerateParamModel generateParamModel) {
|
||||
Template7Model template7Model = generateParamModel.getTemplate7Model();
|
||||
String path = template7Model.getServiceDirectory() + generateParamModel.getFileName() + File.separator;
|
||||
DownloadCodeForm downloadCodeForm = generateParamModel.getDownloadCodeForm();
|
||||
ArrayList<CustomFile> custFileList = new ArrayList<>();
|
||||
if (generateParamModel.isMainTable()) {
|
||||
custFileList.add(new CustomFile.Builder().templatePath("java/Controller.java.vm")
|
||||
.formatNameFunction(tableInfo -> tableInfo.getControllerName())
|
||||
.fileName(StringPool.DOT_JAVA)
|
||||
.filePath(getCustomFilePath(path, OutputFile.controller.name(), downloadCodeForm))
|
||||
.enableFileOverride().build());
|
||||
}
|
||||
custFileList.add(new CustomFile.Builder().templatePath("java/Entity.java.vm")
|
||||
.formatNameFunction(tableInfo -> tableInfo.getEntityName())
|
||||
.fileName(StringPool.DOT_JAVA)
|
||||
.filePath(getCustomFilePath(path, OutputFile.entity.name(), downloadCodeForm)).enableFileOverride()
|
||||
.build());
|
||||
custFileList.add(new CustomFile.Builder().templatePath("java/Mapper.java.vm")
|
||||
.formatNameFunction(tableInfo -> tableInfo.getMapperName())
|
||||
.fileName(StringPool.DOT_JAVA)
|
||||
.filePath(getCustomFilePath(path, OutputFile.mapper.name(), downloadCodeForm)).enableFileOverride()
|
||||
.build());
|
||||
custFileList.add(new CustomFile.Builder().templatePath("java/Service.java.vm")
|
||||
.formatNameFunction(tableInfo -> tableInfo.getServiceName())
|
||||
.fileName(StringPool.DOT_JAVA)
|
||||
.filePath(getCustomFilePath(path, OutputFile.service.name(), downloadCodeForm)).enableFileOverride()
|
||||
.build());
|
||||
custFileList.add(new CustomFile.Builder().templatePath("java/ServiceImpl.java.vm")
|
||||
.formatNameFunction(tableInfo -> tableInfo.getServiceImplName())
|
||||
.fileName(StringPool.DOT_JAVA)
|
||||
.filePath(getCustomFilePath(path, OutputFile.serviceImpl.name(), downloadCodeForm)).enableFileOverride()
|
||||
.build());
|
||||
custFileList.add(new CustomFile.Builder().templatePath("java/Mapper.xml.vm")
|
||||
.formatNameFunction(tableInfo -> tableInfo.getXmlName())
|
||||
.fileName(StringPool.DOT_XML).filePath(getCustomFilePath(path, OutputFile.xml.name(), downloadCodeForm))
|
||||
.enableFileOverride().build());
|
||||
return custFileList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模板名称获取生成文件路径
|
||||
*
|
||||
* @param path
|
||||
* @param codeName
|
||||
* @param downloadCodeForm
|
||||
* @return
|
||||
*/
|
||||
public static String getCustomFilePath(String path, String codeName, DownloadCodeForm downloadCodeForm) {
|
||||
String eachName = "";
|
||||
String frontName = "";
|
||||
String modulName = downloadCodeForm.getModule();
|
||||
String framePath = downloadCodeForm.getModulePackageName();
|
||||
switch (codeName) {
|
||||
case "controller":
|
||||
framePath = getCloudPath("-controller", downloadCodeForm);
|
||||
break;
|
||||
case "entity":
|
||||
framePath = getCloudPath("-entity", downloadCodeForm);
|
||||
break;
|
||||
case "mapper":
|
||||
framePath = getCloudPath("-biz", downloadCodeForm);
|
||||
break;
|
||||
case "xml":
|
||||
if ("cloud".equals(GenerateCommon.IS_CLOUD)) {
|
||||
String fileFront = "yunzhupaas-" + modulName + File.separator + "yunzhupaas-" + modulName + "-biz"
|
||||
+ File.separator;
|
||||
if ("form".equals(modulName)) {
|
||||
fileFront = "yunzhupaas-workflow" + File.separator + "yunzhupaas-workflow-form" + File.separator
|
||||
+ "yunzhupaas-workflow-form-biz" + File.separator;
|
||||
}
|
||||
framePath = fileFront + "src" + File.separator + "main" + File.separator + "resources";
|
||||
return path + File.separator + "java" + File.separator + framePath + File.separator + "mapper"
|
||||
+ File.separator;
|
||||
}
|
||||
return path + File.separator + "resources" + File.separator + "mapper"
|
||||
+ File.separator;
|
||||
case "service":
|
||||
framePath = getCloudPath("-biz", downloadCodeForm);
|
||||
break;
|
||||
case "serviceImpl":
|
||||
codeName = "impl";
|
||||
frontName = "service" + File.separator;
|
||||
framePath = getCloudPath("-biz", downloadCodeForm);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return path + File.separator + "java" + File.separator + framePath + File.separator + frontName + codeName
|
||||
+ File.separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微服务框架路径
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/3/22
|
||||
*/
|
||||
public static String getCloudPath(String houzui, DownloadCodeForm downloadCodeForm) {
|
||||
// 发起表单
|
||||
if ("form".equals(downloadCodeForm.getModule())) {
|
||||
return "yunzhupaas-workflow" + File.separator + "yunzhupaas-workflow-form" + File.separator
|
||||
+ "yunzhupaas-workflow-" + downloadCodeForm.getModule() + houzui + File.separator
|
||||
+ "src" + File.separator + "main" + File.separator + "java" + File.separator + "com"
|
||||
+ File.separator + "yunzhupaas" + File.separator + "form";
|
||||
}
|
||||
String framePath = "yunzhupaas-" + downloadCodeForm.getModule() + File.separator + "yunzhupaas-"
|
||||
+ downloadCodeForm.getModule() + houzui + File.separator
|
||||
+ "src" + File.separator + "main" + File.separator + "java" + File.separator
|
||||
+ downloadCodeForm.getModulePackageName();
|
||||
return framePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取导出字段
|
||||
*
|
||||
* @param columnList
|
||||
* @return
|
||||
*/
|
||||
public static List<ColumnListField> getExpotColumn(List<ColumnListField> columnList) {
|
||||
List<ColumnListField> listOptions = new ArrayList<>();
|
||||
columnList.forEach(item -> {
|
||||
ColumnListField columnListField = new ColumnListField();
|
||||
BeanUtil.copyProperties(item, columnListField);
|
||||
if (item.getVModel().toLowerCase().startsWith(YunzhupaasKeyConsts.CHILD_TABLE_PREFIX)) {
|
||||
columnListField.setTableType(2);
|
||||
columnListField.setVModel(item.getVModel().split("-")[1]);
|
||||
} else if (item.getVModel().toLowerCase().contains("_yunzhupaas_")) {
|
||||
columnListField.setTableType(1);
|
||||
columnListField.setVModel(item.getVModel().split("_yunzhupaas_")[1]);
|
||||
} else {
|
||||
columnListField.setTableType(0);
|
||||
}
|
||||
if ("static".equals(item.getConfig().getDataType())) {
|
||||
columnListField.setOptions(JsonUtil.getObjectToString(item.getOptions()));
|
||||
if (item.getYunzhupaasKey().equals(YunzhupaasKeyConsts.CHECKBOX)) {
|
||||
columnListField.setMultiple(true);
|
||||
}
|
||||
}
|
||||
listOptions.add(columnListField);
|
||||
});
|
||||
return listOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合计千分位字段列表
|
||||
*
|
||||
* @param mast 主表字段
|
||||
* @param mastTable 副表字段
|
||||
* @param type 列表类型 4-行内编辑
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getSummaryThousandList(List<FormAllModel> mast, List<FormAllModel> mastTable,
|
||||
Integer type) {
|
||||
String suffix = "_name";
|
||||
if (type == 4) {
|
||||
suffix = "";
|
||||
}
|
||||
List<String> thousandsField = new ArrayList<>();
|
||||
for (FormAllModel f : mast) {
|
||||
FieLdsModel fm = f.getFormColumnModel().getFieLdsModel();
|
||||
if (fm.isThousands()) {
|
||||
thousandsField.add(fm.getVModel() + suffix);
|
||||
}
|
||||
}
|
||||
for (FormAllModel f : mastTable) {
|
||||
FieLdsModel fm = f.getFormMastTableModel().getMastTable().getFieLdsModel();
|
||||
if (fm.isThousands()) {
|
||||
thousandsField.add(f.getFormMastTableModel().getTable() + "." + fm.getVModel() + suffix);
|
||||
}
|
||||
}
|
||||
return thousandsField;
|
||||
}
|
||||
|
||||
/**
|
||||
* 复杂表头 对象生成。
|
||||
*
|
||||
* @param path
|
||||
* @param generateParamModel
|
||||
* @param entity
|
||||
* @param downloadCodeForm
|
||||
* @param objectAll
|
||||
*/
|
||||
public static void createComplexHeaderExcelVo(String path, GenerateParamModel generateParamModel,
|
||||
VisualdevEntity entity,
|
||||
DownloadCodeForm downloadCodeForm, Map<String, Object> objectAll) {
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(entity.getColumnData(), ColumnDataModel.class);
|
||||
JsonUtil.getListToJsonArray(columnDataModel.getComplexHeaderList());
|
||||
List<HeaderModel> complexHeaderList = columnDataModel.getComplexHeaderList();
|
||||
String templateName = File.separator + "java" + File.separator + "ExcelVO.java.vm";
|
||||
VelocityContext context = new VelocityContext();
|
||||
Map<String, Object> object = new HashMap<>();
|
||||
object.put("genInfo", generateParamModel.getTemplate7Model());
|
||||
object.put("package", generateParamModel.getDownloadCodeForm().getModulePackageName());
|
||||
object.put("module", downloadCodeForm.getModule());
|
||||
object.put("isMain", true);
|
||||
object.put("isComplexVo", true);
|
||||
object.put("importFields", objectAll.get("importFields"));
|
||||
for (HeaderModel item : complexHeaderList) {
|
||||
if (item.getChildColumns().size() > 0) {
|
||||
String className = "Complex" + item.getId();
|
||||
object.put("complexList", JsonUtil.getListToJsonArray(item.getChildColumns()));
|
||||
object.put("className", className);
|
||||
context.put("context", object);
|
||||
String fileNames = GenerateCommon.getFileName(path, templateName, className, downloadCodeForm);
|
||||
GenerateCommon.velocityWriterFile(context, templateName, fileNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染html模板
|
||||
*
|
||||
* @param path 路径
|
||||
* @param object 模板数据
|
||||
* @param templatePath 模板路径
|
||||
*/
|
||||
public static void htmlTemplates(String path, Map<String, Object> object, String templatePath, int type,
|
||||
boolean hasImport,
|
||||
DownloadCodeForm downloadCodeForm, GenerateInterface codeUtil) throws Exception {
|
||||
// 获取模板列表
|
||||
List<String> templates = codeUtil.getTemplates(templatePath, type, hasImport);
|
||||
// 界面模板
|
||||
VelocityContext context = new VelocityContext();
|
||||
context.put("context", object);
|
||||
for (String template : templates) {
|
||||
String className = object.get("className").toString();
|
||||
String fileNames = GenerateCommon.getFileName(path, template, className, downloadCodeForm);
|
||||
GenerateCommon.velocityWriterFile(context, template, fileNames);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模板 获取文件名
|
||||
*
|
||||
* @param path 路径
|
||||
* @param template 模板名称
|
||||
* @param className 文件名称
|
||||
* @return
|
||||
*/
|
||||
public static String getFileName(String path, String template, String className,
|
||||
DownloadCodeForm downloadCodeForm) {
|
||||
String framePath = GenerateCommon.getCloudPath("-entity", downloadCodeForm);
|
||||
String modelfolder = downloadCodeForm.getMainClassName();
|
||||
String modelPath = XSSEscape
|
||||
.escapePath(path + File.separator + "java" + File.separator + framePath + File.separator + "model"
|
||||
+ File.separator + modelfolder.toLowerCase());
|
||||
String htmlPath = XSSEscape.escapePath(
|
||||
path + File.separator + "html" + File.separator + "web" + File.separator + modelfolder.toLowerCase());
|
||||
File htmlfile = new File(htmlPath);
|
||||
File modelfile = new File(modelPath);
|
||||
if (!htmlfile.exists()) {
|
||||
htmlfile.mkdirs();
|
||||
}
|
||||
if (!modelfile.exists()) {
|
||||
modelfile.mkdirs();
|
||||
}
|
||||
|
||||
if (template.contains("extraForm.vue.vm") || template.contains("ExtraForm.vue.vm")) {
|
||||
return htmlPath + File.separator + "ExtraForm.vue";
|
||||
}
|
||||
if (template.contains("Form.vue.vm")) {
|
||||
return htmlPath + File.separator + "Form.vue";
|
||||
}
|
||||
if (template.contains("FormPopup.vue.vm")) {
|
||||
return htmlPath + File.separator + "FormPopup.vue";
|
||||
}
|
||||
if (template.contains("index.vue.vm")) {
|
||||
return htmlPath + File.separator + "index.vue";
|
||||
}
|
||||
if (template.contains("indexEdit.vue.vm")) {
|
||||
return htmlPath + File.separator + "index.vue";
|
||||
}
|
||||
if (template.contains("Detail.vue.vm")) {
|
||||
return htmlPath + File.separator + "Detail.vue";
|
||||
}
|
||||
if (template.contains("api.ts.vm")) {
|
||||
// vue3生成ts文件夹
|
||||
String htmlTSPath = XSSEscape
|
||||
.escapePath(path + File.separator + "html" + File.separator + "web" + File.separator
|
||||
+ modelfolder.toLowerCase() + File.separator + "helper");
|
||||
File htmlJSfile = new File(htmlTSPath);
|
||||
if (!htmlJSfile.exists() && !"form".equals(downloadCodeForm.getModule())) {
|
||||
htmlJSfile.mkdirs();
|
||||
}
|
||||
|
||||
return htmlPath + File.separator + "helper" + File.separator + "api.ts";
|
||||
}
|
||||
// 后端代码
|
||||
if (template.contains("InfoVO.java.vm")) {
|
||||
return modelPath + File.separator + className + "InfoVO.java";
|
||||
}
|
||||
if (template.contains("Form.java.vm")) {
|
||||
return modelPath + File.separator + className + "Form.java";
|
||||
}
|
||||
if (template.contains("ListVO.java.vm")) {
|
||||
return modelPath + File.separator + className + "ListVO.java";
|
||||
}
|
||||
if (template.contains("GroupVO.java.vm")) {
|
||||
return modelPath + File.separator + className + "GroupVO.java";
|
||||
}
|
||||
if (template.contains("Pagination.java.vm")) {
|
||||
return modelPath + File.separator + className + "Pagination.java";
|
||||
}
|
||||
if (template.contains("ExcelVO.java.vm")) {
|
||||
return modelPath + File.separator + className + "ExcelVO.java";
|
||||
}
|
||||
if (template.contains("ExcelErrorVO.java.vm")) {
|
||||
return modelPath + File.separator + className + "ExcelErrorVO.java";
|
||||
}
|
||||
if (template.contains("Model.java.vm")) {
|
||||
return modelPath + File.separator + className + "Model.java";
|
||||
}
|
||||
if (template.contains("ListVO.java.vm")) {
|
||||
return modelPath + File.separator + className + "ListVO.java";
|
||||
}
|
||||
if (template.contains("Constant.java.vm")) {
|
||||
return modelPath + File.separator + className + "Constant.java";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成代码
|
||||
*
|
||||
* @param context
|
||||
* @param template
|
||||
* @param fileNames
|
||||
*/
|
||||
public static void velocityWriterFile(VelocityContext context, String template, String fileNames) {
|
||||
try {
|
||||
// 渲染模板
|
||||
@Cleanup
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tpl = Velocity.getTemplate(template, Constants.UTF_8);
|
||||
tpl.merge(context, sw);
|
||||
if (fileNames != null) {
|
||||
File file = new File(XSSEscape.escapePath(fileNames));
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
@Cleanup
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
IOUtils.write(sw.toString(), fos, Constants.UTF_8);
|
||||
IOUtils.closeQuietly(sw);
|
||||
IOUtils.closeQuietly(fos);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("渲染模板失败,表名:" + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口参数配置,templatejson
|
||||
*
|
||||
* @param allModels
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, Object> getInterTemplateJson(List<FormAllModel> allModels,
|
||||
Map<String, String> childTableKey) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
for (FormAllModel item : allModels) {
|
||||
if (FormEnum.mast.getMessage().equals(item.getYunzhupaasKey())) {
|
||||
FieLdsModel fieLdsModel = BeanUtil.copyProperties(item.getFormColumnModel().getFieLdsModel(),
|
||||
FieLdsModel.class);
|
||||
if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
|
||||
map.put(fieLdsModel.getVModel(), getTemJsonModel(fieLdsModel, childTableKey));
|
||||
}
|
||||
}
|
||||
if (FormEnum.mastTable.getMessage().equals(item.getYunzhupaasKey())) {
|
||||
FieLdsModel fieLdsModel = BeanUtil.copyProperties(
|
||||
item.getFormMastTableModel().getMastTable().getFieLdsModel(), FieLdsModel.class);
|
||||
if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
|
||||
map.put(item.getFormMastTableModel().getVModel(), getTemJsonModel(fieLdsModel, childTableKey));
|
||||
}
|
||||
}
|
||||
if (FormEnum.table.getMessage().equals(item.getYunzhupaasKey())) {
|
||||
List<FormColumnModel> childList = item.getChildList().getChildList();
|
||||
for (FormColumnModel columnModel : childList) {
|
||||
FieLdsModel fieLdsModel = BeanUtil.copyProperties(columnModel.getFieLdsModel(), FieLdsModel.class);
|
||||
if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
|
||||
HashMap<String, String> childTableMap = new HashMap<>();
|
||||
childTableMap.put(item.getChildList().getTableModel(), item.getChildList().getAliasLowName());
|
||||
map.put(item.getChildList().getAliasLowName() + fieLdsModel.getVModel(),
|
||||
getTemJsonModel(fieLdsModel, childTableMap));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static List<TemplateJsonModel> getTemJsonModel(FieLdsModel fieLdsModel, Map<String, String> childTableKey) {
|
||||
List<TemplateJsonModel> templateJson = fieLdsModel.getConfig().getTemplateJson();
|
||||
List<TemplateJsonModel> json = templateJson.size() > 0 ? templateJson
|
||||
: JsonUtil.getJsonToList(fieLdsModel.getTemplateJson(), TemplateJsonModel.class);
|
||||
for (TemplateJsonModel t : json) {
|
||||
if (t.getRelationField() != null && t.getRelationField().contains("-")
|
||||
&& Objects.equals(t.getSourceType(), 1)) {
|
||||
String[] split = t.getRelationField().split("-");
|
||||
t.setRelationField(childTableKey.get(split[0]) + "List-" + split[1]);
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取非系统控件字段
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getNotSystemFields(List<FormAllModel> mast, List<FormAllModel> mastTable,
|
||||
List<FormAllModel> childTable,
|
||||
GenerateParamModel generateParamModel) {
|
||||
List<String> list = new ArrayList<>();
|
||||
String table = generateParamModel.getTable();
|
||||
boolean mainTable = generateParamModel.isMainTable();
|
||||
List<FormColumnModel> fields = new ArrayList<>();
|
||||
for (FormAllModel fam : mast) {
|
||||
if (mainTable) {
|
||||
fields.add(fam.getFormColumnModel());
|
||||
}
|
||||
}
|
||||
for (FormAllModel fam : mastTable) {
|
||||
if (table.equals(fam.getFormMastTableModel().getTable())) {
|
||||
fields.add(fam.getFormMastTableModel().getMastTable());
|
||||
}
|
||||
}
|
||||
for (FormAllModel fam : childTable) {
|
||||
if (table.equals(fam.getChildList().getTableName())) {
|
||||
fields.addAll(fam.getChildList().getChildList());
|
||||
}
|
||||
}
|
||||
for (FormColumnModel fcm : fields) {
|
||||
if (!YunzhupaasKeyConsts.getSystemKey().contains(fcm.getFieLdsModel().getConfig().getYunzhupaasKey())
|
||||
&& StringUtil.isNotEmpty(fcm.getFieLdsModel().getFieldAlias())) {
|
||||
list.add(fcm.getFieLdsModel().getFieldAlias().toUpperCase());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除对象内的json字符串
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String objRemoveJson(String str) {
|
||||
JSONObject object = JSONObject.parseObject(str);
|
||||
|
||||
JSONArray columnList = object.getJSONArray("columnList");
|
||||
removeJson(columnList);
|
||||
object.put("columnList", columnList);
|
||||
|
||||
JSONArray searchList = object.getJSONArray("searchList");
|
||||
removeJson(searchList);
|
||||
object.put("searchList", searchList);
|
||||
|
||||
JSONObject ruleList = object.getJSONObject("ruleList");
|
||||
ruleRemoveJson(ruleList);
|
||||
object.put("ruleList", ruleList);
|
||||
|
||||
JSONObject ruleListApp = object.getJSONObject("ruleListApp");
|
||||
ruleRemoveJson(ruleListApp);
|
||||
object.put("ruleListApp", ruleListApp);
|
||||
|
||||
JSONArray columnOptions = object.getJSONArray("columnOptions");
|
||||
removeJson(columnOptions);
|
||||
object.put("columnOptions", columnOptions);
|
||||
|
||||
JSONArray defaultColumnList = object.getJSONArray("defaultColumnList");
|
||||
removeJson(defaultColumnList);
|
||||
object.put("defaultColumnList", defaultColumnList);
|
||||
|
||||
JSONArray sortList = object.getJSONArray("sortList");
|
||||
removeJson(sortList);
|
||||
object.put("sortList", sortList);
|
||||
|
||||
JSONArray fields = object.getJSONArray("fields");
|
||||
removeJson(fields);
|
||||
object.put("fields", fields);
|
||||
|
||||
object.remove("funcs");
|
||||
return object.toJSONString();
|
||||
}
|
||||
|
||||
private static void ruleRemoveJson(JSONObject ruleList) {
|
||||
if (ruleList != null) {
|
||||
JSONArray conditionList = ruleList.getJSONArray("conditionList");
|
||||
if (conditionList != null) {
|
||||
for (Object o : conditionList) {
|
||||
JSONObject obj = (JSONObject) o;
|
||||
JSONArray groups = obj.getJSONArray("groups");
|
||||
removeJson(groups);
|
||||
obj.put("groups", groups);
|
||||
}
|
||||
ruleList.put("conditionList", conditionList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归移除对应属性
|
||||
*
|
||||
* @param jsonArray
|
||||
*/
|
||||
public static void removeJson(JSONArray jsonArray) {
|
||||
if (jsonArray == null || jsonArray.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
|
||||
String yunzhupaaskey = jsonObject.getJSONObject("__config__").getString("yunzhupaasKey");
|
||||
List<String> childrenListAll = new ArrayList() {
|
||||
{
|
||||
add(FormEnum.card.getMessage());
|
||||
add(FormEnum.row.getMessage());
|
||||
add(FormEnum.tab.getMessage());
|
||||
add(FormEnum.collapse.getMessage());
|
||||
add(FormEnum.collapseItem.getMessage());
|
||||
add(FormEnum.tabItem.getMessage());
|
||||
add(FormEnum.tableGrid.getMessage());
|
||||
add(FormEnum.tableGridTr.getMessage());
|
||||
add(FormEnum.tableGridTd.getMessage());
|
||||
}
|
||||
};
|
||||
if (childrenListAll.contains(yunzhupaaskey) || StringUtil.isEmpty(yunzhupaaskey)) {
|
||||
JSONObject config = jsonObject.getJSONObject("__config__");
|
||||
config.remove("on");
|
||||
JSONArray childArray = config.getJSONArray("children");
|
||||
removeJson(childArray);
|
||||
config.put("children", childArray);
|
||||
jsonObject.put("__config__", config);
|
||||
} else if (FormEnum.table.getMessage().equals(yunzhupaaskey)) {
|
||||
JSONObject configA = jsonObject.getJSONObject("__config__");
|
||||
configA.remove("on");
|
||||
JSONArray children = configA.getJSONArray("children");
|
||||
for (int k = 0; k < children.size(); k++) {
|
||||
JSONObject childrenObject = (JSONObject) children.get(k);
|
||||
childrenObject.remove("on");
|
||||
JSONObject config = childrenObject.getJSONObject("__config__");
|
||||
config.remove("on");
|
||||
if (!"static".equals(config.get("dataType"))) {
|
||||
childrenObject.remove("options");
|
||||
config.remove("options");
|
||||
}
|
||||
childrenObject.put("__config__", config);
|
||||
}
|
||||
configA.put("children", children);
|
||||
if (!"static".equals(configA.get("dataType"))) {
|
||||
jsonObject.remove("options");
|
||||
configA.remove("options");
|
||||
}
|
||||
jsonObject.put("__config__", configA);
|
||||
}
|
||||
jsonObject.remove("on");
|
||||
JSONObject config = jsonObject.getJSONObject("__config__");
|
||||
config.remove("on");
|
||||
if (!"static".equals(config.get("dataType"))) {
|
||||
jsonObject.remove("options");
|
||||
config.remove("options");
|
||||
}
|
||||
jsonObject.put("__config__", config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除代码生成不支持的对象
|
||||
*
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
public static String delNotSupport(Object obj) {
|
||||
if (obj instanceof JSONArray) {
|
||||
List<Object> collect = JsonUtil.getJsonToJsonArray(JsonUtil.getObjectToString(obj)).stream()
|
||||
.filter(t -> !"calculate".equals(JsonUtil.entityToMap(t).get("yunzhupaasKey")))
|
||||
.collect(Collectors.toList());
|
||||
return JSONObject.toJSONString(collect, SerializerFeature.WriteMapNullValue,
|
||||
SerializerFeature.PrettyFormat);
|
||||
}
|
||||
return JSONObject.toJSONString(obj, SerializerFeature.WriteMapNullValue, SerializerFeature.PrettyFormat);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.yunzhupaas.base.util.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.5.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/5/31
|
||||
*/
|
||||
public interface GenerateInterface {
|
||||
|
||||
/**
|
||||
* 获取 前端 及 后端模板
|
||||
*
|
||||
* @param templatePath
|
||||
* @param type
|
||||
* @param hasImport
|
||||
* @return
|
||||
*/
|
||||
List<String> getTemplates(String templatePath, int type, boolean hasImport);
|
||||
|
||||
/**
|
||||
* 获取副子表model、list模板
|
||||
*
|
||||
* @param isChild
|
||||
* @return
|
||||
*/
|
||||
List<String> getChildTemps(boolean isChild);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.yunzhupaas.base.util.common;
|
||||
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.model.DownloadCodeForm;
|
||||
import com.yunzhupaas.base.model.Template7.Template7Model;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.database.model.entity.DbLinkEntity;
|
||||
import com.yunzhupaas.database.util.DataSourceUtil;
|
||||
import com.yunzhupaas.model.visualJson.TableModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.FormAllModel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.5.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/5/31
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class GenerateParamModel {
|
||||
private DataSourceUtil dataSourceUtil;
|
||||
private String path;
|
||||
private String fileName;
|
||||
private String templatesPath;
|
||||
private DownloadCodeForm downloadCodeForm;
|
||||
private VisualdevEntity entity;
|
||||
private UserInfo userInfo;
|
||||
private ConfigValueUtil configValueUtil;
|
||||
private DbLinkEntity linkEntity;
|
||||
/**
|
||||
* 当前表名
|
||||
*/
|
||||
private String table;
|
||||
/**
|
||||
* 主表主键:映射字段
|
||||
*/
|
||||
private String pKeyName;
|
||||
/**
|
||||
* 主表主键:原字段
|
||||
*/
|
||||
private String pKeyNameOriginal;
|
||||
/**
|
||||
* 当前表类名
|
||||
*/
|
||||
private String className;
|
||||
/**
|
||||
* 代码生成基础信息
|
||||
*/
|
||||
private Template7Model template7Model;
|
||||
|
||||
/**
|
||||
* 乐观锁
|
||||
*/
|
||||
private boolean concurrencyLock;
|
||||
/**
|
||||
* 是否自增
|
||||
*/
|
||||
private boolean autoIncrement;
|
||||
/**
|
||||
* 是否主表
|
||||
*/
|
||||
private boolean isMainTable;
|
||||
/**
|
||||
* 命名规范映射
|
||||
*/
|
||||
private Map<String,AliasModel> tableAliseMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 表信息,只解析一遍传参通用
|
||||
*/
|
||||
private List<TableModel> tableModelList;
|
||||
/**
|
||||
* 所有控件,只解析一遍传参通用
|
||||
*/
|
||||
private List<FormAllModel> formAllModel;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.yunzhupaas.base.util.common;
|
||||
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.util.XSSEscape;
|
||||
import lombok.Cleanup;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
public class SuperQueryUtil {
|
||||
|
||||
public static void CreateJsFile(String data,String path,String jsFileType) throws IOException {
|
||||
path = XSSEscape.escapePath(path);
|
||||
String content = "const "+jsFileType+" = " + data;
|
||||
File jsFile = new File(path);
|
||||
Writer writer = null;
|
||||
try {
|
||||
writer = new FileWriter(jsFile);
|
||||
writer.write(content);
|
||||
writer.write(System.getProperty("line.separator"));
|
||||
writer.write("export default "+jsFileType);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (writer!=null){
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateFlowFormJsonFile(String data, String path){
|
||||
try {
|
||||
File file = new File(XSSEscape.escapePath(path+File.separator+"flowForm."+ ModuleTypeEnum.VISUAL_DEV.getTableName()));
|
||||
boolean b = file.createNewFile();
|
||||
if(b) {
|
||||
@Cleanup Writer out = new FileWriter(file);
|
||||
out.write(data);
|
||||
out.close();
|
||||
}
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.yunzhupaas.base.util.custom;
|
||||
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
|
||||
import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class CustomGenerator {
|
||||
|
||||
public ConfigBuilder config;
|
||||
public InjectionConfig injectionConfig;
|
||||
public DataSourceConfig dataSource;
|
||||
public StrategyConfig strategy;
|
||||
public PackageConfig packageInfo;
|
||||
public TemplateConfig template;
|
||||
public GlobalConfig globalConfig;
|
||||
public AbstractTemplateEngine templateEngine;
|
||||
|
||||
private Map<String, Object> customParams;
|
||||
|
||||
public CustomGenerator(Map<String, Object> customParams) {
|
||||
this.customParams = customParams;
|
||||
}
|
||||
|
||||
public void execute(String path) {
|
||||
if (null == this.config) {
|
||||
this.config = new ConfigBuilder(packageInfo, dataSource, strategy, template, globalConfig, injectionConfig);
|
||||
}
|
||||
if (null == this.templateEngine) {
|
||||
if (customParams != null) {
|
||||
this.templateEngine = new CustomTemplateEngine(customParams, path);
|
||||
} else {
|
||||
this.templateEngine = new CustomTemplateEngine(path);
|
||||
}
|
||||
}
|
||||
this.templateEngine.init(this.config).batchOutput().open();
|
||||
}
|
||||
|
||||
public DataSourceConfig getDataSource() {
|
||||
return this.dataSource;
|
||||
}
|
||||
|
||||
public CustomGenerator setDataSource(DataSourceConfig dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StrategyConfig getStrategy() {
|
||||
return this.strategy;
|
||||
}
|
||||
|
||||
public CustomGenerator setStrategy(StrategyConfig strategy) {
|
||||
this.strategy = strategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PackageConfig getPackageInfo() {
|
||||
return this.packageInfo;
|
||||
}
|
||||
|
||||
public CustomGenerator setPackageInfo(PackageConfig packageInfo) {
|
||||
this.packageInfo = packageInfo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TemplateConfig getTemplate() {
|
||||
return this.template;
|
||||
}
|
||||
|
||||
public CustomGenerator setTemplate(TemplateConfig template) {
|
||||
this.template = template;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfigBuilder getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
public CustomGenerator setConfig(ConfigBuilder config) {
|
||||
this.config = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GlobalConfig getGlobalConfig() {
|
||||
return this.globalConfig;
|
||||
}
|
||||
|
||||
public CustomGenerator setGlobalConfig(GlobalConfig globalConfig) {
|
||||
this.globalConfig = globalConfig;
|
||||
return this;
|
||||
}
|
||||
|
||||
public InjectionConfig getCfg() {
|
||||
return this.injectionConfig;
|
||||
}
|
||||
|
||||
public CustomGenerator setCfg(InjectionConfig injectionConfig) {
|
||||
this.injectionConfig = injectionConfig;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AbstractTemplateEngine getTemplateEngine() {
|
||||
return this.templateEngine;
|
||||
}
|
||||
|
||||
public CustomGenerator setTemplateEngine(AbstractTemplateEngine templateEngine) {
|
||||
this.templateEngine = templateEngine;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.yunzhupaas.base.util.custom;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.generator.config.ConstVal;
|
||||
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
|
||||
import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class CustomTemplateEngine extends AbstractTemplateEngine {
|
||||
|
||||
private static final String DOT_VM = ".vm";
|
||||
private VelocityEngine velocityEngine;
|
||||
|
||||
private Map<String, Object> customParams;
|
||||
|
||||
private String path;
|
||||
|
||||
public CustomTemplateEngine(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public CustomTemplateEngine(Map<String, Object> customParams, String path) {
|
||||
this.customParams = customParams;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomTemplateEngine init(ConfigBuilder configBuilder) {
|
||||
super.setConfigBuilder(configBuilder);
|
||||
if (null == this.velocityEngine) {
|
||||
Properties p = new Properties();
|
||||
p.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, path);
|
||||
p.setProperty("ISO-8859-1", Constants.UTF_8);
|
||||
p.setProperty("output.encoding", Constants.UTF_8);
|
||||
this.velocityEngine = new VelocityEngine(p);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writer(Map<String, Object> objectMap, String templatePath, File outputFile) throws Exception {
|
||||
if (templatePath != null && !"".equals(templatePath.trim())) {
|
||||
Template template = this.velocityEngine.getTemplate(templatePath, ConstVal.UTF8);
|
||||
FileOutputStream fos = new FileOutputStream(outputFile);
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, ConstVal.UTF8));
|
||||
if (customParams != null) {
|
||||
objectMap.putAll(customParams);
|
||||
}
|
||||
template.merge(new VelocityContext(objectMap), writer);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String templateFilePath(String filePath) {
|
||||
if (null != filePath && !filePath.contains(".vm")) {
|
||||
StringBuilder fp = new StringBuilder();
|
||||
fp.append(filePath).append(".vm");
|
||||
return fp.toString();
|
||||
} else {
|
||||
return filePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.yunzhupaas.base.util.custom;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public enum VelocityEnum {
|
||||
init;
|
||||
|
||||
public void initVelocity(String path){
|
||||
Properties p = new Properties();
|
||||
p.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, path);
|
||||
p.setProperty("ISO-8859-1", Constants.UTF_8);
|
||||
p.setProperty("output.encoding", Constants.UTF_8);
|
||||
Velocity.init(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
package com.yunzhupaas.base.util.fuctionFormVue3;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.yunzhupaas.base.entity.VisualdevEntity;
|
||||
import com.yunzhupaas.base.model.ColumnDataModel;
|
||||
import com.yunzhupaas.base.model.DownloadCodeForm;
|
||||
import com.yunzhupaas.base.model.Template6.BtnData;
|
||||
import com.yunzhupaas.base.model.Template6.ColumnListField;
|
||||
import com.yunzhupaas.base.model.Template7.Template7Model;
|
||||
import com.yunzhupaas.base.util.common.*;
|
||||
import com.yunzhupaas.generater.model.FormDesign.SearchTypeModel;
|
||||
import com.yunzhupaas.model.visualJson.config.HeaderModel;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.XSSEscape;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.5.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/5/31
|
||||
*/
|
||||
public class GenerateDataView implements GenerateInterface {
|
||||
|
||||
@Override
|
||||
public List<String> getTemplates(String templatePath, int type, boolean hasImport) {
|
||||
List<String> templates = new ArrayList<>();
|
||||
//前端
|
||||
templates.add(templatePath + File.separator + "index.vue.vm");
|
||||
//api接口
|
||||
templates.add(File.separator + "helper" + File.separator + "api.ts.vm");
|
||||
//后端
|
||||
if (hasImport) {
|
||||
templates.add(File.separator + "java" + File.separator + "ExcelVO.java.vm");
|
||||
templates.add(File.separator + "java" + File.separator + "ExcelErrorVO.java.vm");
|
||||
}
|
||||
templates.add(File.separator + "java" + File.separator + "Pagination.java.vm");
|
||||
templates.add(File.separator + "java" + File.separator + "Constant.java.vm");
|
||||
return templates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildTemps(boolean isChild) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据视图代码生成
|
||||
*
|
||||
* @param generateParamModel
|
||||
* @throws Exception
|
||||
*/
|
||||
public void generateDataView(GenerateParamModel generateParamModel) throws Exception {
|
||||
VisualdevEntity entity = generateParamModel.getEntity();
|
||||
DownloadCodeForm downloadCodeForm = generateParamModel.getDownloadCodeForm();
|
||||
String fileName = generateParamModel.getFileName();
|
||||
Template7Model template7Model = generateParamModel.getTemplate7Model();
|
||||
template7Model.setDescription(downloadCodeForm.getDescription());
|
||||
template7Model.setClassName(generateParamModel.getClassName());
|
||||
String templatesPath = generateParamModel.getTemplatesPath();
|
||||
String modelPathName = generateParamModel.getClassName().toLowerCase();
|
||||
|
||||
//columnTempJson
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(entity.getColumnData(), ColumnDataModel.class);
|
||||
//app 列表对象
|
||||
ColumnDataModel appColumnDataModel = JsonUtil.getJsonToBean(entity.getAppColumnData(), ColumnDataModel.class);
|
||||
//按钮
|
||||
List<BtnData> btnPcList = JsonUtil.getJsonToList(columnDataModel.getBtnsList(), BtnData.class);
|
||||
List<BtnData> columnBtnPcList = JsonUtil.getJsonToList(columnDataModel.getColumnBtnsList(), BtnData.class);
|
||||
List<BtnData> btnAppList = JsonUtil.getJsonToList(appColumnDataModel.getBtnsList(), BtnData.class);
|
||||
List<BtnData> columnBtnAppList = JsonUtil.getJsonToList(appColumnDataModel.getColumnBtnsList(), BtnData.class);
|
||||
List<BtnData> btnDataList = new ArrayList<>(btnPcList);
|
||||
List<String> collect3 = btnPcList.stream().map(BtnData::getValue).collect(Collectors.toList());
|
||||
btnDataList.addAll(btnAppList.stream().filter(t -> !collect3.contains(t.getValue())).collect(Collectors.toList()));
|
||||
//是否有下载按钮
|
||||
boolean hasDownloadBtn = btnDataList.stream().anyMatch(btn -> btn.getValue().equals("download"));
|
||||
|
||||
//列表和查询
|
||||
List<ColumnListField> columnList = JsonUtil.getJsonToList(columnDataModel.getColumnList(), ColumnListField.class);
|
||||
List<SearchTypeModel> searchList = JsonUtil.getJsonToList(columnDataModel.getSearchList(), SearchTypeModel.class);
|
||||
List<ColumnListField> columnAppList = JsonUtil.getJsonToList(appColumnDataModel.getColumnList(), ColumnListField.class);
|
||||
List<SearchTypeModel> searchAppList = JsonUtil.getJsonToList(appColumnDataModel.getSearchList(), SearchTypeModel.class);
|
||||
//查询全字段
|
||||
List<SearchTypeModel> searchListAll = new ArrayList<>(searchList);
|
||||
List<String> cSaArr = searchListAll.stream().map(SearchTypeModel::getId).collect(Collectors.toList());
|
||||
searchAppList.stream().forEach(t -> {
|
||||
if (!cSaArr.contains(t.getId())) {
|
||||
searchListAll.add(t);
|
||||
cSaArr.add(t.getId());
|
||||
}
|
||||
});
|
||||
searchListAll.stream().forEach(t -> t.setAfterVModel(t.getId()));
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
//微服务标识
|
||||
map.put("isCloud", GenerateCommon.IS_CLOUD);
|
||||
map.put("isMain", true);
|
||||
map.put("package", downloadCodeForm.getModulePackageName());
|
||||
map.put("module", downloadCodeForm.getModule());
|
||||
map.put("moduleId", entity.getId());
|
||||
map.put("className", DataControlUtils.captureName(generateParamModel.getClassName()));
|
||||
map.put("genInfo", generateParamModel.getTemplate7Model());
|
||||
|
||||
map.put("hasDownloadBtn", hasDownloadBtn);
|
||||
map.put("isList", true);
|
||||
map.put("webType", 4);
|
||||
map.put("hasPage", columnDataModel.getHasPage());
|
||||
map.put("groupTable", columnDataModel.getType() == 3);
|
||||
map.put("groupField", columnDataModel.getGroupField());
|
||||
//数据接口参数
|
||||
map.put("interfaceId", entity.getInterfaceId());
|
||||
map.put("interfaceParam", JSONObject.toJSONString(entity.getInterfaceParam()));
|
||||
//列表全属性
|
||||
map.put("columnDataStr", JSONObject.toJSONString(GenerateCommon.objRemoveJson(entity.getColumnData())));
|
||||
map.put("appColumnDataStr", JSONObject.toJSONString(GenerateCommon.objRemoveJson(entity.getAppColumnData())));
|
||||
map.put("columnData", JsonUtil.stringToMap(entity.getColumnData()));
|
||||
map.put("btnPcList", btnPcList);
|
||||
map.put("searchListAll", searchListAll);
|
||||
|
||||
//合计
|
||||
map.put("configurationTotal", columnDataModel.isShowSummary());
|
||||
List<String> summaryList = CollectionUtils.isEmpty(columnDataModel.getSummaryField()) ? Collections.EMPTY_LIST : columnDataModel.getSummaryField();
|
||||
map.put("fieldsTotal", JsonUtil.getObjectToString(summaryList));
|
||||
|
||||
//复杂表头
|
||||
List<String> complexFieldList = new ArrayList<>();
|
||||
List<Map<String, Object>> complexHeaderList = new ArrayList<>();
|
||||
if (!Objects.equals(columnDataModel.getType(), 3) && !Objects.equals(columnDataModel.getType(), 5)) {
|
||||
for (HeaderModel headerModel : columnDataModel.getComplexHeaderList()) {
|
||||
complexFieldList.addAll(headerModel.getChildColumns());
|
||||
complexHeaderList.add(JsonUtil.entityToMap(headerModel));
|
||||
}
|
||||
}
|
||||
map.put("complexHeaderList", JsonUtil.getListToJsonArray(complexHeaderList));
|
||||
map.put("complexFieldList", JsonUtil.getListToJsonArray(complexFieldList));
|
||||
//添加行参数
|
||||
Map<String, Object> columnDataJson = JsonUtil.stringToMap(entity.getColumnData());
|
||||
|
||||
//最外层zip包路径名称
|
||||
String zipName = template7Model.getServiceDirectory() + fileName;
|
||||
//生成文件夹
|
||||
String htmlTSPath = XSSEscape.escapePath(zipName + File.separator + "html" + File.separator + "web" + File.separator + modelPathName + File.separator + "helper");
|
||||
File htmlJSfile = new File(htmlTSPath);
|
||||
if (!htmlJSfile.exists()) {
|
||||
htmlJSfile.mkdirs();
|
||||
}
|
||||
String colData = JSONObject.toJSONString(columnDataJson.get("columnList"), SerializerFeature.WriteMapNullValue);
|
||||
String colListJsPath = htmlTSPath + File.separator + "columnList.ts";
|
||||
SuperQueryUtil.CreateJsFile(colData, colListJsPath, "columnList");
|
||||
|
||||
String searchData = JSONObject.toJSONString(columnDataJson.get("searchList"), SerializerFeature.WriteMapNullValue);
|
||||
String searchListJsPath = htmlTSPath + File.separator + "searchList.ts";
|
||||
SuperQueryUtil.CreateJsFile(searchData, searchListJsPath, "searchList");
|
||||
//生成controller代码
|
||||
this.genControllerFile(template7Model.getServiceDirectory() + fileName, map, templatesPath, downloadCodeForm);
|
||||
|
||||
//生成复杂表头对象
|
||||
GenerateCommon.createComplexHeaderExcelVo(zipName, generateParamModel, entity, downloadCodeForm, map);
|
||||
|
||||
//数据视图代码生成
|
||||
GenerateCommon.htmlTemplates(template7Model.getServiceDirectory() + fileName,
|
||||
map, templatesPath, 1, false, downloadCodeForm, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成controller代码
|
||||
*
|
||||
* @param path 路径
|
||||
* @param object 模板数据
|
||||
* @param templatePath 模板路径
|
||||
*/
|
||||
public static void genControllerFile(String path, Map<String, Object> object, String templatePath, DownloadCodeForm downloadCodeForm) throws Exception {
|
||||
//获取模板列表
|
||||
String controllerTem = templatePath + File.separator + "ViewController.java.vm";
|
||||
//界面模板
|
||||
VelocityContext context = new VelocityContext();
|
||||
context.put("context", object);
|
||||
String className = object.get("className").toString();
|
||||
|
||||
String controllerDir = path + File.separator + "java" + File.separator + GenerateCommon.getCloudPath("-controller", downloadCodeForm)
|
||||
+ File.separator + "controller";
|
||||
File controllerSrc = new File(controllerDir);
|
||||
if (!controllerSrc.exists()) {
|
||||
controllerSrc.mkdirs();
|
||||
}
|
||||
String fileNames = controllerDir + File.separator + className + "Controller.java";
|
||||
GenerateCommon.velocityWriterFile(context, controllerTem, fileNames);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.yunzhupaas.base.util.fuctionFormVue3;
|
||||
|
||||
import com.yunzhupaas.base.util.common.GenerateInterface;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.5.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/5/31
|
||||
*/
|
||||
public class GenerateForm implements GenerateInterface {
|
||||
|
||||
@Override
|
||||
public List<String> getTemplates(String templatePath, int type, boolean hasImport) {
|
||||
List<String> templates = new ArrayList<>();
|
||||
//前端
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "index.vue.vm");
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "FormPopup.vue.vm");
|
||||
//api接口
|
||||
templates.add(File.separator + "helper" + File.separator + "api.ts.vm");
|
||||
//后端
|
||||
templates.add(File.separator + "java" + File.separator + "Form.java.vm");
|
||||
templates.add(File.separator + "java" + File.separator + "Constant.java.vm");
|
||||
return templates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildTemps(boolean isChild) {
|
||||
List<String> templates = new ArrayList<>();
|
||||
if (isChild) {
|
||||
templates.add(File.separator + "java" + File.separator + "Model.java.vm");
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.yunzhupaas.base.util.fuctionFormVue3;
|
||||
|
||||
|
||||
import com.yunzhupaas.base.util.common.GenerateInterface;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.5.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/5/31
|
||||
*/
|
||||
public class GenerateFormFlow implements GenerateInterface {
|
||||
@Override
|
||||
public List<String> getTemplates(String templatePath, int type, boolean hasImport) {
|
||||
List<String> templates = new ArrayList<>();
|
||||
//前端
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "index.vue.vm");
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "Form.vue.vm");
|
||||
//api接口
|
||||
templates.add(File.separator + "helper" + File.separator + "api.ts.vm");
|
||||
//后端
|
||||
templates.add(File.separator + "java" + File.separator + "Form.java.vm");
|
||||
templates.add(File.separator + "java" + File.separator + "Constant.java.vm");
|
||||
return templates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildTemps(boolean isChild) {
|
||||
List<String> templates = new ArrayList<>();
|
||||
if (isChild) {
|
||||
templates.add(File.separator + "java" + File.separator + "Model.java.vm");
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.yunzhupaas.base.util.fuctionFormVue3;
|
||||
|
||||
|
||||
import com.yunzhupaas.base.util.common.GenerateInterface;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.5.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/5/31
|
||||
*/
|
||||
public class GenerateFormList implements GenerateInterface {
|
||||
/**
|
||||
* 界面的模板
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> getTemplates(String templatePath, int type, boolean hasImport) {
|
||||
List<String> templates = new ArrayList<>();
|
||||
//前端页面
|
||||
if (type == 4) {
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "indexEdit.vue.vm" );
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "ExtraForm.vue.vm" );
|
||||
} else {
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "index.vue.vm" );
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "Form.vue.vm" );
|
||||
}
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "Detail.vue.vm" );
|
||||
//api接口
|
||||
templates.add(File.separator + "helper" + File.separator + "api.ts.vm" );
|
||||
//后端
|
||||
templates.add(File.separator + "java" + File.separator + "Form.java.vm" );
|
||||
if (hasImport) {
|
||||
templates.add(File.separator + "java" + File.separator + "ExcelVO.java.vm" );
|
||||
templates.add(File.separator + "java" + File.separator + "ExcelErrorVO.java.vm" );
|
||||
}
|
||||
templates.add(File.separator + "java" + File.separator + "Pagination.java.vm" );
|
||||
templates.add(File.separator + "java" + File.separator + "Constant.java.vm" );
|
||||
return templates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildTemps(boolean isChild) {
|
||||
List<String> templates = new ArrayList<>();
|
||||
if(isChild){
|
||||
templates.add(File.separator + "java" + File.separator + "Model.java.vm" );
|
||||
templates.add(File.separator + "java" + File.separator + "ExcelVO.java.vm" );
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.yunzhupaas.base.util.fuctionFormVue3;
|
||||
|
||||
import com.yunzhupaas.base.util.common.GenerateInterface;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.5.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/5/31
|
||||
*/
|
||||
public class GenerateFormListFlow implements GenerateInterface {
|
||||
/**
|
||||
* 界面的模板
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> getTemplates(String templatePath, int type, boolean hasImport) {
|
||||
List<String> templates = new ArrayList<>();
|
||||
//前端页面
|
||||
if (type == 4) {
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "indexEdit.vue.vm");
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "Form.vue.vm");
|
||||
} else {
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "index.vue.vm");
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "Form.vue.vm");
|
||||
}
|
||||
//api接口
|
||||
templates.add(File.separator + "helper" + File.separator + "api.ts.vm");
|
||||
//后端
|
||||
templates.add(File.separator + "java" + File.separator + "Form.java.vm");
|
||||
if (hasImport) {
|
||||
templates.add(File.separator + "java" + File.separator + "ExcelVO.java.vm");
|
||||
templates.add(File.separator + "java" + File.separator + "ExcelErrorVO.java.vm");
|
||||
}
|
||||
templates.add(File.separator + "java" + File.separator + "Pagination.java.vm");
|
||||
templates.add(File.separator + "java" + File.separator + "Constant.java.vm");
|
||||
return templates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildTemps(boolean isChild) {
|
||||
List<String> templates = new ArrayList<>();
|
||||
if (isChild) {
|
||||
templates.add(File.separator + "java" + File.separator + "Model.java.vm");
|
||||
templates.add(File.separator + "java" + File.separator + "ExcelVO.java.vm");
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.yunzhupaas.base.util.fuctionFormVue3;
|
||||
|
||||
import com.yunzhupaas.base.util.common.GenerateInterface;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.5.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/5/31
|
||||
*/
|
||||
public class GenerateWorkFlow implements GenerateInterface {
|
||||
|
||||
@Override
|
||||
public List<String> getTemplates(String templatePath, int type, boolean hasImport) {
|
||||
List<String> templates = new ArrayList<>();
|
||||
//前端
|
||||
templates.add(templatePath + File.separator + "html" + File.separator + "index.vue.vm");
|
||||
//后端
|
||||
templates.add(File.separator + "java" + File.separator + "Form.java.vm");
|
||||
templates.add(File.separator + "java" + File.separator + "Constant.java.vm");
|
||||
return templates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildTemps(boolean isChild) {
|
||||
List<String> templates = new ArrayList<>();
|
||||
if (isChild) {
|
||||
templates.add(File.separator + "java" + File.separator + "Model.java.vm");
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user