<?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.gxwebsoft.bszx.mapper.BszxPayMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,b.title as formName,u.phone as mobile,u.avatar,u.nickname
        FROM bszx_pay a
        LEFT JOIN cms_article b ON a.form_id = b.article_id
        LEFT JOIN gxwebsoft_core.sys_user u ON a.user_id = u.user_id
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.age != null">
                AND a.age = #{param.age}
            </if>
            <if test="param.name != null">
                AND a.name LIKE CONCAT('%', #{param.name}, '%')
            </if>
            <if test="param.sex != null">
                AND a.sex = #{param.sex}
            </if>
            <if test="param.phone != null">
                AND a.phone LIKE CONCAT('%', #{param.phone}, '%')
            </if>
            <if test="param.className != null">
                AND a.class_name = #{param.className}
            </if>
            <if test="param.gradeName != null">
                AND a.grade_name LIKE CONCAT('%', #{param.gradeName}, '%')
            </if>
            <if test="param.address != null">
                AND a.address LIKE CONCAT('%', #{param.address}, '%')
            </if>
            <if test="param.workUnit != null">
                AND a.work_unit LIKE CONCAT('%', #{param.workUnit}, '%')
            </if>
            <if test="param.position != null">
                AND a.position LIKE CONCAT('%', #{param.position}, '%')
            </if>
            <if test="param.number != null">
                AND a.number = #{param.number}
            </if>
            <if test="param.price != null">
                AND a.price = #{param.price}
            </if>
            <if test="param.extra != null">
                AND a.extra LIKE CONCAT('%', #{param.extra}, '%')
            </if>
            <if test="param.orderNo != null">
                AND a.order_no LIKE CONCAT('%', #{param.orderNo}, '%')
            </if>
            <if test="param.dateTime != null">
                AND a.date_time LIKE CONCAT('%', #{param.dateTime}, '%')
            </if>
            <if test="param.certificate != null">
                AND a.certificate LIKE CONCAT('%', #{param.certificate}, '%')
            </if>
            <if test="param.formData != null">
                AND a.form_data LIKE CONCAT('%', #{param.formData}, '%')
            </if>
            <if test="param.formId != null">
                AND a.form_id = #{param.formId}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.orderNos != null">
              AND a.order_no IN
              <foreach collection="param.orderNos" item="item" separator="," open="(" close=")">
                #{item}
              </foreach>
            </if>
            <if test="param.keywords != null">
                AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
                 OR u.phone = #{param.keywords}
                 OR a.name LIKE CONCAT('%', #{param.keywords}, '%')
                 OR a.order_no = #{param.keywords}
                )
              </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.bszx.entity.BszxPay">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.bszx.entity.BszxPay">
        <include refid="selectSql"></include>
    </select>


    <!-- 统计金额总和 -->
    <select id="selectSumMoney" resultType="java.math.BigDecimal">
      SELECT COALESCE(SUM(price), 0) as total_money
      FROM bszx_pay
      <if test="ew != null">
        ${ew.customSqlSegment}
      </if>
    </select>

</mapper>
