<?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.yida.data.school.news.mapper.EduSchoolManuscriptMapper">
  <select id="listManuscriptPage" resultType="com.yida.data.school.vo.index.ManuscriptPageInfoVO">
    select distinct esm.id,esm.title,esma.name
    author,esm.publish_date,ifnull(esm.update_date,esm.create_date)updateDate,esm.cover_url,esm.cover_type,esm.content,
    esm.content_type ,
    esm.status,
    GROUP_CONCAT(esml.label) labels
    from edu_school_manuscript esm
    left join (select * from edu_school_manuscript_author where del_flag=0) esma on esm.author_id =
    esma.id
    LEFT JOIN edu_school_manuscript_label esml on esm.id = esml.manuscript_id
    <where>
      esm.del_flag=0
      <if test="schoolId != null">
        and esm.school_id=#{schoolId}
      </if>
      <if test="keywprd != null and keywprd != ''">
        and esm.title like concat('%',#{keywprd},'%')
      </if>
      <if test="author != null and author != ''">
        and esma.name like concat('%',#{author},'%')
      </if>
      <if test="publishDate != null and publishDate != ''">
        and date_format(esm.publish_date,'%Y-%m-%d') =#{publishDate}
      </if>
      <if test="path != null">
        and esm.publish_path like concat('%',#{path},'%')
      </if>
      <if test="status != null">
        and esm.status=#{status}
      </if>
      <if test="notShowId != null">
        and esm.id != #{notShowId}
      </if>
      <if test="type != null">
        and esm.type=#{type}
      </if>
      <if test="label != null">
        and esml.label=#{label}
      </if>
    </where>
    GROUP BY esm.id
    order by esm.publish_date desc,esm.create_date desc
  </select>

  <select id="listPublicManuscriptPage" resultType="com.yida.data.school.vo.index.ManuscriptPageInfoVO">
    select esm.id,esm.title,esm.content,esma.name
    author,esm.publish_date,ifnull(esm.update_date,esm.create_date)updateDate,esm.cover_url,esm.cover_type
    from edu_school_manuscript esm
    left join (select * from edu_school_manuscript_author where del_flag=0) esma on esm.author_id =
    esma.id
    <where>
      esm.del_flag=0
      and esm.status in (2,3)
      and esm.publish_path like '%1%'
      <if test="schoolId != null">
        and esm.school_id=#{schoolId}
      </if>
      <if test="notShowId != null">
        and esm.id!=#{notShowId}
      </if>
      <if test="type != null">
        and esm.type=#{type}
      </if>
    </where>
    order by esm.publish_date desc,esm.create_date desc
  </select>

  <select id="listManuscript"
    resultType="com.yida.data.common.core.entity.school.EduSchoolManuscript">
    select *
    from edu_school_manuscript
    <where>
      del_flag=0
      <if test="schoolId != null">
        and school_id =#{schoolId}
      </if>
      <if test="name != null and name != ''">
        and title like concat('%',#{name},'%')
      </if>
      <if test="status != null">
        and status=#{status}
      </if>
      <if test="type != null">
        and type=#{type}
      </if>
      <if test="path != null">
        and publish_path like concat('%',#{path},'%')
      </if>
    </where>
    order by publish_date desc,create_date desc
  </select>

  <select id="getInfo" resultType="com.yida.data.common.core.entity.school.EduSchoolManuscript">
    select a.*, b.name author_name, GROUP_CONCAT(c.label) as labels
    from edu_school_manuscript a
           left join edu_school_manuscript_author b on a.author_id = b.id
           LEFT JOIN edu_school_manuscript_label c on a.id = c.manuscript_id
    where a.del_flag = 0
      and a.id = #{id}
    GROUP BY a.id
  </select>
  <select id="getInfoIncludeDel" resultType="com.yida.data.common.core.entity.school.EduSchoolManuscript">
    select a.*, b.name author_name
    from edu_school_manuscript a
           left join edu_school_manuscript_author b on a.author_id = b.id
    where a.id = #{id}
  </select>
</mapper>
