<?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.ruoyi.oa.mapper.CmcRecruitMapper">

    <resultMap type="CmcRecruit" id="CmcRecruitResult">
        <result property="recruitId"    column="recruit_id"    />
        <result property="applier"    column="applier"    />
        <result property="applyDept"    column="apply_dept"    />
        <result property="projectId"    column="project_id"    />
        <result property="applyDate"    column="apply_date"    />
        <result property="postName"    column="post_name"    />
        <result property="postNumber"    column="post_number"    />
        <result property="duty"    column="duty"    />
        <result property="qualification"    column="qualification"    />
        <result property="wage"    column="wage"    />
        <result property="deptComment"    column="dept_comment"    />
        <result property="deptUserId"    column="dept_user_id"    />
        <result property="deptTime"    column="dept_time"    />
        <result property="managerComment"    column="manager_comment"    />
        <result property="managerUserId"    column="manager_user_id"    />
        <result property="managerTime"    column="manager_time"    />
        <result property="zjlComment"    column="zjl_comment"    />
        <result property="zjlUserId"    column="zjl_user_id"    />
        <result property="zjlTime"    column="zjl_time"    />
        <association property="applierUser"    javaType="SysUser"         resultMap="ApplierUserResult" />
        <association property="deptUser"    javaType="SysUser"         resultMap="DeptUserResult" />
        <association property="managerUser"    javaType="SysUser"         resultMap="ManagerUserResult" />
        <association property="zjlUser"    javaType="SysUser"         resultMap="ZjlUserResult" />
        <association property="dept"    javaType="SysDept"         resultMap="SysDeptResult" />
        <association property="project"    javaType="CmcProject"         resultMap="CmcProjectResult" />
    </resultMap>

    <resultMap type="SysUser" id="ApplierUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="applier_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="DeptUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="dept_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="ManagerUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="manager_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="ZjlUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="zjl_nick_name"    />
    </resultMap>

    <resultMap type="SysDept" id="SysDeptResult">
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
    </resultMap>

    <resultMap type="CmcProject" id="CmcProjectResult">
        <result property="projectId"    column="project_id"    />
        <result property="projectNumber"    column="project_number"    />
        <result property="projectName"    column="project_name"    />
        <result property="undertakingDept"    column="undertaking_dept"    />
    </resultMap>

    <sql id="selectCmcRecruitVo">
        select r.recruit_id, r.applier, u.nick_name as applier_nick_name, d.dept_name, r.apply_dept, r.project_id, p.project_number, p.project_name, p.undertaking_dept, r.apply_date, r.post_name, r.post_number, r.duty,
        r.qualification, r.wage, r.dept_comment, r.dept_user_id, u1.nick_name as dept_nick_name, r.dept_time, r.manager_comment, r.manager_user_id, u2.nick_name as manager_nick_name, r.manager_time,
        r.zjl_comment, r.zjl_user_id, u3.nick_name as zjl_nick_name, r.zjl_time from cmc_recruit as r
        left join sys_user as u on u.user_id = r.applier
        left join sys_user as u1 on u1.user_id = r.dept_user_id
        left join sys_user as u2 on u2.user_id = r.manager_user_id
        left join sys_user as u3 on u3.user_id = r.zjl_user_id
        left join sys_dept as d on d.dept_id = r.apply_dept
        left join cmc_project as p on r.project_id = p.project_id
    </sql>

    <select id="selectCmcRecruitList" parameterType="CmcRecruit" resultMap="CmcRecruitResult">
        <include refid="selectCmcRecruitVo"/>
        <where>
            <if test="applier != null "> and r.applier = #{applier}</if>
            <if test="applyDept != null "> and r.apply_dept = #{applyDept}</if>
            <if test="projectId != null  and projectId != ''"> and r.project_id = #{projectId}</if>
            <if test="applyDate != null "> and r.apply_date = #{applyDate}</if>
            <if test="postName != null  and postName != ''"> and r.post_name like concat('%', r.#{postName}, r.'%')</if>
            <if test="postNumber != null "> and r.post_number = #{postNumber}</if>
            <if test="duty != null  and duty != ''"> and r.duty = #{duty}</if>
            <if test="qualification != null  and qualification != ''"> and r.qualification = #{qualification}</if>
            <if test="wage != null  and wage != ''"> and r.wage = #{wage}</if>
            <if test="deptComment != null  and deptComment != ''"> and r.dept_comment = #{deptComment}</if>
            <if test="deptUserId != null "> and r.dept_user_id = #{deptUserId}</if>
            <if test="deptTime != null "> and r.dept_time = #{deptTime}</if>
            <if test="managerComment != null  and managerComment != ''"> and r.manager_comment = #{managerComment}</if>
            <if test="managerUserId != null "> and r.manager_user_id = #{managerUserId}</if>
            <if test="managerTime != null "> and r.manager_time = #{managerTime}</if>
            <if test="zjlComment != null  and zjlComment != ''"> and r.zjl_comment = #{zjlComment}</if>
            <if test="zjlUserId != null "> and r.zjl_user_id = #{zjlUserId}</if>
            <if test="zjlTime != null "> and r.zjl_time = #{zjlTime}</if>
        </where>
    </select>

    <select id="selectCmcRecruitByRecruitId" parameterType="String" resultMap="CmcRecruitResult">
        <include refid="selectCmcRecruitVo"/>
        where recruit_id = #{recruitId}
    </select>

    <insert id="insertCmcRecruit" parameterType="CmcRecruit">
        insert into cmc_recruit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="recruitId != null">recruit_id,</if>
            <if test="applier != null">applier,</if>
            <if test="applyDept != null">apply_dept,</if>
            <if test="projectId != null">project_id,</if>
            <if test="applyDate != null">apply_date,</if>
            <if test="postName != null">post_name,</if>
            <if test="postNumber != null">post_number,</if>
            <if test="duty != null">duty,</if>
            <if test="qualification != null">qualification,</if>
            <if test="wage != null">wage,</if>
            <if test="deptComment != null">dept_comment,</if>
            <if test="deptUserId != null">dept_user_id,</if>
            <if test="deptTime != null">dept_time,</if>
            <if test="managerComment != null">manager_comment,</if>
            <if test="managerUserId != null">manager_user_id,</if>
            <if test="managerTime != null">manager_time,</if>
            <if test="zjlComment != null">zjl_comment,</if>
            <if test="zjlUserId != null">zjl_user_id,</if>
            <if test="zjlTime != null">zjl_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="recruitId != null">#{recruitId},</if>
            <if test="applier != null">#{applier},</if>
            <if test="applyDept != null">#{applyDept},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="applyDate != null">#{applyDate},</if>
            <if test="postName != null">#{postName},</if>
            <if test="postNumber != null">#{postNumber},</if>
            <if test="duty != null">#{duty},</if>
            <if test="qualification != null">#{qualification},</if>
            <if test="wage != null">#{wage},</if>
            <if test="deptComment != null">#{deptComment},</if>
            <if test="deptUserId != null">#{deptUserId},</if>
            <if test="deptTime != null">#{deptTime},</if>
            <if test="managerComment != null">#{managerComment},</if>
            <if test="managerUserId != null">#{managerUserId},</if>
            <if test="managerTime != null">#{managerTime},</if>
            <if test="zjlComment != null">#{zjlComment},</if>
            <if test="zjlUserId != null">#{zjlUserId},</if>
            <if test="zjlTime != null">#{zjlTime},</if>
        </trim>
    </insert>

    <update id="updateCmcRecruit" parameterType="CmcRecruit">
        update cmc_recruit
        <trim prefix="SET" suffixOverrides=",">
            <if test="applier != null">applier = #{applier},</if>
            <if test="applyDept != null">apply_dept = #{applyDept},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="applyDate != null">apply_date = #{applyDate},</if>
            <if test="postName != null">post_name = #{postName},</if>
            <if test="postNumber != null">post_number = #{postNumber},</if>
            <if test="duty != null">duty = #{duty},</if>
            <if test="qualification != null">qualification = #{qualification},</if>
            <if test="wage != null">wage = #{wage},</if>
            <if test="deptComment != null">dept_comment = #{deptComment},</if>
            <if test="deptUserId != null">dept_user_id = #{deptUserId},</if>
            <if test="deptTime != null">dept_time = #{deptTime},</if>
            <if test="managerComment != null">manager_comment = #{managerComment},</if>
            <if test="managerUserId != null">manager_user_id = #{managerUserId},</if>
            <if test="managerTime != null">manager_time = #{managerTime},</if>
            <if test="zjlComment != null">zjl_comment = #{zjlComment},</if>
            <if test="zjlUserId != null">zjl_user_id = #{zjlUserId},</if>
            <if test="zjlTime != null">zjl_time = #{zjlTime},</if>
        </trim>
        where recruit_id = #{recruitId}
    </update>

    <delete id="deleteCmcRecruitByRecruitId" parameterType="String">
        delete from cmc_recruit where recruit_id = #{recruitId}
    </delete>

    <delete id="deleteCmcRecruitByRecruitIds" parameterType="String">
        delete from cmc_recruit where recruit_id in
        <foreach item="recruitId" collection="array" open="(" separator="," close=")">
            #{recruitId}
        </foreach>
    </delete>
</mapper>