提交 02983aed 编写于 作者: llz's avatar llz

Merge branch 'master' of http://demo.ibizlab.cn/ibiz4jteam/ibzlite into master

...@@ -3,3 +3,9 @@ spring: ...@@ -3,3 +3,9 @@ spring:
include: sys ,nacos, web-prod include: sys ,nacos, web-prod
application: application:
name: ibzlite-web name: ibzlite-web
zuul:
routes:
dst_ms:
path: /lite/**
serviceId: ${ibiz.ref.service.ibzlite-api:ibzlite-api}
stripPrefix: false
\ No newline at end of file
package cn.ibizlab.core.extensions.service; package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.lite.domain.MetaEntity;
import cn.ibizlab.core.lite.domain.MetaField;
import cn.ibizlab.core.lite.domain.MetaRelationship;
import cn.ibizlab.core.lite.extensions.domain.SysModel;
import cn.ibizlab.core.lite.service.IMetaEntityService;
import cn.ibizlab.core.lite.service.IMetaFieldService;
import cn.ibizlab.core.lite.service.IMetaRelationshipService;
import cn.ibizlab.core.lite.service.impl.DstSystemServiceImpl; import cn.ibizlab.core.lite.service.impl.DstSystemServiceImpl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.core.lite.domain.DstSystem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.util.StringUtils; import org.springframework.stereotype.Service;
import java.util.*;
/** /**
* 实体[系统] 自定义服务对象 * 实体[系统] 自定义服务对象
...@@ -30,140 +13,10 @@ import java.util.*; ...@@ -30,140 +13,10 @@ import java.util.*;
@Service("DstSystemExService") @Service("DstSystemExService")
public class DstSystemExService extends DstSystemServiceImpl { public class DstSystemExService extends DstSystemServiceImpl {
@Autowired
@Lazy
IMetaEntityService entityService;
@Autowired
@Lazy
IMetaFieldService fieldService;
@Autowired
@Lazy
IMetaRelationshipService relationService;
@Autowired
@Lazy
DstSystemExService proxyService;
@Override @Override
protected Class currentModelClass() { protected Class currentModelClass() {
return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1); return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1);
} }
@Override
public boolean create(DstSystem et) {
SysModel structure=et.getSysstructure();
if(!super.create(et))
return false;
et.setSysstructure(structure);
proxyService.syncSysModel(et);
return true;
}
@Override
public boolean update(DstSystem et) {
SysModel structure=et.getSysstructure();
Object ignoreSyncSysModel=et.get("ignoreSyncSysModel");
if(!super.update(et))
return false;
if(ignoreSyncSysModel==null||ignoreSyncSysModel.equals(false)){
et.setSysstructure(structure);
proxyService.syncSysModel(et);
}
return true;
}
/**
* 自定义行为[SyncSysModel]用户扩展
* @param system
* @return
*/
@Override
@Transactional
@Async("asyncExecutor")
public DstSystem syncSysModel(DstSystem system) {
if(StringUtils.isEmpty(system.getPssystemid())||system.getSysstructure()==null)
return system;
Object ignoreSyncSysModel=system.get("ignoreSyncSysModel");
if(ignoreSyncSysModel!=null&&ignoreSyncSysModel.equals(true))
return system;
long start = System.currentTimeMillis();
log.info("开始同步[{}]系统模型",system.getPssystemid());
syncDE(system);
syncDEField(system);
syncDERelation(system);
long end = System.currentTimeMillis();
log.info("完成[{}]系统同步模型任务,总耗时[{}]秒",system.getPssystemid(),(end-start)/1000);
return super.syncSysModel(system);
}
/**
* 同步实体
* @param system
*/
private void syncDE(DstSystem system) {
Map<String,Integer> delDE = new HashMap<>();
entityService.list(new QueryWrapper<MetaEntity>().select("entityid").eq("systemid",system.getPssystemid())).forEach(entity -> delDE.put(entity.getEntityId(),1));
Set<MetaEntity> list = system.getSysstructure().getEntity();
list.forEach(entity -> {
delDE.remove(entity.getEntityId());
});
//移除无效资源
if(delDE.size()>0)
entityService.removeBatch(delDE.keySet());
//存储或更新资源saveOrUpdate
if(list.size()>0)
entityService.saveBatch(list);
}
/**
* 同步实体属性
* @param system
*/
private void syncDEField(DstSystem system) {
Map<String,Integer> delField = new HashMap<>();
Map param=new HashMap();
param.put("id",system.getPssystemid());
List<JSONObject> oldField=fieldService.select("select fieldid from ibzfield t inner join ibzentity t1 on t.entityid =t1.entityid where t1.systemid = #{et.id}",param);
for(JSONObject field: oldField){
delField.put(field.getString("FIELDID"),1);
}
Set<MetaField> list = system.getSysstructure().getField();
list.forEach(field -> {
delField.remove(field.getFieldId());
});
//移除无效资源
if(delField.size()>0)
fieldService.removeBatch(delField.keySet());
//存储或更新资源saveOrUpdate
if(list.size()>0)
fieldService.saveBatch(list);
}
/**
* 同步实体关系
* @param system
*/
private void syncDERelation(DstSystem system) {
Map<String,Integer> delRelation = new HashMap<>();
Map param=new HashMap();
param.put("id",system.getPssystemid());
List<JSONObject> oldRelation=relationService.select("select distinct(relationid) from ibzrelation t inner join ibzentity t1 on t.entityid=t1.entityid or t.refentityid=t1.entityid where t1.systemid=#{et.id} ",param);
for(JSONObject relation: oldRelation){
delRelation.put(relation.getString("RELATIONID"),1);
}
Collection<MetaRelationship> list = system.getSysstructure().getRelation();
list.forEach(relation -> {
delRelation.remove(relation.getId());
});
//移除无效资源
if(delRelation.size()>0)
relationService.removeBatch(delRelation.keySet());
//存储或更新资源saveOrUpdate
if(list.size()>0)
relationService.saveBatch(list);
}
} }
package cn.ibizlab.core.lite.extensions.domain;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.List;
/**
* 实体[实体]
*/
@Getter
@Setter
@NoArgsConstructor
@JsonIgnoreProperties(value = "handler")
public class MetaEntityModel{
/**
* 标识
*/
@JSONField(name = "entity_id")
@JsonProperty("entity_id")
private String entityId;
/**
* 实体名
*/
@JSONField(name = "entity_name")
@JsonProperty("entity_name")
private String entityName;
/**
* 逻辑名称
*/
@JSONField(name = "logic_name")
@JsonProperty("logic_name")
private String logicName;
/**
* 代码名称
*/
@JSONField(name = "code_name")
@JsonProperty("code_name")
private String codeName;
/**
* 表名称
*/
@JSONField(name = "table_name")
@JsonProperty("table_name")
private String tableName;
/**
* 系统标识
*/
@JSONField(name = "system_id")
@JsonProperty("system_id")
private String systemId;
/**
* 系统
*/
@JSONField(name = "system_name")
@JsonProperty("system_name")
private String systemName;
/**
* 数据源标识
*/
@JSONField(name = "ds_id")
@JsonProperty("ds_id")
private String dsId;
/**
* 数据源
*/
@JSONField(name = "ds_name")
@JsonProperty("ds_name")
private String dsName;
/**
* 数据集
*/
private List<cn.ibizlab.core.lite.domain.MetaDataSet> dataSets;
/**
* 属性
*/
private List<cn.ibizlab.core.lite.domain.MetaField> fields;
/**
* 实体关系
*/
private List<cn.ibizlab.core.lite.domain.MetaRelationship> parentEntitys;
/**
* 实体关系
*/
private List<cn.ibizlab.core.lite.domain.MetaRelationship> subEntitys;
}
package cn.ibizlab.core.lite.extensions.domain; package cn.ibizlab.core.lite.extensions.domain;
import cn.ibizlab.core.lite.domain.MetaEntity;
import cn.ibizlab.core.lite.domain.MetaField; import cn.ibizlab.core.lite.domain.MetaField;
import cn.ibizlab.core.lite.domain.MetaRelationship; import cn.ibizlab.core.lite.domain.MetaRelationship;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data; import lombok.Data;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.*; import java.util.*;
@Data @Data
...@@ -16,21 +13,9 @@ public class SysModel { ...@@ -16,21 +13,9 @@ public class SysModel {
private String systemid; private String systemid;
@JsonIgnore
private String systemname; private String systemname;
private List<MetaEntity> entities; private List<MetaEntityModel> entities;
/**
* 获取实体
* @return
*/
public Set<MetaEntity> getEntity(){
Set<MetaEntity> metaEntities=new HashSet<>();
metaEntities.addAll(entities);
return metaEntities;
}
/** /**
* 获取实体属性 * 获取实体属性
* @return * @return
...@@ -41,7 +26,21 @@ public class SysModel { ...@@ -41,7 +26,21 @@ public class SysModel {
List<MetaField> deField=entityNode.getFields(); List<MetaField> deField=entityNode.getFields();
if(!ObjectUtils.isEmpty(deField)){ if(!ObjectUtils.isEmpty(deField)){
deField.forEach(field->{ deField.forEach(field->{
field.setEntityId(DigestUtils.md5DigestAsHex(String.format("%s||%s" ,systemid,entityNode.getEntityName()).getBytes())); String refDEId="";
String refFieldId="";
String curDEId=DigestUtils.md5DigestAsHex(String.format("%s||%s" ,systemid,entityNode.getEntityName()).getBytes());
Object refDEName=field.get("ref_de");
Object refFieldName=field.getRefFieldName();
Object relationCodeName=field.get("relation_codename");
field.setEntityId(curDEId);
if( !ObjectUtils.isEmpty(refDEName) && !ObjectUtils.isEmpty(refFieldName)){
refDEId=DigestUtils.md5DigestAsHex(String.format("%s||%s" ,systemid,refDEName).getBytes());
refFieldId=DigestUtils.md5DigestAsHex(String.format("%s||%s" ,refDEId,refFieldName).getBytes());
field.setRefFieldId(refFieldId);
}
if(!ObjectUtils.isEmpty(curDEId) && !ObjectUtils.isEmpty(refDEId) && !ObjectUtils.isEmpty(relationCodeName)){
field.setRelationId(DigestUtils.md5DigestAsHex(String.format("%s||%s||%s" ,refDEId,curDEId,relationCodeName).getBytes()));
}
}); });
fields.addAll(deField); fields.addAll(deField);
} }
......
package cn.ibizlab.core.lite.extensions.mapping;
import cn.ibizlab.core.lite.domain.MetaEntity;
import cn.ibizlab.core.lite.extensions.domain.MetaEntityModel;
import cn.ibizlab.util.domain.MappingBase;
import org.mapstruct.Mapper;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.NullValuePropertyMappingStrategy;
@Mapper(componentModel = "spring", uses = {},implementationName="metaEntityModelMapping",
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface MetaEntityMapping extends MappingBase<MetaEntityModel, MetaEntity> {
}
package cn.ibizlab.core.lite.extensions.service;
import cn.ibizlab.core.extensions.service.DstSystemExService;
import cn.ibizlab.core.lite.domain.MetaEntity;
import cn.ibizlab.core.lite.domain.MetaField;
import cn.ibizlab.core.lite.domain.MetaRelationship;
import cn.ibizlab.core.lite.extensions.domain.MetaEntityModel;
import cn.ibizlab.core.lite.extensions.domain.SysModel;
import cn.ibizlab.core.lite.extensions.mapping.MetaEntityMapping;
import cn.ibizlab.core.lite.service.IMetaEntityService;
import cn.ibizlab.core.lite.service.IMetaFieldService;
import cn.ibizlab.core.lite.service.IMetaRelationshipService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.util.*;
@Service
@Slf4j
public class LiteCoreService {
@Autowired
@Lazy
IMetaEntityService entityService;
@Autowired
@Lazy
IMetaFieldService fieldService;
@Autowired
@Lazy
IMetaRelationshipService relationService;
@Autowired
@Lazy
DstSystemExService proxyService;
@Autowired
@Lazy
MetaEntityMapping entityMapping;
/**
* 自定义行为[SyncSysModel]用户扩展
* @param sysModel
* @return
*/
@Transactional
@Async("asyncExecutor")
public void syncSysModel(SysModel sysModel) {
long start = System.currentTimeMillis();
log.info("开始同步[{}]系统模型",sysModel.getSystemid());
syncDE(sysModel);
syncDERelation(sysModel);
syncDEField(sysModel);
long end = System.currentTimeMillis();
log.info("完成[{}]系统同步模型任务,总耗时[{}]秒",sysModel.getSystemid(),(end-start)/1000);
}
/**
* 同步实体
* @param sysModel
*/
private void syncDE(SysModel sysModel) {
Map<String,Integer> delDE = new HashMap<>();
entityService.list(new QueryWrapper<MetaEntity>().select("entityid").eq("systemid",sysModel.getSystemid())).forEach(entity -> delDE.put(entity.getEntityId(),1));
List<MetaEntityModel> metaEntityModels = sysModel.getEntities();
Set<MetaEntity> entities=new HashSet<>();
if(!ObjectUtils.isEmpty(metaEntityModels)){
entities.addAll(entityMapping.toDomain(metaEntityModels));
}
entities.forEach(entity -> {
delDE.remove(entity.getEntityId());
});
//移除无效资源
if(delDE.size()>0)
entityService.removeBatch(delDE.keySet());
//存储或更新资源saveOrUpdate
if(entities.size()>0)
entityService.saveBatch(entities);
}
/**
* 同步实体属性
* @param sysModel
*/
private void syncDEField(SysModel sysModel) {
Map<String,Integer> delField = new HashMap<>();
Map param=new HashMap();
param.put("id",sysModel.getSystemid());
List<JSONObject> oldField=fieldService.select("select fieldid from ibzfield t inner join ibzentity t1 on t.entityid =t1.entityid where t1.systemid = #{et.id}",param);
for(JSONObject field: oldField){
delField.put(field.getString("FIELDID"),1);
}
Set<MetaField> list = sysModel.getField();
list.forEach(field -> {
delField.remove(field.getFieldId());
});
//移除无效资源
if(delField.size()>0)
fieldService.removeBatch(delField.keySet());
//存储或更新资源saveOrUpdate
if(list.size()>0)
fieldService.saveBatch(list);
}
/**
* 同步实体关系
* @param sysModel
*/
private void syncDERelation(SysModel sysModel) {
Map<String,Integer> delRelation = new HashMap<>();
Map param=new HashMap();
param.put("id",sysModel.getSystemid());
List<JSONObject> oldRelation=relationService.select("select distinct(relationid) from ibzrelation t inner join ibzentity t1 on t.entityid=t1.entityid or t.refentityid=t1.entityid where t1.systemid=#{et.id} ",param);
for(JSONObject relation: oldRelation){
delRelation.put(relation.getString("RELATIONID"),1);
}
Collection<MetaRelationship> list = sysModel.getRelation();
list.forEach(relation -> {
delRelation.remove(relation.getId());
});
//移除无效资源
if(delRelation.size()>0)
relationService.removeBatch(delRelation.keySet());
//存储或更新资源saveOrUpdate
if(list.size()>0)
relationService.saveBatch(list);
}
}
package cn.ibizlab.api.rest.extensions; package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.api.dto.DstAPIDTO;
import cn.ibizlab.core.lite.domain.DstAPI;
import cn.ibizlab.core.lite.domain.DstComponent; import cn.ibizlab.core.lite.domain.DstComponent;
import cn.ibizlab.core.lite.domain.MetaEntity;
import cn.ibizlab.core.lite.extensions.domain.EntityModel; import cn.ibizlab.core.lite.extensions.domain.EntityModel;
import cn.ibizlab.core.lite.extensions.domain.SysModel;
import cn.ibizlab.core.lite.extensions.service.LiteCoreService;
import cn.ibizlab.core.lite.extensions.service.LiteModelService; import cn.ibizlab.core.lite.extensions.service.LiteModelService;
import cn.ibizlab.core.lite.service.IDstComponentService; import cn.ibizlab.core.lite.service.IDstComponentService;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
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.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@Slf4j @Slf4j
@Api(tags = {"接口" }) @Api(tags = {"接口" })
...@@ -52,4 +50,14 @@ public class LiteCoreResource { ...@@ -52,4 +50,14 @@ public class LiteCoreResource {
return ResponseEntity.status(HttpStatus.OK).body(JSON.parseObject(dstComponent.getConfig())); return ResponseEntity.status(HttpStatus.OK).body(JSON.parseObject(dstComponent.getConfig()));
} }
@Autowired
@Lazy
LiteCoreService liteCoreService;
@ApiOperation(value = "保存系统", tags = {"系统" }, notes = "保存系统")
@RequestMapping(method = RequestMethod.POST, value = "/lite/syncsysmodel")
public void syncSysModel(@RequestBody SysModel sysModel) {
// liteCoreService.syncSysModel(sysModel);
}
} }
...@@ -93,7 +93,7 @@ ibiz: ...@@ -93,7 +93,7 @@ ibiz:
enablePermissionValid: true enablePermissionValid: true
cacheLevel: L1 #(L1)一级本地caffeine缓存;(L2)caffeine缓存+Redis缓存 cacheLevel: L1 #(L1)一级本地caffeine缓存;(L2)caffeine缓存+Redis缓存
auth: auth:
excludesPattern: /dstsystems/save excludesPattern: /dstsystems/save,/lite/syncsysmodel
### jobs ### jobs
jobs: jobs:
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册