wujiefeng 1 год назад
Родитель
Сommit
f0914080d3

+ 32 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/pay/statistics/PayOverviewController.java

@@ -1,5 +1,7 @@
 package com.zhongshu.card.server.core.controller.pay.statistics;
 
+import com.github.microservice.auth.security.annotations.ResourceAuth;
+import com.github.microservice.auth.security.type.AuthType;
 import com.zhongshu.card.client.model.pay.PeriodDetailQueryModel;
 import com.zhongshu.card.client.model.pay.PeriodQueryModel;
 import com.zhongshu.card.client.model.pay.SettleDetailQueryModel;
@@ -7,6 +9,8 @@ import com.zhongshu.card.server.core.service.pay.OrgOverviewService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.web.PageableDefault;
@@ -28,6 +32,7 @@ public class PayOverviewController {
 //        return orgOverviewService.balanceOverview(projectOid, oid);
 //    }
 
+    @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "实时概况", description = "顶部数据及资金概况-折线图")
     @RequestMapping(value = "realTimeOverview", method = RequestMethod.GET)
     public Object realTimeOverview(@RequestParam(name = "projectOid", required = false) String projectOid,
@@ -35,6 +40,7 @@ public class PayOverviewController {
         return orgOverviewService.realTimeOverview(projectOid);
     }
 
+    @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "查询收入账单", description = "查询收入账单-年月日汇总")
     @RequestMapping(value = "queryCreditBill", method = RequestMethod.POST)
     public Object queryCreditBill(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10)Pageable pageable,
@@ -42,6 +48,7 @@ public class PayOverviewController {
         return orgOverviewService.queryCreditBill(pageable, param);
     }
 
+    @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "查询收入账单详情", description = "查询收入账单详情")
     @RequestMapping(value = "queryCreditBillDetail", method = RequestMethod.POST)
     public Object queryCreditBillDetail(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
@@ -49,6 +56,14 @@ public class PayOverviewController {
         return orgOverviewService.queryCreditBillDetail(pageable, periodDetailQueryModel);
     }
 
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @RequestMapping(value = "exportCreditBill", method = RequestMethod.POST)
+    @Operation(summary = "下载收入账单", description = "下载收入账单")
+    public void exportCreditBill(HttpServletRequest request, HttpServletResponse response, @RequestBody PeriodDetailQueryModel periodDetailQueryModel){
+        orgOverviewService.exportCreditBill(request, response, periodDetailQueryModel);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "查询结算账单", description = "查询结算账单")
     @RequestMapping(value = "querySettleBill", method = RequestMethod.POST)
     public Object querySettleBill(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
@@ -56,6 +71,7 @@ public class PayOverviewController {
         return orgOverviewService.querySettleBill(pageable, param);
     }
 
+    @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "查询结算账单详情", description = "查询结算账单详情")
     @RequestMapping(value = "querySettleBillDetail", method = RequestMethod.POST)
     public Object querySettleBillDetail(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
@@ -63,6 +79,14 @@ public class PayOverviewController {
         return orgOverviewService.querySettleBillDetail(pageable, settleDetailQueryModel);
     }
 
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "下载结算账单", description = "下载结算账单")
+    @RequestMapping(value = "exportSettleBill", method = RequestMethod.POST)
+    public void exportSettleBill(HttpServletRequest request, HttpServletResponse response, @RequestBody SettleDetailQueryModel settleDetailQueryModel){
+        orgOverviewService.exportSettleBill(request, response, settleDetailQueryModel);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "查询提现账单", description = "查询提现账单")
     @RequestMapping(value = "queryWithdrawBill", method = RequestMethod.POST)
     public Object queryWithdrawBill(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
@@ -70,10 +94,18 @@ public class PayOverviewController {
         return orgOverviewService.queryWithdrawBill(pageable, param);
     }
 
+    @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "查询提现账单详情", description = "查询提现账单详情")
     @RequestMapping(value = "queryWithdrawBillDetail", method = RequestMethod.POST)
     public Object queryWithdrawBillDetail(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
                                         @Parameter(required = false) SettleDetailQueryModel settleDetailQueryModel){
         return orgOverviewService.queryWithdrawBillDetail(pageable, settleDetailQueryModel);
     }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "下载提现账单", description = "下载提现账单")
