From 011cd5f978b63bb5ce9e485685f69157b7b6b28b Mon Sep 17 00:00:00 2001 From: zhangheng <3226558941@qq.com> Date: Tue, 23 Jun 2026 17:43:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A6=E5=8D=95=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xinelu/common/constant/Constants.java | 5 ++ .../PhoneDialRecordMapper.java | 19 +++- .../ShortMessageSendRecordMapper.java | 12 ++- .../ShortMessageSendRecordVo.java | 2 +- .../phonedialrecord/PhoneDialRecordMapper.xml | 13 +++ .../ShortMessageSendRecordMapper.xml | 13 +++ .../java/com/xinelu/quartz/task/BillTask.java | 90 +++++++++++++++++++ 7 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 postdischarge-quartz/src/main/java/com/xinelu/quartz/task/BillTask.java diff --git a/postdischarge-common/src/main/java/com/xinelu/common/constant/Constants.java b/postdischarge-common/src/main/java/com/xinelu/common/constant/Constants.java index d05d2874..74823b1f 100644 --- a/postdischarge-common/src/main/java/com/xinelu/common/constant/Constants.java +++ b/postdischarge-common/src/main/java/com/xinelu/common/constant/Constants.java @@ -404,4 +404,9 @@ public class Constants { * 医院时间配置 */ public static final String DIAL_TIME ="dial_time"; + + /** + * 账单代码编码 + */ + public static final String BILL_CODE = "AYC"; } diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/phonedialrecord/PhoneDialRecordMapper.java b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/phonedialrecord/PhoneDialRecordMapper.java index 1f58c1b8..19499942 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/phonedialrecord/PhoneDialRecordMapper.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/phonedialrecord/PhoneDialRecordMapper.java @@ -7,7 +7,9 @@ import com.xinelu.manage.dto.statistics.FollowUpRateDto; import com.xinelu.manage.vo.phonedialrecord.BillPhoneDialVo; import com.xinelu.manage.vo.phonedialrecord.PhoneDialRecordVo; import com.xinelu.manage.vo.statistics.PushCount; +import org.apache.ibatis.annotations.Param; +import java.time.LocalDateTime; import java.util.List; /** @@ -107,8 +109,17 @@ public interface PhoneDialRecordMapper { */ List selectPhoneDialStatisticByBillId(Long billId); - /** - * 电话推送统计 - */ - PushCount phoneCount(); + /** + * 电话推送统计 + */ + PushCount phoneCount(); + + /** + * 根据时间查询拨打成功的账单 + * + * @param startMonth 开始时间 + * @param endMonth 结束时间 + * @return PhoneDialRecord + */ + List selectPhoneDialBySendTime(@Param("startMonth") LocalDateTime startMonth, @Param("endMonth") LocalDateTime endMonth); } diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/shortmessagesendrecord/ShortMessageSendRecordMapper.java b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/shortmessagesendrecord/ShortMessageSendRecordMapper.java index 43a5185a..56abdd7c 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/shortmessagesendrecord/ShortMessageSendRecordMapper.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/shortmessagesendrecord/ShortMessageSendRecordMapper.java @@ -9,6 +9,7 @@ import com.xinelu.manage.vo.statistics.PushCount; import com.xinelu.manage.vo.subscribemessagesendrecord.RecordNum; import org.apache.ibatis.annotations.Param; +import java.time.LocalDateTime; import java.util.List; /** @@ -104,4 +105,13 @@ public interface ShortMessageSendRecordMapper { * 短信推送统计 */ PushCount messageCount(); -} + + /** + * 根据时间查询发送成功的账单 + * + * @param startMonth 开始时间 + * @param endMonth 结束时间 + * @return PhoneDialRecord + */ + List selectRecordBySendTime(@Param("startMonth") LocalDateTime startMonth, @Param("endMonth") LocalDateTime endMonth); +} \ No newline at end of file diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/vo/shortmessagesendrecord/ShortMessageSendRecordVo.java b/postdischarge-manage/src/main/java/com/xinelu/manage/vo/shortmessagesendrecord/ShortMessageSendRecordVo.java index 8c5b2f8b..ab946396 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/vo/shortmessagesendrecord/ShortMessageSendRecordVo.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/vo/shortmessagesendrecord/ShortMessageSendRecordVo.java @@ -110,5 +110,5 @@ public class ShortMessageSendRecordVo { * 关联账单名称 */ @ApiModelProperty(value = "关联账单名称") - private Long billName; + private String billName; } diff --git a/postdischarge-manage/src/main/resources/mapper/manage/phonedialrecord/PhoneDialRecordMapper.xml b/postdischarge-manage/src/main/resources/mapper/manage/phonedialrecord/PhoneDialRecordMapper.xml index 861f0464..cd77c7d9 100644 --- a/postdischarge-manage/src/main/resources/mapper/manage/phonedialrecord/PhoneDialRecordMapper.xml +++ b/postdischarge-manage/src/main/resources/mapper/manage/phonedialrecord/PhoneDialRecordMapper.xml @@ -385,4 +385,17 @@ from phone_dial_record record where phone_dial_method = 'AI' + + \ No newline at end of file diff --git a/postdischarge-manage/src/main/resources/mapper/manage/shortmessagesendrecord/ShortMessageSendRecordMapper.xml b/postdischarge-manage/src/main/resources/mapper/manage/shortmessagesendrecord/ShortMessageSendRecordMapper.xml index e2d09250..8b370b6a 100644 --- a/postdischarge-manage/src/main/resources/mapper/manage/shortmessagesendrecord/ShortMessageSendRecordMapper.xml +++ b/postdischarge-manage/src/main/resources/mapper/manage/shortmessagesendrecord/ShortMessageSendRecordMapper.xml @@ -408,4 +408,17 @@ (select count(1) from short_message_send_record where error_code = 1) as failure from short_message_send_record + + \ No newline at end of file diff --git a/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/BillTask.java b/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/BillTask.java new file mode 100644 index 00000000..5355a3c3 --- /dev/null +++ b/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/BillTask.java @@ -0,0 +1,90 @@ +package com.xinelu.quartz.task; + +import com.xinelu.common.constant.Constants; +import com.xinelu.common.constant.PaymentStatusConstants; +import com.xinelu.common.enums.BillSourceEnum; +import com.xinelu.common.utils.codes.GenerateSystemCodeUtil; +import com.xinelu.manage.domain.billinfo.BillInfo; +import com.xinelu.manage.domain.phonedialrecord.PhoneDialRecord; +import com.xinelu.manage.domain.shortmessagesendrecord.ShortMessageSendRecord; +import com.xinelu.manage.mapper.billinfo.BillInfoMapper; +import com.xinelu.manage.mapper.phonedialrecord.PhoneDialRecordMapper; +import com.xinelu.manage.mapper.shortmessagesendrecord.ShortMessageSendRecordMapper; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.YearMonth; +import java.util.List; +import java.util.Objects; + +/** + * @description: 月初生成上月的的账单任务 + * @author: zh + * @create: 2026-06-23 + **/ +@Slf4j +@Component("BillTask") +public class BillTask { + + @Resource + private ShortMessageSendRecordMapper shortMessageSendRecordMapper; + @Resource + private PhoneDialRecordMapper phoneDialRecordMapper; + @Resource + private GenerateSystemCodeUtil generateSystemCodeUtil; + @Resource + private BillInfoMapper billInfoMapper; + + public void generateBillTask() { + // 1.1 获取上个月的 YearMonth 对象 + YearMonth lastMonth = YearMonth.now().minusMonths(1); + // 1.2 获取上个月第一天 00:00:00(开始) + LocalDateTime startOfLastMonth = lastMonth.atDay(1).atStartOfDay(); + // 1.3 获取上个月最后一天 23:59:59(结束) + LocalDateTime endOfLastMonth = lastMonth.atEndOfMonth().atTime(23, 59, 59); + //2.查询上月短信推送记录 + BillInfo shortBillInfo = new BillInfo(); + shortBillInfo.setBillCode(Constants.BILL_CODE + generateSystemCodeUtil.generateSystemCode(Constants.AGENCY_CODE)); + shortBillInfo.setBillName(lastMonth.getMonth().toString() + "月份短信账单"); + shortBillInfo.setBillMonth(lastMonth.getMonth().toString()); + shortBillInfo.setPaymentStatus(PaymentStatusConstants.UNPAID_FEES); + shortBillInfo.setBillSource(BillSourceEnum.MESSAGE.getInfo()); + List shortMessageSendRecords = shortMessageSendRecordMapper.selectRecordBySendTime(startOfLastMonth, endOfLastMonth); + if (CollectionUtils.isNotEmpty(shortMessageSendRecords)) { + long sum = shortMessageSendRecords.stream().filter(Objects::nonNull) + .mapToLong(ShortMessageSendRecord::getMessageQuantity) + .sum(); + shortBillInfo.setPushLength(new BigDecimal(sum)); + + BigDecimal totalAmount = shortMessageSendRecords.stream().filter(Objects::nonNull) + .map(ShortMessageSendRecord::getMessageExpense) + .reduce(BigDecimal.ZERO, BigDecimal::add); + shortBillInfo.setBillExpense(totalAmount); + billInfoMapper.insertBillInfo(shortBillInfo); + } + //2.查询上月电话推送记录 + BillInfo phoneBillInfo = new BillInfo(); + phoneBillInfo.setBillCode(Constants.BILL_CODE + generateSystemCodeUtil.generateSystemCode(Constants.AGENCY_CODE)); + phoneBillInfo.setBillName(lastMonth.getMonth().toString() + "月份电话账单"); + phoneBillInfo.setBillMonth(lastMonth.getMonth().toString()); + phoneBillInfo.setPaymentStatus(PaymentStatusConstants.UNPAID_FEES); + phoneBillInfo.setBillSource(BillSourceEnum.TELEPHONE.getInfo()); + List phoneDialRecords = phoneDialRecordMapper.selectPhoneDialBySendTime(startOfLastMonth, endOfLastMonth); + if (CollectionUtils.isNotEmpty(phoneDialRecords)) { + BigDecimal sum = phoneDialRecords.stream().filter(Objects::nonNull) + .map(PhoneDialRecord::getPhoneDuration) + .reduce(BigDecimal.ZERO, BigDecimal::add); + shortBillInfo.setPushLength(sum); + + BigDecimal totalAmount = phoneDialRecords.stream().filter(Objects::nonNull) + .map(PhoneDialRecord::getPhoneExpense) + .reduce(BigDecimal.ZERO, BigDecimal::add); + shortBillInfo.setBillExpense(totalAmount); + billInfoMapper.insertBillInfo(phoneBillInfo); + } + } +} \ No newline at end of file