<?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.CertificateDao">
    
	<sql id="certificateColumns">
		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.sys_user_info_id AS "userInfoId",
		a.name AS "name",
		a.number AS "number",
		a.profession AS "profession",
		a.level AS "level",
		a.get_date AS "getDate",
		a.end_date AS "endDate"
	</sql>
	
	<sql id="certificateJoins">
	</sql>
	
	<select id="getListByUserInfoId" resultType="Certificate">
		SELECT <include refid="certificateColumns"/>
		FROM  sys_certificate a
		<where>
			a.del_flag = '0'
			<if test="userInfoId != null and userInfoId != ''">
				AND a.sys_user_info_id = #{userInfoId}
			</if>
		</where>
	</select>
    
	<select id="get" resultType="Certificate" >
		SELECT 
			<include refid="certificateColumns"/>
		FROM sys_certificate a
		<include refid="certificateJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="Certificate" >
		SELECT 
			<include refid="certificateColumns"/>
		FROM sys_certificate a
		<include refid="certificateJoins"/>
		<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>
	
	<select id="findAllList" resultType="Certificate" >
		SELECT 
			<include refid="certificateColumns"/>
		FROM sys_certificate a
		<include refid="certificateJoins"/>
		<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_certificate(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			sys_user_info_id,
			name,
			number,
			profession,
			level,
			get_date,
			end_date
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{userInfoId},
			#{name},
			#{number},
			#{profession},
			#{level},
			#{getDate},
			#{endDate}
		)
	</insert>
	
	<update id="update">
		UPDATE sys_certificate SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			sys_user_info_id = #{userInfoId},
			name = #{name},
			number = #{number},
			profession = #{profession},
			level = #{level},
			get_date = #{getDate},
			end_date = #{endDate}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM sys_certificate
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE sys_certificate SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="Certificate" statementType="STATEMENT">
		select * FROM sys_certificate  where ${propertyName} = '${value}'
	</select>
	
</mapper>