|
@@ -20,24 +20,41 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import net.sourceforge.pinyin4j.PinyinHelper;
|
|
|
+import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
|
|
|
+import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
|
|
|
+import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
|
|
|
+import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
|
|
|
+import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.constant.BladeConstant;
|
|
|
+import org.springblade.core.tool.utils.DateUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.core.tool.utils.StringPool;
|
|
|
+import org.springblade.manager.dto.FormElementDTO;
|
|
|
import org.springblade.manager.dto.WbsFormElementDTO2;
|
|
|
import org.springblade.manager.entity.WbsFormElement;
|
|
|
import org.springblade.manager.entity.WbsTree;
|
|
|
import org.springblade.manager.excel.WbsFormElementBatchExcel;
|
|
|
import org.springblade.manager.excel.WbsFormElementExcel;
|
|
|
import org.springblade.manager.mapper.WbsFormElementMapper;
|
|
|
+import org.springblade.manager.mapper.WbsTreeMapper;
|
|
|
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.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* wbs表单元素 服务实现类
|
|
@@ -50,6 +67,7 @@ import java.util.List;
|
|
|
public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMapper, WbsFormElement> implements IWbsFormElementService {
|
|
|
|
|
|
private final WbsFormElementMapper wbsFormElementMapper;
|
|
|
+ private final WbsTreeMapper wbsTreeMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -343,8 +361,143 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean submitExcelRelationWbsTreeAndElement(String fId, String tableElementKey) {
|
|
|
- return false;
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean submitExcelRelationWbsTreeAndElement(FormElementDTO formElementDTO) {
|
|
|
+ //formElementDTO.getId() 当前表id
|
|
|
+ if (formElementDTO.getId() == null) { //新增-新增元素表,实体表
|
|
|
+ this.saveFormElement(formElementDTO);
|
|
|
+ } else { //关联-在已有元素表中新增元素,在实体表中追加字段
|
|
|
+ //获取当前元素表中的所有的元素信息
|
|
|
+ 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));
|
|
|
+ //初始化eKey字段
|
|
|
+ int keyNumber = Integer.parseInt(firstWbsFormElement.getEKey().split("_")[1]);
|
|
|
+ //判断
|
|
|
+ List<WbsFormElement> newList = formElementDTO.getElementList().stream().filter(a ->
|
|
|
+ !wbsFormElements.stream().map(WbsFormElement::getEName).collect(Collectors.toList()).contains(a.getEName())
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+ //新增
|
|
|
+ newList.stream().forEach(wbsFormElementInfo -> {
|
|
|
+ String key = "key_" + (keyNumber + 1);
|
|
|
+ //新增元素到当前表中
|
|
|
+ wbsFormElementInfo.setEKey(key);
|
|
|
+ wbsFormElementInfo.setFId(String.valueOf(formElementDTO.getId()));
|
|
|
+ baseMapper.insert(wbsFormElementInfo);
|
|
|
+ //追加实体表字段
|
|
|
+ wbsTreeMapper.alterTableFiled(formElementDTO.getInitTableName(), key,
|
|
|
+ getInitTableFiledType(wbsFormElementInfo.getEType()),
|
|
|
+ Integer.valueOf(setDefaultElementLength(wbsFormElementInfo.getEType())));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private R saveFormElement(FormElementDTO formElementDTO) {
|
|
|
+ String deptName = formElementDTO.getDeptName();
|
|
|
+ if (deptName.length() > 100 || deptName.length() < 1) {
|
|
|
+ throw new ServiceException("表名长度错误,输入范围1-100个字符长度");
|
|
|
+ }
|
|
|
+ if (formElementDTO.getElementList().size() <= 0) {
|
|
|
+ return R.fail("操作失败,请先添加表单元素");
|
|
|
+ }
|
|
|
+ for (WbsFormElement wbsFormElement : formElementDTO.getElementList()) {
|
|
|
+ if (StringUtils.isEmpty(wbsFormElement.getEName()) ||
|
|
|
+ StringUtils.isEmpty(String.valueOf(wbsFormElement.getEType()))) {
|
|
|
+ return R.fail("操作失败,请完整填写元素名称与类型参数");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //初始化表名
|
|
|
+ Long id = SnowFlakeUtil.getId();
|
|
|
+ String newTableName = "m_wbs_form_" + DateUtil.time() + "_" + id.toString();
|
|
|
+ formElementDTO.setInitTableName(newTableName);
|
|
|
+ //创建元素表
|
|
|
+ boolean b1 = submit2(formElementDTO);
|
|
|
+
|
|
|
+ List<WbsFormElement> elementList = formElementDTO.getElementList();
|
|
|
+ int i = 1;
|
|
|
+ for (WbsFormElement wbsFormElement : elementList) {
|
|
|
+ //当前元素表中元素对应实体表唯一key值、fId、元素默认长度
|
|
|
+ wbsFormElement.setEKey("key_" + i++);
|
|
|
+ wbsFormElement.setFId(String.valueOf(formElementDTO.getId()));
|
|
|
+ wbsFormElement.setELength(Integer.valueOf(setDefaultElementLength(wbsFormElement.getEType())));
|
|
|
+ }
|
|
|
+ //新增元素
|
|
|
+ boolean b2 = this.saveBatch(elementList);
|
|
|
+
|
|
|
+ //找到当前元素表中所有元素
|
|
|
+ List<WbsFormElement> list = this.selectElementListByFid(String.valueOf(formElementDTO.getId()));
|
|
|
+ //初始化实体表
|
|
|
+ Boolean b3 = this.initTable(list, newTableName);
|
|
|
+ if (b1 && b2 && b3) {
|
|
|
+ return R.data(formElementDTO, "新增表单、元素、初始化实体表成功");
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("操作失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean submit2(FormElementDTO dept) {
|
|
|
+ if (Func.isEmpty(dept.getParentId())) {
|
|
|
+ dept.setTenantId(AuthUtil.getTenantId());
|
|
|
+ dept.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ dept.setCreateUser(AuthUtil.getUserId());
|
|
|
+ dept.setParentId(BladeConstant.TOP_PARENT_ID);
|
|
|
+ dept.setAncestors(String.valueOf(BladeConstant.TOP_PARENT_ID));
|
|
|
+ }
|
|
|
+ if (dept.getParentId() > 0) {
|
|
|
+ WbsTree parent = wbsTreeMapper.selectById((dept.getParentId()));
|
|
|
+ if (Func.toLong(dept.getParentId()) == Func.toLong(dept.getId())) {
|
|
|
+ throw new ServiceException("父节点不可选择自身!");
|
|
|
+ }
|
|
|
+ dept.setTenantId(parent.getTenantId());
|
|
|
+ String ancestors = parent.getAncestors() + StringPool.COMMA + dept.getParentId();
|
|
|
+ dept.setAncestors(ancestors);
|
|
|
+ //设置表示该父节点下存在表单
|
|
|
+ wbsTreeMapper.updateIsExistFormById(parent.getId());
|
|
|
+ }
|
|
|
+ //设置类型默认值为 '2' 表单
|
|
|
+ dept.setType(2);
|
|
|
+ dept.setIsDeleted(BladeConstant.DB_NOT_DELETED);
|
|
|
+ dept.setDeptCategory(1);
|
|
|
+ dept.setStatus(1);
|
|
|
+ return wbsTreeMapper.insert(dept) > 0;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public boolean syncDataFiled(String initTableName, List<WbsFormElement> listData) {
|
|
@@ -357,7 +510,6 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private String getInitTableFiledType(Integer type) {
|
|
|
switch (type) {
|
|
|
case 2:
|
|
@@ -380,17 +532,34 @@ public class WbsFormElementServiceImpl extends BaseServiceImpl<WbsFormElementMap
|
|
|
|
|
|
private Integer getElementLength(String type) {
|
|
|
switch (type) {
|
|
|
- case "varchar":
|
|
|
- return 1000;
|
|
|
- case "bigint":
|
|
|
+ case "字符串":
|
|
|
+ case "签名":
|
|
|
+ case "文件":
|
|
|
return 255;
|
|
|
- case "decimal":
|
|
|
- return 65;
|
|
|
- case "datetime":
|
|
|
+ case "整数":
|
|
|
+ case "数值":
|
|
|
+ case "小数":
|
|
|
+ return 20;
|
|
|
+ case "日期":
|
|
|
default:
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private String setDefaultElementLength(Integer type) {
|
|
|
+ switch (type) {
|
|
|
+ case 1: //字符串
|
|
|
+ case 7: //文件
|
|
|
+ case 6: //签名
|
|
|
+ return "255";
|
|
|
+ case 2: //整数
|
|
|
+ case 5: //数值
|
|
|
+ case 3: //小数
|
|
|
+ return "20";
|
|
|
+ case 4: //日期
|
|
|
+ default:
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|