+    @RequestMapping(value = "exportWithdrawBill", method = RequestMethod.POST)
+    public void exportWithdrawBill(HttpServletRequest request, HttpServletResponse response, @RequestBody SettleDetailQueryModel settleDetailQueryModel){
+        orgOverviewService.exportWithdrawBill(request, response, settleDetailQueryModel);
+    }
 }

+ 6 - 4
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/BalancePayService.java

@@ -151,7 +151,7 @@ public class BalancePayService extends SuperService {
                 sourceTransaction.setTransactionStatus(TransactionStatus.Success);
                 sourceTransaction.setAmount(rechargeOrder.getTotal().negate().longValue());
                 sourceTransaction.setRemark("用户余额充值");
-                sourceTransaction.setMeta(Map.of("paymentType",PaymentType.WeChat, "description","用户充值"));
+                sourceTransaction.setMeta(Map.of("paymentType",PaymentType.WeChat, "description","用户充值", "summary", "用户充值"));
                 transferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
 
                 //构建入账账户
@@ -162,7 +162,7 @@ public class BalancePayService extends SuperService {
                 destinationTransaction.setTransactionStatus(TransactionStatus.Success);
                 destinationTransaction.setAmount(rechargeOrder.getTotal().longValue());
                 destinationTransaction.setRemark("用户余额充值");
-                destinationTransaction.setMeta(Map.of("paymentType",PaymentType.WeChat, "description","用户充值"));
+                destinationTransaction.setMeta(Map.of("paymentType",PaymentType.WeChat, "description","用户充值", "summary", "用户充值"));
                 transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
                 //发起转账
                 ResultContent<List<TransactionLogModel>> transfer = transactionLogService.transfer(transferModel);
@@ -208,7 +208,7 @@ public class BalancePayService extends SuperService {
         sourceTransaction.setTransactionStatus(TransactionStatus.Success);
         sourceTransaction.setAmount(total.negate().longValue());
         sourceTransaction.setRemark(remark);
-        sourceTransaction.setMeta(Map.of("paymentType",PaymentType.UserWallet, "description", "用户余额支付"));
+        sourceTransaction.setMeta(Map.of("paymentType",PaymentType.UserWallet, "description", "用户余额支付", "summary", "用户支付"));
         transferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
         //构建入账账户
         TransferTransactionsModel.GeneralLedgerTransaction destinationTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
@@ -218,7 +218,7 @@ public class BalancePayService extends SuperService {
         destinationTransaction.setTransactionStatus(TransactionStatus.Success);
         destinationTransaction.setAmount(total.longValue());
         destinationTransaction.setRemark(remark);
-        destinationTransaction.setMeta(Map.of("paymentType",PaymentType.UserWallet, "description", "用户余额支付"));
+        destinationTransaction.setMeta(Map.of("paymentType",PaymentType.UserWallet, "description", "用户余额支付", "summary", "用户支付"));
         transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
         //发起转账
        return transactionLogService.transfer(transferModel);
@@ -307,6 +307,7 @@ public class BalancePayService extends SuperService {
         sourceTransaction.setOrderNumber(orderNo);
         sourceTransaction.setGeneralLedgerId(orgAccount.getLedgerId());
         sourceTransaction.setRemark(remark);
+        sourceTransaction.setMeta(Map.of("paymentType",PaymentType.UserWallet, "description", "用户余额支付", "summary", "用户退款"));
         transferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
         //构建入账账户
         TransferTransactionsModel.GeneralLedgerTransaction destinationTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
@@ -316,6 +317,7 @@ public class BalancePayService extends SuperService {
         destinationTransaction.setOrderNumber(orderNo);
         destinationTransaction.setGeneralLedgerId(userAccount.getLedgerId());
         destinationTransaction.setRemark(remark);
+        destinationTransaction.setMeta(Map.of("paymentType",PaymentType.UserWallet, "description", "用户余额支付", "summary", "用户退款"));
         transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
         //调用支付中心转账接口
         return transactionLogService.transfer(transferModel);

+ 58 - 58
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/ChinaumsSenselessPayService.java

@@ -508,32 +508,32 @@ public class ChinaumsSenselessPayService extends SuperService {
         PayAccount userBalancePayment = payAccountService.getUserChildren(projectOid, userId, PaymentChannelType.SecretFreePayment);
         //获取机构待结算账户
         PayAccount orgWaitSettle = payAccountService.getOrgChildren(projectOid, oid, PaymentChannelType.WaitSettle);
-        //支付:项目余额子账- 用户无感支付子账+
-        //构建转账参数
-        TransferTransactionsModel transferModel = new TransferTransactionsModel();
-        //构建出账账户
-        TransferTransactionsModel.GeneralLedgerTransaction sourceTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
-        sourceTransaction.setGeneralLedgerId(projectAccount.getLedgerId());
-        sourceTransaction.setOrderNumber(orderNo);
-        //TODO 修改交易类型为:无感支付-借贷
-        sourceTransaction.setTransactionType(TransactionType.Pay);
-        sourceTransaction.setTransactionStatus(TransactionStatus.Success);
-        sourceTransaction.setAmount(total.negate().longValue());
-        sourceTransaction.setRemark(remark);
-        sourceTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "银联无感支付"));
-        transferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
-
-        //构建入账账户
-        TransferTransactionsModel.GeneralLedgerTransaction destinationTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
-        destinationTransaction.setGeneralLedgerId(userBalancePayment.getLedgerId());
-        destinationTransaction.setOrderNumber(orderNo);
-        //TODO 修改交易类型为:无感支付-借贷
-        destinationTransaction.setTransactionType(TransactionType.Pay);
-        destinationTransaction.setTransactionStatus(TransactionStatus.Success);
-        destinationTransaction.setAmount(total.longValue());
-        destinationTransaction.setRemark(remark);
-        destinationTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "用户余额支付"));
-        transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
+//        //支付:项目余额子账- 用户无感支付子账+
+//        //构建转账参数
+//        TransferTransactionsModel transferModel = new TransferTransactionsModel();
+//        //构建出账账户
+//        TransferTransactionsModel.GeneralLedgerTransaction sourceTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
+//        sourceTransaction.setGeneralLedgerId(projectAccount.getLedgerId());
+//        sourceTransaction.setOrderNumber(orderNo);
+//        //TODO 修改交易类型为:无感支付-借贷
+//        sourceTransaction.setTransactionType(TransactionType.Pay);
+//        sourceTransaction.setTransactionStatus(TransactionStatus.Success);
+//        sourceTransaction.setAmount(total.negate().longValue());
+//        sourceTransaction.setRemark(remark);
+//        sourceTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "银联无感支付", "summary", "用户支付"));
+//        transferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
+//
+//        //构建入账账户
+//        TransferTransactionsModel.GeneralLedgerTransaction destinationTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
+//        destinationTransaction.setGeneralLedgerId(userBalancePayment.getLedgerId());
+//        destinationTransaction.setOrderNumber(orderNo);
+//        //TODO 修改交易类型为:无感支付-借贷
+//        destinationTransaction.setTransactionType(TransactionType.Pay);
+//        destinationTransaction.setTransactionStatus(TransactionStatus.Success);
+//        destinationTransaction.setAmount(total.longValue());
+//        destinationTransaction.setRemark(remark);
+//        destinationTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "银联无感支付", "summary", "用户支付"));
+//        transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
 //        transactionLogService.transfer(transferModel);
 
         //支付:用户余额子账- 机构无感支付子账+
@@ -547,7 +547,7 @@ public class ChinaumsSenselessPayService extends SuperService {
         userSourceTransaction.setTransactionStatus(TransactionStatus.Success);
         userSourceTransaction.setAmount(total.negate().longValue());
         userSourceTransaction.setRemark(remark);
-        userSourceTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "银联无感支付"));
+        userSourceTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "银联无感支付", "summary", "用户支付"));
         payTransferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{userSourceTransaction});
 
         //构建入账账户
