Explorar o código

关注推荐新品接口提交

zjy hai 3 semanas
pai
achega
8154eca3f7

+ 61 - 0
alien-entity/src/main/java/shop/alien/entity/second/SecondGoodsCategory.java

@@ -0,0 +1,61 @@
+package shop.alien.entity.second;
+
+
+import com.baomidou.mybatisplus.annotation.*;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 二手商品类别表
+ */
+@Data
+@JsonInclude
+@TableName("second_goods_category")
+public class SecondGoodsCategory implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    @ApiModelProperty(value = "主键ID")
+    private Integer id;
+
+    @TableField("category_name")
+    @ApiModelProperty(value = "类别名称")
+    private String categoryName;
+
+    @TableField("category_url")
+    @ApiModelProperty(value = "类别图片URL")
+    private String categoryUrl;
+
+    @TableField("parent_id")
+    @ApiModelProperty(value = "上级ID")
+    private Integer parentId;
+
+    @TableField("delete_flag")
+    @ApiModelProperty(value = "删除标记 0:未删除 1:已删除")
+    @TableLogic
+    private Integer deleteFlag;
+
+    @TableField(value = "created_time", fill = FieldFill.INSERT)
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @ApiModelProperty(value = "创建时间")
+    private Date createdTime;
+
+    @TableField("created_user_id")
+    @ApiModelProperty(value = "创建人ID")
+    private Integer createdUserId;
+
+    @TableField(value = "updated_time", fill = FieldFill.UPDATE)
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @ApiModelProperty(value = "修改时间")
+    private Date updatedTime;
+
+    @TableField("updated_user_id")
+    @ApiModelProperty(value = "修改人ID")
+    private Integer updatedUserId;
+}

+ 40 - 0
alien-entity/src/main/java/shop/alien/entity/second/vo/SecondGoodsRecommendVo.java

@@ -0,0 +1,40 @@
+package shop.alien.entity.second.vo;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import shop.alien.entity.second.SecondGoods;
+import shop.alien.entity.store.StoreComment;
+
+import java.util.List;
+
+@Data
+@JsonInclude
+@ApiModel(value = "二手商品推荐", description = "推荐")
+public class SecondGoodsRecommendVo extends SecondGoods {
+
+    @ApiModelProperty(value = "用户名称")
+    private String userName;
+
+    @ApiModelProperty(value = "用户头像")
+    private String userImage;
+
+    @ApiModelProperty(value = "距离")
+    private String dist;
+
+    @ApiModelProperty(value = "是否点赞")
+    private String likeStatus;
+
+    @ApiModelProperty(value = "是否收藏")
+    private String collectStatus;
+
+    @ApiModelProperty(value = "评论数量")
+    private String commentCount;
+
+    @ApiModelProperty(value = "评论列表")
+    List<StoreComment> commentList;
+
+    @ApiModelProperty(value = "话题列表")
+    List<String> topicList;
+}

+ 4 - 0
alien-entity/src/main/java/shop/alien/entity/store/LifeCollect.java

