<?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.bigholderAduit.BigholderExceptionInfoMapper">

	<resultMap id="BigholderExceptionInfoMap"
		type="cn.com.countrygarden.bi.main.model.bigholderAduit.BigholderExceptionInfo">
		<id column="id" jdbcType="VARCHAR" property="id" />
		<result column="exception_message" jdbcType="VARCHAR" property="exceptionMessage" />
		<result column="satisfaction_info_id" jdbcType="VARCHAR"
			property="satisfactionInfoId" />
		<result column="exception_aduit_status" jdbcType="VARCHAR"
			property="exceptionAduitStatus" />
		<result column="year_mon" jdbcType="VARCHAR" property="yearMonth" />
		<result column="tb_user_id" jdbcType="VARCHAR" property="tbUserId" />
		<result column="area" jdbcType="VARCHAR" property="area" />
		<result column="original_project_name" jdbcType="VARCHAR"
			property="originalProjectName" />
		<result column="correspond_project" jdbcType="INTEGER"
			property="correspondProject" />
		<result column="jobs" jdbcType="VARCHAR" property="jobs" />
		<result column="total_score" jdbcType="VARCHAR" property="totalScore" />
	</resultMap>

	<select id="selectBySatisfactionInfoId" resultMap="BigholderExceptionInfoMap">
		select * from bigholder_exception_info as b where b.satisfaction_info_id=#{satisfactionInfoId}
	</select>

	<select id="getBigholderExceptionInfo" resultMap="BigholderExceptionInfoMap">
		SELECT * FROM bigholder_exception_info AS b
		<where>
			1=1
			<if test="yearMonth!=null">
				AND b.year_mon=#{yearMonth}
			</if>
			<if test="area!=null">
				AND b.area=#{area}
			</if>
			<if test="exceptionAuditStruts!=null">
				AND b.exception_aduit_status=#{exceptionAuditStruts}
			</if>
		</where>
		order by b.area
	</select>

	<select id="getExByAreasOrOther" resultMap="BigholderExceptionInfoMap">
		SELECT * FROM bigholder_exception_info AS b
		<where>
			1=1
			<if test="yearMonth!=null">
				AND b.year_mon=#{yearMonth}
			</if>
			<if test="areas!=null">
				AND b.area IN
				<foreach item="item" index="index" collection="areas" open="("
					separator="," close=")">
					#{item}
				</foreach>
			</if>
			<if test="exceptionStruts!=null">
				AND b.exception_aduit_status=#{exceptionStruts}
			</if>
		</where>
		order by b.area
	</select>

	<select id="selectById" parameterType="String"
		resultMap="BigholderExceptionInfoMap">
		SELECT * FROM bigholder_exception_info AS b
		WHERE b.id=#{id}
	</select>

	<select id="findExceptionAll" parameterType="String"
		resultMap="BigholderExceptionInfoMap">
		SELECT * FROM bigholder_exception_info AS b
		WHERE
		b.year_mon=#{yearMonth}
	</select>

	<update id="updateBigholderExceptionInfo" parameterType="Map">
		UPDATE
		bigholder_exception_info b
		<trim prefix="set" suffixOverrides=",">
			<if test="auditStatus!=null">
				b.exception_aduit_status=#{auditStatus},
			</if>
			<if test="exceptionMessage!=null">
				b.exception_message=#{exceptionMessage},
			</if>
			<if test="area!=null">
				b.area=#{area},
			</if>
				b.correspond_project=#{correspondProject}
		</trim>
		WHERE b.id=#{id}
	</update>

	<update id="updateExceptionStatus"
		parameterType="cn.com.countrygarden.bi.main.model.bigholderAduit.BigholderExceptionInfo">
		UPDATE
		bigholder_exception_info b
		set
		b.exception_aduit_status=#{exceptionAduitStatus}
		WHERE b.id=#{id}
	</update>

	<insert id="insertBigholderExceptionInfo"
		parameterType="cn.com.countrygarden.bi.main.model.bigholderAduit.BigholderExceptionInfo">
		<![CDATA[
		INSERT INTO bigholder_exception_info (
		exception_message,
		satisfaction_info_id,
		exception_aduit_status,
		tb_user_id,
		year_mon,
		area,
		original_project_name,
		correspond_project,
		jobs,
		total_score
		)
		VALUE (
			#{exceptionMessage},
			#{satisfactionInfoId},
			#{exceptionAduitStatus},
			#{tbUserId},
			#{yearMonth},
			#{area},
			#{originalProjectName},
			#{correspondProject},
			#{jobs},
			#{totalScore}
		)
		 ]]>
	</insert>
	<insert id="deleteBigholderExInfo">
		DELETE FROM bigholder_exception_info
		WHERE
		id=#{id}
	</insert>
</mapper>