Newer
Older
huludao / src / main / resources / mapper / RiverManage / RiverChiefLogDao.xml
<?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.newfiber.api.pc.dao.RiverManage.RiverChiefLogDao" >
  <resultMap id="BaseResultMap" type="com.newfiber.api.pc.model.River.RiverChiefLog" >
    <id column="Serial" property="serial" jdbcType="BIGINT" />
    <result column="Chief_User_No" property="chiefUserNo" jdbcType="VARCHAR" />
    <result column="Log_Content" property="logContent" jdbcType="NVARCHAR" />
    <result column="Log_No" property="logNo" jdbcType="VARCHAR" />
    <result column="Log_Write_Time" property="logWriteTime" jdbcType="TIMESTAMP" />
  </resultMap>

  <select id="selectRiverChiefLogList" resultType="com.newfiber.api.pc.model.River.RiverChiefLog" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog" >
    select
      r.Serial serial,r.Chief_User_No chiefUserNo,r.Log_Content logContent,r.Log_No logNo,DATE_FORMAT(r.Log_Write_Time,'%Y-%m-%d %T') time,
      b.River_Name riverName,r.Log_Pics_No logPicsNo,
    o.user_name 'chiefUserName'
    from river_chief_log r
    inner join river_chief i
    on i.Chief_User_No = r.Chief_User_No
    inner join river_info_basis b
    on b.River_No = i.River_No
    inner join huludao_main.sys_user_info o
    on o.User_No = r.Chief_User_No
    where 1=1
    <if test="logNo != null and logNo != ''">
      and r.Log_No = #{logNo,jdbcType=VARCHAR}
    </if>
    <if test="chiefUserNo != null and chiefUserNo != ''">
      and r.Chief_User_No = #{chiefUserNo,jdbcType=VARCHAR}
    </if>
    <if test="createTime != null">
      and r.Log_Write_Time &gt;= #{createTime}
    </if>
    <if test="endTime != null">
      and r.Log_Write_Time &lt;= #{endTime}
    </if>
    order by r.Log_Write_Time desc

  </select>

  <select id="selectJuniorPatrolTotalByMap" resultType="com.newfiber.api.pc.model.River.RiverChiefLog" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select r.Serial serial,r.River_Chief_No chiefUserNo,DATE_FORMAT(r.Patrol_Start_Time,'%Y-%m-%d %T') time,
            b.River_Name riverName,r.Patrol_No patrolNo,
      o.user_name 'chiefUserName'
      from river_patrol r
      inner join river_chief i
      on i.Chief_User_No = r.River_Chief_No
      inner join river_info_basis b
      on b.River_No = i.River_No
      inner join huludao_main.sys_user_info o
      on o.User_No = r.River_Chief_No
      where 1=1
      <if test="list != null and list.size > 0">
        and r.River_Chief_No in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
      <if test="chiefUserName != null and chiefUserName != ''">
        and o.user_name like '%${chiefUserName}%'
      </if>

      <if test="pageNo != null" >
        order by r.Serial limit #{pageNo},#{pageSize}
      </if>
  </select>

  <select id="selectCountJuniorPatrolTotalByMap" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT r.Serial)
    from river_patrol r
    inner join river_chief i
    on i.Chief_User_No = r.River_Chief_No
    inner join river_info_basis b
    on b.River_No = i.River_No
    inner join huludao_main.sys_user_info o
    on o.User_No = r.River_Chief_No
    where 1=1
    <if test="list != null and list.size > 0">
      and r.River_Chief_No in
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="chiefUserName != null and chiefUserName != ''">
       o.user_name like '%${chiefUserName}%'
    </if>
  </select>

  <select id="selectDivisionNoByUserNo" resultType="com.newfiber.api.pc.model.River.RiverChiefLog" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select DISTINCT o.User_No userNo
      from division_org_manage d
      inner join huludao_main.sys_user_org o
      on o.Org_No = d.Org_No
      where d.Division_No = #{divisionNo,jdbcType=VARCHAR}
  </select>

  <select id="selectDivisionNoByUserNoRiver" resultMap="BaseResultMap" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select DISTINCT o.User_No userNo
    from division_org_manage d
    inner join huludao_main.sys_user_org o
    on o.Org_No = d.Org_No
    inner join river_info_basis b
    on b.Division_No = d.Division_No
    where d.Division_No = #{divisionNo,jdbcType=VARCHAR}
  </select>

  <select id="selectLogList" resultMap="BaseResultMap" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select DATE_FORMAT(r.Log_Write_Time,'%Y-%m-%d %T') time,a.Division_Name divisionName,b.River_Name riverName,r.Log_No logNo,r.Serial serial,
    r.Log_Content logContent,
           o.user_name 'chiefUserName'
      from river_chief_log r
       inner join river_chief i
       on i.Chief_User_No = r.Chief_User_No
       inner join river_info_basis b
       on b.River_No = i.River_No
       inner join administrative_division a
       on a.Division_No = b.Division_No
       inner join huludao_main.sys_user_info o
       on o.User_No = r.Chief_User_No
       where 1=1
      <if test="userNo != null and userNo != ''">
        and r.Chief_User_No != #{userNo,jdbcType=INTEGER}
      </if>
      <if test="createTime != null and createTime != ''">
        and r.Log_Write_Time between #{createTime} and #{endTime}
      </if>
      <if test="riverGrade != null and riverGrade != ''">
        and b.River_Grade = #{riverGrade,jdbcType=INTEGER}
      </if>
      <if test="riverName != null and riverName != ''">
        and b.River_Name like '%${riverName}%'
      </if>
       <if test="pageNo != null" >
          order by r.Serial limit #{pageNo},#{pageSize}
       </if>
  </select>

  <select id="countSelectLogList" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT r.Serial)
    from river_chief_log r
    inner join river_chief i
    on i.Chief_User_No = r.Chief_User_No
    inner join river_info_basis b
    on b.River_No = i.River_No
    inner join administrative_division a
    on a.Division_No = b.Division_No
    inner join huludao_main.sys_user_info o
    on o.User_No = r.Chief_User_No
    where 1=1
    <if test="userNo != null and userNo != ''">
      and r.Chief_User_No != #{userNo,jdbcType=INTEGER}
    </if>
    <if test="createTime != null and createTime != ''">
      and r.Log_Write_Time between #{createTime} and #{endTime}
    </if>
    <if test="riverGrade != null and riverGrade != ''">
      and b.River_Grade = #{riverGrade,jdbcType=INTEGER}
    </if>
    <if test="riverName != null and riverName != ''">
      and b.River_Name like '%${riverName}%'
    </if>
  </select>

  <select id="selectLogListByUserNo" resultType="com.newfiber.api.pc.model.River.RiverChiefLog" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT r.Log_No) countSize,count(DISTINCT z.Patrol_No) countPatrol,a.Division_Name divisionName,b.River_Name riverName,b.River_No riverNo,
    o.user_name 'chiefUserName'
    from river_chief_log r
    inner join river_patrol z
    on z.Patrol_No = r.Log_No
    inner join river_chief i
    on i.Chief_User_No = r.Chief_User_No
    inner join river_info_basis b
    on b.River_No = i.River_No
    inner join administrative_division a
    on a.Division_No = b.Division_No
    inner join huludao_main.sys_user_info o
    on o.User_No = r.Chief_User_No
    where 1=1
    <if test="list != null and list.size > 0">
      and r.Chief_User_No in
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="createTime != null">
      and r.Log_Write_Time between #{createTime} and #{endTime}
    </if>
    <if test="riverGrade != null and riverGrade != ''">
      and b.River_Grade = #{riverGrade,jdbcType=INTEGER}
    </if>
    <if test="riverName != null and riverName != ''">
      and b.River_Name like '%${riverName}%'
    </if>
    <if test="chiefUserNo != null and chiefUserNo != ''">
      and r.Chief_User_No != #{chiefUserNo,jdbcType=VARCHAR}
    </if>
    group by a.Division_Name,b.River_Name,b.River_No,o.user_name
    <if test="pageNo != null" >
      order by b.River_Name limit #{pageNo},#{pageSize}
    </if>
  </select>

  <select id="countSelectLogListByUserNo" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT b.River_Name)
    from river_chief_log r
    inner join river_patrol z
    on z.Patrol_No = r.Log_No
    inner join river_chief i
    on i.Chief_User_No = r.Chief_User_No
    inner join river_info_basis b
    on b.River_No = i.River_No
    inner join administrative_division a
    on a.Division_No = b.Division_No
    inner join huludao_main.sys_user_info o
    on o.User_No = r.Chief_User_No
    where 1=1
    <if test="list != null and list.size > 0">
      and r.Chief_User_No in
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="createTime != null">
      and r.Log_Write_Time between #{createTime} and #{endTime}
    </if>
    <if test="riverGrade != null and riverGrade != ''">
      and b.River_Grade = #{riverGrade,jdbcType=INTEGER}
    </if>
    <if test="riverName != null and riverName != ''">
      and b.River_Name like '%${riverName}%'
    </if>
    <if test="chiefUserNo != null and chiefUserNo != ''">
      and r.Chief_User_No != #{chiefUserNo,jdbcType=VARCHAR}
    </if>
  </select>

  <select id="selectRiverChiefLogByUserNo" resultType="com.newfiber.api.pc.model.River.RiverChiefLog" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog" >
    <!--select-->
    <!--DISTINCT b.Division_No divisionNo-->
    <!--from river_chief_log r-->
    <!--inner join river_chief i-->
    <!--on i.Chief_User_No = r.Chief_User_No-->
    <!--inner join river_info_basis b-->
    <!--on b.River_No = i.River_No-->
    <!--where 1=1-->
    <!--<if test="chiefUserNo != null and chiefUserNo != ''">-->
      <!--and r.Chief_User_No = #{chiefUserNo,jdbcType=VARCHAR}-->
    <!--</if>-->
    SELECT DISTINCT b.Division_No divisionNo
    FROM river_patrol r INNER JOIN river_chief i ON i.Chief_User_No = r.River_Chief_No
    INNER JOIN river_info_basis b ON b.River_No = i.River_No
    WHERE 1 = 1
    <if test="chiefUserNo != null and chiefUserNo != ''">
      and  r.River_Chief_No = #{chiefUserNo,jdbcType=VARCHAR}
    </if>
    limit 1
  </select>

  <delete id="deleteRiverChiefLog" parameterType="java.util.List" >
    delete from river_chief_log
    where Log_No = #{logNo,jdbcType=VARCHAR}
  </delete>

  <insert id="addRiverChiefLog" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog" >
    insert into river_chief_log
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="chiefUserNo != null" >
        Chief_User_No,
      </if>
      <if test="logContent != null" >
        Log_Content,
      </if>
      <if test="logNo != null" >
        Log_No,
      </if>
      <if test="logPicsNo != null" >
        Log_Pics_No,
      </if>
      <if test="riverNo != null" >
        river_no,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="chiefUserNo != null" >
        #{chiefUserNo,jdbcType=VARCHAR},
      </if>
      <if test="logContent != null" >
        #{logContent,jdbcType=NVARCHAR},
      </if>
      <if test="logNo != null" >
        #{logNo,jdbcType=VARCHAR},
      </if>
      <if test="logPicsNo != null" >
        #{logPicsNo,jdbcType=VARCHAR},
      </if>
      <if test="riverNo != null" >
        #{riverNo,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <select id="countRiverChiefLogList" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog" resultType="java.lang.Integer" >
    select
    count(DISTINCT r.Serial)
    from river_chief_log r
    inner join river_chief i
    on i.Chief_User_No = r.Chief_User_No
    inner join river_info_basis b
    on b.River_No = i.River_No
    inner join huludao_main.sys_user_info o
    on o.User_No = r.Chief_User_No
    where 1=1
    <if test="logNo != null and logNo != ''">
      and r.Log_No = #{logNo,jdbcType=VARCHAR}
    </if>
    <if test="chiefUserNo != null and chiefUserNo != ''">
      and r.Chief_User_No = #{chiefUserNo,jdbcType=VARCHAR}
    </if>
    <if test="createTime != null">
      and r.Log_Write_Time &gt;= #{createTime}
    </if>
    <if test="endTime != null">
      and r.Log_Write_Time &lt;= #{endTime}
    </if>
  </select>

  <update id="updateRiverChiefLog" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog" >
    update river_chief_log
    <set >
      <if test="logContent != null" >
        Log_Content = #{logContent,jdbcType=NVARCHAR},
      </if>
      <if test="logPicsNo != null" >
        Log_Pics_No = #{logPicsNo,jdbcType=VARCHAR},
      </if>
    </set>
    where Log_No = #{logNo,jdbcType=VARCHAR}
  </update>

  <select id="selectLogByReach" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT l.Serial)
      from river_chief_log l
      inner join river_patrol r
      on r.Patrol_No = l.Log_No
      where 1=1
      <if test="list != null and list.size > 0">
        and l.Chief_User_No in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
      <if test="startTime != null">
        and l.Log_Write_Time between #{startTime} and #{endTime}
      </if>
  </select>

  <select id="selectLogByReachBy" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT l.Serial)
    from river_chief_log l
    inner join river_patrol r
    on r.Patrol_No = l.Log_No
    inner join river_chief d
    on d.Chief_User_No = l.Chief_User_No
    inner join river_info_basis b
    on b.River_No = d.River_No
    where 1=1
    <if test="list != null and list.size > 0">
      and l.Chief_User_No in
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="startTime != null">
      and l.Log_Write_Time between #{startTime} and #{endTime}
    </if>
    <if test="riverGrade != null">
      and d.Chief_Grade = #{riverGrade,jdbcType=INTEGER}
    </if>
  </select>

  <select id="selectLogByReachTotal" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT l.Serial)
    from river_chief_log l
    where 1=1
    <if test="list != null and list.size > 0">
      and l.Chief_User_No in
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="startTime != null">
      and l.Log_Write_Time between #{startTime} and #{endTime}
    </if>
  </select>

  <select id="selectLogByReachTotalBy" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT l.Serial)
    from river_chief_log l
    inner join river_chief r
    on r.Chief_User_No = l.Chief_User_No
    inner join river_info_basis b
    on b.River_No = r.River_No
    where 1=1
    <if test="list != null and list.size > 0">
      and l.Chief_User_No in
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="startTime != null">
      and l.Log_Write_Time between #{startTime} and #{endTime}
    </if>
    <if test="riverGrade != null">
      and r.Chief_Grade = #{riverGrade,jdbcType=INTEGER}
    </if>
  </select>

  <select id="selectRiverPatrolReach" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT r.Serial)
      from river_patrol r
      where 1=1
      <if test="list != null and list.size > 0">
        and r.River_Chief_No in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
      <if test="startTime != null">
        and r.Patrol_Start_Time between #{startTime} and #{endTime}
      </if>
  </select>

  <select id="countRiverUserTotal" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT r.Serial)
      from river_chief r
      where 1=1
      <if test="list != null and list.size > 0">
        and r.Chief_User_No in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
  </select>

  <select id="countRiverUserPatrolTotal" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT l.Serial)
      from river_patrol l
      where 1=1
      <if test="list != null and list.size > 0">
        and l.River_Chief_No in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
    <if test="startTime != null">
      and l.Patrol_Start_Time &gt;= #{startTime}
    </if>
    <if test="endTime != null">
      and l.Patrol_Start_Time &lt;= #{endTime}
    </if>
  </select>

  <select id="countRiverUserPatrolTotal1" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT l.Serial)
    from river_patrol l
    where 1 = 1
    <if test="riverChiefNo != null">
      and l.River_Chief_No =#{riverChiefNo}
    </if>
    <if test="month != null">
      and DATE_FORMAT(l.Patrol_Start_Time,'20%y-%m') = #{month}
    </if>
  </select>

  <select id="countRiverUserPatrolTotalBy" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT l.Serial)
    from river_patrol l
    inner join river_chief r
    on r.Chief_User_No = l.River_Chief_No
    inner join river_info_basis b
    on b.River_No = r.River_No
    where 1=1
    <if test="list != null and list.size > 0">
      and l.River_Chief_No in
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="startTime != null">
      and l.Patrol_Start_Time between #{startTime} and #{endTime}
    </if>
    <if test="riverGrade != null">
      and r.Chief_Grade = #{riverGrade,jdbcType=INTEGER}
    </if>
  </select>

  <select id="selectRankingLogTotal" resultMap="BaseResultMap" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select t.* from (
    select divisionName,riverName,chiefUserName,countSize,
    case when @prevRank = countSize then @curRank
    when @prevRank := countSize then @curRank := @curRank+1 END AS ranka
    from(
      select a.Division_Name divisionName,b.River_Name riverName,count(DISTINCT r.Log_No) countSize,
       o.user_name 'chiefUserName'
        from river_chief_log r
        inner join river_chief i
        on i.Chief_User_No = r.Chief_User_No
        inner join river_info_basis b
        on b.River_No = i.River_No
        inner join administrative_division a
        on a.Division_No = b.Division_No
        inner join huludao_main.sys_user_info o
        on o.User_No = r.Chief_User_No
        where 1=1
        <if test="list != null and list.size > 0">
          and r.Chief_User_No in
          <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
          </foreach>
        </if>
        <if test="startTime != null">
          and r.Log_Write_Time &gt;= #{startTime}
        </if>
        <if test="endTime != null">
          and r.Log_Write_Time &lt;= #{endTime}
        </if>
        GROUP BY a.Division_Name,b.River_Name,o.user_name ) p,(SELECT @curRank :=0, @prevRank := NULL) z ORDER BY countSize DESC) t
        where t.ranka &lt; 6
        <if test="pageNo != null" >
          limit #{pageNo},#{pageSize}
        </if>
  </select>

  <select id="countRankingLogTotal" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT a.riverName)
      from (select a.Division_Name divisionName,b.River_Name riverName,dense_rank() over( ORDER BY count(DISTINCT r.Log_No) DESC) ranka,count(DISTINCT r.Log_No) countSize,
        o.user_name 'chiefUserName'
        from river_chief_log r
        inner join river_chief i
        on i.Chief_User_No = r.Chief_User_No
        inner join river_info_basis b
        on b.River_No = i.River_No
        inner join administrative_division a
        on a.Division_No = b.Division_No
        inner join huludao_main.sys_user_info o
        on o.User_No = r.Chief_User_No
        where 1=1
        <if test="list != null and list.size > 0">
          and r.Chief_User_No in
          <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
          </foreach>
        </if>
        <if test="startTime != null and startTime != ''">
          and r.Log_Write_Time between #{startTime} and #{endTime}
        </if>
        <if test="pageNo != null" >
          limit #{pageNo} ,#{pageSize}
        </if>) a
        where a.ranka &lt; 6
  </select>

  <select id="countRiver" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT s.River_No)
      from river_chief r
      inner join river_info_basis s
      on s.River_No = r.River_No
      inner join river_chief_log l
      on l.Chief_User_No = r.Chief_User_No
      where 1=1
      <if test="list != null and list.size > 0">
        and r.Chief_User_No in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
      <if test="startTime != null">
        and l.Log_Write_Time &gt;= #{startTime}
      </if>
      <if test="endTime != null">
        and l.Log_Write_Time &lt;= #{endTime}
      </if>

  </select>

  <select id="countRiverNew" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(b.River_No)
	from administrative_division a
	inner join river_info_basis b
	on a.Division_No = b.Division_No
	where a.Parent_Division_No = #{divisionNo,jdbcType=VARCHAR}
  </select>

  <select id="countRiverPatrol" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT s.River_No)
    from river_chief r
    inner join river_info_basis s
    on s.River_No = r.River_No
    inner join river_chief_log l
    on l.Chief_User_No = r.Chief_User_No
    where 1=1
    <if test="list != null and list.size > 0">
      and r.Chief_User_No in
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="startTime != null">
      and l.Log_Write_Time &gt;= #{startTime}
    </if>
    <if test="endTime != null">
      and l.Log_Write_Time &lt;= #{endTime}
    </if>
    <if test="riverGrade != null">
      and r.Chief_Grade = #{riverGrade,jdbcType=INTEGER}
    </if>
  </select>

  <select id="selectChiefPatrolRankingTotal" resultType="com.newfiber.api.pc.model.River.RiverChiefLog" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select t.* from
    (select divisionName,riverName,chiefUserName,countSize,
    case when @prevRank = countSize then @curRank
    when @prevRank := countSize then @curRank := @curRank+1 END AS ranka
    from
    (select  a.Division_Name divisionName,b.River_Name riverName,count(DISTINCT r.Patrol_No) countSize,o.user_name 'chiefUserName'
    from river_patrol r     inner join river_chief i     on i.Chief_User_No = r.River_Chief_No
    inner join river_info_basis b     on b.River_No = i.River_No
    inner join administrative_division a     on a.Division_No = b.Division_No
    inner join huludao_main.sys_user_info o     on o.User_No = r.River_Chief_No
    where 1=1
    <if test="list != null and list.size > 0">
      and r.River_Chief_No in
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="startTime != null">
      and r.Patrol_Start_Time &gt;= #{startTime}
    </if>
    <if test="endTime != null">
      and r.Patrol_Start_Time &lt;= #{endTime}
    </if>
    GROUP BY  a.Division_Name,  b.River_Name  ,o.user_name            ) p,
    (SELECT @curRank :=0, @prevRank := NULL) z ORDER BY countSize desc) t
    where t.ranka &lt; 6
    <if test="pageNo != null" >
      limit #{pageNo},#{pageSize}
    </if>
  </select>

  <select id="countChiefPatrolRankingTotal" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(divisionName) from
    (select divisionName,riverName,chiefUserName,countSize,
    case when @prevRank = countSize then @curRank
    when @prevRank := countSize then @curRank := @curRank+1 END AS ranka
    from
    (select  a.Division_Name divisionName,b.River_Name riverName,count(DISTINCT r.Patrol_No) countSize,o.user_name 'chiefUserName'
    from river_patrol r     inner join river_chief i     on i.Chief_User_No = r.River_Chief_No
    inner join river_info_basis b     on b.River_No = i.River_No
    inner join administrative_division a     on a.Division_No = b.Division_No
    inner join huludao_main.sys_user_info o     on o.User_No = r.River_Chief_No
    where 1=1
    <if test="list != null and list.size > 0">
      and r.River_Chief_No in
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="startTime != null">
      and r.Patrol_Start_Time &gt;= #{startTime}
    </if>
    <if test="endTime != null">
      and r.Patrol_Start_Time &lt;= #{endTime}
    </if>
    GROUP BY  a.Division_Name,  b.River_Name  ,o.user_name            ) p,
    (SELECT @curRank :=0, @prevRank := NULL) z ORDER BY countSize) t
    where t.ranka &lt; 6
    <if test="pageNo != null" >
      limit #{pageNo},#{pageSize}
    </if>
  </select>

  <select id="selectRiverChiefPatrolManage" resultType="com.newfiber.api.pc.model.River.RiverChiefLog" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select a.Division_Name divisionName,b.River_Name riverName,count(DISTINCT r.Patrol_No) countSize,b.River_No riverNo,
      o.user_name 'chiefUserName'
      from river_patrol r
      inner join river_chief i
      on i.Chief_User_No = r.River_Chief_No
      inner join river_info_basis b
      on b.River_No = i.River_No
      inner join administrative_division a
      on a.Division_No = b.Division_No
      inner join huludao_main.sys_user_info o
      on o.User_No = r.River_Chief_No
      where 1=1
      <if test="list != null and list.size > 0">
        and r.River_Chief_No in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
      <if test="list == null">
        and r.River_Chief_No = 'asdasd5452452'
      </if>
      <if test="startTime != null">
        and r.Patrol_Start_Time &gt;= #{startTime}
      </if>
      <if test="endTime != null">
        and r.Patrol_Start_Time &lt;= #{endTime}
      </if>
      <if test="riverName != null and riverName != ''">
        and b.River_Name like '%${riverName}%'
      </if>
      <if test="chiefGrade != null">
        and i.Chief_Grade = #{chiefGrade,jdbcType=INTEGER}
      </if>
      <if test="names != null and names != ''">
        and a.Division_Name like '%${names}%'
      </if>
      group by r.River_Chief_No,a.Division_Name,b.River_Name,b.River_No
      order by b.River_Name
  </select>

  <select id="selectCountRiverChiefPatrolManage" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT b.River_Name) countSize
    from river_patrol r
    inner join river_chief i
    on i.Chief_User_No = r.River_Chief_No
    inner join river_info_basis b
    on b.River_No = i.River_No
    inner join administrative_division a
    on a.Division_No = b.Division_No
    inner join huludao_main.sys_user_info o
    on o.User_No = r.River_Chief_No
    where 1=1
    <if test="list != null and list.size > 0">
      and r.River_Chief_No in
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="list == null">
      and r.River_Chief_No = 'wmj'
    </if>
    <if test="startTime != null">
      and r.Patrol_Start_Time between #{startTime} and #{endTime}
    </if>
    <if test="riverName != null and riverName != ''">
      and b.River_Name like '%${riverName}%'
    </if>
    <if test="chiefGrade != null">
      and i.Chief_Grade = #{chiefGrade,jdbcType=INTEGER}
    </if>
    <if test="names != null and names != ''">
      and a.Division_Name like '%${names}%'
    </if>
  </select>
  
  <select id="getRiverChiefLog" resultType="com.newfiber.api.pc.model.River.RiverChiefLog" >
	SELECT
		r.Serial serial,
		r.Log_No logNo,
		r.Log_Content logContent,
    DATE_FORMAT(r.Log_Write_Time,'%Y-%m-%d %T') time,
		c.Chief_User_No chiefUserNo,
		s.user_name chiefUserName,
		i.River_Name riverName
	FROM
		river_chief_log r
	INNER JOIN huludao_main.sys_user_info s ON s.User_No = r.Chief_User_No
	INNER JOIN river_chief c ON c.Chief_User_No = r.Chief_User_No
	INNER JOIN river_info_basis i ON i.River_No = c.River_No
	WHERE
		1=1
    <if test="list != null">
      AND s.User_No IN
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
      <if test="sort != null">
       order by ${sort}
       		<if test="order != null">
       		${order}
       		</if>
      </if>
      <if test="sort == null">
      order by time DESC
      </if>
      <if test="pageSize != 0">
      limit #{pageNo},#{pageSize}
      </if>
  </select>
  
  <select id="getRiverChiefLogCount" resultType="int" parameterType="java.util.List">
	SELECT
		count(r.Serial)
	FROM
		river_chief_log r
	INNER JOIN huludao_main.sys_user_info s ON s.User_No = r.Chief_User_No
	INNER JOIN river_chief c ON c.Chief_User_No = r.Chief_User_No
	INNER JOIN river_info_basis i ON i.River_No = c.River_No
	WHERE
		1=1
    <if test="list != null">
      AND s.User_No IN
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
  </select>

  <select id="selectChiefLogBySearchTime" resultMap="BaseResultMap" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select r.Serial serial,r.Chief_User_No chiefUserNo,r.Log_Content logContent,r.Log_No logNo,DATE_FORMAT(r.Log_Write_Time,'%Y-%m-%d %T') time,
      r.Log_Pics_No logPicsNo
      from river_chief_log r
      inner join river_patrol l
      on r.Log_No = l.Patrol_No
      where 1=1
      <if test="chiefUserNo != null and chiefUserNo != ''">
        and r.Chief_User_No = #{chiefUserNo,jdbcType=VARCHAR}
      </if>
      <if test="createTime != null and createTime != ''">
        and r.Log_Write_Time between #{createTime} and #{endTime}
      </if>
  </select>

  <select id="selectChiefLogByPatrol" resultMap="BaseResultMap" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select l.Serial serial,l.Chief_User_No chiefUserNo,l.Log_Content logContent,l.Log_No logNo,DATE_FORMAT(l.Log_Write_Time,'%Y-%m-%d %T') time,
      l.Log_Pics_No logPicsNo
      from river_patrol r
      inner join river_chief_log l
      on r.Patrol_No = l.Log_No
      where 1=1
      <if test="patrolNo != null and patrolNo != ''">
        and r.Patrol_No = #{patrolNo,jdbcType=VARCHAR}
      </if>
  </select>

  <select id="selectNextChiefLogDetail" resultType="com.newfiber.api.pc.model.River.RiverChiefLog" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select r.Log_No logNo,b.River_Name riverName,a.Division_Name divisionName,r.Log_Content logContent,DATE_FORMAT(r.Log_Write_Time,'%Y-%m-%d %T') timee,
      i.user_name 'chiefUserName',r.Log_Pics_No logPicsNo
      from river_chief_log r
      inner join river_chief h
      on h.Chief_User_No = r.Chief_User_No
      inner join river_info_basis b
      on b.River_No = h.River_No
      inner join administrative_division a
      on a.Division_No = b.Division_No
      inner join huludao_main.sys_user_info i
      on i.User_No = r.Chief_User_No
      where 1=1
      <if test="list != null and list.size > 0">
        and r.Chief_User_No in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
          #{item}
        </foreach>
      </if>
      <if test="list == null">
        and r.Chief_User_No = 'asdasdasda1223'
      </if>
      <if test="riverGrade != null and riverGrade != ''">
        and b.River_Grade = #{riverGrade,jdbcType=INTEGER}
      </if>
      <if test="riverName != null and riverName != ''">
        and b.River_Name like '%${riverName}%'
      </if>
      <if test="startTime != null">
        and r.Log_Write_Time between #{startTime} and #{endTime}
      </if>
      group by r.Log_No,b.River_Name,a.Division_Name,r.Log_Content,r.Log_Write_Time,i.user_name
      <if test="pageNo != null" >
        order by r.Log_Write_Time desc limit #{pageNo} ,#{pageSize}
      </if>
  </select>

  <select id="countNextChiefLogDetail" resultType="java.lang.Integer" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog">
    select count(DISTINCT r.Serial)
    from river_chief_log r
    inner join river_chief h
    on h.Chief_User_No = r.Chief_User_No
    inner join river_info_basis b
    on b.River_No = h.River_No
    inner join administrative_division a
    on a.Division_No = b.Division_No
    inner join huludao_main.sys_user_info i
    on i.User_No = r.Chief_User_No
    where 1=1
    <if test="list != null and list.size > 0">
      and r.Chief_User_No in
      <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
        #{item}
      </foreach>
    </if>
    <if test="list == null">
      and r.Chief_User_No = 'asdasdasda1223'
    </if>
    <if test="riverGrade != null">
      and b.River_Grade = #{riverGrade,jdbcType=INTEGER}
    </if>
    <if test="riverName != null and riverName != ''">
      and b.River_Name like '%${riverName}%'
    </if>
    <if test="startTime != null">
      and r.Log_Write_Time between #{startTime} and #{endTime}
    </if>
  </select>

  <select id="getRiverPatrolInfo" parameterType="Map" resultType="com.newfiber.api.pc.model.River.RiverPatrol">
    SELECT count(b.River_Name) countSize,b.River_No riverNo,b.River_Name riverName,case when c.Patrol_Days is null then 0 else c.Patrol_Days end total
    from river_patrol a inner join river_info_basis b on a.River_No = b.River_No
    left join patrol_days_config c on a.River_No = c.River_No
    WHERE 1=1
    <if test="riverNos != null and riverNos.size > 0">
     and b.River_No IN
      <foreach collection="riverNos" item="riverNo" open="(" separator="," close=")">
        #{riverNo}
      </foreach>
    </if>
    <if test="st != null">
      and a.Patrol_Start_Time &gt;= #{st}
    </if>
    <if test="et != null">
      and a.Patrol_Start_Time &lt;= #{et}
    </if>
    GROUP BY b.River_No,b.River_Name,c.Patrol_Days
    <if test="page != null and rows!= null">
      limit #{page},#{rows}
    </if>
  </select>
  
  <select id="getRiverPatrolLogInfo" parameterType="Map" resultType="com.newfiber.api.pc.model.River.StaticLogEntity">
    select  sum(m.reachLog) reachLog,sum(m.totalLog) totalLog,sum(m.patrolNum) patrolNum,m.name from (
    select case when t.type = 'a' then t.val else 0 end as reachLog,
    			 case when t.type = 'b' then t.val else 0 end as totalLog,
    			 case when t.type = 'c' then t.val else 0 end as patrolNum,t.name
    from (
    select count(c.Log_No) val,a.River_Name name ,'a' as 'type'
    from river_info_basis a
    left join river_patrol b on a.River_No = b.River_No
    left join river_chief_log c on  b.Patrol_No = c.Log_No
    WHERE a.River_No IN
    <foreach collection="riverNos" item="riverNo" open="(" separator="," close=")">
      #{riverNo}
    </foreach>
    AND c.Log_Write_Time between #{st} and #{et}
    GROUP BY a.River_Name
    union all
    select count(c.Log_No) val,a.River_Name name , 'b' as 'type'
    from river_info_basis a left join river_chief b on
    a.River_No = b.River_No left join river_chief_log c on
    b.Chief_User_No = c.Chief_User_No
    WHERE a.River_No IN
    <foreach collection="riverNos" item="riverNo" open="(" separator="," close=")">
      #{riverNo}
    </foreach>
    AND c.Log_Write_Time between #{st} and #{et}
    GROUP BY a.River_Name
    union all
    SELECT count(b.River_Name) countSize,b.River_Name riverName,'c' as 'type'
    from river_patrol a inner join river_info_basis b on a.River_No = b.River_No
    where b.River_No IN
    <foreach collection="riverNos" item="riverNo" open="(" separator="," close=")">
      #{riverNo}
    </foreach>
    and a.Patrol_Start_Time between #{st} and #{et}
    GROUP BY b.River_Name) t
    ) as m  GROUP BY m.name
  </select>

  <select id="selectRiverChiefList" resultType="com.newfiber.api.pc.model.River.RiverChiefLog" parameterType="com.newfiber.api.pc.model.River.RiverChiefLog" >
    select
    r.Serial serial,r.Chief_User_No chiefUserNo,r.Log_Content logContent,r.Log_No logNo,DATE_FORMAT(r.Log_Write_Time,'%Y-%m-%d %T') time,
    b.River_Name riverName,r.Log_Pics_No logPicsNo,
    o.user_name 'chiefUserName'
    from river_chief_log r
    left join river_info_basis b
    on r.river_no = b.River_No
    left join river_user_relation rur
    on r.river_no = rur.river_no
    inner join huludao_main.sys_user_info o
    on o.User_No = r.Chief_User_No
    where 1=1
    <if test="collect !=null and collect.size()>0">
      and r.river_no in
      <foreach collection="collect" item="riverNo" open="(" separator="," close=")">
        #{riverNo}
      </foreach>
    </if>
    <if test="logNo != null and logNo != ''">
      and r.Log_No = #{logNo,jdbcType=VARCHAR}
    </if>
    <if test="chiefUserNo != null and chiefUserNo != ''">
      and r.Chief_User_No = #{chiefUserNo,jdbcType=VARCHAR}
    </if>
    <if test="createTime != null">
      and r.Log_Write_Time &gt;= #{createTime}
    </if>
    <if test="endTime != null">
      and r.Log_Write_Time &lt;= #{endTime}
    </if>
    order by r.Log_Write_Time desc

  </select>
</mapper>