Compare commits

...

5 Commits

  1. 1
      modules/export/build.gradle
  2. 4
      modules/export/src/main/resources/domains/ExportDemo.xml
  3. 2
      modules/export/src/main/resources/domains/ExportStrategy.xml
  4. 8
      modules/export/src/main/resources/domains/ExportTemplate.xml
  5. 4
      modules/export/src/main/resources/views/ExportDemo-form.xml
  6. 31
      src/main/java/com/hypass/export/controller/Child.java
  7. 223
      src/main/java/com/hypass/export/controller/ExportActionController.java
  8. 38
      src/main/java/com/hypass/export/controller/ExportController.java
  9. 5
      src/main/java/com/hypass/export/controller/Parent.java
  10. 24
      src/main/java/com/hypass/export/model/ExportStrategyDTO.java
  11. 16
      src/main/java/com/hypass/export/model/ExportTemplateDTO.java
  12. 79
      src/main/java/com/hypass/export/model/ExportTemplateDetailDTO.java
  13. 30
      src/main/java/com/hypass/export/model/SaveExportStrategyDTO.java
  14. 10
      src/main/java/com/hypass/export/service/IExportService.java
  15. 96
      src/main/java/com/hypass/export/service/impl/ExportServiceImpl.java
  16. 1
      src/main/resources/AccessInterface.yml
  17. 17
      src/main/resources/application.properties

1
modules/export/build.gradle

@ -4,4 +4,3 @@ hypaas {
}
dependencies {
}

4
modules/export/src/main/resources/domains/ExportDemo.xml

@ -4,7 +4,9 @@
<entity hashAll="false" logUpdates="true" persistable="true" name="ExportDemo" cacheable="false" lang="java" strategy="SINGLE">
<string actOverwrite="false" title="编码" copy="true" massUpdate="false" name="code" isJudg="false"/>
<string actOverwrite="false" title="名称" copy="true" massUpdate="false" name="name" isJudg="false"/>
<many-to-one title="用户名称" massUpdate="false" ref="com.hypaas.auth.db.User" name="relationUserName" copy="true"/>
<many-to-one title="用户多对一" massUpdate="false" ref="com.hypaas.auth.db.User" name="relationUserName" copy="true"/>
<one-to-one title="用户一对一" massUpdate="false" ref="com.hypaas.auth.db.User" name="userName" copy="true"/>
<one-to-many title="用户一对多" ref="com.hypaas.auth.db.User" name="oneToMany" copy="true"/>
<many-to-many title="用户多对多" ref="com.hypaas.auth.db.User" name="manyToMany" copy="true"/>
</entity>
</domain-models>

2
modules/export/src/main/resources/domains/ExportStrategy.xml

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<domain-models xmlns="http://hypaas.com/xml/ns/domain-models" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://hypaas.com/xml/ns/domain-models http://hypaas.com/xml/ns/domain-models/domain-models_5.2.xsd">
<module name="export-entity" package="com.hypass.export"/>
<module name="export" package="com.hypass.export"/>
<entity hashAll="false" logUpdates="true" persistable="true" name="ExportStrategy" cacheable="false" lang="java" strategy="SINGLE">
<string actOverwrite="false" title="导出字段名" copy="true" massUpdate="false" name="fieldName" isJudg="false"/>
<string actOverwrite="false" title="导出字段类型" copy="true" massUpdate="false" name="fieldType" isJudg="false"/>

8
modules/export/src/main/resources/domains/ExportTemplate.xml

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<domain-models xmlns="http://hypaas.com/xml/ns/domain-models" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://hypaas.com/xml/ns/domain-models http://hypaas.com/xml/ns/domain-models/domain-models_5.2.xsd">
<module name="export-entity" package="com.hypass.export"/>
<module name="export" package="com.hypass.export"/>
<entity hashAll="false" logUpdates="true" persistable="true" name="ExportTemplate" cacheable="false" lang="java" strategy="SINGLE">
<string actOverwrite="false" title="模板编码" required="true" copy="true" massUpdate="false" name="code" isJudg="false"/>
<string actOverwrite="false" title="模板名称" copy="true" massUpdate="false" name="name" isJudg="false"/>
<many-to-one title="实体名称" ref="com.hypaas.meta.db.MetaModel" unique="true" name="entityName" copy="true"/>
<string actOverwrite="false" title="模板编码" required="true" copy="true" unique="true" name="code" isJudg="false"/>
<string actOverwrite="false" title="模板名称" copy="true" unique="true" name="name" isJudg="false"/>
<many-to-one title="实体名称" massUpdate="false" ref="com.hypaas.meta.db.MetaModel" unique="false" name="entityName" copy="true"/>
<enum title="是否默认模板" massUpdate="false" ref="com.export.enums.CommonBoolean" name="isDefaultTemplate" copy="true"/>
</entity>
</domain-models>

