OrderBaseInfoMapper.xml 7.46 KB
<?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.order.erp.mapper.order.OrderBaseInfoMapper">
    <select id="queryProjectNoAndInnerNoDto" resultType="com.order.erp.domain.vo.order.QueryProjectNoAndInnerNoDto">
        <if test="flag == true">
            SELECT DISTINCT project_no
            FROM order_base_info
            WHERE enable_flag = 10
            AND project_no like concat('%',#{dto.projectNo},'%')
        </if>
        <if test="flag == false">
            SELECT DISTINCT inner_no
            FROM order_base_info
            WHERE enable_flag = 10
            AND inner_no like concat('%',#{dto.innerNo},'%')
        </if>
    </select>
    <select id="salesAmountStatistics" resultType="java.lang.Double">
        SELECT SUM(opa.customer_total_price) AS total_price
        FROM order_base_info obi
        JOIN order_profit_analysis opa ON opa.order_id = obi.id and opa.enable_flag = 10
        WHERE obi.enable_flag = 10  <!-- 用于动态添加条件 -->
        <!-- 动态添加 customer_code 条件 -->
        <if test="customerCodeIn != null and customerCodeIn.size() > 0">
            AND customer_code IN
            <foreach collection="customerCodeIn" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        <!-- 动态添加 create_time 范围条件 -->
        <if test="begin != null">
            AND obi.create_time >= #{begin}
        </if>
        <if test="end != null">
            AND obi.create_time <![CDATA[ <= ]]> #{end}
        </if>
    </select>
    <select id="salesAmountTarget" resultType="java.lang.Double">
        SELECT SUM(relation_value) AS total_value
        FROM system_setting
        WHERE relation_code = 'salesAmount'
        and enable_flag = 10
        <!-- 动态添加 setting_name 条件 -->
        <if test="customerCodeIn != null and customerCodeIn.size() > 0">
            AND setting_value IN
            <foreach collection="customerCodeIn" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
    </select>

    <resultMap id="mapResult" type="map">
        <result property="key" column="k"/>
        <result property="value" column="v"/>
    </resultMap>
    <select id="customerSalesStatus" resultMap="mapResult">
        SELECT
        obi.customer_code AS k,
        SUM(opa.customer_total_price) AS v
        FROM
        order_base_info obi
        JOIN
        order_profit_analysis opa ON opa.order_id = obi.id AND opa.enable_flag = 10
        WHERE
        obi.enable_flag = 10
        <if test="customerCodeIn != null and customerCodeIn.size() > 0">
            AND obi.customer_code IN
            <foreach item="item" index="index" collection="customerCodeIn" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="begin != null">
            AND obi.create_time >= #{begin}
        </if>
        <if test="end != null">
            AND obi.create_time <![CDATA[ <= ]]> #{end}
        </if>
        GROUP BY
        obi.customer_code
    </select>


    <select id="countRecentMonthValueByOrderStatus" resultType="com.order.erp.domain.vo.order.DateYearMonthTimeVO">
        SELECT
        DATE_FORMAT(obi.create_time, '%Y-%m') AS date,
        SUM(opa.customer_total_price) AS totalPrice,
        YEAR(obi.create_time) AS yearType
        FROM
        order_base_info obi
        JOIN
        order_profit_analysis opa
        ON
        opa.order_id = obi.id
        AND opa.enable_flag = 10
        WHERE
        obi.enable_flag = 10
        AND YEAR(obi.create_time) IN
        <foreach item="year" collection="years" open="(" close=")" separator=",">
            #{year}
        </foreach>
        GROUP BY
        DATE_FORMAT(obi.create_time, '%Y-%m'),
        YEAR(obi.create_time)
        ORDER BY
        date;
    </select>


    <select id="sameAttributeOrder" resultType="com.order.erp.domain.dto.order.OrderBaseInfoDO">
        SELECT
        obi.*
        FROM
        order_base_info obi
        JOIN
        order_inspection_stage opa
        ON
        opa.order_id = obi.id
        AND opa.enable_flag = 10
        WHERE
        obi.enable_flag = 10
        AND
        obi.customer_style = #{customerStyle}
        AND
        obi.inner_no = #{innerNo}
        AND
        obi.return_order = #{isReturnOrder}
        AND
        obi.create_time BETWEEN #{monthsAgo} AND #{now}
        AND
        (opa.mid_check_apply_time IS  NULL
        OR
        opa.mid_check_result IS  NULL)
    </select>

    <select id="countRecentYearByOrderInit" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM (SELECT project_no, inner_no
        FROM order_base_info
        WHERE enable_flag = 10
        AND (return_order != '1' OR return_order IS NULL)
        GROUP BY project_no, inner_no) AS unique_combinations;
    </select>

    <select id="countRecentMonthValueByOrderInit" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM (
        SELECT project_no, inner_no
        FROM order_base_info
        WHERE enable_flag = 10
        AND (return_order != '1' OR return_order IS NULL)  -- 处理 NULL 值
        AND inner_no LIKE CONCAT('_____', #{dataYear}, '%')  -- 直接匹配年份
        GROUP BY project_no, inner_no
        ) AS unique_combinations;

    </select>

    <select id="countRecentDayByOrderInit" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM (
        SELECT project_no, inner_no
        FROM order_base_info
        WHERE enable_flag = 10
        AND (return_order != '1' OR return_order IS NULL)
        AND create_time >= #{startDate}
        AND create_time <![CDATA[ < ]]> #{endDate}
        AND inner_no LIKE CONCAT('_____', #{year}, '%')
        GROUP BY project_no, inner_no
        ) AS unique_combinations;

    </select>

    <select id="countAllYearByOrderStatus" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM (
                 SELECT project_no, inner_no
                 FROM order_base_info
                 WHERE enable_flag = 10
                 AND (return_order != '1' OR return_order IS NULL)
                 AND order_status=#{orderStatus}
                 GROUP BY project_no, inner_no
             ) AS unique_combinations;

    </select>

    <select id="countAllMonthByOrderStatus" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM (
                 SELECT project_no, inner_no
                 FROM order_base_info
                 WHERE enable_flag = 10
                 AND (return_order != '1' OR return_order IS NULL)
                 AND order_status=#{orderStatus}
                 AND inner_no LIKE CONCAT('_____', #{dataYear}, '%')  -- 直接匹配年份
                 GROUP BY project_no, inner_no
             ) AS unique_combinations;

    </select>

    <select id="countAllDayvalueByOrderStatus" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM (
                 SELECT project_no, inner_no
                 FROM order_base_info
                 WHERE enable_flag = 10
                   AND (return_order != '1' OR return_order IS NULL)
                   AND create_time >= #{startDate}
                   AND create_time <![CDATA[ < ]]> #{endDate}
                   AND order_status=#{orderStatus}
                   AND inner_no LIKE CONCAT('_____', #{year}, '%')
                 GROUP BY project_no, inner_no
             ) AS unique_combinations;

    </select>
</mapper>