|
@@ -1,5 +1,6 @@
|
|
|
package org.springblade.manager.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -10,18 +11,18 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
import org.springblade.business.entity.WbsTreeContractStatistics;
|
|
|
import org.springblade.business.feign.InformationQueryClient;
|
|
|
import org.springblade.common.utils.BaiduApiUtil;
|
|
|
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.secure.utils.SecureUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.node.ForestNodeMerger;
|
|
|
-import org.springblade.core.tool.utils.BeanUtil;
|
|
|
-import org.springblade.core.tool.utils.CollectionUtil;
|
|
|
-import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.core.tool.utils.*;
|
|
|
import org.springblade.manager.bean.NodeVO;
|
|
|
import org.springblade.manager.dto.FindAllUserByConditionDTO;
|
|
|
import org.springblade.manager.dto.SaveUserInfoByProjectDTO;
|
|
@@ -40,6 +41,7 @@ import org.springframework.dao.DataAccessException;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.jdbc.core.SingleColumnRowMapper;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -47,6 +49,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -392,6 +395,7 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
|
|
|
|
|
|
if (contractInfo != null) {
|
|
|
/*质检施工合同段*/
|
|
|
+ Map<Long, String> collectNodesMap = getCollectNodesByContractId(contractId);
|
|
|
if (contractInfo.getContractType().equals(1)) {
|
|
|
LambdaQueryWrapper<WbsTreeContract> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.select(WbsTreeContract::getParentId, WbsTreeContract::getId, WbsTreeContract::getPKeyId);
|
|
@@ -402,6 +406,7 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
|
|
|
}
|
|
|
queryWrapper.eq(WbsTreeContract::getContractId, contractId);
|
|
|
queryWrapper.eq(WbsTreeContract::getType, 1);
|
|
|
+ queryWrapper.and(wrapper -> wrapper.ne(WbsTreeContract::getIsBussShow, 2).or().isNull(WbsTreeContract::getIsBussShow));
|
|
|
List<WbsTreeContract> nodes = wbsTreeContractMapper.selectList(queryWrapper);
|
|
|
if (nodes.size() > 0) {
|
|
|
List<WbsTreeContractLazyVO> nodesAllTemp;
|
|
@@ -545,6 +550,11 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
|
|
|
//判断是否展示同步标识
|
|
|
vo.setIsSync(syncPKeyIds.contains(vo.getPrimaryKeyId().toString()) ? 1 : 0);
|
|
|
}
|
|
|
+ if (collectNodesMap.containsKey(vo.getPrimaryKeyId())) {
|
|
|
+ vo.setIsCollect(1);
|
|
|
+ } else {
|
|
|
+ vo.setIsCollect(0);
|
|
|
+ }
|
|
|
}
|
|
|
return vo;
|
|
|
}).collect(Collectors.toList());
|
|
@@ -570,6 +580,7 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
|
|
|
}
|
|
|
queryWrapper.eq(WbsTreeContract::getContractId, contractRelationJlyz.getContractIdSg());
|
|
|
queryWrapper.eq(WbsTreeContract::getType, 1);
|
|
|
+ queryWrapper.and(wrapper -> wrapper.ne(WbsTreeContract::getIsBussShow, 2).or().isNull(WbsTreeContract::getIsBussShow));
|
|
|
List<WbsTreeContract> nodes = wbsTreeContractMapper.selectList(queryWrapper);
|
|
|
if (nodes.size() > 0) {
|
|
|
List<WbsTreeContractLazyVO> nodesAllTemp;
|
|
@@ -714,6 +725,11 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
|
|
|
//判断是否展示同步标识
|
|
|
vo.setIsSync(syncPKeyIds.contains(vo.getPrimaryKeyId().toString()) ? 1 : 0);
|
|
|
}
|
|
|
+ if (collectNodesMap.containsKey(vo.getPrimaryKeyId())) {
|
|
|
+ vo.setIsCollect(1);
|
|
|
+ } else {
|
|
|
+ vo.setIsCollect(0);
|
|
|
+ }
|
|
|
}
|
|
|
return vo;
|
|
|
}).collect(Collectors.toList());
|
|
@@ -1268,4 +1284,367 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
|
|
|
return contractInfo;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R<Object> queryWbsTreeNodeBySaveOrHidden(String contractId, String tableOwner, Integer days, String queryValue, Integer type) {
|
|
|
+ if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isEmpty(contractId)) {
|
|
|
+ return R.fail(200, "合同段id错误");
|
|
|
+ }
|
|
|
+ ContractInfo contractInfo = this.selectById(contractId);
|
|
|
+ if (contractInfo == null) {
|
|
|
+ return R.fail(200, "合同段不存在");
|
|
|
+ }
|
|
|
+ String idsStr = "";
|
|
|
+ if (type != null && type == 1) {
|
|
|
+ List<Long> pKeyIds = jdbcTemplate.query("SELECT distinct p_key_id from blade_tab_sql WHERE user_id = ? and create_time > ?", new Object[]{AuthUtil.getUserId(), DateUtil.offsetDay(new Date(), -days)}, new SingleColumnRowMapper<>(Long.class));
|
|
|
+ if (pKeyIds.isEmpty()) {
|
|
|
+ return R.fail(200, "未查询到信息");
|
|
|
+ }
|
|
|
+ idsStr = pKeyIds.stream().map(id -> id + "").collect(Collectors.joining(","));
|
|
|
+ }
|
|
|
+ Set<String> syncPKeyIds = getSyncFlagIds(contractId, tableOwner);
|
|
|
+ Map<Long, String> collectNodesMap = getCollectNodesByContractId(contractId);
|
|
|
+ /*质检施工合同段*/
|
|
|
+ if (contractInfo.getContractType().equals(1)) {
|
|
|
+ LambdaQueryWrapper<WbsTreeContract> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(WbsTreeContract::getContractId, contractId).eq(WbsTreeContract::getType, 1);
|
|
|
+ if (type != null && type == 1) {
|
|
|
+ queryWrapper.last(" and p_key_id in ( select p_id from m_wbs_tree_contract where p_key_id in (" + idsStr + ") ) ");
|
|
|
+ } else {
|
|
|
+ queryWrapper.eq(WbsTreeContract::getIsBussShow, 2);
|
|
|
+ }
|
|
|
+ List<WbsTreeContract> nodes = wbsTreeContractMapper.selectList(queryWrapper);
|
|
|
+ if (!nodes.isEmpty()) {
|
|
|
+ List<WbsTreeContractLazyVO> nodesAllTemp;
|
|
|
+ Object data = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:" + contractId);
|
|
|
+ if (data != null) {
|
|
|
+ nodesAllTemp = JSON.parseArray(data.toString(), WbsTreeContractLazyVO.class);
|
|
|
+ } else {
|
|
|
+ nodesAllTemp = jdbcTemplate.query("select a.p_key_id,a.id,a.parent_id from m_wbs_tree_contract a where a.type = 1 and a.status = 1 and a.is_deleted = 0 and a.contract_id = " + contractId, new BeanPropertyRowMapper<>(WbsTreeContractLazyVO.class));
|
|
|
+ if (!nodesAllTemp.isEmpty()) {
|
|
|
+ Map<Long, List<WbsTreeContractLazyVO>> groupedByParentId = nodesAllTemp.stream().collect(Collectors.groupingBy(WbsTreeContractLazyVO::getParentId));
|
|
|
+ for (WbsTreeContractLazyVO vo : nodesAllTemp) {
|
|
|
+ if (vo.getParentId() == 0) {
|
|
|
+ vo.setHasChildren(1);
|
|
|
+ }
|
|
|
+ List<WbsTreeContractLazyVO> childNodes = groupedByParentId.getOrDefault(vo.getId(), null);
|
|
|
+ if (childNodes != null && !childNodes.isEmpty()) {
|
|
|
+ vo.setHasChildren(1);
|
|
|
+ } else {
|
|
|
+ vo.setHasChildren(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONArray array = JSONArray.parseArray(JSON.toJSONString(nodesAllTemp));
|
|
|
+ redisTemplate.opsForValue().set("blade-manager::contract:wbstree:" + contractId, JSON.toJSON(array).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Long> parentIds = nodes.stream().map(WbsTreeContract::getParentId).collect(Collectors.toList());
|
|
|
+ List<Long> ids = nodes.stream().map(WbsTreeContract::getId).collect(Collectors.toList());
|
|
|
+ Set<Long> resultNodesPKeyIds = new LinkedHashSet<>();
|
|
|
+ this.recursiveGetParentNodes(resultNodesPKeyIds, parentIds, nodesAllTemp);
|
|
|
+ this.recursiveGetChildNodes(resultNodesPKeyIds, ids, nodesAllTemp);
|
|
|
+
|
|
|
+ resultNodesPKeyIds.addAll(nodes.stream().map(WbsTreeContract::getPKeyId).collect(Collectors.toList()));
|
|
|
+ List<WbsTreeContract> wbsTreeContractList = wbsTreeContractMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().in(WbsTreeContract::getPKeyId, resultNodesPKeyIds));
|
|
|
+
|
|
|
+ if (!wbsTreeContractList.isEmpty()) {
|
|
|
+ String pKeyIdStr = wbsTreeContractList.stream().map(item -> item.getPKeyId() + "").collect(Collectors.joining(","));
|
|
|
+ List<WbsTreeContractStatistics> wbsTreeContractStatisticsList = jdbcTemplate.query("select id, leaf_num, fill_num, approve_num, complete_num,jl_fill_num, jl_approve_num, jl_complete_num from m_wbs_tree_contract_statistics where id in (" + pKeyIdStr + ")",
|
|
|
+ new BeanPropertyRowMapper<>(WbsTreeContractStatistics.class));
|
|
|
+ Map<Long, WbsTreeContractStatistics> wbsTreeContractStatisticsMap = wbsTreeContractStatisticsList.stream().collect(Collectors.toMap(WbsTreeContractStatistics::getId, item -> item));
|
|
|
+ List<WbsTreeContractTreeAllVO> wbsTreeContractTreeAllVOS = wbsTreeContractList.stream()
|
|
|
+ .map(node -> {
|
|
|
+ WbsTreeContractTreeAllVO vo = BeanUtil.copyProperties(node, WbsTreeContractTreeAllVO.class);
|
|
|
+ if (vo != null) {
|
|
|
+ vo.setContractIdRelation(node.getContractId());
|
|
|
+ vo.setType(ObjectUtils.isNotEmpty(node.getNodeType()) ? node.getNodeType() : 0);
|
|
|
+ vo.setTitle(ObjectUtil.isNotEmpty(node.getFullName()) ? node.getFullName() : node.getNodeName());
|
|
|
+ vo.setPrimaryKeyId(node.getPKeyId());
|
|
|
+ WbsTreeContractStatistics statistics = wbsTreeContractStatisticsMap.get(node.getPKeyId());
|
|
|
+ if (statistics != null) {
|
|
|
+ Integer nums = statistics.calculateSubmitNums(tableOwner);
|
|
|
+ vo.setSubmitCounts(nums == null ? 0 : nums.longValue());
|
|
|
+ vo.setColorStatus(statistics.calculateColorStatus(tableOwner));
|
|
|
+ } else {
|
|
|
+ vo.setSubmitCounts(0L);
|
|
|
+ vo.setColorStatus(1);
|
|
|
+ }
|
|
|
+ if(CollectionUtil.isNotEmpty(syncPKeyIds)){
|
|
|
+ //判断是否展示同步标识
|
|
|
+ vo.setIsSync(syncPKeyIds.contains(vo.getPrimaryKeyId().toString()) ? 1 : 0);
|
|
|
+ }
|
|
|
+ if (collectNodesMap.containsKey(vo.getPrimaryKeyId())) {
|
|
|
+ vo.setIsCollect(1);
|
|
|
+ } else {
|
|
|
+ vo.setIsCollect(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ List<WbsTreeContractTreeAllVO> resultList = this.buildWbsTreeByStreamByTreeAll(wbsTreeContractTreeAllVOS);
|
|
|
+ if (StringUtil.hasText(queryValue)) {
|
|
|
+ return R.data(queryTreeResult(resultList, queryValue));
|
|
|
+ }
|
|
|
+ return R.data(resultList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*监理、业主合同段*/
|
|
|
+ } else if (contractInfo.getContractType().equals(2) || contractInfo.getContractType().equals(3)) {
|
|
|
+ Map<Long, List<WbsTreeContractTreeAllVO>> resultMaps = new LinkedHashMap<>();
|
|
|
+ List<ContractRelationJlyz> relationJLYZList = jdbcTemplate.query("select * from m_contract_relation_jlyz where contract_id_jlyz = " + contractId, new BeanPropertyRowMapper<>(ContractRelationJlyz.class));
|
|
|
+ if (ObjectUtil.isEmpty(relationJLYZList) || relationJLYZList.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ for (ContractRelationJlyz contractRelationJlyz : relationJLYZList) {
|
|
|
+ LambdaQueryWrapper<WbsTreeContract> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(WbsTreeContract::getContractId, contractRelationJlyz.getContractIdSg()).eq(WbsTreeContract::getType, 1);
|
|
|
+ if (type != null && type == 1) {
|
|
|
+ queryWrapper.last(" and p_key_id in ( select p_id from m_wbs_tree_contract where p_key_id in (" + idsStr + ") ) ");
|
|
|
+ } else {
|
|
|
+ queryWrapper.eq(WbsTreeContract::getIsBussShow, 2);
|
|
|
+ }
|
|
|
+ List<WbsTreeContract> nodes = wbsTreeContractMapper.selectList(queryWrapper);
|
|
|
+ if (!nodes.isEmpty()) {
|
|
|
+ List<WbsTreeContractLazyVO> nodesAllTemp;
|
|
|
+ Object data = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:" + contractId);
|
|
|
+ if (data != null) {
|
|
|
+ nodesAllTemp = JSON.parseArray(data.toString(), WbsTreeContractLazyVO.class);
|
|
|
+ } else {
|
|
|
+ nodesAllTemp = jdbcTemplate.query("select a.p_key_id,a.id,a.parent_id from m_wbs_tree_contract a where a.type = 1 and a.status = 1 and a.is_deleted = 0 and a.contract_id = " + contractId, new BeanPropertyRowMapper<>(WbsTreeContractLazyVO.class));
|
|
|
+ if (!nodesAllTemp.isEmpty()) {
|
|
|
+ Map<Long, List<WbsTreeContractLazyVO>> groupedByParentId = nodesAllTemp.stream().collect(Collectors.groupingBy(WbsTreeContractLazyVO::getParentId));
|
|
|
+ for (WbsTreeContractLazyVO vo : nodesAllTemp) {
|
|
|
+ if (vo.getParentId() == 0) {
|
|
|
+ vo.setHasChildren(1);
|
|
|
+ }
|
|
|
+ List<WbsTreeContractLazyVO> childNodes = groupedByParentId.getOrDefault(vo.getId(), null);
|
|
|
+ if (childNodes != null && !childNodes.isEmpty()) {
|
|
|
+ vo.setHasChildren(1);
|
|
|
+ } else {
|
|
|
+ vo.setHasChildren(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONArray array = JSONArray.parseArray(JSON.toJSONString(nodesAllTemp));
|
|
|
+ redisTemplate.opsForValue().set("blade-manager::contract:wbstree:" + contractId, JSON.toJSON(array).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Long> parentIds = nodes.stream().map(WbsTreeContract::getParentId).collect(Collectors.toList());
|
|
|
+ List<Long> ids = nodes.stream().map(WbsTreeContract::getId).collect(Collectors.toList());
|
|
|
+ Set<Long> resultNodesPKeyIds = new LinkedHashSet<>();
|
|
|
+ this.recursiveGetParentNodes(resultNodesPKeyIds, parentIds, nodesAllTemp);
|
|
|
+ this.recursiveGetChildNodes(resultNodesPKeyIds, ids, nodesAllTemp);
|
|
|
+
|
|
|
+ resultNodesPKeyIds.addAll(nodes.stream().map(WbsTreeContract::getPKeyId).collect(Collectors.toList()));
|
|
|
+ List<WbsTreeContract> wbsTreeContractList = wbsTreeContractMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().in(WbsTreeContract::getPKeyId, resultNodesPKeyIds));
|
|
|
+ if (!wbsTreeContractList.isEmpty()) {
|
|
|
+ String pKeyIdStr = wbsTreeContractList.stream().map(item -> item.getPKeyId() + "").collect(Collectors.joining(","));
|
|
|
+ List<WbsTreeContractStatistics> wbsTreeContractStatisticsList = jdbcTemplate.query("select id, leaf_num, fill_num, approve_num, complete_num,jl_fill_num, jl_approve_num, jl_complete_num from m_wbs_tree_contract_statistics where id in (" + pKeyIdStr + ")",
|
|
|
+ new BeanPropertyRowMapper<>(WbsTreeContractStatistics.class));
|
|
|
+ Map<Long, WbsTreeContractStatistics> wbsTreeContractStatisticsMap = wbsTreeContractStatisticsList.stream().collect(Collectors.toMap(WbsTreeContractStatistics::getId, item -> item));
|
|
|
+ List<WbsTreeContractTreeAllVO> wbsTreeContractTreeAllVOS = wbsTreeContractList.stream()
|
|
|
+ .map(node -> {
|
|
|
+ WbsTreeContractTreeAllVO vo = BeanUtil.copyProperties(node, WbsTreeContractTreeAllVO.class);
|
|
|
+ if (vo != null) {
|
|
|
+ vo.setContractIdRelation(node.getContractId());
|
|
|
+ vo.setType(ObjectUtils.isNotEmpty(node.getNodeType()) ? node.getNodeType() : 0);
|
|
|
+ vo.setTitle(ObjectUtil.isNotEmpty(node.getFullName()) ? node.getFullName() : node.getNodeName());
|
|
|
+ vo.setPrimaryKeyId(node.getPKeyId());
|
|
|
+ WbsTreeContractStatistics statistics = wbsTreeContractStatisticsMap.get(node.getPKeyId());
|
|
|
+ if (statistics != null) {
|
|
|
+ Integer nums = statistics.calculateSubmitNums(tableOwner);
|
|
|
+ vo.setSubmitCounts(nums == null ? 0 : nums.longValue());
|
|
|
+ vo.setColorStatus(statistics.calculateColorStatus(tableOwner));
|
|
|
+ } else {
|
|
|
+ vo.setSubmitCounts(0L);
|
|
|
+ vo.setColorStatus(1);
|
|
|
+ }
|
|
|
+ if(CollectionUtil.isNotEmpty(syncPKeyIds)){
|
|
|
+ //判断是否展示同步标识
|
|
|
+ vo.setIsSync(syncPKeyIds.contains(vo.getPrimaryKeyId().toString()) ? 1 : 0);
|
|
|
+ }
|
|
|
+ if (collectNodesMap.containsKey(vo.getPrimaryKeyId())) {
|
|
|
+ vo.setIsCollect(1);
|
|
|
+ } else {
|
|
|
+ vo.setIsCollect(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ List<WbsTreeContractTreeAllVO> list = this.buildWbsTreeByStreamByTreeAll(wbsTreeContractTreeAllVOS);
|
|
|
+ if (StringUtil.hasText(queryValue)) {
|
|
|
+ resultMaps.put(contractRelationJlyz.getContractIdSg(), this.queryTreeResult(list, queryValue));
|
|
|
+ } else {
|
|
|
+ resultMaps.put(contractRelationJlyz.getContractIdSg(), list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.data(resultMaps);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<Long, String> getCollectNodesByContractId(String contractId){
|
|
|
+ if (contractId == null || contractId.trim().isEmpty()) {
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+ Map<Long, String> collectNodes = new HashMap<>();
|
|
|
+ try {
|
|
|
+ String string = redisTemplate.opsForValue().get("blade-manager::contract:collectFolder:" + contractId);
|
|
|
+ if (string != null) {
|
|
|
+ String[] split = string.split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ if (StringUtil.isNumeric(s)) {
|
|
|
+ collectNodes.put(Long.parseLong(s), "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("",e);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (!collectNodes.isEmpty()) {
|
|
|
+ return collectNodes;
|
|
|
+ }
|
|
|
+ List<ContractCollectFolder> query = jdbcTemplate.query(String.format("select * from m_contract_collect_folder where contract_id = %s and type = 1", contractId), new BeanPropertyRowMapper<>(ContractCollectFolder.class));
|
|
|
+ for (ContractCollectFolder contractCollectFolder : query) {
|
|
|
+ Long nodeId = contractCollectFolder.getNodeId();
|
|
|
+ collectNodes.put(nodeId, "");
|
|
|
+ String nodeAncestors = contractCollectFolder.getNodeAncestors();
|
|
|
+ if (nodeAncestors != null) {
|
|
|
+ String[] split = nodeAncestors.split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ if (StringUtil.isNumeric(s)) {
|
|
|
+ collectNodes.put(Long.parseLong(s), "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String ids = collectNodes.keySet().stream().map(item -> item + "").collect(Collectors.joining(","));
|
|
|
+ redisTemplate.opsForValue().set("blade-manager::contract:collectFolder:" + contractId, ids, 60 * 60 * 40L, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("合同段id:" + contractId + ", 获取收藏节点失败:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ return collectNodes;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<WbsTreeContractTreeAllVO> queryTreeResult(List<WbsTreeContractTreeAllVO> resultList, String query) {
|
|
|
+ // 查找树结构中name包含query的节点,返回其父节点及所有子节点
|
|
|
+ List<WbsTreeContractTreeAllVO> result = new ArrayList<>();
|
|
|
+ for (WbsTreeContractTreeAllVO node : resultList) {
|
|
|
+ if (node.getTitle().contains(query)) {
|
|
|
+ result.add(node);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (node.getChildren() != null && !node.getChildren().isEmpty()) {
|
|
|
+ List<WbsTreeContractTreeAllVO> list = queryTreeResult(node.getChildren(), query);
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ node.setChildren(new ArrayList<>());
|
|
|
+ } else {
|
|
|
+ node.setChildren( list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (node.getChildren() != null && !node.getChildren().isEmpty()) {
|
|
|
+ result.add(node);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ @NotNull
|
|
|
+ private Set<String> getSyncFlagIds(String contractId, String tableOwner) {
|
|
|
+ //查询wbs同步信息
|
|
|
+ String contractExtendSql = "select a.ancestors from m_wbs_tree_contract_extend a " +
|
|
|
+ "inner join m_wbs_tree_contract b on a.p_key_id = b.p_key_id and b.is_deleted = 0 " +
|
|
|
+ "where a.type = " + tableOwner + " and a.is_sync = 1 and a.is_deleted = 0 and a.contract_id = " + contractId;
|
|
|
+ Set<String> syncPKeyIds = new HashSet<>();
|
|
|
+ if(SecureUtil.isAdministrator()){
|
|
|
+ List<String> strings = null;
|
|
|
+ try {
|
|
|
+ strings = jdbcTemplate.queryForList(contractExtendSql, String.class);
|
|
|
+ } catch (DataAccessException e) {
|
|
|
+ //TODO 暂时忽略错误
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if(strings != null && !strings.isEmpty()){
|
|
|
+ strings.stream().filter(StringUtils::isNotEmpty).forEach(f -> syncPKeyIds.addAll(Arrays.asList(f.split(","))));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return syncPKeyIds;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public R<Object> getCollectTreeNode(String contractId, String tableOwner, Long folderId, String queryValue) {
|
|
|
+ if (StringUtils.isEmpty(contractId)) {
|
|
|
+ return R.fail(200, "合同段id错误");
|
|
|
+ }
|
|
|
+ if (folderId == null || folderId <= 0) {
|
|
|
+ return R.fail(200, "收藏夹不存在");
|
|
|
+ }
|
|
|
+ ContractInfo contractInfo = this.selectById(contractId);
|
|
|
+ if (contractInfo == null) {
|
|
|
+ return R.fail(200, "合同段不存在");
|
|
|
+ }
|
|
|
+ Set<String> syncPKeyIds = getSyncFlagIds(contractId, tableOwner);
|
|
|
+ List<ContractCollectFolder> contractCollectNodes = jdbcTemplate.query("select * from m_contract_collect_folder where type = 1 and parent_id = " + folderId, new BeanPropertyRowMapper<>(ContractCollectFolder.class));
|
|
|
+ if (!contractCollectNodes.isEmpty()) {
|
|
|
+ Set<Long> pKeyIds = new LinkedHashSet<>();
|
|
|
+ for (ContractCollectFolder node : contractCollectNodes) {
|
|
|
+ String ancestors = node.getNodeAncestors();
|
|
|
+ if (ancestors != null) {
|
|
|
+ String[] split = ancestors.split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ if (StringUtil.isNumeric(s)) {
|
|
|
+ pKeyIds.add(Long.parseLong(s));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pKeyIds.add(node.getNodeId());
|
|
|
+ }
|
|
|
+ List<WbsTreeContract> wbsTreeContractList = wbsTreeContractMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery().in(WbsTreeContract::getPKeyId, pKeyIds));
|
|
|
+ if (!wbsTreeContractList.isEmpty()) {
|
|
|
+ String pKeyIdStr = wbsTreeContractList.stream().map(item -> item.getPKeyId() + "").collect(Collectors.joining(","));
|
|
|
+ List<WbsTreeContractStatistics> wbsTreeContractStatisticsList = jdbcTemplate.query("select id, leaf_num, fill_num, approve_num, complete_num,jl_fill_num, jl_approve_num, jl_complete_num from m_wbs_tree_contract_statistics where id in (" + pKeyIdStr + ")",
|
|
|
+ new BeanPropertyRowMapper<>(WbsTreeContractStatistics.class));
|
|
|
+ Map<Long, WbsTreeContractStatistics> wbsTreeContractStatisticsMap = wbsTreeContractStatisticsList.stream().collect(Collectors.toMap(WbsTreeContractStatistics::getId, item -> item));
|
|
|
+ Map<String, List<WbsTreeContract>> contractGroupMap = wbsTreeContractList.stream().collect(Collectors.groupingBy(WbsTreeContract::getContractId));
|
|
|
+ Map<Long, List<WbsTreeContractTreeAllVO>> resultMaps = new LinkedHashMap<>();
|
|
|
+ contractGroupMap.forEach((cId, list) -> {
|
|
|
+ List<WbsTreeContractTreeAllVO> wbsTreeContractTreeAllVOS = list.stream()
|
|
|
+ .map(node -> {
|
|
|
+ WbsTreeContractTreeAllVO vo = BeanUtil.copyProperties(node, WbsTreeContractTreeAllVO.class);
|
|
|
+ if (vo != null) {
|
|
|
+ vo.setContractIdRelation(node.getContractId());
|
|
|
+ vo.setType(ObjectUtils.isNotEmpty(node.getNodeType()) ? node.getNodeType() : 0);
|
|
|
+ vo.setTitle(ObjectUtil.isNotEmpty(node.getFullName()) ? node.getFullName() : node.getNodeName());
|
|
|
+ vo.setPrimaryKeyId(node.getPKeyId());
|
|
|
+ WbsTreeContractStatistics statistics = wbsTreeContractStatisticsMap.get(node.getPKeyId());
|
|
|
+ if (statistics != null) {
|
|
|
+ Integer nums = statistics.calculateSubmitNums(tableOwner);
|
|
|
+ vo.setSubmitCounts(nums == null ? 0 : nums.longValue());
|
|
|
+ vo.setColorStatus(statistics.calculateColorStatus(tableOwner));
|
|
|
+ } else {
|
|
|
+ vo.setSubmitCounts(0L);
|
|
|
+ vo.setColorStatus(1);
|
|
|
+ }
|
|
|
+ if(CollectionUtil.isNotEmpty(syncPKeyIds)){
|
|
|
+ //判断是否展示同步标识
|
|
|
+ vo.setIsSync(syncPKeyIds.contains(vo.getPrimaryKeyId().toString()) ? 1 : 0);
|
|
|
+ }
|
|
|
+ vo.setIsCollect(1);
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ List<WbsTreeContractTreeAllVO> resultList = this.buildWbsTreeByStreamByTreeAll(wbsTreeContractTreeAllVOS);
|
|
|
+ if (StringUtil.hasText(queryValue)) {
|
|
|
+ resultMaps.put(Long.parseLong(cId), this.queryTreeResult(resultList, queryValue));
|
|
|
+ } else {
|
|
|
+ resultMaps.put(Long.parseLong(cId), resultList);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (contractInfo.getContractType() != null && contractInfo.getContractType() == 1) {
|
|
|
+ return R.data(resultMaps.get(contractInfo.getId()));
|
|
|
+ }
|
|
|
+ return R.data(resultMaps);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|