<?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.unis.base.server.dao.PersonSystemDao">
    <insert id="insertone">
        insert into base:d_system (file_name, file_code, uploadpath, status, uploadtime, creator, fid, org_code,dept_id)
        values (#{fileName}, #{fileCode}, #{uploadpath}, #{status}, #{uploadtime}, #{creator}, #{fid}, #{orgCode},#{deptId})
    </insert>
    <insert id="insertBath">
        <foreach collection="list" item="obj" separator=";">
            INSERT INTO base.d_sysperson
            (train_person_dept_code,train_person_dept_name,train_person_id,train_person_name,file_code,main_fid)
            VALUES
            (
            #{obj.trainPersonDeptCode},
            #{obj.trainPersonDeptName},
            #{obj.trainPersonId},
            #{obj.trainPersonName},
            #{obj.fileCode},
            #{obj.mainFid}
            )
        </foreach>
    </insert>
    <insert id="insertDept">
        insert into base.d_deptarr (fid, dept_arr, id)
        values (#{fid}, #{s}, #{id})
    </insert>
    <insert id="insertPerson">
        insert into base.d_sysperson (train_person_dept_code, train_person_dept_name, train_person_id,train_person_name,file_code,main_fid)
        values (#{trainPersonDeptCode}, #{trainPersonDeptName}, #{trainPersonId},#{trainPersonName},#{fileCode},#{mainFid})
    </insert>

    <update id="updateOne">
        update base.d_system
        set file_code = #{fileCode}, file_name = #{fileName},uploadpath = #{uploadpath},uploadtime = #{uploadtime} ,creator = #{creator} where id=#{id}
    </update>
    <update id="updateN">
        update base.d_system
        set status = 1 where file_code=#{fileCode}

    </update>
    <update id="updateY">
        update base.d_system
        set status = 2 where file_code=#{fileCode}
    </update>
    <update id="updatePerson">
        update base.d_sysperson
        set train_person_dept_code = #{trainPersonDeptCode},
            train_person_dept_name = #{trainPersonDeptName},
            train_person_id = #{trainPersonId},
            train_person_name = #{trainPersonName},
            file_code = #{fileCode} where train_person_id=#{trainPersonId}
    </update>
    <update id="uplatedept">
        update base.d_deptarr
        set dept_arr=#{s}
        where fid=#{fid}
    </update>

    <delete id="deleteOne">
        delete
        from base.d_system
        where id=#{id} and status ='1'
    </delete>
    <delete id="deleteAll">
        delete
        from base.d_deptarr
        where fid=#{fid}
    </delete>
    <delete id="delAllP">
        delete
        from base.d_sysperson
        where main_fid=#{fid}
    </delete>
    <!-- <select id="selectSystem" resultType="com.unis.base.server.entity.PersonSystemDO">
         select *
         from base.d_system
         <where>
             <if test="file_name!=null and file_name!=''">
                 and file_name like '%'||#{fileName}||'%'
             </if>
             <if test="orgCode!=null and orgCode!=''">
                 and org_code =#{orgCode}
             </if>
         </where>
         order by uploadtime desc
     </select>-->
    <select id="SelectOne" resultType="com.unis.base.common.vo.PersonSystemVO">
        select *
        from base.d_system
        where id =#{id}
    </select>
    <select id="selectOm" resultType="com.unis.base.common.vo.PersonVO">
        select *
        from base.d_sysperson
        where main_fid=#{fid}
    </select>
    <select id="selectDept" resultType="java.lang.String">
        select dept_arr
        from base.d_deptarr
        where fid=#{fid}
    </select>
    <select id="selecDearr" resultType="com.unis.base.common.vo.DeptArrVO">
        select *
        from base.d_deptarr
        where fid=#{fid}
    </select>
    <select id="seleectName" resultType="java.lang.String">
        select id
        from base.d_system
        where file_name=#{fileName}
    </select>
    <select id="selectSystem" resultType="com.unis.base.server.entity.PersonSystemDO">
        select *
        from base.d_system
        <where>
            <if test="fileName!=null and fileName!=''">
                and file_name like '%'||#{fileName}||'%'
            </if>
            <if test="status!=null and status!=''">
                and status =#{status}
            </if>
            <if test="fid!=null and fid.size()>0">
                and ((fid in
                <foreach collection="fid" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
                 and status = 2) or creator =#{userName} or fid in (select fid from base.d_deptarr where dept_arr = #{orgCode}))
            </if>
            <if test="fid==null or fid.size()==0">
                and (creator =#{userName} or fid in (select fid from base.d_deptarr where dept_arr = #{orgCode}))
            </if>
        </where>
        order by id desc
    </select>
    <select id="selectSystem1" resultType="com.unis.base.server.entity.PersonSystemDO">
        select *
        from base.d_system
        <where>
        <if test="fileName!=null and fileName!=''">
            and file_name like '%'||#{fileName}||'%'
        </if>
            <if test="status!=null and status!=''">
                and status =#{status}
            </if>
        </where>
        order by id desc
    </select>
    <select id="selectSs" resultType="java.lang.String">
        select main_fid from base.d_sysperson where train_person_id=#{userId}
    </select>


</mapper>
