<?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.house365.ws.dao.mapper.ProjectMapper">

    <resultMap id="projectDynamic" type="com.house365.beans.entity.ProjectEntity">
        <result property="id" column="id"/>
        <result property="projectId" column="projectId"/>
        <result property="createUserid" column="createUserid"/>
        <result property="createUsername" column="createUsername"/>
        <result property="createTime" column="createTime"/>
        <result property="dynamicId" column="dynamicId"/>
        <result property="dynamicContent" column="dynamicContent"/>
    </resultMap>

    <select id="getDynamicById" parameterType="com.house365.beans.entity.ProjectDynamicEntity"
            resultMap="projectDynamic">
        select id,projectId,createUserid,createUsername,createTime,dynamicId,dynamicContent
        from project_dynamic
        where projectId = #{projectId}
        ORDER BY id desc
        limit #{pageNo}, #{pageSize}
    </select>

    <resultMap id="infoMap" type="com.house365.beans.entity.ProjectEntity">
        <result property="id" column="id"/>
        <result property="contractCode" column="contractCode"/>
        <result property="projectCode" column="projectCode"/>
        <result property="projectName" column="projectName"/>
        <result property="buildingId" column="buildingId"/>
        <result property="buildingName" column="buildingName"/>
        <result property="status" column="status"/>
        <result property="showStatus" column="showStatus"/>
        <result property="manager" column="manager"/>
        <result property="type" column="type"/>
        <result property="business" column="business"/>
        <result property="kfs" column="kfs"/>
        <result property="city" column="city"/>
        <result property="cityName" column="cityName"/>
        <result property="district" column="district"/>
        <result property="address" column="address"/>
        <result property="startTime" column="startTime"/>
        <result property="source" column="source"/>
        <result property="jitInfo" column="jitInfo"/>
        <result property="hireMoney" column="hireMoney"/>
        <result property="createUserid" column="createUserid"/>
        <result property="createUsername" column="createUsername"/>
        <result property="createTime" column="createTime"/>
        <result property="createIp" column="createIp"/>
        <result property="updateUserid" column="updateUserid"/>
        <result property="updateUsername" column="updateUsername"/>
        <result property="updateTime" column="updateTime"/>
        <result property="updateIp" column="updateIp"/>
        <result property="shorttel" column="shorttel"/>
    </resultMap>

    <select id="queryNameById" parameterType="Integer" resultMap="infoMap">
        select id, contractCode, projectCode, projectName, buildingId, buildingName
        from project
        where id = #{projectId}
    </select>

    <update id="updateCode" parameterType="map">
        UPDATE project
        SET
        contractCode = #{contractCode}
        where id = #{id}
    </update>

    <select id="queryByConditions" parameterType="map" resultMap="infoMap">
        select *
        FROM project
        where 1 = 1
        <if test="contractCode != null and contractCode != '' ">
            AND contractCode = #{contractCode}
        </if>
        <if test="city != null and city != '' ">
            AND city = #{city}
        </if>
        <if test="projectName != null and projectName != '' ">
            AND projectName = #{projectName}
        </if>
        <if test="showStatus != null and showStatus > 0 ">
            AND showStatus = #{showStatus}
        </if>
        <if test="buildingId != null and buildingId > 0 ">
            AND buildingId = #{buildingId}
        </if>
        <if test="cityList != null and cityList.size() > 0 ">
            AND city in
            <foreach collection="cityList" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
    </select>

    <select id="getById" parameterType="Integer" resultMap="infoMap">
        select *
        FROM project
        where id = #{id}
    </select>

</mapper>