@@ -558,10 +558,10 @@ public class ChinaumsSenselessPayService extends SuperService {
         orgDestinationTransaction.setTransactionStatus(TransactionStatus.Success);
         orgDestinationTransaction.setAmount(total.longValue());
         orgDestinationTransaction.setRemark(remark);
-        orgDestinationTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "银联无感支付"));
+        orgDestinationTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "银联无感支付", "summary", "用户支付"));
         payTransferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{orgDestinationTransaction});
         TransferTransactionsModels transactionsModels = new TransferTransactionsModels();
-        transactionsModels.setItems(new TransferTransactionsModel[]{transferModel, payTransferModel});
+        transactionsModels.setItems(new TransferTransactionsModel[]{payTransferModel});
         return transactionLogService.transfers(transactionsModels);
     }
 
@@ -574,32 +574,32 @@ public class ChinaumsSenselessPayService extends SuperService {
         PayAccount userBalancePayment = payAccountService.getUserChildren(projectOid, userId, PaymentChannelType.SecretFreePayment);
         //获取机构待结算账户
         PayAccount orgWaitSettle = payAccountService.getOrgChildren(projectOid, oid, PaymentChannelType.WaitSettle);
-        //支付:项目余额子账+ 用户无感支付子账-
-        //构建转账参数
-        TransferTransactionsModel transferModel = new TransferTransactionsModel();
-        //构建出账账户
-        TransferTransactionsModel.GeneralLedgerTransaction sourceTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
-        sourceTransaction.setGeneralLedgerId(userBalancePayment.getLedgerId());
-        sourceTransaction.setOrderNumber(orderNo);
-        //TODO 修改交易类型为:无感支付-借贷
-        sourceTransaction.setTransactionType(TransactionType.Refund);
-        sourceTransaction.setTransactionStatus(TransactionStatus.Success);
-        sourceTransaction.setAmount(total.negate().longValue());
-        sourceTransaction.setRemark(remark);
-        sourceTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "银联无感支付"));
-        transferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
-
-        //构建入账账户
-        TransferTransactionsModel.GeneralLedgerTransaction destinationTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
-        destinationTransaction.setGeneralLedgerId(projectAccount.getLedgerId());
-        destinationTransaction.setOrderNumber(orderNo);
-        //TODO 修改交易类型为:无感支付-借贷
-        destinationTransaction.setTransactionType(TransactionType.Refund);
-        destinationTransaction.setTransactionStatus(TransactionStatus.Success);
-        destinationTransaction.setAmount(total.longValue());
-        destinationTransaction.setRemark(remark);
-        destinationTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "用户余额支付"));
-        transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
+//        //支付:项目余额子账+ 用户无感支付子账-
+//        //构建转账参数
+//        TransferTransactionsModel transferModel = new TransferTransactionsModel();
+//        //构建出账账户
+//        TransferTransactionsModel.GeneralLedgerTransaction sourceTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
+//        sourceTransaction.setGeneralLedgerId(userBalancePayment.getLedgerId());
+//        sourceTransaction.setOrderNumber(orderNo);
+//        //TODO 修改交易类型为:无感支付-借贷
+//        sourceTransaction.setTransactionType(TransactionType.Refund);
+//        sourceTransaction.setTransactionStatus(TransactionStatus.Success);
+//        sourceTransaction.setAmount(total.negate().longValue());
+//        sourceTransaction.setRemark(remark);
+//        sourceTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "银联无感支付", "summary", "用户退款"));
+//        transferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
+//
+//        //构建入账账户
+//        TransferTransactionsModel.GeneralLedgerTransaction destinationTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
+//        destinationTransaction.setGeneralLedgerId(projectAccount.getLedgerId());
+//        destinationTransaction.setOrderNumber(orderNo);
+//        //TODO 修改交易类型为:无感支付-借贷
+//        destinationTransaction.setTransactionType(TransactionType.Refund);
+//        destinationTransaction.setTransactionStatus(TransactionStatus.Success);
+//        destinationTransaction.setAmount(total.longValue());
+//        destinationTransaction.setRemark(remark);
+//        destinationTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "用户余额支付", "summary", "用户退款"));
+//        transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
 //        transactionLogService.transfer(transferModel);
 
         //支付:机构余额子账- 用户无感支付子账+
