<?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.docus.server.archive.mapper.PowerDeptMapper">
    <insert id="insertBatch">

        INSERT INTO docus_system.power_dept (dept_id, dept_code, dept_name, dict_id,
                                             effective, create_date, creater, update_date,
                                             updater, remark, sort, `type`)
        VALUES
               <foreach collection="deptList" item="dept" separator=",">
                   (#{dept.deptId},#{dept.deptCode},#{dept.deptName},#{dept.dictId},
                    #{dept.effective},#{dept.createDate},#{dept.creater},#{dept.updateDate},
                    #{dept.updater},#{dept.remark},#{dept.sort},#{dept.type})
               </foreach>
    </insert>
    <update id="updateBatch">

        <foreach collection="deptList" item="dept" >
            UPDATE docus_system.power_dept
            SET dept_code=#{dept.deptCode}, dept_name=#{dept.deptName}, dict_id=#{dept.dictId},
                                               effective=#{dept.effective}, create_date=#{dept.createDate}, creater=#{dept.creater},
                                               update_date=#{dept.updateDate}, updater=#{dept.updater}, remark=#{dept.remark},
                                               sort=#{dept.sort}, `type`=#{dept.type} WHERE dept_id=#{dept.deptId};
        </foreach>

    </update>

    <select id="list" resultType="com.docus.server.archive.entity.PowerDept">
       SELECT
              dept_code as deptCode,
              dept_Name as deptName
       FROM `docus_system`.`power_dept`
    </select>
    <select id="findByDeptCodes" resultType="com.docus.server.archive.entity.PowerDept">
        select dept_id, dept_code, dept_name, dict_id,
               effective, create_date, creater, update_date,
               updater, remark, sort, `type`
        from `docus_system`.`power_dept`
        where dept_code in <foreach collection="deptCodes" item="deptCode" separator="," open="(" close=")">
                                #{deptCode}
                            </foreach>
    </select>
</mapper>
