|
@@ -20,6 +20,7 @@ import org.springblade.core.tool.constant.BladeConstant;
|
|
import org.springblade.core.tool.utils.DateUtil;
|
|
import org.springblade.core.tool.utils.DateUtil;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.StringPool;
|
|
import org.springblade.core.tool.utils.StringPool;
|
|
|
|
+import org.springblade.core.tool.utils.StringUtil;
|
|
import org.springblade.manager.dto.FormElementDTO;
|
|
import org.springblade.manager.dto.FormElementDTO;
|
|
import org.springblade.manager.dto.FormElementDTO2;
|
|
import org.springblade.manager.dto.FormElementDTO2;
|
|
import org.springblade.manager.dto.WbsFormElementDTO2;
|
|
import org.springblade.manager.dto.WbsFormElementDTO2;
|
|
@@ -392,19 +393,19 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
List<WbsTabRelationExcelTab> WbsTabRelationExcelTabs = baseMapper.selectWbsTabRelationExcelTab(null, String.valueOf(formElementDTO.getExcelTabId()));
|
|
List<WbsTabRelationExcelTab> WbsTabRelationExcelTabs = baseMapper.selectWbsTabRelationExcelTab(null, String.valueOf(formElementDTO.getExcelTabId()));
|
|
List<Long> tableIds = WbsTabRelationExcelTabs.stream().map(WbsTabRelationExcelTab::getWbsTabId).collect(Collectors.toList());
|
|
List<Long> tableIds = WbsTabRelationExcelTabs.stream().map(WbsTabRelationExcelTab::getWbsTabId).collect(Collectors.toList());
|
|
if (tableIds.size() == 0) {
|
|
if (tableIds.size() == 0) {
|
|
- throw new ServiceException("当前清表未关联元素表");
|
|
|
|
|
|
+ throw new ServiceException("未查询到当前清表所关联的元素表信息");
|
|
}
|
|
}
|
|
|
|
|
|
for (Long tableId : tableIds) {
|
|
for (Long tableId : tableIds) {
|
|
- //获取当前元素表与清表关系信息
|
|
|
|
- List<WbsTabRelationExcelTab> list = baseMapper.selectWbsTabRelationExcelTab(String.valueOf(tableId), String.valueOf(formElementDTO.getExcelTabId()));
|
|
|
|
- if (list.size() <= 0) {
|
|
|
|
- //新增当前元素表与清表关系信息
|
|
|
|
- baseMapper.insertWbsTabRelationExcelTab(SnowFlakeUtil.getId(), formElementDTO.getExcelTabId(), tableId);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //获取当前表信息
|
|
|
|
|
|
+ //获取当前wbs节点元素表信息
|
|
WbsTree wbsTree = wbsTreeMapper.selectOne(Wrappers.<WbsTree>query().lambda().eq(WbsTree::getId, tableId));
|
|
WbsTree wbsTree = wbsTreeMapper.selectOne(Wrappers.<WbsTree>query().lambda().eq(WbsTree::getId, tableId));
|
|
|
|
+ //查询实体表是否存在
|
|
|
|
+ Object obj = baseMapper.showShowTabLike(wbsTree);
|
|
|
|
+ if (obj == null) {
|
|
|
|
+ //不存在对应实体表的元素表不新增同步元素字段
|
|
|
|
+ continue;
|
|
|
|
+ //throw new ServiceException(StringUtil.format("未获取到 {} 对应实体表信息,同步失败",wbsTree.getDeptName()));
|
|
|
|
+ }
|
|
|
|
|
|
//获取表单下的元素信息
|
|
//获取表单下的元素信息
|
|
List<WbsFormElement> wbsFormElements = baseMapper.selectList(Wrappers.<WbsFormElement>query().lambda()
|
|
List<WbsFormElement> wbsFormElements = baseMapper.selectList(Wrappers.<WbsFormElement>query().lambda()
|
|
@@ -419,11 +420,9 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
|
|
|
//初始化eKey字段
|
|
//初始化eKey字段
|
|
int keyNumber = Integer.parseInt(firstWbsFormElement.getEKey().split("_")[1]);
|
|
int keyNumber = Integer.parseInt(firstWbsFormElement.getEKey().split("_")[1]);
|
|
- final int[] keyNumber1 = {1};
|
|
|
|
-
|
|
|
|
- newList.stream().forEach(wbsFormElementInfo -> {
|
|
|
|
- String key = "key_" + (keyNumber + keyNumber1[0]);
|
|
|
|
-
|
|
|
|
|
|
+ int newKeyNumber = keyNumber + 1;
|
|
|
|
+ for (WbsFormElement wbsFormElementInfo : newList) {
|
|
|
|
+ String key = "key_" + (newKeyNumber);
|
|
//新增元素到当前表中
|
|
//新增元素到当前表中
|
|
wbsFormElementInfo.setEKey(key);
|
|
wbsFormElementInfo.setEKey(key);
|
|
wbsFormElementInfo.setId(SnowFlakeUtil.getId());
|
|
wbsFormElementInfo.setId(SnowFlakeUtil.getId());
|
|
@@ -436,23 +435,21 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
String eTypeFiled = getInitTableFiledType(wbsFormElementInfo.getEType());
|
|
String eTypeFiled = getInitTableFiledType(wbsFormElementInfo.getEType());
|
|
int eLengthFiled = Integer.parseInt(setDefaultElementLength(wbsFormElementInfo.getEType()));
|
|
int eLengthFiled = Integer.parseInt(setDefaultElementLength(wbsFormElementInfo.getEType()));
|
|
|
|
|
|
- /*if (wbsFormElementInfo.getEType() == 1 && wbsFormElementInfo.getELength() > 255) {
|
|
|
|
- //转为text类型
|
|
|
|
- eTypeFiled = "text";
|
|
|
|
- eLengthFiled = 0;
|
|
|
|
- }*/
|
|
|
|
-
|
|
|
|
- //追加字段到实体表中
|
|
|
|
- try {
|
|
|
|
|
|
+ //判断是否存在该Key字段
|
|
|
|
+ int row1 = wbsTreeMapper.isThereAField(wbsTree.getInitTableName(), key);
|
|
|
|
+ if (row1 == 0) {
|
|
|
|
+ //追加字段到实体表中
|
|
wbsTreeMapper.alterTableFiled(wbsTree.getInitTableName(), key, eTypeFiled, eLengthFiled);
|
|
wbsTreeMapper.alterTableFiled(wbsTree.getInitTableName(), key, eTypeFiled, eLengthFiled);
|
|
- }catch (Exception e){
|
|
|
|
- //删除元素
|
|
|
|
- baseMapper.deleteElementByfId2(wbsFormElementInfo.getId());
|
|
|
|
- throw new ServiceException("实体表字段同步异常,操作失败");
|
|
|
|
|
|
+ //判断是否追加成功
|
|
|
|
+ int row2 = wbsTreeMapper.isThereAField(wbsTree.getInitTableName(), key);
|
|
|
|
+ if (row2 != 1) {
|
|
|
|
+ //追加失败,删除元素,跳过
|
|
|
|
+ baseMapper.deleteElementByfId2(wbsFormElementInfo.getId());
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
- keyNumber1[0]++;
|
|
|
|
- });
|
|
|
|
|
|
+ newKeyNumber++;
|
|
|
|
+ }
|
|
|
|
|
|
//修改关联信息
|
|
//修改关联信息
|
|
wbsTree.setIsLinkTable(2);
|
|
wbsTree.setIsLinkTable(2);
|
|
@@ -466,83 +463,69 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public boolean saveRelation(FormElementDTO2 formElementDTO) {
|
|
public boolean saveRelation(FormElementDTO2 formElementDTO) {
|
|
- List<Long> elementIds = new ArrayList<>();
|
|
|
|
- try {
|
|
|
|
- //获取当前表信息
|
|
|
|
- WbsTree wbsTree = wbsTreeMapper.selectOne(Wrappers.<WbsTree>query().lambda().eq(WbsTree::getId, formElementDTO.getId()));
|
|
|
|
-
|
|
|
|
- //查询实体表是否存在
|
|
|
|
- Object obj = baseMapper.showShowTabLike(wbsTree);
|
|
|
|
- if (obj == null) {
|
|
|
|
- throw new ServiceException("未获取到对应实体表信息,关联失败");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //获取当前元素表与清表关系信息
|
|
|
|
- List<WbsTabRelationExcelTab> list = baseMapper.selectWbsTabRelationExcelTab(String.valueOf(formElementDTO.getId()), String.valueOf(formElementDTO.getExcelTabId()));
|
|
|
|
- if (list.size() <= 0) {
|
|
|
|
- //新增当前元素表与清表关系信息
|
|
|
|
- baseMapper.insertWbsTabRelationExcelTab(SnowFlakeUtil.getId(), formElementDTO.getExcelTabId(), formElementDTO.getId());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //获取表单下的元素信息
|
|
|
|
- List<WbsFormElement> wbsFormElements = baseMapper.selectList(Wrappers.<WbsFormElement>query().lambda()
|
|
|
|
- .eq(WbsFormElement::getFId, formElementDTO.getId()));
|
|
|
|
- Collections.reverse(wbsFormElements);
|
|
|
|
- WbsFormElement firstWbsFormElement = wbsFormElements.stream().findFirst().orElse(wbsFormElements.get(wbsFormElements.size() - 1));
|
|
|
|
-
|
|
|
|
- //去重,元素表中名称已存在的元素不添加
|
|
|
|
- List<WbsFormElement> newList = formElementDTO.getElementList().stream().filter(a ->
|
|
|
|
- !wbsFormElements.stream().map(WbsFormElement::getEName).collect(Collectors.toList()).contains(a.getEName())
|
|
|
|
- ).collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- //初始化eKey字段
|
|
|
|
- int keyNumber = Integer.parseInt(firstWbsFormElement.getEKey().split("_")[1]);
|
|
|
|
- final int[] keyNumber1 = {1};
|
|
|
|
-
|
|
|
|
- newList.stream().forEach(wbsFormElementInfo -> {
|
|
|
|
- String key = "key_" + (keyNumber + keyNumber1[0]);
|
|
|
|
-
|
|
|
|
- //新增元素到当前表中
|
|
|
|
- wbsFormElementInfo.setEKey(key);
|
|
|
|
- wbsFormElementInfo.setId(SnowFlakeUtil.getId());
|
|
|
|
- wbsFormElementInfo.setFId(String.valueOf(formElementDTO.getId()));
|
|
|
|
- wbsFormElementInfo.setStatus(1);
|
|
|
|
- wbsFormElementInfo.setIsDeleted(0);
|
|
|
|
- wbsFormElementInfo.setELength(Integer.parseInt(setDefaultElementLength(wbsFormElementInfo.getEType())));
|
|
|
|
-
|
|
|
|
- baseMapper.insert(wbsFormElementInfo);
|
|
|
|
- elementIds.add(wbsFormElementInfo.getId());
|
|
|
|
-
|
|
|
|
- String eTypeFiled = getInitTableFiledType(wbsFormElementInfo.getEType());
|
|
|
|
- int eLengthFiled = Integer.parseInt(setDefaultElementLength(wbsFormElementInfo.getEType()));
|
|
|
|
|
|
+ //获取当前表信息
|
|
|
|
+ WbsTree wbsTree = wbsTreeMapper.selectOne(Wrappers.<WbsTree>query().lambda().eq(WbsTree::getId, formElementDTO.getId()));
|
|
|
|
+ //查询实体表是否存在
|
|
|
|
+ Object obj = baseMapper.showShowTabLike(wbsTree);
|
|
|
|
+ if (obj == null) {
|
|
|
|
+ throw new ServiceException(StringUtil.format("未获取到 {} 对应实体表信息,关联失败", wbsTree.getDeptName()));
|
|
|
|
+ }
|
|
|
|
|
|
- /*if (wbsFormElementInfo.getEType() == 1 && wbsFormElementInfo.getELength() > 255) {
|
|
|
|
- //转为text类型
|
|
|
|
- eTypeFiled = "text";
|
|
|
|
- eLengthFiled = 0;
|
|
|
|
- }*/
|
|
|
|
|
|
+ //获取当前元素表与清表关系信息
|
|
|
|
+ List<WbsTabRelationExcelTab> list = baseMapper.selectWbsTabRelationExcelTab(String.valueOf(formElementDTO.getId()), String.valueOf(formElementDTO.getExcelTabId()));
|
|
|
|
+ if (list.size() <= 0) {
|
|
|
|
+ //新增当前元素表与清表关系信息
|
|
|
|
+ baseMapper.insertWbsTabRelationExcelTab(SnowFlakeUtil.getId(), formElementDTO.getExcelTabId(), formElementDTO.getId());
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ //获取表单下的元素信息
|
|
|
|
+ List<WbsFormElement> wbsFormElements = baseMapper.selectList(Wrappers.<WbsFormElement>query().lambda()
|
|
|
|
+ .eq(WbsFormElement::getFId, formElementDTO.getId()));
|
|
|
|
+ Collections.reverse(wbsFormElements);
|
|
|
|
+ WbsFormElement firstWbsFormElement = wbsFormElements.stream().findFirst().orElse(wbsFormElements.get(wbsFormElements.size() - 1));
|
|
|
|
+
|
|
|
|
+ //去重,元素表中名称已存在的元素不添加
|
|
|
|
+ List<WbsFormElement> newList = formElementDTO.getElementList().stream().filter(a ->
|
|
|
|
+ !wbsFormElements.stream().map(WbsFormElement::getEName).collect(Collectors.toList()).contains(a.getEName())
|
|
|
|
+ ).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ //初始化eKey字段
|
|
|
|
+ int keyNumber = Integer.parseInt(firstWbsFormElement.getEKey().split("_")[1]);
|
|
|
|
+ int newKeyNumber = keyNumber + 1;
|
|
|
|
+ for (WbsFormElement wbsFormElementInfo : newList) {
|
|
|
|
+ String key = "key_" + (newKeyNumber);
|
|
|
|
+ //新增元素到当前表中
|
|
|
|
+ wbsFormElementInfo.setEKey(key);
|
|
|
|
+ wbsFormElementInfo.setId(SnowFlakeUtil.getId());
|
|
|
|
+ wbsFormElementInfo.setFId(String.valueOf(formElementDTO.getId()));
|
|
|
|
+ wbsFormElementInfo.setStatus(1);
|
|
|
|
+ wbsFormElementInfo.setELength(Integer.parseInt(setDefaultElementLength(wbsFormElementInfo.getEType())));
|
|
|
|
+
|
|
|
|
+ baseMapper.insert(wbsFormElementInfo);
|
|
|
|
+
|
|
|
|
+ String eTypeFiled = getInitTableFiledType(wbsFormElementInfo.getEType());
|
|
|
|
+ int eLengthFiled = Integer.parseInt(setDefaultElementLength(wbsFormElementInfo.getEType()));
|
|
|
|
+
|
|
|
|
+ //判断是否存在该Key字段
|
|
|
|
+ int row1 = wbsTreeMapper.isThereAField(wbsTree.getInitTableName(), key);
|
|
|
|
+ if (row1 == 0) {
|
|
//追加字段到实体表中
|
|
//追加字段到实体表中
|
|
wbsTreeMapper.alterTableFiled(wbsTree.getInitTableName(), key, eTypeFiled, eLengthFiled);
|
|
wbsTreeMapper.alterTableFiled(wbsTree.getInitTableName(), key, eTypeFiled, eLengthFiled);
|
|
-
|
|
|
|
- keyNumber1[0]++;
|
|
|
|
-
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- //修改关联信息
|
|
|
|
- wbsTree.setIsLinkTable(2);
|
|
|
|
- wbsTreeMapper.updateById(wbsTree);
|
|
|
|
-
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- if (elementIds.size() > 0) {
|
|
|
|
- //删除关联
|
|
|
|
- baseMapper.deleteWbsTabRelationExcelTab(String.valueOf(formElementDTO.getId()), String.valueOf(formElementDTO.getExcelTabId()));
|
|
|
|
- //删除元素
|
|
|
|
- baseMapper.physicalDeleteBatchIds(elementIds);
|
|
|
|
|
|
+ //判断是否追加成功
|
|
|
|
+ int row2 = wbsTreeMapper.isThereAField(wbsTree.getInitTableName(), key);
|
|
|
|
+ if (row2 == 0) {
|
|
|
|
+ //追加失败,删除元素,跳过
|
|
|
|
+ baseMapper.deleteElementByfId2(wbsFormElementInfo.getId());
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- throw new ServiceException("未获取到对应实体表信息,关联失败");
|
|
|
|
|
|
+ newKeyNumber++;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //修改关联信息
|
|
|
|
+ wbsTree.setIsLinkTable(2);
|
|
|
|
+ wbsTreeMapper.updateById(wbsTree);
|
|
|
|
+
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|