|
@@ -0,0 +1,590 @@
|
|
|
+package org.springblade.business.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.Data;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springblade.business.entity.InformationQuery;
|
|
|
+import org.springblade.business.entity.WbsTreeContractStatistics;
|
|
|
+import org.springblade.business.mapper.WbsTreeContractStatisticsMapper;
|
|
|
+import org.springblade.business.service.IWbsTreeContractStatisticsService;
|
|
|
+import org.springblade.core.tool.utils.BeanUtil;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.core.tool.utils.StringUtil;
|
|
|
+import org.springblade.manager.entity.ContractInfo;
|
|
|
+import org.springblade.manager.entity.WbsTreeContract;
|
|
|
+import org.springblade.manager.vo.WbsTreeContractLazyQueryInfoVO;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.support.TransactionTemplate;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class WbsTreeContractStatisticsServiceImpl extends ServiceImpl<WbsTreeContractStatisticsMapper, WbsTreeContractStatistics> implements IWbsTreeContractStatisticsService {
|
|
|
+
|
|
|
+ private final JdbcTemplate jdbcTemplate;
|
|
|
+ private final TransactionTemplate transactionTemplate;
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(WbsTreeContractStatisticsServiceImpl.class);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateInformationNumber(Long wbsId, Integer classify, Long contractId) {
|
|
|
+ InformationQuery query = getInformationQueryByWbsId(wbsId, classify, contractId);
|
|
|
+ if (query == null || query.getStatus() == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Integer status = query.getStatus();
|
|
|
+ WbsTreeContractStatistics contractStatistics = this.getById(wbsId);
|
|
|
+ if (contractStatistics == null) {
|
|
|
+ insertWbsTreeContractStatistics(wbsId, 0);
|
|
|
+ }
|
|
|
+ return transactionTemplate.execute(transactionStatus -> {
|
|
|
+ WbsTreeContractStatistics lock = this.baseMapper.getByIdOnLock(wbsId);
|
|
|
+ if (lock == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String ancestors = lock.getAncestors();
|
|
|
+ if (ancestors == null || !ancestors.isEmpty()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String[] ids = ancestors.split(",");
|
|
|
+ List<Long> collect = Arrays.stream(ids).filter(item -> !item.equals("0") && StringUtil.isNumeric(item)).map(Long::parseLong).collect(Collectors.toList());
|
|
|
+ if (classify == 1) {
|
|
|
+ // 施工
|
|
|
+ if (status == 0 || status == 3) {
|
|
|
+ // fill_num == 0 && approve_num == 0 && complete_num == 0 更新当前节点 set fill_num = 1, approve_num = 0, complete_num = 0 并更新父级节点 set fill_num = fill_num + 1
|
|
|
+ // fill_num == 1 && approve_num == 0 && complete_num == 0 不更新
|
|
|
+ // fill_num == 0 && approve_num == 1 && complete_num == 0 更新当前节点 set fill_num = 1, approve_num = 0, complete_num = 0 并更新父级节点 set fill_num = fill_num + 1, approve_num = approve_num - 1
|
|
|
+ // fill_num == 0 && approve_num == 0 && complete_num == 1 更新当前节点 set fill_num = 1, approve_num = 0, complete_num = 0 并更新父级节点 set fill_num = fill_num + 1, complete_num = complete_num - 1
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().eq(WbsTreeContractStatistics::getId, wbsId)
|
|
|
+ .set(WbsTreeContractStatistics::getFillNum, 1).set(WbsTreeContractStatistics::getApproveNum, 0).set(WbsTreeContractStatistics::getCompleteNum, 0));
|
|
|
+ if (lock.getFillNum() == 0 && lock.getApproveNum() == 0 && lock.getCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("fill_num = fill_num + 1"));
|
|
|
+ } else if (lock.getFillNum() == 0 && lock.getApproveNum() == 1 && lock.getCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("fill_num = fill_num + 1, approve_num = approve_num - 1"));
|
|
|
+ } else if (lock.getFillNum() == 0 && lock.getApproveNum() == 0 && lock.getCompleteNum() == 1) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("fill_num = fill_num + 1, complete_num = complete_num - 1"));
|
|
|
+ }
|
|
|
+ } else if (status == 1) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().eq(WbsTreeContractStatistics::getId, wbsId)
|
|
|
+ .set(WbsTreeContractStatistics::getFillNum, 0).set(WbsTreeContractStatistics::getApproveNum, 1).set(WbsTreeContractStatistics::getCompleteNum, 0));
|
|
|
+ if (lock.getFillNum() == 0 && lock.getApproveNum() == 0 && lock.getCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("approve_num = approve_num + 1"));
|
|
|
+ } else if (lock.getFillNum() == 1 && lock.getApproveNum() == 0 && lock.getCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("fill_num = fill_num - 1, approve_num = approve_num + 1"));
|
|
|
+ } else if (lock.getFillNum() == 0 && lock.getApproveNum() == 0 && lock.getCompleteNum() == 1) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("fill_num = fill_num + 1, complete_num = complete_num - 1"));
|
|
|
+ }
|
|
|
+ } else if (status == 2) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().eq(WbsTreeContractStatistics::getId, wbsId)
|
|
|
+ .set(WbsTreeContractStatistics::getFillNum, 0).set(WbsTreeContractStatistics::getApproveNum, 0).set(WbsTreeContractStatistics::getCompleteNum, 1));
|
|
|
+ if (lock.getFillNum() == 0 && lock.getApproveNum() == 0 && lock.getCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("complete_num = complete_num + 1"));
|
|
|
+ } else if (lock.getFillNum() == 1 && lock.getApproveNum() == 0 && lock.getCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("fill_num = fill_num - 1, complete_num = complete_num + 1"));
|
|
|
+ } else if (lock.getFillNum() == 0 && lock.getApproveNum() == 1 && lock.getCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("approve_num = approve_num - 1, complete_num = complete_num + 1"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (classify == 2) {
|
|
|
+ // 监理
|
|
|
+ if (status == 0 || status == 3) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().eq(WbsTreeContractStatistics::getId, wbsId)
|
|
|
+ .set(WbsTreeContractStatistics::getJlFillNum, 1).set(WbsTreeContractStatistics::getJlApproveNum, 0).set(WbsTreeContractStatistics::getJlCompleteNum, 0));
|
|
|
+ if (lock.getJlFillNum() == 0 && lock.getJlApproveNum() == 0 && lock.getJlCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("jl_fill_num = jl_fill_num + 1"));
|
|
|
+ } else if (lock.getJlFillNum() == 0 && lock.getJlApproveNum() == 1 && lock.getJlCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("jl_fill_num = jl_fill_num + 1, jl_approve_num = jl_approve_num - 1"));
|
|
|
+ } else if (lock.getJlFillNum() == 0 && lock.getJlApproveNum() == 0 && lock.getJlCompleteNum() == 1) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("jl_fill_num = jl_fill_num + 1, jl_complete_num = jl_complete_num - 1"));
|
|
|
+ }
|
|
|
+ } else if (status == 1) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().eq(WbsTreeContractStatistics::getId, wbsId)
|
|
|
+ .set(WbsTreeContractStatistics::getJlFillNum, 0).set(WbsTreeContractStatistics::getJlApproveNum, 1).set(WbsTreeContractStatistics::getJlCompleteNum, 0));
|
|
|
+ if (lock.getJlFillNum() == 0 && lock.getJlApproveNum() == 0 && lock.getJlCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("jl_approve_num = jl_approve_num + 1"));
|
|
|
+ } else if (lock.getJlFillNum() == 1 && lock.getJlApproveNum() == 0 && lock.getJlCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("jl_fill_num = jl_fill_num - 1, jl_approve_num = jl_approve_num + 1"));
|
|
|
+ } else if (lock.getJlFillNum() == 0 && lock.getJlApproveNum() == 0 && lock.getJlCompleteNum() == 1) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("jl_approve_num = jl_approve_num - 1, jl_complete_num = jl_complete_num + 1"));
|
|
|
+ }
|
|
|
+ } else if (status == 2) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().eq(WbsTreeContractStatistics::getId, wbsId)
|
|
|
+ .set(WbsTreeContractStatistics::getJlFillNum, 0).set(WbsTreeContractStatistics::getJlApproveNum, 0).set(WbsTreeContractStatistics::getJlCompleteNum, 1));
|
|
|
+ if (lock.getJlFillNum() == 0 && lock.getJlApproveNum() == 0 && lock.getJlCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("jl_complete_num = jl_complete_num + 1"));
|
|
|
+ } else if (lock.getJlFillNum() == 1 && lock.getJlApproveNum() == 0 && lock.getJlCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("jl_fill_num = jl_fill_num - 1, jl_complete_num = jl_complete_num + 1"));
|
|
|
+ } else if (lock.getJlFillNum() == 0 && lock.getJlApproveNum() == 1 && lock.getJlCompleteNum() == 0) {
|
|
|
+ this.update(Wrappers.<WbsTreeContractStatistics>lambdaUpdate().in(WbsTreeContractStatistics::getId, collect).setSql("jl_approve_num = jl_approve_num - 1, jl_complete_num = jl_complete_num + 1"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public Boolean insertWbsTreeContractStatistics(Long wbsTreeContractPkeyId, Integer isDelete) {
|
|
|
+ if (isDelete == 1) {
|
|
|
+ return this.removeById(wbsTreeContractPkeyId);
|
|
|
+ }
|
|
|
+ WbsTreeContract wbsTreeContract = getWbsTreeContractByPKeyId(wbsTreeContractPkeyId);
|
|
|
+ if (wbsTreeContract == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ WbsTreeContractStatistics wbsTreeContractStatistics = this.getById(wbsTreeContractPkeyId);
|
|
|
+ if (wbsTreeContractStatistics != null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ wbsTreeContractStatistics = createWbsTreeContractStatistics(wbsTreeContract);
|
|
|
+ // 查询父级节点存不存在,不存在则创建
|
|
|
+ List<WbsTreeContractStatistics> parentList = new ArrayList<>();
|
|
|
+ createWbsTreeContractStatisticsParent(wbsTreeContract, wbsTreeContractStatistics, parentList);
|
|
|
+ if (!parentList.isEmpty()) {
|
|
|
+ for (int i = 1; i < parentList.size(); i++) {
|
|
|
+ WbsTreeContractStatistics statistics = parentList.get(i);
|
|
|
+ WbsTreeContractStatistics parent = parentList.get(i - 1);
|
|
|
+ if (parent != null && StringUtil.hasText(parent.getAncestors())) {
|
|
|
+ statistics.setAncestors(parent.getAncestors() + "," + parent.getId());
|
|
|
+ statistics.setParentId(parent.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 查询有没有子节点,子节点是否存在
|
|
|
+ createWbsTreeContractStatisticsChildren(wbsTreeContract, wbsTreeContractStatistics, parentList);
|
|
|
+ parentList.add(wbsTreeContractStatistics);
|
|
|
+ saveBatch(parentList);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean recycleWbsTreeContractStatistics(Long pKeyId) {
|
|
|
+ WbsTreeContractStatistics wbsTreeContractStatistics = this.baseMapper.getByIdOnIgnoreDeleted(pKeyId);
|
|
|
+ if (wbsTreeContractStatistics == null) {
|
|
|
+ insertWbsTreeContractStatistics(pKeyId, 0);
|
|
|
+ }
|
|
|
+ return this.baseMapper.updateDeleteStatus(pKeyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void createWbsTreeContractStatisticsParent(WbsTreeContract wbsTreeContract, WbsTreeContractStatistics wbsTreeContractStatistics, List<WbsTreeContractStatistics> wbsTreeContractStatisticsList) {
|
|
|
+ if (wbsTreeContract.getParentId() == null || wbsTreeContract.getParentId() <= 0) {
|
|
|
+ wbsTreeContractStatistics.setParentId(0L);
|
|
|
+ wbsTreeContractStatistics.setAncestors("");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ WbsTreeContractStatistics parent = this.getById(wbsTreeContractStatistics.getParentId());
|
|
|
+ if (parent == null) {
|
|
|
+ WbsTreeContract wbsTreeContractParent = getWbsTreeContractByPKeyId(wbsTreeContractStatistics.getParentId());
|
|
|
+ if (wbsTreeContractParent == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ parent = createWbsTreeContractStatistics(wbsTreeContractParent);
|
|
|
+ createWbsTreeContractStatisticsParent(wbsTreeContractParent, parent, wbsTreeContractStatisticsList);
|
|
|
+ wbsTreeContractStatisticsList.add(parent);
|
|
|
+ } else {
|
|
|
+ if (StringUtil.hasText(wbsTreeContract.getAncestors())) {
|
|
|
+ wbsTreeContractStatistics.setParentId(parent.getId());
|
|
|
+ wbsTreeContractStatistics.setAncestors(parent.getAncestors() + "," + parent.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void createWbsTreeContractStatisticsChildren(WbsTreeContract wbsTreeContract, WbsTreeContractStatistics wbsTreeContractStatistics, List<WbsTreeContractStatistics> wbsTreeContractStatisticsList) {
|
|
|
+ List<WbsTreeContract> wbsTreeContracts = jdbcTemplate.query("select * from m_wbs_tree_contract where is_deleted = 0 and type = 1 and contract_id = ? and p_id = ?",
|
|
|
+ new Object[]{wbsTreeContract.getContractId(), wbsTreeContract.getPKeyId()}, new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
+ if (wbsTreeContracts == null || wbsTreeContracts.isEmpty()) {
|
|
|
+ wbsTreeContractStatistics.setIsLeaf(1);
|
|
|
+ wbsTreeContractStatistics.setLeafNum(0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ wbsTreeContracts.forEach(item -> {
|
|
|
+ WbsTreeContractStatistics statistics = createWbsTreeContractStatistics(item);
|
|
|
+ createWbsTreeContractStatisticsChildren(item, wbsTreeContractStatistics, wbsTreeContractStatisticsList);
|
|
|
+ statistics.setAncestors(wbsTreeContractStatistics.getAncestors() + "," + wbsTreeContractStatistics.getId());
|
|
|
+ statistics.setParentId(wbsTreeContractStatistics.getId());
|
|
|
+ wbsTreeContractStatisticsList.add(statistics);
|
|
|
+ int num = wbsTreeContractStatistics.getLeafNum() == null ? 0 : wbsTreeContractStatistics.getLeafNum();
|
|
|
+ int i = statistics.getLeafNum() == 0 ? 1 : statistics.getLeafNum();
|
|
|
+ wbsTreeContractStatistics.setLeafNum(num + i);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步
|
|
|
+ */
|
|
|
+ public void sync() {
|
|
|
+ List<ContractInfo> contractInfos = jdbcTemplate.query("select id from m_contract_info where is_deleted = 0 and p_id in (select id from m_project_info where is_deleted = 0)", new BeanPropertyRowMapper<>(ContractInfo.class));
|
|
|
+ if (contractInfos.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (ContractInfo contractInfo : contractInfos) {
|
|
|
+ statisticsContract(contractInfo.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void statisticsContract(Long contractId) {
|
|
|
+ try {
|
|
|
+ List<WbsTreeContract> wbsTreeContracts = jdbcTemplate.query("select * from m_wbs_tree_contract where is_deleted = 0 and type = 1 and status = 1 and contract_id = ? ",
|
|
|
+ new Object[]{contractId}, new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
+
|
|
|
+ List<WbsTreeContractStatistics> addWbsTreeContractStatistics = new ArrayList<>(wbsTreeContracts.size());
|
|
|
+ {
|
|
|
+ List<WbsTreeContractDto> contractDtoList = chickTreeAncestors(wbsTreeContracts);
|
|
|
+ for (WbsTreeContractDto dto : contractDtoList) {
|
|
|
+ addWbsTreeContractStatistics.add(createWbsTreeContractStatistics(dto));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 统计叶子节点数量
|
|
|
+// countLeafNum(addWbsTreeContractStatistics);
|
|
|
+ useIsLeafFieldCountLeafNum(addWbsTreeContractStatistics);
|
|
|
+ countInformationNumber(addWbsTreeContractStatistics, contractId);
|
|
|
+ List<WbsTreeContractStatistics> updateWbsTreeContractStatistics = new ArrayList<>();
|
|
|
+ List<WbsTreeContractStatistics> wbsTreeContractStatistics = this.list(Wrappers.<WbsTreeContractStatistics>lambdaQuery().eq(WbsTreeContractStatistics::getContractId, contractId).eq(WbsTreeContractStatistics::getIsDeleted, 0));
|
|
|
+ Map<Long, WbsTreeContractStatistics> map = wbsTreeContractStatistics.stream().collect(Collectors.toMap(WbsTreeContractStatistics::getId, v -> v));
|
|
|
+ addWbsTreeContractStatistics.removeIf(item -> {
|
|
|
+ WbsTreeContractStatistics statistics = map.get(item.getId());
|
|
|
+ if (statistics == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (updateWbsTreeContractStatisticsFields(statistics, item)) {
|
|
|
+ updateWbsTreeContractStatistics.add(item);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+ if (!addWbsTreeContractStatistics.isEmpty()) {
|
|
|
+ saveBatch(addWbsTreeContractStatistics);
|
|
|
+ }
|
|
|
+ if (!updateWbsTreeContractStatistics.isEmpty()) {
|
|
|
+ updateBatchById(updateWbsTreeContractStatistics);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("更新合同段wbs树统计信息异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean updateWbsTreeContractStatisticsFields(WbsTreeContractStatistics old, WbsTreeContractStatistics newObj) {
|
|
|
+ boolean result = false;
|
|
|
+ if (ObjectUtil.nullSafeEquals(old.getParentId(), newObj.getParentId())) {
|
|
|
+ newObj.setParentId(null);
|
|
|
+ } else {
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ if (ObjectUtil.nullSafeEquals(old.getAncestors(), newObj.getAncestors())) {
|
|
|
+ newObj.setAncestors(null);
|
|
|
+ } else {
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ if (ObjectUtil.nullSafeEquals(old.getIsLeaf(), newObj.getIsLeaf())) {
|
|
|
+ newObj.setIsLeaf(null);
|
|
|
+ } else {
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ if (ObjectUtil.nullSafeEquals(old.getLeafNum(), newObj.getLeafNum())) {
|
|
|
+ newObj.setLeafNum(null);
|
|
|
+ } else {
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ if (ObjectUtil.nullSafeEquals(old.getFillNum(), newObj.getFillNum())) {
|
|
|
+ newObj.setFillNum(null);
|
|
|
+ } else {
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ if (ObjectUtil.nullSafeEquals(old.getApproveNum(), newObj.getApproveNum())) {
|
|
|
+ newObj.setApproveNum(null);
|
|
|
+ } else {
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ if (ObjectUtil.nullSafeEquals(old.getCompleteNum(), newObj.getCompleteNum())) {
|
|
|
+ newObj.setCompleteNum(null);
|
|
|
+ } else {
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ if (ObjectUtil.nullSafeEquals(old.getJlFillNum(), newObj.getJlFillNum())) {
|
|
|
+ newObj.setJlFillNum(null);
|
|
|
+ } else {
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ if (ObjectUtil.nullSafeEquals(old.getJlApproveNum(), newObj.getJlApproveNum())) {
|
|
|
+ newObj.setJlApproveNum(null);
|
|
|
+ } else {
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ if (ObjectUtil.nullSafeEquals(old.getJlCompleteNum(), newObj.getJlCompleteNum())) {
|
|
|
+ newObj.setJlCompleteNum(null);
|
|
|
+ } else {
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ newObj.setStatus(null);
|
|
|
+ newObj.setIsDeleted(null);
|
|
|
+ newObj.setCreateTime(null);
|
|
|
+ newObj.setUpdateTime(null);
|
|
|
+ newObj.setProjectId( null);
|
|
|
+ newObj.setContractId( null);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ private void countInformationNumber(List<WbsTreeContractStatistics> wbsTreeContractStatistics, Long contractId) {
|
|
|
+ if (wbsTreeContractStatistics == null || wbsTreeContractStatistics.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 统计已填报,待审批,已审批数量
|
|
|
+ List<WbsTreeContractLazyQueryInfoVO> sgQueryInfoList = jdbcTemplate.query(
|
|
|
+ "SELECT wbs_id, `status` FROM u_information_query WHERE id in (SELECT id from (SELECT max(id) as id FROM u_information_query WHERE is_deleted = 0 AND type = 1 AND contract_id = ? AND classify = ? GROUP BY wbs_id) as a)",
|
|
|
+ new Object[]{contractId, 1},
|
|
|
+ new BeanPropertyRowMapper<>(WbsTreeContractLazyQueryInfoVO.class));
|
|
|
+ List<WbsTreeContractLazyQueryInfoVO> jlQueryInfoList = jdbcTemplate.query(
|
|
|
+ "SELECT wbs_id, `status` FROM u_information_query WHERE id in (SELECT id from (SELECT max(id) as id FROM u_information_query WHERE is_deleted = 0 AND type = 1 AND contract_id = ? AND classify = ? GROUP BY wbs_id) as a)",
|
|
|
+ new Object[]{contractId, 2},
|
|
|
+ new BeanPropertyRowMapper<>(WbsTreeContractLazyQueryInfoVO.class));
|
|
|
+ if (sgQueryInfoList.isEmpty() && jlQueryInfoList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<Long, WbsTreeContractStatistics> map = wbsTreeContractStatistics.stream().collect(Collectors.toMap(WbsTreeContractStatistics::getId, item -> item, (k1, k2) -> k1));
|
|
|
+ Map<Long, Map<Integer, AtomicInteger>> sgStatisticsMap = countInformation(sgQueryInfoList, map);
|
|
|
+ Map<Long, Map<Integer, AtomicInteger>> jlStatisticsMap = countInformation(jlQueryInfoList, map);
|
|
|
+ wbsTreeContractStatistics.forEach(item -> {
|
|
|
+ Map<Integer, AtomicInteger> sgStatusMap = sgStatisticsMap.get(item.getId());
|
|
|
+ if (sgStatusMap != null && !sgStatusMap.isEmpty()) {
|
|
|
+ AtomicInteger integer = sgStatusMap.get(0);
|
|
|
+ if (integer != null) {
|
|
|
+ item.setFillNum(integer.get());
|
|
|
+ }
|
|
|
+ integer = sgStatusMap.get(1);
|
|
|
+ if (integer != null) {
|
|
|
+ item.setApproveNum(integer.get());
|
|
|
+ }
|
|
|
+ integer = sgStatusMap.get(2);
|
|
|
+ if (integer != null) {
|
|
|
+ item.setCompleteNum(integer.get());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<Integer, AtomicInteger> jlStatusMap = jlStatisticsMap.get(item.getId());
|
|
|
+ if (jlStatusMap != null && !jlStatusMap.isEmpty()) {
|
|
|
+ AtomicInteger integer = jlStatusMap.get(0);
|
|
|
+ if (integer != null) {
|
|
|
+ item.setJlFillNum(integer.get());
|
|
|
+ }
|
|
|
+ integer = jlStatusMap.get(1);
|
|
|
+ if (integer != null) {
|
|
|
+ item.setJlApproveNum(integer.get());
|
|
|
+ }
|
|
|
+ integer = jlStatusMap.get(2);
|
|
|
+ if (integer != null) {
|
|
|
+ item.setJlCompleteNum(integer.get());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<Long, Map<Integer, AtomicInteger>> countInformation(List<WbsTreeContractLazyQueryInfoVO> queryInfoList, Map<Long, WbsTreeContractStatistics> map) {
|
|
|
+ if (queryInfoList == null || queryInfoList.isEmpty()) {
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+ Map<Long, Map<Integer, AtomicInteger>> statisticsMap = new HashMap<>();
|
|
|
+ Map<Long, Integer> sgStatusMap = queryInfoList.stream().peek(item -> {
|
|
|
+ if (item.getStatus() == null || item.getStatus() == 3) {
|
|
|
+ item.setStatus(0);
|
|
|
+ }
|
|
|
+ }).collect(Collectors.toMap(WbsTreeContractLazyQueryInfoVO::getWbsId, WbsTreeContractLazyQueryInfoVO::getStatus));
|
|
|
+ sgStatusMap.forEach((wbsId, status) -> {
|
|
|
+ put(wbsId, status, statisticsMap);
|
|
|
+ WbsTreeContractStatistics statistics = map.get(wbsId);
|
|
|
+ if (statistics == null || statistics.getAncestors() == null || statistics.getAncestors().isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String[] split = statistics.getAncestors().split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ if (!StringUtil.isNumeric(s)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long id = Long.parseLong(s);
|
|
|
+ put(id, status, statisticsMap);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return statisticsMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void put(Long wbsId, Integer status, Map<Long, Map<Integer, AtomicInteger>> statisticsMap) {
|
|
|
+ Map<Integer, AtomicInteger> map = statisticsMap.get(wbsId);
|
|
|
+ if (map == null) {
|
|
|
+ map = new HashMap<>();
|
|
|
+ }
|
|
|
+ AtomicInteger count = map.get(status);
|
|
|
+ if (count == null) {
|
|
|
+ count = new AtomicInteger(0);
|
|
|
+ }
|
|
|
+ count.incrementAndGet();
|
|
|
+ map.put(status, count);
|
|
|
+ statisticsMap.put(wbsId, map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统计叶子节点数量 - 全量
|
|
|
+ */
|
|
|
+ public void countLeafNum(List<WbsTreeContractStatistics> wbsTreeContractStatistics) {
|
|
|
+ Map<Long, List<WbsTreeContractStatistics>> map = wbsTreeContractStatistics.stream().peek(item -> {
|
|
|
+ if (item.getParentId() == null) {
|
|
|
+ item.setParentId(0L);
|
|
|
+ }
|
|
|
+ }).collect(Collectors.groupingBy(WbsTreeContractStatistics::getParentId));
|
|
|
+ List<WbsTreeContractStatistics> list = map.get(0L);
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
+ list.forEach(item -> item.setLeafNum(countLeafNum(map.get(item.getId()), map)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public Integer countLeafNum(List<WbsTreeContractStatistics> wbsTreeContracts, Map<Long, List<WbsTreeContractStatistics>> map) {
|
|
|
+ if (wbsTreeContracts == null || wbsTreeContracts.isEmpty()) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ wbsTreeContracts.forEach(item -> item.setLeafNum(countLeafNum(map.get(item.getId()), map)));
|
|
|
+ return wbsTreeContracts.stream().mapToInt(item -> item.getLeafNum() == null || item.getLeafNum() == 0 ? 1 :item.getLeafNum()).sum();
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 统计叶子节点数量 - 全量
|
|
|
+ */
|
|
|
+ public void useIsLeafFieldCountLeafNum(List<WbsTreeContractStatistics> wbsTreeContractStatistics) {
|
|
|
+ Map<Long, AtomicInteger> countMap = new HashMap<>();
|
|
|
+ Map<Long, WbsTreeContractStatistics> map = wbsTreeContractStatistics.stream().peek(item -> {
|
|
|
+ if (item.getIsLeaf() != null && item.getIsLeaf() == 1 && StringUtil.hasText(item.getAncestors())) {
|
|
|
+ String[] split = item.getAncestors().split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ if (s != null && !s.isEmpty()) {
|
|
|
+ long id = Long.parseLong(s);
|
|
|
+ if (id == 0) continue;
|
|
|
+ AtomicInteger num = countMap.get(id);
|
|
|
+ if (num == null) {
|
|
|
+ num = new AtomicInteger(0);
|
|
|
+ }
|
|
|
+ num.incrementAndGet();
|
|
|
+ countMap.put(id, num);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).collect(Collectors.toMap(WbsTreeContractStatistics::getId, item -> item, (k1, k2) -> k1));
|
|
|
+ countMap.forEach((k, v) -> {
|
|
|
+ WbsTreeContractStatistics statistics = map.get(k);
|
|
|
+ if (statistics != null) {
|
|
|
+ statistics.setLeafNum(v.get());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<WbsTreeContractDto> chickTreeAncestors(List<WbsTreeContract> wbsTreeContracts) {
|
|
|
+ if (wbsTreeContracts == null || wbsTreeContracts.isEmpty()) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<WbsTreeContractDto> contractNodes = wbsTreeContracts.stream().map(item -> BeanUtil.copyProperties(item, WbsTreeContractDto.class)).collect(Collectors.toList());
|
|
|
+ {
|
|
|
+ Map<Long, List<WbsTreeContractDto>> mapByParentId = contractNodes.stream().peek(item -> {
|
|
|
+ if (item.getParentId() == null) {
|
|
|
+ item.setParentId(0L);
|
|
|
+ }
|
|
|
+ if (item.getPId() == null) {
|
|
|
+ item.setPId(0L);
|
|
|
+ }
|
|
|
+ }).collect(Collectors.groupingBy(WbsTreeContractDto::getParentId));
|
|
|
+ List<WbsTreeContractDto> list = mapByParentId.get(0L);
|
|
|
+ list.forEach(item -> item.setAncestorsByParentId("0"));
|
|
|
+ Queue<WbsTreeContractDto> queue = new LinkedList<>(list);
|
|
|
+ while (!queue.isEmpty()) {
|
|
|
+ WbsTreeContractDto poll = queue.poll();
|
|
|
+ List<WbsTreeContractDto> children = mapByParentId.get(poll.getId());
|
|
|
+ if (children != null && !children.isEmpty()) {
|
|
|
+ for (WbsTreeContractDto child : children) {
|
|
|
+ child.setAncestorsByParentId(poll.getAncestorsByParentId() + "," + poll.getPKeyId());
|
|
|
+ child.setTempPId(poll.getPKeyId());
|
|
|
+ queue.offer(child);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ poll.setIsLeaf(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+// {
|
|
|
+// Map<Long, List<WbsTreeContractDto>> mapByParentId = contractNodes.stream().collect(Collectors.groupingBy(WbsTreeContractDto::getPId));
|
|
|
+// List<WbsTreeContractDto> list = mapByParentId.get(0L);
|
|
|
+// list.forEach(item -> item.setAncestorsByPid("0"));
|
|
|
+// Queue<WbsTreeContractDto> queue = new LinkedList<>(list);
|
|
|
+// while (!queue.isEmpty()) {
|
|
|
+// WbsTreeContractDto poll = queue.poll();
|
|
|
+// List<WbsTreeContractDto> children = mapByParentId.get(poll.getPKeyId());
|
|
|
+// if (children != null && !children.isEmpty()) {
|
|
|
+// for (WbsTreeContractDto child : children) {
|
|
|
+// child.setAncestorsByPid(poll.getAncestorsByPid() + "," + poll.getPKeyId());
|
|
|
+// queue.offer(child);
|
|
|
+// }
|
|
|
+// }else {
|
|
|
+// poll.setIsLeaf(1);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// for (WbsTreeContractDto node : contractNodes) {
|
|
|
+// if (!StringUtil.equals(node.getAncestorsByParentId(), node.getAncestorsByPid())) {
|
|
|
+// log.error("数据错误:" + node);
|
|
|
+// } else if (!StringUtil.equals(node.getAncestorsByParentId(), node.getAncestors())){
|
|
|
+// log.error("数据错误:" + node + " ancestorsPid=" + node.getAncestorsPId());
|
|
|
+// }
|
|
|
+// }
|
|
|
+ return contractNodes;
|
|
|
+ }
|
|
|
+
|
|
|
+ private WbsTreeContract getWbsTreeContractByPKeyId(Long pKeyId) {
|
|
|
+ List<WbsTreeContract> query = jdbcTemplate.query("select * from m_wbs_tree_contract where p_key_id = ?", new Object[]{pKeyId}, new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
|
+ if (!query.isEmpty()) {
|
|
|
+ return query.get(0);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private WbsTreeContractStatistics createWbsTreeContractStatistics(WbsTreeContract wbsTreeContract) {
|
|
|
+ return new WbsTreeContractStatistics(wbsTreeContract.getPKeyId(), wbsTreeContract.getProjectId(), wbsTreeContract.getContractId(), wbsTreeContract.getParentId(), wbsTreeContract.getAncestors());
|
|
|
+ }
|
|
|
+ private WbsTreeContractStatistics createWbsTreeContractStatistics(WbsTreeContractDto wbsTreeContract) {
|
|
|
+ return new WbsTreeContractStatistics(wbsTreeContract.getPKeyId(), wbsTreeContract.getProjectId(), wbsTreeContract.getContractId(), wbsTreeContract.getTempPId(), wbsTreeContract.getAncestorsByParentId(), wbsTreeContract.getIsLeaf());
|
|
|
+ }
|
|
|
+
|
|
|
+ private InformationQuery getInformationQueryByWbsId(Long wbsId, Integer classify, Long contractId) {
|
|
|
+ List<InformationQuery> queryList = jdbcTemplate.query(
|
|
|
+ "SELECT wbs_id, classify, `status` FROM u_information_query WHERE id in (SELECT id from (SELECT max(id) as id FROM u_information_query WHERE is_deleted = 0 AND type = 1 AND contract_id = ? AND classify = ? and wbs_id = ?) as a)",
|
|
|
+ new Object[]{contractId, classify, wbsId},
|
|
|
+ new BeanPropertyRowMapper<>(InformationQuery.class));
|
|
|
+ if (!queryList.isEmpty()) {
|
|
|
+ return queryList.get(0);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ private static class WbsTreeContractDto extends WbsTreeContract {
|
|
|
+ private List<WbsTreeContractDto> children;
|
|
|
+ private String ancestorsByParentId;
|
|
|
+ private String ancestorsByPid;
|
|
|
+ private Long tempPId;
|
|
|
+ // 1 是叶子节点, 0 不是叶子节点
|
|
|
+ private Integer isLeaf = 0;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return "WbsTreeContractDto{" +
|
|
|
+ "pKeyId=" + super.getPKeyId() +
|
|
|
+ ", pId=" + super.getPId() +
|
|
|
+ ", parentId=" + super.getParentId() +
|
|
|
+ ", id=" + super.getId() +
|
|
|
+ ", ancestorsByParentId='" + ancestorsByParentId + '\'' +
|
|
|
+ ", ancestorsByPid='" + ancestorsByPid + '\'' +
|
|
|
+ '}';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|