<?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="cn.com.countrygarden.bi.main.dao.dup.MediaResoureceMapper">
	 <!-- 合同录入统计管理映射 -->
	  <resultMap id="MediaResourcesMap" type="cn.com.countrygarden.bi.main.model.dup.MediaResources">
	  	<result column="id" property="id"/>
	  	<result column="organ_name" property="organName"/>
		<result column="comm_name" property="commName"/>
		<result column="media_type" property="mediaType"/>
		<result column="location" property="location"/>
		<result column="specification" property="specification"/>
		<result column="whether_rent" property="whetherRet"/>
		<result column="internal_use_number" property="internalUseNumber"/>
		<result column="idle_number" property="idleNumber"/>
		<result column="total" property="total"/>
		<result column="create_date" property="createDate"/>
		<result column="organ_code" property="organCode"/>
		<result column="comm_id" property="commId"/>
	  </resultMap>
	  
	  <!-- 模糊搜索媒体资源 -->
 	<select id="findMediaResourcesAlllike" parameterType="cn.com.countrygarden.bi.main.model.dup.MediaResources" resultMap="MediaResourcesMap">
 		SELECT
			id,
			organ_name,
			organ_code,
			comm_id,
			comm_name,
			media_type,
			location,
			specification,
			whether_rent,
			internal_use_number,
			idle_number,
			total,
			create_date
		FROM
			tb_media_resources as tmr
		<where>
			<if test="organName!=null and organName!=''">AND tmr.organ_name LIKE CONCAT('%',#{organName},'%')</if>
			<if test="commName!=null and commName!=''">AND tmr.comm_name LIKE CONCAT('%',#{commName},'%')</if>
			<if test="organCode!=null and organCode!=''">AND tmr.organ_code =#{organCode}</if>
			<if test="commId!=null and commId!=''">AND tmr.comm_id =#{commId}</if>
			<if test="mediaType!=null and mediaType!=''">AND tmr.media_type=#{mediaType}</if>
			<if test="location!=null and location!=''">AND tmr.location LIKE CONCAT('%',#{location},'%')</if>
			<if test="specification!=null and specification!=''">AND tmr.specification LIKE CONCAT('%',#{specification},'%')</if>
			<!-- <if test="whetherRet!=null">AND tmr.whether_rent=#{whetherRet}</if> -->
			<!-- <if test="internalUseNumber!=null">AND tmr.internal_use_number=#{internalUseNumber}</if>
			<if test="idleNumber!=null">AND tmr.idle_number=#{idleNumber}</if>
			<if test="total!=null">AND tmr.total=#{total}</if> -->
		</where>
		order by create_date desc
 	</select>
  
  	<!-- 新增媒体资源 -->
  	<insert id="addMediaResources" parameterType="cn.com.countrygarden.bi.main.model.dup.MediaResources">
  		INSERT INTO tb_media_resources (
  			`id`,
			`organ_name`,
			`organ_code`,
			`comm_id`,
			`comm_name`,
			`media_type`,
			`location`,
			`specification`,
			`whether_rent`,
			`internal_use_number`,
			`idle_number`,
			`total`,
			`create_date`
		)
		VALUES
			(
				#{id},
				#{organName},
				#{organCode},
				#{commId},
				#{commName},
				#{mediaType},
				#{location},
				#{specification},
				#{whetherRet},
				#{internalUseNumber},
				#{idleNumber},
				#{total},
				#{createDate}
			)
  	</insert>
  	
  	<!--修改媒体资源  -->
  	<update id="updateMediaResources"  parameterType="cn.com.countrygarden.bi.main.model.dup.MediaResources">

  		UPDATE tb_media_resources
	<set>
			<if test="organCode!=null and organCode!=''"> `organ_code`=#{organCode},</if>
			<if test="commId!=null and commId!=0"> `comm_id`=#{commId},</if>
		 	<if test="organName!=null and organName!=''"> `organ_name`=#{organName},</if>
			<if test="commName!=null and commName!=''"> `comm_name`=#{commName},</if>
			<if test="mediaType!=null and mediaType!=''"> `media_type`= #{mediaType},</if>
			<if test="location!=null and location!=''"> `location` =#{location},</if>
			<if test="specification!=null and specification!=''"> `specification` =#{specification}, </if>
			<if test="whetherRet!=null"> `whether_rent`= #{whetherRet},</if>
			<if test="internalUseNumber!=null">`internal_use_number`=#{internalUseNumber},</if>
			<if test="idleNumber!=null">`idle_number`=#{idleNumber},</if>
			<if test="total!=null">`total`=#{total},</if>
			<if test="createDate!=null">`create_date`=#{createDate}</if>
		</set>
		WHERE
			(`id` = #{id});
			
  	</update>
  	
 	<delete id="deleteMediaResources" parameterType="cn.com.countrygarden.bi.main.model.dup.MediaResources">
	  DELETE
		FROM
			tb_media_resources
		WHERE
			tb_media_resources.id=#{id}
  	</delete>
  
</mapper>