<?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.ReasonMapper">
  <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.financial.Reason">
    <id column="reasonId" jdbcType="VARCHAR" property="reasonId" />
    <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="houseOnWay" jdbcType="VARCHAR" property="houseOnWay" />
    <result column="houseUnconfirmed" jdbcType="VARCHAR" property="houseUnconfirmed" />
    <result column="ncIsWrong" jdbcType="VARCHAR" property="ncIsWrong" />
    <result column="erpIsWrong" jdbcType="VARCHAR" property="erpIsWrong" />
    <result column="notInAmount" jdbcType="VARCHAR" property="notInAmount" />
    <result column="other" jdbcType="VARCHAR" property="other" />
  </resultMap>
  <sql id="Base_Column_List">
    reasonId, projectName, commId, organCode, organName,year,month,houseOnWay,houseUnconfirmed,ncIsWrong,erpIsWrong,notInAmount,other
  </sql>

  <select id="selectReasonsByYear" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from reason
    where year = #{year} AND organCode = #{organCode}
  </select>

  <insert id="insertOrUpdateReason" parameterType="cn.com.countrygarden.bi.main.model.financial.Reason">
    INSERT INTO reason(reasonId,projectName,commId,organCode,organName,year,month,houseOnWay,houseUnconfirmed,ncIsWrong,erpIsWrong,notInAmount,other)
    VALUES (#{reasonId},#{projectName},#{commId},#{organCode},#{organName},#{year},#{month},#{houseOnWay},#{houseUnconfirmed},#{ncIsWrong},#{erpIsWrong},#{notInAmount},#{other}) ON DUPLICATE KEY UPDATE
    reasonId = #{reasonId},projectName = #{projectName},commId = #{commId},organCode = #{organCode},organName = #{organName},year = #{year},month = #{month},
    houseOnWay = #{houseOnWay},houseUnconfirmed = #{houseUnconfirmed},ncIsWrong = #{ncIsWrong},erpIsWrong = #{erpIsWrong},notInAmount = #{notInAmount},other = #{other}
  </insert>
</mapper>