<?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="com.engine.organization.mapper.trigger.StaffTriggerMapper">
    <update id="updateOrgStaffs">
        update jcl_org_map
        <set>
            FPLAN = #{fPlan},
            FONJOB = #{fOnJob},
        </set>
        where FTYPE =#{fType} and FOBJID=#{fObjId}
        AND FDATEBEGIN &lt;= #{currentDate}
        AND FDATEEND &gt;= #{currentDate}
    </update>


    <select id="countCompanyUsers" resultType="java.lang.Integer">
        select count(1)
        from hrmresource
        where status &lt;= 3
          and subcompanyid1 = #{ecCompanyId}
    </select>
    <select id="countDepartmentUsers" resultType="java.lang.Integer">
        select count(1)
        from hrmresource
        where status &lt;= 3
          and departmentid = #{ecDepartmentId}
    </select>

    <select id="countJobUsers" resultType="java.lang.Integer">
        select count(1)
        from hrmresource
        where status &lt;= 3
          and jobtitle = #{jobTitle}
    </select>
    <select id="countAllUsers" resultType="java.lang.Integer">
        select count(1)
        from hrmresource
        where status &lt;= 3
    </select>
    <select id="countCompanyStaffNum" resultType="java.lang.Integer">
        select sum(staff_num)
        from JCL_ORG_STAFF
        where plan_id in (select id
                          from JCL_ORG_STAFFPLAN
                          where time_start &lt;= #{currentDate}
                            and time_end &gt;= #{currentDate}
                            and delete_type = 0
                            and control_dimension = 1)
          and comp_id = #{companyId}
          and delete_type = 0
    </select>
    <select id="countDepartmentStaffNum" resultType="java.lang.Integer">
        select sum(staff_num)
        from JCL_ORG_STAFF
        where plan_id in (select id
                          from JCL_ORG_STAFFPLAN
                          where time_start &lt;= #{currentDate}
                            and time_end &gt;= #{currentDate}
                            and delete_type = 0
                            and control_dimension = 2)
          and dept_id = #{departmentId}
          and delete_type = 0
    </select>
    <select id="countJobStaffNum" resultType="java.lang.Integer">
        select sum(staff_num)
        from JCL_ORG_STAFF
        where plan_id in (select id
                          from JCL_ORG_STAFFPLAN
                          where time_start &lt;= #{currentDate}
                            and time_end &gt;= #{currentDate}
                            and delete_type = 0
                            and control_dimension = 3)
          and job_id = #{jobId}
          and delete_type = 0
    </select>
    <select id="getIdByObjIdAndType" resultType="java.lang.String">
        select id
        from jcl_org_map
        where fobjid = #{fObjId}
          and ftype = #{fType}
          AND FDATEBEGIN &lt;= #{currentDate}
          AND FDATEEND &gt;= #{currentDate}
    </select>
    <select id="sumPlanByParentId" resultType="java.lang.Integer">
        select sum(fplan)
        from jcl_org_map
        where fparentid = #{parentId}
          AND FDATEBEGIN &lt;= #{currentDate}
          AND FDATEEND &gt;= #{currentDate}
    </select>
    <select id="sumOnJobByParentId" resultType="java.lang.Integer">
        select sum(fonjob)
        from jcl_org_map
        where fparentid = #{parentId}
          AND FDATEBEGIN &lt;= #{currentDate}
          AND FDATEEND &gt;= #{currentDate}
    </select>
    <select id="countOnJobByJObId" resultType="java.lang.Integer">
        select count(1)
        from jcl_org_hrmresource a
        where a.job_title = #{jobId} and a.status &lt; 4
    </select>
</mapper>