@@ -613,7 +613,7 @@ public class ChinaumsSenselessPayService extends SuperService {
         orgDestinationTransaction.setTransactionStatus(TransactionStatus.Success);
         orgDestinationTransaction.setAmount(total.negate().longValue());
         orgDestinationTransaction.setRemark(remark);
-        orgDestinationTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "银联无感支付"));
+        orgDestinationTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "银联无感支付", "summary", "用户退款"));
         payTransferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{orgDestinationTransaction});
 
         //构建入账账户
@@ -624,10 +624,10 @@ public class ChinaumsSenselessPayService extends SuperService {
         userSourceTransaction.setTransactionStatus(TransactionStatus.Success);
         userSourceTransaction.setAmount(total.longValue());
         userSourceTransaction.setRemark(remark);
-        userSourceTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "银联无感支付"));
+        userSourceTransaction.setMeta(Map.of("paymentType", PaymentType.UnionFrictionlessPay, "description", "银联无感支付", "summary", "用户退款"));
         payTransferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{userSourceTransaction});
         TransferTransactionsModels transactionsModels = new TransferTransactionsModels();
-        transactionsModels.setItems(new TransferTransactionsModel[]{transferModel, payTransferModel});
+        transactionsModels.setItems(new TransferTransactionsModel[]{payTransferModel});
         return transactionLogService.transfers(transactionsModels);
     }
 

