|
@@ -17,9 +17,13 @@
|
|
|
package org.springblade.manager.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
-import org.checkerframework.checker.units.qual.A;
|
|
|
+import org.springblade.business.entity.ConstructionLedger;
|
|
|
+import org.springblade.business.mapper.ConstructionLedgerMapper;
|
|
|
+import org.springblade.business.service.IConstructionLedgerService;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.log.logger.BladeLogger;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.constant.BladeConstant;
|
|
@@ -29,21 +33,29 @@ 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.ProjectAssignmentWbstreeDTO;
|
|
|
-import org.springblade.manager.dto.WbsTreeDTO;
|
|
|
+import org.springblade.manager.dto.WbsTreeContractDTO;
|
|
|
+import org.springblade.manager.entity.WbsInfo;
|
|
|
+import org.springblade.manager.entity.WbsTreeContract;
|
|
|
+import org.springblade.manager.excel.WbsExcelUtil;
|
|
|
import org.springblade.manager.excel.WbsTreeExcel;
|
|
|
+import org.springblade.manager.mapper.WbsInfoMapper;
|
|
|
+import org.springblade.manager.mapper.WbsTreeContractMapper;
|
|
|
import org.springblade.manager.mapper.WbsTreeMapper;
|
|
|
+import org.springblade.manager.service.IWbsFormElementService;
|
|
|
import org.springblade.manager.service.IWbsTreeService;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.manager.entity.WbsFormElement;
|
|
|
import org.springblade.manager.entity.WbsTree;
|
|
|
import org.springblade.manager.vo.WbsNodeTableVO;
|
|
|
+import org.springblade.manager.vo.WbsTreeContractVO;
|
|
|
import org.springblade.manager.vo.WbsTreeVO;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -53,10 +65,15 @@ import java.util.*;
|
|
|
* @since 2022-04-25
|
|
|
*/
|
|
|
@Service
|
|
|
+@AllArgsConstructor
|
|
|
public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree> implements IWbsTreeService {
|
|
|
|
|
|
- @Resource
|
|
|
- private WbsTreeMapper wbsTreeMapper;
|
|
|
+ private final BladeLogger logger;
|
|
|
+ private final WbsTreeMapper wbsTreeMapper;
|
|
|
+ private final ConstructionLedgerMapper constructionLedgerMapper;
|
|
|
+ private final WbsInfoMapper wbsInfoMapper;
|
|
|
+ private final WbsTreeContractMapper wbsTreeContractMapper;
|
|
|
+ private final IWbsFormElementService wbsFormElementService;
|
|
|
|
|
|
@Override
|
|
|
public IPage<WbsTreeVO> selectWbsTreePage(IPage<WbsTreeVO> page, WbsTreeVO wbsTree) {
|
|
@@ -96,8 +113,7 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
|
|
|
return saveOrUpdate(dept);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public boolean submit2(FormElementDTO dept) {
|
|
|
+ private boolean submit2(FormElementDTO dept) {
|
|
|
if (Func.isEmpty(dept.getParentId())) {
|
|
|
dept.setTenantId(AuthUtil.getTenantId());
|
|
|
dept.setParentId(BladeConstant.TOP_PARENT_ID);
|
|
@@ -124,16 +140,6 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
|
|
|
public List<WbsNodeTableVO> selectByNodeTable(String id) {
|
|
|
//查询节点下的所有表单
|
|
|
List<WbsNodeTableVO> wbsNodeTableVOS = wbsTreeMapper.selectByNodeTable(id);
|
|
|
- /*List<String> ids = new ArrayList<>();
|
|
|
- for (int i = 0; i < wbsNodeTableVOS.size(); i++) {
|
|
|
- String id1 = wbsNodeTableVOS.get(i).getId();
|
|
|
- ids.add(id1+",");
|
|
|
- if ( i == (wbsNodeTableVOS.size()-1)){
|
|
|
- ids.remove(",");
|
|
|
- }
|
|
|
- }
|
|
|
- //根据ID查询元素
|
|
|
- List<String> strings = wbsTreeMapper.selectByElementsTotal(ids);*/
|
|
|
return wbsNodeTableVOS;
|
|
|
}
|
|
|
|
|
@@ -152,17 +158,8 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
|
|
|
return wbsFormElements;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Boolean saveFormElement(WbsTree wbsTree) {
|
|
|
- Integer integer = wbsTreeMapper.insertForm(wbsTree);
|
|
|
- if (integer > 0) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public String selectTableIdByTableName(String deptName) {
|
|
|
+ private String selectTableIdByTableName(String deptName) {
|
|
|
QueryWrapper<WbsTree> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.in("dept_name", deptName);
|
|
|
WbsTree wbsTree = wbsTreeMapper.selectOne(queryWrapper);
|
|
@@ -172,30 +169,67 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
|
|
|
return String.valueOf(wbsTree.getId());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- public void importRegion(List<WbsTreeExcel> data, Boolean isCovered) {
|
|
|
- List<WbsTree> list = new ArrayList<>();
|
|
|
- data.forEach(wbsTreeExcel -> {
|
|
|
- WbsTree wbsTree = BeanUtil.copy(wbsTreeExcel, WbsTree.class);
|
|
|
- list.add(wbsTree);
|
|
|
- });
|
|
|
- if (isCovered) {
|
|
|
- this.saveOrUpdateBatch(list);
|
|
|
- } else {
|
|
|
- this.saveBatch(list);
|
|
|
+ public Boolean importWbsTree(MultipartFile excelFile, WbsTree wbsTreeFu, WbsTree wbsTree1) throws IOException {
|
|
|
+ //赋值
|
|
|
+ wbsTreeFu.setAncestors("0");
|
|
|
+ wbsTree1.setProjectNodeId(wbsTree1.getId());
|
|
|
+ //获取文件路径
|
|
|
+ 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());
|
|
|
+ wbsTreeZi.setAncestors(wbsTreeFu.getAncestors());
|
|
|
+ wbsTreeZi.setProjectNodeId(wbsTree1.getProjectNodeId());
|
|
|
+ //新增节点返回未创建成功查询出来的wbsTree对象、创建成功后的wbsTreeZi对象
|
|
|
+ WbsTree wbsTree = importTree(wbsTreeZi);
|
|
|
+ //后置初始化默认值
|
|
|
+ if (wbsTree == null) {
|
|
|
+ Long id = wbsTreeZi.getId();
|
|
|
+ //设置ancestors祖级id集合
|
|
|
+ StringBuilder stringBuffer = new StringBuilder();
|
|
|
+ StringBuilder appendStr = stringBuffer.append(",").append(wbsTreeZi.getParentId());
|
|
|
+ String ancestors = wbsTreeZi.getAncestors() + appendStr;
|
|
|
+ //修改ancestors的值
|
|
|
+ updateDate(ancestors, id);
|
|
|
+ wbsTreeFu.setParentId(id);
|
|
|
+ wbsTreeFu.setAncestors(ancestors);
|
|
|
+ } else {
|
|
|
+ wbsTreeFu.setParentId(wbsTree.getId());
|
|
|
+ wbsTreeFu.setAncestors(wbsTree.getAncestors());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
-
|
|
|
+ //修改根节点ProjectNodeId
|
|
|
+ int row = baseMapper.updateById(wbsTree1);
|
|
|
+ if (row > 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public WbsTree importTree(WbsTree wbsTreeZi) {
|
|
|
+ private WbsTree importTree(WbsTree wbsTreeZi) {
|
|
|
//查重
|
|
|
QueryWrapper<WbsTree> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("wbs_id", wbsTreeZi.getWbsId());
|
|
|
queryWrapper.eq("dept_name", wbsTreeZi.getDeptName());
|
|
|
queryWrapper.eq("dept_category", wbsTreeZi.getDeptCategory());
|
|
|
- WbsTree wbsTree = baseMapper.selectOne(queryWrapper);
|
|
|
- if (wbsTree == null) {
|
|
|
+ queryWrapper.eq("project_node_id", wbsTreeZi.getProjectNodeId());
|
|
|
+ WbsTree wbsTrees = baseMapper.selectOne(queryWrapper);
|
|
|
+ if (wbsTrees == null) {
|
|
|
//初始化默认值
|
|
|
wbsTreeZi.setStatus(1);
|
|
|
wbsTreeZi.setType(1);
|
|
@@ -204,17 +238,13 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
|
|
|
wbsTreeZi.setIsConcrete(0);
|
|
|
wbsTreeZi.setIsExpernode(0);
|
|
|
}
|
|
|
- int row = baseMapper.insert(wbsTreeZi);
|
|
|
- if (row > 0) {
|
|
|
- return null;
|
|
|
- }
|
|
|
+ baseMapper.insert(wbsTreeZi);
|
|
|
}
|
|
|
- return wbsTree;
|
|
|
+ //TODO 暂时未想到好的处理方法来判断重复条新增问题
|
|
|
+ return wbsTrees;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean updateDate(String ancestors, Long id) {
|
|
|
+ private boolean updateDate(String ancestors, Long id) {
|
|
|
Integer row = baseMapper.updateById2(ancestors, id);
|
|
|
if (row > 0) {
|
|
|
return true;
|
|
@@ -224,7 +254,7 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean saveWbsTreeInProject(ProjectAssignmentWbstreeDTO pawDTO) {
|
|
|
+ public Boolean saveWbsTreeInProject(WbsTreeContractDTO pawDTO) {
|
|
|
String wbsTreeIds = pawDTO.getWbsTreeIds();
|
|
|
if (StringUtils.isEmpty(wbsTreeIds)) {
|
|
|
return false;
|
|
@@ -235,18 +265,30 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
|
|
|
list.forEach(System.out::print);
|
|
|
//新增节点
|
|
|
for (WbsTree wbsTree : list) {
|
|
|
- Integer row = baseMapper.insertToNewWbsTreeTable(pawDTO.getProjectId(), wbsTree);
|
|
|
+ //初始化wbs私有库
|
|
|
+ Integer row = baseMapper.insertWbsTreePrivate(pawDTO.getProjectId(), wbsTree);
|
|
|
if (row > 0) {
|
|
|
- System.out.println("新增节点成功,节点id: ----- " + wbsTree.getId());
|
|
|
+ logger.info(wbsTree.getId().toString(), "初始化项目私有wbs树成功");
|
|
|
+ }
|
|
|
+ //初始化创建合同段私有wbs树
|
|
|
+ Boolean b1 = baseMapper.insertWbsTreeContract(pawDTO.getProjectId(), pawDTO.getContractId(), wbsTree);
|
|
|
+ if (b1) {
|
|
|
+ logger.info(wbsTree.getId().toString(), "初始化合同段wbs树成功");
|
|
|
}
|
|
|
+ //初始化施工台账数据
|
|
|
+ if (wbsTree.getDeptCategory() == 6) {
|
|
|
+ ConstructionLedger constructionLedger = new ConstructionLedger();
|
|
|
+ constructionLedger.setIsBeton(0);
|
|
|
+ constructionLedger.setWbsId(Long.parseLong(pawDTO.getWbsId()));
|
|
|
+ constructionLedger.setContractId(Long.parseLong(pawDTO.getContractId()));
|
|
|
+ int b2 = constructionLedgerMapper.insert(constructionLedger);
|
|
|
+ if (b2 > 0) {
|
|
|
+ logger.info(constructionLedger.getId().toString(), "施工台账初始化成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //TODO 初始化元素表、公式
|
|
|
}
|
|
|
}
|
|
|
- //初始化创建合同段私有wbs树
|
|
|
-
|
|
|
-
|
|
|
- //初始化施工台账数据
|
|
|
-
|
|
|
-
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -258,4 +300,64 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
|
|
|
}
|
|
|
return baseMapper.selectBatchIds(idList);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public WbsTreeContractVO findWbsTreeList() {
|
|
|
+ WbsTreeContractVO wbsTreeContractVO = new WbsTreeContractVO();
|
|
|
+ //查询Wbs总树
|
|
|
+ List<WbsInfo> wbsInfos = wbsInfoMapper.selectAll();
|
|
|
+ wbsTreeContractVO.setWbsInfos(wbsInfos);
|
|
|
+ //查询私有树
|
|
|
+ List<WbsTreeContractDTO> wbsTreeContracts = wbsTreeContractMapper.selectAll();
|
|
|
+ wbsTreeContractVO.setWbsTreeContracts(wbsTreeContracts);
|
|
|
+ return wbsTreeContractVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R saveFormElement(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 = submit2(formElementDTO);
|
|
|
+ //查询当前新建表单的id,通过表单名字查询,表单名必须唯一
|
|
|
+ String tableId = selectTableIdByTableName(formElementDTO.getDeptName());
|
|
|
+ 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);
|
|
|
+ //通过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("操作失败");
|
|
|
+ }
|
|
|
+ //TODO 初始化元素(动态更新元素-就是当用户编辑新增元素时,实体表也要同步新增一个字段,编辑、删除一样需要同步,需要在写3个接口)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|