diff --git a/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSummaryInfoResultDTO.java b/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSummaryInfoResultDTO.java index 71b096ca0f..b007c41289 100644 --- a/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSummaryInfoResultDTO.java +++ b/epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSummaryInfoResultDTO.java @@ -1,8 +1,10 @@ package com.epmet.topic.dto.result; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import java.io.Serializable; +import java.math.BigDecimal; /** * @Author zxc @@ -27,4 +29,7 @@ public class TopicSummaryInfoResultDTO implements Serializable { * 百分比 */ private String ratio = "0.0%"; + + @JsonIgnore + private BigDecimal pro; } diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java index 8c4309dfd6..339737305e 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java @@ -14,7 +14,9 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; import java.text.DecimalFormat; +import java.text.NumberFormat; import java.time.LocalDate; import java.util.*; import java.util.stream.Collectors; @@ -187,12 +189,19 @@ public class TopicServiceImpl implements TopicService { TopicShiftedCountResultDTO shiftedCount = topicDao.getShiftedCount(agencyId); if (topicSummaryInfo.size() != NumConstant.ZERO && shiftedCount != null) { Integer collect = topicSummaryInfo.stream().collect(Collectors.summingInt(TopicSummaryInfoResultDTO::getValue)); - DecimalFormat decimalFormat = new DecimalFormat(".00"); - String ratio; - ratio = collect == NumConstant.ZERO ? NumConstant.ZERO + TopicConstant.RATIO : decimalFormat.format(((float) shiftedCount.getShiftedIssueCount() / (float) collect) * NumConstant.ONE_HUNDRED) + TopicConstant.RATIO; + topicSummaryInfo.forEach(topic -> { + String s = topic.getPro().setScale(NumConstant.TWO, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString(); + topic.setRatio(s.concat(TopicConstant.RATIO)); + }); TopicSummaryInfoResultDTO result = new TopicSummaryInfoResultDTO(); + if (collect == NumConstant.ZERO){ + result.setRatio(NumConstant.ZERO+TopicConstant.RATIO); + }else { + BigDecimal bigDecimal = new BigDecimal(((float) shiftedCount.getShiftedIssueCount() / (float) collect) * NumConstant.ONE_HUNDRED); + String s = bigDecimal.setScale(NumConstant.TWO, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString(); + result.setRatio(s.concat(TopicConstant.RATIO)); + } result.setName(TopicConstant.SHIFTED); - result.setRatio(ratio); result.setValue(shiftedCount.getShiftedIssueCount()); topicSummaryInfo.add(result); } diff --git a/epmet-module/data-report/data-report-server/src/main/resources/mapper/topic/TopicDao.xml b/epmet-module/data-report/data-report-server/src/main/resources/mapper/topic/TopicDao.xml index 29ddddc6c6..01d4a5d335 100644 --- a/epmet-module/data-report/data-report-server/src/main/resources/mapper/topic/TopicDao.xml +++ b/epmet-module/data-report/data-report-server/src/main/resources/mapper/topic/TopicDao.xml @@ -41,7 +41,7 @@ WHEN topic_status_id = 'hidden' THEN '已屏蔽' WHEN topic_status_id = 'closed' THEN '已关闭' ELSE '无' END) AS name, - CONCAT(ROUND(topic_proportion * 100,2),'%') AS ratio + (topic_proportion * 100) AS pro FROM fact_topic_status_agency_daily WHERE