<?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.ym.mec.biz.dal.dao.CooperationOrganLinkmanDao">

	<resultMap type="com.ym.mec.biz.dal.entity.CooperationOrganLinkman"
		id="CooperationOrganLinkman">
		<result column="id_" property="id" />
		<result column="cooperation_organ_id_" property="cooperationOrganId" />
		<result column="linkman_" property="linkman" />
		<result column="mobile_no_" property="mobileNo" />
		<result column="job_" property="job" />
		<result column="create_time_" property="createTime" />
		<result column="tenant_id_" property="tenantId" />
	</resultMap>

	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="CooperationOrganLinkman">
		SELECT *
		FROM cooperation_organ_linkman WHERE id_ = #{id}
	</select>

	<!-- 全查询 -->
	<select id="findAll" resultMap="CooperationOrganLinkman">
		SELECT * FROM
		cooperation_organ_linkman where tenant_id_ = #{tenantId} ORDER BY id_
	</select>

	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.CooperationOrganLinkman"
		useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!-- <selectKey resultClass="int" keyProperty="id" > SELECT SEQ_WSDEFINITION_ID.nextval 
			AS ID FROM DUAL </selectKey> -->
		INSERT INTO cooperation_organ_linkman
		(id_,cooperation_organ_id_,linkman_,mobile_no_,job_,create_time_,tenant_id_)
		VALUES(#{id},#{cooperationOrganId},#{linkman},#{mobileNo},#{job},#{createTime},#{tenantId})
	</insert>
	
	<insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO cooperation_organ_linkman
		(id_,cooperation_organ_id_,linkman_,mobile_no_,job_,create_time_,tenant_id_)
		VALUES
		<foreach collection="list" item="item" separator=",">
		(#{item.id},#{item.cooperationOrganId},#{item.linkman},#{item.mobileNo},#{item.job},#{item.createTime},#{item.tenantId})
		</foreach>
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.CooperationOrganLinkman">
		UPDATE cooperation_organ_linkman
		<set>
			<if test="cooperationOrganId != null">
				cooperation_organ_id_ = #{cooperationOrganId},
			</if>
			<if test="job != null">
				job_ = #{job},
			</if>
			<if test="id != null">
				id_ = #{id},
			</if>
			<if test="linkman != null">
				linkman_ = #{linkman},
			</if>
			<if test="mobileNo != null">
				mobile_no_ = #{mobileNo},
			</if>
			<if test="createTime != null">
				create_time_ = #{createTime},
			</if>
		</set>
		WHERE id_ = #{id} and tenant_id_ = #{tenantId}
	</update>
	
	<update id="batchUpdate" parameterType="com.ym.mec.biz.dal.entity.CooperationOrganLinkman">
        <foreach collection="cooperationOrganLinkmans" item="cooperationOrganLinkman" separator=";">
			UPDATE cooperation_organ_linkman
			<set>
				<if test="cooperationOrganLinkman.cooperationOrganId != null">
					cooperation_organ_id_ = #{cooperationOrganLinkman.cooperationOrganId},
				</if>
				<if test="cooperationOrganLinkman.job != null">
					job_ = #{cooperationOrganLinkman.job},
				</if>
				<if test="cooperationOrganLinkman.id != null">
					id_ = #{cooperationOrganLinkman.id},
				</if>
				<if test="cooperationOrganLinkman.linkman != null">
					linkman_ = #{cooperationOrganLinkman.linkman},
				</if>
				<if test="cooperationOrganLinkman.mobileNo != null">
					mobile_no_ = #{cooperationOrganLinkman.mobileNo},
				</if>
				<if test="cooperationOrganLinkman.createTime != null">
					create_time_ = #{cooperationOrganLinkman.createTime},
				</if>
			</set>
			WHERE id_ = #{cooperationOrganLinkman.id} and tenant_id_ = #{cooperationOrganLinkman.tenantId}
        </foreach>
	</update>

	<!-- 根据主键删除一条记录 -->
	<delete id="delete">
		DELETE FROM cooperation_organ_linkman WHERE id_ = #{id}
	</delete>

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="CooperationOrganLinkman" parameterType="map">
		SELECT * FROM cooperation_organ_linkman where tenant_id_ = #{tenantId} ORDER BY id_
		<include refid="global.limit" />
	</select>

	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM cooperation_organ_linkman where tenant_id_ = #{tenantId}
	</select>
	
	<select id="queryByCooperationOrganId" resultMap="CooperationOrganLinkman">
		SELECT * FROM cooperation_organ_linkman where cooperation_organ_id_ = #{cooperationOrganId} ORDER BY id_ asc
	</select>
	
	<delete id="deleteByCooperationOrganId">
		DELETE FROM cooperation_organ_linkman WHERE cooperation_organ_id_ = #{cooperationOrganId}
	</delete>
</mapper>
