<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.yifu.cloud.plus.v1.yifu.social.mapper.FailReasonConfigMapper">

	<resultMap id="failReasonConfigMap" type="com.yifu.cloud.plus.v1.yifu.social.entity.FailReasonConfig">
		<id property="id" column="ID"/>
		<result property="reason" column="REASON"/>
		<result property="reasonKey" column="REASON_KEY"/>
		<result property="simpleReason" column="SIMPLE_REASON"/>
		<result property="replay" column="REPLAY"/>
		<result property="status" column="STATUS"/>
		<result property="createTime" column="CREATE_TIME"/>
		<result property="createName" column="CREATE_NAME"/>
		<result property="updateTime" column="UPDATE_TIME"/>
		<result property="updateBy" column="UPDATE_BY"/>
		<result property="updateName" column="UPDATE_NAME"/>
		<result property="isReplace" column="IS_REPLACE"/>
		<result property="replaceLeft" column="REPLACE_LEFT"/>
		<result property="replaceRight" column="REPLACE_RIGHT"/>
		<result property="huId" column="hu_id"/>
	</resultMap>
	<sql id="Base_Column_List">
		a.ID,
                a.REASON,
                a.REASON_KEY,
                a.SIMPLE_REASON,
                a.REPLAY,
                a.`STATUS`,
                a.CREATE_TIME,
                a.CREATE_NAME,
				a.CREATE_BY,
                a.UPDATE_TIME,
                a.UPDATE_BY,
				a.UPDATE_NAME,
				a.IS_REPLACE,
				a.REPLACE_LEFT,
				a.REPLACE_RIGHT
	</sql>
	<sql id="failReasonConfig_where">
		<if test="failReasonConfig != null">
			<if test="failReasonConfig.reason != null and failReasonConfig.reason.trim() != ''">
				AND a.REASON LIKE concat('%',#{failReasonConfig.reason},'%')
			</if>
			<if test="failReasonConfig.reasonKey != null and failReasonConfig.reasonKey.trim() != ''">
				AND a.REASON_KEY = #{failReasonConfig.reasonKey}
			</if>
			<if test="failReasonConfig.simpleReason != null and failReasonConfig.simpleReason.trim() != ''">
				AND a.SIMPLE_REASON = #{failReasonConfig.simpleReason}
			</if>
			<if test="failReasonConfig.replay != null and failReasonConfig.replay.trim() != ''">
				AND a.REPLAY = #{failReasonConfig.replay}
			</if>
			<if test="failReasonConfig.status != null and failReasonConfig.status.trim() != ''">
				AND a.STATUS = #{failReasonConfig.status}
			</if>
			<if test="failReasonConfig.isReplace != null and failReasonConfig.isReplace.trim() != ''">
				AND a.IS_REPLACE = #{failReasonConfig.isReplace}
			</if>
		</if>
	</sql>
	<!--failReasonConfig简单分页查询-->
	<select id="getFailReasonConfigPage" resultMap="failReasonConfigMap">
		SELECT
		<include refid="Base_Column_List"/>
		FROM fail_reason_config a
		<where>
			1=1
			<include refid="failReasonConfig_where"/>
		</where>
		order by a.CREATE_TIME desc
	</select>

	<!--查列表-->
	<select id="getFailListByReasonKey" resultMap="failReasonConfigMap">
		SELECT
			a.ID,
			a.REASON_KEY,
			a.REPLAY
		FROM fail_reason_config a
		where a.STATUS = '0'
		<if test="reasonKey != null and reasonKey.trim() != ''">
			AND a.REASON_KEY = #{reasonKey}
		</if>
		order by a.CREATE_TIME desc
	</select>

	<!--获取list组装map来使用 hgw-->
	<select id="getFailReasonConfigList" resultMap="failReasonConfigMap">
		SELECT
			<include refid="Base_Column_List"/>
		FROM fail_reason_config a
		where a.status = '0'
	</select>
	<!--获取户配置的list组装map来使用 hgw-->
	<select id="getFailReasonConfigListByHu" resultMap="failReasonConfigMap">
		SELECT
			a.ID,
			a.REASON,
			a.REASON_KEY,
			a.SIMPLE_REASON,
			r.REPLAY,
			a.STATUS,
			a.CREATE_TIME,
			a.CREATE_NAME,
			a.CREATE_BY,
			a.UPDATE_TIME,
			a.UPDATE_BY,
			a.UPDATE_NAME,
			a.IS_REPLACE,
			a.REPLACE_LEFT,
			a.REPLACE_RIGHT
			,r.id hu_id
		FROM sys_house_hold_info_fail_res r
		LEFT JOIN fail_reason_config a on r.FAIL_ID=a.id
		where a.status = '0'
	</select>
</mapper>