From f9ec26bbbb515f678810c287230dad297dfdac16 Mon Sep 17 00:00:00 2001 From: chen <2710907404@qq.com> Date: Thu, 14 Nov 2024 15:01:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=201.=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=AF=92=E5=93=81=E6=A3=80=E6=9D=90=E9=80=81=E7=BC=B4=E9=87=8F?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=A8=A1=E5=9D=97=EF=BC=88=E7=9B=AE=E5=89=8D?= =?UTF-8?q?=E4=BB=85=E5=AE=9E=E7=8E=B0=E4=BA=86=E6=97=B6=E9=97=B4=E8=8C=83?= =?UTF-8?q?=E5=9B=B4=E5=92=8C=E9=80=81=E7=BC=B4=E5=8D=95=E4=BD=8D=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/imr/component/DateUtils.java | 2 + .../DrugHandingOverStatisticController.java | 30 ++++ .../platform/imr/dto/InRepositoryDTO.java | 1 - .../platform/imr/dto/InnerSampleOutbound.java | 32 ---- .../platform/imr/dto/PrintTableDTO.java | 19 +-- .../platform/imr/dto/PublicityDTO.java | 24 +-- .../platform/imr/dto/QueryApplyDTO.java | 29 +--- .../laboratory/platform/imr/dto/QueryDTO.java | 33 +--- .../platform/imr/dto/QuerySampleDTO.java | 19 +-- .../platform/imr/dto/QueryStorageDTO.java | 13 +- .../platform/imr/dto/base/BaseQuery.java | 38 +++++ .../imr/query/DrugStatisticQuery.java | 29 ++++ .../DrugHandingOverStatisticService.java | 16 ++ .../DrugHandingOverStatisticServiceImpl.java | 161 ++++++++++++++++++ .../platform/imr/vo/DrugStatisticVO.java | 24 +++ 15 files changed, 312 insertions(+), 158 deletions(-) create mode 100644 src/main/java/digital/laboratory/platform/imr/controller/DrugHandingOverStatisticController.java delete mode 100644 src/main/java/digital/laboratory/platform/imr/dto/InnerSampleOutbound.java create mode 100644 src/main/java/digital/laboratory/platform/imr/dto/base/BaseQuery.java create mode 100644 src/main/java/digital/laboratory/platform/imr/query/DrugStatisticQuery.java create mode 100644 src/main/java/digital/laboratory/platform/imr/service/DrugHandingOverStatisticService.java create mode 100644 src/main/java/digital/laboratory/platform/imr/service/impl/DrugHandingOverStatisticServiceImpl.java create mode 100644 src/main/java/digital/laboratory/platform/imr/vo/DrugStatisticVO.java diff --git a/src/main/java/digital/laboratory/platform/imr/component/DateUtils.java b/src/main/java/digital/laboratory/platform/imr/component/DateUtils.java index a400913..5987e8b 100644 --- a/src/main/java/digital/laboratory/platform/imr/component/DateUtils.java +++ b/src/main/java/digital/laboratory/platform/imr/component/DateUtils.java @@ -17,6 +17,8 @@ public class DateUtils { public static final String yyyy_MM_dd_HH_mm_ss = "yyyy-MM-dd HH:mm:ss"; public static final String yyyy_MM_dd = "yyyy-MM-dd"; + + public static final String yyyy_MM = "yyyy-MM"; public static final String TIME_ZONE = "GMT+8"; diff --git a/src/main/java/digital/laboratory/platform/imr/controller/DrugHandingOverStatisticController.java b/src/main/java/digital/laboratory/platform/imr/controller/DrugHandingOverStatisticController.java new file mode 100644 index 0000000..1c132c6 --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/controller/DrugHandingOverStatisticController.java @@ -0,0 +1,30 @@ +package digital.laboratory.platform.imr.controller; + + +import digital.laboratory.platform.common.core.util.R; +import digital.laboratory.platform.imr.query.DrugStatisticQuery; +import digital.laboratory.platform.imr.service.DrugHandingOverStatisticService; +import digital.laboratory.platform.imr.vo.DrugStatisticVO; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +@RestController +@RequestMapping("/drugStatistic") +public class DrugHandingOverStatisticController { + + @Resource + private DrugHandingOverStatisticService drugHandingOverStatisticService; + + @ApiOperation("获取统计图的数据, 根据时间范围, 送缴单位,毒品种类返回数据") + @PostMapping() + public R statistic(@RequestBody DrugStatisticQuery query) { + DrugStatisticVO vo = drugHandingOverStatisticService.statistic(query); + return R.ok(vo); + } + +} diff --git a/src/main/java/digital/laboratory/platform/imr/dto/InRepositoryDTO.java b/src/main/java/digital/laboratory/platform/imr/dto/InRepositoryDTO.java index f1504f5..7cdb565 100644 --- a/src/main/java/digital/laboratory/platform/imr/dto/InRepositoryDTO.java +++ b/src/main/java/digital/laboratory/platform/imr/dto/InRepositoryDTO.java @@ -1,7 +1,6 @@ package digital.laboratory.platform.imr.dto; -import com.baomidou.mybatisplus.annotation.TableId; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; diff --git a/src/main/java/digital/laboratory/platform/imr/dto/InnerSampleOutbound.java b/src/main/java/digital/laboratory/platform/imr/dto/InnerSampleOutbound.java deleted file mode 100644 index 162bbd8..0000000 --- a/src/main/java/digital/laboratory/platform/imr/dto/InnerSampleOutbound.java +++ /dev/null @@ -1,32 +0,0 @@ -package digital.laboratory.platform.imr.dto; - -import java.time.LocalDateTime; - -/** - * 内部样本出库DTO - */ -public class InnerSampleOutbound { - - /** - * id - * 样本id - */ - private String id; - - /** - * 领取人Id - */ - private String recipientId; - - /** - * 归还时间 - */ - private LocalDateTime returnDate; - - - /** - * 原因 - */ - private String cause; - -} diff --git a/src/main/java/digital/laboratory/platform/imr/dto/PrintTableDTO.java b/src/main/java/digital/laboratory/platform/imr/dto/PrintTableDTO.java index 23f13c3..1c49e21 100644 --- a/src/main/java/digital/laboratory/platform/imr/dto/PrintTableDTO.java +++ b/src/main/java/digital/laboratory/platform/imr/dto/PrintTableDTO.java @@ -1,18 +1,14 @@ package digital.laboratory.platform.imr.dto; -import com.alibaba.fastjson.annotation.JSONField; -import com.fasterxml.jackson.annotation.JsonFormat; -import digital.laboratory.platform.imr.component.DateUtils; +import digital.laboratory.platform.imr.dto.base.BaseQuery; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import java.time.LocalDate; - @Data @ApiModel(value = "按时间或委托生成检材出入库登记表") -public class PrintTableDTO { +public class PrintTableDTO extends BaseQuery { @ApiModelProperty(value = "打印筛选条件1.委托/任务;2.时间") private Integer type; @@ -28,15 +24,4 @@ public class PrintTableDTO { @ApiModelProperty(value = "事件名称") private String EventName; - @ApiModelProperty(value = "开始时间") - @JsonFormat(pattern = DateUtils.yyyy_MM_dd, timezone = DateUtils.TIME_ZONE) - @JSONField(format = DateUtils.yyyy_MM_dd) - private LocalDate beginDate; - @ApiModelProperty(value = "结束时间") - @JsonFormat(pattern = DateUtils.yyyy_MM_dd, timezone = DateUtils.TIME_ZONE) - @JSONField(format = DateUtils.yyyy_MM_dd) - private LocalDate finishDate; - - - } diff --git a/src/main/java/digital/laboratory/platform/imr/dto/PublicityDTO.java b/src/main/java/digital/laboratory/platform/imr/dto/PublicityDTO.java index 5807494..0008e6e 100644 --- a/src/main/java/digital/laboratory/platform/imr/dto/PublicityDTO.java +++ b/src/main/java/digital/laboratory/platform/imr/dto/PublicityDTO.java @@ -3,6 +3,7 @@ package digital.laboratory.platform.imr.dto; import com.alibaba.fastjson.annotation.JSONField; import com.fasterxml.jackson.annotation.JsonFormat; import digital.laboratory.platform.imr.component.DateUtils; +import digital.laboratory.platform.imr.dto.base.BaseQuery; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -10,30 +11,9 @@ import lombok.Data; import java.time.LocalDate; @Data @ApiModel(value = "PublicityDTO",description = "销毁与公示dto") -public class PublicityDTO { +public class PublicityDTO extends BaseQuery { - @ApiModelProperty(value = "开始时间") - @JsonFormat(pattern = DateUtils.yyyy_MM_dd, timezone = DateUtils.TIME_ZONE) - @JSONField(format = DateUtils.yyyy_MM_dd) - private LocalDate beginDate; - @ApiModelProperty(value = "结束时间") - @JsonFormat(pattern = DateUtils.yyyy_MM_dd, timezone = DateUtils.TIME_ZONE) - @JSONField(format = DateUtils.yyyy_MM_dd) - private LocalDate finishDate; - @ApiModelProperty(value = "当前申请的状态") private Integer status;//状态 - /** - * 当前页 - */ - @ApiModelProperty(value = "当前页") - private Integer current; - - /** - * 每页显示条数 - */ - - @ApiModelProperty(value = "每页显示条数") - private Integer size; } diff --git a/src/main/java/digital/laboratory/platform/imr/dto/QueryApplyDTO.java b/src/main/java/digital/laboratory/platform/imr/dto/QueryApplyDTO.java index 770c428..f5909c3 100644 --- a/src/main/java/digital/laboratory/platform/imr/dto/QueryApplyDTO.java +++ b/src/main/java/digital/laboratory/platform/imr/dto/QueryApplyDTO.java @@ -1,42 +1,17 @@ package digital.laboratory.platform.imr.dto; -import com.alibaba.fastjson.annotation.JSONField; -import com.fasterxml.jackson.annotation.JsonFormat; -import digital.laboratory.platform.imr.component.DateUtils; +import digital.laboratory.platform.imr.dto.base.BaseQuery; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; - -import java.time.LocalDate; @Data @ApiModel(value="查询申请通用DTO") -public class QueryApplyDTO { +public class QueryApplyDTO extends BaseQuery { @ApiModelProperty(value = "申请类型(1.外带//2.销毁)") private Integer applyType;//名称 - @ApiModelProperty(value = "开始时间") - @JsonFormat(pattern = DateUtils.yyyy_MM_dd, timezone = DateUtils.TIME_ZONE) - @JSONField(format = DateUtils.yyyy_MM_dd) - private LocalDate beginDate; - @ApiModelProperty(value = "结束时间") - @JsonFormat(pattern = DateUtils.yyyy_MM_dd, timezone = DateUtils.TIME_ZONE) - @JSONField(format = DateUtils.yyyy_MM_dd) - private LocalDate finishDate; - @ApiModelProperty(value = "当前申请的状态") private Integer status;//状态 - /** - * 当前页 - */ - @ApiModelProperty(value = "当前页") - private Integer current; - - /** - * 每页显示条数 - */ - - @ApiModelProperty(value = "每页显示条数") - private Integer size; } diff --git a/src/main/java/digital/laboratory/platform/imr/dto/QueryDTO.java b/src/main/java/digital/laboratory/platform/imr/dto/QueryDTO.java index 2dae1a4..405d7d0 100644 --- a/src/main/java/digital/laboratory/platform/imr/dto/QueryDTO.java +++ b/src/main/java/digital/laboratory/platform/imr/dto/QueryDTO.java @@ -1,19 +1,14 @@ package digital.laboratory.platform.imr.dto; -import com.alibaba.fastjson.annotation.JSONField; -import com.fasterxml.jackson.annotation.JsonFormat; -import digital.laboratory.platform.imr.component.DateUtils; +import digital.laboratory.platform.imr.dto.base.BaseQuery; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import java.time.LocalDate; -import java.util.List; - @Data @ApiModel(value = "通用的查询参数dto--选择其中部分数据作为查询参数") -public class QueryDTO { +public class QueryDTO extends BaseQuery { //以下为查询条件 @@ -24,29 +19,8 @@ public class QueryDTO { @ApiModelProperty(value = "样本id集合") private String sampleIds;//名称 - @ApiModelProperty(value = "开始时间") - @JsonFormat(pattern = DateUtils.yyyy_MM_dd, timezone = DateUtils.TIME_ZONE) - @JSONField(format = DateUtils.yyyy_MM_dd) - private LocalDate beginDate; - @ApiModelProperty(value = "结束时间") - @JsonFormat(pattern = DateUtils.yyyy_MM_dd, timezone = DateUtils.TIME_ZONE) - @JSONField(format = DateUtils.yyyy_MM_dd) - private LocalDate finishDate; - @ApiModelProperty(value = "状态--必带参数") private Integer status;//状态 - /** - * 当前页 - */ - @ApiModelProperty(value = "当前页") - private Integer current; - - /** - * 每页显示条数 - */ - - @ApiModelProperty(value = "每页显示条数") - private Integer size; @ApiModelProperty(value = "总量") private Integer total; @@ -59,7 +33,4 @@ public class QueryDTO { private String roomNo; - - - } diff --git a/src/main/java/digital/laboratory/platform/imr/dto/QuerySampleDTO.java b/src/main/java/digital/laboratory/platform/imr/dto/QuerySampleDTO.java index 7620189..243912b 100644 --- a/src/main/java/digital/laboratory/platform/imr/dto/QuerySampleDTO.java +++ b/src/main/java/digital/laboratory/platform/imr/dto/QuerySampleDTO.java @@ -3,6 +3,7 @@ package digital.laboratory.platform.imr.dto; import com.alibaba.fastjson.annotation.JSONField; import com.fasterxml.jackson.annotation.JsonFormat; import digital.laboratory.platform.imr.component.DateUtils; +import digital.laboratory.platform.imr.dto.base.BaseQuery; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -15,7 +16,7 @@ import java.time.LocalDateTime; */ @Data @ApiModel(value = "仓库查询样本dto") -public class QuerySampleDTO { +public class QuerySampleDTO extends BaseQuery { @ApiModelProperty(value = "样本名称") private String name;//名称 @@ -25,24 +26,8 @@ public class QuerySampleDTO { // private String sampleNo;//编号 - @ApiModelProperty(value = "入库开始时间") - @JsonFormat(pattern = DateUtils.yyyy_MM_dd, timezone = DateUtils.TIME_ZONE) - @JSONField(format = DateUtils.yyyy_MM_dd) - private LocalDate beginDate; - @ApiModelProperty(value = "入库结束时间") - @JsonFormat(pattern = DateUtils.yyyy_MM_dd, timezone = DateUtils.TIME_ZONE) - @JSONField(format = DateUtils.yyyy_MM_dd) - private LocalDate finishDate; @ApiModelProperty(value = "状态--必带参数") private Integer status;//状态 - @ApiModelProperty(value = "当前页") - private Integer current; - - /** - * 每页显示条数 - */ - @ApiModelProperty(value = "每页显示条数") - private Integer size; } diff --git a/src/main/java/digital/laboratory/platform/imr/dto/QueryStorageDTO.java b/src/main/java/digital/laboratory/platform/imr/dto/QueryStorageDTO.java index 968fcad..0b6633b 100644 --- a/src/main/java/digital/laboratory/platform/imr/dto/QueryStorageDTO.java +++ b/src/main/java/digital/laboratory/platform/imr/dto/QueryStorageDTO.java @@ -1,6 +1,7 @@ package digital.laboratory.platform.imr.dto; +import digital.laboratory.platform.imr.dto.base.BaseQuery; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -11,7 +12,7 @@ import lombok.Data; @Data @ApiModel(value = "查询存储相关的dto") -public class QueryStorageDTO { +public class QueryStorageDTO extends BaseQuery { @ApiModelProperty(value = "id--这个id可以是房间/柜子") private String id; @@ -19,14 +20,4 @@ public class QueryStorageDTO { @ApiModelProperty(value = "name--这个name可以是房间/柜子") private String name; - - @ApiModelProperty(value = "当前页") - private Integer current; - - - @ApiModelProperty(value = "每页显示条数") - private Integer size; - - - } diff --git a/src/main/java/digital/laboratory/platform/imr/dto/base/BaseQuery.java b/src/main/java/digital/laboratory/platform/imr/dto/base/BaseQuery.java new file mode 100644 index 0000000..384bc99 --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/dto/base/BaseQuery.java @@ -0,0 +1,38 @@ +package digital.laboratory.platform.imr.dto.base; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import digital.laboratory.platform.imr.component.DateUtils; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.time.LocalDate; + +@Data +@ApiModel(value = "BaseQuery", description = "基础查询DTO类") +public class BaseQuery { + + @ApiModelProperty(value = "开始时间") + @JsonFormat(pattern = DateUtils.yyyy_MM_dd, timezone = DateUtils.TIME_ZONE) + @JSONField(format = DateUtils.yyyy_MM_dd) + private LocalDate beginDate; + + @ApiModelProperty(value = "结束时间") + @JsonFormat(pattern = DateUtils.yyyy_MM_dd, timezone = DateUtils.TIME_ZONE) + @JSONField(format = DateUtils.yyyy_MM_dd) + private LocalDate finishDate; + + /** + * 当前页 + */ + @ApiModelProperty(value = "当前页") + private Integer current; + + /** + * 每页显示条数 + */ + + @ApiModelProperty(value = "每页显示条数") + private Integer size; +} diff --git a/src/main/java/digital/laboratory/platform/imr/query/DrugStatisticQuery.java b/src/main/java/digital/laboratory/platform/imr/query/DrugStatisticQuery.java new file mode 100644 index 0000000..cee0b6b --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/query/DrugStatisticQuery.java @@ -0,0 +1,29 @@ +package digital.laboratory.platform.imr.query; + +import com.fasterxml.jackson.annotation.JsonFormat; +import digital.laboratory.platform.imr.component.DateUtils; +import digital.laboratory.platform.imr.dto.base.BaseQuery; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.time.LocalDate; + +@Data +@ApiModel(value = "DrugStatisticQuery", description = "毒品送缴量统计 - 查询对象") +public class DrugStatisticQuery { + + @ApiModelProperty(value = "开始日期") + @JsonFormat(pattern = DateUtils.yyyy_MM_dd) + private LocalDate startDate; + + @ApiModelProperty(value = "结束日期") + @JsonFormat(pattern = DateUtils.yyyy_MM_dd) + private LocalDate endDate; + + @ApiModelProperty(value = "送缴单位 统计") + private String orgId; + + @ApiModelProperty(value = "毒品种类") + private String drugType; +} diff --git a/src/main/java/digital/laboratory/platform/imr/service/DrugHandingOverStatisticService.java b/src/main/java/digital/laboratory/platform/imr/service/DrugHandingOverStatisticService.java new file mode 100644 index 0000000..3d445ea --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/service/DrugHandingOverStatisticService.java @@ -0,0 +1,16 @@ +package digital.laboratory.platform.imr.service; + +import digital.laboratory.platform.imr.query.DrugStatisticQuery; +import digital.laboratory.platform.imr.vo.DrugStatisticVO; + +/** + * 毒品库送缴量统计 服务处接口 + */ +public interface DrugHandingOverStatisticService { + /** + * 获取统计图的数据, 根据时间范围, 送缴单位,毒品种类返回数据 + * @param query + * @return + */ + DrugStatisticVO statistic(DrugStatisticQuery query); +} diff --git a/src/main/java/digital/laboratory/platform/imr/service/impl/DrugHandingOverStatisticServiceImpl.java b/src/main/java/digital/laboratory/platform/imr/service/impl/DrugHandingOverStatisticServiceImpl.java new file mode 100644 index 0000000..82a15ca --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/service/impl/DrugHandingOverStatisticServiceImpl.java @@ -0,0 +1,161 @@ +package digital.laboratory.platform.imr.service.impl; + +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import digital.laboratory.platform.imr.component.DateUtils; +import digital.laboratory.platform.imr.entity.DrugCaseInfo; +import digital.laboratory.platform.imr.entity.DrugMaterialInfo; +import digital.laboratory.platform.imr.mapper.DrugMaterialInfoMapper; +import digital.laboratory.platform.imr.query.DrugStatisticQuery; +import digital.laboratory.platform.imr.service.CommonFeignService; +import digital.laboratory.platform.imr.service.DrugCaseInfoService; +import digital.laboratory.platform.imr.service.DrugHandingOverStatisticService; +import digital.laboratory.platform.imr.vo.DrugMaterialInfoVO; +import digital.laboratory.platform.imr.vo.DrugStatisticVO; +import digital.laboratory.platform.sys.entity.SysOrg; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 毒品库送缴量统计 服务处接口 -- 实现类 + */ +@Service +public class DrugHandingOverStatisticServiceImpl implements DrugHandingOverStatisticService { + + @Resource + private DrugMaterialInfoMapper drugMaterialInfoMapper; + + @Resource + private DrugCaseInfoService drugCaseInfoService; + + @Resource + private CommonFeignService commonFeignService; + + /** + * 获取统计图的数据, 根据时间范围, 送缴单位,毒品种类返回数据 + * @param query + * @return + */ + @Override + public DrugStatisticVO statistic(DrugStatisticQuery query) { + List> lineChartData = buildLineChartData(query); + List> barChartData = buildBarChartData(query); + DrugStatisticVO drugStatisticVO = new DrugStatisticVO(); + drugStatisticVO.setBarChartDataList(barChartData); + drugStatisticVO.setLineChartDataList(lineChartData); + return drugStatisticVO; + } + + /** + * 构建柱状图的数据 + * @param query + * @return + */ + private List> buildBarChartData(DrugStatisticQuery query) { + List> barChartData = new ArrayList<>(); + List orgNameList = new ArrayList<>(); + List dataList = new ArrayList<>(); + + // 根据案件表取所有的送缴单位 + List drugCaseInfoList = drugCaseInfoService.list(); + Map sysOrgMap = drugCaseInfoList.stream() + .collect(Collectors.toMap( + DrugCaseInfo::getHandingOverOrg, + drugCaseInfo -> commonFeignService.remoteGetSysOrg(drugCaseInfo.getHandingOverOrg()), + (existing, replacement) -> existing + ) + ); + // 根据时间点获取检材 + List drugMaterialInfoVOList = drugMaterialInfoMapper.getDrugMaterialVO( + Wrappers.query() + .ge(query.getStartDate() != null, "dc.handing_over_date", query.getStartDate()) + .le(query.getEndDate() != null, "dc.handing_over_date", query.getEndDate()) + ); + Map> groupByHandingOverOrgMap = drugMaterialInfoVOList.stream().collect(Collectors.groupingBy(DrugMaterialInfoVO::getHandingOverOrg)); + sysOrgMap.forEach((orgId, sysOrg) -> { + List voList = groupByHandingOverOrgMap.get(orgId); + if (CollUtil.isNotEmpty(voList)) { + orgNameList.add(sysOrg.getAlias()); + dataList.add(voList.size()); + } + }); + + barChartData.add(orgNameList); + barChartData.add(dataList); + return barChartData; + } + + /** + * 构建折线图的数据 + * @param query + * @return + */ + private List> buildLineChartData(DrugStatisticQuery query) { + List> lineChartData = new ArrayList<>(); // 存储结果值 + List monthsList = new ArrayList<>(); // 存储月份 + List dataList = new ArrayList<>(); // 对应月份送缴的数量 + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DateUtils.yyyy_MM); // 规定日期格式 + LocalDate startDate = query.getStartDate(); + LocalDate endDate = query.getEndDate(); + + // 判断当前查询的模式 + if (startDate == null && endDate == null) { + // 默认统计 一年内的 + LocalDate currentDate = LocalDate.now(); + for (int i = 11; i >= 0; i--) { + fillLineChartData(monthsList, dataList, dateTimeFormatter, currentDate, i); + } + } else if (startDate != null && endDate != null) { + // 计算查询开始时间和接受时间相差的月份数量 + long between = ChronoUnit.MONTHS.between(startDate, endDate); + for (int i = (int) (between -1); i >= 0; i--) { + fillLineChartData(monthsList, dataList, dateTimeFormatter, startDate, i); + } + } else if (startDate == null && endDate != null) { + // 只返回1年内的数据 + for (int i = 11; i >= 0; i--) { + fillLineChartData(monthsList, dataList, dateTimeFormatter, endDate, i); + } + } else { + // 只返回1年内的数据 + for (int i = 11; i >= 0; i--) { + fillLineChartData(monthsList, dataList, dateTimeFormatter, startDate.minusMonths(11), i); + } + } + lineChartData.add(monthsList); + lineChartData.add(dataList); + return lineChartData; + } + + /** + * 填充折线图数据 + * + * @param monthsList 月份列表,用于存储月份字符串 + * @param dataList 数据列表,用于存储数据对象 + * @param dateTimeFormatter 日期时间格式化器,用于格式化日期 + * @param startDate 起始日期 + * @param i 月份偏移量 + */ + private void fillLineChartData(List monthsList, List dataList, DateTimeFormatter dateTimeFormatter, LocalDate startDate, int i) { + LocalDate localDate = startDate.minusMonths(i); + LocalDate withDayOfMonth = localDate.withDayOfMonth(1); + dataList.add( + drugMaterialInfoMapper.getDrugMaterialVO( + Wrappers.query() + .ge("dc.handing_over_date", withDayOfMonth.atStartOfDay()) + .le("dc.handing_over_date", + withDayOfMonth.plusMonths(1).minusDays(1).atTime(LocalTime.MAX)) + ).size() + ); + monthsList.add(localDate.format(dateTimeFormatter)); + } +} diff --git a/src/main/java/digital/laboratory/platform/imr/vo/DrugStatisticVO.java b/src/main/java/digital/laboratory/platform/imr/vo/DrugStatisticVO.java new file mode 100644 index 0000000..f200f40 --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/vo/DrugStatisticVO.java @@ -0,0 +1,24 @@ +package digital.laboratory.platform.imr.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +@ApiModel(value = "DrugStatisticVO", description = "毒品送缴量统计 -返回给前端显示的VO对象 ") +public class DrugStatisticVO { + + @ApiModelProperty(value = "折线图数据") + private List> lineChartDataList; + + @ApiModelProperty(value = "柱状图数据") + private List> barChartDataList; + + @ApiModelProperty(value = "饼图数据") + private List> pieChartDataList; + + @ApiModelProperty(value = "树状图数据") + private String treeChartDateList; +}