@@ -25,6 +25,10 @@ public class LifeCollect {
 
     private String goodsId;
 
+    private String businessId;
+
+    private String businessType;
+
     @ApiModelProperty(value = "删除标记, 0:未删除, 1:已删除")
     @TableField("delete_flag")
     @TableLogic

+ 16 - 0
alien-entity/src/main/java/shop/alien/mapper/second/SecondGoodsCategoryMapper.java

@@ -0,0 +1,16 @@
+package shop.alien.mapper.second;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import shop.alien.entity.second.SecondGoodsCategory;
+
+import java.util.List;
+
+/**
+ * 二手商品映射器
+ */
+public interface SecondGoodsCategoryMapper extends BaseMapper<SecondGoodsCategory> {
+    /**
+     * 自定义分页查询
+     */
+    List<SecondGoodsCategory> querySecondGoodsByParentId(Integer parentId);
+}

+ 26 - 0
alien-entity/src/main/java/shop/alien/mapper/second/SecondRecommendMapper.java

@@ -0,0 +1,26 @@
+package shop.alien.mapper.second;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.apache.ibatis.annotations.Param;
+import shop.alien.entity.second.vo.SecondGoodsRecommendVo;
+import shop.alien.entity.store.StoreComment;
+
+import java.util.List;
+
+
+/**
+ * 二手商品映射器
+ */
+public interface SecondRecommendMapper extends BaseMapper<SecondGoodsRecommendVo> {
+    /**
+     * 自定义分页查询
+     */
+    IPage<SecondGoodsRecommendVo> getSecondRecommendByPage(IPage<SecondGoodsRecommendVo> page, @Param("userId") Integer userId, @Param("position") String position, @Param("typeId") Integer typeId);
+
+    IPage<SecondGoodsRecommendVo> querySecondConcernByPage(IPage<SecondGoodsRecommendVo> page, @Param("phoneId") String phoneId, @Param("position") String position);
+
+    IPage<SecondGoodsRecommendVo> querySecondNewGoodsByPage(IPage<SecondGoodsRecommendVo> page,@Param("userId") String userId, @Param("phoneId") String phoneId, @Param("position") String position);
+
+    List<StoreComment> querySecondCommentInfo(@Param("ids") List<Integer> ids);
+}

+ 36 - 0
alien-entity/src/main/resources/mapper/second/SecondGoodsCategoryMapper.xml

@@ -0,0 +1,36 @@
+<?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.SecondGoodsCategoryMapper">
+    <resultMap id="BaseResultMap" type="shop.alien.entity.second.SecondGoodsCategory">
+        <!--@mbggenerated-->
+        <id column="id" property="id" jdbcType="INTEGER"/>
+        <result column="category_name" property="categoryName" jdbcType="VARCHAR"/>
+        <result column="category_url" property="categoryUrl" jdbcType="VARCHAR"/>
+        <result column="parent_id" property="parentId" jdbcType="INTEGER"/>
+        <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"/>
+    </resultMap>
+
+    <!-- 根据上级ID查询二手商品类别表 -->
+    <select id="querySecondGoodsByParentId" resultType="shop.alien.entity.second.SecondGoodsCategory">
+        SELECT
+            id,
+            category_name,
+            category_url,
+            parent_id
+        FROM
+            second_goods_category
+        WHERE
+            delete_flag = 0
+            <if test="parentId != null and parentId != '' ">
+                AND parent_id = #{parentId}
+            </if>
+            <if test="parentId == null or parentId == '' ">
+                AND parent_id = -1
+            </if>
+    </select>
+
+</mapper>

+ 185 - 0
alien-entity/src/main/resources/mapper/second/SecondGoodsInfoMapper.xml

@@ -0,0 +1,185 @@
+<?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.SecondRecommendMapper">
+    <resultMap id="BaseResultMap" type="shop.alien.entity.second.vo.SecondGoodsRecommendVo">
+        <!--@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="description" property="description" 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="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="user_name" property="userName" jdbcType="VARCHAR"/>
+        <result column="user_image" property="userImage" jdbcType="VARCHAR"/>
+        <result column="goods_status" property="goodsStatus" jdbcType="INTEGER"/>
+        <result column="delete_flag" property="deleteFlag" jdbcType="INTEGER"/>
+        <result column="dist" property="dist" jdbcType="VARCHAR"/>
+        <result column="isLike" property="isLike" jdbcType="VARCHAR"/>
+        <result column="home_image" property="homeImage" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <!-- 分页查询推荐数据 -->
+    <select id="getSecondRecommendByPage" resultType="shop.alien.entity.second.vo.SecondGoodsRecommendVo">
+        with shieldUser as (
+            select g.id from second_shield s inner join second_goods g
+                on s.shield_id = g.user_id  and g.delete_flag = '0' and goods_status = '3' and s.delete_flag = '0'
+            where s.user_id = #{userId} and s.shield_type = 2
+        )
+        SELECT
+            g.id,
+            g.user_id,
+            g.title,
+            g.description,
+            g.price,
+            g.position,
+            g.like_count,
+            g.collect_count,
+            g.category_one_id,
+            g.category_two_id,
+            g.label,
+            g.topic,
+            g.trade_id,
+            g.created_time,
+            g.created_user_id,
+            g.updated_time,
+            g.updated_user_id,
+            u.user_name,
+            u.user_image,
+            g.goods_status,
+            g.delete_flag,
+            ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
+            case when llr.id is null then '0' else '1' end likeStatus,
+            g.home_image
+        FROM
+            second_goods g inner join life_user u on u.id =  g.user_id and u.delete_flag = 0
+            left join life_like_record llr on llr.dianzan_id = g.user_id and llr.huifu_id = g.id and llr.type = 6 and llr.delete_flag = 0
+        where g.delete_flag = 0
+            <if test="typeId != null and typeId != '' ">
+                and (g.category_one_id = #{typeId} or g.category_two_id =#{typeId} )
+            </if>
+            and not exists (select 1 from second_shield s where s.id = g.id)
+            and not exists (select 1 from second_shield s where s.user_id = #{userId} and s.shield_type = 1 and s.shield_id = g.id and s.delete_flag = 0)
+            and g.goods_status = 3
+        order by dist, like_count desc, created_time desc
+    </select>
+
+    <!-- 分页查询关注数据concern -->
+    <select id="querySecondConcernByPage" resultType="shop.alien.entity.second.vo.SecondGoodsRecommendVo">
+        select
+            g.id,
+            g.user_id,
+            g.title,
+            g.describe,
+            g.price,
+            ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
+            g.like_count,
+            g.collect_count,
+            g.label,
+            g.topic,
+            g.trade_id,
+            g.created_time,
+            g.created_user_id,
+            g.updated_time,
+            g.updated_user_id,
+            u.user_name,
+            u.user_image,
+            g.goods_status,
+            g.home_image,
+            case when llr.id is null then '0' else '1' end likeStatus,
+            case when lc.id is null then '0' else '1' end collectStatus,
+            (select count(1) from store_comment c where c.business_id = g.id and c.business_type = 1 and c.delete_flag = 0) as commentCount
+        from
+            life_fans f inner join life_user u on
+                f.followed_id = CONCAT('user_', u.user_phone) and u.delete_flag = 0
+            inner join second_goods g on
+                u.id = g.user_id
+                and g.goods_status = 3
+                and g.delete_flag = 0
+            left join life_like_record llr on llr.dianzan_id = #{phoneId} and llr.huifu_id = g.id and llr.type = 6 and llr.delete_flag = 0
+            left join life_collect lc on lc.goods_id = g.id and lc.user_id = #{phoneId} and lc.delete_flag = 0
+        where
+            f.fans_id = #{phoneId} and f.delete_flag = 0
+    </select>
+
+    <select id="querySecondCommentInfo" resultType="shop.alien.entity.store.StoreComment">
+        select
+            business_id,
+            comment_content,
+            created_time,
+            user_name,
+            user_image,
+            rn
+        from (
+            select
+                c.business_id,
+                c.comment_content,
+                c.created_time,
+                u.user_name,
+                u.user_image,
+                row_number() over (partition by c.business_id order by c.created_time desc) as rn
+            from
+                store_comment c inner join life_user u on c.user_id = u.id and u.delete_flag = 0
+            where c.delete_flag = 0
+                and business_id in
+                <foreach collection="ids" item="id" open="(" separator="," close=")">
+                    ${id}
+                </foreach>
+        ) a where rn <![CDATA[ <= ]]> 2
+    </select>
+
+    <!-- 分页查询推荐数据 -->
+    <select id="querySecondNewGoodsByPage" resultType="shop.alien.entity.second.vo.SecondGoodsRecommendVo">
+        with shieldUser as (
+            select g.id from second_shield s inner join second_goods g
+            on s.shield_id = g.user_id  and g.delete_flag = '0' and goods_status = '3' and s.delete_flag = '0'
+            where s.user_id = #{userId} and s.shield_type = 2
+        )
+        SELECT
+            g.id,
+            g.user_id,
+            g.title,
+            g.description,
+            g.price,
+            g.position,
+            g.like_count,
+            g.collect_count,
+            g.category_one_id,
+            g.category_two_id,
+            g.label,
+            g.topic,
+            g.trade_id,
+            g.created_time,
+            g.created_user_id,
+            g.updated_time,
+            g.updated_user_id,
+            u.user_name,
+            u.user_image,
+            g.goods_status,
+            g.delete_flag,
+            ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(g.position, ',', ' '), ')' ))) / 1000, 2) AS dist,
+            g.home_image,
+            case when llr.id is null then '0' else '1' end likeStatus,
+            case when lc.id is null then '0' else '1' end collectStatus,
+            (select count(1) from store_comment c where c.business_id = g.id and c.business_type = 1 and c.delete_flag = 0) as commentCount
+        FROM
+            second_goods g inner join life_user u on u.id =  g.user_id
+            left join life_like_record llr on llr.dianzan_id = #{phoneId} and llr.huifu_id = g.id and llr.type = 6 and llr.delete_flag = 0
+            left join life_collect lc on lc.goods_id = g.id and lc.user_id = #{phoneId} and lc.delete_flag = 0
+        where g.delete_flag = 0
+            and not exists (select 1 from shieldUser s where s.id = g.id)
+            and not exists (select 1 from second_shield s where s.user_id = #{userId} and s.shield_type = 1 and s.shield_id = g.id)
+            and g.goods_status = 3
+    </select>
+
+</mapper>

+ 33 - 0
alien-second/src/main/java/shop/alien/second/controller/SecondGoodsCategoryController.java

@@ -0,0 +1,33 @@
+package shop.alien.second.controller;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiSort;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+import shop.alien.entity.result.R;
+import shop.alien.entity.second.SecondGoodsCategory;
+import shop.alien.second.service.SecondGoodsCategoryService;
+
+import java.util.List;
+
+@Slf4j
+@Api(tags = {"二手平台-商品类型"})
+@ApiSort(9)
+@CrossOrigin
+@RestController
+@RequestMapping("/second/goodsCategory")
+@RequiredArgsConstructor
+public class SecondGoodsCategoryController {
+
+    private final SecondGoodsCategoryService service;
+
+    @ApiOperation("搜索商品类型")
+    @PostMapping("/querySecondGoodsByParentId")
+    public R<List<SecondGoodsCategory>> querySecondGoodsByParentId(
+            @RequestParam(value = "parentId", required = false) Integer parentId) {
+        return R.data(service.querySecondGoodsByParentId(parentId), "查询成功");
+    }
+
+}

+ 110 - 0
alien-second/src/main/java/shop/alien/second/controller/SecondRecommendController.java

@@ -0,0 +1,110 @@
+package shop.alien.second.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiSort;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+import shop.alien.entity.result.R;
+import shop.alien.entity.second.vo.SecondGoodsRecommendVo;
+import shop.alien.second.service.SecondRecommendService;
+
+@Slf4j
+@Api(tags = {"二手平台-商品列表"})
+@ApiSort(9)
+@CrossOrigin
+@RestController
+@RequestMapping("/recommend")
+@RequiredArgsConstructor
+public class SecondRecommendController {
+
+    private final SecondRecommendService service;
+
+    @ApiOperation("搜索推荐商品列表")
+    @PostMapping("/queryRecommendList")
+    public R<IPage<SecondGoodsRecommendVo>> queryRecommendList(
+            @RequestParam(value = "pageNum", required = false) Integer pageNum,
+            @RequestParam(value = "pageSize", required = false) Integer pageSize,
+            @RequestParam(value = "typeId", required = false) Integer typeId,
+            @RequestParam(value = "longitude", required = false) String longitude,
+            @RequestParam(value = "latitude", required = false) String latitude) {
+        IPage<SecondGoodsRecommendVo> page = new Page<>(pageNum, pageSize);
+        IPage<SecondGoodsRecommendVo> result = service.getSecondRecommendByPage(page, longitude, latitude, typeId);
+        return R.data(result, "查询成功");
+    }
+
+    @ApiOperation("搜索关注商品列表")
+    @PostMapping("/querySecondConcernByPage")
+    public R<IPage<SecondGoodsRecommendVo>> querySecondConcernByPage(
+            @RequestParam(value = "pageNum", required = false) Integer pageNum,
+            @RequestParam(value = "pageSize", required = false) Integer pageSize,
+            @RequestParam(value = "longitude", required = false) String longitude,
+            @RequestParam(value = "latitude", required = false) String latitude) {
+        IPage<SecondGoodsRecommendVo> page = new Page<>(pageNum, pageSize);
+        IPage<SecondGoodsRecommendVo> result = service.querySecondConcernByPage(page, longitude + "," + latitude);
+        return R.data(result, "查询成功");
+    }
+
+    @ApiOperation("搜索新品商品列表")
+    @PostMapping("/querySecondNewGoodsByPage")
+    public R<IPage<SecondGoodsRecommendVo>> querySecondNewGoodsByPage(
+            @RequestParam(value = "pageNum", required = false) Integer pageNum,
+            @RequestParam(value = "pageSize", required = false) Integer pageSize,
+            @RequestParam(value = "longitude", required = false) String longitude,
+            @RequestParam(value = "latitude", required = false) String latitude) {
+        IPage<SecondGoodsRecommendVo> page = new Page<>(pageNum, pageSize);
+        IPage<SecondGoodsRecommendVo> result = service.querySecondNewGoodsByPage(page, longitude + "," + latitude);
+        return R.data(result, "查询成功");
+    }
+
+    @ApiOperation("搜索商品详情")
+    @PostMapping("/querySecondGoodsDetail")
+    public R<SecondGoodsRecommendVo> querySecondGoodsDetail(
+            @RequestParam(value = "goodsId", required = false) Integer goodsId) {
+        //IPage<SecondGoodsRecommendVo> result = service.querySecondNewGoodsByPage(goodsId);
+        return R.data(null, "查询成功");
+    }
+
+
+
+    private static final double EARTH_RADIUS = 6371; // 地球半径 (千米)
+
+    /**
+     * 计算两个经纬度之间的距离
+     * @param lat1 第一个点的纬度
+     * @param lon1 第一个点的经度
+     * @param lat2 第二个点的纬度
+     * @param lon2 第二个点的经度
+     * @return 距离(千米)
+     */
+    public static double calculateDistance(double lat1, double lon1, double lat2, double lon2) {
+        // 将经纬度从度数转换为弧度
+        double radLat1 = Math.toRadians(lat1);
+        double radLon1 = Math.toRadians(lon1);
+        double radLat2 = Math.toRadians(lat2);
+        double radLon2 = Math.toRadians(lon2);
+
+        // 计算经纬度差值
+        double deltaLat = radLat2 - radLat1;
+        double deltaLon = radLon2 - radLon1;
+
+        // Haversine 公式
+        double a = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) +
+                Math.cos(radLat1) * Math.cos(radLat2) *
+                        Math.sin(deltaLon / 2) * Math.sin(deltaLon / 2);
+        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
+
+        // 计算最终距离
+        return EARTH_RADIUS * c;
+    }
+
+    public static void main(String[] args) {
+        // 示例:计算北京 (39.9042° N, 116.4074° E) 到上海 (31.2304° N, 121.4737° E) 的距离
+        double distance = calculateDistance(39.01, 121.49, 41.48, 123.25);
+        System.out.printf("两地距离: %.2f 公里%n", distance);
+    }
+
+}

