banner-mapper.xml 2.43 KB
<?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.cjs.cms.dao.site.BannerDao">
	<sql id="banner_field">
		Id, title, image, url, target, sort, start_at, end_at, create_by, create_at, update_by, update_at, type, banner_location
	</sql>
	
	<sql id="getBannerCondition">
		where 1 = 1
		<if test="title != null and title != ''">
			and title like CONCAT('%',#{title},'%')
		</if>
		<if test="beginDate != null and endDate == null">
			and create_at> = #{beginDate}
		</if>
		<if test="endDate != null and beginDate == null">
			and DATE_ADD(#{endDate} , INTERVAL +1 day)> = create_at
		</if>
		<if test="endDate != null and beginDate != null">
			and create_at between #{beginDate} and
			DATE_ADD(#{endDate}, INTERVAL +1 day)
		</if>
		<if test="type != null and type != ''"> 
		    and type = #{type}
		</if>
		<if test="bannerLocation != null and bannerLocation != ''"> 
		    and banner_location = #{bannerLocation}
		</if>
	</sql>
	
	<insert id="addBanner" parameterType="java.util.Map">
		insert into
		banner(title, image, url, target, sort, start_at, end_at, create_by, create_at, update_by, update_at, type, banner_location)
		values(#{title}, #{image}, #{url}, #{target}, #{sort}, #{startAt}, #{endAt}, #{createBy}, now(), #{updateBy}, now(), #{type}, #{bannerLocation})
	</insert>
	
	<update id="updateBanner" parameterType="java.util.Map">
		update banner set
		title = #{title},url = #{url},target = #{target},sort = #{sort},
		start_at = #{startAt},end_at = #{endAt},update_by = #{updateBy},update_at = now(), type = #{type},  banner_location = #{bannerLocation}
		<if test="image != null and image != ''">
			,image = #{image}
		</if>
		where Id = #{id}
	</update>
	
	<delete id="deleteBanner" parameterType="int">
		delete from banner where
		Id = #{id}
	</delete>
	
	<select id="getBannerList" parameterType="java.util.Map"
		resultType="BannerInfo">
		select
		<include refid="banner_field" />
		from banner
		<include refid="getBannerCondition" />
		order by Id desc
		<include refid="common.pageLimit" />
	</select>

	<select id="getBannerListCount" parameterType="java.util.Map"
		resultType="int">
		select count(*) from banner
		<include refid="getBannerCondition" />
	</select>
	
	<select id="getBannerLocationCount" parameterType="int" resultType="int">
	     select count(*) from banner where banner_location = #{bannerLocation}
	</select>
</mapper>