<?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.SupplementWorkDAO">
    <resultMap id="SupplementWorkMap" type="com.jpsoft.shinestar.modules.business.entity.SupplementWork">
        <id property="id" column="id_"/>
        <result property="personPopedomId" column="person_popedom_id"/>
        <result property="personName" column="person_name"/>
        <result property="procinstId" column="procinst_id"/>
        <result property="workShiftId" column="work_shift_id"/>
        <result property="attendanceDate" column="attendance_date"/>
        <result property="classify" column="classify_"/>
        <result property="type" column="type_"/>
        <result property="status" column="status_"/>
        <result property="submitTime" column="submit_time"/>
        <result property="reason" column="reason_"/>
        <result property="imageUrl" column="image_url"/>
        <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="companyName" column="company_name"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.business.entity.SupplementWork">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into business_supplement_work
	    (id_,person_popedom_id,procinst_id,work_shift_id,attendance_date,classify_,type_,status_,submit_time,reason_,image_url,create_by,create_time,update_by,update_time,del_flag)
		values
		(
            #{id,jdbcType=VARCHAR}
            ,#{personPopedomId,jdbcType=VARCHAR}
            ,#{procinstId,jdbcType=VARCHAR}
            ,#{workShiftId,jdbcType=VARCHAR}
            ,#{attendanceDate,jdbcType=VARCHAR}
            ,#{classify,jdbcType=VARCHAR}
            ,#{type,jdbcType=VARCHAR}
            ,#{status,jdbcType=VARCHAR}
            ,#{submitTime,jdbcType= TIMESTAMP }
            ,#{reason,jdbcType=VARCHAR}
            ,#{imageUrl,jdbcType=VARCHAR}
            ,#{createBy,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{updateBy,jdbcType=VARCHAR}
            ,#{updateTime,jdbcType= TIMESTAMP }
            ,#{delFlag,jdbcType= NUMERIC }
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from business_supplement_work where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.business.entity.SupplementWork">
        update business_supplement_work
        <set>
            <if test="personPopedomId!=null">
                person_popedom_id=#{personPopedomId,jdbcType=VARCHAR},
            </if>
            <if test="procinstId!=null">
                procinst_id=#{procinstId,jdbcType=VARCHAR},
            </if>
            <if test="workShiftId!=null">
                work_shift_id=#{workShiftId,jdbcType=VARCHAR},
            </if>
            <if test="attendanceDate!=null">
                attendance_date=#{attendanceDate,jdbcType=VARCHAR},
            </if>
            <if test="classify!=null">
                classify_=#{classify,jdbcType=VARCHAR},
            </if>
            <if test="type!=null">
                type_=#{type,jdbcType=VARCHAR},
            </if>
            <if test="status!=null">
                status_=#{status,jdbcType=VARCHAR},
            </if>
            <if test="submitTime!=null">
                submit_time=#{submitTime,jdbcType= TIMESTAMP },
            </if>
            <if test="reason!=null">
                reason_=#{reason,jdbcType=VARCHAR},
            </if>
            <if test="imageUrl!=null">
                image_url=#{imageUrl,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>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="SupplementWorkMap">
        select * from business_supplement_work where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from business_supplement_work where id_=#{0}
    </select>
    <select id="list" resultMap="SupplementWorkMap">
        select * from business_supplement_work
    </select>
    <select id="search" parameterType="hashmap" resultMap="SupplementWorkMap">
        <![CDATA[
			select t1.*,
			t3.name_ as person_name,
			t4.name_ as company_name
			from business_supplement_work t1
			inner join base_person_popedom t2 on t1.person_popedom_id = t2.id_
			inner join base_person_info t3 on t3.id_ = t2.person_id
			inner join base_company_info t4 on t4.id_ = t3.company_id
		]]>
        <where>
            t1.del_flag=0
            <if test="searchParams.swPersonName != null">
                and exists (
                    select swp.id_
                    from business_supplement_work_person swp
                    inner join base_person_popedom bpp on swp.person_popedom_id = bpp.id_
                    inner join base_person_info bpi on bpi.id_ = bpp.person_id
                    where swp.supplement_work_id = t1.id_
                    and bpi.name_ like #{searchParams.swPersonName}
                )
            </if>
            <if test="searchParams.personName != null">
                and t3.name_ like #{searchParams.personName}
            </if>
            <if test="searchParams.personPopedomId != null">
                and t1.person_popedom_id = #{searchParams.personPopedomId}
            </if>
            <if test="searchParams.status != null">
                and t1.status_ = #{searchParams.status}
            </if>
            <if test="searchParams.type != null">
                and t1.type_ = #{searchParams.type}
            </if>
            <if test="searchParams.startTime != null">
                <![CDATA[
					and t1.attendance_date >= #{searchParams.startTime}
				]]>
            </if>
            <if test="searchParams.endTime != null">
                <![CDATA[
					and t1.attendance_date <= #{searchParams.endTime}
				]]>
            </if>
            <if test="searchParams.companyCode != null">
                and t4.code_ like #{searchParams.companyCode}
            </if>
            <if test="searchParams.hqCompanyCode != null">
                and t4.code_ like #{searchParams.hqCompanyCode}
            </if>
            <if test="searchParams.hqStatus != null">
                and t3.hq_status = #{searchParams.hqStatus}
            </if>
            <if test="searchParams.hqStatus == null and searchParams.hqPerson != null">
                <![CDATA[
					and ifnull(t3.hq_status,0)<>0
				]]>
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            t1.${sort.name} ${sort.order}
        </foreach>
    </select>
</mapper>