<?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.csdevice.mapper.AppProjectMapper">
  <resultMap id="BaseResultMap" type="com.njcn.csdevice.pojo.po.AppProjectPO">
    <!--@mbg.generated-->
    <!--@Table app_project-->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="user_id" jdbcType="VARCHAR" property="userId" />
    <result column="area_id" jdbcType="VARCHAR" property="areaId" />
    <result column="lng" jdbcType="DECIMAL" property="lng" />
    <result column="lat" jdbcType="DECIMAL" property="lat" />
    <result column="status" jdbcType="TINYINT" property="status" />
    <result column="create_by" jdbcType="CHAR" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="CHAR" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, `name`, user_id, area_id, lng, lat, `status`, create_by, create_time, update_by, 
    update_time
  </sql>

  <select id="getPageVo" resultType="com.njcn.csdevice.pojo.vo.AppProjectVO">
    select a.*,b.pid as engineering_id,(select name from cs_ledger c where c.id=b.pid) as engineering_name from  cs_project a LEFT JOIN cs_ledger b on a.id = b.id where 1=1
    and a.status ="1"
<!--    <if test="userId != null and userId !=''">-->
<!--      and exists (select 1 from cs_engineering_user d where d.engineering_id=b.pid and d.user_id=#{userId})-->
<!--    </if>-->
    <if test="temp!=null and temp.projectId != null and temp.projectId !=''">
      AND a.id  = #{temp.projectId}
    </if>
    AND b.pid in
    <foreach collection='temp.engineeringIds' item='item' index="index" open='(' separator=',' close=')'>
      #{item}
    </foreach>

      <if test="temp!=null and temp.endTime != null and temp.endTime !=''">
          AND a.create_time &lt;= #{temp.endTime}"
      </if>
      <if test="temp!=null and temp.startTime != null and temp.startTime !=''">
          AND a.create_time &gt;= #{temp.startTime}
      </if>
      <if test="temp!=null and temp.searchValue != null and temp.searchValue !=''">
          AND a.`name` like concat('%',#{temp.searchValue},'%')
      </if>
         order by a.create_time desc
  </select>
</mapper>