4
modules/export/src/main/resources/views/ExportDemo-form.xml

@ -4,8 +4,10 @@
<panel itemSpan="6" showFrame="true" name="panel_11">
<field name="code" title="编码"/>
<field name="name" title="名称"/>
<field canSuggest="true" name="relationUserName" title="用户名称"/>
<field canSuggest="true" name="userName" title="用户一对一"/>
<field name="oneToMany" title="用户一对多"/>
<field canSuggest="true" name="manyToMany" title="用户多对多"/>
<field canSuggest="true" name="relationUserName" title="用户多对一"/>
</panel>
</form>
</object-views>

31
src/main/java/com/hypass/export/controller/Child.java

@ -0,0 +1,31 @@
package com.hypass.export.controller;
import com.hypass.export.ExportTemplate;
import java.lang.reflect.Field;
/** @ClassName Child @Description TODO @Author wyj @Date 2023/12/6 13:48 @Version 1.0 */
public class Child extends Parent {
public String childField = "childField";
public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
// 获取 Child 类的对象
ExportTemplate exportTemplate = new ExportTemplate();
Field field = getDeclaredField(exportTemplate, "updatedBy");
System.out.println(field.getName());
}
public static Field getDeclaredField(Object object, String fieldName) {
Field field = null;
Class<?> clazz = object.getClass();
for (; clazz != Object.class; clazz = clazz.getSuperclass()) {
try {
field = clazz.getDeclaredField(fieldName);
return field;
} catch (NoSuchFieldException e) {
// 不需要处理
// 不断向父类查询是否有某个字段
}
}
return null;
}
}

223
src/main/java/com/hypass/export/controller/ExportActionController.java

