123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?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="shop.alien.mapper.second.SecondGoodsMapper">
- <resultMap id="BaseResultMap" type="shop.alien.entity.second.SecondGoods">
- <!--@mbggenerated-->
- <id column="id" property="id" jdbcType="INTEGER"/>
- <result column="user_id" property="userId" jdbcType="INTEGER"/>
- <result column="title" property="title" jdbcType="VARCHAR"/>
- <result column="describe" property="describe" jdbcType="VARCHAR"/>
- <result column="price" property="price" jdbcType="DECIMAL"/>
- <result column="position" property="position" jdbcType="VARCHAR"/>
- <result column="like_count" property="likeCount" jdbcType="INTEGER"/>
- <result column="collect_count" property="collectCount" jdbcType="INTEGER"/>
- <result column="category_one_id" property="categoryOneId" jdbcType="INTEGER"/>
- <result column="category_two_id" property="categoryTwoId" jdbcType="INTEGER"/>
- <result column="label" property="label" jdbcType="VARCHAR"/>
- <result column="topic" property="topic" jdbcType="VARCHAR"/>
- <result column="trade_id" property="tradeId" jdbcType="INTEGER"/>
- <result column="goods_status" property="goodsStatus" jdbcType="INTEGER"/>
- <result column="failed_reason" property="failedReason" jdbcType="VARCHAR"/>
- <result column="delete_flag" property="deleteFlag" jdbcType="INTEGER"/>
- <result column="created_time" property="createdTime" jdbcType="TIMESTAMP"/>
- <result column="created_user_id" property="createdUserId" jdbcType="INTEGER"/>
- <result column="updated_time" property="updatedTime" jdbcType="TIMESTAMP"/>
- <result column="updated_user_id" property="updatedUserId" jdbcType="INTEGER"/>
- <result column="release_time" property="releaseTime" jdbcType="TIMESTAMP"/>
- </resultMap>
- <!-- 自定义分页查询 -->
- <select id="getSecondGoodsByPage" resultType="shop.alien.entity.second.SecondGoods">
- SELECT *
- FROM second_goods
- WHERE delete_flag = 0
- </select>
- <!-- 自定义分页查询并按距离排序 Haversine公式 d=rarccos(cos(ϕ1)cos(ϕ2)cos(Δλ)+sin(ϕ1)sin(ϕ2)) -->
- <select id="getSecondGoodsByPageAndDistance" resultType="shop.alien.entity.second.SecondGoods">
- SELECT *,
- (6371 * acos(cos(radians(#{currentLatitude})) * cos(radians(SUBSTRING_INDEX(position, ',', 1))) * cos(radians(SUBSTRING_INDEX(position, ',', -1)) - radians(#{currentLongitude})) + sin(radians(#{currentLatitude})) * sin(radians(SUBSTRING_INDEX(position, ',', 1))))) AS distance
- FROM second_goods
- WHERE delete_flag = 0
- ORDER BY distance ASC
- </select>
- <!-- 查询商品热卖排行榜 -->
- <select id="getHotSellingRanking" resultType="shop.alien.entity.second.SecondGoods">
- SELECT *
- FROM second_goods
- WHERE delete_flag = 0
- ORDER BY like_count DESC
- </select>
- <!-- 查询商品热卖排行榜(前10名),按标签聚合计算总点赞量 -->
- <select id="getHotSellingRankingTop10" resultType="shop.alien.entity.second.SecondGoods">
- SELECT label, SUM(like_count) AS like_count
- FROM second_goods
- WHERE delete_flag = 0
- GROUP BY label
- ORDER BY like_count DESC
- LIMIT 10
- </select>
- <!-- 获取商品收藏排行榜(前10名),按标签聚合计算总收藏量 -->
- <select id="getCollectTop10" resultType="shop.alien.entity.second.SecondGoods">
- SELECT label, SUM(collect_count) AS collect_count
- FROM second_goods
- WHERE delete_flag = 0
- GROUP BY label
- ORDER BY collect_count DESC
- LIMIT 10
- </select>
- <!-- 带图片信息的商品查询 支持分类和状态筛选 -->
- <select id="selectGoodsWithImages" resultType="shop.alien.entity.second.SecondGoods">
- SELECT *
- FROM second_goods
- <where>
- <if test="categoryId != null">
- AND category_one_id = #{categoryId}
- </if>
- <if test="status != null">
- AND goods_status = #{status}
- </if>
- </where>
- </select>
- <!-- 查询用户屏蔽的商品列表 -->
- <select id="getShieldedGoodsListByType" resultType="shop.alien.entity.second.SecondGoods">
- SELECT sg.*
- FROM second_goods sg
- INNER JOIN second_shield ss ON
- (sg.id = ss.shield_id AND ss.shield_type = 1) OR
- (sg.user_id = ss.shield_id AND ss.shield_type = 2)
- WHERE ss.user_id = #{userId} AND ss.delete_flag = 0 AND sg.delete_flag = 0
- AND ss.shield_type = #{shieldType}
- </select>
- <!-- 搜索商品列表(包含商品信息、图片、用户信息),按距离和创建时间倒序 -->
- <select id="searchGoodsList" resultType="shop.alien.entity.second.SecondGoods">
- SELECT
- sg.*,
- (6371 * acos(cos(radians(#{currentLatitude})) * cos(radians(SUBSTRING_INDEX(sg.position, ',', 1))) * cos(radians(SUBSTRING_INDEX(sg.position, ',', -1)) - radians(#{currentLongitude})) + sin(radians(#{currentLatitude})) * sin(radians(SUBSTRING_INDEX(sg.position, ',', 1))))) AS distance
- FROM second_goods sg
- WHERE sg.delete_flag = 0
- ORDER BY distance ASC, sg.created_time DESC
- </select>
- </mapper>
|