<?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.jeeplus.modules.sys.dao.JudgeDao">
    
	<sql id="judgeColumns">
		a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.name AS "name",
		a.number AS "number",
		a.gender AS "gender",
		a.birthday AS "birthday",
		a.company_name AS "companyName",
		a.title_level AS "titleLevel",
		a.mobile AS "mobile",
		a.registration_qualification AS "registrationQualification",
		a.email AS "email",
		a.qq AS "qq",
		a.idcard AS "idcard",
		a.address AS "address",
		a.consult_type AS "consultType",
		a.consult_profession AS "consultProfession",
		a.is_retire AS "isRetire",
		a.performance AS "performance",
		a.qualification_credentials AS "qualificationCredentials",
		a.qualification_credentials_more AS "qualificationCredentialsMore"
	</sql>
	
	<sql id="judgeJoins">
	</sql>

	<select id="selectJudgeMembers" resultType="Judge">
		SELECT <include refid="judgeColumns"/>
		FROM sys_judge a
		WHERE a.del_flag = '0'
		AND a.consult_type = #{consultType}
		ORDER BY rand() limit #{judgeCount}
	</select>
	
	<select id="selectJudgeMembersBak" resultType="Judge">
		SELECT <include refid="judgeColumns"/>
		FROM sys_judge a
		WHERE a.del_flag = '0'
		AND a.consult_type = #{consultType}
		<if test="judgeMembers != null and judgeMembers !=''">
			AND instr(#{judgeMembers},a.id)=0
		</if>
		ORDER BY rand() limit #{judgeCount}
	</select>
    
	<select id="get" resultType="Judge" >
		SELECT 
			<include refid="judgeColumns"/>
		FROM sys_judge a
		<include refid="judgeJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="Judge" >
		SELECT 
			<include refid="judgeColumns"/>
		FROM sys_judge a
		<include refid="judgeJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="name != null and name != ''">
				AND a.name LIKE 
					<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
			</if>
			<if test="mobile != null and mobile != ''">
				AND a.mobile LIKE 
					<if test="dbName == 'oracle'">'%'||#{mobile}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{mobile}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{mobile},'%')</if>
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="Judge" >
		SELECT 
			<include refid="judgeColumns"/>
		FROM sys_judge a
		<include refid="judgeJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO sys_judge(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			name,
			number,
			gender,
			birthday,
			company_name,
			title_level,
			mobile,
			registration_qualification,
			email,
			qq,
			idcard,
			address,
			consult_type,
			consult_profession,
			is_retire,
			performance,
			qualification_credentials,
			qualification_credentials_more
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{name},
			#{number},
			#{gender},
			#{birthday},
			#{companyName},
			#{titleLevel},
			#{mobile},
			#{registrationQualification},
			#{email},
			#{qq},
			#{idcard},
			#{address},
			#{consultType},
			#{consultProfession},
			#{isRetire},
			#{performance},
			#{qualificationCredentials},
			#{qualificationCredentialsMore}
		)
	</insert>
	
	<update id="update">
		UPDATE sys_judge SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			name = #{name},
			number = #{number},
			gender = #{gender},
			birthday = #{birthday},
			company_name = #{companyName},
			title_level = #{titleLevel},
			mobile = #{mobile},
			registration_qualification = #{registrationQualification},
			email = #{email},
			qq = #{qq},
			idcard = #{idcard},
			address = #{address},
			consult_type = #{consultType},
			consult_profession = #{consultProfession},
			is_retire = #{isRetire},
			performance = #{performance},
			qualification_credentials = #{qualificationCredentials},
			qualification_credentials_more = #{qualificationCredentialsMore}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM sys_judge
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE sys_judge SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="Judge" statementType="STATEMENT">
		select * FROM sys_judge  where ${propertyName} = '${value}'
	</select>
	
</mapper>