|
@@ -20,26 +20,26 @@ package org.springblade.manager.controller;
|
|
|
import io.swagger.annotations.*;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
-import oracle.jdbc.proxy.annotation.Post;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
-import org.bouncycastle.crypto.tls.MACAlgorithm;
|
|
|
import org.springblade.core.cache.utils.CacheUtil;
|
|
|
+import org.springblade.core.excel.util.ExcelUtil;
|
|
|
import org.springblade.core.mp.support.Condition;
|
|
|
import org.springblade.core.secure.BladeUser;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.support.Kv;
|
|
|
+import org.springblade.core.tool.utils.DateUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
-import org.springblade.core.tool.utils.StringUtil;
|
|
|
import org.springblade.manager.dto.FormElementDTO;
|
|
|
-import org.springblade.manager.dto.WbsFormElementDTO;
|
|
|
import org.springblade.manager.dto.WbsTreeDTO;
|
|
|
import org.springblade.manager.entity.WbsFormElement;
|
|
|
import org.springblade.manager.entity.WbsTree;
|
|
|
+import org.springblade.manager.excel.WbsExcelUtil;
|
|
|
+import org.springblade.manager.excel.WbsTreeExcel;
|
|
|
import org.springblade.manager.service.IWbsFormElementService;
|
|
|
import org.springblade.manager.vo.WbsNodeTableVO;
|
|
|
import org.springblade.manager.vo.WbsTreeVO;
|
|
|
import org.springblade.system.cache.DictCache;
|
|
|
-import org.springblade.system.entity.DictBiz;
|
|
|
import org.springblade.system.enums.DictEnum;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -47,11 +47,13 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springblade.manager.wrapper.WbsTreeWrapper;
|
|
|
import org.springblade.manager.service.IWbsTreeService;
|
|
|
import org.springblade.core.boot.ctrl.BladeController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
|
|
|
|
|
@@ -130,7 +132,7 @@ public class WbsTreeController extends BladeController {
|
|
|
@PostMapping("/submit")
|
|
|
@ApiOperationSupport(order = 4)
|
|
|
@ApiOperation(value = "新增或修改", notes = "WbsTreeDTO")
|
|
|
- public R submit(@RequestBody WbsTreeDTO WbsTreeDTO) {
|
|
|
+ public R submit(@Valid @RequestBody WbsTreeDTO WbsTreeDTO) {
|
|
|
if (wbsTreeService.submit(WbsTreeDTO)) {
|
|
|
CacheUtil.clear(SYS_CACHE);
|
|
|
// 返回懒加载树更新节点所需字段
|
|
@@ -154,11 +156,11 @@ public class WbsTreeController extends BladeController {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 表单查询(根据节点ID查询当前表单)
|
|
|
+ * 查询当前节点下所有表单(根据节点ID查询当前表单)
|
|
|
*/
|
|
|
@GetMapping("/selectByNodeTable")
|
|
|
@ApiOperationSupport(order = 6)
|
|
|
- @ApiOperation(value = "表单查询", notes = "传入父节点id")
|
|
|
+ @ApiOperation(value = "查询当前节点下所有表单", notes = "传入父节点id")
|
|
|
public R<List<WbsNodeTableVO>> selectByNodeTable(@ApiParam(value = "父节点id", required = true) @RequestParam String id) {
|
|
|
List<WbsNodeTableVO> rs = wbsTreeService.selectByNodeTable(id);
|
|
|
if (!("").equals(rs) && rs.size() > 0) {
|
|
@@ -181,7 +183,7 @@ public class WbsTreeController extends BladeController {
|
|
|
if (wbsFormElements.size() > 0) {
|
|
|
return R.fail("删除失败,请先移除表单中的元素!");
|
|
|
}
|
|
|
- // 删除表单
|
|
|
+ //删除表单
|
|
|
boolean restul = wbsTreeService.removeTableById(id);
|
|
|
if (restul) {
|
|
|
return R.success("删除成功");
|
|
@@ -191,11 +193,11 @@ public class WbsTreeController extends BladeController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 表单元素列表
|
|
|
+ * 根据表单id查询所有元素
|
|
|
*/
|
|
|
@GetMapping("/selectFormElements")
|
|
|
@ApiOperationSupport(order = 7)
|
|
|
- @ApiOperation(value = "表单元素列表", notes = "传入表单id")
|
|
|
+ @ApiOperation(value = "根据表单id查询所有元素", notes = "传入表单id")
|
|
|
@ApiImplicitParam(name = "id", value = "表单id", required = true)
|
|
|
public R<List<WbsFormElement>> selectFormElements(@RequestParam("id") String id) {
|
|
|
List<WbsFormElement> wbsFormElements = null;
|
|
@@ -217,30 +219,46 @@ public class WbsTreeController extends BladeController {
|
|
|
@ApiOperation(value = "表单与元素新增", notes = "传入FormElementDTO")
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public R saveFormElement(@RequestBody FormElementDTO formElementDTO) {
|
|
|
+ if (formElementDTO.getElementList().size() <= 0) {
|
|
|
+ return R.fail("操作失败,请先添加表单元素");
|
|
|
+ }
|
|
|
+ String filedName = "";
|
|
|
+ String filedType = "";
|
|
|
+ String filedLength = "";
|
|
|
+ for (WbsFormElement wbsFormElement : formElementDTO.getElementList()) {
|
|
|
+ filedName = wbsFormElement.getEName();
|
|
|
+ filedType = String.valueOf(wbsFormElement.getEType());
|
|
|
+ filedLength = String.valueOf(wbsFormElement.getELength());
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(filedName) || StringUtils.isEmpty(filedType) || StringUtils.isEmpty(filedLength)) {
|
|
|
+ return R.fail("操作失败,请完整填写元素参数");
|
|
|
+ }
|
|
|
+ //初始化表名
|
|
|
+ String newTableName = "m_wbs_form_" + DateUtil.time() + "_" + formElementDTO.getDeptName();
|
|
|
+ formElementDTO.setInitTableName(newTableName);
|
|
|
//创建表单
|
|
|
boolean b1 = wbsTreeService.submit2(formElementDTO);
|
|
|
- //查询当前新建表单的id //todo 通过表单名字查询 表单名不是唯一 待商榷
|
|
|
+ //查询当前新建表单的id //todo 通过表单名字查询 表单名必须唯一
|
|
|
String tableId = wbsTreeService.selectTableIdByTableName(formElementDTO.getDeptName());
|
|
|
-
|
|
|
- if (tableId.equals("-1")) {
|
|
|
+ if (("-1").equals(tableId)) {
|
|
|
return R.fail("表单名已经存在,请重新填写表单名");
|
|
|
}
|
|
|
-
|
|
|
+ //赋值fid
|
|
|
List<WbsFormElement> elementList = formElementDTO.getElementList();
|
|
|
-
|
|
|
for (WbsFormElement wbsFormElement : elementList) {
|
|
|
wbsFormElement.setFId(tableId);
|
|
|
}
|
|
|
-
|
|
|
//批量新增元素
|
|
|
boolean b2 = wbsFormElementService.saveBatch(elementList);
|
|
|
- if (b1) {
|
|
|
- if (b2) {
|
|
|
- return R.success("新增表单,元素成功");
|
|
|
- }
|
|
|
- return R.success("新增表单成功");
|
|
|
+ //通过fId查找当前表下的所有元素
|
|
|
+ List<WbsFormElement> list = wbsFormElementService.selectElementListByFid(tableId);
|
|
|
+ //初始化实体表单
|
|
|
+ Boolean b3 = wbsFormElementService.initTable(list, newTableName);
|
|
|
+ if (b1 && b2 && b3) {
|
|
|
+ return R.data(formElementDTO, "新增表单,元素,初始化实体表成功");
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("操作失败");
|
|
|
}
|
|
|
- return R.fail("新增失败");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -259,6 +277,66 @@ public class WbsTreeController extends BladeController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出Wbs树模板
|
|
|
+ */
|
|
|
+ @GetMapping("/export-template")
|
|
|
+ @ApiOperationSupport(order = 10)
|
|
|
+ @ApiOperation(value = "导出WBS树节点模板")
|
|
|
+ public void exportWbsTree(HttpServletResponse response) {
|
|
|
+ List<WbsTreeExcel> list = new ArrayList<>();
|
|
|
+ ExcelUtil.export(response, "WBS树节点模板", "WBS树节点表", list, WbsTreeExcel.class);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入Wbs模板树
|
|
|
+ */
|
|
|
+ @ApiOperationSupport(order = 11)
|
|
|
+ @ApiOperation(value = "导入WBS树节点", notes = "传入excel文件")
|
|
|
+ @RequestMapping(value = "/import-wbsTree", method = RequestMethod.POST)
|
|
|
+ public R importWbsTree(@RequestPart("excelFile") MultipartFile excelFile,
|
|
|
+ @RequestPart("wbsTreeFu") WbsTree wbsTreeFu) throws IOException {
|
|
|
+ //获取文件路径
|
|
|
+ File file = WbsExcelUtil.convert(excelFile);
|
|
|
+ String canonicalPath = file.getCanonicalPath();
|
|
|
+ //解析excel
|
|
|
+ WbsExcelUtil excelUtil = new WbsExcelUtil();
|
|
|
+ ArrayList<Map<String, String>> result = excelUtil.readExcelToObj(canonicalPath);
|
|
|
+ for (Map<String, String> map : result) {
|
|
|
+ map.forEach((nodeType, nodeName) -> {
|
|
|
+ WbsTree wbsTreeZi = new WbsTree();
|
|
|
+ if (StringUtils.isNotEmpty(nodeName)) {
|
|
|
+ //初始化默认值
|
|
|
+ wbsTreeZi.setTenantId(AuthUtil.getTenantId());
|
|
|
+ wbsTreeZi.setDeptName(nodeName);
|
|
|
+ wbsTreeZi.setDeptCategory(Integer.valueOf(nodeType));
|
|
|
+ wbsTreeZi.setWbsId(wbsTreeFu.getWbsId());
|
|
|
+ wbsTreeZi.setParentId(wbsTreeFu.getParentId());
|
|
|
+ //新增节点返回未创建成功查询出来的wbsTree对象、创建成功后的wbsTreeZi对象
|
|
|
+ WbsTree wbsTree = wbsTreeService.importTree(wbsTreeZi);
|
|
|
+ //后置初始化默认值
|
|
|
+ if (wbsTree == null) {
|
|
|
+ Long id = wbsTreeZi.getId();
|
|
|
+ //设置ancestors祖级id集合
|
|
|
+ StringBuilder stringBuffer = new StringBuilder();
|
|
|
+ StringBuilder appendStr = stringBuffer.append(",").append(wbsTreeZi.getParentId());
|
|
|
+ String ancestors = wbsTreeFu.getAncestors() + appendStr;
|
|
|
+ //修改ancestors的值
|
|
|
+ wbsTreeService.updateDate(ancestors, id);
|
|
|
+ wbsTreeFu.setParentId(id);
|
|
|
+ wbsTreeFu.setAncestors(ancestors);
|
|
|
+ } else {
|
|
|
+ wbsTreeFu.setParentId(wbsTree.getId());
|
|
|
+ wbsTreeFu.setAncestors(wbsTree.getAncestors());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return R.success("导入成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|