BannerMapper.xml 4.33 KB
Newer Older
licc's avatar
licc committed
1 2 3
<?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">

licc's avatar
licc committed
4 5
<mapper namespace="cn.wisenergy.mapper.BannerMapper">
    <resultMap id="advertisingMap" type="cn.wisenergy.model.app.Banner">
licc's avatar
licc committed
6 7 8 9 10 11 12 13 14
        <id column="id" property="id"/>
        <result column="company_name" property="companyName"/>
        <result column="status" property="status"/>
        <result column="website" property="website"/>
        <result column="is_have_image" property="isHaveImage"/>
        <result column="type" property="type"/>
        <result column="image" property="image"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
cy's avatar
cy committed
15
        <result column="title" property="title"/>
licc's avatar
licc committed
16 17 18
    </resultMap>

    <sql id="table">
liaoanyuan's avatar
liaoanyuan committed
19
        banner
licc's avatar
licc committed
20 21 22 23 24 25 26 27
    </sql>

    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>

    <sql id="cols_exclude_id">
cy's avatar
cy committed
28
        company_name,status, website,is_have_image,type,image, create_time,update_time,title
licc's avatar
licc committed
29 30 31
    </sql>

    <sql id="vals">
cy's avatar
cy committed
32
        #{companyName},#{status},#{website},#{isHaveImage},#{type},#{image},now(),now(),#{title}
licc's avatar
licc committed
33 34 35 36 37 38 39 40 41
    </sql>

    <sql id="updateCondition">
        <if test="companyName != null">company_name = #{companyName},</if>
        <if test="status != null">status =#{status},</if>
        <if test="website != null">website =#{website},</if>
        <if test="isHaveImage != null">is_have_image =#{isHaveImage},</if>
        <if test="type != null">type =#{type},</if>
        <if test="image != null">image =#{image},</if>
cy's avatar
cy committed
42
        <if test="title != null">title =#{title},</if>
licc's avatar
licc committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        update_time =now()
    </sql>

    <sql id="criteria">
        <if test="id != null">id = #{id}</if>
        <if test="companyName != null">and company_name = #{companyName}</if>
        <if test="status != null">and status =#{status}</if>
        <if test="website != null">and website =#{website}</if>
        <if test="isHaveImage != null">and is_have_image =#{isHaveImage}</if>
        <if test="type != null">and type =#{type}</if>
        <if test="image != null">and image =#{image}</if>
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
        <if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
    </sql>

licc's avatar
licc committed
58
    <insert id="add" parameterType="cn.wisenergy.model.app.Banner" keyProperty="id" useGeneratedKeys="true">
licc's avatar
licc committed
59 60 61 62 63 64 65 66
        insert into
        <include refid="table"/>
        (<include refid="cols_exclude_id"/>)
        value(
        <include refid="vals"/>
        )
    </insert>

licc's avatar
licc committed
67
    <update id="edit" parameterType="cn.wisenergy.model.app.Banner">
licc's avatar
licc committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
        UPDATE
        <include refid="table"/>
        <set>
            <include refid="updateCondition"/>
        </set>
        <where>
            id = #{id}
        </where>
    </update>

    <delete id="delById" parameterType="java.lang.Integer">
        delete from
        <include refid="table"/>
        where id = #{id}
    </delete>

liaoanyuan's avatar
liaoanyuan committed
84
    <select id="getList" resultType="cn.wisenergy.model.dto.BannerDto" parameterType="map">
licc's avatar
licc committed
85 86 87 88
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
89 90 91 92
        <where>
            <if test="status != null">and status =#{status}</if>
            <if test="type != null">and type =#{type}</if>
        </where>
liaoanyuan's avatar
liaoanyuan committed
93
        order by create_time desc
licc's avatar
licc committed
94
        limit #{pageNo},#{pageSize}
licc's avatar
licc committed
95 96 97 98 99 100
    </select>

    <select id="count" resultType="java.lang.Integer">
        select count(1)
        from
        <include refid="table"/>
101 102 103 104
        <where>
            <if test="status != null">and status =#{status}</if>
            <if test="type != null">and type =#{type}</if>
        </where>
licc's avatar
licc committed
105 106
    </select>

liaoanyuan's avatar
liaoanyuan committed
107
    <select id="getById" resultMap="advertisingMap">
licc's avatar
licc committed
108 109 110 111
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
liaoanyuan's avatar
liaoanyuan committed
112 113 114
        where id=#{id}
    </select>

licc's avatar
licc committed
115 116 117 118 119
    <select id="getTopBanners" resultType="cn.wisenergy.model.app.Banner">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
licc's avatar
licc committed
120
        where status=1 and type=#{type}
licc's avatar
licc committed
121 122 123
    </select>

    <update id="editStatus">
liaoanyuan's avatar
liaoanyuan committed
124 125 126 127 128 129 130 131 132
        UPDATE
        <include refid="table"/>
        <set>
            status=#{status}
        </set>
        <where>
            id = #{id}
        </where>
    </update>
licc's avatar
licc committed
133
</mapper>