From 4bbc20243e61457fd26f4ce293f793458f634088 Mon Sep 17 00:00:00 2001 From: wangxy <1481820854@qq.com> Date: Tue, 8 Oct 2024 10:24:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=A3=80=E6=9F=A5=E8=BF=916=E4=B8=AA?= =?UTF-8?q?=E6=9C=88=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/count/TdChecknumController.java | 114 ++++++------------ .../common/utils/ObtainLastSixMonthsUtil.java | 99 +++++++++++++++ 2 files changed, 133 insertions(+), 80 deletions(-) create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/ObtainLastSixMonthsUtil.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/count/TdChecknumController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/count/TdChecknumController.java index edcc220..ccb8fe9 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/count/TdChecknumController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/count/TdChecknumController.java @@ -1,9 +1,13 @@ package com.ruoyi.web.controller.system.count; +import cn.hutool.core.text.StrPool; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysDictData; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.utils.ObtainLastSixMonthsUtil; import com.ruoyi.system.domain.TdPropertyInfo; import com.ruoyi.system.domain.check.TdCheckReport; import com.ruoyi.system.domain.count.CheckResultCountDTO; @@ -11,6 +15,7 @@ import com.ruoyi.system.domain.count.CheckTypeCountDTO; import com.ruoyi.system.service.ISysDictDataService; import com.ruoyi.system.service.ITdNotifyService; import com.ruoyi.system.service.check.TdCheckReportService; +import com.ruoyi.web.controller.manager.CheckReportManager; import io.swagger.annotations.ApiOperation; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; @@ -21,10 +26,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; +import java.time.LocalDate; +import java.time.ZoneId; +import java.util.*; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -42,99 +46,49 @@ public class TdChecknumController extends BaseController{ @Autowired private ITdNotifyService tdNotifyService; + @Resource + private CheckReportManager checkReportManager; + @RequiresPermissions("system:checknum:view") @GetMapping() public String checknum() { return prefix + "/checknum"; } - @ApiOperation("检查通知统计") - @PostMapping("/countNotifyList") - @ResponseBody - public AjaxResult countNotifyList() { - return AjaxResult.success(tdNotifyService.selectCountNotifyList()); - } - - private List checkResult = Arrays.asList("通过", "未通过","待检查","已保存"); - - private List checkType = Arrays.asList("自行检查", "保密局检查"); - /** - * - * 检查结果统计 - * @return com.ruoyi.common.core.domain.AjaxResult + * 检查报告列表 */ - @PostMapping("/countResult") + @PostMapping("/list") @ResponseBody - public AjaxResult countbf() { - CheckResultCountDTO checkResultCountDTO = checkReportService.selectResultCount(); - List datas = checkResult.stream() - .map(name -> { - AtomicReference value = new AtomicReference<>(0L); - if("通过".equals(name)){ - value.set(checkResultCountDTO.getTg()); - }else if("未通过".equals(name)){ - value.set(checkResultCountDTO.getWtg()); - }else if("待检查".equals(name)){ - value.set(checkResultCountDTO.getDjc()); - }else{ - value.set(checkResultCountDTO.getYbc()); - } - JSONObject jsonObject = new JSONObject(); - jsonObject.put("value", value.get()); - jsonObject.put("name", name); - return jsonObject; - }) - .collect(Collectors.toList()); - return AjaxResult.success(datas); + public TableDataInfo list(TdCheckReport tdCheckReport) { + startPage(); + List tdCheckReports = checkReportManager.selectTdCheckReportList(tdCheckReport); + return getDataTable(tdCheckReports); } - /** - * - * 检查类型统计 - * @return com.ruoyi.common.core.domain.AjaxResult - */ - @PostMapping("/countType") - @ResponseBody - public AjaxResult countXH() { - CheckTypeCountDTO checkTypeCountDTO = checkReportService.selectTypeCount(); - List datas = checkType.stream() - .map(name -> { - AtomicReference value = new AtomicReference<>(0L); - if("自行检查".equals(name)){ - value.set(checkTypeCountDTO.getZxjc()); - }else{ - value.set(checkTypeCountDTO.getBmjjc()); - } - JSONObject jsonObject = new JSONObject(); - jsonObject.put("value", value.get()); - jsonObject.put("name", name); - return jsonObject; - }) - .collect(Collectors.toList()); - return AjaxResult.success(datas); - } - - @Autowired - private ISysDictDataService dictDataService; /** * - *检查类型统计 + *检查近6个月统计 * @return */ - @PostMapping("/countCheckType") + @PostMapping("/countCheckMonth") @ResponseBody - public AjaxResult countCheckType() { - SysDictData sysDictData = new SysDictData(); - sysDictData.setDictType("sys_check_type"); - List smType = dictDataService.selectDictDataList(sysDictData); - List list = smType.stream().map(SysDictData::getDictLabel).collect(Collectors.toList()); + public AjaxResult countCheckMonth() { + List recentlySixMonth = ObtainLastSixMonthsUtil.getRecentlySixMonth(); List yAxisData = new ArrayList<>(); - smType.forEach(xAxis -> { + recentlySixMonth.forEach(month -> { + // 获取指定月份的最大日期 + String lastDayOfMonth = ObtainLastSixMonthsUtil.getLastDayOfMonth(month); + // 获取指定天的最大时间 + Date date = Date.from(LocalDate.parse(lastDayOfMonth).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); + Date maxDayTime = ObtainLastSixMonthsUtil.getEndOfDay(date); + // 获取最小时间 + date = Date.from(LocalDate.parse(month.concat(StrPool.DASHED).concat("01")).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); + Date minDayTime = ObtainLastSixMonthsUtil.getStartOfDay(date); AtomicReference yAxis = new AtomicReference<>(0L); - Integer count = checkReportService.lambdaQuery() - .eq(TdCheckReport::getCheckType, xAxis.getDictValue()) - .count(); + Integer count = new LambdaQueryChainWrapper<>(checkReportService.getBaseMapper()) + .ge(TdCheckReport::getCreateTime, minDayTime) + .le(TdCheckReport::getCreateTime, maxDayTime).count(); if(Objects.isNull(count)){ count = 0; } @@ -142,7 +96,7 @@ public class TdChecknumController extends BaseController{ yAxisData.add(yAxis.get()); }); JSONObject obj = new JSONObject(); - obj.put("xAxisData", list.toArray()); + obj.put("xAxisData", recentlySixMonth.toArray()); obj.put("yAxisData", yAxisData); return AjaxResult.success(obj); } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ObtainLastSixMonthsUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ObtainLastSixMonthsUtil.java new file mode 100644 index 0000000..b4431cb --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ObtainLastSixMonthsUtil.java @@ -0,0 +1,99 @@ +package com.ruoyi.common.utils; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + +/** + * @author wangxy + * @ClassName ObtainLastSixMonthsUtil + * @description: 获取最近的六个月 + * @date 2023年10月11日 + * @version: 1.0.0 + */ +public class ObtainLastSixMonthsUtil { + + /** + * 获取最近六个月的yyyy-MM集合 + * + * @return List + */ + public static List getRecentlySixMonth() { + List previousMonths = new ArrayList<>(); + String currentMonth = DateUtil.format(LocalDateTime.now(), "yyyy-MM"); + previousMonths.add(currentMonth); + for (int i = 1; i <= 11; i++) { + DateTime dateTime = DateUtil.offsetMonth(new Date(), -i); + String dateMonth = DateUtil.format(dateTime, "yyyy-MM"); + previousMonths.add(dateMonth); + } + return previousMonths; + } + + /** + * 获取指定月份的最后一天 + * + * @param yearMonth 格式yyyy-MM + * @return String + */ + public static String getLastDayOfMonth(String yearMonth) { + DateTimeFormatter formatter = new DateTimeFormatterBuilder() + .appendPattern("yyyy-MM[dd]") + .parseDefaulting(ChronoField.DAY_OF_MONTH, 1) + .toFormatter(); + LocalDate localDate = LocalDate.parse(yearMonth, formatter); + Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + DateTime dateTime = DateUtil.endOfMonth(date); + return DateUtil.format(dateTime, "yyyy-MM-dd"); + } + + /** + * @param date + * @return + * @description: 获得当天最小时间 + * @author: Jeff + * @date: 2019年12月21日 + */ + public static Date getStartOfDay(Date date) { + return DateUtil.beginOfDay(date); + } + + /** + * @param date + * @return + * @description: 获得当天最大时间 + * @author: Jeff + * @date: 2019年12月21日 + */ + public static Date getEndOfDay(Date date) { + return DateUtil.endOfDay(date); + } + + + /** + * 计算两个时间差 + */ + public static Long getDatePoor(Date endDate, Date nowDate) { + // 获得两个时间的毫秒时间差异 + return DateUtil.between(nowDate, endDate, DateUnit.HOUR); + } + + public static void main(String[] args) { + // System.out.println(getRecentlySixMonth()); + List recentlySixMonth = getRecentlySixMonth(); + recentlySixMonth.forEach(s -> System.out.println(getLastDayOfMonth(s))); + } + + +}