<?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.business.dao.FillAttendanceDAO">
    <resultMap id="FillAttendanceMap" type="com.jpsoft.shinestar.modules.business.entity.FillAttendance">
        <id property="id" column="id_"/>
        <result property="personId" column="person_id"/>
        <result property="personName" column="person_name"/>
        <result property="companyName" column="company_name"/>
        <result property="type" column="type_"/>
        <result property="fillDay" column="fill_day"/>
        <result property="fillAttendanceTime" column="fill_attendance_time"/>
        <result property="content" column="content_"/>
        <result property="approvalPersonId" column="approval_person_id"/>
        <result property="approvalPersonName" column="approval_person_name"/>
        <result property="status" column="status_"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="delFlag" column="del_flag"/>
        <result property="businessWorkAttendanceId" column="business_work_attendance_id"/>
        <result property="approvalNo" column="approval_no"/>
        <result property="approvalTime" column="approval_time"/>
        <result property="approvalContent" column="approval_content"/>
        <result property="longitude" column="longitude_"/>
        <result property="latitude" column="latitude_"/>
        <result property="address" column="address_"/>
        <result property="workStatus" column="work_status"/>
        <result property="remark" column="remark_"/>
        <result property="approvalPersonIdStr" column="approval_person_id_str"/>
        <result property="approvalStatusStr" column="approval_status_str"/>
        <result property="approvalTimeStr" column="approval_time_str"/>
        <result property="approvalContentStr" column="approval_content_str"/>
        <result property="approvalPersonPopedomId" column="approval_person_popedom_id"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.business.entity.FillAttendance">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into business_fill_attendance
	    (id_,person_id,type_,fill_day,fill_attendance_time,content_,approval_person_id,status_,create_by,
	    create_time,update_by,update_time,del_flag,business_work_attendance_id,approval_no,approval_time,approval_content,
	    longitude_,latitude_,address_,work_status,remark_,approval_person_id_str,approval_status_str,approval_time_str,approval_content_str,approval_person_popedom_id)
		values
		(
            #{id,jdbcType=VARCHAR}
            ,#{personId,jdbcType= NUMERIC }
            ,#{type,jdbcType=VARCHAR}
            ,#{fillDay,jdbcType=VARCHAR}
            ,#{fillAttendanceTime,jdbcType=VARCHAR}
            ,#{content,jdbcType=VARCHAR}
            ,#{approvalPersonId,jdbcType= NUMERIC }
            ,#{status,jdbcType=VARCHAR}
            ,#{createBy,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{updateBy,jdbcType=VARCHAR}
            ,#{updateTime,jdbcType= TIMESTAMP }
            ,#{delFlag,jdbcType= NUMERIC }
            ,#{businessWorkAttendanceId,jdbcType=VARCHAR}
            ,#{approvalNo,jdbcType=VARCHAR}
            ,#{approvalTime,jdbcType=TIMESTAMP}
            ,#{approvalContent,jdbcType=VARCHAR}
            ,#{longitude,jdbcType=VARCHAR}
            ,#{latitude,jdbcType=VARCHAR}
            ,#{address,jdbcType=VARCHAR}
            ,#{workStatus,jdbcType=VARCHAR}
            ,#{remark,jdbcType=VARCHAR}
            ,#{approvalPersonIdStr,jdbcType=VARCHAR}
            ,#{approvalStatusStr,jdbcType=VARCHAR}
            ,#{approvalTimeStr,jdbcType=VARCHAR}
            ,#{approvalContentStr,jdbcType=VARCHAR}
            ,#{approvalPersonPopedomId,jdbcType=VARCHAR}
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
		delete from business_fill_attendance where id_=#{id,jdbcType=VARCHAR}
	</delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.business.entity.FillAttendance">
        update business_fill_attendance
        <set>
            <if test="personId!=null">
                person_id=#{personId,jdbcType= NUMERIC },
            </if>
            <if test="type!=null">
                type_=#{type,jdbcType=VARCHAR},
            </if>
            <if test="fillDay!=null">
                fill_day=#{fillDay,jdbcType=VARCHAR},
            </if>
            <if test="fillAttendanceTime!=null">
                fill_attendance_time=#{fillAttendanceTime,jdbcType=VARCHAR},
            </if>
            <if test="content!=null">
                content_=#{content,jdbcType=VARCHAR},
            </if>
            <if test="approvalPersonId!=null">
                approval_person_id=#{approvalPersonId,jdbcType= NUMERIC },
            </if>
            <if test="status!=null">
                status_=#{status,jdbcType=VARCHAR},
            </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>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="businessWorkAttendanceId!=null">
                business_work_attendance_id=#{businessWorkAttendanceId,jdbcType= VARCHAR },
            </if>
            <if test="approvalNo!=null">
                approval_no=#{approvalNo,jdbcType= VARCHAR },
            </if>
            <if test="approvalTime!=null">
                approval_time=#{approvalTime,jdbcType=TIMESTAMP},
            </if>
            <if test="approvalContent!=null">
                approval_content=#{approvalContent,jdbcType=VARCHAR},
            </if>
            <if test="longitude!=null">
                longitude_=#{longitude,jdbcType=VARCHAR},
            </if>
            <if test="latitude!=null">
                latitude_=#{latitude,jdbcType=VARCHAR},
            </if>
            <if test="address!=null">
                address_=#{address,jdbcType=VARCHAR},
            </if>
            <if test="workStatus!=null">
                work_status=#{workStatus,jdbcType=VARCHAR},
            </if>
            <if test="remark!=null">
                remark_=#{remark,jdbcType=VARCHAR},
            </if>

            <if test="approvalPersonIdStr!=null">
                approval_person_id_str=#{approvalPersonIdStr,jdbcType=VARCHAR},
            </if>
            <if test="approvalStatusStr!=null">
                approval_status_str=#{approvalStatusStr,jdbcType=VARCHAR},
            </if>
            <if test="approvalTimeStr!=null">
                approval_time_str=#{approvalTimeStr,jdbcType=VARCHAR},
            </if>
            <if test="approvalContentStr!=null">
                approval_content_str=#{approvalContentStr,jdbcType=VARCHAR},
            </if>
            <if test="approvalPersonPopedomId!=null">
                approval_person_popedom_id=#{approvalPersonPopedomId,jdbcType=VARCHAR},
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="FillAttendanceMap">
		select * from business_fill_attendance where id_=#{0} and del_flag = 0
	</select>
    <select id="exist" parameterType="string" resultType="int">
		select count(*) from business_fill_attendance where id_=#{0} and del_flag = 0
	</select>
    <select id="list" resultMap="FillAttendanceMap">
		select * from business_fill_attendance and del_flag = 0
	</select>
    <select id="search" parameterType="hashmap" resultMap="FillAttendanceMap">
        <![CDATA[
			select a.*,
			b.name_ as person_name,
			c.name_ as approval_person_name,
			d.name_ as company_name
			 from business_fill_attendance a
			left join base_person_info b on a.person_id = b.id_
			left join base_person_info c on a.approval_person_id = c.id_
			left join base_company_info d on b.company_id = d.id_
		]]>
        <where>
            a.del_flag = 0
            and b.del_flag = 0
            and d.del_flag = 0
            <if test="searchParams.id != null">
                and a.ID_ like #{searchParams.id}
            </if>
            <if test="searchParams.personName != null">
                and b.name_ like #{searchParams.personName}
            </if>
            <if test="searchParams.companyCode != null">
                and d.code_ like #{searchParams.companyCode}
            </if>
            <if test="searchParams.type != null">
                and a.type_ = #{searchParams.type}
            </if>
            <if test="searchParams.status != null">
                and a.status_ like #{searchParams.status}
            </if>
            <if test="searchParams.personId != null">
                and a.person_id like #{searchParams.personId}
            </if>
            <if test="searchParams.approvalPersonId != null">
                and a.approval_person_id = #{searchParams.approvalPersonId}
            </if>
            <if test="searchParams.approvalPersonPopedomId != null">
                and a.approval_person_popedom_id = #{searchParams.approvalPersonPopedomId}
            </if>
            <if test="searchParams.approvalPersonIdStr != null">
                and ( a.approval_person_id_str like #{searchParams.approvalPersonIdStr} OR a.approval_person_popedom_id like #{searchParams.approvalPersonIdStr} )
            </if>
            <if test="searchParams.notStatus != null">
                and a.status_ != #{searchParams.notStatus}
            </if>
            <if test='searchParams.startTime!=null'>
                <![CDATA[
                    and a.fill_day >= #{searchParams.startTime}
                ]]>
            </if>
            <if test='searchParams.endTime!=null'>
                <![CDATA[
                    and a.fill_day <= #{searchParams.endTime}
                ]]>
            </if>
            <if test="searchParams.bindCompanyCode != null">
                and d.code_ like #{searchParams.bindCompanyCode}
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            a.${sort.name} ${sort.order}
        </foreach>
    </select>

    <select id="findByBusinessWorkAttendanceId" resultMap="FillAttendanceMap">
        select * from business_fill_attendance
        where business_work_attendance_id = #{businessWorkAttendanceId}
        and del_flag = 0
    </select>
</mapper>