@ -0,0 +1,223 @@
package com.hypass.export.controller;
import com.alibaba.excel.EasyExcel;
import com.export.enums.CommonBoolean;
import com.google.inject.Inject;
import com.hypaas.db.Model;
import com.hypaas.db.Query;
import com.hypaas.meta.MetaFiles;
import com.hypaas.meta.db.MetaFile;
import com.hypaas.meta.db.MetaModel;
import com.hypaas.meta.db.repo.MetaModelRepository;
import com.hypaas.meta.schema.actions.ActionView;
import com.hypaas.rpc.ActionRequest;
import com.hypaas.rpc.ActionResponse;
import com.hypass.export.ExportStrategy;
import com.hypass.export.ExportTemplate;
import com.hypass.export.repo.ExportStrategyRepository;
import com.hypass.export.repo.ExportTemplateRepository;
import java.io.*;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
public class ExportActionController {
@Inject private ExportTemplateRepository exportTemplateRepository;
@Inject private MetaModelRepository metaModelRepository;
@Inject private ExportStrategyRepository exportStrategyRepository;
@Inject private MetaFiles metaFiles;
public void export(ActionRequest request, ActionResponse response) {
// 获取model
String model = request.getModel();
MetaModel entity =
Query.of(MetaModel.class)
.filter("self.fullName = :fullName")
.bind("fullName", model)
.fetchOne();
// 根据model查询对应的模版
ExportTemplate exportTemplate =
Query.of(ExportTemplate.class)
.filter("self.entityName = :entityName")
.bind("entityName", entity)
.fetchOne();
if (exportTemplate == null) {
response.setAlert("该实体模型没有配置导出模版");
return;
}
// 解析策略
List<ExportStrategy> exportStrategys =
Query.of(ExportStrategy.class)
.filter("self.templateInfo = :templateInfo")
.bind("templateInfo", exportTemplate)
.fetch();
if (CollectionUtils.isEmpty(exportStrategys)) {
response.setAlert("该实体模型没有配置导出模版策略");
return;
}
// 设置动态头
List<List<String>> headList = new ArrayList<>();
exportStrategys.forEach(
exportStrategy -> {
if (CommonBoolean.IS.equals(exportStrategy.getIsExport())) {
List<String> head = new ArrayList<>();
if ("ManyToOne".equals(exportStrategy.getFieldAttr())) {
String exportContent = exportStrategy.getExportContent();
if (StringUtils.isEmpty(exportContent)) {
return;
}
String[] split = exportContent.split(",");
for (String s : split) {
head.add(s);
headList.add(head);
}
} else {
head.add(exportStrategy.getExportFiledName());
headList.add(head);
}
}
});
String fullName = entity.getFullName();
final Class<Model> modelClass;
try {
modelClass = (Class<Model>) Class.forName(fullName);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("No such model found.");
}
Query<Model> of = Query.of(modelClass);
List<Model> modelDatas = of.fetch();
// Dynamic data retrieval and processing
List<List<Object>> dataList =
modelDatas.stream()
.map(
data -> {
List<Object> rowData = new ArrayList<>();
for (ExportStrategy strategy : exportStrategys) {
if (CommonBoolean.NOT.equals(strategy.getIsExport())) continue;
if (StringUtils.isEmpty(strategy.getExportFiledName())) {
strategy.setExportFiledName(strategy.getFieldName());
}
Field field = null;
try {
field = getDeclaredField(modelClass, strategy.getFieldName());
field.setAccessible(true);
if (processManyToOne(data, rowData, strategy, field)) continue;
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
Object value = null; // Handle null values if needed
try {
value = field.get(data);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
if (value != null && value.getClass().isEnum()) {
String name = ((Enum<?>) value).name();
rowData.add(name);
} else {
rowData.add(value);
}
}
return rowData;
})
.collect(Collectors.toList());
// 创建 OutputStream 对象
// 创建临时目录
File tempDir = new File(System.getProperty("user.dir"), "temp");
if (!tempDir.exists()) {
tempDir.mkdirs();
}
String fileName = "excel.xlsx";
File file = new File(tempDir, fileName);
// dataList.forEach(data->{
// data.forEach(d -> {
// System.out.println(d.getClass().getTypeName());
// });
// });
EasyExcel.write(file).head(headList).sheet("实体信息").doWrite(dataList);
MetaFile upload = null;
try {
upload = metaFiles.upload(file);
} catch (IOException e) {
tempDir.delete();
throw new RuntimeException(e);
}
if (upload != null) {
response.setView(
ActionView.define("文件导出")
.add(
"html",
"ws/rest/com.hypaas.meta.db.MetaFile/"
+ upload.getId()
+ "/content/download?v="
+ upload.getVersion())
.param("download", "true")
.map());
}
tempDir.delete();
}
private static boolean processManyToOne(
Model data, List<Object> rowData, ExportStrategy strategy, Field field)
throws NoSuchFieldException {
if ("ManyToOne".equals(strategy.getFieldAttr())) {
String exportContent = strategy.getExportContent();
if (StringUtils.isEmpty(exportContent)) return true;
String[] split = exportContent.split(",");
for (String s : split) {
Field subField = getDeclaredField((Class<Model>) field.getType(), s);
subField.setAccessible(true);
Object value = null; // Handle null values if needed
try {
Field declaredField = getDeclaredField((Class<Model>) data.getClass(), field.getName());
declaredField.setAccessible(true);
Object o = declaredField.get(data);
value = subField.get(o);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
rowData.add(value);
}
return true;
}
return false;
}
public static Field getDeclaredField(Class<Model> clazz, String fieldName) {
Field field = null;
try {
field = clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
for (; clazz != Model.class; clazz = (Class<Model>) clazz.getSuperclass()) {
if (clazz != null) {
try {
field = clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException ex) {
continue;
}
if (field != null) return field;
}
}
throw new RuntimeException(e);
}
return field;
}
public static void main(String[] args) {
MetaModel metaModel = new MetaModel();
try {
Field fullName = metaModel.getClass().getDeclaredField("fullName");
System.out.println(111);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
}

38
src/main/java/com/hypass/export/controller/ExportController.java

@ -4,15 +4,14 @@ import com.google.inject.Inject;
import com.google.inject.servlet.RequestScoped;
import com.hypaas.db.JpaSupport;
import com.hypaas.rpc.Response;
import com.hypass.export.model.CascadeModelFieldDTO;
import com.hypass.export.model.ExportStrategyDTO;
import com.hypass.export.model.ExportTemplateDTO;
import com.hypass.export.model.MetaModelDTO;
import com.hypass.export.model.*;
import com.hypass.export.service.IExportService;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
/**
* @ClassName InventoryMgrController @Description TODO @Author Will @Date 2023/7/23 18:58 @Version
@ -25,6 +24,26 @@ public class ExportController extends JpaSupport {
@Inject private IExportService exportService;
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/getTemplateDetail")
public Response getTemplateDetail(@QueryParam("templateId") String templateId) {
Response response = new Response();
ExportTemplateDTO exportTemplateDTO = null;
try {
exportTemplateDTO = exportService.getTemplateDetail(templateId);
} catch (InvocationTargetException e) {
response.setData(null);
response.setStatus(Response.STATUS_FAILURE);
} catch (IllegalAccessException e) {
response.setData(null);
response.setStatus(Response.STATUS_FAILURE);
}
response.setData(exportTemplateDTO);
response.setStatus(Response.STATUS_SUCCESS);
return response;
}
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Path("/getCascadeModelFieldList")
@ -108,10 +127,17 @@ public class ExportController extends JpaSupport {
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/saveTemplateStrategy")
public Response saveTemplateStrategy(ExportStrategyDTO templateStrategyDTO) {
public Response saveTemplateStrategy(SaveExportStrategyDTO saveExportStrategyDTO) {
Boolean result = null;
Response response = new Response();
result = exportService.saveTemplateStrategy(templateStrategyDTO);
if (ObjectUtils.isEmpty(saveExportStrategyDTO)
|| saveExportStrategyDTO.getTemplateId() == null
|| CollectionUtils.isEmpty(saveExportStrategyDTO.getExportStrategyDTOs())) {
response.setData(false);
response.setStatus(Response.STATUS_FAILURE);
return response;
}
result = exportService.saveTemplateStrategy(saveExportStrategyDTO);
response.setData(result);
response.setStatus(Response.STATUS_SUCCESS);
return response;

5
src/main/java/com/hypass/export/controller/Parent.java

@ -0,0 +1,5 @@
package com.hypass.export.controller;
public class Parent {
public String parentField = "parentField";
}

24
src/main/java/com/hypass/export/model/ExportStrategyDTO.java

@ -1,10 +1,6 @@
package com.hypass.export.model;
import com.export.common.CommonBoolean;
import com.hypaas.auth.db.AuditableModel;
import javax.persistence.*;
public class ExportStrategyDTO extends AuditableModel {
public class ExportStrategyDTO {
private Long id;
@ -14,7 +10,7 @@ public class ExportStrategyDTO extends AuditableModel {
private String fieldAttr;
private CommonBoolean isExport;
private String isExport;
private String outContent;
@ -24,6 +20,16 @@ public class ExportStrategyDTO extends AuditableModel {
private Integer templateId;
private String entityName;
public String getEntityName() {
return entityName;
}
public void setEntityName(String entityName) {
this.entityName = entityName;
}
public Integer getTemplateId() {
return templateId;
}
@ -32,12 +38,10 @@ public class ExportStrategyDTO extends AuditableModel {
this.templateId = templateId;
}
@Override
public Long getId() {
return id;
}
@Override
public void setId(Long id) {
this.id = id;
}
@ -66,11 +70,11 @@ public class ExportStrategyDTO extends AuditableModel {
this.fieldAttr = fieldAttr;
}
public CommonBoolean getIsExport() {
public String getIsExport() {
return isExport;
}
public void setIsExport(CommonBoolean isExport) {
public void setIsExport(String isExport) {
this.isExport = isExport;
}

16
src/main/java/com/hypass/export/model/ExportTemplateDTO.java

@ -1,9 +1,5 @@
package com.hypass.export.model;
import com.export.common.CommonBoolean;
import com.hypaas.meta.db.MetaJsonModel;
import javax.persistence.*;
/**
* @ClassName ExportTemplateDTO @Description TODO @Author wyj @Date 2023/11/24 10:19 @Version 1.0
*/
@ -15,9 +11,9 @@ public class ExportTemplateDTO {
private String name;
private MetaJsonModel entityName;
private String entityName;
private CommonBoolean isDefaultTemplate;
private String isDefaultTemplate;
public Long getId() {
return id;
@ -43,19 +39,19 @@ public class ExportTemplateDTO {
this.name = name;
}
public MetaJsonModel getEntityName() {
public String getEntityName() {
return entityName;
}
public void setEntityName(MetaJsonModel entityName) {
public void setEntityName(String entityName) {
this.entityName = entityName;
}
public CommonBoolean getIsDefaultTemplate() {
public String getIsDefaultTemplate() {
return isDefaultTemplate;
}
public void setIsDefaultTemplate(CommonBoolean isDefaultTemplate) {
public void setIsDefaultTemplate(String isDefaultTemplate) {
this.isDefaultTemplate = isDefaultTemplate;
}
}

79
src/main/java/com/hypass/export/model/ExportTemplateDetailDTO.java

@ -0,0 +1,79 @@
package com.hypass.export.model;
import com.hypaas.meta.db.MetaModel;
import java.util.List;
public class ExportTemplateDetailDTO {
private TemplateBaseInfoDTO templateInfo;
private List<ExportStrategyDTO> strategyList;
public static class TemplateBaseInfoDTO {
private Long id;
private String code;
private String name;
private MetaModel entityName;
private String isDefaultTemplate;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public MetaModel getEntityName() {
return entityName;
}
public void setEntityName(MetaModel entityName) {
this.entityName = entityName;
}
public String getIsDefaultTemplate() {
return isDefaultTemplate;
}
public void setIsDefaultTemplate(String isDefaultTemplate) {
this.isDefaultTemplate = isDefaultTemplate;
}
}
public TemplateBaseInfoDTO getTemplateInfo() {
return templateInfo;
}
public void setTemplateInfo(TemplateBaseInfoDTO templateInfo) {
this.templateInfo = templateInfo;
}
public List<ExportStrategyDTO> getStrategyList() {
return strategyList;
}
public void setStrategyList(List<ExportStrategyDTO> strategyList) {
this.strategyList = strategyList;
}
}

30
src/main/java/com/hypass/export/model/SaveExportStrategyDTO.java

@ -0,0 +1,30 @@
package com.hypass.export.model;
import java.io.Serializable;
import java.util.List;
/**
* @ClassName SaveExportStrategyDTO @Description TODO @Author wyj @Date 2023/12/2 15:41 @Version 1.0
*/
public class SaveExportStrategyDTO implements Serializable {
private String templateId;
private List<ExportStrategyDTO> exportStrategyDTOs;
public String getTemplateId() {
return templateId;
}
public void setTemplateId(String templateId) {
this.templateId = templateId;
}
public List<ExportStrategyDTO> getExportStrategyDTOs() {
return exportStrategyDTOs;
}
public void setExportStrategyDTOs(List<ExportStrategyDTO> exportStrategyDTOs) {
this.exportStrategyDTOs = exportStrategyDTOs;
}
}

10
src/main/java/com/hypass/export/service/IExportService.java

@ -1,9 +1,6 @@
package com.hypass.export.service;
import com.hypass.export.model.CascadeModelFieldDTO;
import com.hypass.export.model.ExportStrategyDTO;
import com.hypass.export.model.ExportTemplateDTO;
import com.hypass.export.model.MetaModelDTO;
import com.hypass.export.model.*;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@ -14,7 +11,7 @@ public interface IExportService {
ExportStrategyDTO getModelExportStrategy(String templateId)
throws InvocationTargetException, IllegalAccessException;
boolean saveTemplateStrategy(ExportStrategyDTO exportStrategyDTO);
boolean saveTemplateStrategy(SaveExportStrategyDTO exportStrategyDTO);
List<CascadeModelFieldDTO> getCascadeModelFieldList(String modelName, String fieldName);
@ -22,4 +19,7 @@ public interface IExportService {
boolean saveTemplate(ExportTemplateDTO exportTemplateDTO)
throws InvocationTargetException, IllegalAccessException;
ExportTemplateDTO getTemplateDetail(String templateId)
throws InvocationTargetException, IllegalAccessException;
}

96
src/main/java/com/hypass/export/service/impl/ExportServiceImpl.java

@ -1,7 +1,8 @@
package com.hypass.export.service.impl;
import com.export.common.CommonBoolean;
import com.export.enums.CommonBoolean;
import com.google.inject.Inject;
import com.google.inject.persist.Transactional;
import com.hypaas.db.Query;
import com.hypaas.meta.db.MetaField;
import com.hypaas.meta.db.MetaModel;
@ -9,20 +10,18 @@ import com.hypaas.meta.db.repo.MetaFieldRepository;
import com.hypaas.meta.db.repo.MetaModelRepository;
import com.hypass.export.ExportStrategy;
import com.hypass.export.ExportTemplate;
import com.hypass.export.model.CascadeModelFieldDTO;
import com.hypass.export.model.ExportStrategyDTO;
import com.hypass.export.model.ExportTemplateDTO;
import com.hypass.export.model.MetaModelDTO;
import com.hypass.export.model.*;
import com.hypass.export.repo.ExportStrategyRepository;
import com.hypass.export.repo.ExportTemplateRepository;
import com.hypass.export.service.IExportService;
import com.hypass.export.utils.HypassBeanUtils;
import java.lang.reflect.InvocationTargetException;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
/**
* @ClassName ExportServiceImpl @Description TODO @Author wyj @Date 2023/11/18 16:02 @Version 1.0
@ -61,10 +60,34 @@ public class ExportServiceImpl implements IExportService {
}
@Override
public boolean saveTemplateStrategy(ExportStrategyDTO exportStrategyDTO) {
ExportStrategy exportStrategy = new ExportStrategy();
BeanUtils.copyProperties(exportStrategyDTO, exportStrategy);
@Transactional
public boolean saveTemplateStrategy(SaveExportStrategyDTO saveExportStrategyDTO) {
ExportTemplate exportTemplate =
exportTemplateRepository.find(Long.valueOf(saveExportStrategyDTO.getTemplateId()));
if (ObjectUtils.isEmpty(exportTemplate)) {
throw new RuntimeException("模板不存在");
}
saveExportStrategyDTO
.getExportStrategyDTOs()
.forEach(
exportStrategyDTO -> {
ExportStrategy exportStrategy =
exportStrategyRepository.find(exportStrategyDTO.getId());
exportStrategy.setIsExport(CommonBoolean.valueOf(exportStrategyDTO.getIsExport()));
exportStrategy.setExportFiledName(exportStrategyDTO.getExportFiledName());
exportStrategy.setEntityName(exportStrategyDTO.getEntityName());
exportStrategy.setExportContent(exportStrategyDTO.getExportContent());
exportStrategy.setFieldAttr(exportStrategyDTO.getFieldAttr());
exportStrategy.setFieldType(exportStrategyDTO.getFieldType());
exportStrategy.setFieldName(exportStrategy.getFieldName());
exportStrategy.setId(exportStrategyDTO.getId());
exportStrategy.setOutContent(exportStrategy.getOutContent());
if (exportStrategy.getId() != null) {
exportStrategyRepository.merge(exportStrategy);
} else {
exportStrategyRepository.save(exportStrategy);
}
});
return true;
}
@ -90,7 +113,11 @@ public class ExportServiceImpl implements IExportService {
field -> {
CascadeModelFieldDTO cascadeModelDTO = new CascadeModelFieldDTO();
cascadeModelDTO.setCode(field.getName());
if (StringUtils.isEmpty(field.getLabel())) {
cascadeModelDTO.setName(field.getName());
} else {
cascadeModelDTO.setName(field.getLabel());
}
list.add(cascadeModelDTO);
});
return list;
@ -102,16 +129,24 @@ public class ExportServiceImpl implements IExportService {
public List<ExportStrategyDTO> preConfigExportStrategy(String modelName, String templateId) {
List<ExportStrategyDTO> exportStrategyDTOS = new ArrayList<>();
ExportTemplate exportTemplate = exportTemplateRepository.find(Long.valueOf(templateId));
if (exportTemplate == null) {
List<ExportStrategy> templateStrategyInfos =
Query.of(ExportStrategy.class)
.filter("self.templateInfo = :templateInfo")
.bind("templateInfo", exportTemplate)
.fetch();
if (CollectionUtils.isEmpty(templateStrategyInfos)) {
MetaModel metaModel = metaModelRepository.findByName(modelName);
List<MetaField> fields =
Query.of(MetaField.class)
.filter("self.metaModel = :metaModel")
.filter(
"self.metaModel = :metaModel and (self.relationship is null or self.relationship='ManyToOne')")
.bind("metaModel", metaModel)
.fetch();
if (CollectionUtils.isEmpty(fields)) {
return exportStrategyDTOS;
}
List<ExportStrategyDTO> finalExportStrategyDTOS = exportStrategyDTOS;
fields.forEach(
field -> {
ExportStrategyDTO exportStrategyDTO = new ExportStrategyDTO();
@ -122,25 +157,32 @@ public class ExportServiceImpl implements IExportService {
} else {
exportStrategyDTO.setFieldAttr(field.getRelationship());
}
exportStrategyDTO.setIsExport(CommonBoolean.NOT);
exportStrategyDTO.setIsExport(CommonBoolean.NOT.getValue());
finalExportStrategyDTOS.add(exportStrategyDTO);
});
return finalExportStrategyDTOS;
} else {
List<ExportStrategy> list =
Query.of(ExportStrategy.class)
.filter("self.templateInfo = :templateInfo")
.bind("templateInfo", exportTemplate)
.fetch();
exportStrategyDTOS = HypassBeanUtils.copyProperties4List(list, ExportStrategyDTO.class);
return HypassBeanUtils.copyProperties4List(templateStrategyInfos, ExportStrategyDTO.class);
}
return null;
}
@Override
@Transactional
public boolean saveTemplate(ExportTemplateDTO exportTemplateDTO)
throws InvocationTargetException, IllegalAccessException {
if (exportTemplateDTO == null
|| StringUtils.isEmpty(exportTemplateDTO.getEntityName())
|| StringUtils.isEmpty(exportTemplateDTO.getCode())
|| StringUtils.isEmpty(exportTemplateDTO.getName())) {
throw new InvalidParameterException("参数异常");
}
String entityName = exportTemplateDTO.getEntityName();
MetaModel metaModel = metaModelRepository.findByName(entityName);
ExportTemplate exportTemplate = new ExportTemplate();
HypassBeanUtils.copyProperties(exportTemplateDTO, exportTemplate);
exportTemplate.setEntityName(metaModel);
exportTemplate.setIsDefaultTemplate(
CommonBoolean.valueOf(exportTemplateDTO.getIsDefaultTemplate()));
if (exportTemplateDTO.getIsDefaultTemplate() != null) {
exportTemplateRepository.save(exportTemplate);
} else {
@ -148,4 +190,18 @@ public class ExportServiceImpl implements IExportService {
}
return true;
}
@Override
public ExportTemplateDTO getTemplateDetail(String templateId)
throws InvocationTargetException, IllegalAccessException {
ExportTemplate exportTemplate = exportTemplateRepository.find(Long.valueOf(templateId));
ExportTemplateDTO exportTemplateDTO = new ExportTemplateDTO();
MetaModel entityName = exportTemplate.getEntityName();
exportTemplateDTO.setEntityName(entityName.getName());
if (exportTemplate.getIsDefaultTemplate() == null) {
exportTemplateDTO.setIsDefaultTemplate("NOT");
}
HypassBeanUtils.copyProperties(exportTemplate, exportTemplateDTO);
return exportTemplateDTO;
}
}

1
src/main/resources/AccessInterface.yml

@ -1,3 +1,4 @@
interfaceList:
- "/ws/register/register/face"
- "/ws/register/login/face"
- "/ws/export/**"

17
src/main/resources/application.properties

@ -64,11 +64,17 @@ auth.logout.local=true
# MySQL
#db.default.driver = com.mysql.jdbc.Driver
#db.default.visible=false
db.default.driver=
db.default.driver=com.mysql.cj.jdbc.Driver
db.default.ddl=update
db.default.url=jdbc:://?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&nullCatalogMeansCurrent=true
db.default.user=
db.default.password=
db.default.url=jdbc:mysql://117.78.10.170:3006/app_697b1517b1e2735c8cb78ba7fd0c10d2_master_pre?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&nullCatalogMeansCurrent=true
db.default.user=app_wangyunjie
db.default.password=Asdf123!@#
#db.default.driver=oracle.jdbc.OracleDriver
#db.default.ddl=update
#db.default.url=jdbc:oracle:thin:@124.70.24.169:3521:helowin
#db.default.user=testseq
#db.default.password=sUnwise@2023
db.company1.name=Company 1
db.company1.driver=com.mysql.cj.jdbc.Driver
@ -339,6 +345,9 @@ logging.level.com.hypaas=INFO

Loading…
Cancel
Save