|
@@ -101,33 +101,87 @@ public class PublicOpinionServiceImpl implements IPublicOpinionService {
|
|
|
public Map<String, Object> selectOpinionStats() {
|
|
public Map<String, Object> selectOpinionStats() {
|
|
|
LambdaQueryWrapper<PublicOpinion> wrapper = Wrappers.lambdaQuery();
|
|
LambdaQueryWrapper<PublicOpinion> wrapper = Wrappers.lambdaQuery();
|
|
|
wrapper.eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL);
|
|
wrapper.eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL);
|
|
|
- long total = baseMapper.selectCount(wrapper);
|
|
|
|
|
- long pending = baseMapper.selectCount(wrapper.clone()
|
|
|
|
|
- .in(PublicOpinion::getProcessStatus, List.of("0", "1")));
|
|
|
|
|
- long processed = baseMapper.selectCount(wrapper.clone()
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 今日数据
|
|
|
|
|
+ Calendar todayCal = Calendar.getInstance();
|
|
|
|
|
+ String today = new SimpleDateFormat("yyyy-MM-dd").format(todayCal.getTime());
|
|
|
|
|
+ LambdaQueryWrapper<PublicOpinion> todayWrapper = Wrappers.lambdaQuery()
|
|
|
|
|
+ .eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL)
|
|
|
|
|
+ .likeRight(PublicOpinion::getPublishTime, today);
|
|
|
|
|
+ long todayTotal = baseMapper.selectCount(todayWrapper);
|
|
|
|
|
+ long todayMajor = baseMapper.selectCount(todayWrapper.clone()
|
|
|
|
|
+ .eq(PublicOpinion::getRiskLevel, "重大"));
|
|
|
|
|
+ long todayProcessed = baseMapper.selectCount(todayWrapper.clone()
|
|
|
.eq(PublicOpinion::getProcessStatus, "2"));
|
|
.eq(PublicOpinion::getProcessStatus, "2"));
|
|
|
|
|
|
|
|
|
|
+ // 昨日数据(用于环比)
|
|
|
|
|
+ Calendar yesterdayCal = Calendar.getInstance();
|
|
|
|
|
+ yesterdayCal.add(Calendar.DATE, -1);
|
|
|
|
|
+ String yesterday = new SimpleDateFormat("yyyy-MM-dd").format(yesterdayCal.getTime());
|
|
|
|
|
+ LambdaQueryWrapper<PublicOpinion> yesterdayWrapper = Wrappers.lambdaQuery()
|
|
|
|
|
+ .eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL)
|
|
|
|
|
+ .likeRight(PublicOpinion::getPublishTime, yesterday);
|
|
|
|
|
+ long yesterdayTotal = baseMapper.selectCount(yesterdayWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ // 全部数据
|
|
|
|
|
+ long allTotal = baseMapper.selectCount(wrapper.clone());
|
|
|
|
|
+ long allMajor = baseMapper.selectCount(wrapper.clone().eq(PublicOpinion::getRiskLevel, "重大"));
|
|
|
|
|
+ long allProcessed = baseMapper.selectCount(wrapper.clone().eq(PublicOpinion::getProcessStatus, "2"));
|
|
|
|
|
+ long allPending = allTotal - allProcessed;
|
|
|
|
|
+
|
|
|
|
|
+ // 日增长率
|
|
|
|
|
+ String growthRate;
|
|
|
|
|
+ if (yesterdayTotal == 0) {
|
|
|
|
|
+ growthRate = todayTotal > 0 ? "100%" : "0%";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ double rate = ((double)(todayTotal - yesterdayTotal) / yesterdayTotal) * 100;
|
|
|
|
|
+ growthRate = String.format("%.1f%%", rate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理率
|
|
|
|
|
+ String processRate;
|
|
|
|
|
+ if (allTotal == 0) {
|
|
|
|
|
+ processRate = "0%";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ double rate = ((double)allProcessed / allTotal) * 100;
|
|
|
|
|
+ processRate = String.format("%.1f%%", rate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Map<String, Object> stats = new LinkedHashMap<>();
|
|
Map<String, Object> stats = new LinkedHashMap<>();
|
|
|
- stats.put("total", total);
|
|
|
|
|
- stats.put("pending", pending);
|
|
|
|
|
- stats.put("processed", processed);
|
|
|
|
|
|
|
+ stats.put("todayTotal", todayTotal);
|
|
|
|
|
+ stats.put("todayGrowthRate", growthRate);
|
|
|
|
|
+ stats.put("majorCount", allMajor);
|
|
|
|
|
+ stats.put("majorChange", String.valueOf(todayMajor));
|
|
|
|
|
+ stats.put("processedCount", allProcessed);
|
|
|
|
|
+ stats.put("processRate", processRate);
|
|
|
|
|
+ stats.put("pendingCount", allPending);
|
|
|
return stats;
|
|
return stats;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public List<Map<String, Object>> selectMonthlyTrend(int months) {
|
|
|
|
|
|
|
+ public List<Map<String, Object>> selectDailyTrend(int days) {
|
|
|
List<Map<String, Object>> trend = new ArrayList<>();
|
|
List<Map<String, Object>> trend = new ArrayList<>();
|
|
|
- for (int i = months - 1; i >= 0; i--) {
|
|
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
+ for (int i = days - 1; i >= 0; i--) {
|
|
|
Calendar cal = Calendar.getInstance();
|
|
Calendar cal = Calendar.getInstance();
|
|
|
- cal.add(Calendar.MONTH, -i);
|
|
|
|
|
- String month = new SimpleDateFormat("yyyy-MM").format(cal.getTime());
|
|
|
|
|
- LambdaQueryWrapper<PublicOpinion> wrapper = Wrappers.lambdaQuery();
|
|
|
|
|
- wrapper.eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL)
|
|
|
|
|
- .likeRight(PublicOpinion::getPublishTime, month);
|
|
|
|
|
- long count = baseMapper.selectCount(wrapper);
|
|
|
|
|
|
|
+ cal.add(Calendar.DATE, -i);
|
|
|
|
|
+ String dateStr = sdf.format(cal.getTime());
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<PublicOpinion> baseWrapper = Wrappers.lambdaQuery()
|
|
|
|
|
+ .eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL)
|
|
|
|
|
+ .likeRight(PublicOpinion::getPublishTime, dateStr);
|
|
|
|
|
+
|
|
|
|
|
+ long total = baseMapper.selectCount(baseWrapper.clone());
|
|
|
|
|
+ long major = baseMapper.selectCount(baseWrapper.clone()
|
|
|
|
|
+ .eq(PublicOpinion::getRiskLevel, "重大"));
|
|
|
|
|
+ long processed = baseMapper.selectCount(baseWrapper.clone()
|
|
|
|
|
+ .eq(PublicOpinion::getProcessStatus, "2"));
|
|
|
|
|
+
|
|
|
Map<String, Object> item = new LinkedHashMap<>();
|
|
Map<String, Object> item = new LinkedHashMap<>();
|
|
|
- item.put("month", month);
|
|
|
|
|
- item.put("count", count);
|
|
|
|
|
|
|
+ item.put("date", dateStr.substring(5)); // MM-DD
|
|
|
|
|
+ item.put("total", total);
|
|
|
|
|
+ item.put("major", major);
|
|
|
|
|
+ item.put("processed", processed);
|
|
|
trend.add(item);
|
|
trend.add(item);
|
|
|
}
|
|
}
|
|
|
return trend;
|
|
return trend;
|