|
@@ -1,19 +1,3 @@
|
|
|
-/*
|
|
|
- * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
- *
|
|
|
- * Redistribution and use in source and binary forms, with or without
|
|
|
- * modification, are permitted provided that the following conditions are met:
|
|
|
- *
|
|
|
- * Redistributions of source code must retain the above copyright notice,
|
|
|
- * this list of conditions and the following disclaimer.
|
|
|
- * Redistributions in binary form must reproduce the above copyright
|
|
|
- * notice, this list of conditions and the following disclaimer in the
|
|
|
- * documentation and/or other materials provided with the distribution.
|
|
|
- * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
- * contributors may be used to endorse or promote products derived from
|
|
|
- * this software without specific prior written permission.
|
|
|
- * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
- */
|
|
|
package org.springblade.manager.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -60,12 +44,6 @@ import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-/**
|
|
|
- * wbs表单元素 服务实现类
|
|
|
- *
|
|
|
- * @author liuyc
|
|
|
- * @since 2022-04-27
|
|
|
- */
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMapper, WbsFormElement> implements IWbsFormElementService {
|
|
@@ -179,77 +157,81 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
public R saveAndSyn(WbsFormElement wbsFormElement, String tableName) {
|
|
|
//新增元素字段
|
|
|
//查询当前元素表中元素的最后一个key_?值
|
|
|
- QueryWrapper<WbsFormElement> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("f_id", wbsFormElement.getFId());
|
|
|
- List<WbsFormElement> wbsFormElements = baseMapper.selectList(queryWrapper);
|
|
|
- String substring = "";
|
|
|
- List<String> eKeyNum = new ArrayList<>();
|
|
|
- if (wbsFormElements.size() > 0) {
|
|
|
- for (WbsFormElement formElement : wbsFormElements) {
|
|
|
- String eKey = formElement.getEKey();
|
|
|
- substring = eKey.split("_")[1];
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(substring)) {
|
|
|
- long newFiled = Long.parseLong(substring) + 1;
|
|
|
- String substring1 = "key_" + newFiled;
|
|
|
- eKeyNum.add(substring1);
|
|
|
- if (wbsFormElement.getEType() == 4) {
|
|
|
- wbsFormElement.setELength(0);
|
|
|
+ try {
|
|
|
+ QueryWrapper<WbsFormElement> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("f_id", wbsFormElement.getFId());
|
|
|
+ List<WbsFormElement> wbsFormElements = baseMapper.selectList(queryWrapper);
|
|
|
+ String substring = "";
|
|
|
+ List<String> eKeyNum = new ArrayList<>();
|
|
|
+ if (wbsFormElements.size() > 0) {
|
|
|
+ for (WbsFormElement formElement : wbsFormElements) {
|
|
|
+ String eKey = formElement.getEKey();
|
|
|
+ substring = eKey.split("_")[1];
|
|
|
}
|
|
|
- }
|
|
|
- wbsFormElement.setEKey(eKeyNum.get(eKeyNum.size() - 1));
|
|
|
- } else {
|
|
|
- wbsFormElement.setEKey("key_1");
|
|
|
- }
|
|
|
- String newName = wbsFormElement.getEKey();
|
|
|
-
|
|
|
- //同步
|
|
|
- StringBuilder sbr1 = new StringBuilder();
|
|
|
- String fieldType = judgeDataType(wbsFormElement.getEType());
|
|
|
- if ("varchar".equals(fieldType)) {
|
|
|
- if (wbsFormElement.getELength() > 1000 || wbsFormElement.getELength() < 10) {
|
|
|
- return R.fail("请输入正确的字符串长度,范围为10-1000");
|
|
|
+ if (StringUtils.isNotEmpty(substring)) {
|
|
|
+ long newFiled = Long.parseLong(substring) + 1;
|
|
|
+ String substring1 = "key_" + newFiled;
|
|
|
+ eKeyNum.add(substring1);
|
|
|
+ if (wbsFormElement.getEType() == 4) {
|
|
|
+ wbsFormElement.setELength(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ wbsFormElement.setEKey(eKeyNum.get(eKeyNum.size() - 1));
|
|
|
} else {
|
|
|
- baseMapper.insert(wbsFormElement);
|
|
|
- sbr1.append(" ").append(fieldType).append("(").append(wbsFormElement.getELength()).append(")");
|
|
|
- String sql = newName + " " + sbr1;
|
|
|
- baseMapper.alterAddFiled(sql, tableName);
|
|
|
- return R.data(wbsFormElement, "操作成功");
|
|
|
+ wbsFormElement.setEKey("key_1");
|
|
|
}
|
|
|
- } else if ("bigint".equals(fieldType)) {
|
|
|
- if (wbsFormElement.getELength() > 255 || wbsFormElement.getELength() < 10) {
|
|
|
- return R.fail("请输入正确的整数长度,范围为10-255");
|
|
|
- } else {
|
|
|
- baseMapper.insert(wbsFormElement);
|
|
|
- sbr1.append(" ").append(fieldType).append("(").append(wbsFormElement.getELength()).append(")");
|
|
|
- String sql = newName + " " + sbr1;
|
|
|
- baseMapper.alterAddFiled(sql, tableName);
|
|
|
- return R.data(wbsFormElement, "操作成功");
|
|
|
- }
|
|
|
- } else if ("decimal".equals(fieldType)) {
|
|
|
- if (wbsFormElement.getELength() > 65 || wbsFormElement.getELength() < 10) {
|
|
|
- return R.fail("请输入正确的小数长度,范围为10-65");
|
|
|
- } else {
|
|
|
+ String newName = wbsFormElement.getEKey();
|
|
|
+ wbsFormElement.setStatus(1);
|
|
|
+ //同步
|
|
|
+ StringBuilder sbr1 = new StringBuilder();
|
|
|
+ String fieldType = judgeDataType(wbsFormElement.getEType());
|
|
|
+ if ("varchar".equals(fieldType)) {
|
|
|
+ if (wbsFormElement.getELength() > 1000 || wbsFormElement.getELength() < 10) {
|
|
|
+ return R.fail("请输入正确的字符串长度,范围为10-1000");
|
|
|
+ } else {
|
|
|
+ baseMapper.insert(wbsFormElement);
|
|
|
+ sbr1.append(" ").append(fieldType).append("(").append(wbsFormElement.getELength()).append(")");
|
|
|
+ String sql = newName + " " + sbr1;
|
|
|
+ baseMapper.alterAddFiled(sql, tableName);
|
|
|
+ return R.data(wbsFormElement, "操作成功");
|
|
|
+ }
|
|
|
+ } else if ("bigint".equals(fieldType)) {
|
|
|
+ if (wbsFormElement.getELength() > 255 || wbsFormElement.getELength() < 10) {
|
|
|
+ return R.fail("请输入正确的整数长度,范围为10-255");
|
|
|
+ } else {
|
|
|
+ baseMapper.insert(wbsFormElement);
|
|
|
+ sbr1.append(" ").append(fieldType).append("(").append(wbsFormElement.getELength()).append(")");
|
|
|
+ String sql = newName + " " + sbr1;
|
|
|
+ baseMapper.alterAddFiled(sql, tableName);
|
|
|
+ return R.data(wbsFormElement, "操作成功");
|
|
|
+ }
|
|
|
+ } else if ("decimal".equals(fieldType)) {
|
|
|
+ if (wbsFormElement.getELength() > 65 || wbsFormElement.getELength() < 10) {
|
|
|
+ return R.fail("请输入正确的小数长度,范围为10-65");
|
|
|
+ } else {
|
|
|
+ baseMapper.insert(wbsFormElement);
|
|
|
+ sbr1.append(" ").append(fieldType).append("(").append(wbsFormElement.getELength()).append(")");
|
|
|
+ String sql = newName + " " + sbr1;
|
|
|
+ baseMapper.alterAddFiled(sql, tableName);
|
|
|
+ return R.data(wbsFormElement, "操作成功");
|
|
|
+ }
|
|
|
+ } else if ("datetime".equals(fieldType)) {
|
|
|
baseMapper.insert(wbsFormElement);
|
|
|
- sbr1.append(" ").append(fieldType).append("(").append(wbsFormElement.getELength()).append(")");
|
|
|
+ sbr1.append(" ").append(fieldType).append("(").append(0).append(")");
|
|
|
String sql = newName + " " + sbr1;
|
|
|
baseMapper.alterAddFiled(sql, tableName);
|
|
|
return R.data(wbsFormElement, "操作成功");
|
|
|
}
|
|
|
- } else if ("datetime".equals(fieldType)) {
|
|
|
- baseMapper.insert(wbsFormElement);
|
|
|
- sbr1.append(" ").append(fieldType).append("(").append(0).append(")");
|
|
|
- String sql = newName + " " + sbr1;
|
|
|
- baseMapper.alterAddFiled(sql, tableName);
|
|
|
- return R.data(wbsFormElement, "操作成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ //手动回滚
|
|
|
+ baseMapper.deleteElement(wbsFormElement);
|
|
|
+ throw new ServiceException("未找到实体表,新增失败");
|
|
|
}
|
|
|
|
|
|
return R.fail("操作失败");
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -286,11 +268,11 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
try {
|
|
|
baseMapper.updateFiledType(initTableName, eKey, eType, eLength);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ throw new ServiceException("未找到实体表,修改失败");
|
|
|
}
|
|
|
}
|
|
|
- return "0";
|
|
|
|
|
|
+ return "0";
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -446,6 +428,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public boolean saveRelation(FormElementDTO2 formElementDTO) {
|
|
|
try {
|
|
|
//获取当前元素表与清表关系信息
|
|
@@ -659,7 +642,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
case "字符串":
|
|
|
case "签名":
|
|
|
case "文件":
|
|
|
- return 1000;
|
|
|
+ return 800;
|
|
|
case "整数":
|
|
|
case "数值":
|
|
|
case "小数":
|
|
@@ -673,7 +656,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
private Integer getElementLength2(String type) {
|
|
|
switch (type) {
|
|
|
case "varchar":
|
|
|
- return 1000;
|
|
|
+ return 800;
|
|
|
case "bigint":
|
|
|
case "decimal":
|
|
|
return 20;
|
|
@@ -688,7 +671,7 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
case 1: //字符串
|
|
|
case 7: //文件
|
|
|
case 6: //签名
|
|
|
- return "1000";
|
|
|
+ return "800";
|
|
|
case 2: //整数
|
|
|
case 5: //数值
|
|
|
case 3: //小数
|
|
@@ -742,5 +725,4 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|