package cn.besteam.modules.report.biz;
|
|
import cn.besteam.common.constant.DepartmentEnum;
|
import cn.besteam.common.constant.ErrorCode;
|
import cn.besteam.common.constant.MedicalWasteEnum;
|
import cn.besteam.common.exception.BusinessException;
|
import cn.besteam.common.util.DateUtil;
|
import cn.besteam.modules.medical.entity.MwCollectRecord;
|
import cn.besteam.modules.medical.entity.MwCollectRecordDaySummary;
|
import cn.besteam.modules.medical.entity.MwCollectionAmendantRecord;
|
import cn.besteam.modules.medical.entity.MwWarningRecord;
|
import cn.besteam.modules.medical.service.*;
|
import cn.besteam.modules.report.dto.CollectRecordSummaryDTO;
|
import cn.besteam.modules.report.dto.CollectionWarningLevelDTO;
|
import cn.besteam.modules.report.dto.MedicalReportDTO;
|
import cn.besteam.modules.report.dto.ReportCollectionAmendantDTO;
|
import cn.besteam.modules.report.vo.*;
|
import cn.besteam.modules.system.entity.SysDepartment;
|
import cn.besteam.modules.system.entity.SysDepartmentInformation;
|
import cn.besteam.modules.system.entity.SysDictItem;
|
import cn.besteam.modules.system.service.ISysDepartmentInformationService;
|
import cn.besteam.modules.system.service.ISysDepartmentService;
|
import cn.besteam.modules.system.service.ISysDictItemService;
|
import cn.besteam.modules.system.vo.SysDepartmentInformationReportVO;
|
import cn.hutool.poi.excel.ExcelWriter;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.xssf.usermodel.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.math.BigDecimal;
|
import java.net.URLEncoder;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
import java.util.stream.Stream;
|
|
import static cn.besteam.common.util.DateUtil.*;
|
|
/**
|
* 监管统计
|
*/
|
@Service
|
@Slf4j
|
public class RegulatoryStatisticalBiz {
|
|
@Autowired
|
private ISysDepartmentService sysDepartmentService;
|
|
@Autowired
|
private IMwCollectRecordService mwCollectRecordService;
|
|
@Autowired
|
private ISysDepartmentInformationService sysDepartmentInformationService;
|
|
@Autowired
|
private IMwCollectionAmendantRecordService mwCollectionAmendantRecordService;
|
|
@Autowired
|
private IMwWarningRecordService warningRecordService;
|
|
/**
|
* 区域产废修改报表
|
*
|
* @param dto
|
* @return
|
*/
|
public DepartmentCollectionAmendantReportVO getCollectionAmendantRecordReportList(ReportCollectionAmendantDTO dto) {
|
|
SysDepartment department = sysDepartmentService.getById(dto.getDepartmentId());
|
if (department == null) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
/*if(dto.getStyleTpl()==1){
|
if (!department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.AREA.getType())) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
}else if(dto.getStyleTpl()==2){
|
if (!department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())) {
|
throw new BusinessException(ErrorCode.ERR_500, "医院不存在");
|
}
|
}*/
|
|
DepartmentCollectionAmendantReportVO vo = new DepartmentCollectionAmendantReportVO();
|
vo.setDepartmentName(department.getDepartName());
|
/* List<SysDictItem> wasteTypeList = getWasteTypeList();
|
if (CollectionUtils.isEmpty(wasteTypeList)) {
|
return vo;
|
}
|
vo.setLegend(wasteTypeList.stream().map(SysDictItem::getItemText).collect(Collectors.toList()));
|
vo.getLegend().add("小计");*/
|
//
|
|
List<SysDepartmentInformation> sysDepartmentInformationList = new ArrayList<>();
|
if(dto.getDepartmentLevel()!=null || dto.getDepartmentProperty()!=null || dto.getDepartmentType()!=null || dto.getIsCourts()!=null){
|
QueryWrapper<SysDepartmentInformation> wrapper = new QueryWrapper<SysDepartmentInformation>();
|
wrapper.lambda();
|
if(dto.getDepartmentLevel()!=null) wrapper.eq("department_level",dto.getDepartmentLevel());
|
if(dto.getDepartmentProperty()!=null) wrapper.eq("department_property",dto.getDepartmentProperty());
|
if(dto.getDepartmentType()!=null) wrapper.eq("department_type",dto.getDepartmentType());
|
if(dto.getIsCourts()!=null) wrapper.eq("is_courts",dto.getIsCourts());
|
sysDepartmentInformationList = sysDepartmentInformationService.list(wrapper);
|
}
|
List<MwCollectRecord> totalMwCollectRecordList = new ArrayList<>();
|
List<DepartmentReportItemVO> voList = new ArrayList<>();
|
Integer num1=0;Integer num2=0;Integer num3=0;Integer num4=0;Integer num5=0;Integer num6=0;
|
if(dto.getStatisticalWayType()==1){//区域统计
|
List<SysDepartment> regionList = sysDepartmentService.list(new QueryWrapper<SysDepartment>()//
|
.lambda()//
|
.eq(SysDepartment::getParentId, department.getId())//
|
//.likeRight(SysDepartment::getTreeCode, department.getTreeCode())//
|
.eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.AREA.getType()));//
|
if (CollectionUtils.isEmpty(regionList)) {
|
return vo;
|
}
|
for (SysDepartment sysDepartment : regionList) {
|
Integer subtotal=0;
|
DepartmentReportItemVO itemVO = new DepartmentReportItemVO();
|
itemVO.setKey(sysDepartment.getId());
|
itemVO.setName(sysDepartment.getDepartName());
|
itemVO.setData(new ArrayList<>());
|
//获取下级组织
|
List<SysDepartment> childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda().likeRight(SysDepartment::getTreeCode, sysDepartment.getTreeCode()));
|
if (CollectionUtils.isNotEmpty(childrenList)) {
|
if(CollectionUtils.isNotEmpty(sysDepartmentInformationList)){
|
Integer numTotal = mwCollectRecordService.count(new QueryWrapper<MwCollectRecord>().lambda()//
|
.between(MwCollectRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.in(MwCollectRecord::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.in(MwCollectRecord::getHospitalId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(MwCollectRecord::getDelFlag, 0)//
|
.eq(MwCollectRecord::getAuditStatus, MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus()));
|
itemVO.getData().add(new BigDecimal(numTotal));
|
num1+=numTotal;
|
Integer num = mwCollectRecordService.count(new QueryWrapper<MwCollectRecord>().lambda()//
|
.between(MwCollectRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.in(MwCollectRecord::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.in(MwCollectRecord::getHospitalId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(MwCollectRecord::getDelFlag, 0)//
|
.eq(MwCollectRecord::getAuditStatus, MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus())
|
.eq(MwCollectRecord::getSource, 2));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal)).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num2+=num;
|
num6+=num;subtotal+=num;
|
num = mwCollectionAmendantRecordService.count(new QueryWrapper<MwCollectionAmendantRecord>().lambda()//
|
.between(MwCollectionAmendantRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.in(MwCollectionAmendantRecord::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.in(MwCollectionAmendantRecord::getHospitalId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(MwCollectionAmendantRecord::getDelFlag, 0)//);
|
.eq(MwCollectionAmendantRecord::getType, 1));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num3+=num;
|
num6+=num;subtotal+=num;
|
num = mwCollectionAmendantRecordService.count(new QueryWrapper<MwCollectionAmendantRecord>().lambda()//
|
.between(MwCollectionAmendantRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.in(MwCollectionAmendantRecord::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.in(MwCollectionAmendantRecord::getHospitalId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(MwCollectionAmendantRecord::getDelFlag, 0)//);
|
.eq(MwCollectionAmendantRecord::getType, 2));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num4+=num;
|
num6+=num;subtotal+=num;
|
num = mwCollectionAmendantRecordService.count(new QueryWrapper<MwCollectionAmendantRecord>().lambda()//
|
.between(MwCollectionAmendantRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.in(MwCollectionAmendantRecord::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.in(MwCollectionAmendantRecord::getHospitalId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(MwCollectionAmendantRecord::getDelFlag, 0)//);
|
.eq(MwCollectionAmendantRecord::getType, 3));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num5+=num;
|
num6+=num;subtotal+=num;
|
|
itemVO.getData().add(new BigDecimal(subtotal));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(subtotal).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
}else{
|
Integer numTotal = mwCollectRecordService.count(new QueryWrapper<MwCollectRecord>().lambda()//
|
.between(MwCollectRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.in(MwCollectRecord::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.eq(MwCollectRecord::getDelFlag, 0)//
|
.eq(MwCollectRecord::getAuditStatus, MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus()));
|
itemVO.getData().add(new BigDecimal(numTotal));
|
num1+=numTotal;
|
Integer num = mwCollectRecordService.count(new QueryWrapper<MwCollectRecord>().lambda()//
|
.between(MwCollectRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.in(MwCollectRecord::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.eq(MwCollectRecord::getDelFlag, 0)//
|
.eq(MwCollectRecord::getAuditStatus, MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus())
|
.eq(MwCollectRecord::getSource, 2));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num2+=num;
|
num6+=num;subtotal+=num;
|
num = mwCollectionAmendantRecordService.count(new QueryWrapper<MwCollectionAmendantRecord>().lambda()//
|
.between(MwCollectionAmendantRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.in(MwCollectionAmendantRecord::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.eq(MwCollectionAmendantRecord::getDelFlag, 0)//);
|
.eq(MwCollectionAmendantRecord::getType, 1));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num3+=num;
|
num6+=num;subtotal+=num;
|
num = mwCollectionAmendantRecordService.count(new QueryWrapper<MwCollectionAmendantRecord>().lambda()//
|
.between(MwCollectionAmendantRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.in(MwCollectionAmendantRecord::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.eq(MwCollectionAmendantRecord::getDelFlag, 0)//);
|
.eq(MwCollectionAmendantRecord::getType, 2));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num4+=num;
|
num6+=num;subtotal+=num;
|
num = mwCollectionAmendantRecordService.count(new QueryWrapper<MwCollectionAmendantRecord>().lambda()//
|
.between(MwCollectionAmendantRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.in(MwCollectionAmendantRecord::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.eq(MwCollectionAmendantRecord::getDelFlag, 0)//);
|
.eq(MwCollectionAmendantRecord::getType, 3));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num5+=num;
|
num6+=num;subtotal+=num;
|
itemVO.getData().add(new BigDecimal(subtotal));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(subtotal).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
}
|
|
}
|
voList.add(itemVO);
|
}
|
}else{//医疗机构统计
|
//for (SysDepartment sysDepartment : regionList) {
|
|
//获取下级组织
|
List<SysDepartment> childrenList = new ArrayList<>();
|
if(CollectionUtils.isNotEmpty(sysDepartmentInformationList)){
|
childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda()
|
.likeRight(SysDepartment::getTreeCode, department.getTreeCode())//
|
.in(SysDepartment::getId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))
|
.eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType()));
|
}else{
|
childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda()
|
.likeRight(SysDepartment::getTreeCode, department.getTreeCode()).eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType()));
|
}
|
|
for(SysDepartment sysDepartment1:childrenList){
|
Integer subtotal=0;
|
DepartmentReportItemVO itemVO = new DepartmentReportItemVO();
|
itemVO.setKey(sysDepartment1.getId());
|
itemVO.setName(sysDepartment1.getDepartName());
|
itemVO.setData(new ArrayList<>());
|
if (CollectionUtils.isNotEmpty(childrenList)) {
|
if(CollectionUtils.isNotEmpty(sysDepartmentInformationList)){
|
Integer numTotal = mwCollectRecordService.count(new QueryWrapper<MwCollectRecord>().lambda()//
|
.between(MwCollectRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.eq(MwCollectRecord::getHospitalId, sysDepartment1.getId())//
|
.in(MwCollectRecord::getHospitalId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(MwCollectRecord::getDelFlag, 0)//
|
.eq(MwCollectRecord::getAuditStatus, MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus()));
|
itemVO.getData().add(new BigDecimal(numTotal));
|
num1+=numTotal;
|
Integer num = mwCollectRecordService.count(new QueryWrapper<MwCollectRecord>().lambda()//
|
.between(MwCollectRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.eq(MwCollectRecord::getHospitalId, sysDepartment1.getId())//
|
.in(MwCollectRecord::getHospitalId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(MwCollectRecord::getDelFlag, 0)//
|
.eq(MwCollectRecord::getAuditStatus, MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus())
|
.eq(MwCollectRecord::getSource, 2));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num2+=num;
|
num6+=num;subtotal+=num;
|
num = mwCollectionAmendantRecordService.count(new QueryWrapper<MwCollectionAmendantRecord>().lambda()//
|
.between(MwCollectionAmendantRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.eq(MwCollectionAmendantRecord::getHospitalId, sysDepartment1.getId())//
|
.in(MwCollectionAmendantRecord::getHospitalId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(MwCollectionAmendantRecord::getDelFlag, 0)//);
|
.eq(MwCollectionAmendantRecord::getType, 1));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num3+=num;
|
num6+=num;subtotal+=num;
|
num = mwCollectionAmendantRecordService.count(new QueryWrapper<MwCollectionAmendantRecord>().lambda()//
|
.between(MwCollectionAmendantRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.eq(MwCollectionAmendantRecord::getHospitalId, sysDepartment1.getId())//
|
.in(MwCollectionAmendantRecord::getHospitalId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(MwCollectionAmendantRecord::getDelFlag, 0)//);
|
.eq(MwCollectionAmendantRecord::getType, 2));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num4+=num;
|
num6+=num;subtotal+=num;
|
num = mwCollectionAmendantRecordService.count(new QueryWrapper<MwCollectionAmendantRecord>().lambda()//
|
.between(MwCollectionAmendantRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.eq(MwCollectionAmendantRecord::getHospitalId, sysDepartment1.getId())//
|
.in(MwCollectionAmendantRecord::getHospitalId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(MwCollectionAmendantRecord::getDelFlag, 0)//);
|
.eq(MwCollectionAmendantRecord::getType, 3));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num5+=num;
|
num6+=num;subtotal+=num;
|
|
itemVO.getData().add(new BigDecimal(subtotal));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(subtotal).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
}else{
|
Integer numTotal = mwCollectRecordService.count(new QueryWrapper<MwCollectRecord>().lambda()//
|
.between(MwCollectRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.eq(MwCollectRecord::getHospitalId, sysDepartment1.getId())//
|
.eq(MwCollectRecord::getDelFlag, 0)//
|
.eq(MwCollectRecord::getAuditStatus, MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus()));
|
itemVO.getData().add(new BigDecimal(numTotal));
|
num1+=numTotal;
|
Integer num = mwCollectRecordService.count(new QueryWrapper<MwCollectRecord>().lambda()//
|
.between(MwCollectRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.eq(MwCollectRecord::getHospitalId, sysDepartment1.getId())//
|
.eq(MwCollectRecord::getDelFlag, 0)//
|
.eq(MwCollectRecord::getAuditStatus, MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus())
|
.eq(MwCollectRecord::getSource, 2));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num2+=num;
|
num6+=num;subtotal+=num;
|
num = mwCollectionAmendantRecordService.count(new QueryWrapper<MwCollectionAmendantRecord>().lambda()//
|
.between(MwCollectionAmendantRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.eq(MwCollectionAmendantRecord::getHospitalId, sysDepartment1.getId())//
|
.eq(MwCollectionAmendantRecord::getDelFlag, 0)//);
|
.eq(MwCollectionAmendantRecord::getType, 1));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num3+=num;
|
num6+=num;subtotal+=num;
|
num = mwCollectionAmendantRecordService.count(new QueryWrapper<MwCollectionAmendantRecord>().lambda()//
|
.between(MwCollectionAmendantRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.eq(MwCollectionAmendantRecord::getHospitalId, sysDepartment1.getId())//
|
.eq(MwCollectionAmendantRecord::getDelFlag, 0)//);
|
.eq(MwCollectionAmendantRecord::getType, 2));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num4+=num;
|
num6+=num;subtotal+=num;
|
num = mwCollectionAmendantRecordService.count(new QueryWrapper<MwCollectionAmendantRecord>().lambda()//
|
.between(MwCollectionAmendantRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.eq(MwCollectionAmendantRecord::getHospitalId, sysDepartment1.getId())//
|
.eq(MwCollectionAmendantRecord::getDelFlag, 0)//);
|
.eq(MwCollectionAmendantRecord::getType, 3));
|
itemVO.getData().add(new BigDecimal(num));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(num).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
num5+=num;
|
num6+=num;subtotal+=num;
|
itemVO.getData().add(new BigDecimal(subtotal));
|
if(numTotal>0){
|
itemVO.getData().add(new BigDecimal(subtotal).divide(new BigDecimal(numTotal),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
itemVO.getData().add(new BigDecimal(0));
|
}
|
}
|
|
}
|
voList.add(itemVO);
|
}
|
|
|
// }
|
}
|
|
//合计
|
DepartmentReportItemVO totalItemVO = new DepartmentReportItemVO();
|
totalItemVO.setKey(-2);
|
totalItemVO.setName("合计");
|
totalItemVO.setData(new ArrayList<>());
|
totalItemVO.getData().add(new BigDecimal(num1));
|
totalItemVO.getData().add(new BigDecimal(num2));
|
if(num1>0){
|
totalItemVO.getData().add(new BigDecimal(num2).divide(new BigDecimal(num1),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
totalItemVO.getData().add(new BigDecimal(0));
|
}
|
totalItemVO.getData().add(new BigDecimal(num3));
|
if(num1>0){
|
totalItemVO.getData().add(new BigDecimal(num3).divide(new BigDecimal(num1),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
totalItemVO.getData().add(new BigDecimal(0));
|
}
|
totalItemVO.getData().add(new BigDecimal(num4));
|
if(num1>0){
|
totalItemVO.getData().add(new BigDecimal(num4).divide(new BigDecimal(num1),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
totalItemVO.getData().add(new BigDecimal(0));
|
}
|
totalItemVO.getData().add(new BigDecimal(num5));
|
if(num1>0){
|
totalItemVO.getData().add(new BigDecimal(num5).divide(new BigDecimal(num1),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
totalItemVO.getData().add(new BigDecimal(0));
|
}
|
totalItemVO.getData().add(new BigDecimal(num6));
|
if(num1>0){
|
totalItemVO.getData().add(new BigDecimal(num6).divide(new BigDecimal(num1),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP));
|
}else{
|
totalItemVO.getData().add(new BigDecimal(0));
|
}
|
voList.add(0,totalItemVO);
|
vo.setList(voList);
|
return vo;
|
}
|
|
public void exportCollectionAmendantReport(HttpServletResponse response, ReportCollectionAmendantDTO dto) throws IOException {
|
|
String fileName = "";
|
ExcelWriter writer = null;
|
fileName = "数据修改统计";
|
writer = new ExcelWriter(exportCollectionAmendant(dto, fileName), fileName);
|
if (writer != null) {
|
response.setContentType("application/octet-stream;charset=utf-8");
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
|
writer.flush(response.getOutputStream(), true);
|
writer.close();
|
}
|
}
|
|
@Autowired
|
private ISysDictItemService sysDictItemService;
|
/**
|
* 医疗机构统计
|
*
|
* @param dto
|
* @return
|
*/
|
public MedicalReportVO getMedicalReportList(MedicalReportDTO dto) {
|
|
SysDepartment department = sysDepartmentService.getById(dto.getDepartmentId());
|
if (department == null) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
if (!department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.AREA.getType())) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
MedicalReportVO medicalReportVO=new MedicalReportVO();
|
medicalReportVO.setDepartmentName(department.getDepartName());
|
dto.setTreeCode(department.getTreeCode());
|
//获取机构信息
|
List<SysDepartmentInformationReportVO> informationList = sysDepartmentInformationService.getDepartmentInformationList(dto);
|
//获取列表表头
|
List<SysDictItem> sysDictItems=sysDictItemService.list(new QueryWrapper<SysDictItem>()
|
.eq("dict_id",5)
|
.orderByAsc("sort_order"));
|
Map<String,String> legendMap=new HashMap<>();
|
legendMap.put("0","暂存间");
|
for(SysDictItem sysDictItem:sysDictItems){
|
legendMap.put(sysDictItem.getId()+"",sysDictItem.getItemText());
|
}
|
medicalReportVO.setLegend(legendMap.values());
|
//拼接数据
|
Set<String> legendSet = legendMap.keySet(); //取出所有的key值
|
Long[] dataTotal=new Long[legendSet.size()];
|
if(informationList==null || informationList.size()==0){
|
return medicalReportVO;
|
}
|
for(SysDepartmentInformationReportVO vo:informationList){
|
if(vo.getIsCourts()==null){
|
vo.setIsCourtsStr("");
|
}
|
Long[] data=new Long[legendSet.size()];
|
//获取科室汇总数量
|
List<Map<String,Object>> mapList1=sysDepartmentInformationService.getDepartmentNumber(vo.getTreeCode());
|
Integer i=0;
|
for(String setStr:legendSet){
|
data[i]=0L;
|
if(dataTotal[i]==null){
|
dataTotal[i] = 0l;
|
}
|
for(Map<String,Object> map : mapList1){
|
if(map.get("officeType").toString().equals(setStr)){
|
data[i]=Long.valueOf(map.get("number").toString());
|
dataTotal[i] += Long.valueOf(map.get("number").toString());
|
}
|
}
|
i++;
|
}
|
vo.setData(data);
|
|
}
|
SysDepartmentInformationReportVO totalVo=new SysDepartmentInformationReportVO();
|
totalVo.setData(dataTotal);
|
totalVo.setDepartmentName("合计");
|
informationList.add(0,totalVo);
|
medicalReportVO.setList(informationList);
|
return medicalReportVO;
|
}
|
|
public void exportHospitalReport(HttpServletResponse response, MedicalReportDTO dto) throws IOException {
|
|
String fileName = "";
|
ExcelWriter writer = null;
|
fileName = "医疗机构统计";
|
writer = new ExcelWriter(exportHospitalReport(dto, fileName), fileName);
|
if (writer != null) {
|
response.setContentType("application/octet-stream;charset=utf-8");
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
|
writer.flush(response.getOutputStream(), true);
|
writer.close();
|
}
|
}
|
|
@Autowired
|
private ReportBiz reportBiz;
|
|
@Autowired
|
private IMwCollectRecordDaySummaryService mwCollectRecordDaySummaryService;
|
/**
|
* 医院产废报表
|
*
|
* @param dto
|
* @return
|
*/
|
public DepartmentReportVO getHospitalReportList(CollectRecordSummaryDTO dto) {
|
|
SysDepartment department = sysDepartmentService.getById(dto.getDepartmentId());
|
if (department == null) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
if (!department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.AREA.getType())) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
DepartmentReportVO vo = new DepartmentReportVO();
|
vo.setDepartmentName(department.getDepartName());
|
List<SysDictItem> wasteTypeList = reportBiz.getWasteTypeList();
|
if (CollectionUtils.isEmpty(wasteTypeList)) {
|
return vo;
|
}
|
vo.setLegend(wasteTypeList.stream().map(SysDictItem::getItemText).collect(Collectors.toList()));
|
vo.getLegend().add("小计");
|
//
|
List<SysDepartmentInformation> sysDepartmentInformationList = new ArrayList<>();
|
if(dto.getDepartmentLevel()!=null || dto.getDepartmentProperty()!=null || dto.getDepartmentType()!=null || dto.getIsCourts()!=null){
|
QueryWrapper<SysDepartmentInformation> wrapper = new QueryWrapper<SysDepartmentInformation>();
|
wrapper.lambda();
|
if(dto.getDepartmentLevel()!=null) wrapper.eq("department_level",dto.getDepartmentLevel());
|
if(dto.getDepartmentProperty()!=null) wrapper.eq("department_property",dto.getDepartmentProperty());
|
if(dto.getDepartmentType()!=null) wrapper.eq("department_type",dto.getDepartmentType());
|
if(dto.getIsCourts()!=null) wrapper.eq("is_courts",dto.getIsCourts());
|
sysDepartmentInformationList = sysDepartmentInformationService.list(wrapper);
|
}
|
List<SysDepartment> hospitalList = sysDepartmentService.list(new QueryWrapper<SysDepartment>()//
|
.lambda()//
|
.likeRight(SysDepartment::getTreeCode, department.getTreeCode())//
|
.in(sysDepartmentInformationList.size()>0,SysDepartment::getId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType()));//
|
if (CollectionUtils.isEmpty(hospitalList)) {
|
return vo;
|
}
|
List<MwCollectRecordDaySummary> daySummaries = mwCollectRecordDaySummaryService.list(new QueryWrapper<MwCollectRecordDaySummary>()//
|
.lambda()//
|
.in(MwCollectRecordDaySummary::getHospitalId, hospitalList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.between(dto.getStartTime()!=null && dto.getEndTime()!=null,MwCollectRecordDaySummary::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
);
|
Map<Integer, List<MwCollectRecordDaySummary>> mwCollectRecordMap = daySummaries.stream().collect(Collectors.groupingBy(MwCollectRecordDaySummary::getHospitalId));
|
//
|
List<DepartmentReportItemVO> voList = buildDepartmentReportItemVOList(wasteTypeList, hospitalList, daySummaries, mwCollectRecordMap);
|
vo.setList(voList);
|
return vo;
|
}
|
|
private List<DepartmentReportItemVO> buildDepartmentReportItemVOList(List<SysDictItem> wasteTypeList, List<SysDepartment> officeList, List<MwCollectRecordDaySummary> daySummaries, Map<Integer, List<MwCollectRecordDaySummary>> mwCollectRecordMap) {
|
|
List<DepartmentReportItemVO> voList = new ArrayList<>();
|
for (SysDepartment office : officeList) {
|
DepartmentReportItemVO itemVO = new DepartmentReportItemVO();
|
itemVO.setKey(office.getId());
|
itemVO.setName(office.getDepartName());
|
itemVO.setData(new ArrayList<>());
|
//
|
BigDecimal totalCount = BigDecimal.ZERO;
|
BigDecimal totalWeight = BigDecimal.ZERO;
|
List<MwCollectRecordDaySummary> tempList = mwCollectRecordMap.getOrDefault(office.getId(), new ArrayList<>());
|
for (SysDictItem sysDictItem : wasteTypeList) {
|
BigDecimal weight = tempList.stream().filter(e -> e.getWasteType().equals(sysDictItem.getId())).map(MwCollectRecordDaySummary::getWeight).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP);
|
BigDecimal count = tempList.stream().filter(e -> e.getWasteType().equals(sysDictItem.getId())).map(MwCollectRecordDaySummary::getAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP);
|
itemVO.getData().add(count);
|
itemVO.getData().add(weight);
|
//
|
totalCount = totalCount .add(count);
|
totalWeight = totalWeight.add(weight);
|
}
|
itemVO.getData().add(totalCount);
|
itemVO.getData().add(totalWeight);
|
voList.add(itemVO);
|
}
|
//合计
|
DepartmentReportItemVO totalItemVO = new DepartmentReportItemVO();
|
totalItemVO.setKey(-2);
|
totalItemVO.setName("合计");
|
totalItemVO.setData(new ArrayList<>());
|
BigDecimal totalCount = BigDecimal.ZERO;
|
BigDecimal totalWeight = BigDecimal.ZERO;
|
for (SysDictItem sysDictItem : wasteTypeList) {
|
BigDecimal count = daySummaries.stream().filter(e -> e.getWasteType().equals(sysDictItem.getId())).map(MwCollectRecordDaySummary::getAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP);
|
BigDecimal weight = daySummaries.stream().filter(e -> e.getWasteType().equals(sysDictItem.getId())).map(MwCollectRecordDaySummary::getWeight).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP);
|
totalItemVO.getData().add(count);
|
totalItemVO.getData().add(weight);
|
//
|
totalCount = totalCount .add(count);
|
totalWeight = totalWeight.add(weight);
|
}
|
totalItemVO.getData().add(totalCount);
|
totalItemVO.getData().add(totalWeight);
|
voList.add(0,totalItemVO);
|
return voList;
|
}
|
|
/**
|
* 区域产废报表
|
*
|
* @param dto
|
* @return
|
*/
|
public DepartmentReportVO getRegionReportList(CollectRecordSummaryDTO dto) {
|
|
SysDepartment department = sysDepartmentService.getById(dto.getDepartmentId());
|
if (department == null) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
if (!department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.AREA.getType())) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
DepartmentReportVO vo = new DepartmentReportVO();
|
vo.setDepartmentName(department.getDepartName());
|
List<SysDictItem> wasteTypeList = reportBiz.getWasteTypeList();
|
if (CollectionUtils.isEmpty(wasteTypeList)) {
|
return vo;
|
}
|
vo.setLegend(wasteTypeList.stream().map(SysDictItem::getItemText).collect(Collectors.toList()));
|
vo.getLegend().add("小计");
|
//
|
List<SysDepartment> regionList = sysDepartmentService.list(new QueryWrapper<SysDepartment>()//
|
.lambda()//
|
.eq(SysDepartment::getParentId, department.getId())//
|
.eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.AREA.getType()));//
|
if (CollectionUtils.isEmpty(regionList)) {
|
return vo;
|
}
|
List<SysDepartmentInformation> sysDepartmentInformationList = new ArrayList<>();
|
//if(dto.getDepartmentLevel()!=null || dto.getDepartmentProperty()!=null || dto.getDepartmentType()!=null || dto.getIsCourts()!=null){
|
QueryWrapper<SysDepartmentInformation> wrapper = new QueryWrapper<SysDepartmentInformation>();
|
wrapper.lambda();
|
if(dto.getDepartmentLevel()!=null) wrapper.eq("department_level",dto.getDepartmentLevel());
|
if(dto.getDepartmentProperty()!=null) wrapper.eq("department_property",dto.getDepartmentProperty());
|
if(dto.getDepartmentType()!=null) wrapper.eq("department_type",dto.getDepartmentType());
|
if(dto.getIsCourts()!=null) wrapper.eq("is_courts",dto.getIsCourts());
|
sysDepartmentInformationList = sysDepartmentInformationService.list(wrapper);
|
//}
|
List<MwCollectRecordDaySummary> totalMwCollectRecordList = new ArrayList<>();
|
List<DepartmentReportItemVO> voList = new ArrayList<>();
|
for (SysDepartment sysDepartment : regionList) {
|
DepartmentReportItemVO itemVO = new DepartmentReportItemVO();
|
itemVO.setKey(sysDepartment.getId());
|
itemVO.setName(sysDepartment.getDepartName());
|
itemVO.setData(new ArrayList<>());
|
List<SysDepartment> childrenList = null;
|
//获取下级组织
|
if(sysDepartmentInformationList.size()>0){
|
childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda()
|
.likeRight(SysDepartment::getTreeCode, sysDepartment.getTreeCode())
|
.in(SysDepartment::getId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
);
|
}else {
|
childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda()
|
.likeRight(SysDepartment::getTreeCode, sysDepartment.getTreeCode())
|
.in(SysDepartment::getId, sysDepartmentInformationList.add(new SysDepartmentInformation()))
|
);
|
}
|
List<MwCollectRecordDaySummary> mwCollectRecordList = new ArrayList<>();
|
if (CollectionUtils.isNotEmpty(childrenList)) {
|
mwCollectRecordList = mwCollectRecordDaySummaryService.list(new QueryWrapper<MwCollectRecordDaySummary>().lambda()//
|
.in(MwCollectRecordDaySummary::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.between(dto.getStartTime()!=null && dto.getEndTime()!=null,MwCollectRecordDaySummary::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
);
|
totalMwCollectRecordList.addAll(mwCollectRecordList);
|
}
|
BigDecimal totalCount = BigDecimal.ZERO;
|
BigDecimal totalWeight = BigDecimal.ZERO;
|
for (SysDictItem sysDictItem : wasteTypeList) {
|
BigDecimal count = mwCollectRecordList.stream().filter(e -> e.getWasteType().equals(sysDictItem.getId())).map(MwCollectRecordDaySummary::getAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(0, BigDecimal.ROUND_HALF_UP);
|
BigDecimal weight = mwCollectRecordList.stream().filter(e -> e.getWasteType().equals(sysDictItem.getId())).map(MwCollectRecordDaySummary::getWeight).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP);
|
itemVO.getData().add(count);
|
itemVO.getData().add(weight);
|
//
|
totalCount = totalCount .add(count);
|
totalWeight = totalWeight.add(weight);
|
}
|
itemVO.getData().add(totalCount);
|
itemVO.getData().add(totalWeight);
|
voList.add(itemVO);
|
}
|
//合计
|
DepartmentReportItemVO totalItemVO = new DepartmentReportItemVO();
|
totalItemVO.setKey(-2);
|
totalItemVO.setName("合计");
|
totalItemVO.setData(new ArrayList<>());
|
BigDecimal totalCount = BigDecimal.ZERO;
|
BigDecimal totalWeight = BigDecimal.ZERO;
|
for (SysDictItem sysDictItem : wasteTypeList) {
|
BigDecimal count = totalMwCollectRecordList.stream().filter(e -> e.getWasteType().equals(sysDictItem.getId())).map(MwCollectRecordDaySummary::getAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(0, BigDecimal.ROUND_HALF_UP);
|
BigDecimal weight = totalMwCollectRecordList.stream().filter(e -> e.getWasteType().equals(sysDictItem.getId())).map(MwCollectRecordDaySummary::getWeight).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP);
|
totalItemVO.getData().add(count);
|
totalItemVO.getData().add(weight);
|
//
|
totalCount = totalCount.add(count);
|
totalWeight = totalWeight.add(weight);
|
}
|
totalItemVO.getData().add(totalCount);
|
totalItemVO.getData().add(totalWeight);
|
voList.add(0,totalItemVO);
|
vo.setList(voList);
|
return vo;
|
}
|
/**
|
* 医院产废报表
|
*
|
* @param dto
|
* @return
|
*/
|
public DepartmentReportVO getHospitalStatementList(CollectRecordSummaryDTO dto) {
|
|
SysDepartment department = sysDepartmentService.getById(dto.getDepartmentId());
|
if (department == null) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
if (!department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.AREA.getType())) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
DepartmentReportVO vo = new DepartmentReportVO();
|
vo.setDepartmentName(department.getDepartName());
|
List<SysDictItem> wasteTypeList = reportBiz.getWasteTypeList();
|
if (CollectionUtils.isEmpty(wasteTypeList)) {
|
return vo;
|
}
|
vo.setLegend(wasteTypeList.stream().map(SysDictItem::getItemText).collect(Collectors.toList()));
|
vo.getLegend().add("小计");
|
//
|
List<SysDepartmentInformation> sysDepartmentInformationList = new ArrayList<>();
|
if(dto.getDepartmentLevel()!=null || dto.getDepartmentProperty()!=null || dto.getDepartmentType()!=null || dto.getIsCourts()!=null){
|
QueryWrapper<SysDepartmentInformation> wrapper = new QueryWrapper<SysDepartmentInformation>();
|
wrapper.lambda();
|
if(dto.getDepartmentLevel()!=null) wrapper.eq("department_level",dto.getDepartmentLevel());
|
if(dto.getDepartmentProperty()!=null) wrapper.eq("department_property",dto.getDepartmentProperty());
|
if(dto.getDepartmentType()!=null) wrapper.eq("department_type",dto.getDepartmentType());
|
if(dto.getIsCourts()!=null) wrapper.eq("is_courts",dto.getIsCourts());
|
sysDepartmentInformationList = sysDepartmentInformationService.list(wrapper);
|
}
|
List<SysDepartment> hospitalList = sysDepartmentService.list(new QueryWrapper<SysDepartment>()//
|
.lambda()//
|
.likeRight(SysDepartment::getTreeCode, department.getTreeCode())//
|
.in(sysDepartmentInformationList.size()>0,SysDepartment::getId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType()));//
|
if (CollectionUtils.isEmpty(hospitalList)) {
|
return vo;
|
}
|
List<MwCollectRecordDaySummary> daySummaries = mwCollectRecordDaySummaryService.list(new QueryWrapper<MwCollectRecordDaySummary>()//
|
.lambda()//
|
.in(MwCollectRecordDaySummary::getHospitalId, hospitalList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.between(dto.getStartTime()!=null && dto.getEndTime()!=null,MwCollectRecordDaySummary::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
);
|
vo.setList(buildDepartmentStatementItemVOList(wasteTypeList,daySummaries,dto));
|
return vo;
|
}
|
|
private List<DepartmentReportItemVO> buildDepartmentStatementItemVOList(
|
List<SysDictItem> wasteTypeList,
|
List<MwCollectRecordDaySummary> tempList,
|
CollectRecordSummaryDTO dto) {
|
List<DepartmentReportItemVO> voList = new ArrayList<>();
|
//日期数组
|
SimpleDateFormat sdf = new SimpleDateFormat(DEFAULT_PATTERN);
|
List<String> dateList = DateUtil.getMonthBetween(sdf.format(dto.getStartTime()),sdf.format(dto.getEndTime()),dto.getStatisticalWayType());
|
SimpleDateFormat sdfWayType = new SimpleDateFormat(YYYY_MM_DD);
|
if(dto.getStatisticalWayType() == 4){//年
|
sdfWayType = new SimpleDateFormat(yyyy);
|
}else if(dto.getStatisticalWayType() == 2 || dto.getStatisticalWayType() == 3){//月
|
sdfWayType = new SimpleDateFormat(yyyy_MM);
|
}
|
for(String date : dateList){
|
DepartmentReportItemVO itemVO = new DepartmentReportItemVO();
|
itemVO.setKey(null);
|
itemVO.setName(null);
|
itemVO.setName(date);
|
itemVO.setData(new ArrayList<>());
|
SimpleDateFormat finalSdfWayType = sdfWayType;
|
BigDecimal totalCount = BigDecimal.ZERO;
|
BigDecimal totalWeight = BigDecimal.ZERO;
|
for (SysDictItem sysDictItem : wasteTypeList) {
|
BigDecimal weight = tempList.stream().filter(e -> e.getWasteType().equals(sysDictItem.getId())
|
&& finalSdfWayType.format(e.getCreateTime()).equals(date)
|
).map(MwCollectRecordDaySummary::getWeight).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP);
|
BigDecimal count = tempList.stream().filter(e -> e.getWasteType().equals(sysDictItem.getId())
|
&& finalSdfWayType.format(e.getCreateTime()).equals(date)
|
).map(MwCollectRecordDaySummary::getAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP);
|
itemVO.getData().add(count);
|
itemVO.getData().add(weight);
|
totalCount = totalCount .add(count);
|
totalWeight = totalWeight.add(weight);
|
}
|
itemVO.getData().add(totalCount);
|
itemVO.getData().add(totalWeight);
|
voList.add(itemVO);
|
}
|
|
//合计
|
DepartmentReportItemVO totalItemVO = new DepartmentReportItemVO();
|
totalItemVO.setKey(-2);
|
totalItemVO.setName("合计");
|
totalItemVO.setData(new ArrayList<>());
|
BigDecimal totalCount = BigDecimal.ZERO;
|
BigDecimal totalWeight = BigDecimal.ZERO;
|
for (SysDictItem sysDictItem : wasteTypeList) {
|
BigDecimal count = tempList.stream().filter(e -> e.getWasteType().equals(sysDictItem.getId())).map(MwCollectRecordDaySummary::getAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP);
|
BigDecimal weight = tempList.stream().filter(e -> e.getWasteType().equals(sysDictItem.getId())).map(MwCollectRecordDaySummary::getWeight).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP);
|
totalItemVO.getData().add(count);
|
totalItemVO.getData().add(weight);
|
//
|
totalCount = totalCount .add(count);
|
totalWeight = totalWeight.add(weight);
|
}
|
totalItemVO.getData().add(totalCount);
|
totalItemVO.getData().add(totalWeight);
|
voList.add(0,totalItemVO);
|
return voList;
|
}
|
/**
|
* 区域产废报表
|
*
|
* @param dto
|
* @return
|
*/
|
public DepartmentReportVO getRegionStatementList(CollectRecordSummaryDTO dto) {
|
|
SysDepartment department = sysDepartmentService.getById(dto.getDepartmentId());
|
if (department == null) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
if (!department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.AREA.getType())) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
DepartmentReportVO vo = new DepartmentReportVO();
|
vo.setDepartmentName(department.getDepartName());
|
List<SysDictItem> wasteTypeList = reportBiz.getWasteTypeList();
|
if (CollectionUtils.isEmpty(wasteTypeList)) {
|
return vo;
|
}
|
vo.setLegend(wasteTypeList.stream().map(SysDictItem::getItemText).collect(Collectors.toList()));
|
vo.getLegend().add("小计");
|
//
|
List<SysDepartment> regionList = sysDepartmentService.list(new QueryWrapper<SysDepartment>()//
|
.lambda()//
|
.eq(SysDepartment::getParentId, department.getId())//
|
.eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.AREA.getType()));//
|
if (CollectionUtils.isEmpty(regionList)) {
|
return vo;
|
}
|
List<SysDepartmentInformation> sysDepartmentInformationList = new ArrayList<>();
|
if(dto.getDepartmentLevel()!=null || dto.getDepartmentProperty()!=null || dto.getDepartmentType()!=null || dto.getIsCourts()!=null){
|
QueryWrapper<SysDepartmentInformation> wrapper = new QueryWrapper<SysDepartmentInformation>();
|
wrapper.lambda();
|
if(dto.getDepartmentLevel()!=null) wrapper.eq("department_level",dto.getDepartmentLevel());
|
if(dto.getDepartmentProperty()!=null) wrapper.eq("department_property",dto.getDepartmentProperty());
|
if(dto.getDepartmentType()!=null) wrapper.eq("department_type",dto.getDepartmentType());
|
if(dto.getIsCourts()!=null) wrapper.eq("is_courts",dto.getIsCourts());
|
sysDepartmentInformationList = sysDepartmentInformationService.list(wrapper);
|
}
|
List<MwCollectRecordDaySummary> totalMwCollectRecordList = new ArrayList<>();
|
List<SysDepartment> childrenListAll = new ArrayList<>();
|
for (SysDepartment sysDepartment : regionList) {
|
DepartmentReportItemVO itemVO = new DepartmentReportItemVO();
|
itemVO.setKey(sysDepartment.getId());
|
itemVO.setName(sysDepartment.getDepartName());
|
itemVO.setData(new ArrayList<>());
|
//获取下级组织
|
List<SysDepartment> childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda()
|
.likeRight(SysDepartment::getTreeCode, sysDepartment.getTreeCode())
|
.in(sysDepartmentInformationList.size()>0,SysDepartment::getId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
);
|
childrenListAll = Stream.of(childrenListAll, childrenList)
|
.flatMap(Collection::stream).distinct().collect(Collectors.toList());
|
}
|
List<MwCollectRecordDaySummary> mwCollectRecordList = new ArrayList<>();
|
if (CollectionUtils.isNotEmpty(childrenListAll)) {
|
mwCollectRecordList = mwCollectRecordDaySummaryService.list(new QueryWrapper<MwCollectRecordDaySummary>().lambda()//
|
.in(MwCollectRecordDaySummary::getHospitalId, childrenListAll.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.between(dto.getStartTime()!=null && dto.getEndTime()!=null,MwCollectRecordDaySummary::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
);
|
totalMwCollectRecordList.addAll(mwCollectRecordList);
|
}
|
vo.setList(buildDepartmentStatementItemVOList(wasteTypeList,totalMwCollectRecordList,dto));
|
return vo;
|
}
|
|
|
|
/**
|
* 预警级别统计(区域)
|
*
|
* @param dto
|
* @return
|
*/
|
public CollectionWarningLevelReportVO getWarningRegionLevelReportList(CollectionWarningLevelDTO dto) {
|
SysDepartment department = sysDepartmentService.getById(dto.getDepartmentId());
|
if (department == null) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
if (!department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.AREA.getType())) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
CollectionWarningLevelReportVO vo = new CollectionWarningLevelReportVO();
|
vo.setDepartmentName(department.getDepartName());
|
if(dto.getWarningStatisticalType()!=null && dto.getWarningStatisticalType()==2){
|
vo.setLegend(Arrays.asList("未出医废预警","入库超时预警","入库前疑似遗失预警","出库超时预警","入库后疑似遗失预警","小计"));
|
}else {
|
vo.setLegend(Arrays.asList("一级预警","二级预警","三级预警","小计"));
|
}
|
//
|
List<SysDepartment> regionList = sysDepartmentService.list(new QueryWrapper<SysDepartment>()//
|
.lambda()//
|
.eq(SysDepartment::getParentId, department.getId())//
|
.eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.AREA.getType()));//
|
if (CollectionUtils.isEmpty(regionList)) {
|
return vo;
|
}
|
|
List<SysDepartmentInformation> sysDepartmentInformationList = new ArrayList<>();
|
//if(dto.getDepartmentLevel()!=null || dto.getDepartmentProperty()!=null || dto.getDepartmentType()!=null || dto.getIsCourts()!=null){
|
QueryWrapper<SysDepartmentInformation> wrapper = new QueryWrapper<SysDepartmentInformation>();
|
wrapper.lambda();
|
if(dto.getDepartmentLevel()!=null) wrapper.eq("department_level",dto.getDepartmentLevel());
|
if(dto.getDepartmentProperty()!=null) wrapper.eq("department_property",dto.getDepartmentProperty());
|
if(dto.getDepartmentType()!=null) wrapper.eq("department_type",dto.getDepartmentType());
|
if(dto.getIsCourts()!=null) wrapper.eq("is_courts",dto.getIsCourts());
|
sysDepartmentInformationList = sysDepartmentInformationService.list(wrapper);
|
//}
|
List<MwWarningRecord> totalMwCollectRecordList = new ArrayList<>();
|
List<CollectionWarningLevelItemVO> voList = new ArrayList<>();
|
for (SysDepartment sysDepartment : regionList) {
|
CollectionWarningLevelItemVO itemVO = new CollectionWarningLevelItemVO();
|
itemVO.setKey(sysDepartment.getId());
|
itemVO.setName(sysDepartment.getDepartName());
|
itemVO.setData(new ArrayList<>());
|
List<SysDepartment> childrenList = null;
|
//获取下级组织
|
if(sysDepartmentInformationList.size()>0){
|
childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda()
|
.likeRight(SysDepartment::getTreeCode, sysDepartment.getTreeCode())
|
.in(SysDepartment::getId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
);
|
}else {
|
childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda()
|
.likeRight(SysDepartment::getTreeCode, sysDepartment.getTreeCode())
|
.in(SysDepartment::getId,sysDepartmentInformationList.add(new SysDepartmentInformation()))//
|
);
|
}
|
|
List<MwWarningRecord> mwWarningRecords = new ArrayList<>();
|
if (CollectionUtils.isNotEmpty(childrenList)) {
|
mwWarningRecords = warningRecordService.list(new QueryWrapper<MwWarningRecord>().lambda()//
|
.in(MwWarningRecord::getHospitalId, childrenList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.between(dto.getStartTime()!=null && dto.getStartTime()!=null,MwWarningRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.between(dto.getRelieveStartTime()!=null && dto.getRelieveStartTime()!=null,MwWarningRecord::getRelieveTime, DateUtil.format(dto.getRelieveStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getRelieveEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
);
|
totalMwCollectRecordList.addAll(mwWarningRecords);
|
}
|
voList.add(getLevelVoList(mwWarningRecords,itemVO,dto.getWarningStatisticalType()));
|
}
|
//合计
|
CollectionWarningLevelItemVO totalItemVO = new CollectionWarningLevelItemVO();
|
totalItemVO.setKey(-2);
|
totalItemVO.setName("合计");
|
totalItemVO.setData(new ArrayList<>());
|
voList.add(0,getLevelVoList(totalMwCollectRecordList,totalItemVO,dto.getWarningStatisticalType()));
|
vo.setList(voList);
|
return vo;
|
}
|
//预警级别
|
private CollectionWarningLevelItemVO getLevelVoList(List<MwWarningRecord> totalMwCollectRecordList,
|
CollectionWarningLevelItemVO itemVO,Integer warningStatisticalType
|
){
|
//总预警数
|
BigDecimal warningTotalCount = new BigDecimal(0);
|
//总反馈数
|
BigDecimal feedbackTotalCount = new BigDecimal(0);
|
//总解除数
|
BigDecimal relieveTotalCount = new BigDecimal(0);
|
List<Integer> legend=new ArrayList<>();
|
if(warningStatisticalType!=null && warningStatisticalType==2) {
|
//todo 预警类型
|
//1:未出医废预警 3:入库超时预警 5:入库前疑似遗失预警 4:出库超时预警 10:入库后疑似遗失预警
|
legend = Arrays.asList(1,3,5,4,10);
|
}else {
|
//todo 等级
|
legend = Arrays.asList(1,2,3);
|
}
|
|
for(Integer l:legend){
|
//预警数据
|
Long warningCount = 0L;
|
if(warningStatisticalType!=null && warningStatisticalType==2){
|
warningCount = totalMwCollectRecordList.stream().filter(e -> e.getType().equals(l)).count();
|
}else {
|
warningCount = totalMwCollectRecordList.stream().filter(e -> e.getLevel().equals(l)).count();
|
}
|
warningTotalCount = warningTotalCount.add(new BigDecimal(warningCount));
|
//反馈数据
|
Long feedbackCount = 0L;
|
if(warningStatisticalType!=null && warningStatisticalType==2){
|
feedbackCount = totalMwCollectRecordList.stream().filter(e -> e.getType().equals(l) && e.getMessageCount()>0).count();
|
}else {
|
feedbackCount = totalMwCollectRecordList.stream().filter(e -> e.getLevel().equals(l) && e.getMessageCount()>0).count();
|
}
|
|
feedbackTotalCount = feedbackTotalCount.add(new BigDecimal(feedbackCount));
|
//解除数
|
Long relieveCount = 0L;
|
if(warningStatisticalType!=null && warningStatisticalType==2){
|
relieveCount = totalMwCollectRecordList.stream().filter(e -> e.getType().equals(l) && e.getStatus().equals(MedicalWasteEnum.WarningRecordStatusEnum.PASS)).count();
|
}else {
|
relieveCount = totalMwCollectRecordList.stream().filter(e -> e.getLevel().equals(l) && e.getStatus().equals(MedicalWasteEnum.WarningRecordStatusEnum.PASS)).count();
|
}
|
relieveTotalCount = relieveTotalCount.add(new BigDecimal(relieveCount));
|
|
itemVO.getData().add(new BigDecimal(warningCount));
|
itemVO.getData().add(new BigDecimal(feedbackCount));
|
|
BigDecimal feedbackPercentage = new BigDecimal(0);
|
BigDecimal relievePercentage = new BigDecimal(0);
|
if(warningCount>0){
|
//反馈率
|
feedbackPercentage = new BigDecimal(feedbackCount).divide(new BigDecimal(warningCount),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP);
|
//解除率
|
relievePercentage = new BigDecimal(relieveCount).divide(new BigDecimal(warningCount),4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP);
|
}
|
itemVO.getData().add(feedbackPercentage);
|
itemVO.getData().add(new BigDecimal(relieveCount));
|
|
itemVO.getData().add(relievePercentage);
|
}
|
|
|
BigDecimal feedbackTotalPercentage = new BigDecimal(0);
|
BigDecimal relieveTotalPercentage = new BigDecimal(0);
|
if(warningTotalCount.intValue()>0){
|
feedbackTotalPercentage = feedbackTotalCount.divide(warningTotalCount,4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP);
|
relieveTotalPercentage = relieveTotalCount.divide(warningTotalCount,4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP);
|
}
|
itemVO.getData().add(warningTotalCount);
|
itemVO.getData().add(feedbackTotalCount);
|
itemVO.getData().add(feedbackTotalPercentage);
|
itemVO.getData().add(relieveTotalCount);
|
itemVO.getData().add(relieveTotalPercentage);
|
return itemVO;
|
}
|
|
/**
|
* 预警级别统计(医院)
|
*
|
* @param dto
|
* @return
|
*/
|
public CollectionWarningLevelReportVO getWarningHospitalLevelReportList(CollectionWarningLevelDTO dto) {
|
|
SysDepartment department = sysDepartmentService.getById(dto.getDepartmentId());
|
if (department == null) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
if (!department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.AREA.getType())) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
CollectionWarningLevelReportVO vo = new CollectionWarningLevelReportVO();
|
vo.setDepartmentName(department.getDepartName());
|
//
|
List<SysDepartmentInformation> sysDepartmentInformationList = new ArrayList<>();
|
if(dto.getDepartmentLevel()!=null || dto.getDepartmentProperty()!=null || dto.getDepartmentType()!=null || dto.getIsCourts()!=null){
|
QueryWrapper<SysDepartmentInformation> wrapper = new QueryWrapper<SysDepartmentInformation>();
|
wrapper.lambda();
|
if(dto.getDepartmentLevel()!=null) wrapper.eq("department_level",dto.getDepartmentLevel());
|
if(dto.getDepartmentProperty()!=null) wrapper.eq("department_property",dto.getDepartmentProperty());
|
if(dto.getDepartmentType()!=null) wrapper.eq("department_type",dto.getDepartmentType());
|
if(dto.getIsCourts()!=null) wrapper.eq("is_courts",dto.getIsCourts());
|
sysDepartmentInformationList = sysDepartmentInformationService.list(wrapper);
|
}
|
List<SysDepartment> hospitalList = sysDepartmentService.list(new QueryWrapper<SysDepartment>()//
|
.lambda()//
|
.likeRight(SysDepartment::getTreeCode, department.getTreeCode())//
|
.in(sysDepartmentInformationList.size()>0,SysDepartment::getId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType()));//
|
if (CollectionUtils.isEmpty(hospitalList)) {
|
return vo;
|
}
|
List<MwWarningRecord> mwWarningRecords = new ArrayList<>();
|
mwWarningRecords = warningRecordService.list(new QueryWrapper<MwWarningRecord>().lambda()//
|
.in(MwWarningRecord::getHospitalId, hospitalList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.between(dto.getStartTime()!=null && dto.getStartTime()!=null,MwWarningRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.between(dto.getRelieveStartTime()!=null && dto.getRelieveStartTime()!=null,MwWarningRecord::getRelieveTime, DateUtil.format(dto.getRelieveStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getRelieveEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
);
|
Map<Integer, List<MwWarningRecord>> mwCollectRecordMap = mwWarningRecords.stream().collect(Collectors.groupingBy(MwWarningRecord::getHospitalId));
|
List<CollectionWarningLevelItemVO> voList = new ArrayList<>();
|
for (SysDepartment sysDepartment : hospitalList) {
|
CollectionWarningLevelItemVO itemVO = new CollectionWarningLevelItemVO();
|
itemVO.setKey(sysDepartment.getId());
|
itemVO.setName(sysDepartment.getDepartName());
|
itemVO.setData(new ArrayList<>());
|
List<MwWarningRecord> tempList = mwCollectRecordMap.getOrDefault(sysDepartment.getId(), new ArrayList<>());
|
voList.add(getLevelVoList(tempList,itemVO,dto.getWarningStatisticalType()));
|
|
}
|
//合计
|
CollectionWarningLevelItemVO totalItemVO = new CollectionWarningLevelItemVO();
|
totalItemVO.setKey(-2);
|
totalItemVO.setName("合计");
|
totalItemVO.setData(new ArrayList<>());
|
voList.add(0,getLevelVoList(mwWarningRecords,totalItemVO,dto.getWarningStatisticalType()));
|
vo.setList(voList);
|
return vo;
|
}
|
|
/**
|
* 导出报表
|
*
|
* @param dto 1区域产废统计 2医院产废统计
|
* @param type 1:统计,2:报表
|
*
|
*/
|
public void exportDepartmentReport(HttpServletResponse response, CollectRecordSummaryDTO dto,Integer type) throws IOException {
|
|
String fileName = "";
|
ExcelWriter writer = null;
|
if(type==1){
|
switch (dto.getStyleTpl()) {
|
case 1:
|
fileName = "区域产废统计";
|
writer = new ExcelWriter(exportDepartmentReport(dto, fileName,type), fileName);
|
break;
|
case 2:
|
fileName = "医院产废统计";
|
writer = new ExcelWriter(exportDepartmentReport(dto, fileName,type), fileName);
|
break;
|
default:
|
throw new BusinessException(ErrorCode.ERR_500, "请选择报表类型");
|
}
|
}else {
|
switch (dto.getStyleTpl()) {
|
case 1:
|
fileName = "区域产废报表";
|
writer = new ExcelWriter(exportDepartmentReport(dto, fileName,type), fileName);
|
break;
|
case 2:
|
fileName = "医院产废报表";
|
writer = new ExcelWriter(exportDepartmentReport(dto, fileName,type), fileName);
|
break;
|
default:
|
throw new BusinessException(ErrorCode.ERR_500, "请选择报表类型");
|
}
|
}
|
|
if (writer != null) {
|
response.setContentType("application/octet-stream;charset=utf-8");
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
|
writer.flush(response.getOutputStream(), true);
|
writer.close();
|
}
|
}
|
|
/**
|
* 预警级别报表(区域)
|
*
|
* @param dto
|
* @return
|
*/
|
public CollectionWarningLevelReportVO getWarningRegionLevelStatementList(CollectionWarningLevelDTO dto) {
|
SysDepartment department = sysDepartmentService.getById(dto.getDepartmentId());
|
if (department == null) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
if (!department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.AREA.getType())) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
CollectionWarningLevelReportVO vo = new CollectionWarningLevelReportVO();
|
vo.setDepartmentName(department.getDepartName());
|
if(dto.getWarningStatisticalType()!=null && dto.getWarningStatisticalType()==2){
|
vo.setLegend(Arrays.asList("未出医废预警","入库超时预警","入库前疑似遗失预警","出库超时预警","入库后疑似遗失预警","小计"));
|
}else {
|
vo.setLegend(Arrays.asList("一级预警","二级预警","三级预警","小计"));
|
}
|
//
|
List<SysDepartment> regionList = sysDepartmentService.list(new QueryWrapper<SysDepartment>()//
|
.lambda()//
|
.eq(SysDepartment::getParentId, department.getId())//
|
.eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.AREA.getType()));//
|
if (CollectionUtils.isEmpty(regionList)) {
|
return vo;
|
}
|
|
List<SysDepartmentInformation> sysDepartmentInformationList = new ArrayList<>();
|
//if(dto.getDepartmentLevel()!=null || dto.getDepartmentProperty()!=null || dto.getDepartmentType()!=null || dto.getIsCourts()!=null){
|
QueryWrapper<SysDepartmentInformation> wrapper = new QueryWrapper<SysDepartmentInformation>();
|
wrapper.lambda();
|
if(dto.getDepartmentLevel()!=null) wrapper.eq("department_level",dto.getDepartmentLevel());
|
if(dto.getDepartmentProperty()!=null) wrapper.eq("department_property",dto.getDepartmentProperty());
|
if(dto.getDepartmentType()!=null) wrapper.eq("department_type",dto.getDepartmentType());
|
if(dto.getIsCourts()!=null) wrapper.eq("is_courts",dto.getIsCourts());
|
sysDepartmentInformationList = sysDepartmentInformationService.list(wrapper);
|
//}
|
List<MwWarningRecord> totalMwCollectRecordList = new ArrayList<>();
|
List<SysDepartment> childrenListAll = new ArrayList<>();
|
for (SysDepartment sysDepartment : regionList) {
|
List<SysDepartment> childrenList = null;
|
if(sysDepartmentInformationList.size() > 0) {
|
//获取下级组织
|
childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda()
|
.likeRight(SysDepartment::getTreeCode, sysDepartment.getTreeCode())
|
.in( SysDepartment::getId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
);
|
}else {
|
//获取下级组织
|
childrenList = sysDepartmentService.list(new QueryWrapper<SysDepartment>().lambda()
|
.likeRight(SysDepartment::getTreeCode, sysDepartment.getTreeCode())
|
.in( SysDepartment::getId, sysDepartmentInformationList.add(new SysDepartmentInformation()))//
|
);
|
}
|
childrenListAll = Stream.of(childrenListAll, childrenList)
|
.flatMap(Collection::stream).distinct().collect(Collectors.toList());
|
}
|
List<MwWarningRecord> mwWarningRecords = new ArrayList<>();
|
if (CollectionUtils.isNotEmpty(childrenListAll)) {
|
mwWarningRecords = warningRecordService.list(new QueryWrapper<MwWarningRecord>().lambda()//
|
.in(MwWarningRecord::getHospitalId, childrenListAll.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.between(dto.getStartTime()!=null && dto.getStartTime()!=null,MwWarningRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.between(dto.getRelieveStartTime()!=null && dto.getRelieveStartTime()!=null,MwWarningRecord::getRelieveTime, DateUtil.format(dto.getRelieveStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getRelieveEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
);
|
totalMwCollectRecordList.addAll(mwWarningRecords);
|
}
|
//合计
|
vo.setList(getStatementVoList(totalMwCollectRecordList,dto.getWarningStatisticalType(),dto));
|
return vo;
|
}
|
//预警报表
|
private List<CollectionWarningLevelItemVO> getStatementVoList(List<MwWarningRecord> totalMwCollectRecordList,
|
Integer warningStatisticalType,
|
CollectionWarningLevelDTO dto
|
){
|
List<CollectionWarningLevelItemVO> voList = new ArrayList<>();
|
List<Integer> legend = new ArrayList<>();
|
if (warningStatisticalType != null && warningStatisticalType == 2) {
|
//todo 预警类型
|
//1:未出医废预警 3:入库超时预警 5:入库前疑似遗失预警 4:出库超时预警 10:入库后疑似遗失预警
|
legend = Arrays.asList(1, 3, 5, 4, 10);
|
} else {
|
//todo 等级
|
legend = Arrays.asList(1, 2, 3);
|
}
|
//todo 根据日期汇总
|
|
//日期数组
|
SimpleDateFormat sdf = new SimpleDateFormat(DEFAULT_PATTERN);
|
List<String> dateList = DateUtil.getMonthBetween(sdf.format(dto.getStartTime()),sdf.format(dto.getEndTime()),dto.getStatisticalWayType());
|
SimpleDateFormat sdfWayType = new SimpleDateFormat(YYYY_MM_DD);
|
if(dto.getStatisticalWayType() == 4){//年
|
sdfWayType = new SimpleDateFormat(yyyy);
|
}else if(dto.getStatisticalWayType() == 2 || dto.getStatisticalWayType() == 3){//月
|
sdfWayType = new SimpleDateFormat(yyyy_MM);
|
}
|
for(String date : dateList){
|
CollectionWarningLevelItemVO itemVO= new CollectionWarningLevelItemVO();
|
itemVO.setKey(null);
|
itemVO.setName(null);
|
itemVO.setName(date);
|
itemVO.setData(new ArrayList<>());
|
SimpleDateFormat finalSdfWayType = sdfWayType;
|
//总预警数
|
BigDecimal warningTotalCount = new BigDecimal(0);
|
//总反馈数
|
BigDecimal feedbackTotalCount = new BigDecimal(0);
|
//总解除数
|
BigDecimal relieveTotalCount = new BigDecimal(0);
|
for (Integer l : legend) {
|
//预警数据
|
Long warningCount = 0L;
|
if (warningStatisticalType != null && warningStatisticalType == 2) {
|
warningCount = totalMwCollectRecordList.stream().filter(e -> e.getType().equals(l)
|
&& finalSdfWayType.format(e.getCreateTime()).equals(date))
|
.count();
|
} else {
|
warningCount = totalMwCollectRecordList.stream().filter(e -> e.getLevel().equals(l)
|
&& finalSdfWayType.format(e.getCreateTime()).equals(date))
|
.count();
|
}
|
//反馈数据
|
Long feedbackCount = 0L;
|
if (warningStatisticalType != null && warningStatisticalType == 2) {
|
feedbackCount = totalMwCollectRecordList.stream().filter(e -> e.getType().equals(l) && e.getMessageCount() > 0
|
&& finalSdfWayType.format(e.getCreateTime()).equals(date))
|
.count();
|
} else {
|
feedbackCount = totalMwCollectRecordList.stream().filter(e -> e.getLevel().equals(l) && e.getMessageCount() > 0
|
&& finalSdfWayType.format(e.getCreateTime()).equals(date))
|
.count();
|
}
|
|
//解除数
|
Long relieveCount = 0L;
|
if (warningStatisticalType != null && warningStatisticalType == 2) {
|
relieveCount = totalMwCollectRecordList.stream().filter(e -> e.getType().equals(l) && e.getStatus().equals(MedicalWasteEnum.WarningRecordStatusEnum.PASS)
|
&& finalSdfWayType.format(e.getCreateTime()).equals(date))
|
.count();
|
} else {
|
relieveCount = totalMwCollectRecordList.stream().filter(e -> e.getLevel().equals(l) && e.getStatus().equals(MedicalWasteEnum.WarningRecordStatusEnum.PASS)
|
&& finalSdfWayType.format(e.getCreateTime()).equals(date))
|
.count();
|
}
|
|
itemVO.getData().add(new BigDecimal(warningCount));
|
warningTotalCount = warningTotalCount.add(new BigDecimal(warningCount));
|
itemVO.getData().add(new BigDecimal(feedbackCount));
|
feedbackTotalCount = feedbackTotalCount.add(new BigDecimal(feedbackCount));
|
|
BigDecimal feedbackPercentage = new BigDecimal(0);
|
BigDecimal relievePercentage = new BigDecimal(0);
|
if (warningCount > 0) {
|
//反馈率
|
feedbackPercentage = new BigDecimal(feedbackCount).divide(new BigDecimal(warningCount), 4, BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_UP);
|
//解除率
|
relievePercentage = new BigDecimal(relieveCount).divide(new BigDecimal(warningCount), 4, BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_UP);
|
}
|
itemVO.getData().add(feedbackPercentage);
|
itemVO.getData().add(new BigDecimal(relieveCount));
|
relieveTotalCount = relieveTotalCount.add(new BigDecimal(relieveCount));
|
itemVO.getData().add(relievePercentage);
|
}
|
BigDecimal feedbackTotalPercentage = new BigDecimal(0);
|
BigDecimal relieveTotalPercentage = new BigDecimal(0);
|
if(warningTotalCount.intValue()>0){
|
feedbackTotalPercentage = feedbackTotalCount.divide(warningTotalCount,4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP);
|
relieveTotalPercentage = relieveTotalCount.divide(warningTotalCount,4,BigDecimal.ROUND_UP).multiply(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_UP);
|
}
|
|
itemVO.getData().add(warningTotalCount);
|
itemVO.getData().add(feedbackTotalCount);
|
itemVO.getData().add(feedbackTotalPercentage);
|
itemVO.getData().add(relieveTotalCount);
|
itemVO.getData().add(relieveTotalPercentage);
|
voList.add(itemVO);
|
}
|
//合计
|
CollectionWarningLevelItemVO totalItemVO= new CollectionWarningLevelItemVO();
|
totalItemVO.setKey(-2);
|
totalItemVO.setName("合计");
|
totalItemVO.setData(new ArrayList<>());
|
voList.add(0,getLevelVoList(totalMwCollectRecordList,totalItemVO,dto.getWarningStatisticalType()));
|
return voList;
|
}
|
|
/**
|
* 预警级别统计(医院)
|
*
|
* @param dto
|
* @return
|
*/
|
public CollectionWarningLevelReportVO getWarningHospitalLevelStatementList(CollectionWarningLevelDTO dto) {
|
|
SysDepartment department = sysDepartmentService.getById(dto.getDepartmentId());
|
if (department == null) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
if (!department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.AREA.getType())) {
|
throw new BusinessException(ErrorCode.ERR_500, "区域不存在");
|
}
|
CollectionWarningLevelReportVO vo = new CollectionWarningLevelReportVO();
|
vo.setDepartmentName(department.getDepartName());
|
//
|
List<SysDepartmentInformation> sysDepartmentInformationList = new ArrayList<>();
|
if(dto.getDepartmentLevel()!=null || dto.getDepartmentProperty()!=null || dto.getDepartmentType()!=null || dto.getIsCourts()!=null){
|
QueryWrapper<SysDepartmentInformation> wrapper = new QueryWrapper<SysDepartmentInformation>();
|
wrapper.lambda();
|
if(dto.getDepartmentLevel()!=null) wrapper.eq("department_level",dto.getDepartmentLevel());
|
if(dto.getDepartmentProperty()!=null) wrapper.eq("department_property",dto.getDepartmentProperty());
|
if(dto.getDepartmentType()!=null) wrapper.eq("department_type",dto.getDepartmentType());
|
if(dto.getIsCourts()!=null) wrapper.eq("is_courts",dto.getIsCourts());
|
sysDepartmentInformationList = sysDepartmentInformationService.list(wrapper);
|
}
|
List<SysDepartment> hospitalList = sysDepartmentService.list(new QueryWrapper<SysDepartment>()//
|
.lambda()//
|
.likeRight(SysDepartment::getTreeCode, department.getTreeCode())//
|
.in(sysDepartmentInformationList.size()>0,SysDepartment::getId, sysDepartmentInformationList.stream().map(SysDepartmentInformation::getDepartmentId).collect(Collectors.toList()))//
|
.eq(SysDepartment::getOrgType, DepartmentEnum.OrgTypeEnum.HOSPITAL.getType()));//
|
if (CollectionUtils.isEmpty(hospitalList)) {
|
return vo;
|
}
|
List<MwWarningRecord> mwWarningRecords = new ArrayList<>();
|
mwWarningRecords = warningRecordService.list(new QueryWrapper<MwWarningRecord>().lambda()//
|
.in(MwWarningRecord::getHospitalId, hospitalList.stream().map(SysDepartment::getId).collect(Collectors.toList()))//
|
.between(dto.getStartTime()!=null && dto.getStartTime()!=null,MwWarningRecord::getCreateTime, DateUtil.format(dto.getStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
.between(dto.getRelieveStartTime()!=null && dto.getRelieveStartTime()!=null,MwWarningRecord::getRelieveTime, DateUtil.format(dto.getRelieveStartTime(), "yyyy-MM-dd HH:mm:ss"), DateUtil.format(dto.getRelieveEndTime(), "yyyy-MM-dd HH:mm:ss"))//
|
);
|
//合计
|
vo.setList(getStatementVoList(mwWarningRecords,dto.getWarningStatisticalType(),dto));
|
return vo;
|
}
|
|
/**
|
*
|
* @param dto
|
* @param sheetName
|
* @param type 1:统计,2:报表
|
* @return
|
*/
|
private XSSFWorkbook exportDepartmentReport(CollectRecordSummaryDTO dto, String sheetName,Integer type) {
|
|
DepartmentReportVO vo = null;
|
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
String cellName = "", title = "";
|
if (dto.getStyleTpl() == 1) {
|
if(type==1){
|
vo = getRegionReportList(dto);
|
title = vo.getDepartmentName() + "医疗废物统计";
|
cellName = "区域名称";
|
}else if(type==2){
|
vo = getRegionStatementList(dto);
|
title = vo.getDepartmentName() + "医疗废物报表";
|
cellName = "时间";
|
}
|
|
} else if (dto.getStyleTpl() == 2) {
|
if(type==1){
|
vo = getHospitalReportList(dto);
|
title = vo.getDepartmentName() + "医疗废物统计";
|
cellName = "医院名称";
|
}else if(type==2){
|
vo = getHospitalStatementList(dto);
|
title = vo.getDepartmentName() + "医疗废物报表";
|
cellName = "时间";
|
}
|
|
}
|
XSSFSheet sheet = workbook.createSheet(sheetName);
|
XSSFCellStyle cellStyle = createDefaultCellStyle(workbook);
|
XSSFCellStyle rightCellStyle = createDefaultRightCellStyle(workbook);
|
//
|
int maxCellSize = 1 + vo.getLegend().size() * 2;
|
XSSFRow titleRow = sheet.createRow(0);
|
XSSFRow dateRow = sheet.createRow(1);
|
XSSFRow firstRow = sheet.createRow(2);
|
XSSFRow secondRow = sheet.createRow(3);
|
int legendIndex = 0;
|
for (int i = 0; i < maxCellSize; i++) {
|
XSSFCell titleRowCell = titleRow.createCell(i);
|
titleRowCell.setCellStyle(cellStyle);
|
XSSFCell firstRowCell = firstRow.createCell(i);
|
firstRowCell.setCellStyle(cellStyle);
|
XSSFCell secondRowCell = secondRow.createCell(i);
|
secondRowCell.setCellStyle(cellStyle);
|
XSSFCell dateRowCell = dateRow.createCell(i);
|
dateRowCell.setCellStyle(rightCellStyle);
|
if (i == 0) {
|
titleRowCell.setCellValue(title);
|
firstRowCell.setCellValue(cellName);
|
} else {
|
if (i % 2 == 1) {
|
firstRowCell.setCellValue(vo.getLegend().get(legendIndex));
|
legendIndex++;
|
//
|
secondRowCell.setCellValue("数量");
|
} else {
|
secondRowCell.setCellValue("重量(KG)");
|
}
|
}
|
if (i == maxCellSize - 1) {
|
dto.setStatisticalWayType(dto.getStatisticalWayType()==null?1:dto.getStatisticalWayType());
|
if(dto.getStatisticalWayType() == 1 || dto.getStatisticalWayType() == 3){
|
dateRowCell.setCellValue("时间:" + DateUtil.format(dto.getStartTime(), "yyyy年MM月dd日") + "至" + DateUtil.format(dto.getEndTime(), "yyyy年MM月dd日"));
|
}else if(dto.getStatisticalWayType() == 2){
|
dateRowCell.setCellValue("时间:" + DateUtil.format(dto.getStartTime(), "yyyy年MM月") + "至" + DateUtil.format(dto.getEndTime(), "yyyy年MM月"));
|
}else if(dto.getStatisticalWayType() == 4){
|
dateRowCell.setCellValue("时间:" + DateUtil.format(dto.getStartTime(), "yyyy年") + "至" + DateUtil.format(dto.getEndTime(), "yyyy年"));
|
}
|
|
}
|
}
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, maxCellSize - 1));
|
sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 0));
|
for (int i = 0; i < vo.getLegend().size(); i++) {
|
sheet.addMergedRegion(new CellRangeAddress(2, 2, 1 + i * 2, 2 + i * 2));
|
}
|
//
|
if (CollectionUtils.isNotEmpty(vo.getList())) {
|
for (int i = 0; i < vo.getList().size(); i++) {
|
DepartmentReportItemVO itemVO = vo.getList().get(i);
|
XSSFRow dataRow = sheet.createRow(i + 4);
|
int dataIndex = 0;
|
for (int k = 0; k < maxCellSize; k++) {
|
XSSFCell dataRowCell = dataRow.createCell(k);
|
dataRowCell.setCellStyle(cellStyle);
|
if (k == 0) {
|
dataRowCell.setCellValue(itemVO.getName());
|
} else {
|
dataRowCell.setCellValue(itemVO.getData().get(dataIndex).toString());
|
dataIndex++;
|
}
|
}
|
}
|
}
|
sheet.setColumnWidth(0, 6065);
|
return workbook;
|
}
|
|
|
/**
|
* 导出报表
|
*
|
* @param dto 1区域预警级别统计 2医院预警级别统计
|
* @param type 1:统计,2:报表
|
*/
|
public void exportCollectionWarningLevelReport(HttpServletResponse response, CollectionWarningLevelDTO dto,Integer type) throws IOException {
|
|
String fileName = "";
|
ExcelWriter writer = null;
|
if(type == 1 ){
|
switch (dto.getStyleTpl()) {
|
case 1:
|
fileName = "区域预警级别统计";
|
if(dto.getWarningStatisticalType()!=null && dto.getWarningStatisticalType() == 2){
|
fileName = "区域预警类型统计";
|
}
|
writer = new ExcelWriter(exportCollectionWarningLevelReport(dto, fileName,type), fileName);
|
break;
|
case 2:
|
fileName = "医院预警级别统计";
|
if(dto.getWarningStatisticalType()!=null && dto.getWarningStatisticalType() == 2){
|
fileName = "医院预警类型统计";
|
}
|
writer = new ExcelWriter(exportCollectionWarningLevelReport(dto, fileName,type), fileName);
|
break;
|
default:
|
throw new BusinessException(ErrorCode.ERR_500, "请选择报表类型");
|
}
|
}else {
|
fileName = "预警级别报表";
|
if(dto.getWarningStatisticalType()!=null && dto.getWarningStatisticalType() == 2){
|
fileName = "预警类型报表";
|
}
|
writer = new ExcelWriter(exportCollectionWarningLevelReport(dto, fileName,type), fileName);
|
}
|
|
if (writer != null) {
|
response.setContentType("application/octet-stream;charset=utf-8");
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
|
writer.flush(response.getOutputStream(), true);
|
writer.close();
|
}
|
}
|
|
private XSSFWorkbook exportCollectionWarningLevelReport(CollectionWarningLevelDTO dto, String sheetName,Integer type) {
|
|
CollectionWarningLevelReportVO vo = null;
|
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
String cellName = "", title = "";
|
if (dto.getStyleTpl() == 1) {
|
if(type==1){//统计
|
vo = getWarningRegionLevelReportList(dto);
|
cellName = "区域名称";
|
}else if(type==2){//报表
|
vo = getWarningRegionLevelStatementList(dto);
|
cellName = "时间";
|
}
|
|
|
} else if (dto.getStyleTpl() == 2) {
|
if(type==1){//统计
|
vo = getWarningHospitalLevelReportList(dto);
|
cellName = "医院名称";
|
}else if(type==2){//报表
|
vo = getWarningHospitalLevelStatementList(dto);
|
cellName = "时间";
|
}
|
|
|
}
|
if(type==1){
|
if(dto.getWarningStatisticalType()!=null && dto.getWarningStatisticalType()==2){
|
title = vo.getDepartmentName() + "预警类型统计";
|
}else{
|
title = vo.getDepartmentName() + "预警级别统计";
|
}
|
}else {
|
if(dto.getWarningStatisticalType()!=null && dto.getWarningStatisticalType()==2){
|
title = vo.getDepartmentName() + "预警类型报表";
|
}else{
|
title = vo.getDepartmentName() + "预警级别报表";
|
}
|
}
|
XSSFSheet sheet = workbook.createSheet(sheetName);
|
XSSFCellStyle cellStyle = createDefaultCellStyle(workbook);
|
XSSFCellStyle rightCellStyle = createDefaultRightCellStyle(workbook);
|
//
|
int maxCellSize = 21;
|
if(dto.getWarningStatisticalType()!=null && dto.getWarningStatisticalType()==2){
|
maxCellSize = 31;
|
}
|
XSSFRow titleRow = sheet.createRow(0);
|
XSSFRow dateRow = sheet.createRow(1);
|
XSSFRow firstRow = sheet.createRow(2);
|
XSSFRow secondRow = sheet.createRow(3);
|
for (int i = 0; i < maxCellSize; i++) {
|
XSSFCell titleRowCell = titleRow.createCell(i);
|
titleRowCell.setCellStyle(cellStyle);
|
XSSFCell firstRowCell = firstRow.createCell(i);
|
firstRowCell.setCellStyle(cellStyle);
|
XSSFCell secondRowCell = secondRow.createCell(i);
|
secondRowCell.setCellStyle(cellStyle);
|
XSSFCell dateRowCell = dateRow.createCell(i);
|
dateRowCell.setCellStyle(rightCellStyle);
|
if (i == 0) {
|
titleRowCell.setCellValue(title);
|
firstRowCell.setCellValue(cellName);
|
} else {
|
if(i==1){//
|
firstRowCell.setCellValue("一级预警");
|
if(dto.getWarningStatisticalType()!=null && dto.getWarningStatisticalType()==2){
|
firstRowCell.setCellValue("未出医废预警");
|
}
|
secondRowCell.setCellValue("预警数");
|
}
|
if(i==6){//
|
firstRowCell.setCellValue("二级预警");
|
if(dto.getWarningStatisticalType()!=null && dto.getWarningStatisticalType()==2){
|
firstRowCell.setCellValue("入库超时预警");
|
}
|
secondRowCell.setCellValue("预警数");
|
}
|
if(i==11){//
|
firstRowCell.setCellValue("三级预警");
|
if(dto.getWarningStatisticalType()!=null && dto.getWarningStatisticalType()==2){
|
firstRowCell.setCellValue("入库前疑似遗失预警");
|
}
|
secondRowCell.setCellValue("预警数");
|
}
|
if(dto.getWarningStatisticalType()!=null && dto.getWarningStatisticalType()==2){
|
if (i == 16) {//
|
firstRowCell.setCellValue("出库超时预警");
|
secondRowCell.setCellValue("预警数");
|
}
|
if (i == 21) {//
|
firstRowCell.setCellValue("入库后疑似遗失预警");
|
secondRowCell.setCellValue("预警数");
|
}
|
if (i == 26) {//
|
firstRowCell.setCellValue("小计");
|
secondRowCell.setCellValue("预警数");
|
}
|
}else {
|
if (i == 16) {//
|
firstRowCell.setCellValue("小计");
|
secondRowCell.setCellValue("预警数");
|
}
|
|
}
|
|
if(i==2 || i==7 || i==12 || i==17 || i==22 || i==27){
|
secondRowCell.setCellValue("反馈数");
|
}
|
if(i==3 || i==8 || i==13 || i==18 || i==23 || i==28){
|
secondRowCell.setCellValue("反馈率");
|
}
|
if(i==4 || i==9 || i==14 || i==19 || i==24 || i==29){
|
secondRowCell.setCellValue("解除数");
|
}
|
if(i==5 || i==10 || i==15 || i==20 || i==25 || i==30){
|
secondRowCell.setCellValue("解除率");
|
}
|
}
|
if (i == maxCellSize - 1) {
|
dto.setStatisticalWayType(dto.getStatisticalWayType()==null?1:dto.getStatisticalWayType());
|
if(dto.getStatisticalWayType() == 1 || dto.getStatisticalWayType() == 3){
|
dateRowCell.setCellValue("时间:" + DateUtil.format(dto.getStartTime(), "yyyy年MM月dd日") + "至" + DateUtil.format(dto.getEndTime(), "yyyy年MM月dd日"));
|
}else if(dto.getStatisticalWayType() == 2){
|
dateRowCell.setCellValue("时间:" + DateUtil.format(dto.getStartTime(), "yyyy年MM月") + "至" + DateUtil.format(dto.getEndTime(), "yyyy年MM月"));
|
}else if(dto.getStatisticalWayType() == 4){
|
dateRowCell.setCellValue("时间:" + DateUtil.format(dto.getStartTime(), "yyyy年") + "至" + DateUtil.format(dto.getEndTime(), "yyyy年"));
|
}
|
|
}
|
}
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, maxCellSize - 1));
|
sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 0));
|
sheet.addMergedRegion(new CellRangeAddress(2, 2, 1, 5));
|
sheet.addMergedRegion(new CellRangeAddress(2, 2, 6, 10));
|
sheet.addMergedRegion(new CellRangeAddress(2, 2, 11, 15));
|
sheet.addMergedRegion(new CellRangeAddress(2, 2, 16, 20));
|
if(dto.getWarningStatisticalType()!=null && dto.getWarningStatisticalType()==2){
|
sheet.addMergedRegion(new CellRangeAddress(2, 2, 21, 25));
|
sheet.addMergedRegion(new CellRangeAddress(2, 2, 26, 30));
|
}
|
|
//
|
if (CollectionUtils.isNotEmpty(vo.getList())) {
|
for (int i = 0; i < vo.getList().size(); i++) {
|
CollectionWarningLevelItemVO itemVO = vo.getList().get(i);
|
XSSFRow dataRow = sheet.createRow(i + 4);
|
int dataIndex = 0;
|
for (int k = 0; k < maxCellSize; k++) {
|
XSSFCell dataRowCell = dataRow.createCell(k);
|
dataRowCell.setCellStyle(cellStyle);
|
if (k == 0) {
|
dataRowCell.setCellValue(itemVO.getName());
|
} else {
|
dataRowCell.setCellValue(itemVO.getData().get(dataIndex).toString());
|
if(k ==3 || k ==5 || k ==8 || k ==10 || k ==13 || k ==15 || k==18
|
|| k==20 || k==23 || k==25 || k==28 || k==30){
|
dataRowCell.setCellValue(itemVO.getData().get(dataIndex).toString()+"%");
|
}
|
dataIndex++;
|
}
|
}
|
}
|
}
|
sheet.setColumnWidth(0, 6065);
|
return workbook;
|
}
|
|
private XSSFWorkbook exportHospitalReport(MedicalReportDTO dto, String sheetName) {
|
|
MedicalReportVO vo = getMedicalReportList(dto);
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFSheet sheet = workbook.createSheet(sheetName);
|
XSSFCellStyle cellStyle = createDefaultCellStyle(workbook);
|
XSSFCellStyle rightCellStyle = createDefaultRightCellStyle(workbook);
|
int maxCellSize = 6 + vo.getLegend().size() ;
|
XSSFRow titleRow = sheet.createRow(0);
|
XSSFRow firstRow = sheet.createRow(1);
|
XSSFRow secondRow = sheet.createRow(2);
|
int legendIndex = 0;
|
int titleIndex = 0;
|
for (int i = 0; i < maxCellSize; i++) {
|
XSSFCell titleRowCell = titleRow.createCell(i);
|
titleRowCell.setCellStyle(cellStyle);
|
XSSFCell firstRowCell = firstRow.createCell(i);
|
firstRowCell.setCellStyle(cellStyle);
|
XSSFCell secondRowCell = secondRow.createCell(i);
|
secondRowCell.setCellStyle(cellStyle);
|
if (i == 0) {
|
titleRowCell.setCellValue("医疗机构统计");
|
firstRowCell.setCellValue("机构名称");
|
} else {
|
String[] titleStr = new String[]{"机构级别","机构类型","机构性质","分院"};
|
if(i<5) {
|
firstRowCell.setCellValue(titleStr[titleIndex]);
|
titleIndex++;
|
}
|
if(i>=5 && i<= maxCellSize - 2){
|
firstRowCell.setCellValue("科室总数");
|
}
|
if (i>= 5 && i<=maxCellSize - 2) {
|
secondRowCell.setCellValue(vo.getLegend().stream().toArray()[legendIndex].toString());
|
legendIndex++;
|
}
|
if (i == maxCellSize - 1) {
|
firstRowCell.setCellValue("创建时间");
|
}
|
}
|
}
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, maxCellSize - 1));
|
sheet.addMergedRegion(new CellRangeAddress(1, 2, 0, 0));
|
sheet.addMergedRegion(new CellRangeAddress(1, 2, 1, 1));
|
sheet.addMergedRegion(new CellRangeAddress(1, 2, 2, 2));
|
sheet.addMergedRegion(new CellRangeAddress(1, 2, 3, 3));
|
sheet.addMergedRegion(new CellRangeAddress(1, 2, 4, 4));
|
sheet.addMergedRegion(new CellRangeAddress(1, 1, 5, maxCellSize - 2));
|
sheet.addMergedRegion(new CellRangeAddress(1, 2, maxCellSize - 1, maxCellSize - 1));
|
//
|
if (CollectionUtils.isNotEmpty(vo.getList())) {
|
for (int i = 0; i < vo.getList().size(); i++) {
|
SysDepartmentInformationReportVO itemVO = vo.getList().get(i);
|
XSSFRow dataRow = sheet.createRow(i + 3);
|
int dataIndex = 0;
|
for (int k = 0; k < maxCellSize; k++) {
|
XSSFCell dataRowCell = dataRow.createCell(k);
|
dataRowCell.setCellStyle(cellStyle);
|
if (k == 0) {
|
dataRowCell.setCellValue(itemVO.getDepartmentName());
|
}else if (k == 1) {
|
dataRowCell.setCellValue(itemVO.getDepartmentLevel());
|
}else if (k == 2) {
|
dataRowCell.setCellValue(itemVO.getDepartmentType());
|
}else if (k == 3) {
|
dataRowCell.setCellValue(itemVO.getDepartmentProperty());
|
}else if (k == 4) {
|
if(itemVO.getIsCourts()!=null){
|
if(itemVO.getIsCourts()==0){
|
dataRowCell.setCellValue("否");
|
}else {
|
dataRowCell.setCellValue("是");
|
}
|
}
|
} else if(k == maxCellSize - 1){
|
dataRowCell.setCellValue(DateUtil.format(itemVO.getCreateTime(),"yyyy-MM-dd"));
|
}else {
|
dataRowCell.setCellValue(itemVO.getData()[dataIndex]);
|
dataIndex++;
|
}
|
}
|
}
|
}
|
sheet.setColumnWidth(0, 6065);
|
|
|
return workbook;
|
}
|
|
private XSSFWorkbook exportCollectionAmendant(ReportCollectionAmendantDTO dto, String sheetName) {
|
|
DepartmentCollectionAmendantReportVO vo = getCollectionAmendantRecordReportList(dto);
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFSheet sheet = workbook.createSheet(sheetName);
|
XSSFCellStyle cellStyle = createDefaultCellStyle(workbook);
|
XSSFCellStyle leftCellStyle = createDefaultLeftCellStyle(workbook);
|
XSSFCellStyle rightCellStyle = createDefaultRightCellStyle(workbook);
|
//
|
int maxCellSize = 12;
|
XSSFRow titleRow = sheet.createRow(0);
|
XSSFRow headFirstRow = sheet.createRow(1);
|
XSSFRow headSecondRow = sheet.createRow(2);
|
int legendIndex = 0;
|
for (int i = 0; i < maxCellSize; i++) {
|
XSSFCell titleRowCell = titleRow.createCell(i);
|
titleRowCell.setCellStyle(cellStyle);
|
XSSFCell headFirstRowwCell = headFirstRow.createCell(i);
|
headFirstRowwCell.setCellStyle(cellStyle);
|
XSSFCell headSecondRowCell = headSecondRow.createCell(i);
|
headSecondRowCell.setCellStyle(cellStyle);
|
if (i == 0) {
|
titleRowCell.setCellValue("数据修改统计");
|
headFirstRowwCell.setCellValue("机构名称");
|
} else if (i == 1) {
|
headFirstRowwCell.setCellValue("医废总数");
|
} else if (i == 2) {
|
headFirstRowwCell.setCellValue("医废补录");
|
headSecondRowCell.setCellValue("数量");
|
} else if (i == 3) {
|
headSecondRowCell.setCellValue("补录率");
|
}else if (i == 4) {
|
headFirstRowwCell.setCellValue("修改医废类别");
|
headSecondRowCell.setCellValue("数量");
|
} else if (i == 5) {
|
headSecondRowCell.setCellValue("修改率");
|
}else if (i == 6) {
|
headFirstRowwCell.setCellValue("修改重量");
|
headSecondRowCell.setCellValue("数量");
|
} else if (i == 7) {
|
headSecondRowCell.setCellValue("修改率");
|
}else if (i == 8) {
|
headFirstRowwCell.setCellValue("删除");
|
headSecondRowCell.setCellValue("数量");
|
} else if (i == 9) {
|
headSecondRowCell.setCellValue("删除率");
|
}else if (i == 10) {
|
headFirstRowwCell.setCellValue("小计");
|
headSecondRowCell.setCellValue("数量");
|
} else if (i == 11) {
|
headSecondRowCell.setCellValue("修改率");
|
}
|
}
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, maxCellSize - 1));
|
//
|
sheet.addMergedRegion(new CellRangeAddress(1, 2, 0, 0));
|
sheet.addMergedRegion(new CellRangeAddress(1, 2, 1, 1));
|
sheet.addMergedRegion(new CellRangeAddress(1, 1, 2, 3));
|
sheet.addMergedRegion(new CellRangeAddress(1, 1, 4, 5));
|
sheet.addMergedRegion(new CellRangeAddress(1, 1, 6, 7));
|
sheet.addMergedRegion(new CellRangeAddress(1, 1, 8, 9));
|
sheet.addMergedRegion(new CellRangeAddress(1, 1, 10, 11));
|
//
|
if (CollectionUtils.isNotEmpty(vo.getList())) {
|
for (int i = 0; i < vo.getList().size(); i++) {
|
DepartmentReportItemVO itemVO = vo.getList().get(i);
|
XSSFRow dataRow = sheet.createRow(i + 3);
|
int dataIndex = 0;
|
for (int k = 0; k < maxCellSize; k++) {
|
XSSFCell dataRowCell = dataRow.createCell(k);
|
dataRowCell.setCellStyle(cellStyle);
|
if (k == 0) {
|
dataRowCell.setCellValue(itemVO.getName());
|
} else {
|
dataRowCell.setCellValue(itemVO.getData().get(dataIndex).toString());
|
if(k==3 || k==5 || k==7 || k==9 || k==11){
|
dataRowCell.setCellValue(itemVO.getData().get(dataIndex).toString()+"%");
|
}
|
dataIndex++;
|
}
|
}
|
}
|
}
|
sheet.setColumnWidth(0, 6065);
|
return workbook;
|
}
|
|
private XSSFCellStyle createDefaultCellStyle(XSSFWorkbook workbook) {
|
|
XSSFCellStyle cellStyle = workbook.createCellStyle();
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
XSSFFont font = workbook.createFont();
|
font.setFontName("宋体");
|
font.setFontHeightInPoints((short) 12);
|
cellStyle.setFont(font);
|
return cellStyle;
|
}
|
|
private XSSFCellStyle createDefaultLeftCellStyle(XSSFWorkbook workbook) {
|
|
XSSFCellStyle cellStyle = workbook.createCellStyle();
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
cellStyle.setAlignment(HorizontalAlignment.LEFT);
|
XSSFFont font = workbook.createFont();
|
font.setFontName("宋体");
|
font.setFontHeightInPoints((short) 12);
|
cellStyle.setFont(font);
|
return cellStyle;
|
}
|
|
private XSSFCellStyle createDefaultRightCellStyle(XSSFWorkbook workbook) {
|
|
XSSFCellStyle cellStyle = workbook.createCellStyle();
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
cellStyle.setAlignment(HorizontalAlignment.RIGHT);
|
XSSFFont font = workbook.createFont();
|
font.setFontName("宋体");
|
font.setFontHeightInPoints((short) 12);
|
cellStyle.setFont(font);
|
return cellStyle;
|
}
|
}
|