+ 20 - 0
alien-second/src/main/java/shop/alien/second/service/SecondGoodsCategoryService.java

@@ -0,0 +1,20 @@
+package shop.alien.second.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import shop.alien.entity.second.SecondGoodsCategory;
+
+import java.util.List;
+
+/**
+ * 二手商品服务接口
+ */
+public interface SecondGoodsCategoryService extends IService<SecondGoodsCategory> {
+
+    /**
+     * 获取分类列表
+     * @param parentId 父ID
+     * @return 分页后的屏蔽商品列
+     */
+    List<SecondGoodsCategory> querySecondGoodsByParentId(Integer parentId);
+
+}

+ 25 - 0
alien-second/src/main/java/shop/alien/second/service/SecondRecommendService.java

@@ -0,0 +1,25 @@
+package shop.alien.second.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
+import shop.alien.entity.second.vo.SecondGoodsRecommendVo;
+
+
+/**
+ * 二手商品服务接口
+ */
+public interface SecondRecommendService extends IService<SecondGoodsRecommendVo> {
+
+    /**
+     * 查询推荐信息
+     * @param page 分页信息
+     * @return 是否成功保存
+     */
+    IPage<SecondGoodsRecommendVo> getSecondRecommendByPage(IPage<SecondGoodsRecommendVo> page, String longitude, String latitude, Integer typeId);
+
+    IPage<SecondGoodsRecommendVo> querySecondConcernByPage(IPage<SecondGoodsRecommendVo> page, String position);
+
+    IPage<SecondGoodsRecommendVo> querySecondNewGoodsByPage(IPage<SecondGoodsRecommendVo> page, String position);
+
+
+}

