<?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.workprequalification.dao.WorkProjectLinkmanDao">
    
	<sql id="workProjectLinkmanColumns">
		a.id AS "id",
		a.name AS "name",
		a.position AS "position",
		a.qq AS "qq",
		a.link_phone AS "linkPhone",
		a.link_mobile AS "linkMobile",
		a.email AS "email",
		a.is_default AS "isDefault",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.del_flag AS "delFlag",
		a.client_id AS "clientId",
		a.project_id AS "projectId"
	</sql>
	
	<sql id="workProjectLinkmanJoins">
		LEFT JOIN work_client_info b ON b.id = a.client_id
		LEFT JOIN work_prequalification c ON c.id = a.project_id
	</sql>
	
    
	<select id="get" resultType="WorkProjectLinkman" >
		SELECT 
			<include refid="workProjectLinkmanColumns"/>
		FROM work_project_linkman a
		<include refid="workProjectLinkmanJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkProjectLinkman" >
		SELECT 
			<include refid="workProjectLinkmanColumns"/>
		FROM work_project_linkman a
		<include refid="workProjectLinkmanJoins"/>
		<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="clientId != null and clientId != ''">
				AND a.client_id = #{clientId}
			</if>
			<if test="projectId != null and projectId != ''">
				AND a.project_id = #{projectId}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.create_date ASC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="WorkClientLinkman" >
		SELECT 
			<include refid="workProjectLinkmanColumns"/>
		FROM work_project_linkman a
		<include refid="workProjectLinkmanJoins"/>
		<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.create_date ASC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO work_project_linkman(
			id,
			name,
			position,
			qq,
			link_phone,
			link_mobile,
			email,
			is_default,
			create_by,
			create_date,
			update_by,
			update_date,
			del_flag,
			client_id,
			project_id
		) VALUES (
			#{id},
			#{name},
			#{position},
			#{qq},
			#{linkPhone},
			#{linkMobile},
			#{email},
			#{isDefault},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{delFlag},
			#{clientId},
			#{projectId}
		)
	</insert>
	
	<update id="update">
		UPDATE work_project_linkman SET 	
			name = #{name},
			position = #{position},
			qq = #{qq},
			link_phone = #{linkPhone},
			link_mobile = #{linkMobile},
			email = #{email},
			is_default = #{isDefault},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			client_id = #{clientId},
			project_id = #{projectId}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_project_linkman
		<choose>
			<when test="id !=null and id != ''">
				WHERE id = #{id}
			</when>
			<otherwise>
				WHERE project_id = #{projectId}
			</otherwise>
		</choose>
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_project_linkman SET 
			del_flag = #{DEL_FLAG_DELETE}
		<choose>
			<when test="id !=null and id != ''">
				WHERE id = #{id}
			</when>
			<otherwise>
				WHERE project_id = #{projectId}
			</otherwise>
		</choose>
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkClientLinkman" statementType="STATEMENT">
		select * FROM work_project_linkman  where ${propertyName} = '${value}'
	</select>
	
</mapper>