<?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.hjm.mapper.HjmViolationMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT DISTINCT a.*,b.image
        FROM hjm_violation a
        LEFT JOIN hjm_car b ON a.code = b.code
        LEFT JOIN gxwebsoft_core.sys_organization c ON b.organization_id = c.organization_id
        LEFT JOIN gxwebsoft_core.sys_organization f ON b.organization_parent_id = f.organization_id
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.title != null">
                AND a.title LIKE CONCAT('%', #{param.title}, '%')
            </if>
            <if test="param.code != null">
              AND a.code = #{param.code}
            </if>
            <if test="param.categoryId != null">
                AND a.category_id = #{param.categoryId}
            </if>
            <if test="param.money != null">
                AND a.money = #{param.money}
            </if>
            <if test="param.score != null">
                AND a.score = #{param.score}
            </if>
            <if test="param.organizationId != null">
              AND b.organization_id = #{param.organizationId}
            </if>
            <if test="param.organizationParentId != null">
              AND b.organization_parent_id = #{param.organizationParentId}
            </if>
            <if test="param.adminId != null">
                AND a.admin_id = #{param.adminId}
            </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.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.keywords != null">
                AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
                  OR a.code = #{param.keywords}
                )
              </if>
        </where>
    </sql>

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

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

</mapper>
