Browse Source

百分比

master
zxc 5 years ago
parent
commit
be8b47a820
  1. 5
      epmet-module/data-report/data-report-client/src/main/java/com/epmet/topic/dto/result/TopicSummaryInfoResultDTO.java
  2. 17
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/service/topic/impl/TopicServiceImpl.java
  3. 2
      epmet-module/data-report/data-report-server/src/main/resources/mapper/topic/TopicDao.xml

5
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;
}

17
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);
}

2
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

Loading…
Cancel
Save