admin
2019-11-23 51a4ff5d777028d52a19c314a99f796334cb7b51
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?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.goods.ScanHistoryV2Mapper">
    <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.goods.ScanHistoryV2">
        <id column="s_id" property="id" jdbcType="BIGINT" />
        <result column="s_device" property="device" jdbcType="VARCHAR" />
        <result column="s_createtime" property="createTime" jdbcType="TIMESTAMP" />
        <result column="s_updatetime" property="updateTime" jdbcType="TIMESTAMP" />
 
        <association property="userInfo" column="s_uid"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="s_uid" property="id" jdbcType="BIGINT" />
        </association>
 
        <association property="commonGoods" column="s_common_goods_id"
            select="com.yeshi.fanli.dao.mybatis.goods.CommonGoodsMapper.selectByPrimaryKey">
        </association>
 
    </resultMap>
    <sql id="Base_Column_List">s_id,s_device,s_uid,s_common_goods_id,s_createtime,s_updatetime
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_scanhistory_v2 where s_id = #{id,jdbcType=BIGINT}
    </select>
 
    <!-- 根据UID或者设备号获取浏览记录 -->
    <select id="selectByDeviceOrUid" resultMap="BaseResultMap">
        SELECT * FROM (
                SELECT SUBSTRING_INDEX(GROUP_CONCAT(s.s_id ORDER BY s.s_createtime DESC), ',', 1)AS hid 
                FROM yeshi_ec_scanhistory_v2 s
            <if test="source != null">
                LEFT JOIN `yeshi_ec_common_goods` g ON s.`s_common_goods_id` = g.`cg_id`
            </if>
                WHERE
                    <trim prefix="(" suffix=")" suffixOverrides="or">
                        <if test="uid != null"> s.`s_uid`=#{uid,jdbcType=BIGINT} or</if>
                        <if test="device != null">s.`s_device`=#{device,jdbcType=VARCHAR} or</if>
                    </trim>
                    <if test="source != null">AND g.`cg_goods_type` = #{source}</if>
                 GROUP BY s.s_common_goods_id
                )A
        LEFT JOIN yeshi_ec_scanhistory_v2 B ON B.s_id = A.hid
        ORDER BY B.s_createtime DESC
        LIMIT #{start},#{count}
    </select>
 
    <!-- 根据UID或者设备号获取浏览记录条数 -->
    <select id="selectCountByDeviceOrUid" resultType="java.lang.Long">
        SELECT IFNULL(COUNT(DISTINCT s.`s_common_goods_id`),0) FROM yeshi_ec_scanhistory_v2 s
        <if test="source != null">
        LEFT JOIN `yeshi_ec_common_goods` g ON s.`s_common_goods_id` = g.`cg_id`
        </if>
        WHERE
        <trim prefix="(" suffix=")" suffixOverrides="or">
            <if test="uid != null"> s.`s_uid`=#{uid,jdbcType=BIGINT} or</if>
            <if test="device != null">s.`s_device`=#{device,jdbcType=VARCHAR} or</if>
        </trim>
        <if test="source != null">AND g.`cg_goods_type` = #{source}</if>
    </select>
 
 
 
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_scanhistory_v2 where s_id = #{id,jdbcType=BIGINT}
    </delete>
 
    <!-- 根据设备或用户ID删除 -->
 
    <select id="listDeviceOrUid" resultMap="BaseResultMap">
        SELECT s.* FROM yeshi_ec_scanhistory_v2 s
        WHERE
        <trim prefix="(" suffix=")" suffixOverrides="or">
            <if test="uid != null"> s.`s_uid`=#{uid,jdbcType=BIGINT} or</if>
            <if test="device != null">s.`s_device`=#{device,jdbcType=VARCHAR} or</if>
        </trim>
    </select>
 
 
    <!-- 根据设备或用户ID与商品信息检索 -->
    <select id="selectByDeviceOrUidAndGoodsIdAndGoodsType"    resultMap="BaseResultMap">
        SELECT s.* FROM yeshi_ec_scanhistory_v2 s left join
        yeshi_ec_common_goods g on g.cg_id=s.s_common_goods_id
        WHERE
        <trim prefix="(" suffix=")" suffixOverrides="or">
            <if test="uid != null"> s.`s_uid`=#{uid,jdbcType=BIGINT} or</if>
            <if test="device != null">s.`s_device`=#{device,jdbcType=VARCHAR} or</if>
        </trim>
        and g.cg_goods_id=#{goodsId}
    </select>
    
        <!-- 根据设备或用户ID与商品信息检索 -->
    <select id="getByCommonGoodsId"    resultMap="BaseResultMap">
        SELECT s.* FROM yeshi_ec_scanhistory_v2 s
        WHERE
        <trim prefix="(" suffix=")" suffixOverrides="or">
            <if test="uid != null"> s.`s_uid`=#{uid,jdbcType=BIGINT} or</if>
            <if test="device != null">s.`s_device`=#{device,jdbcType=VARCHAR} or</if>
        </trim>
        and s.s_common_goods_id =#{commonId}
    </select>
 
 
    <insert id="insert" parameterType="com.yeshi.fanli.entity.goods.ScanHistoryV2"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_scanhistory_v2
        (s_id,s_device,s_uid,s_common_goods_id,s_createtime,s_updatetime)
        values
        (#{id,jdbcType=BIGINT},#{device,jdbcType=VARCHAR},#{userInfo.id,jdbcType=BIGINT},#{commonGoods.id,jdbcType=BIGINT},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
 
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.goods.ScanHistoryV2"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_scanhistory_v2
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">s_id,</if>
            <if test="device != null">s_device,</if>
            <if test="userInfo != null">s_uid,</if>
            <if test="commonGoods != null">s_common_goods_id,</if>
            <if test="createTime != null">s_createtime,</if>
            <if test="updateTime != null">s_updatetime,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="device != null">#{device,jdbcType=VARCHAR},</if>
            <if test="userInfo != null">#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="commonGoods != null">#{commonGoods.id,jdbcType=BIGINT},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.goods.ScanHistoryV2">update
        yeshi_ec_scanhistory_v2 set s_device =
        #{device,jdbcType=VARCHAR},s_uid =
        #{userInfo.id,jdbcType=BIGINT},s_common_goods_id =
        #{commonGoods.id,jdbcType=BIGINT},s_createtime =
        #{createTime,jdbcType=TIMESTAMP},s_updatetime =
        #{updateTime,jdbcType=TIMESTAMP} where s_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.goods.ScanHistoryV2">
        update yeshi_ec_scanhistory_v2
        <set>
            <if test="device != null">s_device=#{device,jdbcType=VARCHAR},</if>
            <if test="userInfo != null">s_uid=#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="commonGoods != null">s_common_goods_id=#{commonGoods.id,jdbcType=BIGINT},
            </if>
            <if test="createTime != null">s_createtime=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">s_updatetime=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where s_id = #{id,jdbcType=BIGINT}
    </update>
</mapper>