Newer
Older
huludao / src / main / resources / mapper / News / NewsDao.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.News.NewsDao" >
  <resultMap id="BaseResultMap" type="com.newfiber.api.pc.model.EventsManage.News" >
    <id column="Serial" property="serial" jdbcType="BIGINT" />
    <result column="News_NO" property="newsNo" jdbcType="VARCHAR" />
    <result column="Title" property="title" jdbcType="NVARCHAR" />
    <result column="Title_Img" property="titleImg" jdbcType="NVARCHAR" />
    <result column="Publish_UserID" property="publishUserid" jdbcType="VARCHAR" />
    <result column="Publish_UserName" property="publishUsername" jdbcType="NVARCHAR" />
    <result column="Publish_Time" property="publishTime" jdbcType="TIMESTAMP" />
    <result column="Area" property="area" jdbcType="NVARCHAR" />
    <result column="Abstracts" property="abstracts" jdbcType="NVARCHAR" />
    <result column="OrgNo" property="orgNo" jdbcType="VARCHAR"/>
  </resultMap>
  <resultMap id="ResultMapWithBLOBs" type="com.newfiber.api.pc.model.EventsManage.News" extends="BaseResultMap" >
    <result column="Content" property="content" jdbcType="LONGVARCHAR" />
  </resultMap>
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
    <if test="fields == null" >
      Serial, News_NO, Title, Title_Img, Publish_UserID, Publish_UserName, Publish_Time, 
      Area, Abstracts
    </if>
    <if test="fields != null" >
      ${fields}
    </if>
  </sql>


  <sql id="Base_Filed" >
    <if test="fields == null" >
      N.Serial, N.News_NO, N.Title, N.Title_Img, N.Publish_UserID, N.Publish_UserName, N.Publish_Time,
      N.Area, N.Abstracts,D.divisionName AS divisionName
    </if>
    <if test="fields != null" >
      ${fields}
    </if>
  </sql>

  <sql id="Blob_Column_List" >
    Content
  </sql>

  <sql id="op">

    <choose>
      <when test="sort!=null and sort != ''">

        ${sort}
      </when>
      <otherwise>
        Serial
      </otherwise>
    </choose>

  </sql>
  <sql id="oc">
    <choose>
      <when test="order !=null and order  != ''">
        ${order}
      </when>
      <otherwise>
        DESC
      </otherwise>
    </choose>

  </sql>



  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.newfiber.api.pc.model.EventsManage.NewsQuery" >
    select
    <if test="distinct" >
      distinct
    </if>
    N.Serial, N.News_NO, N.Title,N.Content, N.Title_Img, N.Publish_UserID, N.Publish_UserName, DATE_FORMAT(N.Publish_Time,'%Y-%m-%d %T') formatTime,
    N.Area, N.Abstracts,D.Division_Name AS divisionName,N.Publish_Time
    from news N INNER JOIN administrative_division D ON N.Area=D.Division_No
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="_parameter == null" >
      WHERE 1=1
    </if>
    <if test="str!=null and str!=''">
      AND N.Title LIKE '${str}'
    </if>
    ORDER by
    <choose>
      <when test="sort!=null and sort!='' and sort!='Content'">
        ${sort}
      </when>
      <otherwise>
        N.Publish_Time
      </otherwise>
    </choose>
    <include refid="oc"/>
    <if test="startRow != null" >
      limit #{startRow},#{pageSize}
    </if>
  </select>



  <delete id="deleteByExample" parameterType="com.newfiber.api.pc.model.EventsManage.NewsQuery" >
    delete from news
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>

  <insert id="insertSelective" parameterType="com.newfiber.api.pc.model.EventsManage.News" >
    insert into news
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="serial != null" >
        Serial,
      </if>
      <if test="newsNo != null" >
        News_NO,
      </if>
      <if test="title != null" >
        Title,
      </if>
      <if test="titleImg != null" >
        Title_Img,
      </if>
      <if test="publishUserid != null" >
        Publish_UserID,
      </if>
      <if test="publishUsername != null" >
        Publish_UserName,
      </if>
      <if test="publishTime != null" >
        Publish_Time,
      </if>
      <if test="area != null" >
        Area,
      </if>
      <if test="abstracts != null" >
        Abstracts,
      </if>
      <if test="content != null" >
        Content,
      </if>
      <if test="orgNo != null">
        orgNo,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="serial != null" >
        #{serial,jdbcType=BIGINT},
      </if>
      <if test="newsNo != null" >
        #{newsNo,jdbcType=VARCHAR},
      </if>
      <if test="title != null" >
        #{title,jdbcType=NVARCHAR},
      </if>
      <if test="titleImg != null" >
        #{titleImg,jdbcType=NVARCHAR},
      </if>
      <if test="publishUserid != null" >
        #{publishUserid,jdbcType=VARCHAR},
      </if>
      <if test="publishUsername != null" >
        #{publishUsername,jdbcType=NVARCHAR},
      </if>
      <if test="publishTime != null" >
        #{publishTime,jdbcType=TIMESTAMP},
      </if>
      <if test="area != null" >
        #{area,jdbcType=NVARCHAR},
      </if>
      <if test="abstracts != null" >
        #{abstracts,jdbcType=NVARCHAR},
      </if>
      <if test="content != null" >
        #{content,jdbcType=LONGVARCHAR},
      </if>
      <if test="orgNo != null">
        #{orgNo,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>


  <select id="countByExample" parameterType="com.newfiber.api.pc.model.EventsManage.NewsQuery" resultType="java.lang.Integer" >
    select count(t.Serial) from (select
    <if test="distinct" >
      distinct
    </if>
    N.Serial, N.News_NO, N.Title,N.Content, N.Title_Img, N.Publish_UserID, N.Publish_UserName, DATE_FORMAT(N.Publish_Time,'%Y-%m-%d %T') formatTime,
    N.Area, N.Abstracts,D.Division_No AS divisionNo
    from news N INNER JOIN administrative_division D ON N.Area=D.Division_No
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="_parameter == null" >
      WHERE 1=1
    </if>
    <if test="str!=null and str!=''">
      AND N.Title LIKE '${str}'
    </if>) t
  </select>



  <update id="updateByExampleSelective" parameterType="map" >
    update news
    <set >
      <if test="record.serial != null" >
        Serial = #{record.serial,jdbcType=BIGINT},
      </if>
      <if test="record.newsNo != null" >
        News_NO = #{record.newsNo,jdbcType=VARCHAR},
      </if>
      <if test="record.title != null" >
        Title = #{record.title,jdbcType=NVARCHAR},
      </if>
      <if test="record.titleImg != null" >
        Title_Img = #{record.titleImg,jdbcType=NVARCHAR},
      </if>
      <if test="record.publishUserid != null" >
        Publish_UserID = #{record.publishUserid,jdbcType=VARCHAR},
      </if>
      <if test="record.publishUsername != null" >
        Publish_UserName = #{record.publishUsername,jdbcType=NVARCHAR},
      </if>
      <if test="record.publishTime != null" >
        Publish_Time = #{record.publishTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.area != null" >
        Area = #{record.area,jdbcType=NVARCHAR},
      </if>
      <if test="record.abstracts != null" >
        Abstracts = #{record.abstracts,jdbcType=NVARCHAR},
      </if>
      <if test="record.content != null" >
        Content = #{record.content,jdbcType=LONGVARCHAR},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>

  <!-- 获取新闻表列表 -->
  <select id="queryList" resultType="com.newfiber.api.pc.model.EventsManage.News">
    select
    n.Serial serial,
    News_NO newsNo,
    Title title,
    Title_Img titleImg,
    Content content,
    Publish_UserID publishUserid,
    Publish_UserName publishUsername,
    Publish_Time publishTime,
    Area area,
    Abstracts abstracts,
    type type,
    type_Name typeName,
    n.OrgNo orgNo,
    s.Org_Name orgName
    from news n left JOIN huludao_main.sys_organization s ON n.OrgNo = s.Org_No
    WHERE 1=1
    <if test="title != null and title !=''">
      AND Title LIKE '%${title}%'
    </if>
  </select>

  <select id="selectImportantNews" resultType="com.newfiber.api.pc.model.EventsManage.News">
        select
        n.Serial serial,
    News_NO newsNo,
    Title title,
    Title_Img titleImg,
    Content content,
    Publish_UserID publishUserid,
    Publish_UserName publishUsername,
    Publish_Time publishTime,
    Area area,
    Abstracts abstracts,
    type type,
    type_Name typeName,
    n.OrgNo orgNo,
    s.Org_Name orgName
		from news n left JOIN huludao_main.sys_organization s ON n.OrgNo = s.Org_No
		WHERE ranking = 2  ORDER BY Publish_Time DESC LIMIT 0,5
    </select>

  <select id="selectRiversOfSameLevel" parameterType="String" resultType="com.newfiber.api.pc.model.River.RiverInfoBasis">
        SELECT
         r.River_No riverNo,
         r.River_Name riverName,
         u.user_name userName,
         o.Org_Name orgName
         FROM river_info_basis r INNER JOIN river_chief c ON r.River_No = c.River_No
         INNER JOIN huludao_main.sys_user_info u ON u.User_No = c.Chief_User_No
         LEFT JOIN huludao_main.sys_user_org uo ON u.User_No = uo.User_No
         LEFT JOIN huludao_main.sys_organization o ON uo.Org_No = o.Org_No
        WHERE EXISTS (
        SELECT ad.Division_No AS divisionNo FROM administrative_division ad
        WHERE ad.Parent_Division_No =
        (  SELECT
        DISTINCT
         d.Parent_Division_No
         FROM huludao_main.sys_user_org uo INNER JOIN division_org_manage do ON uo.Org_No = do.Org_No
        INNER JOIN administrative_division d ON do.Division_No = d.Division_No
        WHERE uo.User_No = #{userNo})
        AND r.Division_No = ad.Division_No
        )
    </select>

  <select id="selectListByRiver" parameterType="String" resultMap="BaseResultMap">
        SELECT
			n.Serial serial,
    News_NO newsNo,
    Title title,
    Title_Img titleImg,
    Content content,
    Publish_UserID publishUserid,
    Publish_UserName publishUsername,
    Publish_Time publishTime,
    Area area,
    Abstracts abstracts,
    type type,
    type_Name typeName,
    n.OrgNo orgNo,
    o.Org_Name orgName
         FROM news n left JOIN huludao_main.sys_organization o ON n.OrgNo = o.Org_No
        WHERE RiverNo = #{riverNo}

    </select>

  <select id="selectListByDivision" parameterType="String" resultMap="BaseResultMap">
        SELECT
        n.Serial serial,
    News_NO newsNo,
    Title title,
    Title_Img titleImg,
    Content content,
    Publish_UserID publishUserid,
    Publish_UserName publishUsername,
    Publish_Time publishTime,
    Area area,
    Abstracts abstracts,
    type type,
    type_Name typeName,
    n.OrgNo orgNo,
    o.Org_Name orgName
        FROM news n left JOIN huludao_main.sys_organization o ON n.OrgNo = o.Org_No
        WHERE Area = #{divisionNo}

    </select>

  <select id="selectAll" resultType="com.newfiber.api.pc.model.EventsManage.News">
    select
      n.Serial serial,
      News_NO newsNo,
      Title title,
      Title_Img titleImg,
      Content content,
      Publish_UserID publishUserid,
      Publish_UserName publishUsername,
      Publish_Time publishTime,
      Area area,
      Abstracts abstracts,
      type type,
      type_Name typeName,
      n.OrgNo orgNo,
      s.Org_Name orgName
    from news n left JOIN huludao_main.sys_organization s ON n.OrgNo = s.Org_No
    order by Publish_Time desc
  </select>
</mapper>