+ 31 - 0
alien-second/src/main/java/shop/alien/second/service/impl/SecondGoodsCategoryServiceImpl.java

@@ -0,0 +1,31 @@
+package shop.alien.second.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import shop.alien.entity.second.SecondGoodsCategory;
+import shop.alien.mapper.second.SecondGoodsCategoryMapper;
+import shop.alien.second.service.SecondGoodsCategoryService;
+
+import java.util.List;
+
+/**
+ * 二手商品服务实现类
+ */
+@Service
+@RequiredArgsConstructor
+public class SecondGoodsCategoryServiceImpl extends ServiceImpl<SecondGoodsCategoryMapper, SecondGoodsCategory> implements SecondGoodsCategoryService {
+
+    @Autowired
+    private SecondGoodsCategoryMapper mapper;
+    /**
+     * 保存商品为草稿状态
+     * @param parentId 商品实体
+     * @return 是否成功保存
+     */
+    @Override
+    public List<SecondGoodsCategory> querySecondGoodsByParentId(Integer parentId) {
+        return mapper.querySecondGoodsByParentId(parentId);
+    }
+}

+ 176 - 0
alien-second/src/main/java/shop/alien/second/service/impl/SecondRecommendServiceImpl.java

@@ -0,0 +1,176 @@
+package shop.alien.second.service.impl;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.poi.util.StringUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import shop.alien.entity.second.vo.SecondGoodsRecommendVo;
+import shop.alien.entity.store.StoreComment;
+import shop.alien.mapper.second.SecondRecommendMapper;
+import shop.alien.second.service.SecondRecommendService;
+import shop.alien.util.common.JwtUtil;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 二手商品服务实现类
+ */
+@Service
+public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMapper, SecondGoodsRecommendVo> implements SecondRecommendService {
+
+    @Autowired
+    private SecondRecommendMapper mapper;
+    /**
+     * 获取二手商品推荐列表
+     * @param page 分页信息
+     * @return 推荐列表
+     */
+    @Override
+    public IPage<SecondGoodsRecommendVo> getSecondRecommendByPage(
+            IPage<SecondGoodsRecommendVo> page, String longitude, String latitude, Integer typeId) {
+        JSONObject data = JwtUtil.getCurrentUserInfo();
+        Integer userId = null;
+        if (data != null) {
+            userId = data.getInteger("userId");
+        }
+        if (userId == null) {
+            return null;
+        }
+        IPage<SecondGoodsRecommendVo> result = mapper.getSecondRecommendByPage(page, userId, longitude + "," + latitude, typeId);
+        for (SecondGoodsRecommendVo row : result.getRecords()){
+            if (StringUtil.isNotBlank(row.getDist())) {
+                row.setPosition("距离" + row.getDist() + "km");
+            }
+            if (StringUtil.isNotBlank(row.getTopic())) {
+                List<String> topicList = Arrays.asList(row.getTopic().split(","));
+                row.setTopicList(topicList);
+            }
+        }
+        return result;
+    }
+
+    /**
+     * 获取二手商品关注列表
+     * @param page 分页信息
+     * @return 关注列表
+     */
+    public IPage<SecondGoodsRecommendVo> querySecondConcernByPage(
+            IPage<SecondGoodsRecommendVo> page, String position) {
+        JSONObject data = JwtUtil.getCurrentUserInfo();
+        String phoneId = null;
+        if (data != null) {
+            phoneId = data.getString("phone");
+        }
+        if (StringUtil.isBlank(phoneId)) {
+            return null;
+        }
+        IPage<SecondGoodsRecommendVo> list = mapper.querySecondConcernByPage(page, "user_" + phoneId, position);
+        List<Integer> idList = list.getRecords().stream() // 创建流
+                .map(obj -> obj.getId())   // 提取每个元素的 ID
+                .collect(Collectors.toList());
+        if (CollectionUtil.isEmpty(idList)) {
+            return list;
+        }
+        List<StoreComment> commentList =mapper.querySecondCommentInfo(idList);
+        list.getRecords().forEach(item -> {
+            // 距离拼接
+            if (StringUtil.isNotBlank(item.getDist())) {
+                item.setPosition("距离" + item.getDist() + "km");
+            }
+            // 话题列表
+            if (StringUtil.isNotBlank(item.getTopic())) {
+                List<String> topicList = Arrays.asList(item.getTopic().split(","));
+                item.setTopicList(topicList);
+            }
+            // 评论列表
+            List<StoreComment> cList = new ArrayList<>();
+            commentList.forEach(comment -> {
+                if (item.getId() == comment.getBusinessId()) {
+                    cList.add(comment);
+                }
+            });
+            if (cList.size() > 0) {
+                item.setCommentList(cList);
+            }
+        });
+        return list;
+    }
+
+
+    /**
+     * 获取二手商品新品列表
+     * @param page 分页信息
+     * @return 关注列表
+     */
+    public IPage<SecondGoodsRecommendVo> querySecondNewGoodsByPage(
+            IPage<SecondGoodsRecommendVo> page, String position) {
+        JSONObject data = JwtUtil.getCurrentUserInfo();
+        String phoneId = null;
+        String userId = null;
+        if (data != null) {
+            phoneId = data.getString("phone");
+            userId = data.getString("userId");
+        }
+        if (StringUtil.isBlank(phoneId)) {
+            return null;
+        }
+        IPage<SecondGoodsRecommendVo> list = mapper.querySecondNewGoodsByPage(page, userId,"user_" + phoneId, position);
+        List<Integer> idList = list.getRecords().stream() // 创建流
+                .map(obj -> obj.getId())   // 提取每个元素的 ID
+                .collect(Collectors.toList());
+        if (CollectionUtil.isEmpty(idList)) {
+            return list;
+        }
+        List<StoreComment> commentList =mapper.querySecondCommentInfo(idList);
+        list.getRecords().forEach(item -> {
+            // 距离拼接
+            if (StringUtil.isNotBlank(item.getDist())) {
+                item.setPosition("距离" + item.getDist() + "km");
+            }
+            // 话题列表
+            if (StringUtil.isNotBlank(item.getTopic())) {
+                List<String> topicList = Arrays.asList(item.getTopic().split(","));
+                item.setTopicList(topicList);
+            }
+            // 评论列表
+            List<StoreComment> cList = new ArrayList<>();
+            commentList.forEach(comment -> {
+                if (item.getId() == comment.getBusinessId()) {
+                    cList.add(comment);
+                }
+            });
+            if (cList.size() > 0) {
+                item.setCommentList(cList);
+            }
+        });
+        return list;
+    }
+    public static void main(String[] args) {
+        List<Map<String, Object>> list = new ArrayList<>();
+        Map<String, Object> map = new HashMap<>();
+        map.put("id", 1);
+        map.put("name", "张三");
+        list.add(map);
+        Map<String, Object> map1 = new HashMap<>();
+        map1.put("id", 2);
+        map1.put("name", "张三");
+        list.add(map1);
+        Map<String, Object> map2 = new HashMap<>();
+        map2.put("id", 3);
+        map2.put("name", "张三");
+        list.add(map2);
+        Map<String, Object> map3 = new HashMap<>();
+        map3.put("id", 4);
+        map3.put("name", "张三");
+        list.add(map3);
+        List<String> idList = list.stream() // 创建流
+                .map(obj -> obj.get("id").toString())   // 提取每个元素的 ID
+                .collect(Collectors.toList());
+
+        System.out.println(idList);
+    }
+}

