| | |
| | | import com.google.common.collect.Lists; |
| | | import com.sinata.common.core.domain.entity.SysDictData; |
| | | import com.sinata.common.entity.PageDTO; |
| | | import com.sinata.common.utils.BeanUtils; |
| | | import com.sinata.common.utils.CollUtils; |
| | | import com.sinata.common.utils.DateUtils; |
| | | import com.sinata.common.utils.SecurityUtils; |
| | | import com.sinata.common.utils.StringUtils; |
| | | import com.sinata.system.domain.MwCollectRecord; |
| | | import com.sinata.system.domain.MwMicroEquipment; |
| | | import com.sinata.system.domain.MwMicroEquipmentRecord; |
| | | import com.sinata.system.domain.MwMicroEquipmentRecordItem; |
| | | import com.sinata.system.domain.SysDepartment; |
| | | import com.sinata.system.domain.dto.MwMicroEquipmentRecordDTO; |
| | | import com.sinata.system.domain.query.MwMicroEquipmentRecordQuery; |
| | | import com.sinata.system.domain.query.MwMicroEquipmentStaticsQuery; |
| | | import com.sinata.system.domain.vo.DepartmentReportItemVO; |
| | | import com.sinata.system.domain.vo.DepartmentReportVO; |
| | | import com.sinata.system.domain.vo.MwCollectRecordVO; |
| | | import com.sinata.system.domain.vo.MwMicroEquipmentRecordVO; |
| | | import com.sinata.system.domain.vo.MwMicroEquipmentStaticsTitleVO; |
| | | import com.sinata.system.domain.vo.MwMicroEquipmentStaticsVO; |
| | | import com.sinata.system.domain.vo.SysDictDataVO; |
| | | import com.sinata.system.enums.MedicalWasteStatusEnum; |
| | | import com.sinata.system.mapper.MwMicroEquipmentRecordMapper; |
| | | import com.sinata.system.service.ISysDictDataService; |
| | | import com.sinata.system.service.MwCollectRecordService; |
| | | import com.sinata.system.service.MwMicroEquipmentRecordItemService; |
| | | import com.sinata.system.service.MwMicroEquipmentRecordService; |
| | | import com.sinata.system.service.MwMicroEquipmentService; |
| | | import com.sinata.system.service.MwStagingRoomService; |
| | | import com.sinata.system.service.SysDepartmentService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private final MwCollectRecordService mwCollectRecordService; |
| | | private final MwMicroEquipmentRecordItemService mwMicroEquipmentRecordItemService; |
| | | private final ISysDictDataService sysDictDataService; |
| | | private final MwStagingRoomService mwStagingRoomService; |
| | | private final MwMicroEquipmentService mwMicroEquipmentService; |
| | | |
| | | /** |
| | | * 设备使用记录分页列表 |
| | |
| | | return PageDTO.empty(0L, 0L); |
| | | } |
| | | return PageDTO.of(baseMapper.pageList(new Page<>(query.getPageCurr(), query.getPageSize()), query, treeCode)); |
| | | } |
| | | |
| | | @Override |
| | | public MwMicroEquipmentRecordVO detail(Long id) { |
| | | MwMicroEquipmentRecordVO mwMicroEquipmentRecordVO = BeanUtils.copyBean(this.getById(id), MwMicroEquipmentRecordVO.class); |
| | | if (Objects.nonNull(mwMicroEquipmentRecordVO)) { |
| | | mwMicroEquipmentRecordVO.setMedicalWasteList(mwStagingRoomService.queryMedicalWasteList(mwMicroEquipmentRecordVO.getId())); |
| | | } |
| | | return mwMicroEquipmentRecordVO; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<List<String>> getStaticsData(MwMicroEquipmentStaticsQuery query) { |
| | | public DepartmentReportVO getStaticsData(MwMicroEquipmentStaticsQuery query) { |
| | | DepartmentReportVO vo = new DepartmentReportVO(); |
| | | SysDepartment department = sysDepartmentService.getById(query.getDepartmentId()); |
| | | if (Objects.nonNull(department)) { |
| | | vo.setDepartmentName(department.getDepartmentName()); |
| | | } |
| | | MwMicroEquipment microEquipment = mwMicroEquipmentService.getById(query.getEquipmentId()); |
| | | vo.setEquipmentName(microEquipment.getEquipmentName()); |
| | | List<SysDictDataVO> wasteTypeList = sysDictDataService.medicalWasteTypeList(); |
| | | |
| | | if (CollUtils.isEmpty(wasteTypeList)) { |
| | | return vo; |
| | | } |
| | | vo.setLegend(wasteTypeList.stream().map(SysDictDataVO::getDictLabel).collect(Collectors.toList())); |
| | | vo.getLegend().add("小计"); |
| | | String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId()); |
| | | List<SysDictData> medicalWasteTypeList = sysDictDataService.lambdaQuery().eq(SysDictData::getDictType, "medical_waste_type").list(); |
| | | |
| | | List<MwMicroEquipmentStaticsVO> staticsData = baseMapper.getStaticsData(query, treeCode); |
| | | SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS); |
| | | switch (query.getDateType()) { |
| | |
| | | break; |
| | | } |
| | | List<String> dateList = DateUtils.getDayBetween(query.getStartTime(), query.getEndTime(), query.getDateType()); |
| | | List<List<String>> result = new ArrayList<>(); |
| | | if (CollUtils.isNotEmpty(staticsData)) { |
| | | List<DepartmentReportItemVO> result = new ArrayList<>(); |
| | | for (String date : dateList) { |
| | | List<String> list = new ArrayList<>(); |
| | | list.add(date); |
| | | DepartmentReportItemVO departmentReportItemVO = new DepartmentReportItemVO(); |
| | | departmentReportItemVO.setName(date); |
| | | departmentReportItemVO.setData(new ArrayList<>()); |
| | | SimpleDateFormat finalSdf = sdf; |
| | | BigDecimal totalWeight = BigDecimal.ZERO; |
| | | BigDecimal totalCount = BigDecimal.ZERO; |
| | | for (SysDictData sysDictData : medicalWasteTypeList) { |
| | | BigDecimal weight = staticsData.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) |
| | | && finalSdf.format(e.getUseTime()).equals(date) |
| | | ).map(MwMicroEquipmentStaticsVO::getWeight).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, RoundingMode.HALF_UP); |
| | | ).map(MwMicroEquipmentStaticsVO::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP); |
| | | long count = staticsData.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) |
| | | && finalSdf.format(e.getUseTime()).equals(date)).count(); |
| | | list.add(weight.toString()); |
| | | list.add(String.valueOf(count)); |
| | | departmentReportItemVO.getData().add(weight); |
| | | departmentReportItemVO.getData().add(BigDecimal.valueOf(count)); |
| | | totalWeight = totalWeight.add(weight); |
| | | totalCount = totalCount.add(BigDecimal.valueOf(count)); |
| | | } |
| | | staticsData.stream().filter(e -> finalSdf.format(e.getUseTime()).equals(date)).findFirst().ifPresent(item -> { |
| | | list.add(item.getTotalWeight().toString()); |
| | | list.add(String.valueOf(item.getBagNum())); |
| | | }); |
| | | result.add(list); |
| | | departmentReportItemVO.getData().add(totalWeight); |
| | | departmentReportItemVO.getData().add(totalCount); |
| | | result.add(departmentReportItemVO); |
| | | } |
| | | vo.setList(result); |
| | | } |
| | | return result; |
| | | return vo; |
| | | } |
| | | |
| | | @Override |
| | |
| | | .head(head) |
| | | .autoCloseStream(Boolean.TRUE) |
| | | .sheet("处置分析报表") |
| | | .doWrite(getStaticsData(query)); |
| | | .doWrite(getStaticsReportData(query)); |
| | | } |
| | | |
| | | /** |
| | | * 导出报表数据 |
| | | * |
| | | * @param query |
| | | * @return |
| | | */ |
| | | private List<List<Object>> getStaticsReportData(MwMicroEquipmentStaticsQuery query) { |
| | | DepartmentReportVO vo = getStaticsData(query); |
| | | if (CollUtils.isNotEmpty(vo.getList())) { |
| | | List<List<Object>> result = new ArrayList<>(); |
| | | for (DepartmentReportItemVO departmentReportItemVO : vo.getList()) { |
| | | List<Object> data = new ArrayList<>(); |
| | | data.add(departmentReportItemVO.getName()); |
| | | data.addAll(departmentReportItemVO.getData()); |
| | | result.add(data); |
| | | } |
| | | return result; |
| | | } |
| | | return CollUtils.emptyList(); |
| | | } |
| | | |
| | | /** |
| | | * 导出报表表头 |
| | | * |
| | | * @return |
| | | */ |
| | | private List<List<String>> head() { |
| | | List<SysDictData> medicalWasteTypeList = sysDictDataService.lambdaQuery().eq(SysDictData::getDictType, "medical_waste_type").list(); |
| | | List<List<String>> headTitles = Lists.newArrayList(); |
| | |
| | | headTitles.add(Lists.newArrayList("小计", "总数量")); |
| | | return headTitles; |
| | | } |
| | | |
| | | } |