+ 149 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/OrgOverviewService.java

@@ -1,8 +1,10 @@
 package com.zhongshu.card.server.core.service.pay;
 
 import com.github.microservice.components.data.base.page.PageableModel;
+import com.github.microservice.core.util.bean.BeanUtil;
 import com.github.microservice.pay.client.model.ledger.GeneralLedgerQueryModel;
 import com.github.microservice.pay.client.model.ledger.GeneralLedgerTreeModel;
+import com.github.microservice.pay.client.model.ledger.TransactionLogModel;
 import com.github.microservice.pay.client.model.ledger.transaction.*;
 import com.github.microservice.pay.client.ret.ResultContent;
 import com.github.microservice.pay.client.ret.ResultState;
@@ -12,6 +14,7 @@ import com.github.microservice.pay.client.type.ledger.LedgerEntry;
 import com.github.microservice.pay.client.type.ledger.TransactionStatus;
 import com.github.microservice.pay.client.type.ledger.TransactionType;
 import com.github.microservice.types.payment.PaymentChannelType;
+import com.github.microservice.types.payment.PaymentType;
 import com.zhongshu.card.client.model.pay.*;
 import com.zhongshu.card.client.type.PeriodType;
 import com.zhongshu.card.client.type.SettleStatus;
@@ -19,9 +22,15 @@ import com.zhongshu.card.client.utils.DateUtils;
 import com.zhongshu.card.server.core.domain.pay.PayAccount;
 import com.zhongshu.card.server.core.service.base.SuperService;
 import com.zhongshu.card.server.core.service.org.OrganizationUserServiceImpl;
+import com.zhongshu.card.server.core.util.ExcelUtils;
+import com.zhongshu.card.server.core.util.excel.CommonExeclParam;
+import com.zhongshu.card.server.core.util.excel.CommonExeclTd;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.bson.Document;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
@@ -34,6 +43,7 @@ import java.util.*;
 import java.util.stream.Collectors;
 
 import static org.springframework.integration.IntegrationPatternType.filter;
+import static org.springframework.integration.IntegrationPatternType.inbound_gateway;
 
 @Service
 @Slf4j
@@ -305,6 +315,76 @@ public class OrgOverviewService extends SuperService {
         return ResultContent.buildContent(transactionLogService.aggregate(queryModel).getContent().getPages());
     }
 
