add data export

This commit is contained in:
Timi
2026-10-25 01:17:24 +08:00
parent c20f0b6f45
commit f3eddc69af
34 changed files with 1890 additions and 76 deletions
@@ -0,0 +1,156 @@
<?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.imyeyu.api.modules.gao.mapper.GaoDataExportMapper">
<sql id="exportWhere">
`${scopeColumn}` = #{scopeValue}
<if test="hasDeletedAt">
AND `deleted_at` IS NULL
</if>
<if test="requiredBizType != null">
AND `biz_type` = #{requiredBizType}
</if>
<if test="beginAt != null and timeColumn != null">
AND `${timeColumn}` &gt;= #{beginAt}
</if>
<if test="endAt != null and timeColumn != null">
AND `${timeColumn}` &lt;= #{endAt}
</if>
</sql>
<select id="countRows" resultType="long">
SELECT COUNT(*)
FROM `${tableName}`
WHERE <include refid="exportWhere"/>
</select>
<select id="selectRows" resultType="map">
SELECT *
FROM `${tableName}`
WHERE <include refid="exportWhere"/>
ORDER BY `${timeColumn}` ASC, `id` ASC
LIMIT #{offset}, #{limit}
</select>
<select id="selectChildren" resultType="map">
SELECT *
FROM `${tableName}`
WHERE `${foreignKey}` IN
<foreach collection="parentIdList" item="parentId" open="(" separator="," close=")">
#{parentId}
</foreach>
<if test="hasDeletedAt">
AND `deleted_at` IS NULL
</if>
ORDER BY `${foreignKey}` ASC, `created_at` ASC
</select>
<select id="countChildren" resultType="long">
SELECT COUNT(*)
FROM `${childTableName}` `c`
INNER JOIN `${tableName}` `r` ON `r`.`id` = `c`.`${childForeignKey}`
WHERE
1 = 1
<if test="hasDeletedAt">
AND `r`.`deleted_at` IS NULL
</if>
AND `r`.`${scopeColumn}` = #{scopeValue}
<if test="requiredBizType != null">
AND `r`.`biz_type` = #{requiredBizType}
</if>
<if test="beginAt != null and timeColumn != null">
AND `r`.`${timeColumn}` &gt;= #{beginAt}
</if>
<if test="endAt != null and timeColumn != null">
AND `r`.`${timeColumn}` &lt;= #{endAt}
</if>
<if test="childHasDeletedAt">
AND `c`.`deleted_at` IS NULL
</if>
</select>
<select id="selectChildrenByScope" resultType="map">
SELECT `c`.*
FROM `${childTableName}` `c`
INNER JOIN `${tableName}` `r` ON `r`.`id` = `c`.`${childForeignKey}`
WHERE
1 = 1
<if test="hasDeletedAt">
AND `r`.`deleted_at` IS NULL
</if>
AND `r`.`${scopeColumn}` = #{scopeValue}
<if test="requiredBizType != null">
AND `r`.`biz_type` = #{requiredBizType}
</if>
<if test="beginAt != null and timeColumn != null">
AND `r`.`${timeColumn}` &gt;= #{beginAt}
</if>
<if test="endAt != null and timeColumn != null">
AND `r`.`${timeColumn}` &lt;= #{endAt}
</if>
<if test="childHasDeletedAt">
AND `c`.`deleted_at` IS NULL
</if>
ORDER BY `c`.`created_at` ASC
LIMIT #{limit}
</select>
<select id="statAttachment" resultType="map">
SELECT
COUNT(`a`.`id`) AS `attachmentCount`,
COALESCE(SUM(`a`.`size`), 0) AS `attachmentSize`
FROM `attachment` `a`
INNER JOIN `${tableName}` `r` ON `r`.`id` = `a`.`biz_id`
WHERE
`a`.`deleted_at` IS NULL
AND (`a`.`destroy_at` IS NULL OR `a`.`destroy_at` &gt; UNIX_TIMESTAMP() * 1000)
<if test="hasDeletedAt">
AND `r`.`deleted_at` IS NULL
</if>
AND `r`.`${scopeColumn}` = #{scopeValue}
<if test="requiredBizType != null">
AND `r`.`biz_type` = #{requiredBizType}
</if>
<if test="beginAt != null and timeColumn != null">
AND `r`.`${timeColumn}` &gt;= #{beginAt}
</if>
<if test="endAt != null and timeColumn != null">
AND `r`.`${timeColumn}` &lt;= #{endAt}
</if>
AND `a`.`biz_type` IN
<foreach collection="attachmentBizTypeList" item="bizType" open="(" separator="," close=")">
#{bizType}
</foreach>
</select>
<select id="statChildAttachment" resultType="map">
SELECT
COUNT(`a`.`id`) AS `attachmentCount`,
COALESCE(SUM(`a`.`size`), 0) AS `attachmentSize`
FROM `attachment` `a`
INNER JOIN `${childTableName}` `c` ON `c`.`id` = `a`.`biz_id`
INNER JOIN `${tableName}` `r` ON `r`.`id` = `c`.`${childForeignKey}`
WHERE
`a`.`deleted_at` IS NULL
AND (`a`.`destroy_at` IS NULL OR `a`.`destroy_at` &gt; UNIX_TIMESTAMP() * 1000)
<if test="hasDeletedAt">
AND `r`.`deleted_at` IS NULL
</if>
<if test="childHasDeletedAt">
AND `c`.`deleted_at` IS NULL
</if>
AND `r`.`${scopeColumn}` = #{scopeValue}
<if test="requiredBizType != null">
AND `r`.`biz_type` = #{requiredBizType}
</if>
<if test="beginAt != null and timeColumn != null">
AND `r`.`${timeColumn}` &gt;= #{beginAt}
</if>
<if test="endAt != null and timeColumn != null">
AND `r`.`${timeColumn}` &lt;= #{endAt}
</if>
AND `a`.`biz_type` IN
<foreach collection="attachmentBizTypeList" item="bizType" open="(" separator="," close=")">
#{bizType}
</foreach>
</select>
</mapper>
@@ -11,6 +11,10 @@
AND o.`purchased_at` &gt;= #{beginAt}
AND o.`purchased_at` &lt;= #{endAt}
</sql>
<sql id="operatingOrderFilter">
<include refid="orderFilter"/>
<if test="status == null">AND o.`status` &lt;&gt; 'CANCELLED'</if>
</sql>
<select id="selectDaily" resultType="com.imyeyu.api.modules.gao.vo.GaoSalesOrderDailyStatView">
SELECT
@@ -23,7 +27,7 @@
COALESCE(SUM(o.`paid_amount` - o.`refunded_amount`), 0) AS `netPaidAmount`
FROM `gao_sales_order` o
WHERE 1 = 1
<include refid="orderFilter"/>
<include refid="operatingOrderFilter"/>
GROUP BY DATE_FORMAT(FROM_UNIXTIME(o.`purchased_at` / 1000), '%Y%m%d')
ORDER BY `dateValue` ASC
</select>
@@ -38,7 +42,7 @@
COALESCE(SUM(o.`paid_amount` - o.`refunded_amount`), 0) AS `netPaidAmount`
FROM `gao_sales_order` o
WHERE 1 = 1
<include refid="orderFilter"/>
<include refid="operatingOrderFilter"/>
GROUP BY o.`order_type`
ORDER BY o.`order_type` ASC
</select>
@@ -50,11 +54,11 @@
COALESCE(SUM(o.`sale_amount`), 0) AS `saleAmount`,
COALESCE(SUM(o.`paid_amount`), 0) AS `paidAmount`,
COALESCE(SUM(o.`pending_paid_amount`), 0) AS `pendingPaidAmount`,
COALESCE(SUM(o.`sale_amount` - o.`paid_amount`), 0) AS `unpaidAmount`,
COALESCE(SUM(GREATEST(o.`sale_amount` - o.`paid_amount`, 0)), 0) AS `unpaidAmount`,
COALESCE(SUM(o.`refunded_amount`), 0) AS `refundedAmount`
FROM `gao_sales_order` o
WHERE 1 = 1
<include refid="orderFilter"/>
<include refid="operatingOrderFilter"/>
GROUP BY o.`payment_status`
ORDER BY o.`payment_status` ASC
</select>
@@ -72,8 +76,7 @@
FROM `gao_sales_order` o
LEFT JOIN `gao_customer` c ON c.`id` = o.`customer_id` AND c.`deleted_at` IS NULL
WHERE 1 = 1
<include refid="orderFilter"/>
<if test="status == null">AND o.`status` &lt;&gt; 'CANCELLED'</if>
<include refid="operatingOrderFilter"/>
GROUP BY o.`customer_id`, c.`code`, c.`name`
ORDER BY `netPaidAmount` DESC, `orderCount` DESC, o.`customer_id` ASC
LIMIT #{topN}
@@ -167,12 +170,12 @@
COALESCE(SUM(o.`sale_amount`), 0) AS `saleAmount`,
COALESCE(SUM(o.`paid_amount`), 0) AS `paidAmount`,
COALESCE(SUM(o.`pending_paid_amount`), 0) AS `pendingPaidAmount`,
COALESCE(SUM(o.`sale_amount` - o.`paid_amount`), 0) AS `unpaidAmount`,
COALESCE(SUM(GREATEST(o.`sale_amount` - o.`paid_amount`, 0)), 0) AS `unpaidAmount`,
COALESCE(SUM(o.`refunded_amount`), 0) AS `refundedAmount`,
COALESCE(SUM(o.`paid_amount` - o.`refunded_amount`), 0) AS `netPaidAmount`
FROM `gao_sales_order` o
WHERE 1 = 1
<include refid="orderFilter"/>
<include refid="operatingOrderFilter"/>
</select>
<select id="selectConsumptionDaily" resultType="com.imyeyu.api.modules.gao.vo.GaoSalesOrderConsumptionDailyStatView">
@@ -208,7 +211,7 @@
COALESCE(SUM(o.`paid_amount` - o.`refunded_amount`), 0) AS `netPaidAmount`
FROM `gao_sales_order` o
WHERE 1 = 1
<include refid="orderFilter"/>
<include refid="operatingOrderFilter"/>
GROUP BY DATE_FORMAT(FROM_UNIXTIME(o.`purchased_at` / 1000), '%Y%m%d')
ORDER BY `dateValue` ASC
</select>
@@ -120,11 +120,14 @@
COALESCE(SUM(o.`sale_amount`), 0) AS `saleAmount`,
COALESCE(SUM(o.`paid_amount`), 0) AS `paidAmount`,
COALESCE(SUM(o.`pending_paid_amount`), 0) AS `pendingPaidAmount`,
COALESCE(SUM(o.`sale_amount` - o.`paid_amount`), 0) AS `unpaidAmount`,
COALESCE(SUM(GREATEST(o.`sale_amount` - o.`paid_amount`, 0)), 0) AS `unpaidAmount`,
COALESCE(SUM(o.`refunded_amount`), 0) AS `refundedAmount`,
COALESCE(SUM(o.`paid_amount` - o.`refunded_amount`), 0) AS `netPaidAmount`
FROM `gao_sales_order` o LEFT JOIN `gao_customer` c ON c.`id` = o.`customer_id`
WHERE <include refid="queryWhere"/>
<if test="(statusList == null or statusList.size() == 0) and status == null">
AND o.`status` &lt;&gt; 'CANCELLED'
</if>
</select>
<sql id="customerProductWhere">
i.`deleted_at` IS NULL