liujie
2026-01-21 98b6c80ce7ef744462cb496a41884b6dfadadba5
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ProjectInfoServiceImpl.java
@@ -12,6 +12,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
@@ -45,12 +47,37 @@
        }
        LocalDate thisMonth = LocalDate.now().minusMonths(0).with(TemporalAdjusters.firstDayOfMonth());
        Map<String, List<Record>> map = list.stream().collect(groupingBy(Record::getHierarchyName));
        List<ProjectHiddenDangerTrendVo> collect = map.entrySet().stream().map(entry -> {
            ProjectHiddenDangerTrendVo vo = new ProjectHiddenDangerTrendVo();
            vo.setName(entry.getKey());
            List<Record> value = entry.getValue();
            long count = value.stream().filter(record -> record.getCreateTime().isAfter(thisMonth.atStartOfDay())).count();
            // 根据value集合中的createTime 选出本月的数据
            vo.setThisMonth((int) count);
            vo.setLastMonth(value.size()-(int) count);
        return List.of();
            int num = vo.getThisMonth() - vo.getLastMonth();
            if (num != 0) {
                if(vo.getLastMonth()>0){
                    String rate = BigDecimal.valueOf(num).divide(BigDecimal.valueOf(vo.getLastMonth()), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString();
                    vo.setRate(rate);
                }else {
                    vo.setRate("100.00");
                }
            }else {
                vo.setRate("0.00");
            }
            return vo;
        }).toList();
        return collect;
    }
    public static void main(String[] args) {
        LocalDate lastMonth = LocalDate.now().minusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
        System.out.println(LocalDate.now()+" 23:59:59");
        LocalDate lastMonth = LocalDate.now().minusMonths(0).with(TemporalAdjusters.firstDayOfMonth());
        System.out.println(lastMonth+" 23:59:59");
    }
}