+    public void exportCreditBill(HttpServletRequest request, HttpServletResponse response, PeriodDetailQueryModel periodDetailQueryModel){
+        String projectOid = periodDetailQueryModel.getProjectOid();
+        if (StringUtils.isBlank(projectOid)) {
+            projectOid = getCurrentProjectOid();
+        }
+
+        List<String> oidList = organizationUserService.getUserOrgListOids(getCurrentUserId(), projectOid);
+        if (oidList==null || oidList.isEmpty()){
+            throw new RuntimeException("未加入机构");
+        }
+
+        PayAccount payAccount = payAccountService.getOrgChildren(projectOid, oidList.get(0), PaymentChannelType.WaitSettle);
+
+        GeneralLedgerQueryTransactionLogModel queryModel = new GeneralLedgerQueryTransactionLogModel();
+
+        queryModel.setStartTime(periodDetailQueryModel.getStartTime());
+        queryModel.setEndTime(periodDetailQueryModel.getEndTime());
+        queryModel.setGeneralLedgerId(new String[]{payAccount.getLedgerId()});
+
+        Map<String, Object> filter = new HashMap<>();
+        filter.put("transactionType",new Document("$ne", "Settle"));
+        queryModel.setFilter(filter);
+        List<TransactionLogModel> list = transactionLogService.aggregateNotPage(queryModel).getContent().getList();
+
+        buildBillExcel(request, response, periodDetailQueryModel.getCreateDate(), list);
+    }
+
+    private static void buildBillExcel(HttpServletRequest request, HttpServletResponse response, String title, List<TransactionLogModel> list) {
+        CommonExeclParam execlParam = new CommonExeclParam();
+        execlParam.setTitle(String.format("%s收入账单", title));
+        execlParam.setStartRow(2);
+
+        List<Map<String, Object>> data = list.stream().map(it -> {
+            Map<String, Object> map = new HashMap<>();
+            map.put("id", it.getId());
+            map.put("orderNo", it.getOrderNumber());
+            map.put("createDate", DateUtils.paresTime(it.getCreateTime(), DateUtils.FORMAT_LONG));
+            if (it.getMeta()!=null) {
+                if (it.getMeta().get("paymentType") != null){
+                    PaymentType paymentType = PaymentType.valueOf(it.getMeta().get("paymentType").toString());
+                    map.put("paymentType", paymentType.getRemark());
+                }
+                if (it.getMeta().get("summary") !=null){
+                    map.put("summary", it.getMeta().get("summary").toString());
+                }
+            }
+            LedgerEntry ledgerEntry = it.getLedgerEntry();
+            if (ledgerEntry.equals(LedgerEntry.Credit)) {
+                map.put("ledgerEntry", "收入");
+            } else if (ledgerEntry.equals(LedgerEntry.Debit)) {
+                map.put("ledgerEntry", "支出");
+            }
+            map.put("remark", it.getRemark());
+            map.put("amount", it.getAmount());
+            return map;
+        }).collect(Collectors.toList());
+        execlParam.setDatas(data);
+        List<CommonExeclTd> tds = new ArrayList<>();
+        tds.add(CommonExeclTd.build("账单流水编号", "id"));
+        tds.add(CommonExeclTd.build("关联订单编号", "orderNo"));
+        tds.add(CommonExeclTd.build("创建时间", "createDate"));
+        tds.add(CommonExeclTd.build("支付方式", "paymentType"));
+        tds.add(CommonExeclTd.build("账单类型", "ledgerEntry"));
+        tds.add(CommonExeclTd.build("记账摘要", "summary"));
+        tds.add(CommonExeclTd.build("金额(元)", "amount"));
+
+        execlParam.setTds(tds);
+        ExcelUtils.commonExecuteExcel(request, response, execlParam);
+    }
+
     public Object querySettleBill(Pageable pageable, PeriodQueryModel param){
         String projectOid = param.getProjectOid();
         if (StringUtils.isBlank(param.getProjectOid())){
@@ -389,6 +469,40 @@ public class OrgOverviewService extends SuperService {
         return ResultContent.buildContent(transactionLogService.aggregate(queryModel).getContent().getPages());
     }
 
+    public void exportSettleBill(HttpServletRequest request, HttpServletResponse response, SettleDetailQueryModel settleDetailQueryModel) {
+        String projectOid = settleDetailQueryModel.getProjectOid();
+        if (StringUtils.isBlank(projectOid)) {
+            projectOid = getCurrentProjectOid();
+        }
+
+        List<String> oidList = organizationUserService.getUserOrgListOids(getCurrentUserId(), projectOid);
+        if (oidList == null || oidList.isEmpty()) {
+            throw new RuntimeException("未加入机构");
+        }
+
+        PayAccount payAccount = payAccountService.getOrgChildren(projectOid, oidList.get(0), PaymentChannelType.WaitSettle);
+
+        GeneralLedgerQueryTransactionLogModel queryModel = new GeneralLedgerQueryTransactionLogModel();
+
+        queryModel.setGeneralLedgerId(new String[]{payAccount.getLedgerId()});
+
+        Map<String, Object> filter = new HashMap<>();
+
+        String createDate = settleDetailQueryModel.getCreateDate();
+        if (StringUtils.isBlank(createDate)) {
+            throw new RuntimeException("createDate不能为空");
+        }
+
+        String formatCreateTime = DateUtils.paresTime(DateUtils.timeToLong(createDate, DateUtils.pattern), DateUtils.pattern);
+
+        filter.put("meta.settleStatus", SettleStatus.Settle);
+        filter.put("meta.settleTime", formatCreateTime);
+        filter.put("transactionType", new Document("$ne", "Settle"));
+        queryModel.setFilter(filter);
+        List<TransactionLogModel> list = transactionLogService.aggregateNotPage(queryModel).getContent().getList();
+        buildBillExcel(request, response, settleDetailQueryModel.getCreateDate(), list);
+    }
+
 
     public Object queryWithdrawBill(Pageable pageable, PeriodQueryModel param){
         String projectOid = param.getProjectOid();
@@ -475,6 +589,41 @@ public class OrgOverviewService extends SuperService {
         return ResultContent.buildContent(transactionLogService.aggregate(queryModel).getContent().getPages());
     }
 
+    public void exportWithdrawBill(HttpServletRequest request, HttpServletResponse response, SettleDetailQueryModel settleDetailQueryModel){
+        String projectOid = settleDetailQueryModel.getProjectOid();
+        if (StringUtils.isBlank(projectOid)) {
+            projectOid = getCurrentProjectOid();
+        }
+
+        List<String> oidList = organizationUserService.getUserOrgListOids(getCurrentUserId(), projectOid);
+        if (oidList==null || oidList.isEmpty()){
+            throw new RuntimeException("未加入机构");
+        }
+
+        PayAccount payAccount = payAccountService.getOrgChildren(projectOid, oidList.get(0), PaymentChannelType.Settle);
+
+        GeneralLedgerQueryTransactionLogModel queryModel = new GeneralLedgerQueryTransactionLogModel();
+
+        queryModel.setGeneralLedgerId(new String[]{payAccount.getLedgerId()});
+
+        Map<String, Object> filter = new HashMap<>();
+
+        String createDate = settleDetailQueryModel.getCreateDate();
+        if (StringUtils.isBlank(createDate)){
+            throw new RuntimeException("createDate不能为空");
+        }
+
+        Long startTime = DateUtils.timeToLong(createDate, DateUtils.pattern);
+
+        queryModel.setStartTime(startTime);
+        queryModel.setEndTime(startTime + 24*60*60*1000L);
+
+        filter.put("transactionType",new Document("$in", List.of(TransactionType.Withdrawal, TransactionType.WithdrawRefund)));
+        queryModel.setFilter(filter);
+        List<TransactionLogModel> list = transactionLogService.aggregateNotPage(queryModel).getContent().getList();
+        buildBillExcel(request, response, settleDetailQueryModel.getCreateDate(), list);
+    }
+
 
     private BigDecimal changeRate(Long todayAmount, Long yesterdayAmount) {
         BigDecimal amountChangeRate = BigDecimal.ZERO;