chore: initialize qiming workspace repository
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.xspaceagi</groupId>
|
||||
<artifactId>app-platform-bill</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>app-platform-bill-infra</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.xspaceagi</groupId>
|
||||
<artifactId>app-platform-bill-domain</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.xspaceagi</groupId>
|
||||
<artifactId>system-sdk</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.xspaceagi</groupId>
|
||||
<artifactId>app-platform-pay-sdk</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.xspaceagi</groupId>
|
||||
<artifactId>app-platform-pricing-sdk</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.xspaceagi.bill.infra.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("bill_daily_revenue")
|
||||
public class BillDailyRevenue {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("_tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String dt;
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
private String status;
|
||||
|
||||
private Date created;
|
||||
|
||||
private Date modified;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.xspaceagi.bill.infra.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("bill_order")
|
||||
public class BillOrder {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("_tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String description;
|
||||
|
||||
private String bizType;
|
||||
|
||||
private String orderStatus;
|
||||
|
||||
private String payStatus;
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
private String extra;
|
||||
|
||||
private Date created;
|
||||
|
||||
private Date modified;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.xspaceagi.bill.infra.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("bill_order_item")
|
||||
public class BillOrderItem {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("_tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
private Long orderId;
|
||||
|
||||
private String targetType;
|
||||
|
||||
private String targetName;
|
||||
|
||||
private Long targetId;
|
||||
|
||||
private BigDecimal price;
|
||||
|
||||
private Integer count;
|
||||
|
||||
private String snapshot;
|
||||
|
||||
private Date created;
|
||||
|
||||
private Date modified;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.xspaceagi.bill.infra.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("bill_resource_stat")
|
||||
public class BillResourceStat {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("_tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String type;
|
||||
|
||||
private String targetType;
|
||||
|
||||
private Long targetId;
|
||||
|
||||
private String dt;
|
||||
|
||||
private Long callCount;
|
||||
|
||||
private Long callFailedCount;
|
||||
|
||||
private BigDecimal creditAmount;
|
||||
|
||||
private BigDecimal feeAmount;
|
||||
|
||||
private Long cacheInputTokens;
|
||||
|
||||
private Long inputTokens;
|
||||
|
||||
private Long outputTokens;
|
||||
|
||||
private String extra;
|
||||
|
||||
private Date created;
|
||||
|
||||
private Date modified;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.xspaceagi.bill.infra.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("bill_revenue_detail")
|
||||
public class BillRevenueDetail {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("_tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String dt;
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
private String type;
|
||||
|
||||
private Long typeId;
|
||||
|
||||
private Long orderId;
|
||||
|
||||
private String targetType;
|
||||
|
||||
private Long targetId;
|
||||
|
||||
private String remark;
|
||||
|
||||
private String bizNo;
|
||||
|
||||
private String extra;
|
||||
|
||||
private Date created;
|
||||
|
||||
private Date modified;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.xspaceagi.bill.infra.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("bill_withdraw_application")
|
||||
public class BillWithdrawApplication {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("_tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
private BigDecimal fee;
|
||||
|
||||
private BigDecimal actualAmount;
|
||||
|
||||
private String status;
|
||||
|
||||
private String rejectReason;
|
||||
|
||||
private String paymentExtra;
|
||||
|
||||
private Date created;
|
||||
|
||||
private Date modified;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.xspaceagi.bill.infra.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("bill_withdraw_config")
|
||||
public class BillWithdrawConfig {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("_tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
private BigDecimal minAmount;
|
||||
|
||||
private Integer monthlyLimit;
|
||||
|
||||
private Integer dailyLimit;
|
||||
|
||||
private String limitMode;
|
||||
|
||||
private Date created;
|
||||
|
||||
private Date modified;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.xspaceagi.bill.infra.dao.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("bill_withdraw_revenue_ref")
|
||||
public class BillWithdrawRevenueRef {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("_tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
private Long applicationId;
|
||||
|
||||
private Long revenueId;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.xspaceagi.bill.infra.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillDailyRevenue;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface BillDailyRevenueMapper extends BaseMapper<BillDailyRevenue> {
|
||||
|
||||
Map<String, Object> selectStatsByUserId(@Param("userId") Long userId,
|
||||
@Param("today") String today,
|
||||
@Param("monthStart") String monthStart);
|
||||
|
||||
List<Map<String, Object>> selectUserRankings(@Param("monthStart") String monthStart,
|
||||
@Param("monthEnd") String monthEnd,
|
||||
@Param("userId") Long userId);
|
||||
|
||||
Long countUserRankings(@Param("monthStart") String monthStart,
|
||||
@Param("monthEnd") String monthEnd,
|
||||
@Param("userId") Long userId);
|
||||
|
||||
Map<String, Object> selectAdminStats(@Param("monthStart") String monthStart,
|
||||
@Param("monthEnd") String monthEnd,
|
||||
@Param("today") String today,
|
||||
@Param("userId") Long userId);
|
||||
|
||||
List<Map<String, Object>> selectAdminDailyRevenues(@Param("monthStart") String monthStart,
|
||||
@Param("monthEnd") String monthEnd,
|
||||
@Param("userId") Long userId,
|
||||
@Param("status") String status,
|
||||
@Param("offset") int offset,
|
||||
@Param("limit") int limit);
|
||||
|
||||
Long countAdminDailyRevenues(@Param("monthStart") String monthStart,
|
||||
@Param("monthEnd") String monthEnd,
|
||||
@Param("userId") Long userId,
|
||||
@Param("status") String status);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.xspaceagi.bill.infra.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillOrderItem;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface BillOrderItemMapper extends BaseMapper<BillOrderItem> {
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.xspaceagi.bill.infra.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillOrder;
|
||||
import com.xspaceagi.bill.sdk.dto.OrderQueryRequest;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface BillOrderMapper extends BaseMapper<BillOrder> {
|
||||
|
||||
List<BillOrder> selectListWithFilters(@Param("query") OrderQueryRequest query,
|
||||
@Param("offset") int offset,
|
||||
@Param("limit") int limit);
|
||||
|
||||
Long countWithFilters(@Param("query") OrderQueryRequest query);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.xspaceagi.bill.infra.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillResourceStat;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface BillResourceStatMapper extends BaseMapper<BillResourceStat> {
|
||||
|
||||
List<Map<String, Object>> selectSummary(@Param("tenantId") Long tenantId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("dtStart") String dtStart,
|
||||
@Param("dtEnd") String dtEnd);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.xspaceagi.bill.infra.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillRevenueDetail;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface BillRevenueDetailMapper extends BaseMapper<BillRevenueDetail> {
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.xspaceagi.bill.infra.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillWithdrawApplication;
|
||||
import com.xspaceagi.bill.sdk.dto.WithdrawQueryRequest;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface BillWithdrawApplicationMapper extends BaseMapper<BillWithdrawApplication> {
|
||||
|
||||
List<BillWithdrawApplication> selectListWithFilters(@Param("query") WithdrawQueryRequest query,
|
||||
@Param("offset") int offset,
|
||||
@Param("limit") int limit);
|
||||
|
||||
Long countWithFilters(@Param("query") WithdrawQueryRequest query);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.xspaceagi.bill.infra.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillWithdrawConfig;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface BillWithdrawConfigMapper extends BaseMapper<BillWithdrawConfig> {
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.xspaceagi.bill.infra.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillWithdrawRevenueRef;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface BillWithdrawRevenueRefMapper extends BaseMapper<BillWithdrawRevenueRef> {
|
||||
|
||||
@Select("SELECT * FROM bill_withdraw_revenue_ref WHERE application_id = #{applicationId}")
|
||||
List<BillWithdrawRevenueRef> selectByApplicationId(@Param("applicationId") Long applicationId);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.xspaceagi.bill.infra.dao.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillDailyRevenue;
|
||||
|
||||
public interface IBillDailyRevenueService extends IService<BillDailyRevenue> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.xspaceagi.bill.infra.dao.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillOrderItem;
|
||||
|
||||
public interface IBillOrderItemService extends IService<BillOrderItem> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.xspaceagi.bill.infra.dao.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillOrder;
|
||||
|
||||
public interface IBillOrderService extends IService<BillOrder> {
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.xspaceagi.bill.infra.dao.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillResourceStat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IBillResourceStatService extends IService<BillResourceStat> {
|
||||
|
||||
/**
|
||||
* 追加统计数据(按天),同一维度已存在则累加,否则新增
|
||||
*/
|
||||
void appendStat(BillResourceStat stat);
|
||||
|
||||
/**
|
||||
* 按条件查询统计数据
|
||||
*/
|
||||
List<BillResourceStat> queryStats(Long tenantId, Long userId, String type,
|
||||
String targetType, Long targetId,
|
||||
String dtStart, String dtEnd,
|
||||
int offset, int limit);
|
||||
|
||||
Long countStats(Long tenantId, Long userId, String type,
|
||||
String targetType, Long targetId,
|
||||
String dtStart, String dtEnd);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.xspaceagi.bill.infra.dao.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillRevenueDetail;
|
||||
|
||||
public interface IBillRevenueDetailService extends IService<BillRevenueDetail> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.xspaceagi.bill.infra.dao.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillWithdrawApplication;
|
||||
|
||||
public interface IBillWithdrawApplicationService extends IService<BillWithdrawApplication> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.xspaceagi.bill.infra.dao.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillWithdrawConfig;
|
||||
|
||||
public interface IBillWithdrawConfigService extends IService<BillWithdrawConfig> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.xspaceagi.bill.infra.dao.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillWithdrawRevenueRef;
|
||||
|
||||
public interface IBillWithdrawRevenueRefService extends IService<BillWithdrawRevenueRef> {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.xspaceagi.bill.infra.dao.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillDailyRevenue;
|
||||
import com.xspaceagi.bill.infra.dao.mapper.BillDailyRevenueMapper;
|
||||
import com.xspaceagi.bill.infra.dao.service.IBillDailyRevenueService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class BillDailyRevenueServiceImpl extends ServiceImpl<BillDailyRevenueMapper, BillDailyRevenue> implements IBillDailyRevenueService {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.xspaceagi.bill.infra.dao.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillOrderItem;
|
||||
import com.xspaceagi.bill.infra.dao.mapper.BillOrderItemMapper;
|
||||
import com.xspaceagi.bill.infra.dao.service.IBillOrderItemService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class BillOrderItemServiceImpl extends ServiceImpl<BillOrderItemMapper, BillOrderItem> implements IBillOrderItemService {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.xspaceagi.bill.infra.dao.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillOrder;
|
||||
import com.xspaceagi.bill.infra.dao.mapper.BillOrderMapper;
|
||||
import com.xspaceagi.bill.infra.dao.service.IBillOrderService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class BillOrderServiceImpl extends ServiceImpl<BillOrderMapper, BillOrder> implements IBillOrderService {
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.xspaceagi.bill.infra.dao.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillResourceStat;
|
||||
import com.xspaceagi.bill.infra.dao.mapper.BillResourceStatMapper;
|
||||
import com.xspaceagi.bill.infra.dao.service.IBillResourceStatService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class BillResourceStatServiceImpl extends ServiceImpl<BillResourceStatMapper, BillResourceStat> implements IBillResourceStatService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void appendStat(BillResourceStat stat) {
|
||||
BillResourceStat existing = lambdaQuery()
|
||||
.eq(BillResourceStat::getTenantId, stat.getTenantId())
|
||||
.eq(BillResourceStat::getUserId, stat.getUserId())
|
||||
.eq(BillResourceStat::getType, stat.getType())
|
||||
.eq(BillResourceStat::getTargetType, stat.getTargetType())
|
||||
.eq(BillResourceStat::getTargetId, stat.getTargetId())
|
||||
.eq(BillResourceStat::getDt, stat.getDt())
|
||||
.one();
|
||||
if (existing == null) {
|
||||
stat.setCreated(new Date());
|
||||
save(stat);
|
||||
} else {
|
||||
existing.setCallCount(safeAddLong(existing.getCallCount(), stat.getCallCount()));
|
||||
existing.setCallFailedCount(safeAddLong(existing.getCallFailedCount(), stat.getCallFailedCount()));
|
||||
existing.setCreditAmount(safeAdd(existing.getCreditAmount(), stat.getCreditAmount()));
|
||||
existing.setFeeAmount(safeAdd(existing.getFeeAmount(), stat.getFeeAmount()));
|
||||
existing.setCacheInputTokens(safeAddLong(existing.getCacheInputTokens(), stat.getCacheInputTokens()));
|
||||
existing.setInputTokens(safeAddLong(existing.getInputTokens(), stat.getInputTokens()));
|
||||
existing.setOutputTokens(safeAddLong(existing.getOutputTokens(), stat.getOutputTokens()));
|
||||
existing.setModified(new Date());
|
||||
updateById(existing);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BillResourceStat> queryStats(Long tenantId, Long userId, String type,
|
||||
String targetType, Long targetId,
|
||||
String dtStart, String dtEnd,
|
||||
int offset, int limit) {
|
||||
return lambdaQuery()
|
||||
.eq(tenantId != null, BillResourceStat::getTenantId, tenantId)
|
||||
.eq(userId != null, BillResourceStat::getUserId, userId)
|
||||
.eq(type != null, BillResourceStat::getType, type)
|
||||
.eq(targetType != null, BillResourceStat::getTargetType, targetType)
|
||||
.eq(targetId != null, BillResourceStat::getTargetId, targetId)
|
||||
.ge(dtStart != null, BillResourceStat::getDt, dtStart)
|
||||
.le(dtEnd != null, BillResourceStat::getDt, dtEnd)
|
||||
.orderByDesc(BillResourceStat::getDt)
|
||||
.last("LIMIT " + offset + ", " + limit)
|
||||
.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countStats(Long tenantId, Long userId, String type,
|
||||
String targetType, Long targetId,
|
||||
String dtStart, String dtEnd) {
|
||||
return lambdaQuery()
|
||||
.eq(tenantId != null, BillResourceStat::getTenantId, tenantId)
|
||||
.eq(userId != null, BillResourceStat::getUserId, userId)
|
||||
.eq(type != null, BillResourceStat::getType, type)
|
||||
.eq(targetType != null, BillResourceStat::getTargetType, targetType)
|
||||
.eq(targetId != null, BillResourceStat::getTargetId, targetId)
|
||||
.ge(dtStart != null, BillResourceStat::getDt, dtStart)
|
||||
.le(dtEnd != null, BillResourceStat::getDt, dtEnd)
|
||||
.count();
|
||||
}
|
||||
|
||||
private BigDecimal safeAdd(BigDecimal a, BigDecimal b) {
|
||||
if (a == null && b == null) return BigDecimal.ZERO;
|
||||
if (a == null) return b;
|
||||
if (b == null) return a;
|
||||
return a.add(b);
|
||||
}
|
||||
|
||||
private Long safeAddLong(Long a, Long b) {
|
||||
if (a == null && b == null) return 0L;
|
||||
if (a == null) return b;
|
||||
if (b == null) return a;
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.xspaceagi.bill.infra.dao.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillRevenueDetail;
|
||||
import com.xspaceagi.bill.infra.dao.mapper.BillRevenueDetailMapper;
|
||||
import com.xspaceagi.bill.infra.dao.service.IBillRevenueDetailService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class BillRevenueDetailServiceImpl extends ServiceImpl<BillRevenueDetailMapper, BillRevenueDetail> implements IBillRevenueDetailService {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.xspaceagi.bill.infra.dao.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillWithdrawApplication;
|
||||
import com.xspaceagi.bill.infra.dao.mapper.BillWithdrawApplicationMapper;
|
||||
import com.xspaceagi.bill.infra.dao.service.IBillWithdrawApplicationService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class BillWithdrawApplicationServiceImpl extends ServiceImpl<BillWithdrawApplicationMapper, BillWithdrawApplication> implements IBillWithdrawApplicationService {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.xspaceagi.bill.infra.dao.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillWithdrawConfig;
|
||||
import com.xspaceagi.bill.infra.dao.mapper.BillWithdrawConfigMapper;
|
||||
import com.xspaceagi.bill.infra.dao.service.IBillWithdrawConfigService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class BillWithdrawConfigServiceImpl extends ServiceImpl<BillWithdrawConfigMapper, BillWithdrawConfig> implements IBillWithdrawConfigService {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.xspaceagi.bill.infra.dao.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xspaceagi.bill.infra.dao.entity.BillWithdrawRevenueRef;
|
||||
import com.xspaceagi.bill.infra.dao.mapper.BillWithdrawRevenueRefMapper;
|
||||
import com.xspaceagi.bill.infra.dao.service.IBillWithdrawRevenueRefService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class BillWithdrawRevenueRefServiceImpl extends ServiceImpl<BillWithdrawRevenueRefMapper, BillWithdrawRevenueRef> implements IBillWithdrawRevenueRefService {
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.xspaceagi.bill.infra.dao.mapper.BillDailyRevenueMapper">
|
||||
|
||||
<select id="selectStatsByUserId" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
COALESCE(SUM(amount), 0) AS totalRevenue,
|
||||
COALESCE(SUM(CASE WHEN dt = #{today} THEN amount ELSE 0 END), 0) AS todayRevenue,
|
||||
COALESCE(SUM(CASE WHEN dt >= #{monthStart} THEN amount ELSE 0 END), 0) AS monthRevenue,
|
||||
COALESCE(SUM(CASE WHEN status = 'PENDING' THEN amount ELSE 0 END), 0) AS unsettledAmount,
|
||||
COALESCE(SUM(CASE WHEN status = 'PENDING' AND dt < #{today} THEN amount ELSE 0 END), 0) AS pendingAmount,
|
||||
COALESCE(SUM(CASE WHEN status = 'SETTLED' THEN amount ELSE 0 END), 0) AS settledAmount
|
||||
FROM bill_daily_revenue
|
||||
WHERE user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectUserRankings" resultType="java.util.HashMap">
|
||||
SELECT user_id AS userId, SUM(amount) AS amount
|
||||
FROM bill_daily_revenue
|
||||
WHERE dt >= #{monthStart} AND dt <= #{monthEnd}
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
GROUP BY user_id
|
||||
ORDER BY amount DESC
|
||||
</select>
|
||||
|
||||
<select id="countUserRankings" resultType="java.lang.Long">
|
||||
SELECT COUNT(DISTINCT user_id)
|
||||
FROM bill_daily_revenue
|
||||
WHERE dt >= #{monthStart} AND dt <= #{monthEnd}
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
LIMIT 20
|
||||
</select>
|
||||
|
||||
<select id="selectAdminStats" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
COALESCE(SUM(amount), 0) AS totalRevenue,
|
||||
COALESCE(SUM(CASE WHEN dt = #{today} THEN amount ELSE 0 END), 0) AS todayRevenue,
|
||||
COALESCE(SUM(CASE WHEN dt >= #{monthStart} AND dt <= #{monthEnd} THEN amount ELSE 0 END), 0) AS monthRevenue,
|
||||
COALESCE(SUM(CASE WHEN status = 'PENDING' THEN amount ELSE 0 END), 0) AS pendingAmount,
|
||||
COALESCE(SUM(CASE WHEN status = 'SETTLED' THEN amount ELSE 0 END), 0) AS settledAmount
|
||||
FROM bill_daily_revenue
|
||||
WHERE dt >= #{monthStart} AND dt <= #{monthEnd}
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectAdminDailyRevenues" resultType="java.util.HashMap">
|
||||
SELECT dt, user_id, amount, status
|
||||
FROM bill_daily_revenue
|
||||
WHERE dt >= #{monthStart} AND dt <= #{monthEnd}
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
ORDER BY dt DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<select id="countAdminDailyRevenues" resultType="java.lang.Long">
|
||||
SELECT COUNT(*)
|
||||
FROM bill_daily_revenue
|
||||
WHERE dt >= #{monthStart} AND dt <= #{monthEnd}
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.xspaceagi.bill.infra.dao.mapper.BillOrderMapper">
|
||||
|
||||
<select id="selectListWithFilters"
|
||||
resultType="com.xspaceagi.bill.infra.dao.entity.BillOrder">
|
||||
SELECT * FROM bill_order
|
||||
<where>
|
||||
<if test="query.orderId != null">AND id = #{query.orderId}</if>
|
||||
<if test="query.userId != null">AND user_id = #{query.userId}</if>
|
||||
<if test="query.bizType != null">AND biz_type = #{query.bizType.code}</if>
|
||||
<if test="query.orderStatus != null and query.orderStatus != ''">AND order_status = #{query.orderStatus}</if>
|
||||
<if test="query.payStatus != null and query.payStatus != ''">AND pay_status = #{query.payStatus}</if>
|
||||
<if test="query.startTime != null and query.startTime != ''">AND created >= #{query.startTime}</if>
|
||||
<if test="query.endTime != null and query.endTime != ''">AND created <= #{query.endTime}</if>
|
||||
</where>
|
||||
ORDER BY created DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<select id="countWithFilters" resultType="java.lang.Long">
|
||||
SELECT COUNT(*) FROM bill_order
|
||||
<where>
|
||||
<if test="query.orderId != null">AND id = #{query.orderId}</if>
|
||||
<if test="query.userId != null">AND user_id = #{query.userId}</if>
|
||||
<if test="query.bizType != null">AND biz_type = #{query.bizType.code}</if>
|
||||
<if test="query.orderStatus != null and query.orderStatus != ''">AND order_status = #{query.orderStatus}</if>
|
||||
<if test="query.payStatus != null and query.payStatus != ''">AND pay_status = #{query.payStatus}</if>
|
||||
<if test="query.startTime != null and query.startTime != ''">AND created >= #{query.startTime}</if>
|
||||
<if test="query.endTime != null and query.endTime != ''">AND created <= #{query.endTime}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.xspaceagi.bill.infra.dao.mapper.BillResourceStatMapper">
|
||||
|
||||
<select id="selectSummary" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
type,
|
||||
COALESCE(SUM(input_tokens), 0) AS totalInputTokens,
|
||||
COALESCE(SUM(output_tokens), 0) AS totalOutputTokens,
|
||||
COALESCE(SUM(cache_input_tokens), 0) AS totalCacheInputTokens,
|
||||
COUNT(DISTINCT CASE WHEN target_type IN ('Plugin', 'Workflow') THEN target_id END) AS toolCount,
|
||||
COALESCE(SUM(CASE WHEN target_type IN ('Plugin', 'Workflow') THEN call_count ELSE 0 END), 0) AS toolCallCount,
|
||||
COUNT(DISTINCT CASE WHEN target_type = 'Agent' THEN target_id END) AS agentCount,
|
||||
COALESCE(SUM(CASE WHEN target_type = 'Agent' THEN call_count ELSE 0 END), 0) AS agentCallCount,
|
||||
COALESCE(SUM(CASE WHEN target_type = 'Model' THEN call_count ELSE 0 END), 0) AS modelCallCount,
|
||||
COALESCE(SUM(CASE WHEN target_type = 'Model' THEN call_failed_count ELSE 0 END), 0) AS failedModelCallCount,
|
||||
COALESCE(SUM(CASE WHEN target_type IN ('Plugin', 'Workflow') THEN call_failed_count ELSE 0 END), 0) AS failedToolCallCount,
|
||||
COALESCE(SUM(CASE WHEN target_type = 'Agent' THEN call_failed_count ELSE 0 END), 0) AS failedAgentCallCount,
|
||||
COALESCE(SUM(credit_amount), 0) AS totalCreditAmount,
|
||||
COALESCE(SUM(fee_amount), 0) AS totalAmount
|
||||
FROM bill_resource_stat
|
||||
WHERE 1 = 1
|
||||
<if test="tenantId != null">
|
||||
AND _tenant_id = #{tenantId}
|
||||
</if>
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="dtStart != null">
|
||||
AND dt >= #{dtStart}
|
||||
</if>
|
||||
<if test="dtEnd != null">
|
||||
AND dt <= #{dtEnd}
|
||||
</if>
|
||||
GROUP BY type
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.xspaceagi.bill.infra.dao.mapper.BillWithdrawApplicationMapper">
|
||||
|
||||
<select id="selectListWithFilters"
|
||||
resultType="com.xspaceagi.bill.infra.dao.entity.BillWithdrawApplication">
|
||||
SELECT * FROM bill_withdraw_application
|
||||
<where>
|
||||
<if test="query.userId != null">AND user_id = #{query.userId}</if>
|
||||
<if test="query.status != null">AND status = #{query.status.code}</if>
|
||||
</where>
|
||||
ORDER BY created DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<select id="countWithFilters" resultType="java.lang.Long">
|
||||
SELECT COUNT(*) FROM bill_withdraw_application
|
||||
<where>
|
||||
<if test="query.userId != null">AND user_id = #{query.userId}</if>
|
||||
<if test="query.status != null">AND status = #{query.status.code}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user