提交 2aa2dc28 编写于 作者: tangyaolong's avatar tangyaolong

【dst模型初始化导入导出】第三版

上级 156edbc8
package cn.ibizlab.core.lite.extensions.domain;
import cn.ibizlab.core.lite.domain.MetaRelationship;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.NoArgsConstructor;
......@@ -27,4 +28,6 @@ public class RelationshipModel {
private String entityId;
private MetaRelationship relation;
}
package cn.ibizlab.core.lite.extensions.service;
import cn.ibizlab.core.lite.domain.*;
import cn.ibizlab.core.extensions.domain.AssembleModel;
import cn.ibizlab.core.extensions.service.MetaModelExService;
import cn.ibizlab.core.lite.domain.DstApp;
import cn.ibizlab.core.lite.domain.DstSystem;
import cn.ibizlab.core.lite.domain.MetaEntity;
import cn.ibizlab.core.lite.domain.MetaModel;
import cn.ibizlab.core.lite.extensions.domain.EntityModel;
import cn.ibizlab.core.lite.extensions.domain.FieldModel;
import cn.ibizlab.core.lite.extensions.domain.RelationshipModel;
import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.core.lite.extensions.util.LiteStorage;
import cn.ibizlab.core.lite.filter.MetaEntitySearchContext;
import cn.ibizlab.core.lite.filter.MetaFieldSearchContext;
import cn.ibizlab.core.lite.service.*;
import cn.ibizlab.util.domain.FileItem;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.errors.InternalServerErrorException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.PostConstruct;
import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.io.*;
import java.nio.file.Files;
import java.util.*;
import static cn.ibizlab.util.service.SimpleFileService.getExtensionName;
@Service
public class LiteModelService {
......@@ -91,7 +99,7 @@ public class LiteModelService {
EntityModel entityModel = new EntityModel();
entityModel.setEntity(entity);
entityModel.setDataSets(metaDataSetService.selectByEntityId(entity.getEntityId()));
entityModel.setDataSets(metaDataSetService.selectByEntityId(entity != null ? entity.getEntityId() : null));
Map<String, RelationshipModel> parentSet = new LinkedHashMap();
List<RelationshipModel> references = new ArrayList<>();
......@@ -100,6 +108,7 @@ public class LiteModelService {
RelationshipModel model = new RelationshipModel();
MetaEntity parentEntity = LiteStorage.getMetaEntity(item.getRefEntityId());
if(parentEntity!=null){
model.setRelation(item);
model.setCodeName(item.getCodeName());
model.setDataSourceName(parentEntity.getDsName());
model.setEntityCodeName(parentEntity.getCodeName());
......@@ -120,6 +129,7 @@ public class LiteModelService {
RelationshipModel model = new RelationshipModel();
MetaEntity subEntity = LiteStorage.getMetaEntity(item.getEntityId());
if(subEntity!=null){
model.setRelation(item);
model.setCodeName(StringUtils.isEmpty(item.getNestedName())?item.getCodeName()+"_"+item.getEntityName():item.getNestedName());
model.setDataSourceName(subEntity.getDsName());
model.setEntityCodeName(subEntity.getCodeName());
......@@ -195,6 +205,11 @@ public class LiteModelService {
@Lazy
private IDstSystemService dstSystemService;
@Value("${ibiz.filePath:/app/file/}")
private String fileRoot;
@Autowired
private MetaModelExService metaModelExService;
@Cacheable( value="syspssystem",key = "'row:all-dst-apps'")
public LinkedHashMap<String, DstApp> getApps() {
......@@ -247,4 +262,103 @@ public class LiteModelService {
return list;
}
public FileItem uploadFile(MultipartFile multipartFile) {
FileItem item = null;
// 获取文件名
String fileName = multipartFile.getOriginalFilename();
// 获取文件后缀
String extname = "."+getExtensionName(fileName);
try {
String fileid = DigestUtils.md5DigestAsHex(multipartFile.getInputStream());
String fileFullPath = this.fileRoot+"ibizutil"+File.separator+File.separator+fileName;
File file = new File(fileFullPath);
File parent = new File(file.getParent());
if(!parent.exists()) {
parent.mkdirs();
}
FileCopyUtils.copy(multipartFile.getInputStream(), Files.newOutputStream(file.toPath()));
item = new FileItem(fileid, fileName, fileid, fileName, (int)multipartFile.getSize(), extname);
} catch (IOException e) {
throw new InternalServerErrorException("文件上传失败,"+e);
}
return item;
}
public String saveFile(String jsonObject) {
// 获取文件名
String fileName = "packageModel_"+UUID.randomUUID().toString().replace("-","").toUpperCase();
// 获取文件后缀
String extname = ".json";
try {
String fileFullPath = this.fileRoot+"ibizutil"+File.separator+fileName+extname;
File file = new File(fileFullPath);
File parent = new File(file.getParent());
if(!parent.exists()) {
parent.mkdirs();
}
writeFile(fileFullPath,jsonObject);
} catch (Exception e) {
throw new InternalServerErrorException("文件上传失败,"+e);
}
return fileName+extname;
}
public File getFile(String fileId) {
String dirpath = this.fileRoot + "ibizutil" + File.separator + fileId;
File parent = new File(dirpath);
if (parent.exists()) {
return parent;
}
throw new InternalServerErrorException("文件未找到");
}
public static void writeFile(String filePath, String sets) throws IOException {
FileWriter fw = new FileWriter(filePath);
PrintWriter out = new PrintWriter(fw);
out.write(sets);
out.println();
fw.close();
out.close();
}
public String exportFile(List<MetaModel> model){
List<AssembleModel> temp = new ArrayList<>();
for (MetaModel metaModel : model) {
temp.add(null);
}
String json = JSON.toJSONString(temp);
String fileName = this.saveFile(json);
return fileName;
}
public List<AssembleModel> translateFile(MultipartFile file){
BufferedReader reader = null;
String ans = "";
try{
Reader read = new InputStreamReader(file.getInputStream(), "utf-8");
reader = new BufferedReader(read);
String tmpString = null;
while((tmpString = reader.readLine()) != null){
ans += tmpString ;
}
if(StringUtils.isEmpty(ans)){
throw new BadRequestAlertException("文件内容为空","","");
}
List<AssembleModel> assembleModel = JSONObject.parseArray(ans, AssembleModel.class);
return assembleModel;
}catch (Exception e){
return null;
}finally{
if(reader != null){
try{
reader.close();
}catch(IOException ee){
ee.printStackTrace();
}
}
}
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册