王运杰
1 year ago
12 changed files with 584 additions and 3 deletions
@ -0,0 +1,16 @@
|
||||
package com.hypass.export.config; |
||||
|
||||
import com.google.inject.Inject; |
||||
import com.hypaas.app.HypaasModule; |
||||
import com.hypass.export.service.IExportService; |
||||
import com.hypass.export.service.impl.ExportServiceImpl; |
||||
import org.springframework.context.ApplicationContext; |
||||
|
||||
public class ExtendModule extends HypaasModule { |
||||
@Inject private ApplicationContext context; |
||||
|
||||
@Override |
||||
protected void configure() { |
||||
bind(IExportService.class).to(ExportServiceImpl.class); |
||||
} |
||||
} |
@ -0,0 +1,119 @@
|
||||
package com.hypass.export.controller; |
||||
|
||||
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.service.IExportService; |
||||
import java.lang.reflect.InvocationTargetException; |
||||
import java.util.List; |
||||
import javax.ws.rs.*; |
||||
import javax.ws.rs.core.MediaType; |
||||
|
||||
/** |
||||
* @ClassName InventoryMgrController @Description TODO @Author Will @Date 2023/7/23 18:58 @Version |
||||
* 1.0 |
||||
*/ |
||||
@RequestScoped |
||||
@Produces(MediaType.APPLICATION_JSON) |
||||
@Path("/export") |
||||
public class ExportController extends JpaSupport { |
||||
|
||||
@Inject private IExportService exportService; |
||||
|
||||
@GET |
||||
@Consumes(MediaType.APPLICATION_JSON) |
||||
@Path("/getCascadeModelFieldList") |
||||
public Response getCascadeModelFieldList( |
||||
@QueryParam("modelName") String modelName, @QueryParam("fieldName") String fieldName) { |
||||
Response response = new Response(); |
||||
List<CascadeModelFieldDTO> list = exportService.getCascadeModelFieldList(modelName, fieldName); |
||||
response.setData(list); |
||||
response.setStatus(Response.STATUS_SUCCESS); |
||||
return response; |
||||
} |
||||
|
||||
@POST |
||||
@Consumes(MediaType.APPLICATION_JSON) |
||||
@Path("/saveTemplate") |
||||
public Response saveTemplate(ExportTemplateDTO exportTemplateDTO) { |
||||
Response response = new Response(); |
||||
response.setStatus(Response.STATUS_SUCCESS); |
||||
Boolean result = false; |
||||
try { |
||||
result = exportService.saveTemplate(exportTemplateDTO); |
||||
} catch (InvocationTargetException e) { |
||||
result = false; |
||||
response.setStatus(Response.STATUS_FAILURE); |
||||
} catch (IllegalAccessException e) { |
||||
result = false; |
||||
response.setStatus(Response.STATUS_FAILURE); |
||||
} |
||||
response.setData(result); |
||||
return response; |
||||
} |
||||
|
||||
/** |
||||
* 查询模型列表 |
||||
* |
||||
* @return |
||||
*/ |
||||
@GET |
||||
@Path("/getModelList") |
||||
public Response getModelList() { |
||||
List<MetaModelDTO> modelList = exportService.getModelList(); |
||||
Response response = new Response(); |
||||
response.setData(modelList); |
||||
response.setStatus(Response.STATUS_SUCCESS); |
||||
return response; |
||||
} |
||||
|
||||
@GET |
||||
@Consumes(MediaType.APPLICATION_JSON) |
||||
@Path("/preConfigExportStrategy") |
||||
public Response preConfigExportStrategy( |
||||
@QueryParam("modelName") String modelName, @QueryParam("templateId") String templateId) { |
||||
List<ExportStrategyDTO> exportStrategyDTOS = null; |
||||
Response response = new Response(); |
||||
exportStrategyDTOS = exportService.preConfigExportStrategy(modelName, templateId); |
||||
response.setData(exportStrategyDTOS); |
||||
response.setStatus(Response.STATUS_SUCCESS); |
||||
return response; |
||||
} |
||||
|
||||
@GET |
||||
@Consumes(MediaType.APPLICATION_JSON) |
||||
@Path("/getModelExportStrategy") |
||||
public Response getModelExportStrategy(@QueryParam("templateId") String templateId) { |
||||
ExportStrategyDTO modelExportStrategy = null; |
||||
Response response = new Response(); |
||||
try { |
||||
modelExportStrategy = exportService.getModelExportStrategy(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(modelExportStrategy); |
||||
response.setStatus(Response.STATUS_SUCCESS); |
||||
return response; |
||||
} |
||||
|
||||
@POST |
||||
@Consumes(MediaType.APPLICATION_JSON) |
||||
@Path("/saveTemplateStrategy") |
||||
public Response saveTemplateStrategy(ExportStrategyDTO templateStrategyDTO) { |
||||
Boolean result = null; |
||||
Response response = new Response(); |
||||
result = exportService.saveTemplateStrategy(templateStrategyDTO); |
||||
response.setData(result); |
||||
response.setStatus(Response.STATUS_SUCCESS); |
||||
return response; |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.hypass.export.model; |
||||
|
||||
/** @ClassName MetaModelDTO @Description TODO @Author wyj @Date 2023/11/18 15:56 @Version 1.0 */ |
||||
public class CascadeModelFieldDTO { |
||||
|
||||
private String name; |
||||
|
||||
private String code; |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public void setCode(String code) { |
||||
this.code = code; |
||||
} |
||||
} |
@ -0,0 +1,100 @@
|
||||
package com.hypass.export.model; |
||||
|
||||
import com.export.common.CommonBoolean; |
||||
import com.hypaas.auth.db.AuditableModel; |
||||
import javax.persistence.*; |
||||
|
||||
public class ExportStrategyDTO extends AuditableModel { |
||||
|
||||
private Long id; |
||||
|
||||
private String fieldName; |
||||
|
||||
private String fieldType; |
||||
|
||||
private String fieldAttr; |
||||
|
||||
private CommonBoolean isExport; |
||||
|
||||
private String outContent; |
||||
|
||||
private String exportFiledName; |
||||
|
||||
private String exportContent; |
||||
|
||||
private Integer templateId; |
||||
|
||||
public Integer getTemplateId() { |
||||
return templateId; |
||||
} |
||||
|
||||
public void setTemplateId(Integer templateId) { |
||||
this.templateId = templateId; |
||||
} |
||||
|
||||
@Override |
||||
public Long getId() { |
||||
return id; |
||||
} |
||||
|
||||
@Override |
||||
public void setId(Long id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getFieldName() { |
||||
return fieldName; |
||||
} |
||||
|
||||
public void setFieldName(String fieldName) { |
||||
this.fieldName = fieldName; |
||||
} |
||||
|
||||
public String getFieldType() { |
||||
return fieldType; |
||||
} |
||||
|
||||
public void setFieldType(String fieldType) { |
||||
this.fieldType = fieldType; |
||||
} |
||||
|
||||
public String getFieldAttr() { |
||||
return fieldAttr; |
||||
} |
||||
|
||||
public void setFieldAttr(String fieldAttr) { |
||||
this.fieldAttr = fieldAttr; |
||||
} |
||||
|
||||
public CommonBoolean getIsExport() { |
||||
return isExport; |
||||
} |
||||
|
||||
public void setIsExport(CommonBoolean isExport) { |
||||
this.isExport = isExport; |
||||
} |
||||
|
||||
public String getOutContent() { |
||||
return outContent; |
||||
} |
||||
|
||||
public void setOutContent(String outContent) { |
||||
this.outContent = outContent; |
||||
} |
||||
|
||||
public String getExportFiledName() { |
||||
return exportFiledName; |
||||
} |
||||
|
||||
public void setExportFiledName(String exportFiledName) { |
||||
this.exportFiledName = exportFiledName; |
||||
} |
||||
|
||||
public String getExportContent() { |
||||
return exportContent; |
||||
} |
||||
|
||||
public void setExportContent(String exportContent) { |
||||
this.exportContent = exportContent; |
||||
} |
||||
} |
@ -0,0 +1,61 @@
|
||||
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 |
||||
*/ |
||||
public class ExportTemplateDTO { |
||||
|
||||
private Long id; |
||||
|
||||
private String code; |
||||
|
||||
private String name; |
||||
|
||||
private MetaJsonModel entityName; |
||||
|
||||
private CommonBoolean 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 MetaJsonModel getEntityName() { |
||||
return entityName; |
||||
} |
||||
|
||||
public void setEntityName(MetaJsonModel entityName) { |
||||
this.entityName = entityName; |
||||
} |
||||
|
||||
public CommonBoolean getIsDefaultTemplate() { |
||||
return isDefaultTemplate; |
||||
} |
||||
|
||||
public void setIsDefaultTemplate(CommonBoolean isDefaultTemplate) { |
||||
this.isDefaultTemplate = isDefaultTemplate; |
||||
} |
||||
} |
@ -0,0 +1,55 @@
|
||||
package com.hypass.export.model; |
||||
|
||||
/** @ClassName MetaModelDTO @Description TODO @Author wyj @Date 2023/11/18 15:56 @Version 1.0 */ |
||||
public class MetaModelDTO { |
||||
|
||||
private Long id; |
||||
|
||||
private String name; |
||||
|
||||
private String packageName; |
||||
|
||||
private String tableName; |
||||
|
||||
private String fullName; |
||||
|
||||
public Long getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(Long id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getPackageName() { |
||||
return packageName; |
||||
} |
||||
|
||||
public void setPackageName(String packageName) { |
||||
this.packageName = packageName; |
||||
} |
||||
|
||||
public String getTableName() { |
||||
return tableName; |
||||
} |
||||
|
||||
public void setTableName(String tableName) { |
||||
this.tableName = tableName; |
||||
} |
||||
|
||||
public String getFullName() { |
||||
return fullName; |
||||
} |
||||
|
||||
public void setFullName(String fullName) { |
||||
this.fullName = fullName; |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
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 java.lang.reflect.InvocationTargetException; |
||||
import java.util.List; |
||||
|
||||
/** 文件导出接口 */ |
||||
public interface IExportService { |
||||
List<MetaModelDTO> getModelList(); |
||||
|
||||
ExportStrategyDTO getModelExportStrategy(String templateId) |
||||
throws InvocationTargetException, IllegalAccessException; |
||||
|
||||
boolean saveTemplateStrategy(ExportStrategyDTO exportStrategyDTO); |
||||
|
||||
List<CascadeModelFieldDTO> getCascadeModelFieldList(String modelName, String fieldName); |
||||
|
||||
List<ExportStrategyDTO> preConfigExportStrategy(String modelName, String templateId); |
||||
|
||||
boolean saveTemplate(ExportTemplateDTO exportTemplateDTO) |
||||
throws InvocationTargetException, IllegalAccessException; |
||||
} |
@ -0,0 +1,151 @@
|
||||
package com.hypass.export.service.impl; |
||||
|
||||
import com.export.common.CommonBoolean; |
||||
import com.google.inject.Inject; |
||||
import com.hypaas.db.Query; |
||||
import com.hypaas.meta.db.MetaField; |
||||
import com.hypaas.meta.db.MetaModel; |
||||
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.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.util.ArrayList; |
||||
import java.util.List; |
||||
import org.apache.commons.collections.CollectionUtils; |
||||
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 |
||||
*/ |
||||
public class ExportServiceImpl implements IExportService { |
||||
|
||||
@Inject private MetaModelRepository metaModelRepository; |
||||
|
||||
@Inject private ExportStrategyRepository exportStrategyRepository; |
||||
|
||||
@Inject private ExportTemplateRepository exportTemplateRepository; |
||||
|
||||
@Inject private MetaFieldRepository metaFieldRepository; |
||||
|
||||
@Override |
||||
public List<MetaModelDTO> getModelList() { |
||||
List<MetaModel> fetch = metaModelRepository.all().fetch(); |
||||
if (CollectionUtils.isNotEmpty(fetch)) { |
||||
return HypassBeanUtils.copyProperties4List(fetch, MetaModelDTO.class); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public ExportStrategyDTO getModelExportStrategy(String templateId) |
||||
throws InvocationTargetException, IllegalAccessException { |
||||
ExportTemplate exportTemplate = exportTemplateRepository.find(Long.valueOf(templateId)); |
||||
ExportStrategy exportStrategy = |
||||
Query.of(ExportStrategy.class) |
||||
.filter("self.templateInfo = :templateInfo") |
||||
.bind("templateInfo", exportTemplate) |
||||
.fetchOne(); |
||||
ExportStrategyDTO exportStrategyDTO = new ExportStrategyDTO(); |
||||
HypassBeanUtils.copyProperties(exportStrategy, exportStrategyDTO); |
||||
return exportStrategyDTO; |
||||
} |
||||
|
||||
@Override |
||||
public boolean saveTemplateStrategy(ExportStrategyDTO exportStrategyDTO) { |
||||
ExportStrategy exportStrategy = new ExportStrategy(); |
||||
BeanUtils.copyProperties(exportStrategyDTO, exportStrategy); |
||||
exportStrategyRepository.save(exportStrategy); |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public List<CascadeModelFieldDTO> getCascadeModelFieldList(String modelName, String fieldName) { |
||||
MetaModel metaModel = metaModelRepository.findByName(modelName); |
||||
MetaField metaField = |
||||
Query.of(MetaField.class) |
||||
.filter("self.metaModel = :metaModel and self.name = :name") |
||||
.bind("metaModel", metaModel) |
||||
.bind("name", fieldName) |
||||
.fetchOne(); |
||||
String typeName = metaField.getTypeName(); |
||||
MetaModel cascadeModel = metaModelRepository.findByName(typeName); |
||||
List<MetaField> fields = |
||||
Query.of(MetaField.class) |
||||
.filter("self.metaModel = :metaModel") |
||||
.bind("metaModel", cascadeModel) |
||||
.fetch(); |
||||
if (CollectionUtils.isNotEmpty(fields)) { |
||||
List<CascadeModelFieldDTO> list = new ArrayList<>(); |
||||
fields.forEach( |
||||
field -> { |
||||
CascadeModelFieldDTO cascadeModelDTO = new CascadeModelFieldDTO(); |
||||
cascadeModelDTO.setCode(field.getName()); |
||||
cascadeModelDTO.setName(field.getLabel()); |
||||
list.add(cascadeModelDTO); |
||||
}); |
||||
return list; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public List<ExportStrategyDTO> preConfigExportStrategy(String modelName, String templateId) { |
||||
List<ExportStrategyDTO> exportStrategyDTOS = new ArrayList<>(); |
||||
ExportTemplate exportTemplate = exportTemplateRepository.find(Long.valueOf(templateId)); |
||||
if (exportTemplate == null) { |
||||
MetaModel metaModel = metaModelRepository.findByName(modelName); |
||||
List<MetaField> fields = |
||||
Query.of(MetaField.class) |
||||
.filter("self.metaModel = :metaModel") |
||||
.bind("metaModel", metaModel) |
||||
.fetch(); |
||||
if (CollectionUtils.isEmpty(fields)) { |
||||
return exportStrategyDTOS; |
||||
} |
||||
fields.forEach( |
||||
field -> { |
||||
ExportStrategyDTO exportStrategyDTO = new ExportStrategyDTO(); |
||||
exportStrategyDTO.setFieldName(field.getName()); |
||||
exportStrategyDTO.setFieldType(field.getTypeName()); |
||||
if (StringUtils.isEmpty(field.getRelationship())) { |
||||
exportStrategyDTO.setFieldAttr("普通"); |
||||
} else { |
||||
exportStrategyDTO.setFieldAttr(field.getRelationship()); |
||||
} |
||||
exportStrategyDTO.setIsExport(CommonBoolean.NOT); |
||||
}); |
||||
} else { |
||||
List<ExportStrategy> list = |
||||
Query.of(ExportStrategy.class) |
||||
.filter("self.templateInfo = :templateInfo") |
||||
.bind("templateInfo", exportTemplate) |
||||
.fetch(); |
||||
|
||||
exportStrategyDTOS = HypassBeanUtils.copyProperties4List(list, ExportStrategyDTO.class); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public boolean saveTemplate(ExportTemplateDTO exportTemplateDTO) |
||||
throws InvocationTargetException, IllegalAccessException { |
||||
ExportTemplate exportTemplate = new ExportTemplate(); |
||||
HypassBeanUtils.copyProperties(exportTemplateDTO, exportTemplate); |
||||
if (exportTemplateDTO.getIsDefaultTemplate() != null) { |
||||
exportTemplateRepository.save(exportTemplate); |
||||
} else { |
||||
exportTemplateRepository.merge(exportTemplate); |
||||
} |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,29 @@
|
||||
package com.hypass.export.utils; |
||||
|
||||
import cn.hutool.core.bean.BeanUtil; |
||||
import java.lang.reflect.InvocationTargetException; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import org.springframework.beans.BeanUtils; |
||||
import org.springframework.util.CollectionUtils; |
||||
|
||||
/** @ClassName HypassBeanUtils @Description TODO @Author wyj @Date 2023/2/8 18:26 @Version 1.0 */ |
||||
public class HypassBeanUtils { |
||||
|
||||
public static <T> List<T> copyProperties4List(List<?> sources, Class<T> destination) { |
||||
if (CollectionUtils.isEmpty(sources)) { |
||||
return new ArrayList<>(); |
||||
} |
||||
|
||||
List<T> list = new ArrayList<>(); |
||||
for (Object source : sources) { |
||||
list.add(BeanUtil.copyProperties(source, destination)); |
||||
} |
||||
return list; |
||||
} |
||||
|
||||
public static void copyProperties(Object orig, Object dest) |
||||
throws InvocationTargetException, IllegalAccessException { |
||||
BeanUtils.copyProperties(orig, dest); |
||||
} |
||||
} |
Loading…
Reference in new issue