<?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.zcloud.mapper.dsno1.system.OfficeMapper">

    <!--表名 -->
    <sql id="tableName">
        BUS_OFFICE
    </sql>

    <!--数据字典表名 -->
    <sql id="dicTableName">
        SYS_DICTIONARIES
    </sql>

    <!-- 字段 -->
    <sql id="Field">
        f.WORK_ID,
        f.WORK_NAME,
        f.THUMBNAIL,
        f.REMARK,
        f.STATUS,
        f.ISDELETE,
        f.OPERATOR,
        f.OPERATTIME,
        f.CREATTIME,
        f.CREATOR,
        f.CORPINFO_ID
    </sql>

    <!-- 字段用于新增 -->
    <sql id="Field2">
        WORK_ID,
        WORK_NAME,
        THUMBNAIL,
        REMARK,
        STATUS,
        ISDELETE,
        OPERATOR,
        OPERATTIME,
        CREATTIME,
        CREATOR,
        CORPINFO_ID
    </sql>

    <!-- 字段值 -->
    <sql id="FieldValue">
        #{WORK_ID},
        #{WORK_NAME},
        #{THUMBNAIL},
        #{REMARK},
        #{STATUS},
        #{ISDELETE},
        #{OPERATOR},
        #{OPERATTIME},
        #{CREATTIME},
        #{CREATOR},
        #{CORPINFO_ID}
    </sql>
    <sql id="FieldValue2">
        #{item.WORK_ID},
        #{item.WORK_NAME},
        #{item.THUMBNAIL},
        #{item.REMARK},
        #{item.STATUS},
        #{item.ISDELETE},
        #{item.OPERATOR},
        #{item.OPERATTIME},
        #{item.CREATTIME},
        #{item.CREATOR},
        #{item.CORPINFO_ID}
    </sql>

    <!-- 新增-->
    <insert id="save" parameterType="pd">
        insert into
        <include refid="tableName"></include>
        (
        <include refid="Field2"></include>
        ) values (
        <include refid="FieldValue"></include>
        )
    </insert>
    <insert id="saveBatch">
        insert into <include refid="tableName"></include>
		(<include refid="Field2"></include>) values
		<foreach item="item" index="index" collection="list" separator="," >
			(<include refid="FieldValue2"></include>)
		</foreach>
    </insert>

    <!-- 删除-->
    <delete id="delete" parameterType="pd">
        update
        <include refid="tableName"></include>
        set
        ISDELETE = '1',
        OPERATOR = #{OPERATOR},
        OPERATTIME = #{OPERATTIME}
        where
        WORK_ID = #{WORK_ID} and CORPINFO_ID = #{CORPINFO_ID}
    </delete>

    <!-- 修改 -->
    <update id="edit" parameterType="pd">
        update
        <include refid="tableName"></include>
            set
        CORPINFO_ID = #{CORPINFO_ID}
        <if test="WORK_ID != null and WORK_ID != ''">
            ,WORK_ID = #{WORK_ID}
        </if>
        where
        WORK_NAME = #{WORK_NAME} and CORPINFO_ID = #{CORPINFO_ID}
    </update>

    <!-- 通过ID获取数据 -->
    <select id="findById" parameterType="pd" resultType="pd">
        select
        <include refid="Field"></include>
        from
        <include refid="tableName"></include> f
        where
        f.WORK_ID = #{WORK_ID} and CORPINFO_ID = #{CORPINFO_ID}
    </select>

    <!-- 列表 -->
    <select id="datalistPage" parameterType="page" resultType="pd">
        select
        <include refid="Field"></include>
        from
        <include refid="tableName"></include> f
        where f.ISDELETE = '0' and f.CORPINFO_ID = #{pd.CORPINFO_ID}
        <if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
        </if>
        ORDER BY f.OPERATTIME DESC
    </select>

    <!-- 列表(全部) -->
    <select id="listAll" parameterType="pd" resultType="pd">
        select
       *
        from
        <include refid="tableName"></include> f
        where
        f.ISDELETE = '0'
        and f.CORPINFO_ID = #{CORPINFO_ID}
    </select>

    <!-- 批量删除 -->
    <delete id="deleteAll" parameterType="pd">
        update
        <include refid="tableName"></include>
        set
        ISDELETE = '1'
        where
        WORK_ID in
        <foreach item="item" index="index" collection="DATA_IDS" open="(" separator="," close=")">
            #{item}
        </foreach> and CORPINFO_ID = #{CORPINFO_ID}
    </delete>
</mapper>
