From ae086bc3ad6f785e6368b84e57a7e199c675779b Mon Sep 17 00:00:00 2001 From: liusheng <337615773@qq.com> Date: 星期三, 02 四月 2025 11:42:28 +0800 Subject: [PATCH] 代码提交 --- smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskDetailServiceImpl.java | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 48 insertions(+), 3 deletions(-) diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskDetailServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskDetailServiceImpl.java index 292ff61..706566b 100644 --- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskDetailServiceImpl.java +++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskDetailServiceImpl.java @@ -4,10 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; -import com.smartor.domain.ServiceSubtask; +import com.smartor.domain.*; import com.smartor.domain.ServiceSubtaskDetail; -import com.smartor.domain.ServiceSubtaskDetail; -import com.smartor.domain.ServiceTask; import com.smartor.mapper.ServiceSubtaskDetailMapper; import com.smartor.mapper.ServiceSubtaskMapper; import com.smartor.service.IServiceSubtaskDetailService; @@ -17,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; @@ -234,4 +234,49 @@ return serviceTaskMap; } + + /* + * @param targetid + * @return 鎸囨爣缁熻 + */ + @Override + public List<ServiceSubtaskDetailTarget> countPatByTarget(Long targetid) { + List<ServiceSubtaskDetailTarget> serviceSubtaskDetailTargets = ServiceSubtaskDetailMapper.countPatByTarget(targetid); + if (CollectionUtils.isNotEmpty(serviceSubtaskDetailTargets)) { + Long totalCount = serviceSubtaskDetailTargets.stream().filter(target -> target.getMatchedtext() == null || target.getMatchedtext().isEmpty()).mapToLong(target -> target.getCount() != null ? target.getCount() : 0) // 纭繚 count 涓� 0 濡傛灉涓� null + .sum(); + + Long allShowCount = 0L; + + // 閬嶅巻鍒楄〃锛屽皢 matchedText 涓�""璧嬪�肩粰 null + for (ServiceSubtaskDetailTarget target : serviceSubtaskDetailTargets) { + if (target.getMatchedtext() == null) { + target.setCount(target.getCount() != null ? target.getCount() + totalCount : totalCount); // 缁� matchedText 涓� null 鐨勫璞¤祴鍊� + } + //鍏佽null鐩稿姞锛屼笉鍏佽""鐩稿姞 + if (target.getMatchedtext() == null || !target.getMatchedtext().isEmpty()) { + allShowCount = allShowCount + target.getCount(); + } + } + + // 浣跨敤杩唬鍣ㄥ垹闄� matchedText 涓� "" 鐨勫璞� + Iterator<ServiceSubtaskDetailTarget> iterator = serviceSubtaskDetailTargets.iterator(); + while (iterator.hasNext()) { + ServiceSubtaskDetailTarget target = iterator.next(); + if (target.getMatchedtext() != null && target.getMatchedtext().isEmpty()) { + iterator.remove(); // 鍒犻櫎 matchedText 涓� "" 鐨勫璞� + } + } + for (ServiceSubtaskDetailTarget target : serviceSubtaskDetailTargets) { + target.setTargetShowCount(allShowCount.toString()); + BigDecimal count = new BigDecimal(target.getCount() != null ? target.getCount().toString() : "0"); + BigDecimal allCount = new BigDecimal(allShowCount.toString()); + if (allCount.compareTo(BigDecimal.ZERO) == 0) + target.setPercentage(count.divide(allCount, 2, RoundingMode.HALF_UP).toString()); + } + } + + return serviceSubtaskDetailTargets; + } + } -- Gitblit v1.9.3