<?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="cn.com.countrygarden.bi.main.dao.financial.ProjectProfitMapper">
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.financial.ProjectProfit">
        <result column="projectId" jdbcType="VARCHAR" property="projectId"/>
        <result column="projectName" jdbcType="VARCHAR" property="projectName"/>
        <result column="commId" jdbcType="VARCHAR" property="commId"/>
        <result column="organCode" jdbcType="VARCHAR" property="organCode"/>
        <result column="organName" jdbcType="VARCHAR" property="organName"/>
        <result column="year" jdbcType="VARCHAR" property="year"/>
        <result column="month" jdbcType="VARCHAR" property="month"/>
        <result column="item" jdbcType="VARCHAR" property="item"/>
        <result column="projectStage" jdbcType="VARCHAR" property="projectStage"/>
        <result column="incomeWithOutTax" jdbcType="VARCHAR" property="incomeWithOutTax"/>
        <result column="profit" jdbcType="VARCHAR" property="profit"/>
        <result column="profitRate" jdbcType="VARCHAR" property="profitRate"/>
    </resultMap>
    <sql id="Base_Column_List">
    projectId, projectName, commId, organCode, organName,year,month,item,projectStage,incomeWithOutTax,profit,profitRate
  </sql>
    <select id="selectProjectProfit" resultType="cn.com.countrygarden.bi.main.model.financial.ProjectProfit">
        select *
        from ProjectProfit
        where 1=1
        and commId in
        <foreach item="commId" index="index" collection="commIdList" open="(" separator="," close=")">
        #{commId}
        </foreach>
        and year = #{year}
    </select>

    <insert id="insertOrUpdateProjectProfit" parameterType="cn.com.countrygarden.bi.main.model.financial.ProjectProfit">
      INSERT INTO project_profit(projectId,projectName,commId,organCode,organName,year,month,item,projectStage,incomeWithOutTax,profit,profitRate)
	  VALUES (#{projectId},#{projectName},#{commId},#{organCode},#{organName},#{year},#{month},#{item},#{projectStage},#{incomeWithOutTax},#{profit},#{profitRate}) ON DUPLICATE KEY UPDATE
	  projectId = #{projectId},projectName = #{projectName},commId = #{commId},organCode = #{organCode},organName = #{organName},year = #{year},month = #{month},
	  item = #{item},projectStage = #{projectStage},incomeWithOutTax = #{incomeWithOutTax},profit = #{profit},profitRate = #{profitRate}
    </insert>

    <select id="selectProfitByOrganYearMonth" resultMap="BaseResultMap">
      SELECT <include refid="Base_Column_List"/> FROM project_profit
      WHERE organCode = #{organCode} AND year = #{year} AND month = #{month}
    </select>


</mapper>