<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.PunchLocationDAO">
	<resultMap id="PunchLocationMap" type="com.jpsoft.shinestar.modules.base.entity.PunchLocation">
		<id property="id" column="id_" />
			<result property="companyId" column="company_id" />
			<result property="companyName" column="company_name" />
			<result property="name" column="name_" />
			<result property="longtitude" column="longtitude_" />
			<result property="latitude" column="latitude_" />
			<result property="remark" column="remark_" />
			<result property="isEnable" column="is_enable" />
			<result property="delFlag" column="del_flag" />
			<result property="createBy" column="create_by" />
			<result property="createTime" column="create_time" />
			<result property="updateBy" column="update_by" />
			<result property="updateTime" column="update_time" />
			</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.PunchLocation">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into base_punch_location
	    (id_,company_id,name_,longtitude_,latitude_,remark_,is_enable,del_flag,create_by,create_time,update_by,update_time)
		values
		(
#{id,jdbcType=VARCHAR}
,#{companyId,jdbcType=VARCHAR}
,#{name,jdbcType=VARCHAR}
,#{longtitude,jdbcType=VARCHAR}
,#{latitude,jdbcType=VARCHAR}
,#{remark,jdbcType=VARCHAR}
,#{isEnable,jdbcType= NUMERIC }
,#{delFlag,jdbcType= NUMERIC }
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from base_punch_location where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.PunchLocation">
		update base_punch_location
		<set>
				<if test="companyId!=null">
		company_id=#{companyId,jdbcType=VARCHAR},
		</if>
				<if test="name!=null">
		name_=#{name,jdbcType=VARCHAR},
		</if>
				<if test="longtitude!=null">
		longtitude_=#{longtitude,jdbcType=VARCHAR},
		</if>
				<if test="latitude!=null">
		latitude_=#{latitude,jdbcType=VARCHAR},
		</if>
				<if test="remark!=null">
		remark_=#{remark,jdbcType=VARCHAR},
		</if>
				<if test="isEnable!=null">
		is_enable=#{isEnable,jdbcType= NUMERIC },
		</if>
				<if test="delFlag!=null">
		del_flag=#{delFlag,jdbcType= NUMERIC },
		</if>
				<if test="createBy!=null">
		create_by=#{createBy,jdbcType=VARCHAR},
		</if>
				<if test="createTime!=null">
		create_time=#{createTime,jdbcType= TIMESTAMP },
		</if>
				<if test="updateBy!=null">
		update_by=#{updateBy,jdbcType=VARCHAR},
		</if>
				<if test="updateTime!=null">
		update_time=#{updateTime,jdbcType= TIMESTAMP },
		</if>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="PunchLocationMap">
		select * from base_punch_location where id_=#{0} and del_flag = 0
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from base_punch_location where id_=#{0} and del_flag = 0
	</select>
	<select id="list" resultMap="PunchLocationMap">
		select * from base_punch_location where del_flag = 0
	</select>
	<select id="search" parameterType="hashmap" resultMap="PunchLocationMap">
		<![CDATA[
			select a.*,b.name_ as company_name
			from base_punch_location a left join base_company_info b on a.company_id = b.id_ and b.del_flag = 0
		]]>
		<where>
			a.del_flag = 0
			<if test="searchParams.id != null">
				and a.ID_ like #{searchParams.id}
			</if>
			<if test="searchParams.companyId != null">
				and a.company_id = #{searchParams.companyId}
			</if>
			<if test="searchParams.companyIds != null">
				and a.company_id in
				<foreach collection="searchParams.companyIds" item="companyId" open="( "  close=" ) " separator=",">
					#{companyId}
				</foreach>
			</if>
			<if test="searchParams.name != null">
				and a.name_ like #{searchParams.name}
			</if>
			<if test="searchParams.isEnable != null">
				and a.is_enable = #{searchParams.isEnable}
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>
</mapper>