提交 35ebcbe1 编写于 作者: sq3536's avatar sq3536

提交

上级 1a7808a1
package cn.ibizlab.core.lite.extensions.domain; package cn.ibizlab.core.lite.extensions.domain;
import cn.ibizlab.core.lite.domain.MetaRelationship;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
...@@ -27,4 +28,6 @@ public class RelationshipModel { ...@@ -27,4 +28,6 @@ public class RelationshipModel {
private String entityId; private String entityId;
private MetaRelationship relation;
} }
...@@ -4,8 +4,10 @@ import cn.ibizlab.core.lite.domain.*; ...@@ -4,8 +4,10 @@ import cn.ibizlab.core.lite.domain.*;
import cn.ibizlab.core.lite.extensions.domain.MetaEntityModel; import cn.ibizlab.core.lite.extensions.domain.MetaEntityModel;
import cn.ibizlab.core.lite.extensions.domain.SysModel; import cn.ibizlab.core.lite.extensions.domain.SysModel;
import cn.ibizlab.core.lite.extensions.mapping.MetaEntityMapping; import cn.ibizlab.core.lite.extensions.mapping.MetaEntityMapping;
import cn.ibizlab.core.lite.filter.MetaFieldSearchContext;
import cn.ibizlab.core.lite.service.*; import cn.ibizlab.core.lite.service.*;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
...@@ -126,7 +128,7 @@ public class LiteCoreService { ...@@ -126,7 +128,7 @@ public class LiteCoreService {
entity.setEntityId(entity.getDefaultKey(true).toString()); entity.setEntityId(entity.getDefaultKey(true).toString());
create.add(entity); create.add(entity);
} }
gloabEntity.put(sysModel.getSystemid()+"."+entity.getEntityName(),entity.getEntityId()); gloabEntity.put((sysModel.getSystemid()+"."+entity.getEntityName()).toUpperCase(),entity.getEntityId());
String moduleId=entity.getModuleId(); String moduleId=entity.getModuleId();
String moduleName=entity.getModuleName(); String moduleName=entity.getModuleName();
if(!ObjectUtils.isEmpty(moduleId) && !ObjectUtils.isEmpty(moduleName)){ if(!ObjectUtils.isEmpty(moduleId) && !ObjectUtils.isEmpty(moduleName)){
...@@ -163,24 +165,60 @@ public class LiteCoreService { ...@@ -163,24 +165,60 @@ public class LiteCoreService {
* @param sysModel * @param sysModel
*/ */
private void syncDEField(SysModel sysModel,int saveMode) { private void syncDEField(SysModel sysModel,int saveMode) {
Map<String,String> delField = new HashMap<>(); Map<String,MetaField> delField = new HashMap<>();
Map param=new HashMap();
param.put("id",sysModel.getSystemid());
List<JSONObject> oldField=fieldService.select("select fieldid as \"FIELDID\",fieldname as \"FIELDNAME\",t.entityid as \"ENTITYID\",t.entityname as \"ENTITYNAME\" from ibzfield t inner join ibzentity t1 on t.entityid =t1.entityid where t1.systemid = #{et.id}",param); MetaFieldSearchContext context=new MetaFieldSearchContext();
for(JSONObject field: oldField){ context.setSize(Integer.MAX_VALUE);
delField.put(field.getString("ENTITYNAME")+"."+field.getString("FIELDNAME"),field.getString("FIELDID")); context.setN_systemid_eq(sysModel.getSystemid());
} fieldService.searchDefault(context).getContent().forEach(item->{
delField.put((item.getEntityName()+"."+item.getFieldName()).toUpperCase(),item);
});
List<MetaField> create=new ArrayList<>(); List<MetaField> create=new ArrayList<>();
List<MetaField> update=new ArrayList<>(); List<MetaField> update=new ArrayList<>();
List<MetaField> change=new ArrayList<>();
Set<MetaField> list = sysModel.getField(); Set<MetaField> list = sysModel.getField();
list.forEach(field -> { list.forEach(field -> {
if(gloabEntity.containsKey(sysModel.getSystemid()+"."+field.getEntityName())) if(gloabEntity.containsKey((sysModel.getSystemid()+"."+field.getEntityName()).toUpperCase()))
field.setEntityId(gloabEntity.get(sysModel.getSystemid()+"."+field.getEntityName())); field.setEntityId(gloabEntity.get((sysModel.getSystemid()+"."+field.getEntityName()).toUpperCase()));
if(delField.containsKey(field.getEntityName()+"."+field.getFieldName())) String fieldKey=(field.getEntityName()+"."+field.getFieldName()).toUpperCase();
if(delField.containsKey(fieldKey))
{ {
field.setFieldId(delField.get(field.getEntityName()+"."+field.getFieldName())); MetaField oldField = delField.get(fieldKey);
field.setFieldId(oldField.getFieldId());
update.add(field); update.add(field);
delField.remove(field.getEntityName()+"."+field.getFieldName());
if((!DataObject.getStringValue(oldField.getFieldType(),"").equalsIgnoreCase(DataObject.getStringValue(field.getFieldType(),"")))
||(DataObject.getIntegerValue(oldField.getDataLength(),0)!=DataObject.getIntegerValue(field.getDataLength(),0)&&(!DataObject.getStringValue(oldField.getFieldType(),"").startsWith("DATE")))
||DataObject.getIntegerValue(oldField.getNullable(),0)!=DataObject.getIntegerValue(field.getNullable(),0)
||(!DataObject.getStringValue(oldField.getUnionKey(),"").equalsIgnoreCase(DataObject.getStringValue(field.getUnionKey(),"")))
||(DataObject.getIntegerValue(oldField.getKeyField(),0)!=DataObject.getIntegerValue(field.getKeyField(),0))
||(!DataObject.getStringValue(oldField.getPredefined(),"").equalsIgnoreCase(DataObject.getStringValue(field.getPredefined(),"")))
||((!DataObject.getStringValue(oldField.getExpression(),"").equalsIgnoreCase(DataObject.getStringValue(field.getExpression(),"")))&&DataObject.getIntegerValue(oldField.getPhysicalField(),1)==0)
)
{
MetaField newField=new MetaField();
newField.setFieldId(oldField.getFieldId());
newField.setEntityName(field.getEntityName());
newField.setFieldName(field.getFieldName());
newField.setDataType(field.getDataType());
newField.setFieldType(field.getFieldType());
newField.setDataLength(field.getDataLength());
newField.setDataPreci(field.getDataPreci());
newField.setNullable(field.getNullable());
newField.setUnionKey(field.getUnionKey());
if(!StringUtils.isEmpty(field.getExpression()))
newField.setExpression(field.getExpression());
if(!StringUtils.isEmpty(field.getPredefined()))
newField.setPredefined(field.getPredefined());
newField.setKeyField(field.getKeyField());
change.add(newField);
}
delField.remove(fieldKey);
} }
else { else {
field.setFieldId(field.getDefaultKey(true).toString()); field.setFieldId(field.getDefaultKey(true).toString());
...@@ -192,10 +230,21 @@ public class LiteCoreService { ...@@ -192,10 +230,21 @@ public class LiteCoreService {
// if(delField.size()>0) // if(delField.size()>0)
// fieldService.removeBatch(delField.values()); // fieldService.removeBatch(delField.values());
//存储或更新资源saveOrUpdate //存储或更新资源saveOrUpdate
if(create.size()>0&&saveMode!=ONLYUPDATE)
change.forEach(newField->{
System.out.println(newField.getEntityName()+"."+newField.getFieldName()+" "+newField.getDataType()+"("+newField.getDataLength()+(DataObject.getIntegerValue(newField.getDataPreci(),0)==0?")":(","+newField.getDataPreci()+")"))
+(DataObject.getIntegerValue(newField.getNullable(),0)==0?" not null":" null")+" "+DataObject.getStringValue(newField.getUnionKey(),""));
});
if(create.size()>0&&saveMode!=ONLYUPDATE) {
fieldService.createBatch(create); fieldService.createBatch(create);
if(update.size()>0&&saveMode!=ONLYCREATE) }
if(change.size()>0&&saveMode==ONLYCREATE) {
fieldService.updateBatch(change);
}
if(update.size()>0&&saveMode!=ONLYCREATE) {
fieldService.updateBatch(update); fieldService.updateBatch(update);
}
} }
/** /**
......
package cn.ibizlab.core.lite.extensions.service; package cn.ibizlab.core.lite.extensions.service;
import cn.ibizlab.core.lite.domain.*; 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.EntityModel;
import cn.ibizlab.core.lite.extensions.domain.FieldModel; import cn.ibizlab.core.lite.extensions.domain.FieldModel;
import cn.ibizlab.core.lite.extensions.domain.RelationshipModel; import cn.ibizlab.core.lite.extensions.domain.RelationshipModel;
import cn.ibizlab.core.lite.extensions.model.DataModel; import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.core.lite.extensions.util.LiteStorage; 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.filter.MetaFieldSearchContext;
import cn.ibizlab.core.lite.service.*; import cn.ibizlab.core.lite.service.*;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.domain.FileItem;
import cn.ibizlab.util.errors.InternalServerErrorException;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired; 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.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching; import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.sql.Wrapper; import java.io.File;
import java.util.ArrayList; import java.io.FileWriter;
import java.util.LinkedHashMap; import java.io.IOException;
import java.util.List; import java.io.PrintWriter;
import java.util.Map; import java.nio.file.Files;
import java.util.*;
import static cn.ibizlab.util.service.SimpleFileService.getExtensionName;
@Service @Service
public class LiteModelService { public class LiteModelService {
...@@ -55,11 +62,6 @@ public class LiteModelService { ...@@ -55,11 +62,6 @@ public class LiteModelService {
@Lazy @Lazy
private IMetaRelationshipService metaRelationshipService; private IMetaRelationshipService metaRelationshipService;
@Autowired
@Lazy
private IDstDataSourceService dstDataSourceService;
@Autowired @Autowired
@Lazy @Lazy
private IMetaDataSetService metaDataSetService; private IMetaDataSetService metaDataSetService;
...@@ -91,27 +93,30 @@ public class LiteModelService { ...@@ -91,27 +93,30 @@ public class LiteModelService {
EntityModel entityModel = new EntityModel(); EntityModel entityModel = new EntityModel();
entityModel.setEntity(entity); entityModel.setEntity(entity);
entityModel.setDataSets(metaDataSetService.selectByEntityId(entity.getEntityId()));
Map<String, RelationshipModel> parentSet = new LinkedHashMap(); Map<String, RelationshipModel> parentSet = new LinkedHashMap();
List<RelationshipModel> references = new ArrayList<>(); List<RelationshipModel> references = new ArrayList<>();
metaRelationshipService.selectByEntityId(entity.getEntityId()).forEach(item-> if (entity != null) {
{ entityModel.setDataSets(metaDataSetService.selectByEntityId(entity.getEntityId()));
RelationshipModel model = new RelationshipModel(); metaRelationshipService.selectByEntityId(entity.getEntityId()).forEach(item->
MetaEntity parentEntity = LiteStorage.getMetaEntity(item.getRefEntityId()); {
if(parentEntity!=null){ RelationshipModel model = new RelationshipModel();
model.setCodeName(item.getCodeName()); MetaEntity parentEntity = LiteStorage.getMetaEntity(item.getRefEntityId());
model.setDataSourceName(parentEntity.getDsName()); if(parentEntity!=null){
model.setEntityCodeName(parentEntity.getCodeName()); model.setRelation(item);
model.setEntityId(parentEntity.getEntityId()); model.setCodeName(item.getCodeName());
model.setEntityLogicName(parentEntity.getLogicName()); model.setDataSourceName(parentEntity.getDsName());
model.setEntityName(parentEntity.getEntityName()); model.setEntityCodeName(parentEntity.getCodeName());
model.setSystemId(parentEntity.getSystemId()); model.setEntityId(parentEntity.getEntityId());
model.setTableName(parentEntity.getTableName()); model.setEntityLogicName(parentEntity.getLogicName());
parentSet.put(item.getId(),model); model.setEntityName(parentEntity.getEntityName());
references.add(model); model.setSystemId(parentEntity.getSystemId());
} model.setTableName(parentEntity.getTableName());
}); parentSet.put(item.getId(),model);
references.add(model);
}
});
}
entityModel.setReferences(references); entityModel.setReferences(references);
List<RelationshipModel> nesteds = new ArrayList<>(); List<RelationshipModel> nesteds = new ArrayList<>();
...@@ -120,6 +125,7 @@ public class LiteModelService { ...@@ -120,6 +125,7 @@ public class LiteModelService {
RelationshipModel model = new RelationshipModel(); RelationshipModel model = new RelationshipModel();
MetaEntity subEntity = LiteStorage.getMetaEntity(item.getEntityId()); MetaEntity subEntity = LiteStorage.getMetaEntity(item.getEntityId());
if(subEntity!=null){ if(subEntity!=null){
model.setRelation(item);
model.setCodeName(StringUtils.isEmpty(item.getNestedName())?item.getCodeName()+"_"+item.getEntityName():item.getNestedName()); model.setCodeName(StringUtils.isEmpty(item.getNestedName())?item.getCodeName()+"_"+item.getEntityName():item.getNestedName());
model.setDataSourceName(subEntity.getDsName()); model.setDataSourceName(subEntity.getDsName());
model.setEntityCodeName(subEntity.getCodeName()); model.setEntityCodeName(subEntity.getCodeName());
...@@ -166,9 +172,7 @@ public class LiteModelService { ...@@ -166,9 +172,7 @@ public class LiteModelService {
public void initMetaEntity() public void initMetaEntity()
{ {
metaEntityService.list().forEach(metaEntity -> { metaEntityService.list().forEach(LiteStorage::putMetaEntity);
LiteStorage.putMetaEntity(metaEntity);
});
} }
@Autowired @Autowired
...@@ -195,6 +199,8 @@ public class LiteModelService { ...@@ -195,6 +199,8 @@ public class LiteModelService {
@Lazy @Lazy
private IDstSystemService dstSystemService; private IDstSystemService dstSystemService;
@Value("${ibiz.filePath:/app/file/}")
private String fileRoot;
@Cacheable( value="syspssystem",key = "'row:all-dst-apps'") @Cacheable( value="syspssystem",key = "'row:all-dst-apps'")
public LinkedHashMap<String, DstApp> getApps() { public LinkedHashMap<String, DstApp> getApps() {
...@@ -209,9 +215,7 @@ public class LiteModelService { ...@@ -209,9 +215,7 @@ public class LiteModelService {
system.setApps(system.getSysstructure().getSysApps(true)); system.setApps(system.getSysstructure().getSysApps(true));
dstSystemService.update(system); dstSystemService.update(system);
} }
system.getApps().forEach(app-> { system.getApps().forEach(app-> appNode.put(app.getId(),app));
appNode.put(app.getId(),app);
});
}); });
return appNode; return appNode;
} }
...@@ -247,4 +251,65 @@ public class LiteModelService { ...@@ -247,4 +251,65 @@ public class LiteModelService {
return list; return list;
} }
public FileItem uploadFile(MultipartFile multipartFile) {
FileItem item;
// 获取文件名
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();
}
} }
...@@ -63,7 +63,7 @@ public class DstLiquibaseService{ ...@@ -63,7 +63,7 @@ public class DstLiquibaseService{
@Value("${ibiz.generateDs.catalogName:}") @Value("${ibiz.generateDs.catalogName:}")
protected String catalogName; protected String catalogName;
@Value("${ibiz.generateDs.generateField:tables,views,columns,indexes,foreignkeys,primarykeys,uniqueconstraints}") @Value("${ibiz.generateDs.generateField:tables,columns,indexes,foreignkeys,primarykeys,uniqueconstraints}")
protected String generateField; protected String generateField;
@Value("${ibiz.generateDs.includeCatalog:false}") @Value("${ibiz.generateDs.includeCatalog:false}")
...@@ -170,6 +170,26 @@ public class DstLiquibaseService{ ...@@ -170,6 +170,26 @@ public class DstLiquibaseService{
sysModel.setSystemid((String) commonMessage.get(0).get("author")); sysModel.setSystemid((String) commonMessage.get(0).get("author"));
sysModel.setSystemname((String) commonMessage.get(0).get("author")); sysModel.setSystemname((String) commonMessage.get(0).get("author"));
} }
Hashtable<String,Set<String>> keysets=new Hashtable<String,Set<String>>();
for (int i = 0;i < commonMessage.size(); i++) {
temp = (Map) commonMessage.get(i).get("addPrimaryKey");
if(ObjectUtil.isEmpty(temp)){
continue;
}
if(ObjectUtil.isEmpty(temp.get("tableName"))||ObjectUtil.isEmpty(temp.get("columnNames"))){
continue;
}
String tableName=temp.get("tableName").toString().toUpperCase();
String columnNames=temp.get("columnNames").toString().toUpperCase().replace(" ", "");
Set<String> sets=new LinkedHashSet<>();
for(String str:columnNames.split(","))
{
sets.add(str);
}
keysets.put(tableName, sets);
}
// 第三层 获取实体对象List 在这层可以放入subEntitys、parentEntitys等关系字段 // 第三层 获取实体对象List 在这层可以放入subEntitys、parentEntitys等关系字段
for (int i = 0;i < commonMessage.size(); i++) { for (int i = 0;i < commonMessage.size(); i++) {
temp = (Map) commonMessage.get(i).get("createTable"); temp = (Map) commonMessage.get(i).get("createTable");
...@@ -178,12 +198,14 @@ public class DstLiquibaseService{ ...@@ -178,12 +198,14 @@ public class DstLiquibaseService{
} }
metaEntityModel = new MetaEntityModel(); metaEntityModel = new MetaEntityModel();
// 为了获取MetaEntityModel下那些基本类型字段(此处可补充MetaEntityModel等描述字段) // 为了获取MetaEntityModel下那些基本类型字段(此处可补充MetaEntityModel等描述字段)
metaEntityModel.setEntityName(temp.get("tableName") == null ? "" : temp.get("tableName").toString().toUpperCase()); String tableName=temp.get("tableName") == null ? "" : temp.get("tableName").toString().toUpperCase();
metaEntityModel.setCodeName(temp.get("tableName") == null ? "" : temp.get("tableName").toString().toUpperCase()); metaEntityModel.setEntityName(tableName);
metaEntityModel.setTableName(temp.get("tableName") == null ? "" : temp.get("tableName").toString().toUpperCase()); metaEntityModel.setCodeName(tableName);
metaEntityModel.setLogicName(temp.get("tableName") == null ? "" : temp.get("tableName").toString().toUpperCase()); metaEntityModel.setTableName(tableName);
metaEntityModel.setLogicName(temp.get("remarks") == null ? metaEntityModel.getEntityName() : temp.get("remarks").toString().toUpperCase());
metaEntityModel.setSystemId((String) commonMessage.get(0).get("author")); metaEntityModel.setSystemId((String) commonMessage.get(0).get("author"));
if(!(temp.get("column") instanceof List)) if(!(temp.get("column") instanceof List))
continue; continue;
column = (List<Map>) temp.get("column"); column = (List<Map>) temp.get("column");
...@@ -192,6 +214,12 @@ public class DstLiquibaseService{ ...@@ -192,6 +214,12 @@ public class DstLiquibaseService{
List<MetaRelationship> parentRelationships = new CopyOnWriteArrayList<>(); List<MetaRelationship> parentRelationships = new CopyOnWriteArrayList<>();
List<MetaRelationship> subRelationships = new CopyOnWriteArrayList<>(); List<MetaRelationship> subRelationships = new CopyOnWriteArrayList<>();
List<MetaField> unionKeys=new ArrayList<>(); List<MetaField> unionKeys=new ArrayList<>();
Set<String> keyset=keysets.get(tableName);
if(keyset==null){
keyset = new LinkedHashSet<>();
}
for (int j = 0; j < column.size();j++){ for (int j = 0; j < column.size();j++){
// (此处可补充MetaField描述字段,以及父子外键关系等) // (此处可补充MetaField描述字段,以及父子外键关系等)
metaField = new MetaField(); metaField = new MetaField();
...@@ -210,7 +238,7 @@ public class DstLiquibaseService{ ...@@ -210,7 +238,7 @@ public class DstLiquibaseService{
if(metaField.getDataType().indexOf("CHAR")>=0) { if(metaField.getDataType().indexOf("CHAR")>=0) {
metaField.setFieldType("TEXT"); metaField.setFieldType("TEXT");
if(metaField.getDataLength()>=1000) if(metaField.getDataLength()>=1000)
metaField.setFieldType("LONGTEXT1000"); metaField.setFieldType("LONGTEXT_1000");
} }
else if((metaField.getDataType().indexOf("NUMB")>=0&&(metaField.getDataPreci()==null||metaField.getDataPreci()==0)&&metaField.getDataLength()>9)||(metaField.getDataType().indexOf("BIGINT")>=0)||(metaField.getDataType().indexOf("LONG")>=0)) else if((metaField.getDataType().indexOf("NUMB")>=0&&(metaField.getDataPreci()==null||metaField.getDataPreci()==0)&&metaField.getDataLength()>9)||(metaField.getDataType().indexOf("BIGINT")>=0)||(metaField.getDataType().indexOf("LONG")>=0))
metaField.setFieldType("BIGINT"); metaField.setFieldType("BIGINT");
...@@ -222,32 +250,60 @@ public class DstLiquibaseService{ ...@@ -222,32 +250,60 @@ public class DstLiquibaseService{
metaField.setFieldType("LONGTEXT"); metaField.setFieldType("LONGTEXT");
else if(metaField.getDataType().indexOf("TIME")>=0) else if(metaField.getDataType().indexOf("TIME")>=0)
metaField.setFieldType("DATETIME"); metaField.setFieldType("DATETIME");
else if(metaField.getDataType().indexOf("DATE")>=0) else if(metaField.getDataType().indexOf("DATE")>=0) {
metaField.setFieldType("DATE"); metaField.setFieldType("DATE");
}
if(metaField.getFieldType().startsWith("DATE") &&metaField.getDataType().startsWith("TIME") )
{
if(metaField.getFieldName().equalsIgnoreCase("ZHXGSJ")
||metaField.getFieldName().equalsIgnoreCase("ZSJKBGSJ")
||metaField.getFieldName().equalsIgnoreCase("UPDATEDATE") )
{
metaField.setFieldType("DATETIME");
metaField.setPredefined("UPDATEDATE");
}
else if(metaField.getFieldName().equalsIgnoreCase("CJSJ")||metaField.getFieldName().equalsIgnoreCase("CREATEDATE"))
{
metaField.setFieldType("DATETIME");
metaField.setPredefined("CREATEDATE");
}
else if(metaField.getDataPreci()==null||metaField.getDataPreci()==0)
metaField.setFieldType("DATE");
else
metaField.setFieldType("DATETIME");
}
if(metaField.getFieldName().equalsIgnoreCase("ENABLE")||metaField.getFieldName().equalsIgnoreCase("SFSC"))
{
metaField.setPredefined("LOGICVALID");
}
int isKey=0;
Map<String,List<Map>> map = (Map<String, List<Map>>) column.get(j).get("constraints"); Map<String,List<Map>> map = (Map<String, List<Map>>) column.get(j).get("constraints");
if(!ObjectUtil.isEmpty(map)){ if(!ObjectUtil.isEmpty(map)){
metaField.setNullable(map.get("nullable")==null?1:0); metaField.setNullable(map.get("nullable")==null?1:0);
int isKey=map.get("primaryKey")==null?0:1; isKey=map.get("primaryKey")==null?0:1;
metaField.setKeyField(isKey);
if(isKey==1)
unionKeys.add(metaField);
}else { }else {
metaField.setNullable(1); metaField.setNullable(1);
metaField.setKeyField(0);
} }
String name = column.get(j).get("name") == null? "" : column.get(j).get("name").toString();
if(isKey==0&&keyset.contains(metaField.getFieldName()))
isKey=1;
metaField.setKeyField(isKey);
if(isKey==1)
unionKeys.add(metaField);
String name = column.get(j).get("name") == null? "" : column.get(j).get("name").toString();
// 若在父键表查有该数据且属于同一实体则记录一条 // 若在父键表查有该数据且属于同一实体则记录一条
for (int l = 0; l < parentEntities.size();l++){ for (int l = 0; l < parentEntities.size();l++){
if(name.equals(parentEntities.get(l).keySet().toString().replaceAll("[\\[\\]]", ""))){ if(name.equals(parentEntities.get(l).keySet().toString().replaceAll("[\\[\\]]", ""))){
if(temp.get("tableName").toString().toUpperCase().equals(parentEntities.get(l).get(name).getRefEntityName())) { if(temp.get("tableName").toString().toUpperCase().equals(parentEntities.get(l).get(name).getRefEntityName())) {
parentEntities.get(l).get(name).setEntityId(metaField.getEntityId()); parentEntities.get(l).get(name).setEntityId(metaField.getEntityId());
parentRelationships.add(parentEntities.get(l).get(name)); parentRelationships.add(parentEntities.get(l).get(name));
}
} }
} }
}
metaEntityModel.setParentEntitys(parentRelationships); metaEntityModel.setParentEntitys(parentRelationships);
// 若在子键表查有该数据且属于同一实体则记录一条 // 若在子键表查有该数据且属于同一实体则记录一条
...@@ -266,7 +322,11 @@ public class DstLiquibaseService{ ...@@ -266,7 +322,11 @@ public class DstLiquibaseService{
metaFields.add(metaField); metaFields.add(metaField);
} }
if(unionKeys.size()>1) int unionKeysLimit=1;
if(sysModel.getSystemid().equalsIgnoreCase("tyyw2plus")||sysModel.getSystemid().equalsIgnoreCase("tyyw"))
unionKeysLimit=0;
if(unionKeys.size()>unionKeysLimit)
{ {
MetaField uilid = new MetaField(); MetaField uilid = new MetaField();
unionKeys.get(0).copyTo(uilid,true); unionKeys.get(0).copyTo(uilid,true);
...@@ -276,6 +336,7 @@ public class DstLiquibaseService{ ...@@ -276,6 +336,7 @@ public class DstLiquibaseService{
uilid.setKeyField(1); uilid.setKeyField(1);
uilid.setPhysicalField(0); uilid.setPhysicalField(0);
uilid.setFieldType("TEXT"); uilid.setFieldType("TEXT");
uilid.setDataType("VARCHAR");
String expression=""; String expression="";
for(int no=0;no<unionKeys.size();no++) for(int no=0;no<unionKeys.size();no++)
{ {
......
...@@ -11,8 +11,10 @@ import cn.ibizlab.core.lite.extensions.service.DbEntityService; ...@@ -11,8 +11,10 @@ import cn.ibizlab.core.lite.extensions.service.DbEntityService;
import cn.ibizlab.core.lite.extensions.service.LiteCoreService; import cn.ibizlab.core.lite.extensions.service.LiteCoreService;
import cn.ibizlab.core.lite.extensions.service.LiteDataService; import cn.ibizlab.core.lite.extensions.service.LiteDataService;
import cn.ibizlab.core.lite.extensions.service.LiteModelService; import cn.ibizlab.core.lite.extensions.service.LiteModelService;
import cn.ibizlab.core.lite.filter.MetaFieldSearchContext;
import cn.ibizlab.core.lite.service.IDstComponentService; import cn.ibizlab.core.lite.service.IDstComponentService;
import cn.ibizlab.core.lite.service.IDstConfigService; import cn.ibizlab.core.lite.service.IDstConfigService;
import cn.ibizlab.core.lite.service.IMetaFieldService;
import cn.ibizlab.util.client.IBZDictFeignClient; import cn.ibizlab.util.client.IBZDictFeignClient;
import cn.ibizlab.util.dict.CodeItem; import cn.ibizlab.util.dict.CodeItem;
import cn.ibizlab.util.dict.CodeList; import cn.ibizlab.util.dict.CodeList;
...@@ -21,6 +23,7 @@ import cn.ibizlab.util.errors.BadRequestAlertException; ...@@ -21,6 +23,7 @@ import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.DataObject; import cn.ibizlab.util.helper.DataObject;
import cn.ibizlab.util.security.AuthenticationUser; import cn.ibizlab.util.security.AuthenticationUser;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
...@@ -31,6 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -31,6 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -71,6 +75,81 @@ public class LiteCoreResource { ...@@ -71,6 +75,81 @@ public class LiteCoreResource {
return ResponseEntity.ok(liteDataService.getModelObjs(modelid, null,key)); return ResponseEntity.ok(liteDataService.getModelObjs(modelid, null,key));
} }
@Autowired
@Lazy
private IMetaFieldService fieldService;
@RequestMapping(method = RequestMethod.GET, value = "/lite/{system}/{from}.ibzbak")
public ResponseEntity<JSONObject> ibzbak(@PathVariable(name="system",required = true) String system,@PathVariable(name="from",required = true) String from)
{
MetaFieldSearchContext context=new MetaFieldSearchContext();
context.setSize(Integer.MAX_VALUE);
context.setN_systemid_eq(system);
context.getSearchCond().ge("updatedate", DataObject.getTimestampValue(from, null));
JSONArray jArray = new JSONArray();
fieldService.searchDefault(context).getContent().forEach(sx->{
JSONObject json = new JSONObject();
JSONObject jo = new JSONObject();
jo.put("psdefieldname", sx.getFieldName());
jo.put("predefinetype", sx.getPredefined());
jo.put("unionkeyvalue", sx.getUnionKey());
jo.put("codename", sx.getCodeName());
jo.put("physicalfield", sx.getPhysicalField());
jo.put("psdeid", DigestUtils.md5DigestAsHex(("2C40DFCD-0DF5-47BF-91A5-C45F810B0001||"+sx.getEntityName()).getBytes()).toLowerCase());
jo.put("logicname", sx.getFieldLogicName());
if (sx.getDataLength() != null && sx.getDataLength() > 0)
jo.put("length", sx.getDataLength());
if (sx.getDataPreci() != null && sx.getDataPreci() > 0)
jo.put("precision2", sx.getDataPreci());
jo.put("ordervalue", sx.getShowOrder());
jo.put("psdefieldid", DigestUtils.md5DigestAsHex((DigestUtils.md5DigestAsHex(("2C40DFCD-0DF5-47BF-91A5-C45F810B0001||"+sx.getEntityName()).getBytes()).toLowerCase()+"||"+sx.getFieldName()).getBytes()).toLowerCase());
if(1==sx.getPhysicalField()&&(StringUtils.isEmpty(sx.getExpression())))
jo.put("deftype", 1);
else {
jo.put("deftype", 2);
jo.put("formulaformat",sx.getExpression());
}
jo.put("pkey", sx.getKeyField());
jo.put("pssystemid", "2C40DFCD-0DF5-47BF-91A5-C45F810B0001");
jo.put("psdename", sx.getEntityName());
jo.put("tablename", sx.getEntityName());
String strRT = "文本,可指定长度";
String strDataTypeId=sx.getFieldType();
jo.put("psdatatypeid", strDataTypeId);
if (strDataTypeId.equalsIgnoreCase("DECIMAL"))
strRT = "数值";
else if (strDataTypeId.equalsIgnoreCase("INT"))
strRT = "整型";
else if (strDataTypeId.equalsIgnoreCase("BIGDECIMAL"))
strRT = "大数值";
else if (strDataTypeId.equalsIgnoreCase("BIGINT"))
strRT = "大整型";
else if (strDataTypeId.equalsIgnoreCase("LONGTEXT"))
strRT = "长文本,没有长度限制";
else if (strDataTypeId.equalsIgnoreCase("LONGTEXT_1000"))
strRT = "长文本,长度1000";
else if (strDataTypeId.equalsIgnoreCase("DATE"))
strRT = "日期型";
else if (strDataTypeId.equalsIgnoreCase("DATETIME"))
strRT = "日期时间型";
jo.put("psdatatypename", strRT);
jo.put("allowempty", sx.getNullable());
json.put("srfvalue", jo);
json.put("srfdeid", "42d91505b9bb15b9900b4298fcca9915");
json.put("srfdename", "PSDEFIELD");
jArray.add(json);
});
JSONObject jo = new JSONObject();
jo.put("items", jArray);
return ResponseEntity.ok(jo);
}
@RequestMapping(method = RequestMethod.GET, value = {"/lite/datamodels/{modelid}","/lite/datamodels/{modelid}/name/{modelname}"}) @RequestMapping(method = RequestMethod.GET, value = {"/lite/datamodels/{modelid}","/lite/datamodels/{modelid}/name/{modelname}"})
public ResponseEntity<DataModel> getDataModel(@PathVariable(name="modelid") String modelid, public ResponseEntity<DataModel> getDataModel(@PathVariable(name="modelid") String modelid,
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册