+ 35 - 2
alien-store/src/main/java/shop/alien/store/controller/LifeCollectController.java

@@ -6,11 +6,15 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import io.swagger.annotations.*;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.util.StringUtil;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
+import shop.alien.entity.second.SecondGoods;
 import shop.alien.entity.store.LifeCollect;
 import shop.alien.entity.store.vo.StoreInfoVo;
+import shop.alien.mapper.second.SecondGoodsMapper;
 import shop.alien.store.config.GaoDeMapUtil;
 import shop.alien.mapper.LifeCollectMapper;
 import shop.alien.mapper.StoreInfoMapper;
@@ -35,6 +39,8 @@ public class LifeCollectController {
 
     private final LifeCollectMapper lifeCollectMapper;
 
+    private final SecondGoodsMapper secondGoodsMapper;
+
     private final StoreInfoMapper storeInfoMapper;
 
     private final GaoDeMapUtil gaoDeMapUtil;
@@ -92,6 +98,13 @@ public class LifeCollectController {
         log.info("LifeCollectController.addCollect?lifeCollect={}", lifeCollect.toString());
         lifeCollect.setCreatedTime(new Date());
         int num = lifeCollectMapper.insert(lifeCollect);
+        // 二手商品收藏数量+1
+        if (StringUtil.isBlank(lifeCollect.getBusinessType()) && lifeCollect.getBusinessType().equals(1)) {
+            LambdaUpdateWrapper<SecondGoods> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
+            lambdaUpdateWrapper.eq(SecondGoods::getId, lifeCollect.getBusinessId());
+            lambdaUpdateWrapper.setSql("collect_count = collect_count + 1");
+            secondGoodsMapper.update(null, lambdaUpdateWrapper);
+        }
         if (num == 0) {
             return R.fail("收藏失败");
         }
@@ -103,13 +116,33 @@ public class LifeCollectController {
     @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id", dataType = "String", paramType = "query"),
             @ApiImplicitParam(name = "storeId", value = "storeId", dataType = "String", paramType = "query")})
     @PostMapping("cancelCollect")
-    public R<Boolean> cancelCollect(@RequestParam String userId, @RequestParam String storeId) {
+    public R<Boolean> cancelCollect(
+            @RequestParam(value = "userId", required = false) String userId,
+            @RequestParam(value = "storeId", required = false) String storeId,
+            @RequestParam(value = "businessId", required = false) String businessId,
+            @RequestParam(value = "businessType", required = false) String businessType) {
         log.info("LifeCollectController.cancelCollect?userId={},storeId={}", userId, storeId);
         LambdaUpdateWrapper<LifeCollect> wrapper = new LambdaUpdateWrapper<>();
         wrapper.eq(LifeCollect::getUserId, userId);
-        wrapper.eq(LifeCollect::getStoreId, storeId);
+        if (StringUtil.isBlank(businessType) && businessType.equals(1)) {
+            wrapper.eq(LifeCollect::getBusinessId, businessId);
+            wrapper.eq(LifeCollect::getBusinessType, businessType);
+        } else {
+            wrapper.eq(LifeCollect::getStoreId, storeId);
+        }
         wrapper.set(LifeCollect::getDeleteFlag, 1);
         int num = lifeCollectMapper.update(null, wrapper);
+        // 二手交易收藏数量-1
+        if (StringUtil.isBlank(businessType) && businessType.equals(1)) {
+            // 创建LambdaUpdateWrapper实例用于构建更新条件
+            LambdaUpdateWrapper<SecondGoods> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
+            // 设置更新条件:根据商品ID匹配且收藏数大于0
+            lambdaUpdateWrapper.eq(SecondGoods::getId, businessId).gt(SecondGoods::getCollectCount, 0);
+            // 执行SQL语句将收藏数减1
+            lambdaUpdateWrapper.setSql("collect_count = collect_count - 1");
+            secondGoodsMapper.update(null, lambdaUpdateWrapper);
+        }
+
         if (num == 0) {
             return R.fail("取消收藏失败");
         }