<?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="cn.timer.api.dao.yggl.YgglMainLzbMapper">

    <resultMap id="BaseResultMap" type="cn.timer.api.bean.yggl.YgglMainLzb" >
        	<id column="id" property="id" />
                <id column="id" property="id" />
                <result column="emp_num" property="empNum" />
                <result column="phone" property="phone" />
                <result column="password" property="password" />
                <result column="head_url" property="headUrl" />
                <result column="name" property="name" />
                <result column="english_name" property="englishName" />
                <result column="sex" property="sex" />
                <result column="zj_type" property="zjType" />
                <result column="zj_num" property="zjNum" />
                <result column="sfzyx_time" property="sfzyxTime" />
                <result column="birthday" property="birthday" />
                <result column="age" property="age" />
                <result column="is_married" property="isMarried" />
                <result column="is_pregnant" property="isPregnant" />
                <result column="area" property="area" />
                <result column="mz" property="mz" />
                <result column="zzmm" property="zzmm" />
                <result column="jg" property="jg" />
                <result column="city" property="city" />
                <result column="hk_type" property="hkType" />
                <result column="hk_address" property="hkAddress" />
                <result column="qq" property="qq" />
                <result column="wechat" property="wechat" />
                <result column="email" property="email" />
                <result column="blood_type" property="bloodType" />
                <result column="language" property="language" />
                <result column="edu" property="edu" />
                <result column="zy" property="zy" />
                <result column="zz_remark" property="zzRemark" />
                <result column="job_type" property="jobType" />
                <result column="job_status" property="jobStatus" />
                <result column="rz_time" property="rzTime" />
                <result column="syq" property="syq" />
                <result column="zz_time" property="zzTime" />
                <result column="sjzz_time" property="sjzzTime" />
                <result column="is_jrkq" property="isJrkq" />
                <result column="jobNum" property="jobNum" />
                <result column="work_address" property="workAddress" />
                <result column="work_phone" property="workPhone" />
                <result column="work_email" property="workEmail" />
                <result column="zpqd" property="zpqd" />
                <result column="bmgw_id" property="bmgwId" />
                <result column="org_code" property="orgCode" />
                <result column="unionid" property="unionid" />
                <result column="openid" property="openid" />
                <result column="mpopenid" property="mpopenid" />
                <result column="appopenid" property="appopenid" />
                <result column="lz_time" property="lzTime" />
                <result column="sjlz_time" property="sjlzTime" />
                <result column="lzyy_id" property="lzyyId" />

    </resultMap>

    <sql id="Base_Column_List">
                id,
                emp_num,
                phone,
                password,
                head_url,
                name,
                english_name,
                sex,
                zj_type,
                zj_num,
                sfzyx_time,
                birthday,
                age,
                is_married,
                is_pregnant,
                area,
                mz,
                zzmm,
                jg,
                city,
                hk_type,
                hk_address,
                qq,
                wechat,
                email,
                blood_type,
                language,
                edu,
                zy,
                zz_remark,
                job_type,
                job_status,
                rz_time,
                syq,
                zz_time,
                sjzz_time,
                is_jrkq,
                job_num,
                work_address,
                work_phone,
                work_email,
                zpqd,
                bmgw_id,
                org_code,
                unionid,
                openid,
                mpopenid,
                appopenid,
                lz_time,
                sjlz_time,
                lzyy_id
    </sql>

    <sql id="Base_Column_List_Alias">
                id YgglMainLzb_id,
                emp_num YgglMainLzb_emp_num,
                phone YgglMainLzb_phone,
                password YgglMainLzb_password,
                head_url YgglMainLzb_head_url,
                name YgglMainLzb_name,
                english_name YgglMainLzb_english_name,
                sex YgglMainLzb_sex,
                zj_type YgglMainLzb_zj_type,
                zj_num YgglMainLzb_zj_num,
                sfzyx_time YgglMainLzb_sfzyx_time,
                birthday YgglMainLzb_birthday,
                age YgglMainLzb_age,
                is_married YgglMainLzb_is_married,
                is_pregnant YgglMainLzb_is_pregnant,
                area YgglMainLzb_area,
                mz YgglMainLzb_mz,
                zzmm YgglMainLzb_zzmm,
                jg YgglMainLzb_jg,
                city YgglMainLzb_city,
                hk_type YgglMainLzb_hk_type,
                hk_address YgglMainLzb_hk_address,
                qq YgglMainLzb_qq,
                wechat YgglMainLzb_wechat,
                email YgglMainLzb_email,
                blood_type YgglMainLzb_blood_type,
                language YgglMainLzb_language,
                edu YgglMainLzb_edu,
                zy YgglMainLzb_zy,
                zz_remark YgglMainLzb_zz_remark,
                job_type YgglMainLzb_job_type,
                job_status YgglMainLzb_job_status,
                rz_time YgglMainLzb_rz_time,
                syq YgglMainLzb_syq,
                zz_time YgglMainLzb_zz_time,
                sjzz_time YgglMainLzb_sjzz_time,
                is_jrkq YgglMainLzb_is_jrkq,
                job_num YgglMainLzb_job_num,
                work_address YgglMainLzb_work_address,
                work_phone YgglMainLzb_work_phone,
                work_email YgglMainLzb_work_email,
                zpqd YgglMainLzb_zpqd,
                bmgw_id YgglMainLzb_bmgw_id,
                org_code YgglMainLzb_org_code,
                unionid YgglMainLzb_unionid,
                openid YgglMainLzb_openid,
                mpopenid YgglMainLzb_mpopenid,
                appopenid YgglMainLzb_appopenid,
                lz_time YgglMainLzb_lz_time,
                sjlz_time YgglMainLzb_sjlz_time,
                lzyyId  YgglMainLzb_lzyy_id,
    </sql>
	<!-- 查询本月离职人数 -->
	<select id="queryDeparture" resultType="cn.timer.api.dto.yggl.YgglCartogramDto">
        SELECT
			EXTRACT(MONTH FROM sjlz_time) AS mouth,
			COUNT(emp_num) departureNum
		FROM
			yggl_main_lzb
		WHERE
			org_code=#{orgCode}
    </select>


	<!-- 查询员工信息 搜索 分页 -->
	<select id="queryLzb" parameterType="cn.timer.api.dto.yggl.LzbQueryDto" resultType="cn.timer.api.dto.yggl.LzbDto">
    	SELECT
			a.name `name`,
			a.emp_num `empNum`,
			c.name `bm`,
			b.name `gw`,
			a.job_type `type`,
			a.job_status `jobStatus`,
			a.rz_time `rz`,
			timestampdiff(day,a.rz_time,a.lz_time) `workage`,
			a.lz_time `ylz`,
			a.phone `phone`,
			a.lzbz `bz`,
			a.lzyy lzyy,
			a.sjlz_time sjlz,
			a.job_num
		FROM
			yggl_main_lzb a
		LEFT JOIN zzgl_bmgw_m b ON a.bmgw_id = b.id
		LEFT JOIN zzgl_bmgw_m c ON b.up_id = c.id
		WHERE
			a.org_code = #{q.orgCode}
		<if test ="null != q.jobStatus and q.jobStatus !=''">
		AND
			a.job_status = #{q.jobStatus}
		</if>
		<if test ="null != q.query and q.query !=''">
		AND
			(a.name like CONCAT('%',#{q.query},'%') OR a.emp_num like CONCAT('%',#{q.query},'%') OR a.job_num like CONCAT('%',#{q.query},'%'))
		</if>
		ORDER BY a.job_status ASC
    </select>

	<!--

    <insert id="insert" useGeneratedKeys="true" keyColumn="id" parameterType="cn.timer.api.bean.yggl.YgglMainLzb">
        INSERT INTO yggl_main_lzb
        <trim prefix="(" suffix=")" suffixOverrides=",">
                        <if test ='null != empNum'>
                        emp_num,
                        </if>
                        <if test ='null != phone'>
                        phone,
                        </if>
                        <if test ='null != password'>
                        password,
                        </if>
                        <if test ='null != headUrl'>
                        head_url,
                        </if>
                        <if test ='null != name'>
                        name,
                        </if>
                        <if test ='null != englishName'>
                        english_name,
                        </if>
                        <if test ='null != sex'>
                        sex,
                        </if>
                        <if test ='null != zjType'>
                        zj_type,
                        </if>
                        <if test ='null != zjNum'>
                        zj_num,
                        </if>
                        <if test ='null != sfzyxTime'>
                        sfzyx_time,
                        </if>
                        <if test ='null != birthday'>
                        birthday,
                        </if>
                        <if test ='null != age'>
                        age,
                        </if>
                        <if test ='null != isMarried'>
                        is_married,
                        </if>
                        <if test ='null != isPregnant'>
                        is_pregnant,
                        </if>
                        <if test ='null != area'>
                        area,
                        </if>
                        <if test ='null != mz'>
                        mz,
                        </if>
                        <if test ='null != zzmm'>
                        zzmm,
                        </if>
                        <if test ='null != jg'>
                        jg,
                        </if>
                        <if test ='null != city'>
                        city,
                        </if>
                        <if test ='null != hkType'>
                        hk_type,
                        </if>
                        <if test ='null != hkAddress'>
                        hk_address,
                        </if>
                        <if test ='null != qq'>
                        qq,
                        </if>
                        <if test ='null != wechat'>
                        wechat,
                        </if>
                        <if test ='null != email'>
                        email,
                        </if>
                        <if test ='null != bloodType'>
                        blood_type,
                        </if>
                        <if test ='null != language'>
                        language,
                        </if>
                        <if test ='null != edu'>
                        edu,
                        </if>
                        <if test ='null != zy'>
                        zy,
                        </if>
                        <if test ='null != zzRemark'>
                        zz_remark,
                        </if>
                        <if test ='null != jobType'>
                        job_type,
                        </if>
                        <if test ='null != jobStatus'>
                        job_status,
                        </if>
                        <if test ='null != rzTime'>
                        rz_time,
                        </if>
                        <if test ='null != syq'>
                        syq,
                        </if>
                        <if test ='null != zzTime'>
                        zz_time,
                        </if>
                        <if test ='null != sjzzTime'>
                        sjzz_time,
                        </if>
                        <if test ='null != isJrkq'>
                        is_jrkq,
                        </if>
                        <if test ='null != jobNum'>
                        job_num,
                        </if>
                        <if test ='null != workAddress'>
                        work_address,
                        </if>
                        <if test ='null != workPhone'>
                        work_phone,
                        </if>
                        <if test ='null != workEmail'>
                        work_email,
                        </if>
                        <if test ='null != zpqd'>
                        zpqd,
                        </if>
                        <if test ='null != bmgwId'>
                        bmgw_id,
                        </if>
                        <if test ='null != orgCode'>
                        org_code,
                        </if>
                        <if test ='null != unionid'>
                        unionid,
                        </if>
                        <if test ='null != openid'>
                        openid,
                        </if>
                        <if test ='null != mpopenid'>
                        mpopenid,
                        </if>
                        <if test ='null != appopenid'>
                        appopenid,
                        </if>
                        <if test ='null != lzTime'>
                        lz_time,
                        </if>
                        <if test ='null != sjlzTime'>
                        sjlz_time
                        </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                        <if test ='null != empNum'>
                        #{empNum},
                        </if>
                        <if test ='null != phone'>
                        #{phone},
                        </if>
                        <if test ='null != password'>
                        #{password},
                        </if>
                        <if test ='null != headUrl'>
                        #{headUrl},
                        </if>
                        <if test ='null != name'>
                        #{name},
                        </if>
                        <if test ='null != englishName'>
                        #{englishName},
                        </if>
                        <if test ='null != sex'>
                        #{sex},
                        </if>
                        <if test ='null != zjType'>
                        #{zjType},
                        </if>
                        <if test ='null != zjNum'>
                        #{zjNum},
                        </if>
                        <if test ='null != sfzyxTime'>
                        #{sfzyxTime},
                        </if>
                        <if test ='null != birthday'>
                        #{birthday},
                        </if>
                        <if test ='null != age'>
                        #{age},
                        </if>
                        <if test ='null != isMarried'>
                        #{isMarried},
                        </if>
                        <if test ='null != isPregnant'>
                        #{isPregnant},
                        </if>
                        <if test ='null != area'>
                        #{area},
                        </if>
                        <if test ='null != mz'>
                        #{mz},
                        </if>
                        <if test ='null != zzmm'>
                        #{zzmm},
                        </if>
                        <if test ='null != jg'>
                        #{jg},
                        </if>
                        <if test ='null != city'>
                        #{city},
                        </if>
                        <if test ='null != hkType'>
                        #{hkType},
                        </if>
                        <if test ='null != hkAddress'>
                        #{hkAddress},
                        </if>
                        <if test ='null != qq'>
                        #{qq},
                        </if>
                        <if test ='null != wechat'>
                        #{wechat},
                        </if>
                        <if test ='null != email'>
                        #{email},
                        </if>
                        <if test ='null != bloodType'>
                        #{bloodType},
                        </if>
                        <if test ='null != language'>
                        #{language},
                        </if>
                        <if test ='null != edu'>
                        #{edu},
                        </if>
                        <if test ='null != zy'>
                        #{zy},
                        </if>
                        <if test ='null != zzRemark'>
                        #{zzRemark},
                        </if>
                        <if test ='null != jobType'>
                        #{jobType},
                        </if>
                        <if test ='null != jobStatus'>
                        #{jobStatus},
                        </if>
                        <if test ='null != rzTime'>
                        #{rzTime},
                        </if>
                        <if test ='null != syq'>
                        #{syq},
                        </if>
                        <if test ='null != zzTime'>
                        #{zzTime},
                        </if>
                        <if test ='null != sjzzTime'>
                        #{sjzzTime},
                        </if>
                        <if test ='null != isJrkq'>
                        #{isJrkq},
                        </if>
                        <if test ='null != jobNum'>
                        #{jobNum},
                        </if>
                        <if test ='null != workAddress'>
                        #{workAddress},
                        </if>
                        <if test ='null != workPhone'>
                        #{workPhone},
                        </if>
                        <if test ='null != workEmail'>
                        #{workEmail},
                        </if>
                        <if test ='null != zpqd'>
                        #{zpqd},
                        </if>
                        <if test ='null != bmgwId'>
                        #{bmgwId},
                        </if>
                        <if test ='null != orgCode'>
                        #{orgCode},
                        </if>
                        <if test ='null != unionid'>
                        #{unionid},
                        </if>
                        <if test ='null != openid'>
                        #{openid},
                        </if>
                        <if test ='null != mpopenid'>
                        #{mpopenid},
                        </if>
                        <if test ='null != appopenid'>
                        #{appopenid},
                        </if>
                        <if test ='null != lzTime'>
                        #{lzTime},
                        </if>
                        <if test ='null != sjlzTime'>
                        #{sjlzTime}
                        </if>
        </trim>
    </insert>

    <delete id="delete" >
        DELETE FROM yggl_main_lzb
        WHERE id = #{id}
    </delete>

    <update id="update" parameterType="cn.timer.api.bean.yggl.YgglMainLzb">
        UPDATE yggl_main_lzb
        <set>
                    <if test ='null != empNum'>emp_num = #{empNum},</if>
                    <if test ='null != phone'>phone = #{phone},</if>
                    <if test ='null != password'>password = #{password},</if>
                    <if test ='null != headUrl'>head_url = #{headUrl},</if>
                    <if test ='null != name'>name = #{name},</if>
                    <if test ='null != englishName'>english_name = #{englishName},</if>
                    <if test ='null != sex'>sex = #{sex},</if>
                    <if test ='null != zjType'>zj_type = #{zjType},</if>
                    <if test ='null != zjNum'>zj_num = #{zjNum},</if>
                    <if test ='null != sfzyxTime'>sfzyx_time = #{sfzyxTime},</if>
                    <if test ='null != birthday'>birthday = #{birthday},</if>
                    <if test ='null != age'>age = #{age},</if>
                    <if test ='null != isMarried'>is_married = #{isMarried},</if>
                    <if test ='null != isPregnant'>is_pregnant = #{isPregnant},</if>
                    <if test ='null != area'>area = #{area},</if>
                    <if test ='null != mz'>mz = #{mz},</if>
                    <if test ='null != zzmm'>zzmm = #{zzmm},</if>
                    <if test ='null != jg'>jg = #{jg},</if>
                    <if test ='null != city'>city = #{city},</if>
                    <if test ='null != hkType'>hk_type = #{hkType},</if>
                    <if test ='null != hkAddress'>hk_address = #{hkAddress},</if>
                    <if test ='null != qq'>qq = #{qq},</if>
                    <if test ='null != wechat'>wechat = #{wechat},</if>
                    <if test ='null != email'>email = #{email},</if>
                    <if test ='null != bloodType'>blood_type = #{bloodType},</if>
                    <if test ='null != language'>language = #{language},</if>
                    <if test ='null != edu'>edu = #{edu},</if>
                    <if test ='null != zy'>zy = #{zy},</if>
                    <if test ='null != zzRemark'>zz_remark = #{zzRemark},</if>
                    <if test ='null != jobType'>job_type = #{jobType},</if>
                    <if test ='null != jobStatus'>job_status = #{jobStatus},</if>
                    <if test ='null != rzTime'>rz_time = #{rzTime},</if>
                    <if test ='null != syq'>syq = #{syq},</if>
                    <if test ='null != zzTime'>zz_time = #{zzTime},</if>
                    <if test ='null != sjzzTime'>sjzz_time = #{sjzzTime},</if>
                    <if test ='null != isJrkq'>is_jrkq = #{isJrkq},</if>
                    <if test ='null != jobNum'>job_num = #{jobNum},</if>
                    <if test ='null != workAddress'>work_address = #{workAddress},</if>
                    <if test ='null != workPhone'>work_phone = #{workPhone},</if>
                    <if test ='null != workEmail'>work_email = #{workEmail},</if>
                    <if test ='null != zpqd'>zpqd = #{zpqd},</if>
                    <if test ='null != bmgwId'>bmgw_id = #{bmgwId},</if>
                    <if test ='null != orgCode'>org_code = #{orgCode},</if>
                    <if test ='null != unionid'>unionid = #{unionid},</if>
                    <if test ='null != openid'>openid = #{openid},</if>
                    <if test ='null != mpopenid'>mpopenid = #{mpopenid},</if>
                    <if test ='null != appopenid'>appopenid = #{appopenid},</if>
                    <if test ='null != lzTime'>lz_time = #{lzTime},</if>
                    <if test ='null != sjlzTime'>sjlz_time = #{sjlzTime}</if>
        </set>
        WHERE id = #{id}
    </update>


    <select id="load" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM yggl_main_lzb
        WHERE id = #{id}
    </select>

    <select id="pageList" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM yggl_main_lzb
        LIMIT #{offset}, #{pageSize}
    </select>

    <select id="pageListCount" resultType="java.lang.Integer">
        SELECT count(1)
        FROM yggl_main_lzb
    </select>

	 -->

</mapper>