<?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.condition.QuickSearchMapper">


    <select id="getQuickSearchSetting" resultType="com.engine.organization.entity.search.QuickSearchSetting">
        select id, isquicksearch, isshowtype, ishidename
        from jcl_quicksearch_setting
        where belongto = #{belongTo}
    </select>

    <select id="getQuickSearchConditionList"
            resultType="com.engine.organization.entity.search.QuickSearchCondition">
        select c.id, fieldid, c.customname, c.type, c.orderid, c.showmodel
        from jcl_quicksearch_condition c
        where belongto = #{belongTo}
          and modelid = #{modelId}
        order by c.orderid, c.id
    </select>

    <select id="getQuickSearchConditionById"
            resultType="com.engine.organization.entity.search.QuickSearchCondition">
        select c.id, fieldid, c.customname, c.type, c.orderid, c.showmodel
        from jcl_quicksearch_condition c
        where id = #{id}
    </select>

    <select id="getQuickSearchOptionList" resultType="com.engine.organization.entity.search.QuickSearchOption">
        select b.fieldid, b.fieldlabel, b.fieldname, fieldhtmltype, b.type
        from hrm_formfield b
                 inner join hrm_fieldgroup c on c.id = b.groupid and c.grouptype in (-1, 1, 3)
    </select>
    <select id="getQuickSearchDetailByCid"
            resultType="com.engine.organization.entity.search.QuickSearchDetail">
        select id,
               customname,
               minnum,
               maxnum,
               type,
               orderid,
               fieldid,
               belongto
        from jcl_quicksearch_detail
        where cid = #{cId}
        order by orderid, id
    </select>

    <select id="getQuickSearchDetailById" resultType="com.engine.organization.entity.search.QuickSearchDetail">
        select id,
               customname,
               minnum,
               maxnum,
               type,
               orderid,
               fieldid,
               belongto
        from jcl_quicksearch_detail
        where id = #{id}
    </select>

    <select id="getQuickSearchFieldListByConditionId"
            resultType="com.engine.organization.entity.search.QuickSearchField">
        SELECT *
        FROM (SELECT t2.fielddbtype, t2.fieldhtmltype, t2.type, t1.scopeid as scopeId, t2.fieldname
              FROM cus_formfield t1,
                   cus_formdict t2
              WHERE t1.fieldid = t2.id
                AND t1.scope = 'HrmCustomFieldByInfoType'
              UNION ALL
              SELECT t3.fielddbtype, t3.fieldhtmltype, t3.TYPE, c.grouptype as scopeId, t3.fieldname
              FROM hrm_formfield t3
                       inner join hrm_fieldgroup c on c.id = t3.groupid and c.grouptype in (-1, 1, 3)) hrmallfield
        WHERE FIELDHTMLTYPE != '6'
          and fieldname = #{fieldName}
          and scopeId = #{scopeId}
    </select>
    <select id="getHrmFormFieldByFieldId"
            resultType="com.engine.organization.entity.jclimport.po.HrmFormFieldPO">
        select a.fieldid,
               a.fieldname,
               a.issystem,
               a.fieldlabel labelname,
               a.ismand,
               a.fielddbtype,
               a.fieldhtmltype,
               a.type,
               a.dmlurl
        from hrm_formfield a
        where a.fieldhtmltype != '6'
          and a.fieldid = #{fieldId}
    </select>
    <select id="getSelectItemListByFieldId"
            resultType="com.engine.organization.entity.jclimport.po.JclSelectItem">
        select selectvalue, selectname
        from hrm_selectitem
        where fieldid = #{fieldId}
    </select>
    <select id="getAllFieldInfo" resultType="com.engine.organization.entity.jclimport.po.CusFormFieldPO">
        SELECT *
        FROM (SELECT t1.fieldid,
                     t2.fieldname,
                     t1.fieldlable fieldLabel,
                     t1.ismand,
                     t2.fielddbtype,
                     t2.fieldhtmltype,
                     t2.type,
                     t1.dmlurl,
                     fieldorder,
                     groupid,
                     t1.scopeid as scopeId,
                     'cus'      as tablename
              FROM cus_formfield t1,
                   cus_formdict t2
              WHERE t1.fieldid = t2.id
                AND t1.scope = 'HrmCustomFieldByInfoType'
              UNION ALL
              SELECT t3.fieldid,
                     t3.fieldname,
                     t3.fieldlabel  fieldLabel,
                     t3.ismand,
                     t3.fielddbtype,
                     t3.fieldhtmltype,
                     t3.TYPE,
                     t3.dmlurl,
                     t3.fieldorder,
                     t3.groupid,
                     c.grouptype as scopeId,
                     'hrm'       as tablename
              FROM hrm_formfield t3
                       inner join hrm_fieldgroup c on c.id = t3.groupid and c.grouptype in (-1, 1, 3)) hrmallfield
        WHERE FIELDHTMLTYPE != '6'
        ORDER BY hrmallfield.groupid, hrmallfield.fieldorder
    </select>

    <insert id="insertQuickSearchSetting">
        insert into jcl_quicksearch_setting(belongto,
                                            isquicksearch,
                                            isshowtype,
                                            ishidename,
                                            updatetor,
                                            updatedate,
                                            updatetime)
        values (#{quickSearchSetting.belongTo},
                #{quickSearchSetting.isQuickSearch},
                #{quickSearchSetting.isShowType},
                #{quickSearchSetting.isHideName},
                #{quickSearchSetting.updateTor},
                #{quickSearchSetting.updateDate},
                #{quickSearchSetting.updateTime})
    </insert>

    <update id="updateQuickSearchSetting">
        update jcl_quicksearch_setting
        set isquicksearch=#{quickSearchSetting.isQuickSearch},
            isshowtype=#{quickSearchSetting.isShowType},
            ishidename=#{quickSearchSetting.isHideName}
        where id = #{quickSearchSetting.id}
    </update>

    <insert id="insertQuickSearchCondition">
        insert into jcl_quicksearch_condition(belongto, fieldid, customname, type, orderid, showmodel, modelid)
        values (#{quickSearchCondition.belongTo}, #{quickSearchCondition.fieldId}, #{quickSearchCondition.customName},
                #{quickSearchCondition.type}, #{quickSearchCondition.orderId}, #{quickSearchCondition.showModel},
                #{quickSearchCondition.modelId})
    </insert>

    <update id="updateQuickSearchCondition">
        update jcl_quicksearch_condition
        set belongto=#{quickSearchCondition.belongTo},
            fieldid=#{quickSearchCondition.fieldId},
            customname=#{quickSearchCondition.customName},
            type=#{quickSearchCondition.type},
            orderid=#{quickSearchCondition.orderId},
            showmodel=#{quickSearchCondition.showModel},
            modelid = #{quickSearchCondition.modelId}
        where id = #{quickSearchCondition.id}
    </update>

    <insert id="insertQuickSearchDetail">
        insert into jcl_quicksearch_detail(cid, customname, minnum, maxnum, type, orderid, fieldid, belongto)
        values (#{quickSearchDetail.cId}, #{quickSearchDetail.customName}, #{quickSearchDetail.minNum},
                #{quickSearchDetail.maxNum}, #{quickSearchDetail.type}, #{quickSearchDetail.orderId},
                #{quickSearchDetail.fieldId}, #{quickSearchDetail.belongTo})
    </insert>

    <update id="updateQuickSearchDetail">
        update jcl_quicksearch_detail
        set cid=#{quickSearchDetail.cId},
            customname=#{quickSearchDetail.customName},
            minnum=#{quickSearchDetail.minNum},
            maxnum=#{quickSearchDetail.maxNum},
            type=#{quickSearchDetail.type},
            orderid=#{quickSearchDetail.orderId},
            fieldid=#{quickSearchDetail.fieldId},
            belongto=#{quickSearchDetail.belongTo}
        where id = #{quickSearchDetail.id}
    </update>

    <delete id="deleteQuickSearchDetailByCid">
        delete
        from jcl_quicksearch_detail
        where cid = #{cId}
    </delete>
    <delete id="deleteQuickSearchConditionByIds">
        delete from jcl_quicksearch_condition where id in
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <delete id="deleteQuickSearchDetailByCids">
        delete from jcl_quicksearch_detail where cid in
        <foreach collection="cIds" open="(" item="cid" separator="," close=")">
            #{cid}
        </foreach>
    </delete>

    <delete id="deleteQuickSearchDetailByIds">
        delete from jcl_quicksearch_detail where id in
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </delete>


</mapper>