提交 0da4cb53 编写于 作者: zhouweidong's avatar zhouweidong

实体、属性、关系注册

上级 c8ff38f5
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 com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Primary;
import org.springframework.util.StringUtils;
import java.util.*;
/**
......@@ -16,20 +29,132 @@ import java.util.*;
@Service("DstSystemExService")
public class DstSystemExService extends DstSystemServiceImpl {
@Autowired
@Lazy
IMetaEntityService entityService;
@Autowired
@Lazy
IMetaFieldService fieldService;
@Autowired
@Lazy
IMetaRelationshipService relationService;
@Override
protected Class currentModelClass() {
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);
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);
syncSysModel(et);
}
return true;
}
/**
* 自定义行为[SyncSysModel]用户扩展
* @param et
* @param system
* @return
*/
@Override
@Transactional
public DstSystem syncSysModel(DstSystem et) {
return super.syncSysModel(et);
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;
syncDE(system);
syncDEField(system);
syncDERelation(system);
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);
}
Set<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);
}
}
......@@ -8,7 +8,10 @@ import java.math.BigInteger;
import java.util.HashMap;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import cn.ibizlab.core.lite.extensions.domain.SysModel;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
......@@ -59,10 +62,10 @@ public class DstSystem extends EntityMP implements Serializable {
/**
* 结构
*/
@TableField(value = "sysstructure")
@TableField(value = "sysstructure",typeHandler = JacksonTypeHandler.class)
@JSONField(name = "sysstructure")
@JsonProperty("sysstructure")
private String sysstructure;
private SysModel sysstructure;
/**
* 校验
*/
......@@ -91,7 +94,7 @@ public class DstSystem extends EntityMP implements Serializable {
/**
* 设置 [结构]
*/
public void setSysstructure(String sysstructure){
public void setSysstructure(SysModel sysstructure){
this.sysstructure = sysstructure ;
this.modify("sysstructure",sysstructure);
}
......
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.MetaRelationship;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.util.DigestUtils;
import org.springframework.util.ObjectUtils;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Data
public class SysModel {
private String systemid;
@JsonIgnore
private String systemname;
private List<MetaEntity> entities;
/**
* 获取实体
* @return
*/
public Set<MetaEntity> getEntity(){
Set<MetaEntity> metaEntities=new HashSet<>();
metaEntities.addAll(entities);
return metaEntities;
}
/**
* 获取实体属性
* @return
*/
public Set<MetaField> getField(){
Set<MetaField> fields=new HashSet<>();
this.entities.forEach(entityNode->{
List<MetaField> deField=entityNode.getFields();
if(!ObjectUtils.isEmpty(deField)){
deField.forEach(field->{
field.setEntityId(DigestUtils.md5DigestAsHex(String.format("%s||%s" ,systemid,entityNode.getEntityName()).getBytes()));
});
fields.addAll(deField);
}
}
);
return fields;
}
/**
* 获取实体关系
* @return
*/
public Set<MetaRelationship> getRelation(){
Set<MetaRelationship> relations=new HashSet<>();
this.entities.forEach(entityNode->{
List<MetaRelationship> parentRelation= entityNode.getParentEntitys();
List<MetaRelationship> subRelation= entityNode.getSubEntitys();
if(!ObjectUtils.isEmpty(parentRelation)){
addToRelations(relations,parentRelation);
}
if(!ObjectUtils.isEmpty(subRelation)){
addToRelations(relations,subRelation);
}
});
return relations;
}
private void addToRelations(Set<MetaRelationship> relations, List<MetaRelationship> entityRelations){
entityRelations.forEach(entityRelation->{
entityRelation.setEntityId(DigestUtils.md5DigestAsHex(String.format("%s||%s" ,systemid,entityRelation.getEntityName()).getBytes()));
entityRelation.setRefEntityId(DigestUtils.md5DigestAsHex(String.format("%s||%s" ,systemid,entityRelation.getRefEntityName()).getBytes()));
});
relations.addAll(entityRelations);
}
// private List<EntityModel> entities;
//
// /**
// * 获取实体
// * @return
// */
// public Set<MetaEntity> getEntity(){
// Set<MetaEntity> entities=new HashSet<>();
// this.entities.forEach(entity->{
// MetaEntity metaEntity=new MetaEntity();
// metaEntity.setEntityName(entity.getEntityName());
// metaEntity.setCodeName(entity.getCodeName());
// metaEntity.setLogicName(entity.getLogicName());
// metaEntity.setSystemId(entity.getSystemId());
// metaEntity.setSystemName(entity.getSystemId());
// metaEntity.setTableName(entity.getTableName());
// entities.add(metaEntity);
// }
// );
// return entities;
// }
//
// /**
// * 获取实体属性
// * @return
// */
// public Set<MetaField> getField(){
// Set<MetaField> fields=new HashSet<>();
// this.entities.forEach(entity->{
// entity.getFields().forEach(fieldModel->{
// MetaField metaField=new MetaField();
// metaField.setCodeName(fieldModel.getCodeName());
// metaField.setFieldName(fieldModel.getColumnName());
// metaField.setFieldLogicName(fieldModel.getComment());
// metaField.setFieldShowName(fieldModel.getShowName());
// metaField.setEntityId(DigestUtils.md5DigestAsHex(String.format("%s||%s" ,systemid,entity.getEntityName()).getBytes()));
// fields.add(metaField);
// }
// );
// }
// );
// return fields;
// }
//
// /**
// * 获取实体关系
// * @return
// */
// public Set<MetaRelationship> getRelation(){
// Set<MetaRelationship> relations=new HashSet<>();
// this.entities.forEach(entity->{
// entity.getNesteds().forEach(relation->{
// MetaRelationship metaRelationship=new MetaRelationship();
//// metaRelationship.setName();
// metaRelationship.setCodeName(relation.getCodeName());
// metaRelationship.setEntityId(DigestUtils.md5DigestAsHex(String.format("%s||%s" ,systemid,relation.getEntityName()).getBytes()));
// metaRelationship.setEntityName(relation.getEntityName());
//// metaRelationship.setRefEntityName();
// metaRelationship.setRefEntityId(DigestUtils.md5DigestAsHex(String.format("%s||%s" ,systemid,relation.getEntityName()).getBytes()));
// }
// );
// }
// );
// return relations;
// }
}
......@@ -8,6 +8,8 @@ import java.util.Map;
import java.util.HashMap;
import java.io.Serializable;
import java.math.BigDecimal;
import cn.ibizlab.core.lite.extensions.domain.SysModel;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
......@@ -52,7 +54,7 @@ public class DstSystemDTO extends DTOBase implements Serializable {
@JSONField(name = "sysstructure")
@JsonProperty("sysstructure")
@Size(min = 0, max = 1048576, message = "内容长度必须小于等于[1048576]")
private String sysstructure;
private SysModel sysstructure;
/**
* 属性 [MD5CHECK]
......@@ -83,7 +85,7 @@ public class DstSystemDTO extends DTOBase implements Serializable {
/**
* 设置 [SYSSTRUCTURE]
*/
public void setSysstructure(String sysstructure){
public void setSysstructure(SysModel sysstructure){
this.sysstructure = sysstructure ;
this.modify("sysstructure",sysstructure);
}
......
......@@ -47,6 +47,10 @@ public class DstSystemResource {
@Lazy
public DstSystemMapping dstsystemMapping;
@Autowired
@Lazy
IDstSystemService dstSystem;
@PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzlite-DstSystem-Create-all')")
@ApiOperation(value = "新建系统", tags = {"系统" }, notes = "新建系统")
@RequestMapping(method = RequestMethod.POST, value = "/dstsystems")
......@@ -120,13 +124,19 @@ public class DstSystemResource {
return ResponseEntity.status(HttpStatus.OK).body(dstsystemService.checkKey(dstsystemMapping.toDomain(dstsystemdto)));
}
@PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzlite-DstSystem-Save-all')")
// @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzlite-DstSystem-Save-all')")
@ApiOperation(value = "保存系统", tags = {"系统" }, notes = "保存系统")
@RequestMapping(method = RequestMethod.POST, value = "/dstsystems/save")
@RequestMapping(method = RequestMethod.POST, value = "/dstsystems/save")
public ResponseEntity<Boolean> save(@RequestBody DstSystemDTO dstsystemdto) {
DstSystem system = dstSystem.getById(dstsystemdto.getPssystemid());
if( system!=null && !StringUtils.isEmpty(system.getMd5check()) && system.getMd5check().equals(dstsystemdto.getMd5check())){
log.warn(String.format("[%s]系统资源没有变化,忽略本次同步请求:",dstsystemdto.getPssystemid()));
return ResponseEntity.status(HttpStatus.OK).body(true);
}
return ResponseEntity.status(HttpStatus.OK).body(dstsystemService.save(dstsystemMapping.toDomain(dstsystemdto)));
}
@PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','ibzlite-DstSystem-Save-all')")
@ApiOperation(value = "批量保存系统", tags = {"系统" }, notes = "批量保存系统")
@RequestMapping(method = RequestMethod.POST, value = "/dstsystems/savebatch")
......
......@@ -92,6 +92,8 @@ ribbon:
ibiz:
enablePermissionValid: true
cacheLevel: L1 #(L1)一级本地caffeine缓存;(L2)caffeine缓存+Redis缓存
auth:
excludesPattern: /dstsystems/save
### jobs
jobs:
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册