账单生成

This commit is contained in:
zhangheng 2026-06-23 17:43:17 +08:00
parent 4ec5725128
commit 011cd5f978
7 changed files with 148 additions and 6 deletions

View File

@ -404,4 +404,9 @@ public class Constants {
* 医院时间配置
*/
public static final String DIAL_TIME ="dial_time";
/**
* 账单代码编码
*/
public static final String BILL_CODE = "AYC";
}

View File

@ -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<BillInfoDto> selectPhoneDialStatisticByBillId(Long billId);
/**
* 电话推送统计
*/
PushCount phoneCount();
/**
* 电话推送统计
*/
PushCount phoneCount();
/**
* 根据时间查询拨打成功的账单
*
* @param startMonth 开始时间
* @param endMonth 结束时间
* @return PhoneDialRecord
*/
List<PhoneDialRecord> selectPhoneDialBySendTime(@Param("startMonth") LocalDateTime startMonth, @Param("endMonth") LocalDateTime endMonth);
}

View File

@ -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<ShortMessageSendRecord> selectRecordBySendTime(@Param("startMonth") LocalDateTime startMonth, @Param("endMonth") LocalDateTime endMonth);
}

View File

@ -110,5 +110,5 @@ public class ShortMessageSendRecordVo {
* 关联账单名称
*/
@ApiModelProperty(value = "关联账单名称")
private Long billName;
private String billName;
}

View File

@ -385,4 +385,17 @@
from phone_dial_record record
where phone_dial_method = 'AI'
</select>
<select id="selectPhoneDialBySendTime"
resultType="com.xinelu.manage.domain.phonedialrecord.PhoneDialRecord">
<include refid="selectPhoneDialRecordVo"/>
where error_code = 0
and bill_id is null
<if test="startMonth != null">
and dial_time &gt;= #{startMonth}
</if>
<if test="endMonth != null">
and dial_time &lt;= #{endMonth}
</if>
</select>
</mapper>

View File

@ -408,4 +408,17 @@
(select count(1) from short_message_send_record where error_code = 1) as failure
from short_message_send_record
</select>
<select id="selectRecordBySendTime"
resultType="com.xinelu.manage.domain.shortmessagesendrecord.ShortMessageSendRecord">
<include refid="selectShortMessageSendRecordVo"/>
where error_code = 0
and bill_id is null
<if test="startMonth != null">
and send_time &gt;= #{startMonth}
</if>
<if test="endMonth != null">
and send_time &lt;= #{endMonth}
</if>
</select>
</mapper>

View File

@ -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<ShortMessageSendRecord> 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<PhoneDialRecord> 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);
}
}
}