<?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.nantian.cloud.jljc.mapper.RecordPersonManagerMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jljc.entity.RecordPersonManager">
        <id column="id" property="id"/>
        <result column="epc" property="epc"/>
        <result column="name" property="name"/>
        <result column="phone" property="phone"/>
        <result column="duties" property="duties"/>
        <result column="card_type" property="cardType"/>
        <result column="card_code" property="cardCode"/>
        <result column="work_experience" property="workExperience"/>
        <result column="year" property="year"/>
        <result column="profile" property="profile"/>
        <result column="auditor_id" property="auditorId"/>
        <result column="auditor" property="auditor"/>
        <result column="audit_status" property="auditStatus"/>
        <result column="audit_remark" property="auditRemark"/>
        <result column="audit_date" property="auditDate"/>
        <result column="remark" property="remark"/>
        <result column="update_id" property="updateId"/>
        <result column="update_date" property="updateDate"/>
        <result column="delete_flag" property="deleteFlag"/>
        <result column="dept_id" property="deptId"/>
    </resultMap>

    <resultMap id="BaseResultMapVo" type="com.nantian.cloud.jljc.vo.RecordPersonManagerVo">
        <id column="id" property="id"/>
        <result column="epc" property="epc"/>
        <result column="name" property="name"/>
        <result column="phone" property="phone"/>
        <result column="duties" property="duties"/>
        <result column="card_type" property="cardType"/>
        <result column="card_code" property="cardCode"/>
        <result column="work_experience" property="workExperience"/>
        <result column="year" property="year"/>
        <result column="profile" property="profile"/>
        <result column="auditor_id" property="auditorId"/>
        <result column="auditor" property="auditor"/>
        <result column="audit_status" property="auditStatus"/>
        <result column="audit_remark" property="auditRemark"/>
        <result column="audit_date" property="auditDate"/>
        <result column="remark" property="remark"/>
        <result column="update_id" property="updateId"/>
        <result column="update_date" property="updateDate"/>
        <result column="delete_flag" property="deleteFlag"/>
        <result column="epcName" property="epcName"/>
        <result column="parea" property="parea"/>
        <result column="area" property="area"/>
        <result column="ptrade" property="ptrade"/>
        <result column="trade" property="trade"/>
        <result column="dept_id" property="deptId"/>
    </resultMap>

    <resultMap id="RecordPersonManagerPOJO" type="com.nantian.cloud.jljc.vo.RecordPersonManagerPOJO">
        <result column="epc" property="epc"/>
        <result column="cmpName" property="cmpName"/>
        <result column="name" property="name"/>
        <result column="phone" property="phone"/>
        <result column="duties" property="duties"/>
        <result column="card_type" property="cardType"/>
        <result column="card_code" property="cardCode"/>
        <result column="work_experience" property="workExperience"/>
        <result column="profile" property="profile"/>
        <result column="year" property="year"/>
        <result column="updateDate" property="updateDate"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, epc, name, phone, duties, card_type, card_code, work_experience, year, profile, auditor_id, auditor, audit_status,
        audit_remark, audit_date, remark, update_id, update_date, delete_flag, dept_id
    </sql>

    <update id="updateByAudit">
        update record_person_manager
        <set>
            <if test="auditorId != null">
                auditor_id = #{auditorId},
            </if>
            <if test="auditor != null">
                auditor = #{auditor},
            </if>
            <if test="auditStatus != null">
                audit_status = #{auditStatus},
            </if>
            <if test="auditDate != null">
                audit_date = #{auditDate},
            </if>
            <if test="auditRemark != null">
                audit_remark = #{auditRemark},
            </if>
        </set>
        where id = #{id}
    </update>

    <delete id="removeByPersonId">
        update record_person_manager
        <set>
            <if test="updateId != null">
                update_id = #{updateId},
            </if>
            <if test="updateDate != null">
                update_date = #{updateDate},
            </if>
            <if test="deleteFlag != null">
                delete_flag = #{deleteFlag},
            </if>
        </set>
        where id = #{id}
    </delete>

    <select id="getCompInfoByCodeAndYear" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>
        from record_person_manager
        where epc = #{epc}
        and delete_flag = "1"
        <if test="year!=null and year != ''">
            and year = #{year}
        </if>
    </select>

    <select id="getGovInfoByCodeAndYear" resultMap="BaseResultMapVo">
        select p.id, p.epc, p.name, p.phone,p.dept_id, p.duties, p.card_type, p.card_code, p.work_experience, p.year, p.profile,
        p.auditor_id,
        p.auditor, p.audit_status, p.audit_remark, p.audit_date, p.remark, p.update_id, p.update_date, p.delete_flag,
        e.cmp_name as epcName, dr.meaning as parea, dr2.meaning as area, tk.name as ptrade, tk2.name as trade
        from record_person_manager p
        inner join enterprise_info e on e.enterprise_code = p.epc and p.delete_flag = "1"
        inner join dict_region dr on e.region_code = dr.id
        inner join dict_region dr2 on e.region_code = dr2.id
        inner join trade_kind tk on e.industry_code = tk.code
        inner join trade_kind tk2 on e.industry_code = tk2.code
        <if test="epcStr!=null and epcStr != ''">
            and e.cmp_name like concat("%",#{epcStr},"%")
        </if>
        <if test="year!=null and year != ''">
            and p.year = #{year}
        </if>
        <if test="trade!=null and trade != ''">
            and tk2.code like concat("%",#{trade},"%")
        </if>
        <if test="parea != null and parea != ''">
            and dr.id = #{parea}
        </if>
        <if test="area != null and area != ''">
            and dr2.id = #{area}
        </if>
        <if test="name != null and name != ''">
            and p.name = #{name}
        </if>
    </select>

    <select id="getPersonById" resultType="com.nantian.cloud.jljc.entity.RecordPersonManager">
        select
        <include refid="Base_Column_List"></include>
        from record_person_manager
        where id = #{id}
    </select>

    <select id="excelExport" resultType="com.nantian.cloud.jljc.vo.RecordPersonManagerPOJO">
        select p.id, p.epc, p.name, p.phone, p.duties, p.card_type, p.card_code, p.work_experience, p.year, p.profile,
        p.auditor_id,
        p.auditor, p.audit_status, p.audit_remark, p.audit_date, p.remark, p.update_id, p.update_date, p.delete_flag,
        e.cmp_name as epcName, dr.meaning as parea, dr2.meaning as area, tk.name as ptrade, tk2.name as trade
        from record_person_manager p
        inner join enterprise_info e on e.enterprise_code = p.epc and p.delete_flag = "1"
        inner join dict_region dr on e.region_code = dr.id
        inner join dict_region dr2 on e.region_code = dr2.id
        inner join trade_kind tk on e.industry_code = tk.code
        inner join trade_kind tk2 on e.industry_code = tk2.code
        <if test="epcStr!=null and epcStr != ''">
            and e.cmp_name like concat("%",#{epcStr},"%")
        </if>
        <if test="year!=null and year!= ''">
            and p.year = #{year}
        </if>
        <if test="epc!=null and epc != ''">
            and p.epc = #{epc}
        </if>
        <if test="trade!=null and trade != ''">
            and tk2.code like concat("%",#{trade},"%")
        </if>
        <if test="parea != null and parea != ''">
            and dr.id = #{parea}
        </if>
        <if test="area != null and area != ''">
            and dr2.id = #{area}
        </if>
    </select>

</mapper>
