|
|
@@ -3,6 +3,7 @@ package org.dromara.riskctrl.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.common.core.constant.SystemConstants;
|
|
|
@@ -31,6 +32,7 @@ import java.util.*;
|
|
|
@Service
|
|
|
public class PublicOpinionServiceImpl implements IPublicOpinionService {
|
|
|
|
|
|
+ @Resource
|
|
|
private final PublicOpinionMapper baseMapper;
|
|
|
|
|
|
@Override
|
|
|
@@ -99,34 +101,53 @@ public class PublicOpinionServiceImpl implements IPublicOpinionService {
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> selectOpinionStats() {
|
|
|
- LambdaQueryWrapper<PublicOpinion> wrapper = Wrappers.lambdaQuery();
|
|
|
- wrapper.eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL);
|
|
|
-
|
|
|
// 今日数据
|
|
|
Calendar todayCal = Calendar.getInstance();
|
|
|
String today = new SimpleDateFormat("yyyy-MM-dd").format(todayCal.getTime());
|
|
|
- LambdaQueryWrapper<PublicOpinion> todayWrapper = Wrappers.lambdaQuery()
|
|
|
- .eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL)
|
|
|
+
|
|
|
+ LambdaQueryWrapper<PublicOpinion> todayWrapper = Wrappers.lambdaQuery();
|
|
|
+ todayWrapper.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"));
|
|
|
|
|
|
- // 昨日数据(用于环比)
|
|
|
+ LambdaQueryWrapper<PublicOpinion> todayMajorWrapper = Wrappers.lambdaQuery();
|
|
|
+ todayMajorWrapper.eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL)
|
|
|
+ .likeRight(PublicOpinion::getPublishTime, today)
|
|
|
+ .eq(PublicOpinion::getRiskLevel, "重大");
|
|
|
+ long todayMajor = baseMapper.selectCount(todayMajorWrapper);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<PublicOpinion> todayProcessedWrapper = Wrappers.lambdaQuery();
|
|
|
+ todayProcessedWrapper.eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL)
|
|
|
+ .likeRight(PublicOpinion::getPublishTime, today)
|
|
|
+ .eq(PublicOpinion::getProcessStatus, "2");
|
|
|
+ long todayProcessed = baseMapper.selectCount(todayProcessedWrapper);
|
|
|
+
|
|
|
+ // 昨日数据
|
|
|
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)
|
|
|
+
|
|
|
+ LambdaQueryWrapper<PublicOpinion> yesterdayWrapper = Wrappers.lambdaQuery();
|
|
|
+ yesterdayWrapper.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"));
|
|
|
+ LambdaQueryWrapper<PublicOpinion> allWrapper = Wrappers.lambdaQuery();
|
|
|
+ allWrapper.eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL);
|
|
|
+ long allTotal = baseMapper.selectCount(allWrapper);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<PublicOpinion> allMajorWrapper = Wrappers.lambdaQuery();
|
|
|
+ allMajorWrapper.eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL)
|
|
|
+ .eq(PublicOpinion::getRiskLevel, "重大");
|
|
|
+ long allMajor = baseMapper.selectCount(allMajorWrapper);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<PublicOpinion> allProcessedWrapper = Wrappers.lambdaQuery();
|
|
|
+ allProcessedWrapper.eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL)
|
|
|
+ .eq(PublicOpinion::getProcessStatus, "2");
|
|
|
+ long allProcessed = baseMapper.selectCount(allProcessedWrapper);
|
|
|
+
|
|
|
long allPending = allTotal - allProcessed;
|
|
|
|
|
|
// 日增长率
|
|
|
@@ -134,7 +155,7 @@ public class PublicOpinionServiceImpl implements IPublicOpinionService {
|
|
|
if (yesterdayTotal == 0) {
|
|
|
growthRate = todayTotal > 0 ? "100%" : "0%";
|
|
|
} else {
|
|
|
- double rate = ((double)(todayTotal - yesterdayTotal) / yesterdayTotal) * 100;
|
|
|
+ double rate = ((double) (todayTotal - yesterdayTotal) / yesterdayTotal) * 100;
|
|
|
growthRate = String.format("%.1f%%", rate);
|
|
|
}
|
|
|
|
|
|
@@ -143,7 +164,7 @@ public class PublicOpinionServiceImpl implements IPublicOpinionService {
|
|
|
if (allTotal == 0) {
|
|
|
processRate = "0%";
|
|
|
} else {
|
|
|
- double rate = ((double)allProcessed / allTotal) * 100;
|
|
|
+ double rate = ((double) allProcessed / allTotal) * 100;
|
|
|
processRate = String.format("%.1f%%", rate);
|
|
|
}
|
|
|
|
|
|
@@ -162,23 +183,31 @@ public class PublicOpinionServiceImpl implements IPublicOpinionService {
|
|
|
public List<Map<String, Object>> selectDailyTrend(int days) {
|
|
|
List<Map<String, Object>> trend = new ArrayList<>();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
for (int i = days - 1; i >= 0; i--) {
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
cal.add(Calendar.DATE, -i);
|
|
|
String dateStr = sdf.format(cal.getTime());
|
|
|
|
|
|
- LambdaQueryWrapper<PublicOpinion> baseWrapper = Wrappers.lambdaQuery()
|
|
|
- .eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL)
|
|
|
+ LambdaQueryWrapper<PublicOpinion> totalWrapper = Wrappers.lambdaQuery();
|
|
|
+ totalWrapper.eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL)
|
|
|
.likeRight(PublicOpinion::getPublishTime, dateStr);
|
|
|
+ long total = baseMapper.selectCount(totalWrapper);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<PublicOpinion> majorWrapper = Wrappers.lambdaQuery();
|
|
|
+ majorWrapper.eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL)
|
|
|
+ .likeRight(PublicOpinion::getPublishTime, dateStr)
|
|
|
+ .eq(PublicOpinion::getRiskLevel, "重大");
|
|
|
+ long major = baseMapper.selectCount(majorWrapper);
|
|
|
|
|
|
- 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"));
|
|
|
+ LambdaQueryWrapper<PublicOpinion> processedWrapper = Wrappers.lambdaQuery();
|
|
|
+ processedWrapper.eq(PublicOpinion::getDelFlag, SystemConstants.NORMAL)
|
|
|
+ .likeRight(PublicOpinion::getPublishTime, dateStr)
|
|
|
+ .eq(PublicOpinion::getProcessStatus, "2");
|
|
|
+ long processed = baseMapper.selectCount(processedWrapper);
|
|
|
|
|
|
Map<String, Object> item = new LinkedHashMap<>();
|
|
|
- item.put("date", dateStr.substring(5)); // MM-DD
|
|
|
+ item.put("date", dateStr.substring(5));
|
|
|
item.put("total", total);
|
|
|
item.put("major", major);
|
|
|
item.put("processed", processed);
|