<?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.hrmresource.SystemDataMapper">

    <resultMap id="CustomFieldMap" type="com.engine.organization.entity.jclimport.po.CusFormFieldPO">
        <result column="fieldlable" property="fieldLabel"/>
        <result column="fieldid" property="fieldId"/>
        <result column="fieldname" property="fieldName"/>
        <result column="ismand" property="required"/>
        <result column="fieldhtmltype" property="fieldHtmlType"/>
        <result column="type" property="type"/>
        <result column="dmlurl" property="dmlUrl"/>
        <result column="scopeid" property="scopeId"/>
        <result column="tablename" property="tableName"/>
    </resultMap>

    <resultMap id="SelectItemMap" type="com.engine.organization.entity.jclimport.po.JclSelectItem">
        <result column="fieldid" property="fieldId"/>
        <result column="selectvalue" property="selectValue"/>
        <result column="selectname" property="selectName"/>
    </resultMap>

    <resultMap id="RecordMap" type="com.engine.organization.entity.commom.RecordInfo">
        <result column="uuid" property="uuid"/>
        <result column="id" property="id"/>
        <result column="canceled" property="canceled"/>
    </resultMap>

    <insert id="insertCusFieldData">
        insert into cus_fielddata(scope, scopeid, id)
        values ('HrmCustomFieldByInfoType', #{scopeId}, #{id})
    </insert>

    <update id="updateResourceJobTitleByIds">
        update hrmresource set JOBTITLE = #{jobTitle} where id in
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="updateCusFieldData">
        update cus_fielddata
        <set>
            field100001=#{field100001},
            field100002=#{field100002},
            field100003=#{field100003},
            field100008=#{field100008},
            field100006=#{field100006},
            field100007=#{field100007},
            field100005=#{field100005},
            field100010=#{field100010},
            field100009=#{field100009},
        </set>
        where scope = 'HrmCustomFieldByInfoType'
        and id = #{id}
        and scopeid = #{scopeId}
    </update>

    <!--    <select id="getSysLanguageByLicense" resultType="com.alibaba.fastjson.JSONObject">-->
    <!--        select multilanguage, (select id from syslanguage where language='简体中文' or language='中文') as cnLanguageId-->
    <!--        from license-->
    <!--    </select>-->

    <!--    <select id="getSysLanguageByActivable" resultType="com.alibaba.fastjson.JSONObject">-->
    <!--        select id, language-->
    <!--        from syslanguage-->
    <!--        where activable = 1-->
    <!--    </select>-->

    <!--    <select id="getHrmEducationLevelData" resultType="com.alibaba.fastjson.JSONObject">-->
    <!--        select id, name-->
    <!--        from HrmEducationLevel-->
    <!--    </select>-->

    <!--    <select id="getHrmJobCallData" resultType="com.alibaba.fastjson.JSONObject">-->
    <!--        select id, name-->
    <!--        from HrmJobCall-->
    <!--    </select>-->

    <!--    <select id="getHrmLocationsByCountryId" resultType="com.alibaba.fastjson.JSONObject">-->
    <!--        select id, locationname-->
    <!--        from HrmLocations-->
    <!--        where countryid = 1-->
    <!--    </select>-->

    <!--    <select id="getHrmUseKindData" resultType="com.alibaba.fastjson.JSONObject">-->
    <!--        select id, name-->
    <!--        from HrmUseKind-->
    <!--    </select>-->
    <select id="getScCompanyNameById" resultType="java.lang.String">
        select subcompanyname
        from hrmsubcompany
        where id = #{companyId}
    </select>
    <select id="getScDepartmentNameById" resultType="java.lang.String">
        select departmentname
        from hrmdepartment
        where id = #{departmentId}
    </select>
    <select id="getScHrmResourceNameById" resultType="java.lang.String">
        select lastname
        from hrmresource
        where id = #{managerId}
    </select>
    <select id="getHrmObjectByID" resultMap="RecordMap">
        select *
        from ${tableName}
        where id = #{id}
    </select>
    <select id="getHrmObjectByUUID" resultMap="RecordMap">
        select *
        from ${tableName}
        where uuid = #{uuid}
    </select>
    <select id="getHrmJobTitleByName" resultMap="RecordMap">
        select *
        from hrmjobtitles
        where jobtitlename = #{name}
    </select>
    <select id="getHrmResourceIds" resultType="java.lang.Long">
        select id
        from hrmresource
        where departmentid = #{departmentId}
          And jobTitle = #{jobTitle}
    </select>
    <select id="getHrmFieldBeanList" resultMap="CustomFieldMap">
        select b.labelname   as fieldlable,
               '0' as scopeid,
               a.fieldid,
               a.fieldname,
               a.ismand,
               a.fieldhtmltype,
               a.type,
               'hrmresource' as tablename
        from hrm_formfield a
                 inner join htmllabelinfo b on a.fieldlabel = b.indexid and b.languageid = 7
        where a.fielddbtype != '6'
        order by groupid, fieldorder
    </select>
    <select id="getHrmCustomFieldList" resultMap="CustomFieldMap">
        select b.labelname      as fieldlable,
               a.scopeid,
               a.fieldid,
               a.hrm_fieldlable as fieldname,
               a.ismand,
               c.fieldhtmltype,
               c.type,
               a.dmlurl,
               'cus_fielddata'  as tablename
        from cus_formfield a
                 inner join htmllabelinfo b on a.fieldlable = b.indexid and b.languageid = 7
                 inner join cus_formdict c on a.fieldid = c.id and c.fieldhtmltype != '6'
        order by groupid, fieldorder
    </select>
    <select id="getSelectItems" resultMap="SelectItemMap">
        select fieldid, selectvalue, selectname
        from ${tableName} and fieldid = #{fieldId}
    </select>
    <select id="getHrmFieldBeanListByFields" resultMap="CustomFieldMap">
        select b.labelname as fieldlable,
        a.fieldid,
        a.fieldname,
        a.ismand,
        a.fieldhtmltype,
        a.type,
        '0' as scopeid,
        'hrmresource' as tablename
        from hrm_formfield a
        inner join htmllabelinfo b on a.fieldlabel = b.indexid and b.languageid = 7
        where a.fielddbtype != '6' and a.isuse = '1'
        and a.fieldname in
        <foreach collection="fields" open="(" item="field" separator="," close=")">
            #{field}
        </foreach>
        order by groupid ,fieldorder
    </select>
    <select id="getHrmCusFieldDataByIdAndScopeId"
            resultType="com.engine.organization.entity.cusfielddata.po.CusFieldData">
        select *
        from cus_fielddata
        where scope = 'HrmCustomFieldByInfoType'
          and scopeid = #{scopeId}
          and id = #{id}
    </select>
    <select id="getHrmResourceMaxId" resultType="java.lang.Long">
        select max(id)
        from hrmresource
    </select>
    <select id="getHrmResourceIdsByDept" resultType="java.lang.Long">
        select id
        from hrmresource
        where departmentid = #{departmentId}
    </select>


</mapper>