|
@@ -40,6 +40,7 @@ import org.springblade.manager.dto.FormElementDTO;
|
|
|
import org.springblade.manager.dto.FormElementDTO2;
|
|
|
import org.springblade.manager.dto.WbsFormElementDTO2;
|
|
|
import org.springblade.manager.entity.WbsFormElement;
|
|
|
+import org.springblade.manager.entity.WbsTabRelationExcelTab;
|
|
|
import org.springblade.manager.entity.WbsTree;
|
|
|
import org.springblade.manager.excel.WbsFormElementBatchExcel;
|
|
|
import org.springblade.manager.excel.WbsFormElementExcel;
|
|
@@ -50,6 +51,7 @@ import org.springblade.manager.service.IWbsFormElementService;
|
|
|
import org.springblade.manager.service.IWbsTreeService;
|
|
|
import org.springblade.manager.vo.WbsFormElementVO;
|
|
|
import org.springblade.manager.vo.WbsFormElementVO2;
|
|
|
+import org.springblade.manager.vo.WbsNodeTableVO;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -376,16 +378,26 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean submitExcelRelationWbsTreeAndElement(FormElementDTO2 formElementDTO) {
|
|
|
//新增元素表、实体表
|
|
|
- if (formElementDTO.getTableIds() == null) {
|
|
|
+ if (formElementDTO.getSubmitStatus() == 2) {
|
|
|
this.saveFormElement(formElementDTO);
|
|
|
|
|
|
- } else {
|
|
|
+ } else if (formElementDTO.getSubmitStatus() == 1) {
|
|
|
//关联-在已有元素表中新增元素,在实体表中追加字段
|
|
|
- List<String> tableIds = formElementDTO.getTableIds();
|
|
|
+ //获取当前清表关联的所有tableIds
|
|
|
+ List<WbsTabRelationExcelTab> WbsTabRelationExcelTabs = baseMapper.selectWbsTabRelationExcelTab(null, String.valueOf(formElementDTO.getExcelTabId()));
|
|
|
+ List<Long> tableIds = WbsTabRelationExcelTabs.stream().map(WbsTabRelationExcelTab::getWbsTabId).collect(Collectors.toList());
|
|
|
if (tableIds.size() == 0) {
|
|
|
- throw new ServiceException("请选择一张元素表进行关联");
|
|
|
+ throw new ServiceException("当前清表未关联元素表");
|
|
|
}
|
|
|
- for (String 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);
|
|
|
+ }
|
|
|
+
|
|
|
//获取当前表信息
|
|
|
WbsTree wbsTree = wbsTreeMapper.selectOne(Wrappers.<WbsTree>query().lambda().eq(WbsTree::getId, tableId));
|
|
|
|
|
@@ -410,7 +422,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
//新增元素到当前表中
|
|
|
wbsFormElementInfo.setEKey(key);
|
|
|
wbsFormElementInfo.setId(SnowFlakeUtil.getId());
|
|
|
- wbsFormElementInfo.setFId(tableId);
|
|
|
+ wbsFormElementInfo.setFId(String.valueOf(tableId));
|
|
|
wbsFormElementInfo.setStatus(1);
|
|
|
wbsFormElementInfo.setELength(Integer.parseInt(setDefaultElementLength(wbsFormElementInfo.getEType())));
|
|
|
|
|
@@ -432,105 +444,128 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean cancelRelation(String id) {
|
|
|
- return wbsTreeMapper.cancelRelation(id);
|
|
|
- }
|
|
|
-
|
|
|
- private boolean saveFormElement(FormElementDTO2 formElementDTO) {
|
|
|
- String deptName = formElementDTO.getDeptName();
|
|
|
- if (deptName.length() > 100 || deptName.length() < 1) {
|
|
|
- throw new ServiceException("表名长度错误,输入范围1-100个字符长度");
|
|
|
- }
|
|
|
- if (formElementDTO.getElementList().size() <= 0) {
|
|
|
- throw new ServiceException("操作失败,请先添加表单元素");
|
|
|
- }
|
|
|
- for (WbsFormElement wbsFormElement : formElementDTO.getElementList()) {
|
|
|
- if (StringUtils.isEmpty(wbsFormElement.getEName()) ||
|
|
|
- StringUtils.isEmpty(String.valueOf(wbsFormElement.getEType()))) {
|
|
|
- throw new ServiceException("操作失败,请完整填写元素名称与类型参数");
|
|
|
+ public boolean saveRelation(FormElementDTO2 formElementDTO) {
|
|
|
+ try {
|
|
|
+ //获取当前元素表与清表关系信息
|
|
|
+ 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());
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //初始化
|
|
|
- Long id = SnowFlakeUtil.getId();
|
|
|
- String newTableName = "m_" + DateUtil.time() + "_" + id;
|
|
|
- formElementDTO.setInitTableName(newTableName);
|
|
|
+ //获取当前表信息
|
|
|
+ WbsTree wbsTree = wbsTreeMapper.selectOne(Wrappers.<WbsTree>query().lambda().eq(WbsTree::getId, formElementDTO.getId()));
|
|
|
|
|
|
- //创建元素表
|
|
|
- boolean b1 = submit2(formElementDTO);
|
|
|
+ //获取表单下的元素信息
|
|
|
+ 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> elementList = formElementDTO.getElementList();
|
|
|
- int i = 1;
|
|
|
- for (WbsFormElement wbsFormElement : elementList) {
|
|
|
- //当前元素表中元素对应实体表唯一key值、fId、元素默认长度
|
|
|
- wbsFormElement.setEKey("key_" + i++);
|
|
|
- wbsFormElement.setId(SnowFlakeUtil.getId());
|
|
|
- wbsFormElement.setFId(String.valueOf(formElementDTO.getId()));
|
|
|
- wbsFormElement.setELength(Integer.valueOf(setDefaultElementLength(wbsFormElement.getEType())));
|
|
|
- }
|
|
|
+ //去重,元素表中名称已存在的元素不添加
|
|
|
+ List<WbsFormElement> newList = formElementDTO.getElementList().stream().filter(a ->
|
|
|
+ !wbsFormElements.stream().map(WbsFormElement::getEName).collect(Collectors.toList()).contains(a.getEName())
|
|
|
+ ).collect(Collectors.toList());
|
|
|
|
|
|
- boolean b2 = this.saveBatch(elementList);
|
|
|
+ //初始化eKey字段
|
|
|
+ int keyNumber = Integer.parseInt(firstWbsFormElement.getEKey().split("_")[1]);
|
|
|
+ final int[] keyNumber1 = {1};
|
|
|
|
|
|
- //找到当前元素表中所有元素
|
|
|
- List<WbsFormElement> list = this.selectElementListByFid(String.valueOf(formElementDTO.getId()));
|
|
|
+ newList.stream().forEach(wbsFormElementInfo -> {
|
|
|
+ String key = "key_" + (keyNumber + keyNumber1[0]);
|
|
|
|
|
|
- //初始化实体表
|
|
|
- Boolean b3 = this.initTable(list, newTableName);
|
|
|
+ //新增元素到当前表中
|
|
|
+ wbsFormElementInfo.setEKey(key);
|
|
|
+ wbsFormElementInfo.setId(SnowFlakeUtil.getId());
|
|
|
+ wbsFormElementInfo.setFId(String.valueOf(formElementDTO.getId()));
|
|
|
+ wbsFormElementInfo.setStatus(1);
|
|
|
+ wbsFormElementInfo.setELength(Integer.parseInt(setDefaultElementLength(wbsFormElementInfo.getEType())));
|
|
|
|
|
|
- if (b1 && b2 && b3) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- throw new ServiceException("操作失败");
|
|
|
- }
|
|
|
+ baseMapper.insert(wbsFormElementInfo);
|
|
|
|
|
|
- }
|
|
|
+ //追加字段到实体表中
|
|
|
+ wbsTreeMapper.alterTableFiled(wbsTree.getInitTableName(), key,
|
|
|
+ getInitTableFiledType(wbsFormElementInfo.getEType()),
|
|
|
+ Integer.valueOf(setDefaultElementLength(wbsFormElementInfo.getEType())));
|
|
|
|
|
|
- private static String getPinyin(String text, String separator) {
|
|
|
- //text 文本, separator 转换后添加的分隔符
|
|
|
- char[] chars = text.toCharArray();
|
|
|
- HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
|
|
|
+ keyNumber1[0]++;
|
|
|
|
|
|
- // 设置大小写
|
|
|
- format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
|
|
|
+ });
|
|
|
|
|
|
- // 设置声调表示方法
|
|
|
- format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
|
|
|
+ //修改关联信息
|
|
|
+ wbsTree.setIsLinkTable(2);
|
|
|
+ wbsTreeMapper.updateById(wbsTree);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ServiceException("关联失败");
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- // 设置字母u表示方法
|
|
|
- format.setVCharType(HanyuPinyinVCharType.WITH_V);
|
|
|
- String[] s;
|
|
|
- String rs = "";
|
|
|
- try {
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- for (int i = 0; i < chars.length; i++) {
|
|
|
- // 判断是否为汉字字符
|
|
|
- if (String.valueOf(chars[i]).matches("[\\u4E00-\\u9FA5]+")) {
|
|
|
- s = PinyinHelper.toHanyuPinyinStringArray(chars[i], format);
|
|
|
- if (s != null) {
|
|
|
- sb.append(s[0]).append(separator);
|
|
|
- continue;
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean saveFormElement(FormElementDTO2 formElementDTO) {
|
|
|
+ //获取新增节点ids
|
|
|
+ List<String> nodeIds = formElementDTO.getNodeIds();
|
|
|
+ if (nodeIds.size() <= 0) {
|
|
|
+ throw new ServiceException("请至少选择一个节点进行新增操作");
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ for (String nodeId : nodeIds) {
|
|
|
+ String deptName = formElementDTO.getDeptName();
|
|
|
+ if (deptName.length() > 100 || deptName.length() < 1) {
|
|
|
+ throw new ServiceException("表名长度错误,输入范围1-100个字符长度");
|
|
|
+ }
|
|
|
+ if (formElementDTO.getElementList().size() <= 0) {
|
|
|
+ throw new ServiceException("操作失败,请先添加表单元素");
|
|
|
+ }
|
|
|
+ for (WbsFormElement wbsFormElement : formElementDTO.getElementList()) {
|
|
|
+ if (StringUtils.isEmpty(wbsFormElement.getEName()) ||
|
|
|
+ StringUtils.isEmpty(String.valueOf(wbsFormElement.getEType()))) {
|
|
|
+ throw new ServiceException("操作失败,请完整填写元素名称与类型参数");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- sb.append(chars[i]);
|
|
|
+ //初始化
|
|
|
+ Long id = SnowFlakeUtil.getId();
|
|
|
+ String newTableName = "m_" + DateUtil.time() + "_" + id;
|
|
|
+ formElementDTO.setInitTableName(newTableName);
|
|
|
+
|
|
|
+ //设置parentId=nodeId
|
|
|
+ formElementDTO.setParentId(Long.valueOf(nodeId));
|
|
|
+
|
|
|
+ //创建元素表
|
|
|
+ boolean b = submit2(formElementDTO);
|
|
|
+ if (b) {
|
|
|
+ List<WbsFormElement> elementList = formElementDTO.getElementList();
|
|
|
+ int i = 1;
|
|
|
+ for (WbsFormElement wbsFormElement : elementList) {
|
|
|
+ //当前元素表中元素对应实体表唯一key值、fId、元素默认长度
|
|
|
+ wbsFormElement.setEKey("key_" + i++);
|
|
|
+ wbsFormElement.setId(SnowFlakeUtil.getId());
|
|
|
+ wbsFormElement.setFId(String.valueOf(formElementDTO.getId()));
|
|
|
+ wbsFormElement.setELength(Integer.valueOf(setDefaultElementLength(wbsFormElement.getEType())));
|
|
|
+ }
|
|
|
+ //新增元素
|
|
|
+ this.saveBatch(elementList);
|
|
|
+
|
|
|
+ //获取当前元素表中所有元素
|
|
|
+ List<WbsFormElement> list = this.selectElementListByFid(String.valueOf(formElementDTO.getId()));
|
|
|
+
|
|
|
+ //初始化实体表
|
|
|
+ this.initTable(list, newTableName);
|
|
|
+
|
|
|
+ //绑定与清表关系
|
|
|
+ baseMapper.insertWbsTabRelationExcelTab(SnowFlakeUtil.getId(), formElementDTO.getExcelTabId(), formElementDTO.getId());
|
|
|
|
|
|
- if ((i + 1 >= chars.length) || String.valueOf(chars[i + 1]).matches("[\\u4E00-\\u9FA5]+")) {
|
|
|
- sb.append(separator);
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ServiceException("新增元素表操作失败");
|
|
|
}
|
|
|
-
|
|
|
- rs = sb.substring(0, sb.length());
|
|
|
- } catch (BadHanyuPinyinOutputFormatCombination e) {
|
|
|
- e.printStackTrace();
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
- return rs;
|
|
|
-
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
private boolean submit2(FormElementDTO2 dept) {
|
|
@@ -558,9 +593,28 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
dept.setDeptCategory(1);
|
|
|
dept.setStatus(1);
|
|
|
dept.setIsLinkTable(2);
|
|
|
+ dept.setId(SnowFlakeUtil.getId());
|
|
|
|
|
|
return wbsTreeMapper.insert(dept) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean cancelRelation(String id, String excelId) {
|
|
|
+ //查询元素表与清表关联关系
|
|
|
+ List<WbsTabRelationExcelTab> list = baseMapper.selectWbsTabRelationExcelTab(id, excelId);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ //删除元素表与清表关联关系
|
|
|
+ baseMapper.deleteWbsTabRelationExcelTab(id, excelId);
|
|
|
+
|
|
|
+ //修改状态
|
|
|
+ wbsTreeMapper.cancelRelation(id);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<WbsNodeTableVO> searchNodeTables(String nodeId, String excelId) {
|
|
|
+ return wbsTreeMapper.searchNodeTables(nodeId, excelId);
|
|
|
}
|
|
|
|
|
|
public boolean syncDataFiled(String initTableName, List<WbsFormElement> listData) {
|
|
@@ -630,7 +684,6 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private String setDefaultElementLength(Integer type) {
|
|
|
switch (type) {
|
|
|
case 1: //字符串
|
|
@@ -647,4 +700,48 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static String getPinyin(String text, String separator) {
|
|
|
+ //text 文本, separator 转换后添加的分隔符
|
|
|
+ char[] chars = text.toCharArray();
|
|
|
+ HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
|
|
|
+
|
|
|
+ // 设置大小写
|
|
|
+ format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
|
|
|
+
|
|
|
+ // 设置声调表示方法
|
|
|
+ format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
|
|
|
+
|
|
|
+ // 设置字母u表示方法
|
|
|
+ format.setVCharType(HanyuPinyinVCharType.WITH_V);
|
|
|
+ String[] s;
|
|
|
+ String rs = "";
|
|
|
+ try {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (int i = 0; i < chars.length; i++) {
|
|
|
+ // 判断是否为汉字字符
|
|
|
+ if (String.valueOf(chars[i]).matches("[\\u4E00-\\u9FA5]+")) {
|
|
|
+ s = PinyinHelper.toHanyuPinyinStringArray(chars[i], format);
|
|
|
+ if (s != null) {
|
|
|
+ sb.append(s[0]).append(separator);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sb.append(chars[i]);
|
|
|
+
|
|
|
+ if ((i + 1 >= chars.length) || String.valueOf(chars[i + 1]).matches("[\\u4E00-\\u9FA5]+")) {
|
|
|
+ sb.append(separator);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ rs = sb.substring(0, sb.length());
|
|
|
+ } catch (BadHanyuPinyinOutputFormatCombination e) {
|
|
|
+ e.printStackTrace();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return rs;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|