<?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.pcloud.book.skill.dao.impl.PcloudResourceDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.skill.entity.PcloudResource" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="description" property="description" jdbcType="VARCHAR" />
    <result column="pro_label_id" property="proLabelId" jdbcType="BIGINT" />
    <result column="dep_label_id" property="depLabelId" jdbcType="BIGINT" />
    <result column="pur_label_id" property="purLabelId" jdbcType="BIGINT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="is_delete" property="isDelete" jdbcType="BIT" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, name, description, pro_label_id, dep_label_id, pur_label_id,
    create_time, update_time, is_delete
  </sql>

  <select id="getPcloudResourceList" resultType="com.pcloud.book.skill.facade.response.QueryPcloudResponseVO" parameterType="map" >
    SELECT
      id,
      NAME,
      description,
      pro_label_id proLabelId,
      dep_label_id depLabelId,
      pur_label_id purLabelId
    FROM
        `pcloud_resource`
    WHERE is_delete = 0
    <if test="name != null">
      AND name like CONCAT('%',#{name},'%')
    </if>
    <if test="proLabelId != null">
      AND pro_label_id = #{proLabelId}
    </if>
    <if test="depLabelId != null">
      AND dep_label_id = #{depLabelId}
    </if>
    <if test="purLabelId != null">
      AND pur_label_id = #{purLabelId}
    </if>
    ORDER BY id DESC
  </select>

  <select id="getPcloudResource" resultType="com.pcloud.book.skill.facade.response.QueryPcloudResponseVO"  parameterType="long">
    SELECT
      id,
      NAME,
      description,
      pro_label_id proLabelId,
      dep_label_id depLabelId,
      pur_label_id purLabelId
    FROM pcloud_resource
    WHERE id=#{id} AND is_delete = 0
  </select>

  <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from pcloud_resource
    where id = #{id,jdbcType=INTEGER}
  </select>
  <insert id="insert" parameterType="com.pcloud.book.skill.entity.PcloudResource" keyProperty="id" useGeneratedKeys="true">
    insert into pcloud_resource (name, description, pro_label_id, dep_label_id, pur_label_id,
     create_time, update_time, is_delete)
    values (#{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{proLabelId,jdbcType=INTEGER}, #{depLabelId,jdbcType=INTEGER}, #{purLabelId,jdbcType=INTEGER},
      NOW(), NOW(), 0)
  </insert>
  <update id="update" parameterType="com.pcloud.book.skill.entity.PcloudResource" >
    update pcloud_resource
    <set >
      <if test="name != null" >
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="description != null" >
        description = #{description,jdbcType=VARCHAR},
      </if>
      <if test="proLabelId != null" >
        pro_label_id = #{proLabelId,jdbcType=INTEGER},
      </if>
      <if test="depLabelId != null" >
        dep_label_id = #{depLabelId,jdbcType=INTEGER},
      </if>
      <if test="purLabelId != null" >
        pur_label_id = #{purLabelId,jdbcType=INTEGER},
      </if>
      <if test="isDelete != null" >
        is_delete = #{isDelete,jdbcType=BIT},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>

  <update id="deletePcloudResource" parameterType="long">
    update pcloud_resource
    set is_delete = 1
    where id = #{id,jdbcType=BIGINT}
  </update>

  <select id="mayByIds" parameterType="long" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"/>
    from pcloud_resource
    where id in
    <foreach collection="list" index="i" item="item" open="(" separator="," close=")">
      ${item}
    </foreach>
  </select>
</mapper>