TbRWhitelistRuleSmapper.xml 11.4 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.zteits.bill.mapper.smapper.TbRWhitelistRuleSmapper">
    <resultMap id="BaseResultMap" type="com.zteits.bill.domain.TbRWhitelistRule">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="white_r_no" jdbcType="VARCHAR" property="whiteRNo"/>
        <result column="white_r_name" jdbcType="VARCHAR" property="whiteRName"/>
        <result column="match_type" jdbcType="INTEGER" property="matchType"/>
        <result column="charge_type" jdbcType="INTEGER" property="chargeType"/>
        <result column="car_color" jdbcType="VARCHAR" property="carColor"/>
        <result column="car_num" jdbcType="VARCHAR" property="carNum"/>
        <result column="car_owner" jdbcType="VARCHAR" property="carOwner"/>
        <result column="sex" jdbcType="INTEGER" property="sex"/>
        <result column="address" jdbcType="VARCHAR" property="address"/>
        <result column="card_id" jdbcType="VARCHAR" property="cardId"/>
        <result column="phone" jdbcType="VARCHAR" property="phone"/>
        <result column="white_r_state" jdbcType="INTEGER" property="whiteRState"/>
        <result column="auditor_status" jdbcType="INTEGER" property="auditorStatus"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="data_state" jdbcType="INTEGER" property="dataState"/>
        <result column="create_empid" jdbcType="VARCHAR" property="createEmpid"/>
        <result column="create_name" jdbcType="VARCHAR" property="createName"/>
        <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
        <result column="modify_empid" jdbcType="VARCHAR" property="modifyEmpid"/>
        <result column="modify_name" jdbcType="VARCHAR" property="modifyName"/>
        <result column="modify_date" jdbcType="TIMESTAMP" property="modifyDate"/>
        <result column="eff_date" jdbcType="TIMESTAMP" property="effDate"/>
        <result column="exp_date" jdbcType="TIMESTAMP" property="expDate"/>
        <result column="max_charge_fee" jdbcType="BIGINT" property="maxChargeFee"/>
        <result column="report_fee_type" jdbcType="INTEGER" property="reportFeeType" />
        <result column="org_id" jdbcType="BIGINT" property="orgId" />
    </resultMap>
    <sql id="Base_Column_List">
    id, white_r_no, white_r_name, match_type, charge_type, car_color, car_num, car_owner, 
    sex, address, card_id, phone, white_r_state, auditor_status, remark, data_state, 
    create_empid, create_name, create_date, modify_empid, modify_name, modify_date, eff_date, 
    exp_date, max_charge_fee, report_fee_type, org_id
  </sql>

    <!-- 模糊匹配查询白名单list -->
    <select id="queryWhitelistByCarNum" resultType="com.zteits.bill.domain.WhitelistIsFreeDO">
        select
        a.white_r_no as whiteRNo,
        a.white_r_name as whiteRName,
        b.pl_no as plNo,
        a.match_type as matchType,
        b.car_number as carNum,
        a.max_charge_fee as maxChargeFee,
        a.eff_date as effDate,
        a.exp_date as expDate
        from tb_r_whitelist_rule a ,
        tb_r_whitelist_park_car_rel b
        where a.white_r_no=b.white_r_no
        and a.data_state=b.data_state
        and a.data_state=1
        and a.auditor_status=2 /**审核状态:1:待审核 2:审核通过,3:审核驳回.*/
        and a.white_r_state=1 /**规则状态:1、上架;2、下架.*/
        and b.pl_no =#{plNo}
        <![CDATA[and a.eff_date <= now()]]>
        <![CDATA[and a.exp_date >= now()]]>
        and a.match_type in
        <foreach collection="matchTypeList" item="matchType" open="(" close=")" separator=",">
            #{matchType}
        </foreach>
    </select>


    <!-- 通过车牌号+plNo精确查询白名单 -->
    <select id="queryWhitelistByCarNumAndPlNo"
            parameterType="com.zteits.clouds.api.dto.bill.whitelist.param.QueryCarNumIsWhitelistRequest"
            resultType="com.zteits.bill.domain.WhitelistIsFreeDO">
        select a.white_r_no as whiteRNo,
        a.white_r_name as whiteRName,
        b.pl_no as plNo,
        a.match_type as matchType,
        a.charge_type as chargeType,
        b.car_number as carNum,
        a.max_charge_fee as maxChargeFee,
        a.eff_date as effDate,
        a.exp_date as expDate
        from tb_r_whitelist_rule a ,
        tb_r_whitelist_park_car_rel b
        where a.white_r_no=b.white_r_no
        and a.data_state=b.data_state
        and a.data_state=1
        and a.auditor_status=2 /**审核状态:1:待审核 2:审核通过,3:审核驳回.*/
        and a.white_r_state=1 /**规则状态:1、上架;2、下架.*/
        and a.match_type=3 /**匹配类型:1:前置匹配 2:后置匹配 3:完全匹配.*/
        <if test="chargerType != null">
            AND a.charge_type = #{chargerType}
        </if>
        and a.eff_date &lt;= #{currentDate}
        and a.exp_date &gt;= #{currentDate}
        and b.pl_no =#{plNo}
        and b.car_number = #{carNumber}
        order by b.id desc
        limit 0,1
    </select>

    <!-- 通过车牌号+plNo精确查询白名单 -->
    <select id="queryWhitelistByCarNumAndPlNoList"
            parameterType="com.zteits.clouds.api.dto.bill.whitelist.param.QueryCarNumIsWhitelistRequest"
            resultType="com.zteits.bill.domain.WhitelistIsFreeDO">
        select a.white_r_no as whiteRNo,
        a.white_r_name as whiteRName,
        b.pl_no as plNo,
        a.match_type as matchType,
        a.charge_type as chargeType,
        b.car_number as carNum,
        a.max_charge_fee as maxChargeFee,
        a.eff_date as effDate,
        a.exp_date as expDate
        from tb_r_whitelist_rule a ,
        tb_r_whitelist_park_car_rel b
        where a.white_r_no=b.white_r_no
        and a.data_state=b.data_state
        and a.data_state=1
        and a.auditor_status=2 /**审核状态:1:待审核 2:审核通过,3:审核驳回.*/
        and a.white_r_state=1 /**规则状态:1、上架;2、下架.*/
        and a.match_type=3 /**匹配类型:1:前置匹配 2:后置匹配 3:完全匹配.*/
        <if test="chargerType != null">
            AND a.charge_type = #{chargerType}
        </if>
        and a.eff_date &lt;= #{currentDate}
        and a.exp_date &gt;= #{currentDate}
        and b.pl_no =#{plNo}
        and b.car_number = #{carNumber}
        order by b.id desc
    </select>

    <!--通过车牌/停车场编码等查询白名单规则-->
    <select id="queryWhitelistRuleForPage" resultMap="BaseResultMap"
            parameterType="com.zteits.clouds.api.dto.bill.whitelist.param.WhitelistRuleForPageRequest">
        select
        c.id,
        c.white_r_no,
        c.white_r_name,
        c.match_type,
        c.charge_type,
        c.car_num,
        c.white_r_state,
        c.eff_date,
        c.exp_date,
        c.create_date,
        c.max_charge_fee
        from tb_r_whitelist_rule c
        where c.id in
        (select
        a.id
        from tb_r_whitelist_rule a
        left JOIN tb_r_whitelist_park_rel b on a.white_r_no = b.white_r_no and b.data_state = 1
        left JOIN tb_r_whitelist_rule_car_number d on a.white_r_no = d.white_r_no and d.data_state =1
        where a.data_state = 1
        <if test="whiteRName != null and whiteRName !=''">
            and a.white_r_name LIKE '%${whiteRName}%'
        </if>
        <if test="plNos != null and plNos.size >0">
            and b.pl_no in
            <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        <if test="carNum != null and carNum !=''">
            and d.car_number LIKE '%${carNum}%'
        </if>
        <if test="matchType != null">
            and a.match_type = #{matchType}
        </if>
        <if test="beginTime != null">
            AND b.create_date &gt;= #{beginTime}
        </if>
        <if test="endTime != null">
            AND b.create_date &lt;= #{endTime}
        </if>
        <if test="orgId != null">
            AND a.org_id = #{orgId}
        </if>
        group by a.id)
        Order by c.create_date desc
    </select>

    <!--查询白名单规则-->
    <select id="queryWhiteRuleById" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from tb_r_whitelist_rule
        where id = #{id,jdbcType=BIGINT}
        and data_state = 1
    </select>
    <!-- 查询需要推送的白名单 -->
    <select id="queryNoPustWhiteCarNoList"
            resultType="com.zteits.clouds.api.dto.bill.whitelist.WhitelistParkRelPushDTO">
        select a.white_r_no whiteRNo,
               a.white_r_name whiteRName,
               a.eff_date effDate,
               a.exp_date expDate,
               a.report_fee_type reportFeeType,
               b.car_number carNum,
               b.id id,
               b.pl_no plNo,
               b.white_state whiteState
        from tb_r_whitelist_rule a,
             tb_r_whitelist_park_car_rel b
        where a.match_type = 3
          and a.charge_type = 1
          and a.white_r_no = b.white_r_no
          <![CDATA[and a.exp_date >= #{nowDate}]]>
          and b.push_state = 0
    </select>

    <!-- 根据车牌号码,停车场编号判断符合条件的白名单列表,包括过期数据 -->
    <select id="queryAllWhiteCarInfoByParkCodeAnCarnumber"
            resultMap="BaseResultMap">
          select
        c.id,
        c.white_r_no,
        c.white_r_name,
        c.match_type,

        c.charge_type,
        c.car_num,
        c.white_r_state,
        c.eff_date,
        c.exp_date,
        c.create_date,
        c.max_charge_fee
        from tb_r_whitelist_rule c
        where c.id in
        (select
        a.id
        from tb_r_whitelist_rule a
        left JOIN tb_r_whitelist_park_rel b on a.white_r_no = b.white_r_no and b.data_state = 1
        left JOIN tb_r_whitelist_rule_car_number d on a.white_r_no = d.white_r_no and d.data_state =1
        where a.data_state = 1
        and b.pl_no  = #{plNo}
		and d.car_number = #{carNumber}
        group by a.id)
    </select>
    <select id="queryAllActiveInfo" resultType="com.zteits.bill.domain.TbRWhitelistRule">
        SELECT c.car_number as  carNum FROM `tb_r_whitelist_rule_car_number` c
        left join tb_r_whitelist_rule t
        on c.white_r_no = t.white_r_no
        where
         t.org_id = #{orgId}
         and c.data_state = 1
         and t.data_state = 1
         and t.eff_date &lt; now()
         and t.exp_date > now()
    </select>

    <!-- 更新已存在的历史白名单为失效 -->
    <update id="updateWhiteRuleExpireDateByCarNos" parameterType="com.zteits.clouds.api.dto.bill.whitelist.param.AddWhiteRuleRequest">
        update tb_r_whitelist_park_rel c,
        (select b.id
        from tb_r_whitelist_rule a,
             tb_r_whitelist_park_rel b
        where a.data_state = 1
          and b.data_state = 1
          and a.white_r_no = b.white_r_no
          and a.car_num in
        <foreach collection="carNums" open="(" close=")" item="carNum" separator=",">
            #{carNum}
        </foreach>
          and exp_date > #{effDate}
          and b.pl_no in
        <foreach collection="plNos" open="(" close=")" item="plNo" separator=",">
            #{plNo}
        </foreach>
        )d
        set c.data_state = 0,
            c.modify_empid = #{createEmpid},
            c.modify_date = #{createDate}
        where c.id = d.id
    </update>

</mapper>