Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
wangjian963
2026-06-02 16:03:09 +08:00
7 changed files with 797 additions and 560 deletions

View File

@@ -39,6 +39,16 @@ public class HomeStatisticsDto {
* 相对前日变化百分比
*/
private Double revenueTrend;
/**
* 今日收入金额(数值,单位:元)
*/
private java.math.BigDecimal todayRevenueAmount;
/**
* 昨日收入金额(数值,单位:元)
*/
private java.math.BigDecimal yesterdayRevenueAmount;
/**
* 今日预约数量
@@ -69,4 +79,19 @@ public class HomeStatisticsDto {
* 待写病历数量
*/
private Integer pendingEmr;
}
/**
* 今日处方数量
*/
private Integer todayPrescriptions;
/**
* 昨日处方数量
*/
private Integer yesterdayPrescriptions;
/**
* 处方相对前日变化百分比
*/
private Double prescriptionTrend;
}

View File

@@ -13,7 +13,16 @@ import com.openhis.administration.service.IPatientService;
import com.openhis.administration.service.IPractitionerService;
import com.openhis.common.enums.ParticipantType;
import com.openhis.web.dto.HomeStatisticsDto;
import com.openhis.financial.domain.PaymentReconciliation;
import com.openhis.financial.service.IPaymentReconciliationService;
import com.openhis.medication.domain.MedicationRequest;
import com.openhis.medication.service.IMedicationRequestService;
import com.openhis.common.enums.PaymentStatus;
import com.openhis.web.service.IHomeStatisticsService;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import com.openhis.web.patientmanage.mapper.PatientManageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -46,6 +55,12 @@ public class HomeStatisticsServiceImpl implements IHomeStatisticsService {
@Autowired
private IPatientService patientService;
@Autowired
private IPaymentReconciliationService paymentReconciliationService;
@Autowired
private IMedicationRequestService medicationRequestService;
/**
* 获取首页统计数据
*
@@ -105,18 +120,108 @@ public class HomeStatisticsServiceImpl implements IHomeStatisticsService {
double patientTrend = calculateTrend(totalPatients, yesterdayPatients);
statistics.setPatientTrend(patientTrend);
// 今日收入和预约等其他统计暂时设为0后续从相应表查询
statistics.setTodayRevenue("¥ 0");
statistics.setYesterdayRevenue("¥ 0");
statistics.setRevenueTrend(0.0);
// 查询今日收入
BigDecimal todayRevenue = queryRevenueByDate(new Date());
BigDecimal yesterdayRevenue = queryRevenueByDate(getYesterday());
java.text.DecimalFormat df = new java.text.DecimalFormat("#,##0.00");
statistics.setTodayRevenue("¥ " + df.format(todayRevenue));
statistics.setYesterdayRevenue("¥ " + df.format(yesterdayRevenue));
statistics.setTodayRevenueAmount(todayRevenue);
statistics.setYesterdayRevenueAmount(yesterdayRevenue);
statistics.setRevenueTrend(calculateTrend(todayRevenue.doubleValue(), yesterdayRevenue.doubleValue()));
// 今日预约和待审核暂时设为0后续实现
statistics.setTodayAppointments(0);
statistics.setYesterdayAppointments(0);
statistics.setAppointmentTrend(0.0);
statistics.setPendingApprovals(0);
// 查询今日处方数量
int todayPrescriptions = queryPrescriptionCountByDate(new Date(), practitioner);
int yesterdayPrescriptions = queryPrescriptionCountByDate(getYesterday(), practitioner);
statistics.setTodayPrescriptions(todayPrescriptions);
statistics.setYesterdayPrescriptions(yesterdayPrescriptions);
statistics.setPrescriptionTrend(calculateTrend(todayPrescriptions, yesterdayPrescriptions));
return statistics;
}
/**
* 查询指定日期的处方数量
*
* @param date 日期
* @param practitioner 当前医生null 则查全部)
* @return 处方数量
*/
private int queryPrescriptionCountByDate(Date date, Practitioner practitioner) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date dayStart = cal.getTime();
cal.add(Calendar.DAY_OF_MONTH, 1);
Date dayEnd = cal.getTime();
LambdaQueryWrapper<MedicationRequest> query = new LambdaQueryWrapper<>();
query.ge(MedicationRequest::getCreateTime, dayStart)
.lt(MedicationRequest::getCreateTime, dayEnd)
.eq(MedicationRequest::getDeleteFlag, "0");
// 如果是医生角色,只统计自己开的处方
if (practitioner != null) {
query.eq(MedicationRequest::getPractitionerId, practitioner.getId());
}
return (int) medicationRequestService.count(query);
}
/**
* 查询指定日期的收款总额(状态为支付成功且未全部退款)
*
* @param date 日期
* @return 收款总额
*/
private BigDecimal queryRevenueByDate(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date dayStart = cal.getTime();
cal.add(Calendar.DAY_OF_MONTH, 1);
Date dayEnd = cal.getTime();
LambdaQueryWrapper<PaymentReconciliation> query = new LambdaQueryWrapper<>();
query.ge(PaymentReconciliation::getBillDate, dayStart)
.lt(PaymentReconciliation::getBillDate, dayEnd)
.eq(PaymentReconciliation::getStatusEnum, PaymentStatus.SUCCESS.getValue())
.eq(PaymentReconciliation::getDeleteFlag, "0")
.select(PaymentReconciliation::getDisplayAmount);
java.util.List<PaymentReconciliation> list = paymentReconciliationService.list(query);
if (list == null || list.isEmpty()) {
return BigDecimal.ZERO;
}
return list.stream()
.map(p -> p.getDisplayAmount() != null ? p.getDisplayAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
/**
* 获取昨天的日期
*/
private Date getYesterday() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, -1);
return cal.getTime();
}
/**
* 计算相对前日的百分比变化
*