<?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.sysnumberinfo.dao.SysNumberInfoDao">
    
	<sql id="sysNumberInfoColumns">
		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.name AS "name",
		a.first AS "first",
		a.separators AS "separator",
		a.year AS "year",
		a.mouth AS "mouth",
		a.day AS "day",
		a.identifier AS "identifier",
		a.sequences AS "sequence",
		a.num_length AS "numLength",
		a.num_first AS "numFirst",
		a.example AS "example",
		c.id AS "sysNumberClass.id",
		c.name AS "sysNumberClass.name"
		
	</sql>
	
	<sql id="sysNumberInfoJoins">
	   LEFT JOIN sys_number_class c ON c.id = a.class_id
	</sql>
	
    
	<select id="get" resultType="SysNumberInfo" >
		SELECT 
			<include refid="sysNumberInfoColumns"/>
		FROM sys_number_info a
		<include refid="sysNumberInfoJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="SysNumberInfo" >
		SELECT 
			<include refid="sysNumberInfoColumns"/>
		FROM sys_number_info a
		<include refid="sysNumberInfoJoins"/>
		<where>
			
			<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="sysNumberClass != null and sysNumberClass.id != null and sysNumberClass.id != ''">
				AND a.class_id = #{sysNumberClass.id}
			</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="SysNumberInfo" >
		SELECT 
			<include refid="sysNumberInfoColumns"/>
		FROM sys_number_info a
		<include refid="sysNumberInfoJoins"/>
		<where>
			
		</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_number_info(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			name,
			first,
			separators,
			year,
			mouth,
			day,
			identifier,
			sequences,
			class_id,
			num_length,
			num_first,
			example
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{name},
			#{first},
			#{separator},
			#{year},
			#{mouth},
			#{day},
			#{identifier},
			#{sequence},
			#{sysNumberClass.id},
			#{numLength},
			#{numFirst},
			#{example}
		)
	</insert>
	
	<update id="update">
		UPDATE sys_number_info SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			name = #{name},
			first = #{first},
			separators = #{separator},
			year = #{year},
			mouth = #{mouth},
			day = #{day},
			identifier = #{identifier},
			sequences = #{sequence},
			class_id = #{sysNumberClass.id},
			num_length = #{numLength},
			num_first = #{numFirst},
			example = #{example}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM sys_number_info
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE sys_number_info SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="SysNumberInfo" statementType="STATEMENT">
		select * FROM sys_number_info  where ${propertyName} = '${value}'
	</select>
	
</mapper>