<?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.officequalify.dao.OfficequalifyDao">
    
	<sql id="officequalifyColumns">
		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.qualify_grade AS "qualifyGrade",
		a.specialty AS "specialty",
		a.first_date AS "firstDate",
		a.end_date AS "endDate",
		a.continue_date AS "continueDate",
		a.issued_agency AS "issuedAgency",
		a.introduction AS "introduction",
		a.image AS "image",
		a.company_name AS "companyName",
		a.num AS "num",
		a.upload_date AS "uploadDate",
		wa.attachment_name AS "uName",
		office.name AS "office.name",
		a.company_id AS "companyId",
		wa.url AS "url",
		a.sysoffice_id AS "office.id"
	</sql>
	
	<sql id="officequalifyJoins">
		LEFT JOIN sys_office office ON office.id = a.sysoffice_id
		LEFT join work_attachment wa on wa.attachment_id = a.id
	</sql>
	
    
	<select id="get" resultType="Officequalify" >
		SELECT 
			<include refid="officequalifyColumns"/>
		FROM office_qualify a
		<include refid="officequalifyJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="Officequalify" >
		SELECT 
			<include refid="officequalifyColumns"/>
		FROM office_qualify a
		<include refid="officequalifyJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL} and wa.attachment_flag = '109'
			<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="(companyId == null or companyId == '') and office != null and office.id != null and office.id != ''">
				AND a.sysoffice_id = #{office.id}
			</if>
			<if test="companyId != null and companyId != ''">
				AND a.company_id = #{companyId}
			</if>
			<if test="companyName != null and companyName != ''">
				AND a.company_name LIKE
				<if test="dbName == 'oracle'">'%'||#{companyName}||'%'</if>
				<if test="dbName == 'mssql'">'%'+#{companyName}+'%'</if>
				<if test="dbName == 'mysql'">concat('%',#{companyName},'%')</if>
			</if>
			<if test="qualifyGrade != null and qualifyGrade != ''">
				AND a.qualify_grade = #{qualifyGrade}
			</if>
			<if test="specialty != null and specialty != ''">
				AND a.specialty = #{specialty}
			</if>
			<if test="issuedAgency != null and issuedAgency != ''">
				AND a.issued_agency = #{issuedAgency}
			</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="Officequalify" >
		SELECT 
			<include refid="officequalifyColumns"/>
		FROM office_qualify a
		<include refid="officequalifyJoins"/>
		<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 office_qualify(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			name,
			qualify_grade,
			specialty,
			first_date,
			end_date,
			continue_date,
			issued_agency,
			introduction,
			image,
			company_name,
		    num,
		    upload_date,
		    company_id,
			sysoffice_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{name},
			#{qualifyGrade},
			#{specialty},
			#{firstDate},
			#{endDate},
			#{continueDate},
			#{issuedAgency},
			#{introduction},
			#{image},
			#{companyName},
			#{num},
			#{uploadDate},
			#{companyId},
			#{office.id}
		)
	</insert>
	
	<update id="update">
		UPDATE office_qualify SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			name = #{name},
			qualify_grade = #{qualifyGrade},
			specialty = #{specialty},
			first_date = #{firstDate},
			end_date = #{endDate},
			continue_date = #{continueDate},
			issued_agency = #{issuedAgency},
			introduction = #{introduction},
			image = #{image},
			company_name = #{companyName},
			num = #{num},
			upload_date = #{uploadDate},
			company_id = #{companyId},
			sysoffice_id = #{office.id}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM office_qualify
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE office_qualify SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="Officequalify" statementType="STATEMENT">
		select * FROM office_qualify  where ${propertyName} = '${value}'
	</select>
	
	<select id="findListByoffice" resultType="Office">
		SELECT 
			*
		FROM sys_office a
		<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>
		</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>
</mapper>