FrontDeptMapper.xml 13 KB
<?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.lhcredit.project.business.frontDept.mapper.FrontDeptMapper">

    <resultMap type="FrontDept" id="FrontDeptResult">
        <result property="id"    column="id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="ancestors"    column="ancestors"    />
        <result property="deptName"    column="dept_name"    />
        <result property="sort"    column="sort"    />
        <result property="deptType"    column="dept_type"    />
        <result property="isEnable"    column="is_enable"    />
        <result property="contractType"    column="contract_type"    />
        <result property="signingMethod"    column="signing_method"    />
        <result property="contractNum"    column="contract_num"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="parentName" column="parent_name" />
        <result property="bizTypes" column="biz_types" />
        <result property="reportNum" column="report_num" />
        <result property="financeNum" column="finance_num" />
        <result property="monitorNum" column="monitor_num" />
        <result property="reportParams"    column="report_params"    />
        <result property="monitorBegin"    column="monitor_begin"    />
        <result property="monitorEnd"    column="monitor_end"    />
    </resultMap>

    <sql id="selectFrontDeptVo">
        select id, parent_id, ancestors, dept_name, sort, dept_type, is_enable, contract_type, report_params ,signing_method, contract_num, create_by, create_time, update_by, update_time, remark,biz_types,report_num,finance_num,monitor_num,monitor_begin,monitor_end from front_dept
    </sql>

    <select id="selectFrontDeptList" parameterType="FrontDept" resultMap="FrontDeptResult">
        <include refid="selectFrontDeptVo"/>
        <where>
            <if test="id != null "> and id = #{id}</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="ancestors != null  and ancestors != '' "> and ancestors = #{ancestors}</if>
            <if test="deptName != null  and deptName != '' "> and dept_name like CONCAT('%',#{deptName},'%')</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="deptType != null  and deptType != '' "> and dept_type = #{deptType}</if>
            <if test="isEnable != null  and isEnable != '' "> and is_enable = #{isEnable}</if>
            <if test="contractType != null  and contractType != '' "> and contract_type = #{contractType}</if>
            <if test="signingMethod != null  and signingMethod != '' "> and signing_method = #{signingMethod}</if>
            <if test="contractNum != null  and contractNum != '' "> and contract_num = #{contractNum}</if>
            <if test="monitorBegin != null  and monitorBegin != '' "> and monitor_begin = #{monitorBegin}</if>
            <if test="monitorEnd != null  and monitorEnd != '' "> and monitor_end = #{monitorEnd}</if>
            <if test="createBy != null  and createBy != '' "> and create_by = #{createBy}</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
            <if test="updateBy != null  and updateBy != '' "> and update_by = #{updateBy}</if>
            <if test="updateTime != null "> and update_time = #{updateTime}</if>
            <if test="remark != null  and remark != '' "> and remark = #{remark}</if>
        </where>
    </select>

    <select id="getFrontDeptById" parameterType="Long" resultMap="FrontDeptResult">
        <include refid="selectFrontDeptVo"></include>
        <where>
            id=#{id}
        </where>
    </select>

    <select id="getFrontDeptByName" parameterType="Long" resultMap="FrontDeptResult">
        <include refid="selectFrontDeptVo"></include>
        <where>
            dept_name=#{orgName}
        </where>
    </select>

    <select id="selectFrontDeptById" parameterType="Long" resultMap="FrontDeptResult">
        select d.id, d.parent_id, d.ancestors, d.dept_name,d.report_params, d.sort, d.dept_type, d.is_enable, d.contract_type, d.contract_num,d.biz_types,d.report_num,d.finance_num,d.monitor_num,d.monitor_begin,d.monitor_end,
               (select dept_name from front_dept where id = d.parent_id) parent_name
        from front_dept d
        where d.id = #{id}
    </select>

    <select id="selectFrontDeptByName" parameterType="String" resultMap="FrontDeptResult">
        <include refid="selectFrontDeptVo"/>
        where dept_name = #{deptName}
    </select>

    <select id="getDeptListByIds"  parameterType="long" resultMap="FrontDeptResult">
        <include refid="selectFrontDeptVo"/>
        <where>
            id IN
            <foreach item="id" collection="list" open="(" separator="," close=")">
                #{id}
            </foreach>
        </where>
    </select>

  <insert id="insertFrontDept" parameterType="FrontDept" useGeneratedKeys="true" keyProperty="id">
        insert into front_dept
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="parentId != null  ">parent_id,</if>
			<if test="ancestors != null  and ancestors != ''  ">ancestors,</if>
			<if test="deptName != null  and deptName != ''  ">dept_name,</if>
			<if test="sort != null  ">sort,</if>
			<if test="deptType != null  and deptType != ''  ">dept_type,</if>
			<if test="isEnable != null  and isEnable != ''  ">is_enable,</if>
			<if test="contractType != null  and contractType != ''  ">contract_type,</if>
			<if test="signingMethod != null  and signingMethod != ''  ">signing_method,</if>
			<if test="contractNum != null  and contractNum != ''  ">contract_num,</if>
			<if test="createBy != null  and createBy != ''  ">create_by,</if>
			<if test="createTime != null  ">create_time,</if>
			<if test="updateBy != null  and updateBy != ''  ">update_by,</if>
			<if test="updateTime != null  ">update_time,</if>
			<if test="remark != null  and remark != ''  ">remark,</if>
			<if test="bizTypes != null  and bizTypes != ''  ">biz_types,</if>
			<if test="reportNum != null  ">report_num,</if>
			<if test="financeNum != null  ">finance_num,</if>
			<if test="monitorNum != null  ">monitor_num,</if>
			<if test="reportParams != null  and reportParams != ''  ">report_params,</if>
			<if test="monitorBegin != null  and monitorBegin != ''  ">monitor_begin,</if>
			<if test="monitorEnd != null  and monitorEnd != ''  ">monitor_end,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="parentId != null  ">#{parentId},</if>
			<if test="ancestors != null  and ancestors != ''  ">#{ancestors},</if>
			<if test="deptName != null  and deptName != ''  ">#{deptName},</if>
			<if test="sort != null  ">#{sort},</if>
			<if test="deptType != null  and deptType != ''  ">#{deptType},</if>
			<if test="isEnable != null  and isEnable != ''  ">#{isEnable},</if>
			<if test="contractType != null  and contractType != ''  ">#{contractType},</if>
			<if test="signingMethod != null  and signingMethod != ''  ">#{signingMethod},</if>
			<if test="contractNum != null  and contractNum != ''  ">#{contractNum},</if>
			<if test="createBy != null  and createBy != ''  ">#{createBy},</if>
			<if test="createTime != null  ">#{createTime},</if>
			<if test="updateBy != null  and updateBy != ''  ">#{updateBy},</if>
			<if test="updateTime != null  ">#{updateTime},</if>
			<if test="remark != null  and remark != ''  ">#{remark},</if>
			<if test="bizTypes != null  and bizTypes != ''  ">#{bizTypes},</if>
			<if test="reportNum != null  ">#{reportNum},</if>
			<if test="financeNum != null  ">#{financeNum},</if>
			<if test="monitorNum != null  ">#{monitorNum},</if>
			<if test="reportParams != null  and reportParams != ''  ">#{reportParams},</if>
            <if test="monitorBegin != null  and monitorBegin != ''  ">#{monitorBegin},</if>
            <if test="monitorEnd != null  and monitorEnd != ''  ">#{monitorEnd},</if>
         </trim>
    </insert>

    <update id="updateFrontDept" parameterType="FrontDept">
        update front_dept
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null  ">parent_id = #{parentId},</if>
            <if test="ancestors != null  and ancestors != ''  ">ancestors = #{ancestors},</if>
            <if test="deptName != null  and deptName != ''  ">dept_name = #{deptName},</if>
            <if test="sort != null  ">sort = #{sort},</if>
            <if test="deptType != null  and deptType != ''  ">dept_type = #{deptType},</if>
            <if test="isEnable != null  and isEnable != ''  ">is_enable = #{isEnable},</if>
            <if test="contractType != null  and contractType != ''  ">contract_type = #{contractType},</if>
            <if test="signingMethod != null  and signingMethod != ''  ">signing_method = #{signingMethod},</if>
            <if test="contractNum != null  and contractNum != ''  ">contract_num = #{contractNum},</if>
            <if test="createBy != null  and createBy != ''  ">create_by = #{createBy},</if>
            <if test="createTime != null  ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''  ">update_by = #{updateBy},</if>
            <if test="updateTime != null  ">update_time = #{updateTime},</if>
            <if test="remark != null  and remark != ''  ">remark = #{remark},</if>
            <if test="bizTypes != null  and bizTypes != ''  ">biz_types = #{bizTypes},</if>
            <if test="reportNum != null  ">report_num = #{reportNum},</if>
            <if test="financeNum != null  ">finance_num = #{financeNum},</if>
            <if test="monitorNum != null  ">monitor_num = #{monitorNum},</if>
            <if test="reportParams != null  and reportParams != ''  ">report_params = #{reportParams},</if>
            <if test="monitorBegin != null  and monitorBegin != '' ">  monitor_begin = #{monitorBegin},</if>
            <if test="monitorEnd != null  and monitorEnd != '' ">  monitor_end = #{monitorEnd},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateFrontDeptByAncestors" parameterType="FrontDept">
        update front_dept
        <trim prefix="SET" suffixOverrides=",">
            <if test="bizTypes != null  ">biz_types = #{bizTypes},</if>
            <if test="updateTime != null  ">update_time = #{updateTime},</if>
        </trim>
        <where>
            id = #{id}
            OR ancestors LIKE  CONCAT('%',#{id},'%')
        </where>
    </update>

    <delete id="deleteFrontDeptById" parameterType="Long">
        delete from front_dept where id = #{id}
    </delete>

    <delete id="deleteFrontDeptByIds" parameterType="String">
        delete from front_dept where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectFrontDeptByOrgId" resultType="com.lhcredit.project.business.frontDept.domain.FrontDept">
        SELECT
            id,
            parent_id as parentId,
            ancestors,
            dept_name as deptName,
            sort,
            dept_type as deptType,
            is_enable as isEnable,
            contract_type as contractType,
            signing_method as signingMethod,
            contract_num as contractNum,
            biz_types as bizTypes,
            monitor_begin as monitorBegin,
            monitor_end as monitorEnd
        FROM front_dept WHERE id = #{orgId}
    </select>
    <select id="findDeptTypeAll" resultType="com.lhcredit.project.business.frontDept.domain.FrontDept">
        SELECT * FROM front_dept de WHERE
            FIND_IN_SET(#{orgId},
                        de.ancestors) or id = #{orgId}
    </select>

    <select id="checkDeptNameUnique" resultMap="FrontDeptResult">
        <include refid="selectFrontDeptVo"/>
        where dept_name=#{deptName} and parent_id = #{parentId}
    </select>

    <select id="selectDeptTreeByOrgId" resultMap="FrontDeptResult">
        SELECT * FROM front_dept WHERE id=#{orgId}
        UNION ALL
        SELECT * FROM front_dept WHERE id IN(SELECT dept_id FROM org_dept WHERE org_id=#{orgId})
    </select>
    <select id="likeByName" resultMap="FrontDeptResult">
        <include refid="selectFrontDeptVo"/>
    where dept_name like CONCAT('%',#{name},'%')
    </select>

    <select id="getParentOrgInfoByOrgId" parameterType="long" resultMap="FrontDeptResult">
        SELECT
            f.id,
            f.parent_id,
            f.dept_name,
            d.dept_name AS parent_name
        FROM
            front_dept f
              LEFT JOIN front_dept d ON f.parent_id = d.id
        <where>
            f.id = #{orgId}
        </where>
    </select>
    <select id="getparentId" parameterType="long" resultMap="FrontDeptResult">
        <include refid="selectFrontDeptVo"/>
        where parent_id =#{id}
    </select>

</mapper>