<?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.sunxung.factoring.mapper.project.BusinessAssigneeMapper">

	<resultMap type="BusinessAssignee" id="assigneeResult">
		<result property="id" column="id" />
		<result property="businessKey" column="business_key" />
		<result property="businessType" column="business_type" />
		<result property="assigneeId" column="assignee_id" />
		<result property="candidateId" column="candidate_id" />
		<result property="assigneeType" column="assignee_type" />
		<result property="userCreate" column="user_create" />
		<result property="userModified" column="user_modified" />
		<result property="gmtCreate" column="gmt_create" />
		<result property="gmtModified" column="gmt_modified" />
	</resultMap>

	<sql id="fields">
		p.id,
		p.business_key,
		p.business_type,
		p.assignee_id,
		p.candidate_id,
		p.assignee_type,
		p.user_create,
		p.user_modified,
		p.gmt_create,
		p.gmt_modified
	</sql>

	<insert id="add" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="BusinessAssignee">
		INSERT INTO business_assignee
		(
			business_key,business_type,assignee_id,assignee_type,candidate_id,user_create
		)
		VALUES
		(
			#{businessKey},#{businessType},#{assigneeId},#{assigneeType},#{candidateId},#{userCreate}
		)
	</insert>

	<update id="update" parameterType="BusinessAssignee">
		UPDATE business_assignee
		SET
			assignee_id=#{assigneeId}
		WHERE id=#{id}
	</update>

	<select id="get" parameterType="java.lang.Long" resultMap="assigneeResult">
		SELECT <include refid="fields"/> FROM business_assignee p WHERE p.id=#{value}
	</select>

	<select id="getByBusiness" resultMap="assigneeResult">
		SELECT
			<include refid="fields"/>
		FROM
			business_assignee p
		WHERE
			p.business_key=#{businessKey}
			AND p.business_type=#{businessType}
			AND p.assignee_type=#{assigneeType}
	</select>

	<select id="findIdsByBusiness" resultType="java.lang.Long">
		SELECT
			p.assignee_id
		FROM
			business_assignee p
		WHERE
			p.business_key=#{businessKey}
			AND p.business_type=#{businessType}
	</select>
</mapper>
