<?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.willalp.system.mapper.SysDeptJobMapper">

    <resultMap type="SysDeptJob" id="SysDeptJobResult">
        <result property="jobId" column="job_id"/>
        <result property="parentId" column="parent_id"/>
        <result property="ancestors" column="ancestors"/>
        <result property="jobCode" column="job_code"/>
        <result property="jobName" column="job_name"/>
        <result property="status" column="status"/>
        <result property="jgid" column="jgid"/>
        <result property="deptId" column="dept_id"/>
        <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="isDelete" column="is_delete"/>
    </resultMap>

    <sql id="selectSysDeptJobVo">
        select job_id, parent_id, ancestors, job_code, job_name, status, jgid, dept_id, create_by, create_time, update_by, update_time, remark, is_delete        from sys_dept_job
    </sql>

    <select id="selectSysDeptJobList" parameterType="SysDeptJob" resultMap="SysDeptJobResult">
        <include refid="selectSysDeptJobVo"/>
        <where>
            is_delete = 0
            <if test="jobCode != null  and jobCode != ''">
                and job_code = #{jobCode}
            </if>
            <if test="jobName != null  and jobName != ''">
                and job_name like concat('%', #{jobName}, '%')
            </if>
            <if test="status != null  and status != ''">
                and status = #{status}
            </if>
            <if test="jgid != null  and jgid != ''">
                and jgid = #{jgid}
            </if>
            <if test="deptId != null  and deptId != ''">
                and dept_id = #{deptId}
            </if>
        </where>
    </select>

    <select id="selectById" parameterType="SysDeptJob" resultMap="SysDeptJobResult">
        <include refid="selectSysDeptJobVo"/>
        where is_delete = 0 and job_id = #{jobId}
    </select>

    <update id="updateSysDeptJob" parameterType="SysDeptJob">
        update sys_dept_job
        <set>
            <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
            <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
            <if test="jobCode != null and jobCode != ''">job_code = #{jobCode},</if>
            <if test="jobName != null and jobName != ''">job_name = #{jobName},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="status != null and status  != ''">status = #{status},</if>
            <if test="jgid != null and jgid != ''">jgid = #{jgid},</if>
            <if test="deptId != null and deptId != ''">dept_id = #{deptId},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            update_time = sysdate()
        </set>
        where job_id = #{jobId}
    </update>

    <update id="deleteSysDeptJobByJobId">
        update sys_dept_job set is_delete = 1 where job_id = #{jobId}
    </update>
</mapper>
