<?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.sbgjj.SbgjjAdminCbryMapper">

    <resultMap id="BaseResultMap" type="cn.timer.api.bean.sbgjj.SbgjjAdminCbry" >
                <id column="id" property="id" />
                <result column="user_num" property="userNum" />
                <result column="sbcb_state" property="sbcbState" />
                <result column="gjjcb_state" property="gjjcbState" />
                <result column="jl_mode" property="jlMode" />
                <result column="cbfacs" property="cbfacs" />
                <result column="sbjl_statime" property="sbjlStatime" />
                <result column="sbjljs" property="sbjljs" />
                <result column="gjjjl_statime" property="gjjjlStatime" />
                <result column="gjjjljs" property="gjjjljs" />
                <result column="sbjl_endtime" property="sbjlEndtime" />
                <result column="gjjjl_endtime" property="gjjjlEndtime" />
                <result column="insure_num" property="insureNum" />
                <result column="insure_time" property="insureTime" />
                <result column="stop_num" property="stopNum" />
                <result column="stop_time" property="stopTime" />
                <result column="state" property="state" />
                <result column="qyid" property="qyid" />
                <result column="sbfaid" property="sbfaid" />
                <result column="gjjfaid" property="gjjfaid" />
                <result column="is_use" property="isUse" />
    </resultMap>
    
    <resultMap id="InsuredPersonnelMap" type="cn.timer.api.dto.sbgjj.InsuredPersonnelDto" >
                <result column="empnum" property="empnum" />
                <result column="empname" property="empname" />
                <result column="cbfacs" property="cbfacs" />
                <result column="dept" property="dept" />
                <result column="post" property="post" />
                <result column="sbcbstate" property="sbcbstate" />
                <result column="gjjcbstate" property="gjjcbstate" />
                <result column="jlmode" property="jlmode" />
                <result column="emphone" property="emphone" />
                <result column="emzjnum" property="emzjnum" />
                <result column="cbryid" property="cbryid" />
                <result column="csid" property="csid" />
                <result column="sbfaid" property="sbfaid" />
                <result column="sbjlstatime" property="sbjlstatime" />
                <result column="sbjljs" property="sbjljs" />
                <result column="gjjfaid" property="gjjfaid" />
                <result column="gjjjlstatime" property="gjjjlstatime" />
                <result column="gjjjljs" property="gjjjljs" />
    </resultMap>
    
    <resultMap id="YgglEmpInfoMap" type="cn.timer.api.bean.yggl.YgglMainEmp" >
        	<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="job_num" 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" />
    </resultMap>

    <sql id="Base_Column_List">
                id,
                user_num,
                sbcb_state,
                gjjcb_state,
                jl_mode,
                cbfacs,
                sbjl_statime,
                sbjljs,
                gjjjl_statime,
                gjjjljs,
                sbjl_endtime,
                gjjjl_endtime,
                insure_num,
                insure_time,
                stop_num,
                stop_time,
                state,
                qyid,
                sbfaid,
                gjjfaid
    </sql>
    
    <sql id="salary_List">
    	id,org_code,emp_num,age,appopenid,area,birthday,blood_type,bmgw_id,province_id,province,district_id,district,city_id,
		city,edu,english_name,head_url,hk_address,hk_type,is_jrkq,is_married,is_pregnant,jg_id,jg,job_status,job_type,language,
		address,mpopenid,mz,name,openid,job_num,password,phone,qq,rz_time,sex,sfzyx_time,sjzz_time,syq,unionid,wechat,work_address,work_email,
		work_phone,zj_num,zj_type,zpqd,zy,zz_remark,zz_time,zzmm,update_man,update_time,is_manager,before_leaving_sts,bmgw_name,custom_num
    </sql>
    
    <sql id="Base_Column_List_Alias">
                id SbgjjAdminCbry_id,
                user_num SbgjjAdminCbry_user_num,
                sbcb_state SbgjjAdminCbry_sbcb_state,
                gjjcb_state SbgjjAdminCbry_gjjcb_state,
                jl_mode SbgjjAdminCbry_jl_mode,
                cbfacs SbgjjAdminCbry_cbfacs,
                sbjl_statime SbgjjAdminCbry_sbjl_statime,
                sbjljs SbgjjAdminCbry_sbjljs,
                gjjjl_statime SbgjjAdminCbry_gjjjl_statime,
                gjjjljs SbgjjAdminCbry_gjjjljs,
                sbjl_endtime SbgjjAdminCbry_sbjl_endtime,
                gjjjl_endtime SbgjjAdminCbry_gjjjl_endtime,
                insure_num SbgjjAdminCbry_insure_num,
                insure_time SbgjjAdminCbry_insure_time,
                stop_num SbgjjAdminCbry_stop_num,
                stop_time SbgjjAdminCbry_stop_time,
                state SbgjjAdminCbry_state,
                qyid SbgjjAdminCbry_qyid,
                sbfaid SbgjjAdminCbry_sbfaid,
                gjjfaid SbgjjAdminCbry_gjjfaid
    </sql>


	 <select id="EmployeeListByorgCode" resultMap="YgglEmpInfoMap">
	     select <include refid="salary_List" /> 
	     	from yggl_main_emp
			    where org_code = #{orgCode,jdbcType=VARCHAR}
			    and job_status != 3
			and emp_num not in (select cbry.user_num from sbgjj_admin_cbry cbry where cbry.qyid = #{orgCode,jdbcType=VARCHAR})
	  </select>


<select id="InsuredPersonnel" resultMap="InsuredPersonnelMap">
		select emp.emp_num as empnum,
			 emp.`name` as empname,
			 emp.phone as emphone,
			 emp.zj_num as emzjnum,
			 cbry.id as cbryid,
			 cbry.cbfacs as cbfacs,
			 csbh.id as csid,
			 bmgw.dept,
			 bmgw.post,
			cbry.sbcb_state as sbcbstate,
			cbry.gjjcb_state as gjjcbstate,
			cbry.jl_mode as jlmode,
			cbry.sbfaid as sbfaid,
			cbry.sbjl_statime as sbjlstatime,
			cbry.sbjljs as sbjljs,
			cbry.gjjfaid as gjjfaid,
			cbry.gjjjl_statime as gjjjlstatime,
			cbry.gjjjljs as gjjjljs
			from yggl_main_emp emp 
	LEFT JOIN sbgjj_admin_cbry as cbry on cbry.user_num = emp.emp_num and cbry.state = 1 and cbry.qyid = #{orgcode}
	LEFT JOIN (select m.name as post,um.name as dept,m.id as mid
				 from zzgl_bmgw_m m 
				 left join zzgl_bmgw_m um on um.id = m.up_id  
			) as bmgw on bmgw.mid = emp.bmgw_id
	LEFT JOIN sbgjj_yj_csbh as csbh on csbh.city_name = cbry.cbfacs
	where emp.org_code = #{orgcode}
	<if test="title != null" >
    	and (emp.`name` like CONCAT('%',#{title},'%') or emp.emp_num = #{title})
    </if>
</select>

<select id="InsuredEmployees" resultMap="InsuredPersonnelMap">
		select emp.emp_num as empnum,
			 emp.`name` as empname,
			 emp.phone as emphone,
			 emp.zj_num as emzjnum,
			 cbry.id as cbryid,
			 cbry.cbfacs as cbfacs,
			 csbh.id as csid,
			 bmgw.dept,
			 bmgw.post,
			cbry.sbcb_state as sbcbstate,
			cbry.gjjcb_state as gjjcbstate,
			cbry.jl_mode as jlmode,
			cbry.sbfaid as sbfaid,
			cbry.sbjl_statime as sbjlstatime,
			cbry.sbjljs as sbjljs,
			cbry.gjjfaid as gjjfaid,
			cbry.gjjjl_statime as gjjjlstatime,
			cbry.gjjjljs as gjjjljs
			from yggl_main_emp emp 
	LEFT JOIN sbgjj_admin_cbry as cbry on cbry.user_num = emp.emp_num and cbry.state = 1
	LEFT JOIN (select m.name as post,um.name as dept,m.id as mid
				 from zzgl_bmgw_m m 
				 left join zzgl_bmgw_m um on um.id = m.up_id  
			) as bmgw on bmgw.mid = emp.bmgw_id
	LEFT JOIN sbgjj_yj_csbh as csbh on csbh.city_name = cbry.cbfacs
	where emp.org_code = #{param.orgcode}
	<if test="param.title != null" >
    	and (emp.`name` like CONCAT('%',#{param.title},'%') or emp.emp_num = #{param.title})
    </if>
</select>


    <insert id="insertsbgjjadmincbry" parameterType="cn.timer.api.bean.sbgjj.SbgjjAdminCbry" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO sbgjj_admin_cbry
        <trim prefix="(" suffix=")" suffixOverrides=",">
                        <if test ='null != userNum'>
                        user_num,
                        </if>
                        <if test ='null != sbcbState'>
                        sbcb_state,
                        </if>
                        <if test ='null != gjjcbState'>
                        gjjcb_state,
                        </if>
                        <if test ='null != jlMode'>
                        jl_mode,
                        </if>
                        <if test ='null != cbfacs'>
                        cbfacs,
                        </if>
                        <if test ='null != sbjlStatime'>
                        sbjl_statime,
                        </if>
                        <if test ='null != sbjljs'>
                        sbjljs,
                        </if>
                        <if test ='null != gjjjlStatime'>
                        gjjjl_statime,
                        </if>
                        <if test ='null != gjjjljs'>
                        gjjjljs,
                        </if>
                        <if test ='null != sbjlEndtime'>
                        sbjl_endtime,
                        </if>
                        <if test ='null != gjjjlEndtime'>
                        gjjjl_endtime,
                        </if>
                        <if test ='null != insureNum'>
                        insure_num,
                        </if>
                        <if test ='null != insureTime'>
                        insure_time,
                        </if>
                        <if test ='null != stopNum'>
                        stop_num,
                        </if>
                        <if test ='null != stopTime'>
                        stop_time,
                        </if>
                        <if test ='null != state'>
                        state,
                        </if>
                        <if test ='null != qyid'>
                        qyid,
                        </if>
                        <if test ='null != sbfaid'>
                        sbfaid,
                        </if>
                        <if test ='null != gjjfaid'>
                        gjjfaid,
                        </if>
                        <if test ='null != isUse'>
                        is_use
                        </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                        <if test ='null != userNum'>
                        #{userNum},
                        </if>
                        <if test ='null != sbcbState'>
                        #{sbcbState},
                        </if>
                        <if test ='null != gjjcbState'>
                        #{gjjcbState},
                        </if>
                        <if test ='null != jlMode'>
                        #{jlMode},
                        </if>
                        <if test ='null != cbfacs'>
                        #{cbfacs},
                        </if>
                        <if test ='null != sbjlStatime'>
                        #{sbjlStatime},
                        </if>
                        <if test ='null != sbjljs'>
                        #{sbjljs},
                        </if>
                        <if test ='null != gjjjlStatime'>
                        #{gjjjlStatime},
                        </if>
                        <if test ='null != gjjjljs'>
                        #{gjjjljs},
                        </if>
                        <if test ='null != sbjlEndtime'>
                        #{sbjlEndtime},
                        </if>
                        <if test ='null != gjjjlEndtime'>
                        #{gjjjlEndtime},
                        </if>
                        <if test ='null != insureNum'>
                        #{insureNum},
                        </if>
                        <if test ='null != insureTime'>
                        #{insureTime},
                        </if>
                        <if test ='null != stopNum'>
                        #{stopNum},
                        </if>
                        <if test ='null != stopTime'>
                        #{stopTime},
                        </if>
                        <if test ='null != state'>
                        #{state},
                        </if>
                        <if test ='null != qyid'>
                        #{qyid},
                        </if>
                        <if test ='null != sbfaid'>
                        #{sbfaid},
                        </if>
                        <if test ='null != gjjfaid'>
                        #{gjjfaid},
                        </if>
                        <if test ='null != isUse'>
                        #{isUse}
                        </if>
        </trim>
    </insert>

   <!--  <delete id="delete" >
        DELETE FROM sbgjj_admin_cbry
        WHERE id = #{id}
    </delete>

    <update id="update" parameterType="cn.timer.api.bean.sbgjj.SbgjjAdminCbry">
        UPDATE sbgjj_admin_cbry
        <set>
                    <if test ='null != userNum'>user_num = #{userNum},</if>
                    <if test ='null != sbcbState'>sbcb_state = #{sbcbState},</if>
                    <if test ='null != gjjcbState'>gjjcb_state = #{gjjcbState},</if>
                    <if test ='null != jlMode'>jl_mode = #{jlMode},</if>
                    <if test ='null != cbfacs'>cbfacs = #{cbfacs},</if>
                    <if test ='null != sbjlStatime'>sbjl_statime = #{sbjlStatime},</if>
                    <if test ='null != sbjljs'>sbjljs = #{sbjljs},</if>
                    <if test ='null != gjjjlStatime'>gjjjl_statime = #{gjjjlStatime},</if>
                    <if test ='null != gjjjljs'>gjjjljs = #{gjjjljs},</if>
                    <if test ='null != sbjlEndtime'>sbjl_endtime = #{sbjlEndtime},</if>
                    <if test ='null != gjjjlEndtime'>gjjjl_endtime = #{gjjjlEndtime},</if>
                    <if test ='null != insureNum'>insure_num = #{insureNum},</if>
                    <if test ='null != insureTime'>insure_time = #{insureTime},</if>
                    <if test ='null != stopNum'>stop_num = #{stopNum},</if>
                    <if test ='null != stopTime'>stop_time = #{stopTime},</if>
                    <if test ='null != state'>state = #{state},</if>
                    <if test ='null != qyid'>qyid = #{qyid},</if>
                    <if test ='null != sbfaid'>sbfaid = #{sbfaid},</if>
                    <if test ='null != gjjfaid'>gjjfaid = #{gjjfaid}</if>
        </set>
        WHERE id = #{id}
    </update>


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

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

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


</mapper>