excel导出

This commit is contained in:
lzh 2025-10-16 16:37:06 +08:00
parent a989dae45a
commit 8116303f05
5 changed files with 2270 additions and 1242 deletions

File diff suppressed because it is too large Load Diff

View File

@ -370,6 +370,22 @@ func (this *GetBundleBalanceReq) Validate() error {
func (this *BundleBalanceItem) Validate() error {
return nil
}
func (this *BundleBalanceExportItem) Validate() error {
return nil
}
func (this *BundleBalanceExportReq) Validate() error {
return nil
}
func (this *BundleBalanceExportResp) Validate() error {
for _, item := range this.Data {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Data", err)
}
}
}
return nil
}
func (this *GetBundleBalanceListResp) Validate() error {
for _, item := range this.Data {
if item != nil {

View File

@ -70,6 +70,7 @@ type BundleClient interface {
CreateBundleBalance(ctx context.Context, in *CreateBundleBalanceReq, opts ...grpc_go.CallOption) (*CreateBundleBalanceResp, common.ErrorWithAttachment)
AddBundleBalance(ctx context.Context, in *AddBundleBalanceReq, opts ...grpc_go.CallOption) (*AddBundleBalanceResp, common.ErrorWithAttachment)
BundleActivate(ctx context.Context, in *BundleActivateReq, opts ...grpc_go.CallOption) (*BundleActivateResp, common.ErrorWithAttachment)
BundleBalanceExport(ctx context.Context, in *BundleBalanceExportReq, opts ...grpc_go.CallOption) (*BundleBalanceExportResp, common.ErrorWithAttachment)
// 使用记录
GetUsedRecordList(ctx context.Context, in *GetUsedRecordListReq, opts ...grpc_go.CallOption) (*GetUsedRecordListResp, common.ErrorWithAttachment)
GetImageWorkDetail(ctx context.Context, in *GetImageWorkDetailReq, opts ...grpc_go.CallOption) (*GetImageWorkDetailResp, common.ErrorWithAttachment)
@ -140,6 +141,7 @@ type BundleClientImpl struct {
CreateBundleBalance func(ctx context.Context, in *CreateBundleBalanceReq) (*CreateBundleBalanceResp, error)
AddBundleBalance func(ctx context.Context, in *AddBundleBalanceReq) (*AddBundleBalanceResp, error)
BundleActivate func(ctx context.Context, in *BundleActivateReq) (*BundleActivateResp, error)
BundleBalanceExport func(ctx context.Context, in *BundleBalanceExportReq) (*BundleBalanceExportResp, error)
GetUsedRecordList func(ctx context.Context, in *GetUsedRecordListReq) (*GetUsedRecordListResp, error)
GetImageWorkDetail func(ctx context.Context, in *GetImageWorkDetailReq) (*GetImageWorkDetailResp, error)
GetVedioWorkDetail func(ctx context.Context, in *GetVedioWorkDetailReq) (*GetVedioeWorkDetailResp, error)
@ -408,6 +410,12 @@ func (c *bundleClient) BundleActivate(ctx context.Context, in *BundleActivateReq
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/BundleActivate", in, out)
}
func (c *bundleClient) BundleBalanceExport(ctx context.Context, in *BundleBalanceExportReq, opts ...grpc_go.CallOption) (*BundleBalanceExportResp, common.ErrorWithAttachment) {
out := new(BundleBalanceExportResp)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/BundleBalanceExport", in, out)
}
func (c *bundleClient) GetUsedRecordList(ctx context.Context, in *GetUsedRecordListReq, opts ...grpc_go.CallOption) (*GetUsedRecordListResp, common.ErrorWithAttachment) {
out := new(GetUsedRecordListResp)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
@ -574,6 +582,7 @@ type BundleServer interface {
CreateBundleBalance(context.Context, *CreateBundleBalanceReq) (*CreateBundleBalanceResp, error)
AddBundleBalance(context.Context, *AddBundleBalanceReq) (*AddBundleBalanceResp, error)
BundleActivate(context.Context, *BundleActivateReq) (*BundleActivateResp, error)
BundleBalanceExport(context.Context, *BundleBalanceExportReq) (*BundleBalanceExportResp, error)
// 使用记录
GetUsedRecordList(context.Context, *GetUsedRecordListReq) (*GetUsedRecordListResp, error)
GetImageWorkDetail(context.Context, *GetImageWorkDetailReq) (*GetImageWorkDetailResp, error)
@ -723,6 +732,9 @@ func (UnimplementedBundleServer) AddBundleBalance(context.Context, *AddBundleBal
func (UnimplementedBundleServer) BundleActivate(context.Context, *BundleActivateReq) (*BundleActivateResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method BundleActivate not implemented")
}
func (UnimplementedBundleServer) BundleBalanceExport(context.Context, *BundleBalanceExportReq) (*BundleBalanceExportResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method BundleBalanceExport not implemented")
}
func (UnimplementedBundleServer) GetUsedRecordList(context.Context, *GetUsedRecordListReq) (*GetUsedRecordListResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetUsedRecordList not implemented")
}
@ -1942,6 +1954,35 @@ func _Bundle_BundleActivate_Handler(srv interface{}, ctx context.Context, dec fu
return interceptor(ctx, in, info, handler)
}
func _Bundle_BundleBalanceExport_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(BundleBalanceExportReq)
if err := dec(in); err != nil {
return nil, err
}
base := srv.(dubbo3.Dubbo3GrpcService)
args := []interface{}{}
args = append(args, in)
md, _ := metadata.FromIncomingContext(ctx)
invAttachment := make(map[string]interface{}, len(md))
for k, v := range md {
invAttachment[k] = v
}
invo := invocation.NewRPCInvocation("BundleBalanceExport", args, invAttachment)
if interceptor == nil {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
info := &grpc_go.UnaryServerInfo{
Server: srv,
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
return interceptor(ctx, in, info, handler)
}
func _Bundle_GetUsedRecordList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(GetUsedRecordListReq)
if err := dec(in); err != nil {
@ -2685,6 +2726,10 @@ var Bundle_ServiceDesc = grpc_go.ServiceDesc{
MethodName: "BundleActivate",
Handler: _Bundle_BundleActivate_Handler,
},
{
MethodName: "BundleBalanceExport",
Handler: _Bundle_BundleBalanceExport_Handler,
},
{
MethodName: "GetUsedRecordList",
Handler: _Bundle_GetUsedRecordList_Handler,

View File

@ -34,6 +34,7 @@ func BundleRouter(r *gin.RouterGroup) {
bundleBalance.POST("list", bundle.GetBundleBalance)
bundleBalance.POST("used-record", bundle.GetUsedRecordList)
bundleBalance.POST("activate", bundle.BundleActivate)
bundleBalance.POST("export", bundle.BundleExport)
}
}
bundleClientRouteV2 := bundleRoute.Group("system/v2")

View File

@ -3,15 +3,20 @@ package bundle
import (
"context"
"errors"
"fmt"
"fonchain-fiee/api/bundle"
"fonchain-fiee/api/cast"
"fonchain-fiee/pkg/service"
"os"
"reflect"
"strconv"
"time"
bundleModel "fonchain-fiee/pkg/model/bundle"
"fonchain-fiee/pkg/model/login"
"github.com/gin-gonic/gin"
"github.com/xuri/excelize/v2"
)
func BundleExtend(c *gin.Context) {
@ -262,3 +267,103 @@ func BundleActivate(ctx *gin.Context) {
}
service.Success(ctx, res)
}
func BundleExport(ctx *gin.Context) {
var req bundle.BundleBalanceExportReq
if err := ctx.ShouldBindJSON(&req); err != nil {
service.Error(ctx, err)
return
}
res, err := service.BundleProvider.BundleBalanceExport(context.Background(), &req)
if err != nil {
service.Error(ctx, err)
return
}
f := excelize.NewFile()
sheet := "Sheet1"
f.NewSheet(sheet)
// 写入表头
headers := []string{
"所属月份",
"用户编号",
"名字",
"手机号",
"支付时间",
"套餐金额",
"增值服务金额",
"支付金额",
"币种",
"手续费",
"套餐视频单价",
"增值视频单价",
"套餐账号总数",
"增值账号总数",
"套餐账号使用数",
"增值账号使用数",
"当前可用套餐视频数",
"当前可用增值视频数",
"当前已用套餐视频数",
"当前已用增值视频数",
"当前作废套餐视频数",
"当前作废增值视频数",
"当月新增套餐视频数",
"当月新增增值视频数",
"当月作废套餐视频数",
"当月作废增值视频数",
"当前可用套餐图文数",
"当前可用增值图文数",
"当前已用套餐图文数",
"当前已用增值图文数",
"当前作废套餐图文数",
"当前作废增值图文数",
"当月新增套餐图文数",
"当月新增增值图文数",
"当月作废套餐图文数",
"当月作废增值图文数",
"当前可用套餐数据分析数",
"当前可用增值数据分析数",
"当前已用套餐数据分析数",
"当前已用增值数据分析数",
"当前作废套餐数据分析数",
"当前作废增值数据分析数",
"当月新增套餐数据分析数",
"当月新增增值数据分析数",
"当月作废套餐数据分析数",
"当月作废增值数据分析数",
"当月手动扩展账号新增数",
"当月手动扩展视频新增数",
"当月手动扩展图文新增数",
"当月手动扩展数据分析新增数",
"当月新增手动扩展时长(天)",
"当月手动扩展账号使用数",
"当月手动扩展视频使用数",
"当月手动扩展图文使用数",
"当月手动扩展数据分析使用数",
}
for i, h := range headers {
cell, _ := excelize.CoordinatesToCellName(i+1, 1)
f.SetCellValue(sheet, cell, h)
}
// 写入数据
for r, item := range res.Data {
row := r + 2
v := reflect.ValueOf(item)
for c := 0; c < v.NumField(); c++ {
cell, _ := excelize.CoordinatesToCellName(c+1, row)
f.SetCellValue(sheet, cell, v.Field(c).Interface())
}
}
path := fmt.Sprintf("%s/%d/%s月余量导出.xlsx", os.TempDir(), time.Now().UnixMilli(), req.Month)
// 保存文件
if err := f.SaveAs(path); err != nil {
fmt.Println("保存失败:", err)
return
}
defer os.Remove(path)
ctx.File(path)
}