demand: TMS系统 - 客户账单管理 - 收款明细查询 - 优化查询性能,通过多线程处理将复杂字段的关联查询性能从5s优化到1s
committer: heyu
This commit is contained in:
parent
cc3e27371d
commit
e23709bc86
@ -41,8 +41,7 @@ public interface EmisSettlePayRecordMapper extends BaseMapper<EmisSettlePayRecor
|
|||||||
*/
|
*/
|
||||||
public List<EmisSettlePayRecord> selectEmisSettlePayRecordList(EmisSettlePayRecord emisSettlePayRecord);
|
public List<EmisSettlePayRecord> selectEmisSettlePayRecordList(EmisSettlePayRecord emisSettlePayRecord);
|
||||||
|
|
||||||
public Map getSettlePayStatInfoMap(EmisSettlePayRecord emisSettlePayRecord);
|
public Map<String, Object> getSettlePayStatInfoMap(EmisSettlePayRecord emisSettlePayRecord);
|
||||||
|
|
||||||
|
|
||||||
public List<EmisSettlePayRecord> selectSettlePayRecordListBySettleBillNo(String settleBillNo);
|
public List<EmisSettlePayRecord> selectSettlePayRecordListBySettleBillNo(String settleBillNo);
|
||||||
|
|
||||||
@ -98,5 +97,46 @@ public interface EmisSettlePayRecordMapper extends BaseMapper<EmisSettlePayRecor
|
|||||||
* @param endTime 结束时间
|
* @param endTime 结束时间
|
||||||
* @return 每天的已收款金额统计
|
* @return 每天的已收款金额统计
|
||||||
*/
|
*/
|
||||||
List<Map<String, Object>> calculateRecedMoney(@Param("beginTime") String beginTime, @Param("endTime") String endTime);
|
List<Map<String, Object>> calculateRecedMoney(@Param("beginTime") String beginTime,
|
||||||
|
@Param("endTime") String endTime);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据支付ID列表获取运单号
|
||||||
|
*
|
||||||
|
* @param payIds 支付ID列表
|
||||||
|
* @return 运单号映射
|
||||||
|
*/
|
||||||
|
List<Map<String, Object>> getWaybillCodesByPayIds(@Param("list") List<String> payIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据支付ID列表获取账单金额
|
||||||
|
*
|
||||||
|
* @param payIds 支付ID列表
|
||||||
|
* @return 账单金额映射
|
||||||
|
*/
|
||||||
|
List<Map<String, Object>> getBillAmountsByPayIds(@Param("list") List<String> payIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据支付ID列表获取开票金额
|
||||||
|
*
|
||||||
|
* @param payIds 支付ID列表
|
||||||
|
* @return 开票金额映射
|
||||||
|
*/
|
||||||
|
List<Map<String, Object>> getInvoiceAmountsByPayIds(@Param("list") List<String> payIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据支付ID列表获取开票状态
|
||||||
|
*
|
||||||
|
* @param payIds 支付ID列表
|
||||||
|
* @return 开票状态映射
|
||||||
|
*/
|
||||||
|
List<Map<String, Object>> getInvoiceStatusByPayIds(@Param("list") List<String> payIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据支付ID列表获取发票申请备注
|
||||||
|
*
|
||||||
|
* @param payIds 支付ID列表
|
||||||
|
* @return 发票申请备注映射
|
||||||
|
*/
|
||||||
|
List<Map<String, Object>> getInvoiceRemarksByPayIds(@Param("list") List<String> payIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public interface IEmisSettlePayRecordService
|
|||||||
*/
|
*/
|
||||||
public List<EmisSettlePayRecord> selectEmisSettlePayRecordList(EmisSettlePayRecord emisSettlePayRecord);
|
public List<EmisSettlePayRecord> selectEmisSettlePayRecordList(EmisSettlePayRecord emisSettlePayRecord);
|
||||||
|
|
||||||
public Map getSettlePayStatInfoMap(EmisSettlePayRecord emisSettlePayRecord);
|
public Map<String, Object> getSettlePayStatInfoMap(EmisSettlePayRecord emisSettlePayRecord);
|
||||||
|
|
||||||
public List<PayBackRecordDtl> queryPayBackRecordList(EmisSettlePayRecord emisSettlePayRecord);
|
public List<PayBackRecordDtl> queryPayBackRecordList(EmisSettlePayRecord emisSettlePayRecord);
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,9 @@ import java.time.ZoneId;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import com.xdadan.erp.emis.domain.*;
|
import com.xdadan.erp.emis.domain.*;
|
||||||
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
|
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
|
||||||
@ -24,12 +27,10 @@ import com.xdadan.erp.emis.domain.stat.PayBackRecordDtl;
|
|||||||
import com.xdadan.erp.emis.mapper.*;
|
import com.xdadan.erp.emis.mapper.*;
|
||||||
import com.xdadan.erp.emis.service.EmisBaseService;
|
import com.xdadan.erp.emis.service.EmisBaseService;
|
||||||
import com.xdadan.erp.emis.service.IEmisSettleBillService;
|
import com.xdadan.erp.emis.service.IEmisSettleBillService;
|
||||||
import com.xdadan.erp.emis.service.IEmisSettleSubBillService;
|
|
||||||
import com.xdadan.erp.emis.utils.WaybillHelper;
|
import com.xdadan.erp.emis.utils.WaybillHelper;
|
||||||
import jodd.util.StringUtil;
|
import jodd.util.StringUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.MapUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -43,8 +44,11 @@ import com.xdadan.erp.emis.service.IEmisSettlePayRecordService;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements IEmisSettlePayRecordService
|
public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements IEmisSettlePayRecordService {
|
||||||
{
|
|
||||||
|
// 创建线程池用于并行查询
|
||||||
|
private final ExecutorService executorService = Executors.newFixedThreadPool(5);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EmisSettlePayRecordMapper emisSettlePayRecordMapper;
|
private EmisSettlePayRecordMapper emisSettlePayRecordMapper;
|
||||||
|
|
||||||
@ -57,20 +61,15 @@ public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements I
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EmisSettleBillMapper emisSettleBillMapper;
|
private EmisSettleBillMapper emisSettleBillMapper;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EmisSettleSubBillMapper emisSettleSubBillMapper;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IEmisSettleBillService emisSettleBillService;
|
private IEmisSettleBillService emisSettleBillService;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EmisSettleInvoiceRecordMapper emisSettleInvoiceRecordMapper;
|
private EmisSettleInvoiceRecordMapper emisSettleInvoiceRecordMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EmisSettlePayInvoiceRelMapper emisSettlePayInvoiceRelMapper;
|
private EmisSettlePayInvoiceRelMapper emisSettlePayInvoiceRelMapper;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询账单收退款记录
|
* 查询账单收退款记录
|
||||||
*
|
*
|
||||||
@ -83,22 +82,202 @@ public class EmisSettlePayRecordServiceImpl extends EmisBaseService implements I
|
|||||||
return emisSettlePayRecordMapper.selectEmisSettlePayRecordById(id);
|
return emisSettlePayRecordMapper.selectEmisSettlePayRecordById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询账单收退款记录列表
|
* 查询账单收退款记录列表(带扩展信息)
|
||||||
*
|
*
|
||||||
* @param emisSettlePayRecord 账单收退款记录
|
* @param emisSettlePayRecord 账单收退款记录
|
||||||
* @return 账单收退款记录
|
* @return 账单收退款记录
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<EmisSettlePayRecord> selectEmisSettlePayRecordList(EmisSettlePayRecord emisSettlePayRecord)
|
public List<EmisSettlePayRecord> selectEmisSettlePayRecordList(EmisSettlePayRecord emisSettlePayRecord) {
|
||||||
{
|
// 先查询基础数据
|
||||||
return emisSettlePayRecordMapper.selectEmisSettlePayRecordList(emisSettlePayRecord);
|
List<EmisSettlePayRecord> baseList = emisSettlePayRecordMapper
|
||||||
|
.selectEmisSettlePayRecordList(emisSettlePayRecord);
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(baseList)) {
|
||||||
|
return baseList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取支付ID列表
|
||||||
|
List<String> payIds = baseList.stream()
|
||||||
|
.map(EmisSettlePayRecord::getPayId)
|
||||||
|
.filter(StringUtils::isNotBlank)
|
||||||
|
.distinct()
|
||||||
|
.collect(java.util.stream.Collectors.toList());
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(payIds)) {
|
||||||
|
return baseList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 并行查询扩展信息
|
||||||
|
CompletableFuture<Map<String, Object>> waybillCodesFuture = CompletableFuture
|
||||||
|
.supplyAsync(() -> getWaybillCodesMap(payIds), executorService);
|
||||||
|
CompletableFuture<Map<String, Object>> billAmountsFuture = CompletableFuture
|
||||||
|
.supplyAsync(() -> getBillAmountsMap(payIds), executorService);
|
||||||
|
CompletableFuture<Map<String, Object>> invoiceAmountsFuture = CompletableFuture
|
||||||
|
.supplyAsync(() -> getInvoiceAmountsMap(payIds), executorService);
|
||||||
|
CompletableFuture<Map<String, Object>> invoiceStatusFuture = CompletableFuture
|
||||||
|
.supplyAsync(() -> getInvoiceStatusMap(payIds), executorService);
|
||||||
|
CompletableFuture<Map<String, Object>> invoiceRemarksFuture = CompletableFuture
|
||||||
|
.supplyAsync(() -> getInvoiceRemarksMap(payIds), executorService);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 等待所有查询完成并获取结果
|
||||||
|
Map<String, Object> waybillCodesMap = waybillCodesFuture.join();
|
||||||
|
Map<String, Object> billAmountsMap = billAmountsFuture.join();
|
||||||
|
Map<String, Object> invoiceAmountsMap = invoiceAmountsFuture.join();
|
||||||
|
Map<String, Object> invoiceStatusMap = invoiceStatusFuture.join();
|
||||||
|
Map<String, Object> invoiceRemarksMap = invoiceRemarksFuture.join();
|
||||||
|
|
||||||
|
// 组装数据
|
||||||
|
for (EmisSettlePayRecord record : baseList) {
|
||||||
|
String payId = record.getPayId();
|
||||||
|
|
||||||
|
// 设置运单号
|
||||||
|
if (waybillCodesMap.containsKey(payId)) {
|
||||||
|
record.setBillCodes((String) waybillCodesMap.get(payId));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置账单金额
|
||||||
|
if (billAmountsMap.containsKey(payId)) {
|
||||||
|
record.setBillAmount((BigDecimal) billAmountsMap.get(payId));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置开票金额
|
||||||
|
if (invoiceAmountsMap.containsKey(payId)) {
|
||||||
|
record.setInvoiceAmount((BigDecimal) invoiceAmountsMap.get(payId));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置开票状态
|
||||||
|
if (invoiceStatusMap.containsKey(payId)) {
|
||||||
|
record.setInvoiceStatus((String) invoiceStatusMap.get(payId));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置备注(发票申请备注)
|
||||||
|
if (invoiceRemarksMap.containsKey(payId)) {
|
||||||
|
record.setRemark((String) invoiceRemarksMap.get(payId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("并行查询扩展信息时发生异常", e);
|
||||||
|
// 如果并行查询失败,回退到串行查询
|
||||||
|
Map<String, Object> waybillCodesMap = getWaybillCodesMap(payIds);
|
||||||
|
Map<String, Object> billAmountsMap = getBillAmountsMap(payIds);
|
||||||
|
Map<String, Object> invoiceAmountsMap = getInvoiceAmountsMap(payIds);
|
||||||
|
Map<String, Object> invoiceStatusMap = getInvoiceStatusMap(payIds);
|
||||||
|
Map<String, Object> invoiceRemarksMap = getInvoiceRemarksMap(payIds);
|
||||||
|
|
||||||
|
// 组装数据
|
||||||
|
for (EmisSettlePayRecord record : baseList) {
|
||||||
|
String payId = record.getPayId();
|
||||||
|
|
||||||
|
// 设置运单号
|
||||||
|
if (waybillCodesMap.containsKey(payId)) {
|
||||||
|
record.setBillCodes((String) waybillCodesMap.get(payId));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置账单金额
|
||||||
|
if (billAmountsMap.containsKey(payId)) {
|
||||||
|
record.setBillAmount((BigDecimal) billAmountsMap.get(payId));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置开票金额
|
||||||
|
if (invoiceAmountsMap.containsKey(payId)) {
|
||||||
|
record.setInvoiceAmount((BigDecimal) invoiceAmountsMap.get(payId));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置开票状态
|
||||||
|
if (invoiceStatusMap.containsKey(payId)) {
|
||||||
|
record.setInvoiceStatus((String) invoiceStatusMap.get(payId));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置备注(发票申请备注)
|
||||||
|
if (invoiceRemarksMap.containsKey(payId)) {
|
||||||
|
record.setRemark((String) invoiceRemarksMap.get(payId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return baseList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取运单号映射
|
||||||
|
*/
|
||||||
|
private Map<String, Object> getWaybillCodesMap(List<String> payIds) {
|
||||||
|
List<Map<String, Object>> waybillCodesList = emisSettlePayRecordMapper.getWaybillCodesByPayIds(payIds);
|
||||||
|
Map<String, Object> result = new java.util.HashMap<>();
|
||||||
|
for (Map<String, Object> map : waybillCodesList) {
|
||||||
|
String payId = (String) map.get("pay_id");
|
||||||
|
if (payId != null) {
|
||||||
|
result.put(payId, map.get("bill_codes"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取账单金额映射
|
||||||
|
*/
|
||||||
|
private Map<String, Object> getBillAmountsMap(List<String> payIds) {
|
||||||
|
List<Map<String, Object>> billAmountsList = emisSettlePayRecordMapper.getBillAmountsByPayIds(payIds);
|
||||||
|
Map<String, Object> result = new java.util.HashMap<>();
|
||||||
|
for (Map<String, Object> map : billAmountsList) {
|
||||||
|
String payId = (String) map.get("pay_id");
|
||||||
|
if (payId != null) {
|
||||||
|
result.put(payId, map.get("rec_money"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取开票金额映射
|
||||||
|
*/
|
||||||
|
private Map<String, Object> getInvoiceAmountsMap(List<String> payIds) {
|
||||||
|
List<Map<String, Object>> invoiceAmountsList = emisSettlePayRecordMapper.getInvoiceAmountsByPayIds(payIds);
|
||||||
|
Map<String, Object> result = new java.util.HashMap<>();
|
||||||
|
for (Map<String, Object> map : invoiceAmountsList) {
|
||||||
|
String payId = (String) map.get("pay_id");
|
||||||
|
if (payId != null) {
|
||||||
|
result.put(payId, map.get("total_amount"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取开票状态映射
|
||||||
|
*/
|
||||||
|
private Map<String, Object> getInvoiceStatusMap(List<String> payIds) {
|
||||||
|
List<Map<String, Object>> invoiceStatusList = emisSettlePayRecordMapper.getInvoiceStatusByPayIds(payIds);
|
||||||
|
Map<String, Object> result = new java.util.HashMap<>();
|
||||||
|
for (Map<String, Object> map : invoiceStatusList) {
|
||||||
|
String payId = (String) map.get("pay_id");
|
||||||
|
if (payId != null) {
|
||||||
|
result.put(payId, map.get("status"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取发票申请备注映射
|
||||||
|
*/
|
||||||
|
private Map<String, Object> getInvoiceRemarksMap(List<String> payIds) {
|
||||||
|
List<Map<String, Object>> invoiceRemarksList = emisSettlePayRecordMapper.getInvoiceRemarksByPayIds(payIds);
|
||||||
|
Map<String, Object> result = new java.util.HashMap<>();
|
||||||
|
for (Map<String, Object> map : invoiceRemarksList) {
|
||||||
|
String payId = (String) map.get("pay_id");
|
||||||
|
if (payId != null) {
|
||||||
|
result.put(payId, map.get("invoice_remark"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map getSettlePayStatInfoMap(EmisSettlePayRecord emisSettlePayRecord)
|
public Map<String, Object> getSettlePayStatInfoMap(EmisSettlePayRecord emisSettlePayRecord) {
|
||||||
{
|
|
||||||
return emisSettlePayRecordMapper.getSettlePayStatInfoMap(emisSettlePayRecord);
|
return emisSettlePayRecordMapper.getSettlePayStatInfoMap(emisSettlePayRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -95,83 +95,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
a.refund_remark, a.refund_op_man_code, a.refund_register_site_code,
|
a.refund_remark, a.refund_op_man_code, a.refund_register_site_code,
|
||||||
a.refund_register_man_code, a.satisfy_money, a.satisfy_reason, a.allowance_money,
|
a.refund_register_man_code, a.satisfy_money, a.satisfy_reason, a.allowance_money,
|
||||||
a.allowance_reason, a.deduction_money, a.deduction_reason, a.other_money,
|
a.allowance_reason, a.deduction_money, a.deduction_reason, a.other_money,
|
||||||
a.other_reason, a.trade_date,
|
a.other_reason, a.trade_date, a.remark,
|
||||||
-- 重新赋值备注字段:财务开票备注+账单备注
|
a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time, a.create_site, a.update_site
|
||||||
CONCAT_WS(';',
|
|
||||||
COALESCE(invoice_remarks.invoice_remark, ''),
|
|
||||||
COALESCE(bill_remark.remark, '')
|
|
||||||
) as remark,
|
|
||||||
a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time, a.create_site, a.update_site,
|
|
||||||
-- 运单号(多个用逗号分隔)
|
|
||||||
COALESCE(waybill_codes.bill_codes, '') as bill_codes,
|
|
||||||
-- 账单金额
|
|
||||||
COALESCE(bill_amount.rec_money, 0) as bill_amount,
|
|
||||||
-- 开票金额
|
|
||||||
COALESCE(invoice_amount.total_amount, 0) as invoice_amount,
|
|
||||||
-- 开票状态
|
|
||||||
COALESCE(invoice_status.status, '0') as invoice_status
|
|
||||||
from emis_settle_pay_record a
|
from emis_settle_pay_record a
|
||||||
-- 关联获取运单号
|
|
||||||
left join (
|
|
||||||
select
|
|
||||||
espbr.pay_id,
|
|
||||||
GROUP_CONCAT(essb.bill_code SEPARATOR ',') as bill_codes
|
|
||||||
from emis_settle_pay_bill_rel espbr
|
|
||||||
left join emis_settle_sub_bill essb on espbr.settle_bill_no = essb.settle_bill_no
|
|
||||||
where espbr.del_flag = '0' and essb.del_flag = '0'
|
|
||||||
group by espbr.pay_id
|
|
||||||
) waybill_codes on a.pay_id = waybill_codes.pay_id
|
|
||||||
-- 关联获取账单金额
|
|
||||||
left join (
|
|
||||||
select
|
|
||||||
espbr.pay_id,
|
|
||||||
esb.rec_money
|
|
||||||
from emis_settle_pay_bill_rel espbr
|
|
||||||
left join emis_settle_bill esb on espbr.settle_bill_no = esb.settle_bill_no
|
|
||||||
where espbr.del_flag = '0' and esb.del_flag = '0'
|
|
||||||
group by espbr.pay_id
|
|
||||||
) bill_amount on a.pay_id = bill_amount.pay_id
|
|
||||||
-- 关联获取开票金额
|
|
||||||
left join (
|
|
||||||
select
|
|
||||||
espir.pay_id,
|
|
||||||
SUM(esir.open_money) as total_amount
|
|
||||||
from emis_settle_pay_invoice_rel espir
|
|
||||||
left join emis_settle_invoice_record esir on espir.apply_seq_no = esir.apply_seq_no
|
|
||||||
where espir.del_flag = '0' and esir.del_flag = '0' and esir.invoice_status = '1'
|
|
||||||
group by espir.pay_id
|
|
||||||
) invoice_amount on a.pay_id = invoice_amount.pay_id
|
|
||||||
-- 关联获取开票状态
|
|
||||||
left join (
|
|
||||||
select
|
|
||||||
espir.pay_id,
|
|
||||||
esir.invoice_status as status
|
|
||||||
from emis_settle_pay_invoice_rel espir
|
|
||||||
left join emis_settle_invoice_record esir on espir.apply_seq_no = esir.apply_seq_no
|
|
||||||
where espir.del_flag = '0' and esir.del_flag = '0'
|
|
||||||
group by espir.pay_id
|
|
||||||
) invoice_status on a.pay_id = invoice_status.pay_id
|
|
||||||
-- 关联获取财务开票备注
|
|
||||||
left join (
|
|
||||||
select
|
|
||||||
espir.pay_id,
|
|
||||||
GROUP_CONCAT(esir.invioce_remark SEPARATOR ';') as invoice_remark
|
|
||||||
from emis_settle_pay_invoice_rel espir
|
|
||||||
left join emis_settle_invoice_record esir on espir.apply_seq_no = esir.apply_seq_no
|
|
||||||
where espir.del_flag = '0' and esir.del_flag = '0'
|
|
||||||
and esir.invioce_remark is not null and esir.invioce_remark != ''
|
|
||||||
group by espir.pay_id
|
|
||||||
) invoice_remarks on a.pay_id = invoice_remarks.pay_id
|
|
||||||
-- 关联获取账单备注
|
|
||||||
left join (
|
|
||||||
select
|
|
||||||
espbr.pay_id,
|
|
||||||
esb.remark
|
|
||||||
from emis_settle_pay_bill_rel espbr
|
|
||||||
left join emis_settle_bill esb on espbr.settle_bill_no = esb.settle_bill_no
|
|
||||||
where espbr.del_flag = '0' and esb.del_flag = '0'
|
|
||||||
group by espbr.pay_id
|
|
||||||
) bill_remark on a.pay_id = bill_remark.pay_id
|
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="getSettlePayStatInfoMap" parameterType="EmisSettlePayRecord" resultType="map">
|
<select id="getSettlePayStatInfoMap" parameterType="EmisSettlePayRecord" resultType="map">
|
||||||
@ -694,4 +620,156 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
ORDER BY
|
ORDER BY
|
||||||
tradeDay
|
tradeDay
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据支付ID列表获取运单号 -->
|
||||||
|
<select id="getWaybillCodesByPayIds" parameterType="java.util.List" resultType="map">
|
||||||
|
select
|
||||||
|
espbr.pay_id,
|
||||||
|
GROUP_CONCAT(essb.bill_code SEPARATOR ',') as bill_codes
|
||||||
|
from emis_settle_pay_bill_rel espbr
|
||||||
|
left join emis_settle_sub_bill essb on espbr.settle_bill_no = essb.settle_bill_no
|
||||||
|
where espbr.del_flag = '0' and essb.del_flag = '0'
|
||||||
|
and espbr.pay_id in
|
||||||
|
<foreach collection="list" item="payId" open="(" separator="," close=")">
|
||||||
|
#{payId}
|
||||||
|
</foreach>
|
||||||
|
group by espbr.pay_id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据支付ID列表获取账单金额 -->
|
||||||
|
<select id="getBillAmountsByPayIds" parameterType="java.util.List" resultType="map">
|
||||||
|
select
|
||||||
|
espbr.pay_id,
|
||||||
|
esb.rec_money
|
||||||
|
from emis_settle_pay_bill_rel espbr
|
||||||
|
left join emis_settle_bill esb on espbr.settle_bill_no = esb.settle_bill_no
|
||||||
|
where espbr.del_flag = '0' and esb.del_flag = '0'
|
||||||
|
and espbr.pay_id in
|
||||||
|
<foreach collection="list" item="payId" open="(" separator="," close=")">
|
||||||
|
#{payId}
|
||||||
|
</foreach>
|
||||||
|
group by espbr.pay_id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据支付ID列表获取开票金额 -->
|
||||||
|
<select id="getInvoiceAmountsByPayIds" parameterType="java.util.List" resultType="map">
|
||||||
|
select
|
||||||
|
espr.pay_id,
|
||||||
|
SUM(esir.apply_money) as total_amount
|
||||||
|
from emis_settle_pay_record espr
|
||||||
|
left join emis_settle_invoice_record esir on espr.settle_bill_no = esir.settle_bill_no
|
||||||
|
where espr.del_flag = '0' and esir.del_flag = '0' and esir.invoice_status = '2'
|
||||||
|
and espr.pay_id in
|
||||||
|
<foreach collection="list" item="payId" open="(" separator="," close=")">
|
||||||
|
#{payId}
|
||||||
|
</foreach>
|
||||||
|
group by espr.pay_id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据支付ID列表获取开票状态 -->
|
||||||
|
<select id="getInvoiceStatusByPayIds" parameterType="java.util.List" resultType="map">
|
||||||
|
select
|
||||||
|
pay_id,
|
||||||
|
CONCAT_WS(';',
|
||||||
|
-- 1. 已开票记录(若存在则拼接,否则为NULL)
|
||||||
|
GROUP_CONCAT(
|
||||||
|
CASE WHEN op_date IS NOT NULL THEN -- 只拼接明细行
|
||||||
|
CONCAT(
|
||||||
|
DATE_FORMAT(op_date, '%m%d'),
|
||||||
|
'已开票',
|
||||||
|
CASE
|
||||||
|
WHEN total_amount = FLOOR(total_amount) THEN CAST(FLOOR(total_amount) AS CHAR)
|
||||||
|
ELSE TRIM(TRAILING '0' FROM TRIM(TRAILING '.' FROM CAST(total_amount AS CHAR)))
|
||||||
|
END,
|
||||||
|
' ',
|
||||||
|
company_name
|
||||||
|
)
|
||||||
|
END
|
||||||
|
ORDER BY op_date
|
||||||
|
SEPARATOR ';'
|
||||||
|
),
|
||||||
|
-- 2. 剩余未开金额(从汇总行提取计算)
|
||||||
|
CASE
|
||||||
|
WHEN (MAX(bill_amount) - MAX(invoice_amount)) > 0
|
||||||
|
THEN CONCAT('剩余未开',
|
||||||
|
CASE
|
||||||
|
WHEN (MAX(bill_amount) - MAX(invoice_amount)) = FLOOR(MAX(bill_amount) - MAX(invoice_amount))
|
||||||
|
THEN CAST(FLOOR(MAX(bill_amount) - MAX(invoice_amount)) AS CHAR)
|
||||||
|
ELSE TRIM(TRAILING '0' FROM TRIM(TRAILING '.' FROM CAST((MAX(bill_amount) - MAX(invoice_amount)) AS CHAR)))
|
||||||
|
END, '元')
|
||||||
|
ELSE ''
|
||||||
|
END
|
||||||
|
) as status
|
||||||
|
from (
|
||||||
|
-- 子查询1:已开票明细行(按日期分组)
|
||||||
|
select
|
||||||
|
espr.pay_id,
|
||||||
|
esir.op_date,
|
||||||
|
SUM(esir.apply_money) as total_amount,
|
||||||
|
GROUP_CONCAT(DISTINCT esir.company_name SEPARATOR ' ') as company_name,
|
||||||
|
0 as total_invoiced_amount, -- 明细行不参与汇总计算
|
||||||
|
0 as bill_amount,
|
||||||
|
0 as invoice_amount
|
||||||
|
from emis_settle_pay_record espr
|
||||||
|
left join emis_settle_pay_bill_rel espbr on espr.pay_id = espbr.pay_id
|
||||||
|
left join emis_settle_invoice_record esir on espbr.settle_bill_no = esir.settle_bill_no
|
||||||
|
where espr.del_flag = '0'
|
||||||
|
and espbr.del_flag = '0'
|
||||||
|
and esir.del_flag = '0'
|
||||||
|
and esir.invoice_status = '2'
|
||||||
|
and espr.pay_id in
|
||||||
|
<foreach collection="list" item="payId" open="(" separator="," close=")">
|
||||||
|
#{payId}
|
||||||
|
</foreach>
|
||||||
|
group by espr.pay_id, esir.op_date
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
-- 子查询2:汇总行(计算总开票金额和账单金额)
|
||||||
|
select
|
||||||
|
espr.pay_id,
|
||||||
|
NULL as op_date, -- 汇总行无日期,用于区分
|
||||||
|
0 as total_amount,
|
||||||
|
'' as company_name,
|
||||||
|
SUM(CASE WHEN esir.invoice_status = '2' THEN esir.apply_money ELSE 0 END) as total_invoiced_amount,
|
||||||
|
MAX(esb.rec_money) as bill_amount,
|
||||||
|
SUM(CASE WHEN esir.invoice_status = '2' THEN esir.apply_money ELSE 0 END) as invoice_amount
|
||||||
|
from emis_settle_pay_record espr
|
||||||
|
left join emis_settle_pay_bill_rel espbr on espr.pay_id = espbr.pay_id
|
||||||
|
left join emis_settle_bill esb on espbr.settle_bill_no = esb.settle_bill_no
|
||||||
|
left join emis_settle_invoice_record esir on espbr.settle_bill_no = esir.settle_bill_no
|
||||||
|
where espr.del_flag = '0'
|
||||||
|
and espbr.del_flag = '0'
|
||||||
|
and esb.del_flag = '0'
|
||||||
|
and esir.del_flag = '0'
|
||||||
|
and espr.pay_id in
|
||||||
|
<foreach collection="list" item="payId" open="(" separator="," close=")">
|
||||||
|
#{payId}
|
||||||
|
</foreach>
|
||||||
|
group by espr.pay_id
|
||||||
|
) invoice_summary
|
||||||
|
group by pay_id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- 根据支付ID列表获取发票申请备注 -->
|
||||||
|
<select id="getInvoiceRemarksByPayIds" parameterType="java.util.List" resultType="map">
|
||||||
|
select
|
||||||
|
espr.pay_id,
|
||||||
|
GROUP_CONCAT(
|
||||||
|
CONCAT('(', esir.remark, ')')
|
||||||
|
SEPARATOR ';'
|
||||||
|
) as invoice_remark
|
||||||
|
from emis_settle_pay_record espr
|
||||||
|
left join emis_settle_invoice_record esir on espr.settle_bill_no = esir.settle_bill_no
|
||||||
|
where espr.del_flag = '0' and esir.del_flag = '0'
|
||||||
|
and esir.remark is not null and esir.remark != ''
|
||||||
|
and esir.invoice_status = '2'
|
||||||
|
and espr.pay_id in
|
||||||
|
<foreach collection="list" item="payId" open="(" separator="," close=")">
|
||||||
|
#{payId}
|
||||||
|
</foreach>
|
||||||
|
group by espr.pay_id
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user