admin
2020-05-06 24a8d17e007545f7426c48352109aa1a9c6587ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?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.yeshi.fanli.dao.mybatis.homemodule.HomeNavbarUserMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.homemodule.HomeNavbarUser">
    <id column="hnu_id" property="id" jdbcType="BIGINT"/>
    <result column="hnu_uid" property="uid" jdbcType="BIGINT"/>
    <result column="hnu_device" property="device" jdbcType="VARCHAR"/>
    <result column="hnu_order" property="order" jdbcType="INTEGER"/>
    <result column="hnu_create_time" property="createTime" jdbcType="TIMESTAMP"/>
    
    <association property="homeNavbar" column="hnu_navbar_id" javaType="com.yeshi.fanli.entity.bus.homemodule.HomeNavbar">
        <id column="hnu_navbar_id" property="id" jdbcType="BIGINT" />    
    </association>
  </resultMap>
  
  <resultMap id="WholeResultMap" type="com.yeshi.fanli.entity.bus.homemodule.HomeNavbarUser">
    <id column="hnu_id" property="id" jdbcType="BIGINT"/>
    <result column="hnu_uid" property="uid" jdbcType="BIGINT"/>
    <result column="hnu_device" property="device" jdbcType="VARCHAR"/>
    <result column="hnu_order" property="order" jdbcType="INTEGER"/>
    <result column="hnu_create_time" property="createTime" jdbcType="TIMESTAMP"/>
    <association property="homeNavbar" column="hnu_navbar_id" resultMap="com.yeshi.fanli.dao.mybatis.homemodule.HomeNavbarMapper.BaseResultMap"/>
  </resultMap>
  
  <sql id="Base_Column_List">hnu_id,hnu_uid,hnu_device,hnu_order,hnu_navbar_id,hnu_create_time</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_home_navbar_user where hnu_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_home_navbar_user where hnu_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.homemodule.HomeNavbarUser" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_home_navbar_user (hnu_id,hnu_uid,hnu_device,hnu_order,hnu_navbar_id,hnu_create_time) values (#{id,jdbcType=BIGINT},#{uid,jdbcType=BIGINT},#{device,jdbcType=VARCHAR},#{order,jdbcType=INTEGER},#{homeNavbar.id,jdbcType=BIGINT},#{createTime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.homemodule.HomeNavbarUser" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_home_navbar_user
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">hnu_id,</if>
      <if test="uid != null">hnu_uid,</if>
      <if test="device != null">hnu_device,</if>
      <if test="order != null">hnu_order,</if>
      <if test="homeNavbar != null">hnu_navbar_id,</if>
      <if test="createTime != null">hnu_create_time,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="uid != null">#{uid,jdbcType=BIGINT},</if>
      <if test="device != null">#{device,jdbcType=VARCHAR},</if>
      <if test="order != null">#{order,jdbcType=INTEGER},</if>
      <if test="homeNavbar != null">#{homeNavbar.id,jdbcType=BIGINT},</if>
      <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.homemodule.HomeNavbarUser">update yeshi_ec_home_navbar_user set hnu_uid = #{uid,jdbcType=BIGINT},hnu_device = #{device,jdbcType=VARCHAR},hnu_order = #{order,jdbcType=INTEGER},hnu_navbar_id = #{homeNavbar.id,jdbcType=BIGINT},hnu_create_time = #{createTime,jdbcType=TIMESTAMP} where hnu_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.homemodule.HomeNavbarUser">update yeshi_ec_home_navbar_user
    <set>
      <if test="uid != null">hnu_uid=#{uid,jdbcType=BIGINT},</if>
      <if test="device != null">hnu_device=#{device,jdbcType=VARCHAR},</if>
      <if test="order != null">hnu_order=#{order,jdbcType=INTEGER},</if>
      <if test="homeNavbar != null">hnu_navbar_id=#{homeNavbar.id,jdbcType=BIGINT},</if>
      <if test="createTime != null">hnu_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
    </set> where hnu_id = #{id,jdbcType=BIGINT}
  </update>
  
    <!-- 批量插入数据 -->
  <insert id="insertBatch" keyProperty="id" parameterType="java.util.List">
        insert into yeshi_ec_home_navbar_user
        (hnu_id,hnu_uid,hnu_device,hnu_order,hnu_navbar_id,hnu_create_time)
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.id,jdbcType=BIGINT},
            #{item.uid,jdbcType=BIGINT},
            #{item.device,jdbcType=VARCHAR},
            #{item.order,jdbcType=INTEGER},
            #{item.homeNavbar.id,jdbcType=BIGINT},
            #{item.createTime,jdbcType=TIMESTAMP}
            )
        </foreach>
  </insert>
  
  <!-- 批量更新排序 -->
  <update id="updateSelectiveBatch" parameterType="java.util.List">
        update yeshi_ec_home_navbar_user
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="hnu_order=case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.order !=null">
                        when hnu_id=#{item.id} then #{item.order}
                    </if>
                </foreach>
            </trim>
        </trim>
        where hnu_id in
        <foreach collection="list" index="index" item="item"
            separator="," open="(" close=")">
            #{item.id,jdbcType=BIGINT}
        </foreach>
    </update>
  
      <delete id="deleteByPrimaryKeyBatch" parameterType="java.util.List">
        DELETE FROM yeshi_ec_home_navbar_user WHERE hnu_id in
        <foreach collection="list" item="item" open="(" close=")"
            separator=",">#{item}</foreach>
    </delete>
    
    <delete id="deleteByUid">
        DELETE FROM yeshi_ec_home_navbar_user 
        WHERE hnu_uid = #{uid}
    </delete>
    
    <delete id="deleteByDevice">
        DELETE FROM yeshi_ec_home_navbar_user 
        WHERE hnu_device = #{device}
    </delete>
  
  <select id="listEffectiveNavbars" resultMap="WholeResultMap">
     SELECT * FROM yeshi_ec_home_navbar_user u
    LEFT JOIN yeshi_ec_home_navbar h ON u.`hnu_navbar_id` = h.`br_id`
    WHERE h.br_state = 1 
          AND IF(h.br_start_time IS NULL,TRUE, h.br_start_time<![CDATA[<=]]> NOW()) 
          AND IF(h.br_end_time IS NULL,TRUE, h.br_end_time <![CDATA[>=]]> NOW())
        <if test="uid != null"> AND u.`hnu_uid` = #{uid} </if>
        <if test="device != null"> AND u.`hnu_device` = #{device}</if>
    ORDER BY u.`hnu_order`
  </select>
  
   <select id="listMyNavbars" resultMap="BaseResultMap">
     SELECT * FROM yeshi_ec_home_navbar_user u
    WHERE 1=1
        <if test="uid != null"> AND u.`hnu_uid` = #{uid} </if>
        <if test="device != null"> AND u.`hnu_device` = #{device}</if>
  </select>
  
  
  
  
  
  
</mapper>