1、表关联,字段之间连接。
This commit is contained in:
parent
647815da80
commit
ae6b9a2dd7
|
@ -96,7 +96,8 @@ public class MdmServiceImpl implements IMdmService {
|
|||
if ("typeOptionRuleForm".equals(filedRule.getFormName()) && "service".equals(filedRule.getRuleCode())) {
|
||||
System.out.println(filedRule.getRuleValue());
|
||||
//根据db_name查询字段
|
||||
queryFiledsByDbname(dbEntity, filedRule);
|
||||
// queryFiledsByDbname(dbEntity, filedRule);
|
||||
queryFiledssByDbname(dbEntity, filedRule);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -105,6 +106,56 @@ public class MdmServiceImpl implements IMdmService {
|
|||
return mdmModuleDbEntityList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字段规则挂在字段上,不重新封装
|
||||
*/
|
||||
public void queryFiledssByDbname(MdmModuleDbFiledsEntity dbfiledEntity, MdmModuleDbFiledsRuleEntity filedRule){
|
||||
if (i >= 5) {
|
||||
Assert.state(false, "字段:{},关联层数超过5层,请查询是否存在死循环嵌套", dbfiledEntity.getChName());
|
||||
}
|
||||
i++;
|
||||
//查询表,再查询字段
|
||||
MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
|
||||
mdmModuleDbEntity.setDbName(filedRule.getRuleValue());
|
||||
List<MdmModuleDbEntity> mdmModuleDbEntityList = mdmModuleDbDao.query(mdmModuleDbEntity);
|
||||
if (mdmModuleDbEntityList.size() == 0) {
|
||||
Assert.state(false, "查询表:{}。失败", filedRule.getRuleValue());
|
||||
}
|
||||
dbfiledEntity.setMdmModuleDbEntity(mdmModuleDbEntityList.get(0));
|
||||
|
||||
//查询字段
|
||||
MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity = new MdmModuleDbFiledsEntity();
|
||||
mdmModuleDbFiledsEntity.setDbId(mdmModuleDbEntityList.get(0).getId());
|
||||
List<MdmModuleDbFiledsEntity> filedList = mdmModuleDbFiledsDao.query(mdmModuleDbFiledsEntity);
|
||||
|
||||
//过滤viewType1
|
||||
List<MdmModuleDbFiledsEntity> filedType1 = filedList.stream().filter(dbField -> "1".equals(dbField.getViewType())).collect(Collectors.toList());
|
||||
mdmModuleDbEntityList.get(0).setSublistMdmModuleDbFileds(filedType1);
|
||||
dbfiledEntity.setSublistMdmModuleDbFileds(filedType1);
|
||||
|
||||
//查询rule
|
||||
for (MdmModuleDbFiledsEntity dbFiledsEntity : filedType1) {
|
||||
MdmModuleDbFiledsRuleEntity ruleEntity = new MdmModuleDbFiledsRuleEntity();
|
||||
ruleEntity.setMdmId(dbFiledsEntity.getMdmId());
|
||||
ruleEntity.setFiledId(dbFiledsEntity.getId());
|
||||
List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRuleEntities = mdmModuleDbFiledsRuleDao.queryBase(ruleEntity);
|
||||
dbFiledsEntity.setMdmModuleDbFiledsRules(mdmModuleDbFiledsRuleEntities);
|
||||
}
|
||||
//在再判断filedType1中的rule是否有form_name='typeOptionRuleForm' rule_code='service'
|
||||
for (MdmModuleDbFiledsEntity dbFiledEntity : filedType1) {
|
||||
for (MdmModuleDbFiledsRuleEntity mdmModuleDbFiledsRule : dbFiledEntity.getMdmModuleDbFiledsRules()) {
|
||||
if ("typeOptionRuleForm".equals(mdmModuleDbFiledsRule.getFormName()) && "service".equals(mdmModuleDbFiledsRule.getRuleCode())) {
|
||||
System.out.println(mdmModuleDbFiledsRule);
|
||||
queryFiledssByDbname(dbFiledEntity, mdmModuleDbFiledsRule);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据db_name查询字段,注意循环嵌套
|
||||
* 根据rule form_name='typeOptionRuleForm' rule_code='service'
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
package com.hzya.frame.voucher.ae.comf.template.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.hzya.frame.mdm.mdmModule.dao.IMdmModuleDao;
|
||||
import com.hzya.frame.mdm.mdmModule.entity.MdmModuleEntity;
|
||||
import com.hzya.frame.mdm.mdmModule.service.IMdmModuleService;
|
||||
import com.hzya.frame.mdm.mdmModuleDb.dao.IMdmModuleDbDao;
|
||||
import com.hzya.frame.mdm.mdmModuleDb.entity.MdmModuleDbEntity;
|
||||
import com.hzya.frame.mdm.mdmModuleDbFileds.dao.IMdmModuleDbFiledsDao;
|
||||
import com.hzya.frame.mdm.mdmModuleDbFileds.entity.MdmModuleDbFiledsEntity;
|
||||
import com.hzya.frame.mdm.mdmModuleDbFileds.service.IMdmModuleDbFiledsService;
|
||||
import com.hzya.frame.mdm.mdmModuleDbFiledsRule.dao.IMdmModuleDbFiledsRuleDao;
|
||||
import com.hzya.frame.mdm.mdmModuleDbFiledsRule.entity.MdmModuleDbFiledsRuleEntity;
|
||||
import com.hzya.frame.voucher.ae.comf.subject.dao.IAeConfSubjectClassificationDao;
|
||||
|
@ -25,8 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import com.hzya.frame.basedao.service.impl.BaseService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
/**
|
||||
* (AeConfVoucherTemplate)表服务实现类
|
||||
|
@ -43,8 +38,6 @@ public class AeConfVoucherTemplateServiceImpl extends BaseService<AeConfVoucherT
|
|||
@Autowired
|
||||
private IAeConfSubjectClassificationDao subjectClassificationDao;
|
||||
@Autowired
|
||||
private IMdmModuleDao mdmModuleDao;
|
||||
@Autowired
|
||||
private IMdmModuleDbDao mdmModuleDbDao;
|
||||
@Autowired
|
||||
private IMdmModuleDbFiledsDao mdmModuleDbFiledsDao;
|
||||
|
@ -166,86 +159,207 @@ public class AeConfVoucherTemplateServiceImpl extends BaseService<AeConfVoucherT
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkAbstract(AeConfVoucherTemplateEntity entity) {
|
||||
String abstractRes = entity.getAbstractRes();
|
||||
|
||||
// 校验基本格式
|
||||
if (abstractRes.contains("++") || abstractRes.startsWith("+") || abstractRes.endsWith("+")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String[] parts = abstractRes.split("\\+");
|
||||
for (String part : parts) {
|
||||
if (part.startsWith("@@$")) {
|
||||
String fieldPath = part.substring(3); // 去除 @@$
|
||||
if (!isValidFieldPath(entity.getMdmId(), fieldPath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证字段路径是否有效(支持任意深度)
|
||||
*/
|
||||
private boolean isValidFieldPath(String mdmId, String fieldPath) {
|
||||
String[] pathParts = fieldPath.split("\\.");
|
||||
MdmModuleDbEntity currentDb = queryDb(mdmId, pathParts[0]);
|
||||
if (currentDb == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 1; i < pathParts.length; i++) {
|
||||
String fieldName = pathParts[i];
|
||||
|
||||
// 查询当前表中的字段
|
||||
MdmModuleDbFiledsEntity field = queryFileds(currentDb.getId(), fieldName);
|
||||
if (field == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 如果不是最后一个字段,继续查找关联表
|
||||
if (i < pathParts.length - 1) {
|
||||
currentDb = queryFiledRelevanceDb(field);
|
||||
if (currentDb == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// * 校验摘要,并拿到最终字符串
|
||||
// */
|
||||
// @Override
|
||||
// public boolean checkAbstract(AeConfVoucherTemplateEntity entity) {
|
||||
// boolean flag = false;
|
||||
// boolean flag = true;
|
||||
// String abstractRes = entity.getAbstractRes();
|
||||
// if (abstractRes.contains("++") || abstractRes.startsWith("+") || abstractRes.endsWith("+")) {
|
||||
// flag = false;
|
||||
// return flag;
|
||||
// }
|
||||
// String[] split = abstractRes.split("\\+");
|
||||
// System.out.println(split);
|
||||
// for (String str : split) {
|
||||
// if (str.startsWith("@@$")) {//单据字段
|
||||
// // 使用正则表达式匹配 @@$对象名.字段名
|
||||
// Pattern pattern = Pattern.compile("@@\\$(.*?)\\.(.*)");
|
||||
// Matcher matcher = pattern.matcher(str);
|
||||
// if (matcher.find()) {
|
||||
// String objectName = matcher.group(1); // 对象名:"销售订单明细"
|
||||
// String fieldName = matcher.group(2); // 字段名:"原币-原始单据业务发生币种"
|
||||
//
|
||||
// System.out.println("对象名: " + objectName);
|
||||
// System.out.println("字段名: " + fieldName);
|
||||
// } else {
|
||||
// return flag;
|
||||
// String substring = str.substring(3, str.length());
|
||||
// String[] subSplit = substring.split("\\.");
|
||||
// int length = subSplit.length;
|
||||
// switch (length) {
|
||||
// case 1://表名
|
||||
// flag = false;
|
||||
// break;
|
||||
// case 2://表名.字段
|
||||
// MdmModuleDbEntity mdmModuleDbEntity2 = queryDb(entity.getMdmId(), subSplit[0]);
|
||||
// if (mdmModuleDbEntity2 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取db_id
|
||||
// String dbId2 = mdmModuleDbEntity2.getId();
|
||||
// MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity2 = queryFileds(dbId2, subSplit[1]);
|
||||
// if (mdmModuleDbFiledsEntity2 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// break;
|
||||
// case 3://表名.字段.字段,需要查询倒数第二次字段关联的表
|
||||
// MdmModuleDbEntity mdmModuleDbEntity3 = queryDb(entity.getMdmId(), subSplit[0]);
|
||||
// if (mdmModuleDbEntity3 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取db_id
|
||||
// String dbId3 = mdmModuleDbEntity3.getId();
|
||||
// MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity3 = queryFileds(dbId3, subSplit[1]);
|
||||
// if (mdmModuleDbFiledsEntity3 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取关联表
|
||||
// MdmModuleDbEntity mdmModuleDbEntity31 = queryFiledRelevanceDb(mdmModuleDbFiledsEntity3);
|
||||
// if(mdmModuleDbEntity31==null){
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取db_id31
|
||||
// String dbId31 = mdmModuleDbEntity31.getId();
|
||||
// MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity31 = queryFileds(dbId31, subSplit[2]);
|
||||
// if (mdmModuleDbFiledsEntity31 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// break;
|
||||
// case 4://表名.字段.字段.字段
|
||||
// MdmModuleDbEntity mdmModuleDbEntity4 = queryDb(entity.getMdmId(), subSplit[0]);
|
||||
// if (mdmModuleDbEntity4 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取db_id
|
||||
// String dbId4 = mdmModuleDbEntity4.getId();
|
||||
// MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity4 = queryFileds(dbId4, subSplit[1]);
|
||||
// if (mdmModuleDbFiledsEntity4 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取关联表
|
||||
// MdmModuleDbEntity mdmModuleDbEntity41 = queryFiledRelevanceDb(mdmModuleDbFiledsEntity4);
|
||||
// if(mdmModuleDbEntity41==null){
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取db_id41
|
||||
// String dbId41 = mdmModuleDbEntity41.getId();
|
||||
// MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity41 = queryFileds(dbId41, subSplit[2]);
|
||||
// if (mdmModuleDbFiledsEntity41 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取关联表
|
||||
// MdmModuleDbEntity mdmModuleDbEntity42 = queryFiledRelevanceDb(mdmModuleDbFiledsEntity41);
|
||||
// if(mdmModuleDbEntity42==null){
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取db_id41
|
||||
// String dbId42 = mdmModuleDbEntity42.getId();
|
||||
// MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity42 = queryFileds(dbId42, subSplit[3]);
|
||||
// if (mdmModuleDbFiledsEntity42 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// break;
|
||||
// case 5://表名.字段.字段.字段.字段
|
||||
// MdmModuleDbEntity mdmModuleDbEntity5 = queryDb(entity.getMdmId(), subSplit[0]);
|
||||
// if (mdmModuleDbEntity5 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取db_id
|
||||
// String dbId5 = mdmModuleDbEntity5.getId();
|
||||
// MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity5 = queryFileds(dbId5, subSplit[1]);
|
||||
// if (mdmModuleDbFiledsEntity5 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取关联表
|
||||
// MdmModuleDbEntity mdmModuleDbEntity51 = queryFiledRelevanceDb(mdmModuleDbFiledsEntity5);
|
||||
// if(mdmModuleDbEntity51==null){
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取db_id51
|
||||
// String dbId51 = mdmModuleDbEntity51.getId();
|
||||
// MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity51 = queryFileds(dbId51, subSplit[2]);
|
||||
// if (mdmModuleDbFiledsEntity51 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取关联表
|
||||
// MdmModuleDbEntity mdmModuleDbEntity52 = queryFiledRelevanceDb(mdmModuleDbFiledsEntity51);
|
||||
// if(mdmModuleDbEntity52==null){
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取db_id52
|
||||
// String dbId52 = mdmModuleDbEntity52.getId();
|
||||
// MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity52 = queryFileds(dbId52, subSplit[3]);
|
||||
// if (mdmModuleDbFiledsEntity52 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取关联表
|
||||
// MdmModuleDbEntity mdmModuleDbEntity53 = queryFiledRelevanceDb(mdmModuleDbFiledsEntity52);
|
||||
// if(mdmModuleDbEntity53==null){
|
||||
// flag = false;
|
||||
// }
|
||||
// //获取db_id53
|
||||
// String dbId53 = mdmModuleDbEntity53.getId();
|
||||
// MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity53 = queryFileds(dbId53, subSplit[4]);
|
||||
// if (mdmModuleDbFiledsEntity53 == null) {
|
||||
// flag = false;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// return flag;
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public boolean checkAbstract(AeConfVoucherTemplateEntity entity) {
|
||||
boolean flag = true;
|
||||
String abstractRes = entity.getAbstractRes();
|
||||
String[] split = abstractRes.split("\\+");
|
||||
System.out.println(split);
|
||||
for (String str : split) {
|
||||
if (str.startsWith("@@$")) {//单据字段
|
||||
// 使用正则表达式匹配 @@$对象名.字段名
|
||||
String substring = str.substring(3, str.length());
|
||||
String[] subSplit = substring.split("\\.");
|
||||
int length = subSplit.length;
|
||||
switch (length) {
|
||||
case 1://表名
|
||||
flag = false;
|
||||
break;
|
||||
case 2://表名.字段
|
||||
MdmModuleDbEntity mdmModuleDbEntity2 = queryDb(entity.getMdmId(), subSplit[0]);
|
||||
if (mdmModuleDbEntity2 == null) {
|
||||
flag = false;
|
||||
}
|
||||
//获取db_id
|
||||
String dbId2 = mdmModuleDbEntity2.getId();
|
||||
MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity2 = queryFileds(dbId2, subSplit[1]);
|
||||
if (mdmModuleDbFiledsEntity2 == null) {
|
||||
flag = false;
|
||||
}
|
||||
System.out.println(2);
|
||||
break;
|
||||
case 3://表名.字段.字段,需要查询倒数第二次字段关联的表
|
||||
MdmModuleDbEntity mdmModuleDbEntity3 = queryDb(entity.getMdmId(), subSplit[0]);
|
||||
if (mdmModuleDbEntity3 == null) {
|
||||
flag = false;
|
||||
}
|
||||
//获取db_id
|
||||
String dbId3 = mdmModuleDbEntity3.getId();
|
||||
MdmModuleDbFiledsEntity mdmModuleDbFiledsEntity3 = queryFileds(dbId3, subSplit[1]);
|
||||
if (mdmModuleDbFiledsEntity3 == null) {
|
||||
flag = false;
|
||||
}
|
||||
//获取关联表
|
||||
System.out.println(3);
|
||||
break;
|
||||
case 4://表名.字段.字段.字段
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据表
|
||||
*/
|
||||
|
@ -278,13 +392,23 @@ public class AeConfVoucherTemplateServiceImpl extends BaseService<AeConfVoucherT
|
|||
/**
|
||||
* 查找字段关联表
|
||||
*/
|
||||
public MdmModuleDbFiledsEntity queryFiledRelevanceDb(MdmModuleDbFiledsEntity filedsEntity) {
|
||||
public MdmModuleDbEntity queryFiledRelevanceDb(MdmModuleDbFiledsEntity filedsEntity) {
|
||||
//查询字段的rules
|
||||
MdmModuleDbFiledsRuleEntity mdmModuleDbFiledsRuleEntity = new MdmModuleDbFiledsRuleEntity();
|
||||
mdmModuleDbFiledsRuleEntity.setFiledId(filedsEntity.getId());
|
||||
List<MdmModuleDbFiledsRuleEntity> ruleList = mdmModuleDbFiledsRuleDao.query(mdmModuleDbFiledsRuleEntity);
|
||||
|
||||
|
||||
for (MdmModuleDbFiledsRuleEntity filedRule : ruleList) {
|
||||
if ("typeOptionRuleForm".equals(filedRule.getFormName()) && "service".equals(filedRule.getRuleCode())) {
|
||||
String ruleValue = filedRule.getRuleValue();
|
||||
MdmModuleDbEntity mdmModuleDbEntity = new MdmModuleDbEntity();
|
||||
mdmModuleDbEntity.setDbName(ruleValue);
|
||||
List<MdmModuleDbEntity> dbList = mdmModuleDbDao.query(mdmModuleDbEntity);
|
||||
if(dbList.size()==0||dbList.size()>1){
|
||||
return null;
|
||||
}
|
||||
return dbList.get(0);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue