<?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.sysimportinfo.dao.SysImportInfoDao">
    
	<sql id="sysimportinfoColumns">
		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.url AS "url",
		a.file_name AS "fileName",
		a.err_info AS "errInfo",
		a.err_count AS "errCount",
		a.is_true AS "isTrue",
		a.modular AS "modular",
		a.company_id AS "companyId",
		a.office_id AS "officeId",
		u.name AS "createBy.name"
	</sql>
	
	<sql id="sysimportinfoJoins">
		JOIN sys_office o ON o.id = a.office_id
		JOIN sys_office s ON s.id = a.company_id
		JOIN sys_user u on u.id = a.create_by
	</sql>
	
    
	<select id="get" resultType="Sysimportinfo" >
		SELECT 
			<include refid="sysimportinfoColumns"/>
		FROM sys_import_info a
		<include refid="sysimportinfoJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="Sysimportinfo" >
		SELECT 
			<include refid="sysimportinfoColumns"/>
		FROM sys_import_info a
		<include refid="sysimportinfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="modular != null and modular != ''">
				AND a.modular = #{modular}
			</if>
			<if test="createBy != null and createBy.name != null and createBy.name != ''">
				AND u.name LIKE
				<if test="dbName == 'oracle'">'%'||#{createBy.name}||'%'</if>
				<if test="dbName == 'mssql'">'%'+#{createBy.name}+'%'</if>
				<if test="dbName == 'mysql'">concat('%',#{createBy.name},'%')</if>
			</if>
			<if test="isTrue != null and isTrue != ''">
				AND a.is_true = #{isTrue}
			</if>
			${sqlMap.dsf}
		</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="Sysimportinfo" >
		SELECT 
			<include refid="sysimportinfoColumns"/>
		FROM sys_import_info a
		<include refid="sysimportinfoJoins"/>
		<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_import_info(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			url,
			file_name,
			err_info,
			err_count,
			is_true,
			modular,
			company_id,
			office_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{url},
			#{fileName},
			#{errInfo},
			#{errCount},
			#{isTrue},
			#{modular},
			#{companyId},
			#{officeId}
		)
	</insert>
	
	<update id="update">
		UPDATE sys_import_info SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			url = #{url},
			file_name = #{fileName},
			err_info = #{errInfo},
			err_count = #{errCount},
			is_true = #{isTrue},
			modular = #{modular},
			company_id = #{companyId},
			office_id = #{officeId}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM sys_import_info
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE sys_import_info SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="Sysimportinfo" statementType="STATEMENT">
		select * FROM sys_import_info  where ${propertyName} = '${value}'
	</select>
	
</mapper>