<?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.goafanti.common.dao.JtBusinessProjectMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.JtBusinessProject">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="category_id" jdbcType="VARCHAR" property="categoryId" />
    <result column="number" jdbcType="VARCHAR" property="number" />
    <result column="price" jdbcType="DECIMAL" property="price" />
    <result column="activity_price" jdbcType="DECIMAL" property="activityPrice" />
    <result column="member_price" jdbcType="DECIMAL" property="memberPrice" />
    <result column="offset" jdbcType="REAL" property="offset" />
    <result column="activity_flag" jdbcType="INTEGER" property="activityFlag" />
    <result column="introduce" jdbcType="VARCHAR" property="introduce" />
    <result column="province" jdbcType="INTEGER" property="province" />
    <result column="city" jdbcType="INTEGER" property="city" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="min_img_url" jdbcType="VARCHAR" property="minImgUrl" />
    <result column="max_img_url" jdbcType="VARCHAR" property="maxImgUrl" />
    <result column="value" jdbcType="VARCHAR" property="value" />
    <result column="apply_conditions" jdbcType="VARCHAR" property="applyConditions" />
    <result column="owner_id" jdbcType="VARCHAR" property="ownerId" />
    <result column="is_hot" jdbcType="INTEGER" property="isHot" />
    <result column="audit_status" jdbcType="INTEGER" property="auditStatus" />
    <result column="audit_info" jdbcType="VARCHAR" property="auditInfo" />
    <result column="release_date" jdbcType="TIMESTAMP" property="releaseDate" />
    <result column="advertisement" jdbcType="VARCHAR" property="advertisement" />
    <result column="keyword" jdbcType="VARCHAR" property="keyword" />
    <result column="summary" jdbcType="VARCHAR" property="summary" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <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 close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <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 close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    id, name, category_id, number, price, activity_price, member_price, offset, activity_flag, 
    introduce, province, city, create_time, min_img_url, max_img_url, value, apply_conditions, 
    owner_id, is_hot, audit_status, audit_info, release_date, advertisement,keyword,summary
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.JtBusinessProjectExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from jt_business_project
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    select 
    <include refid="Base_Column_List" />
    from jt_business_project
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    delete from jt_business_project
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.JtBusinessProjectExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    delete from jt_business_project
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.JtBusinessProject">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    insert into jt_business_project (id, name, category_id, 
      number, price, activity_price, 
      member_price, offset, activity_flag, 
      introduce, province, city, 
      create_time, min_img_url, max_img_url, 
      value, apply_conditions, owner_id, 
      is_hot, audit_status, audit_info, 
      release_date, advertisement,keyword,summary)
    values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{categoryId,jdbcType=VARCHAR}, 
      #{number,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL}, #{activityPrice,jdbcType=DECIMAL}, 
      #{memberPrice,jdbcType=DECIMAL}, #{offset,jdbcType=REAL}, #{activityFlag,jdbcType=INTEGER}, 
      #{introduce,jdbcType=VARCHAR}, #{province,jdbcType=INTEGER}, #{city,jdbcType=INTEGER}, 
      #{createTime,jdbcType=TIMESTAMP}, #{minImgUrl,jdbcType=VARCHAR}, #{maxImgUrl,jdbcType=VARCHAR}, 
      #{value,jdbcType=VARCHAR}, #{applyConditions,jdbcType=VARCHAR}, #{ownerId,jdbcType=VARCHAR}, 
      #{isHot,jdbcType=INTEGER}, #{auditStatus,jdbcType=INTEGER}, #{auditInfo,jdbcType=VARCHAR}, 
      #{releaseDate,jdbcType=TIMESTAMP}, #{advertisement,jdbcType=VARCHAR},#{keyword,jdbcType=VARCHAR},#{summary,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.JtBusinessProject">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    insert into jt_business_project
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="categoryId != null">
        category_id,
      </if>
      <if test="number != null">
        number,
      </if>
      <if test="price != null">
        price,
      </if>
      <if test="activityPrice != null">
        activity_price,
      </if>
      <if test="memberPrice != null">
        member_price,
      </if>
      <if test="offset != null">
        offset,
      </if>
      <if test="activityFlag != null">
        activity_flag,
      </if>
      <if test="introduce != null">
        introduce,
      </if>
      <if test="province != null">
        province,
      </if>
      <if test="city != null">
        city,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="minImgUrl != null">
        min_img_url,
      </if>
      <if test="maxImgUrl != null">
        max_img_url,
      </if>
      <if test="value != null">
        value,
      </if>
      <if test="applyConditions != null">
        apply_conditions,
      </if>
      <if test="ownerId != null">
        owner_id,
      </if>
      <if test="isHot != null">
        is_hot,
      </if>
      <if test="auditStatus != null">
        audit_status,
      </if>
      <if test="auditInfo != null">
        audit_info,
      </if>
      <if test="releaseDate != null">
        release_date,
      </if>
      <if test="advertisement != null">
        advertisement,
      </if>
      <if test="keyword != null">
      keyword,
      </if>
      <if test="summary != null">
      summary,
       </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="categoryId != null">
        #{categoryId,jdbcType=VARCHAR},
      </if>
      <if test="number != null">
        #{number,jdbcType=VARCHAR},
      </if>
      <if test="price != null">
        #{price,jdbcType=DECIMAL},
      </if>
      <if test="activityPrice != null">
        #{activityPrice,jdbcType=DECIMAL},
      </if>
      <if test="memberPrice != null">
        #{memberPrice,jdbcType=DECIMAL},
      </if>
      <if test="offset != null">
        #{offset,jdbcType=REAL},
      </if>
      <if test="activityFlag != null">
        #{activityFlag,jdbcType=INTEGER},
      </if>
      <if test="introduce != null">
        #{introduce,jdbcType=VARCHAR},
      </if>
      <if test="province != null">
        #{province,jdbcType=INTEGER},
      </if>
      <if test="city != null">
        #{city,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="minImgUrl != null">
        #{minImgUrl,jdbcType=VARCHAR},
      </if>
      <if test="maxImgUrl != null">
        #{maxImgUrl,jdbcType=VARCHAR},
      </if>
      <if test="value != null">
        #{value,jdbcType=VARCHAR},
      </if>
      <if test="applyConditions != null">
        #{applyConditions,jdbcType=VARCHAR},
      </if>
      <if test="ownerId != null">
        #{ownerId,jdbcType=VARCHAR},
      </if>
      <if test="isHot != null">
        #{isHot,jdbcType=INTEGER},
      </if>
      <if test="auditStatus != null">
        #{auditStatus,jdbcType=INTEGER},
      </if>
      <if test="auditInfo != null">
        #{auditInfo,jdbcType=VARCHAR},
      </if>
      <if test="releaseDate != null">
        #{releaseDate,jdbcType=TIMESTAMP},
      </if>
      <if test="advertisement != null">
        #{advertisement,jdbcType=VARCHAR},
      </if>
       <if test="keyword != null">
      #{keyword,jdbcType=VARCHAR},
      </if>
      <if test="summary != null">
      #{summary,jdbcType=VARCHAR}
       </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.JtBusinessProjectExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    select count(*) from jt_business_project
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    update jt_business_project
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.name != null">
        name = #{record.name,jdbcType=VARCHAR},
      </if>
      <if test="record.categoryId != null">
        category_id = #{record.categoryId,jdbcType=VARCHAR},
      </if>
      <if test="record.number != null">
        number = #{record.number,jdbcType=VARCHAR},
      </if>
      <if test="record.price != null">
        price = #{record.price,jdbcType=DECIMAL},
      </if>
      <if test="record.activityPrice != null">
        activity_price = #{record.activityPrice,jdbcType=DECIMAL},
      </if>
      <if test="record.memberPrice != null">
        member_price = #{record.memberPrice,jdbcType=DECIMAL},
      </if>
      <if test="record.offset != null">
        offset = #{record.offset,jdbcType=REAL},
      </if>
      <if test="record.activityFlag != null">
        activity_flag = #{record.activityFlag,jdbcType=INTEGER},
      </if>
      <if test="record.introduce != null">
        introduce = #{record.introduce,jdbcType=VARCHAR},
      </if>
      <if test="record.province != null">
        province = #{record.province,jdbcType=INTEGER},
      </if>
      <if test="record.city != null">
        city = #{record.city,jdbcType=INTEGER},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.minImgUrl != null">
        min_img_url = #{record.minImgUrl,jdbcType=VARCHAR},
      </if>
      <if test="record.maxImgUrl != null">
        max_img_url = #{record.maxImgUrl,jdbcType=VARCHAR},
      </if>
      <if test="record.value != null">
        value = #{record.value,jdbcType=VARCHAR},
      </if>
      <if test="record.applyConditions != null">
        apply_conditions = #{record.applyConditions,jdbcType=VARCHAR},
      </if>
      <if test="record.ownerId != null">
        owner_id = #{record.ownerId,jdbcType=VARCHAR},
      </if>
      <if test="record.isHot != null">
        is_hot = #{record.isHot,jdbcType=INTEGER},
      </if>
      <if test="record.auditStatus != null">
        audit_status = #{record.auditStatus,jdbcType=INTEGER},
      </if>
      <if test="record.auditInfo != null">
        audit_info = #{record.auditInfo,jdbcType=VARCHAR},
      </if>
      <if test="record.releaseDate != null">
        release_date = #{record.releaseDate,jdbcType=TIMESTAMP},
      </if>
      <if test="record.advertisement != null">
        advertisement = #{record.advertisement,jdbcType=VARCHAR},
      </if>
      <if test="keyword !=null">
      keyword =#{keyword,jdbcType=VARCHAR},
      </if>
      <if test="summary != null">
      summary =#{summary,jdbcType=VARCHAR},
       </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    update jt_business_project
    set id = #{record.id,jdbcType=VARCHAR},
      name = #{record.name,jdbcType=VARCHAR},
      category_id = #{record.categoryId,jdbcType=VARCHAR},
      number = #{record.number,jdbcType=VARCHAR},
      price = #{record.price,jdbcType=DECIMAL},
      activity_price = #{record.activityPrice,jdbcType=DECIMAL},
      member_price = #{record.memberPrice,jdbcType=DECIMAL},
      offset = #{record.offset,jdbcType=REAL},
      activity_flag = #{record.activityFlag,jdbcType=INTEGER},
      introduce = #{record.introduce,jdbcType=VARCHAR},
      province = #{record.province,jdbcType=INTEGER},
      city = #{record.city,jdbcType=INTEGER},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      min_img_url = #{record.minImgUrl,jdbcType=VARCHAR},
      max_img_url = #{record.maxImgUrl,jdbcType=VARCHAR},
      value = #{record.value,jdbcType=VARCHAR},
      apply_conditions = #{record.applyConditions,jdbcType=VARCHAR},
      owner_id = #{record.ownerId,jdbcType=VARCHAR},
      is_hot = #{record.isHot,jdbcType=INTEGER},
      audit_status = #{record.auditStatus,jdbcType=INTEGER},
      audit_info = #{record.auditInfo,jdbcType=VARCHAR},
      release_date = #{record.releaseDate,jdbcType=TIMESTAMP},
      advertisement = #{record.advertisement,jdbcType=VARCHAR},
      keyword = #{keyword,jdbcType=VARCHAR},#{summary,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.JtBusinessProject">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    update jt_business_project
    <set>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="categoryId != null">
        category_id = #{categoryId,jdbcType=VARCHAR},
      </if>
      <if test="number != null">
        number = #{number,jdbcType=VARCHAR},
      </if>
      <if test="price != null">
        price = #{price,jdbcType=DECIMAL},
      </if>
      <if test="activityPrice != null">
        activity_price = #{activityPrice,jdbcType=DECIMAL},
      </if>
      <if test="memberPrice != null">
        member_price = #{memberPrice,jdbcType=DECIMAL},
      </if>
      <if test="offset != null">
        offset = #{offset,jdbcType=REAL},
      </if>
      <if test="activityFlag != null">
        activity_flag = #{activityFlag,jdbcType=INTEGER},
      </if>
      <if test="introduce != null">
        introduce = #{introduce,jdbcType=VARCHAR},
      </if>
      <if test="province != null">
        province = #{province,jdbcType=INTEGER},
      </if>
      <if test="city != null">
        city = #{city,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="minImgUrl != null">
        min_img_url = #{minImgUrl,jdbcType=VARCHAR},
      </if>
      <if test="maxImgUrl != null">
        max_img_url = #{maxImgUrl,jdbcType=VARCHAR},
      </if>
      <if test="value != null">
        value = #{value,jdbcType=VARCHAR},
      </if>
      <if test="applyConditions != null">
        apply_conditions = #{applyConditions,jdbcType=VARCHAR},
      </if>
      <if test="ownerId != null">
        owner_id = #{ownerId,jdbcType=VARCHAR},
      </if>
      <if test="isHot != null">
        is_hot = #{isHot,jdbcType=INTEGER},
      </if>
      <if test="auditStatus != null">
        audit_status = #{auditStatus,jdbcType=INTEGER},
      </if>
      <if test="auditInfo != null">
        audit_info = #{auditInfo,jdbcType=VARCHAR},
      </if>
      <if test="releaseDate != null">
        release_date = #{releaseDate,jdbcType=TIMESTAMP},
      </if>
      <if test="advertisement != null">
        advertisement = #{advertisement,jdbcType=VARCHAR},
      </if>
      <if test="keyword != null">
      	keyword = #{keyword,jdbcType=VARCHAR},
      </if>
      <if test="summary != null">
      summary = #{summary,jdbcType=VARCHAR},
       </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.JtBusinessProject">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Aug 01 10:34:40 CST 2018.
    -->
    update jt_business_project
    set name = #{name,jdbcType=VARCHAR},
      category_id = #{categoryId,jdbcType=VARCHAR},
      number = #{number,jdbcType=VARCHAR},
      price = #{price,jdbcType=DECIMAL},
      activity_price = #{activityPrice,jdbcType=DECIMAL},
      member_price = #{memberPrice,jdbcType=DECIMAL},
      offset = #{offset,jdbcType=REAL},
      activity_flag = #{activityFlag,jdbcType=INTEGER},
      introduce = #{introduce,jdbcType=VARCHAR},
      province = #{province,jdbcType=INTEGER},
      city = #{city,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      min_img_url = #{minImgUrl,jdbcType=VARCHAR},
      max_img_url = #{maxImgUrl,jdbcType=VARCHAR},
      value = #{value,jdbcType=VARCHAR},
      apply_conditions = #{applyConditions,jdbcType=VARCHAR},
      owner_id = #{ownerId,jdbcType=VARCHAR},
      is_hot = #{isHot,jdbcType=INTEGER},
      audit_status = #{auditStatus,jdbcType=INTEGER},
      audit_info = #{auditInfo,jdbcType=VARCHAR},
      release_date = #{releaseDate,jdbcType=TIMESTAMP},
      advertisement = #{advertisement,jdbcType=VARCHAR},
      keyword = #{keyword,jdbcType=VARCHAR},
      summary =#{summary,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKeyWithModule" resultType="com.goafanti.business.bo.JtBusinessProjectResult">
    select 
        jtbp.id, jtbp.name, jtbp.category_id as categoryId, jtbp.number, jtbp.price, jtbp.activity_price as activityPrice, jtbp.member_price as memberPrice, jtbp.offset, 
        jtbp.activity_flag as activityFlag, u.nickname as ownerName,ifnull(p.count,0) as interestCount,if(isnull(x.project_id),0,1) as interested,jtbp.keyword,jtbp.summary,
    jtbp.introduce, jtbp.province, jtbp.city, jtbp.create_time as createTime, jtbp.min_img_url as minImgUrl, jtbp.max_img_url as maxImgUrl, jtbp.value, jtbp.apply_conditions as applyConditions, 
    jtbp.owner_id as ownerId, jtbp.is_hot as isHot, jtbp.audit_status as auditStatus, jtbp.audit_info as auditInfo, jtbp.release_date as releaseDate,jtbc.module as module,jtbp.advertisement
    ,u.`type` as type
    from jt_business_project jtbp left join `user` u on jtbp.owner_id=u.id
    left join jt_business_category jtbc on jtbc.id =  jtbp.category_id
    left join (select project_id,count(*) as count from project_interest group by project_id) p on jtbp.id=p.project_id
    left join (select project_id from project_interest <if test="uid != null"> where uid= #{uid,jdbcType=VARCHAR} </if>group by project_id) x on jtbp.id=x.project_id
    where jtbp.id = #{id,jdbcType=VARCHAR}
  </select>
  
   <select id="getBusinessProjectByCategoryId" resultType="com.goafanti.common.model.JtBusinessProject">
	  select 
	  	id,
	  	name,
	  	introduce,
	  	min_img_url as minImgUrl
	 from 
	  	jt_business_project
	  	where  audit_status=2
	  	<if test="id!=null">
	  	and category_id= #{id,jdbcType=VARCHAR} 
	  	</if>
	  	<if test="isHot != null">
	  		and is_hot = #{isHot,jdbcType=INTEGER}
	  	</if>
	  	order by release_date desc
	  	limit #{size,jdbcType=INTEGER}
  </select>
  
  <select id="findJtBusinessProjectByPage" resultType="com.goafanti.business.bo.JtBusinessProjectResult">
  select 
	  jtbp.id,  
	  jtbp.name, 
	  jtbp.category_id as categoryId,  
	  jtbp.number,  
	  jtbp.price,  
	  jtbp.activity_price as activityPrice,  
	  jtbp.member_price as memberPrice,  
	  jtbp.offset, 
	  jtbp.activity_flag as activityFlag, 
	  jtbp.introduce,  
	  jtbp.province, jtbp.city,  
	  jtbp.create_time as createTime,
	  jtbp.min_img_url as minImgUrl,
	  jtbp.max_img_url as maxImgUrl, 
	  jtbp.value,  
	  jtbp.apply_conditions as applyConditions,
	  jtbp.is_hot as isHot,
	  jtbp.audit_status as auditStatus,
	  jtbp.release_Date as releaseDate,
	  jtbp.advertisement,
	  jtbp.summary,
	  ifnull(dct.dealCount,0) as dealCount,
	  ifnull(x.count,0) as interestCount,
	  u.nickname as companyName,u.id as companyId,
	  jtbc1.module,
	  u.`type` as type
  from jt_business_project jtbp
  left join user u on u.id=jtbp.owner_id
  left join (select project_id as id,count(*) as count from project_interest group by project_id)x on jtbp.id=x.id
  left join (select sum(commodity_quantity) as dealCount ,commodity_id from jt_order_detail group by commodity_id) dct on jtbp.id=dct.commodity_id
  left join jt_business_category jtbc1 on jtbc1.id = jtbp.category_id
  <if test="topId!=null">
  left join jt_business_category jtbc on jtbc.super_id =#{topId,jdbcType=VARCHAR}
  </if>
  <if test="tag != null">
  left join jt_business_project_tag x on x.project_id=jtbp.id
  left join jt_tag y on x.tag_id=y.id
  </if>
  where 1=1
  <if test="tag != null">
  and y.id= #{tag,jdbcType=VARCHAR}
  </if>
  <if test="module == 0">
  and jtbc1.module &gt; 1
  </if>
  <if test="isHot != null">
  and jtbp.is_hot = #{isHot,jdbcType=INTEGER}
  </if>
  <!-- <if test="module == 1">
  and jtbc1.module =1
  </if> -->
  <if test="module !=null and module !=0">
  and jtbc1.module=#{module,jdbcType=INTEGER}
  </if>
  <if test="secondId!=null">
  and jtbp.category_id=#{secondId,jdbcType=VARCHAR}
  </if>
  <if test="name!=null">
  and jtbp.name like concat("%",#{name,jdbcType=VARCHAR},"%")
  </if>
  <if test="topId!=null">
 and jtbc.id=jtbp.category_id
  </if>
  <if test="ownerId!=null">
  and jtbp.owner_id=#{ownerId,jdbcType=VARCHAR}
  </if>
  <if test="auditStatus!=null">
  and jtbp.audit_status=#{auditStatus,jdbcType=INTEGER}
  </if>
  <if test="orderType!=null and orderType==0">
  order by release_date 
  </if>
  <if test="orderType!=null and orderType==1">
  order by jtbp.price
  </if>
  <if test="orderType!=null and orderType==2">
  order by dct.dealCount
  </if>
  <if test="orderSort!=null and orderSort==0">
   desc
   </if>
  	<if test="page_sql!=null">
		${page_sql}
	</if>
  </select>
  <select id="findJtBusinessCountByPage" resultType="java.lang.Integer">
	 select 
	 count(0)
	 from jt_business_project jtbp
	  <if test="topId!=null">
	  left join jt_business_category jtbc on jtbc.super_id =#{topId,jdbcType=VARCHAR}
	  </if>
	    <if test="module!=null">
  left join jt_business_category jtbc1 on jtbc1.id = jtbp.category_id
  </if>
	<if test="tag != null">
  left join jt_business_project_tag x on x.project_id=jtbp.id
  left join jt_tag y on x.tag_id=y.id
  </if>
  where 1=1 
  <if test="tag != null">
  and y.id= #{tag,jdbcType=VARCHAR}
  </if> 
 <if test="module == 0">
  and jtbc1.module &gt; 1
  </if>
  <if test="isHot != null">
  and jtbp.is_hot = #{isHot,jdbcType=INTEGER}
  </if>
 <!--  <if test="module == 1">
  and jtbc1.module =1
  </if> -->
  <if test="module !=null and module !=0">
  and jtbc1.module=#{module,jdbcType=INTEGER}
  </if>
	  <if test="secondId!=null">
	  and jtbp.category_id=#{secondId,jdbcType=VARCHAR}
	  </if>
	  <if test="name!=null">
	  and jtbp.name like concat("%",#{name,jdbcType=VARCHAR},"%")
	  </if>
	  <if test="topId!=null">
	 and jtbc.id=jtbp.category_id
	  </if>
	    <if test="ownerId!=null">
	  and jtbp.owner_id=#{ownerId,jdbcType=VARCHAR}
	  </if>
	    <if test="auditStatus!=null">
  and jtbp.audit_status=#{auditStatus,jdbcType=INTEGER}
  </if>
  </select>
  
  <select id="findProjectOrderByNumber" resultType="com.goafanti.common.model.JtBusinessProject">
  select
 <include refid="Base_Column_List" />
  from jt_business_project jtbp
  where audit_status=2
  order by create_time desc
  </select>
  <select id="findInterestedProjcet" resultType="com.goafanti.common.model.JtBusinessProject">
  select 
  jtbp.id,  
	  jtbp.name, 
	  jtbp.category_id as categoryId,  
	  jtbp.number,  
	  jtbp.price,  
	  jtbp.activity_price as activityPrice,  
	  jtbp.member_price as memberPrice,  
	  jtbp.offset, 
	  jtbp.activity_flag as activityFlag, 
	  jtbp.introduce,  
	  jtbp.province, jtbp.city,  
	  jtbp.create_time as createTime,
	  jtbp.min_img_url as minImgUrl,
	  jtbp.max_img_url as maxImgUrl, 
	  jtbp.value,  
	  jtbp.apply_conditions as applyConditions,
	  jtbp.is_hot as isHot,
	  jtbp.audit_status as auditStatus,
	  jtbp.release_Date as releaseDate,
	  jtbp.advertisement
   from 
  jt_business_project jtbp
  left join project_interest pi on jtbp.id=pi.project_id
  where pi.uid=#{uid,jdbcType=VARCHAR}
 	<if test="page_sql!=null">
		${page_sql}
	</if>
  </select>
    <select id="findInterestedProjcetCount" resultType="java.lang.Integer">
  select 
  count(0)
   from 
  jt_business_project jtbp
  left join project_interest pi on jtbp.id=pi.project_id
  where pi.uid=#{uid,jdbcType=VARCHAR}
  </select>
  <select id="myCollectionProjectList" resultType="com.goafanti.common.bo.MyCollection">
  select 
  	  jtbp.id,  
	  jtbp.name, 
	  jtbp.advertisement as introduction, 
	  jtbp.price as textA,
	  u.nickname as ownerName,
	  jtbp.min_img_url as ImgUrl,
	  ifnull(p.count,'0') as interestCount
	from 
  jt_business_project jtbp
  left join project_interest pi on jtbp.id=pi.project_id
  left join `user` u on jtbp.owner_id =u.id
  left join (select project_id,count(*) as count from project_interest group by  project_id) p 
  on p.project_id=jtbp.id
  where pi.uid=#{uid,jdbcType=VARCHAR}
  order by pi.create_time desc
  <if test="page_sql!=null">
		${page_sql}
	</if>
  </select>
  <select id="myCollectionProjectCount" resultType="java.lang.Integer">
  select 
  count(0)
   from 
  jt_business_project jtbp
  left join project_interest pi on jtbp.id=pi.project_id
  where pi.uid=#{uid,jdbcType=VARCHAR}
  </select>
  
   <select id="recommendedApplicationList" resultType="com.goafanti.common.bo.MyCollection">
  select a.id,a.name,a.advertisement as introduction,a.price as textA,
  		c.nickname as ownerName,ifnull(d.count,0) as interestCount,a.min_img_url as ImgUrl
  	from jt_business_project a
  	left join jt_business_category b on  a.category_id=b.id
  	left join user c on a.owner_id=c.id
  	left join (select project_id as id,count(*) as count  from project_interest group by project_id) d 
  	on a.id=d.id
  	where  a.is_hot=1 and a.audit_status=2
   <if test="type==1">
  	and b.module != 1 
  	</if>
  	<if test="type==2">
  	and b.module = 5 
  	</if>
  	order by a.release_date desc
  <if test="page_sql!=null">
		${page_sql}
	</if>
  </select>
  <select id="recommendedApplicationCount" resultType="java.lang.Integer">
  select count(*)
  	from jt_business_project a
  	left join jt_business_category b on  a.category_id=b.id
  	where  a.is_hot=1 and a.audit_status=2
  	<if test="type==1">
  	and b.module != 1 
  	</if>
  	<if test="type==2">
  	and b.module = 5 
  	</if>
  </select>
  <!-- 查看科技服务项目   -->
  <select id="getKJListByIds" resultType="com.goafanti.common.model.JtBusinessProject">
    select 
	    p.id,
	  	p.name,
	  	p.introduce,
	  	p.min_img_url as minImgUrl,
	  	p.advertisement
  	from jt_business_project p
    left join jt_business_category c on p.category_id = c.id
    where c.module = #{module} 
    and p.audit_status = 2 
    <if test="isHot">
    and is_hot = #{isHot}
    </if>
    order by release_date desc
	  	limit #{size}
   </select>
	   
	 <!-- 根据二级分类名称查 -->
  <select id="getModuleByName" resultType="com.goafanti.common.model.JtBusinessProject">
	 select  b.id,
	  	b.name,
	  	b.introduce,
	  	b.min_img_url as minImgUrl
	from (select x.id from jt_business_category x inner join jt_business_category y on x.super_id = y.id where y.name=#{name})a 
	left join jt_business_project b on a.id = b.category_id
	where  
	b.audit_status = 2 
	<if test="isHot">
    and is_hot = #{isHot}
    </if>
	order by b.release_date desc 
	limit #{size}
  </select>
  
  <!-- 根据项目标签名称查出拥有该标签的项目  -->
  <select id="getProjectByTag" resultMap="BaseResultMap">
  select p.* from jt_tag t 
  inner join jt_business_project_tag pt on t.id = pt.tag_id
  inner join jt_business_project p on pt.project_id = p.id
  where p.audit_status = 2 and t.name = #{name}
  order by p.release_date desc
  limit #{size}
  </select>
  
</mapper>
