<?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.njcn.csharmonic.mapper.CsConfigurationMapper">
  <resultMap id="BaseResultMap" type="com.njcn.csharmonic.pojo.po.CsConfigurationPO">
    <!--@mbg.generated-->
    <!--@Table cs_configuration-->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="scope" jdbcType="INTEGER" property="scope" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
      <!--@mbg.generated-->
      id, `name`, `status`, `scope`,create_by, create_time, update_by, update_time
  </sql>

  <select id="queryPage" resultMap="BaseResultMap">
    select * from cs_configuration a where a.status="1"
    and
    SUBSTRING_INDEX(a.project_ids,',',1) in
    <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
      #{item}
    </foreach>
    <choose>
      <when test="userId != null and userId != ''">
        AND (a.scope = 1 OR (a.scope = 0 AND a.create_by = #{userId}))
      </when>
      <otherwise>
        AND (a.scope = 1 OR a.scope = 0)
      </otherwise>
    </choose>
    <if test="temp!=null and temp.searchValue != null and temp.searchValue !=''">
      AND a.name  like concat(concat("%",#{temp.searchValue}),"%")
    </if>
    <if test="temp!=null and temp.searchEndTime  != null and temp.searchEndTime !=''">
    AND a.create_time &lt;= #{temp.searchEndTime}"
    </if>
    <if test="temp!=null and temp.searchBeginTime != null and temp.searchBeginTime !=''">
    AND a.create_time &gt;= #{temp.searchBeginTime}
    </if>
    <if test="temp!=null and temp.id != null and temp.id !=''">
      AND a.id = #{temp.id}
    </if>
    order by a.order_by asc,create_time desc

  </select>
</mapper>