<?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.jeeplus.test.roster.mapper.RosterBaseMapper">
  <resultMap id="BaseResultMap" type="com.jeeplus.test.roster.service.dto.RosterBaseDTO">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy.id" />
    <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy.id" />
    <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="office_id" jdbcType="VARCHAR" property="officeId" />
    <result column="job_position_id" jdbcType="VARCHAR" property="jobPositionId" />
    <result column="position_id" jdbcType="VARCHAR" property="positionId" />
    <result column="rank_id" jdbcType="VARCHAR" property="rankId" />
    <result column="job_no" jdbcType="VARCHAR" property="jobNo" />
    <result column="certificates_type" jdbcType="VARCHAR" property="certificatesType" />
    <result column="id_card" jdbcType="VARCHAR" property="idCard" />
    <result column="certificates_front" jdbcType="VARCHAR" property="certificatesFront" />
    <result column="certificates_back" jdbcType="VARCHAR" property="certificatesBack" />
    <result column="mobile" jdbcType="VARCHAR" property="mobile" />
    <result column="contract_type" jdbcType="VARCHAR" property="contractType" />
    <result column="worker_type" jdbcType="VARCHAR" property="workerType" />
    <result column="onboarding_date" jdbcType="TIMESTAMP" property="onboardingDate" />
    <result column="seniority" jdbcType="VARCHAR" property="seniority" />
    <result column="contract_company" jdbcType="VARCHAR" property="contractCompany" />
    <result column="sex" jdbcType="VARCHAR" property="sex" />
    <result column="birth_date" jdbcType="TIMESTAMP" property="birthDate" />
    <result column="work_place" jdbcType="VARCHAR" property="workPlace" />
    <result column="contact_address" jdbcType="VARCHAR" property="contactAddress" />
    <result column="employment_situation" jdbcType="VARCHAR" property="employmentSituation" />
    <result column="working_hour" jdbcType="VARCHAR" property="workingHour" />
    <result column="ethnic" jdbcType="VARCHAR" property="ethnic" />
    <result column="account_type" jdbcType="VARCHAR" property="accountType" />
    <result column="account_addr" jdbcType="VARCHAR" property="accountAddr" />
    <result column="origin" jdbcType="VARCHAR" property="origin" />
    <result column="live_addr" jdbcType="VARCHAR" property="liveAddr" />
    <result column="highest_education" jdbcType="VARCHAR" property="highestEducation" />
    <result column="political_face" jdbcType="VARCHAR" property="politicalFace" />
    <result column="marital_status" jdbcType="VARCHAR" property="maritalStatus" />
    <result column="blood_type" jdbcType="VARCHAR" property="bloodType" />
    <result column="emergency_contact_name" jdbcType="VARCHAR" property="emergencyContactName" />
    <result column="emergency_contact_tel" jdbcType="VARCHAR" property="emergencyContactTel" />
    <result column="spouse_name" jdbcType="VARCHAR" property="spouseName" />
    <result column="child_name" jdbcType="VARCHAR" property="childName" />
    <result column="qq" jdbcType="VARCHAR" property="qq" />
    <result column="wechat" jdbcType="VARCHAR" property="wechat" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="headshot" jdbcType="VARCHAR" property="headshot" />
    <result column="office_name" jdbcType="VARCHAR" property="officeName" />
    <result column="person_type" jdbcType="VARCHAR" property="personType" />
    <association property="rosterContractDTO" javaType="com.jeeplus.test.roster.service.dto.RosterContractDTO" column="id" select="getContractDTO"></association>
    <association property="rosterLeadershipDTO" javaType="com.jeeplus.test.roster.service.dto.RosterLeadershipDTO" column="id" select="getLeadershipDTO"></association>
    <collection property="rosterBankCardsDTOList" ofType="com.jeeplus.test.roster.service.dto.RosterBankCardsDTO" column="id" select="getBankCardsList"></collection>
    <collection property="rosterEducateDTOList" ofType="com.jeeplus.test.roster.service.dto.RosterEducateDTO" column="id" select="getEducateList"></collection>
    <collection property="rosterWorkDTOList" ofType="com.jeeplus.test.roster.service.dto.RosterWorkDTO" column="id" select="getWorkList"></collection>
    <collection property="rosterFamilyDTOList" ofType="com.jeeplus.test.roster.service.dto.RosterFamilyDTO" column="id" select="getFamilyList"></collection>
    <collection property="rosterCertificateDTOList" ofType="com.jeeplus.test.roster.service.dto.RosterCertificateDTO" column="id" select="getCertificateList"></collection>
    <collection property="rosterFilesDTOList" ofType="com.jeeplus.test.roster.service.dto.RosterFilesDTO" column="id" select="getFilesList"></collection>
    <collection property="postList" ofType="com.jeeplus.sys.domain.Post" column="id" select="getPostList"></collection>
    <collection property="roleList" ofType="com.jeeplus.sys.domain.Role" column="id" select="getRoleList"></collection>
  </resultMap>

  <sql id="Base_Column_List">
    rb.id,
    rb.create_by,
    rb.create_date,
    rb.update_by,
    rb.update_date,
    rb.remarks,
    rb.del_flag,
    rb.`name`,
    rb.office_id,
    rb.job_position_id,
    rb.position_id,
    rb.rank_id,
    rb.job_no,
    rb.certificates_type,
    rb.id_card,
    rb.certificates_front,
    rb.certificates_back,
    rb.mobile,
    rb.contract_type,
    rb.worker_type,
    rb.onboarding_date,
    rb.seniority,
    rb.contract_company,
    rb.sex,
    rb.birth_date,
    rb.work_place,
    rb.contact_address,
    rb.employment_situation,
    rb.working_hour,
    rb.ethnic,
    rb.account_type,
    rb.account_addr,
    rb.origin,
    rb.live_addr,
    rb.highest_education,
    rb.political_face,
    rb.marital_status,
    rb.blood_type,
    rb.emergency_contact_name,
    rb.emergency_contact_tel,
    rb.spouse_name,
    rb.child_name,
    rb.qq,
    rb.wechat,
    rb.email,
    rb.headshot,
    rb.person_type
  </sql>
  <sql id="Contract_Column_List">
    rc.id,
    rc.create_by,
    rc.create_date,
    rc.update_by,
    rc.update_date,
    rc.remarks,
    rc.base_id,
    rc.begin_date,
    rc.end_date,
    rc.work_email,
    rc.work_mobile,
    rc.probation_period_end_date,
    rc.probation_period_month,
    rc.del_flag
  </sql>
  <sql id="Leadership_Column_List">
        rl.id,
        rl.create_by,
        rl.create_date,
        rl.update_by,
        rl.update_date,
        rl.remarks,
        rl.del_flag,
        rl.base_id,
        rl.debrief_type,
        rl.supervisor_id
    </sql>
  <sql id="BankCards_Column_List">
    rbc.id,
        rbc.create_by,
        rbc.create_date,
        rbc.update_by,
        rbc.update_date,
        rbc.remarks,
        rbc.del_flag,
        rbc.base_id,
        rbc.payroll_card_open_bank,
        rbc.payroll_card_branches,
        rbc.payroll_card_bank_account,
        rbc.payroll_card_opening_name,
        rbc.payroll_card_pic,
        rbc.is_default
  </sql>
  <sql id="Educate_Column_List">
    re.id,
    re.create_by,
    re.create_date,
    re.update_by,
    re.update_date,
    re.remarks,
    re.del_flag,
    re.base_id,
    re.college_name,
    re.profession,
    re.entry_date,
    re.graduation_date,
    re.have_degree,
    re.education_cert_first,
    re.education_cert_second,
    re.degree
  </sql>
  <sql id="Certificate_Column_List">
    rce.id,
    rce.create_by,
    rce.create_date,
    rce.update_by,
    rce.update_date,
    rce.remarks,
    rce.del_flag,
    rce.base_id,
    rce.cert_name,
    rce.cert_type,
    rce.cert_no,
    rce.issued_institution,
    rce.issued_date,
    rce.record_date,
    rce.remind_date,
    rce.expire_date,
    rce.profession,
    rce.`level`,
    rce.description
  </sql>
  <sql id="Family_Column_List">
    rfa.id,
    rfa.create_by,
    rfa.create_date,
    rfa.update_by,
    rfa.update_date,
    rfa.remarks,
    rfa.del_flag,
    rfa.base_id,
    rfa.`name`,
    rfa.relationship,
    rfa.birth_date,
    rfa.birth_certificate
  </sql>
  <sql id="Files_Column_List">
    rf.id,
    rf.create_by,
    rf.create_date,
    rf.update_by,
    rf.update_date,
    rf.remarks,
    rf.del_flag,
    rf.base_id,
    rf.url,
    rf.name
  </sql>
  <sql id="Work_Column_List">
    rw.id,
    rw.create_by,
    rw.create_date,
    rw.update_by,
    rw.update_date,
    rw.remarks,
    rw.del_flag,
    rw.base_id,
    rw.company_name,
    rw.posts,
    rw.entry_date,
    rw.separation_date,
    rw.post_description
  </sql>

  <select id="getPostList" resultType="com.jeeplus.sys.domain.Post">
      select
          distinct sp.id,
          sp.name
      from sys_user su
      left join sys_user_post sup on su.id = sup.user_id
      left join sys_post sp on sp.id = sup.post_id and sp.del_flag = '0'
      where su.roster_id = #{id} and su.del_flag = '0'
  </select>
  <select id="getRoleList" resultType="com.jeeplus.sys.domain.Role">
        select
            distinct sr.id,
            sr.name
        from sys_user su
        left join sys_user_role sur on su.id = sur.user_id
        left join sys_role sr on sr.id = sur.role_id and sr.del_flag = '0'
        where su.roster_id = #{id} and su.del_flag = '0'
  </select>
  <select id="getContractDTO" resultType="com.jeeplus.test.roster.service.dto.RosterContractDTO">
    select
    <include refid="Contract_Column_List"></include>
    from roster_contract rc
    where rc.del_flag = '0' and rc.base_id = #{id}
  </select>
  <select id="getLeadershipDTO" resultType="com.jeeplus.test.roster.service.dto.RosterLeadershipDTO">
    select
    <include refid="Leadership_Column_List"></include>
    from roster_leadership rl
    where rl.del_flag = '0' and rl.base_id = #{id}
  </select>
  <select id="getBankCardsList" resultType="com.jeeplus.test.roster.service.dto.RosterBankCardsDTO">
    select
    <include refid="BankCards_Column_List"></include>
    from roster_bank_cards rbc
    where rbc.del_flag = '0' and rbc.base_id = #{id}
  </select>
  <select id="getEducateList" resultType="com.jeeplus.test.roster.service.dto.RosterEducateDTO">
    select
    <include refid="Educate_Column_List"></include>
    from roster_educate re
    where re.del_flag = '0' and re.base_id = #{id}
  </select>
  <select id="getWorkList" resultType="com.jeeplus.test.roster.service.dto.RosterWorkDTO">
    select
    <include refid="Work_Column_List"></include>
    from roster_work rw
    where rw.del_flag = '0' and rw.base_id = #{id}
  </select>
  <select id="getFamilyList" resultType="com.jeeplus.test.roster.service.dto.RosterFamilyDTO">
    select
    <include refid="Family_Column_List"></include>
    from roster_family rfa
    where rfa.del_flag = '0' and rfa.base_id = #{id}
  </select>
  <select id="getCertificateList" resultType="com.jeeplus.test.roster.service.dto.RosterCertificateDTO">
    select
    <include refid="Certificate_Column_List"></include>
    from roster_certificate rce
    where rce.del_flag = '0' and rce.base_id = #{id}
  </select>
  <select id="getFilesList" resultMap="FilesMap">
    select
    <include refid="Files_Column_List"></include>,
    su.name su_name
    from roster_files rf
    left join sys_user su on rf.create_by = su.id and su.del_flag = '0'
    where rf.del_flag = '0' and rf.base_id = #{id}
    order by rf.create_date desc
  </select>

  <resultMap id="FilesMap" type="com.jeeplus.test.roster.service.dto.RosterFilesDTO">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy.id" />
    <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy.id" />
    <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
    <result column="base_id" jdbcType="VARCHAR" property="baseId" />
    <result column="url" jdbcType="VARCHAR" property="url" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="su_name" jdbcType="VARCHAR" property="createBy.name" />
  </resultMap>

  <select id="findList" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"></include>,
    so.name office_name
    from roster_base rb
    left join sys_office so on rb.office_id = so.id and so.del_flag = '0'
    LEFT JOIN sys_user su ON su.roster_id = rb.id and su.del_flag = 0
    LEFT JOIN sys_office soc ON soc.id = su.company_id
    LEFT JOIN sys_office soo ON soo.id = su.office_id
    ${ew.customSqlSegment}
    order by rb.create_date desc
  </select>

  <select id="queryById" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"></include>
    from roster_base rb
    where rb.id = #{id}
  </select>

  <delete id="deleteByIdPhysical">
    delete from roster_base where id = #{id}
  </delete>

</mapper>