<?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.mosty.base.manager.mapper.TbJcglBqMapper">

    <select id="paginQuery" resultType="com.mosty.base.model.vo.jcgl.TbJcglBqVo">
        select b.id,b.bqlx,b.bqmc,b.bqbh,b.bqpym,b.xt_sjzt,b.bqtb,b.mx_id,b.bz,(select count(1) from tb_jcgl_xfll_bq
        where bq_id = b.id and xt_scbz = '0' and xt_sjzt = '1') as xfll_sl
        from tb_jcgl_bq b
        where b.xt_scbz = '0'
        <if test="params.bqlx != null and params.bqlx != ''">
            and bqlx=#{params.bqlx}
        </if>
        <if test="params.bqmc != null and params.bqmc != ''">
            and bqmc like concat('%',#{params.bqmc},'%')
        </if>
        <if test="params.bqpym != null and params.bqpym != ''">
            and bqpym like concat('%',#{params.bqpym},'%')
        </if>
    </select>
    <select id="countBqsl" resultType="com.mosty.base.model.vo.jcgl.TbJcglBqVo">
        select bq.id,bq.bqmc,bq.bqpym,bq.tp bqtb,IfNULL(bq2.sl,0)xfllSl,bq.bqlx from (
        (select id,bqmc,bqpym,'' tp,bqlx from tb_jcgl_bq where xt_scbz = '0' and xt_sjzt = '1'
        <if test="vo.bqlx !=null and vo.bqlx !=''">
            and bqlx = #{vo.bqlx}
        </if>
            )bq
        LEFT JOIN
        (select bq_id,count(*)sl from tb_jcgl_xfll_bq  where xt_scbz = 0  GROUP BY bq_id)bq2
        on bq.id = bq2.bq_id)
    </select>

    <select id="countBqslByBqlx" resultType="java.lang.Integer">
        select count(1) from tb_jcgl_bq where xt_scbz = '0' and bqlx = #{bqlx}
    </select>

    <!--批量删除-->
    <update id="deleteBatch">
        update tb_jcgl_bq set xt_scbz = '1' where id in
        <foreach collection="list" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </update>

    <!--批量注销-->
    <update id="zxBatch">
        update tb_jcgl_bq set xt_sjzt = '0' where id in
        <foreach collection="list" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </update>

</mapper>
