xuhy
2024-09-24 ae4c93dd2e2aef79332360fb5dec13c5b2c961f3
ruoyi-system/src/main/resources/mapper/system/TOrderSaleMapper.xml
@@ -58,9 +58,9 @@
    <select id="amountSum" resultType="com.ruoyi.system.vo.AmountSumVO">
        select
            COUNT(id) AS orderCount,
            SUM(orderMoney) AS saleAmount,
            SUM(payMoney) AS payAmount,
            SUM(orderMoney - payMoney) AS obligation
        IFNULL(SUM(orderMoney),0) AS saleAmount,
        IFNULL(SUM(payMoney),0) AS payAmount,
        IFNULL(SUM(orderMoney - IFNULL(payMoney,0)),0) AS obligation
        from t_order_sale
        <where>
            <if test="query.orderNum != null and query.orderNum != ''">
@@ -99,10 +99,11 @@
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND isCover = 1
            AND status = 2
        </where>
    </select>
    <select id="exportOrderSale" resultType="com.ruoyi.system.vo.TOrderSaleVO">
        select id, orderTime, remark, createTime, updateTime, disabled, createBy, updateBy, orderNum, status,orderMoney,payMoney,shopId
        select id, orderTime, remark, createTime, updateTime, disabled, createBy, updateBy, orderNum, status,orderMoney,payMoney,shopId,payType
        from t_order_sale
        <where>
            <if test="query.orderNum != null and query.orderNum != ''">
@@ -135,10 +136,11 @@
                AND shopId = #{query.shopId}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (createTime BETWEEN #{query.startTime} AND #{query.endTime})
                AND (orderTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND isCover = 1
            AND status = 2
        </where>
    </select>
    <select id="getDataGeneratorSaleDetail" resultType="java.util.Map">
@@ -217,5 +219,96 @@
            and tdg.orderType = 2
        </where>
    </select>
    <select id="profitDetails" resultType="com.ruoyi.system.vo.GoodsProfitVO">
        SELECT
        tomg.goodsName,
        (select typeName from t_goods_type where id = tomg.typeId) AS typeName,
        IFNULL(SUM( tomg.goodsCount ),0) AS totalSalesCount,
        IFNULL(SUM( tomg.goodsCount * tomg.thisSalePrice ),0) AS goodsSaleAmount,
        IFNULL(SUM( tomg.goodsCount * tomg.goodsCostPrice ),0) AS goodsCostAmount,
        IFNULL(SUM(tomg.goodsCount *(tomg.thisSalePrice - tomg.goodsCostPrice)),0) AS goodsProfitAmount
        FROM t_order_sale_goods tomg
        LEFT JOIN t_order_sale tom ON tom.id = tomg.orderId
        <where>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.orderTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            <if test="query.goodsName != null and query.goodsName != ''">
                AND tomg.goodsName like concat('%', #{query.goodsName}, '%')
            </if>
            <if test="query.typeId != null and query.typeId != ''">
                AND tomg.typeId = #{query.typeId}
            </if>
            <if test="query.shopId != null">
                AND tom.shopId = #{query.shopId}
            </if>
            AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND tom.isCover = 1
            AND tom.status = 2
        </where>
        GROUP BY tomg.goodsName
    </select>
    <select id="profitDetailsStatistics" resultType="java.util.Map">
        SELECT
        IFNULL(SUM(a.goodsSaleAmount),0) AS totalSales,
        IFNULL(SUM(a.goodsCostAmount),0) AS totalCosts,
        IFNULL(SUM(a.goodsProfitAmount),0) AS totalProfits
        FROM (
        SELECT
        tomg.goodsName,
        IFNULL(SUM( tomg.goodsCount ),0) AS totalSalesCount,
        IFNULL(SUM( tomg.goodsCount * tomg.thisSalePrice ),0) AS goodsSaleAmount,
        IFNULL(SUM( tomg.goodsCount * tomg.goodsCostPrice ),0) AS goodsCostAmount,
        IFNULL(SUM(tomg.goodsCount * (tomg.thisSalePrice - tomg.goodsCostPrice)),0) AS goodsProfitAmount
        FROM t_order_sale_goods tomg
        LEFT JOIN t_order_sale tom ON tom.id = tomg.orderId
        <where>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.orderTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            <if test="query.goodsName != null and query.goodsName != ''">
                AND tomg.goodsName like concat('%', #{query.goodsName}, '%')
            </if>
            <if test="query.typeId != null and query.typeId != ''">
                AND tomg.typeId = #{query.typeId}
            </if>
            <if test="query.shopId != null">
                AND tom.shopId = #{query.shopId}
            </if>
            AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND tom.isCover = 1
            AND tom.status = 2
        </where>
        GROUP BY tomg.goodsName) a
    </select>
    <select id="profitDetailsExport" resultType="com.ruoyi.system.vo.GoodsProfitVO">
        SELECT
        tomg.goodsName,
        (select typeName from t_goods_type where id = tomg.typeId) AS typeName,
        IFNULL(SUM( tomg.goodsCount ),0) AS totalSalesCount,
        IFNULL(SUM( tomg.goodsCount * tomg.thisSalePrice ),0) AS goodsSaleAmount,
        IFNULL(SUM( tomg.goodsCount * tomg.goodsCostPrice ),0) AS goodsCostAmount,
        IFNULL(SUM(tomg.goodsCount *(tomg.thisSalePrice - tomg.goodsCostPrice)),0) AS goodsProfitAmount
        FROM t_order_sale_goods tomg
        LEFT JOIN t_order_sale tom ON tom.id = tomg.orderId
        <where>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.orderTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            <if test="query.goodsName != null and query.goodsName != ''">
                AND tomg.goodsName like concat('%', #{query.goodsName}, '%')
            </if>
            <if test="query.typeId != null and query.typeId != ''">
                AND tomg.typeId = #{query.typeId}
            </if>
            <if test="query.shopId != null">
                AND tom.shopId = #{query.shopId}
            </if>
            AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND tom.isCover = 1
            AND tom.status = 2
        </where>
        GROUP BY tomg.goodsName
    </select>
</mapper>