Browse Source

我的交易列表接口

wxd 3 weeks ago
parent
commit
9d3951b543

+ 117 - 0
alien-entity/src/main/java/shop/alien/entity/second/vo/SellGoodsVo.java

@@ -0,0 +1,117 @@
+package shop.alien.entity.second.vo;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import shop.alien.entity.second.SecondGoods;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+@Data
+@JsonInclude
+@ApiModel(value = "二手商品发布", description = "发布")
+public class SellGoodsVo extends SecondGoods {
+
+    @ApiModelProperty(value = "保存方式 0:草稿 1:发布")
+    private Integer saveType;
+
+    @ApiModelProperty(value = "商品距离")
+    private String distance;
+
+    @TableField(exist = false)
+    @ApiModelProperty(value = "用户名称")
+    private String userName;
+
+    @TableField(exist = false)
+    @ApiModelProperty(value = "用户真名")
+    private String realName;
+
+    @TableField(exist = false)
+    @ApiModelProperty(value = "用户电话")
+    private String userPhone;
+
+    @TableField(exist = false)
+    @ApiModelProperty(value = "用户头像")
+    private String userImage;
+
+    @TableField(exist = false)
+    @ApiModelProperty(value = "收藏状态 默认为 0")
+    private Integer collectStatus = 0;
+
+    @TableField(exist = false)
+    @ApiModelProperty(value = "点赞状态 默认为 0")
+    private Integer likeStatus = 0;
+
+    @ApiModelProperty("一级分类名称")
+    @TableField(exist = false)
+    private String categoryOneName;
+
+    @ApiModelProperty("二级分类名称")
+    @TableField(exist = false)
+    private String categoryTwoName;
+
+    /** -------------------- 搜索入参 -------------------- */
+
+    @TableField(exist = false)
+    @ApiModelProperty(value = "当前页码")
+    private Integer pageNum = 1;
+
+    @ApiModelProperty(value = "每页数量")
+    private Integer pageSize = 10;
+
+    @ApiModelProperty(value = "当前经度")
+    private Double currentLatitude;
+
+    @ApiModelProperty(value = "当前纬度")
+    private Double currentLongitude;
+
+
+
+    @ApiModelProperty(value = "买家id")
+    private Integer buyerId;
+
+    @ApiModelProperty(value = "卖家id")
+    private Integer sellerId;
+
+    @ApiModelProperty(value = "交易时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date transactionTime;
+
+    @ApiModelProperty(value = "交易地点(经纬度)")
+    private String transactionLatitudeLongitude;
+
+    @ApiModelProperty(value = "交易地点(详细地址)")
+    private String transactionLocation;
+
+    @ApiModelProperty(value = "交易金额")
+    private BigDecimal transactionAmount;
+
+    @ApiModelProperty(value = "买家交易状态  1-交易成功  2-交易失败")
+    private Integer buyerTransactionStatus;
+
+    @ApiModelProperty(value = "卖家交易状态  1-交易成功  2-交易失败")
+    private Integer sellerTransactionStatus;
+
+    @ApiModelProperty(value = "交易状态  0-待交易  1-交易成功  2-交易失败  3-交易取消")
+    private Integer tradeStatus;
+
+    @ApiModelProperty(value = "买家评价")
+    private String buyerEvaluate;
+
+    @ApiModelProperty(value = "卖家评价")
+    private String sellerEvaluate;
+
+    @ApiModelProperty(value = "交易对方的用户ID")
+    private Integer otherPartyId;
+
+
+}

+ 32 - 0
alien-entity/src/main/java/shop/alien/mapper/second/SecondGoodsMapper.java

@@ -10,6 +10,7 @@ import org.apache.ibatis.annotations.Select;
 import shop.alien.entity.second.SecondGoods;
 import shop.alien.entity.second.SecondShield;
 import shop.alien.entity.second.vo.SecondGoodsVo;
+import shop.alien.entity.second.vo.SellGoodsVo;
 import shop.alien.entity.store.StoreInfo;
 
 import java.util.List;
@@ -245,4 +246,35 @@ public interface SecondGoodsMapper extends BaseMapper<SecondGoods> {
             "on sg.category_two_id = sgc2.id "+
             "${ew.customSqlSegment}")
     IPage<SecondGoodsVo> getLikeGoodsPage(IPage<SecondGoodsVo> page,  @Param(Constants.WRAPPER) QueryWrapper<SecondGoodsVo> queryWrapper);
+
+    /**
+     * 获取用户交易中的商品列表
+     * @param page 分页参数
+     * @param queryWrapper 查询条件
+     * @return 交易中的商品列表
+     */
+    @Select("SELECT " +
+            "str.goods_id, " +
+            "    str.buyer_id, " +
+            "    str.seller_id, " +
+            "    str.transaction_time, " +
+            "    str.transaction_latitude_longitude, " +
+            "    str.transaction_location, " +
+            "    str.transaction_amount, " +
+            "    str.buyer_signin, " +
+            "    str.seller_signin, " +
+            "    str.buyer_transaction_status, " +
+            "    str.seller_transaction_status, " +
+            "    str.trade_status, " +
+            "    str.buyer_evaluate, " +
+            "    str.seller_evaluate,"+
+            "sg.*, " +
+            "    CASE " +
+            "        WHEN str.buyer_id = #{userId} THEN str.seller_id " +
+            "        ELSE str.buyer_id " +
+            "    END AS other_party_id " +
+            "FROM second_trade_record str " +
+            "LEFT JOIN second_goods sg ON str.goods_id = sg.id "+
+            "${ew.customSqlSegment}")
+    IPage<SellGoodsVo> getTransactionList(IPage<SellGoodsVo> page, @Param("userId") Integer userId, @Param(Constants.WRAPPER) QueryWrapper<SellGoodsVo> queryWrapper);
 }

+ 16 - 12
alien-second/src/main/java/shop/alien/second/controller/UserGoodsController.java

@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
 import shop.alien.entity.second.SecondGoods;
 import shop.alien.entity.second.vo.SecondGoodsVo;
+import shop.alien.entity.second.vo.SellGoodsVo;
 import shop.alien.second.service.SecondGoodsService;
 import shop.alien.util.common.JwtUtil;
 
@@ -200,23 +201,26 @@ public class UserGoodsController {
         return result;
     }
 
-
     /**
-     * 我的 - 交易列表
-     * 我卖出的商品列表-分页
+     * 我的- 交易列表
      */
-    @GetMapping("/getSellGoodsPage")
-    @ApiOperation("根据商品状态获取商品列表 - 0:草稿(我的草稿列表) 1:审核中 2:审核失败 3:已上架 4:已下架 5:已售出(我卖出的商品列表) -分页")
-    public R<IPage<SecondGoodsVo>> getSellGoodsPage(
-            @ApiParam("分页参数") @RequestBody SecondGoodsVo secondGoodsVo) {
-        log.info("SecondGoodsController.getSellGoodsPage?secondGoodsVo={}", secondGoodsVo.toString());
-        R<IPage<SecondGoodsVo>> result = new R<>();
-        IPage<SecondGoodsVo> page = new Page<>(secondGoodsVo.getPageNum(), secondGoodsVo.getPageSize());
+    @GetMapping("/getTransactionList")
+    @ApiOperation("我的- 交易列表")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "pageNum", value = "分页页数", dataType = "Integer", paramType = "query", required = true),
+            @ApiImplicitParam(name = "pageSize", value = "分页条数", dataType = "Integer", paramType = "query", required = true)})
+    public R<IPage<SellGoodsVo>> getTransactionList(
+            @RequestParam(defaultValue = "1") Integer pageNum,
+            @RequestParam(defaultValue = "10") Integer pageSize) {
+        log.info("SecondGoodsController.getTransactionList?page={},size={},", pageNum,pageSize);
+        IPage<SellGoodsVo> page = new Page<>(pageNum, pageSize);
+        R<IPage<SellGoodsVo>> result = new R<>();
         JSONObject data = JwtUtil.getCurrentUserInfo();
         if (null != data) {
-            int userId = data.getInteger("userId");
-            result = R.data(secondGoodsService.getSellGoodsPage(page,secondGoodsVo,userId));
+            Integer userId = data.getInteger("userId");
+            result = R.data(secondGoodsService.getTransactionList(page,userId));
         }
         return result;
     }
+
 }

+ 9 - 0
alien-second/src/main/java/shop/alien/second/service/SecondGoodsService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import shop.alien.entity.second.SecondGoods;
 import shop.alien.entity.second.vo.SecondGoodsVo;
+import shop.alien.entity.second.vo.SellGoodsVo;
 
 import java.util.List;
 
@@ -135,4 +136,12 @@ public interface SecondGoodsService extends IService<SecondGoods> {
      * @return 分页后的商品点赞商品列表
      */
     IPage<SecondGoodsVo> getLikeGoodsPage(IPage<SecondGoodsVo> page, int userId, String phone);
+
+    /**
+     * 获取商品交易列表(分页)
+     * @param page 搜索条件
+     * @param userId 用户ID
+     * @return 分页后的商品交易列表
+     */
+    IPage<SellGoodsVo> getTransactionList(IPage<SellGoodsVo> page, Integer userId);
 }

+ 77 - 26
alien-second/src/main/java/shop/alien/second/service/impl/SecondGoodsServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
 import org.apache.ibatis.annotations.Param;
@@ -12,6 +13,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 import shop.alien.entity.second.SecondGoods;
 import shop.alien.entity.second.vo.SecondGoodsVo;
+import shop.alien.entity.second.vo.SellGoodsVo;
 import shop.alien.entity.store.*;
 import shop.alien.entity.store.vo.LifeUserVo;
 import shop.alien.mapper.*;
@@ -573,6 +575,27 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
     }
 
     /**
+     * 获取交易列表
+     * @param page 分页参数
+     * @param userId 用户ID
+     * @return IPage<SecondGoodsVo> 交易列表
+     */
+    @Override
+    public IPage<SellGoodsVo> getTransactionList(IPage<SellGoodsVo> page, Integer userId) {
+        IPage<SellGoodsVo> result = new Page<>();
+        QueryWrapper<SellGoodsVo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("sg.delete_flag", 0)
+                .eq("str.delete_flag", 0)
+                .and(wrapper -> wrapper.eq("str.buyer_id", userId)
+                        .or()
+                        .eq("str.seller_id", userId));
+        result = secondGoodsMapper.getTransactionList(page, userId, queryWrapper);
+        // 批量设置用户信息
+        batchSetSellUserInfo(result);
+        return result;
+    }
+
+    /**
      * 查询搜索结果
      * @param page 分页参数
      * @param secondGoodsVo 查询参数
@@ -628,40 +651,35 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
     }
 
     /**
-     * 批量设置用户信息
+     * 批量设置用户信息(用于SecondGoodsVo列表)
      * @param searchGoodsList 搜索结果
      */
     private void batchSetUserInfo(IPage<SecondGoodsVo> searchGoodsList) {
-        // 批量获取用户信息(头像,用户姓名,用户id)
-        if (CollectionUtil.isNotEmpty(searchGoodsList.getRecords())) {
-            List<Integer> userIds = searchGoodsList.getRecords().stream()
-                    .map(SecondGoodsVo::getUserId)
-                    .collect(Collectors.toList());
-                    // 批量获取用户信息
-                    QueryWrapper<LifeUserVo> queryWrapper = new QueryWrapper<>();
-                    queryWrapper.in("id", userIds); // 使用字符串 "user_id" 直接指定数据库列名
-                    queryWrapper.in("delete_flag", 0);
-                    List<LifeUserVo> userInfoList = lifeUserMapper.getUserByIds(queryWrapper);
-                    // 根据用户id进行分组 返回map
-                    Map<Integer, LifeUserVo> userInfoMap = userInfoList.stream()
-                            .collect(Collectors.toMap(LifeUserVo::getId, lifeUserVo -> lifeUserVo));
-                    // 获取用户信息
-                    for (SecondGoodsVo goods : searchGoodsList.getRecords()) {
-                        LifeUserVo userInfo = userInfoMap.get(goods.getUserId());
-                        if (userInfo != null){
-                            // 用户名称
+        batchSetUserInfo(searchGoodsList, 
+                        SecondGoodsVo::getUserId,
+                        (goods, userInfo) -> {
                             goods.setUserName(userInfo.getUserName());
-                            // 用户真实姓名
                             goods.setRealName(userInfo.getRealName());
-                            // 用户头像
                             goods.setUserImage(userInfo.getUserImage());
-                            // 用户id
                             goods.setUserId(userInfo.getId());
-                            // 用户手机号
                             goods.setUserPhone(userInfo.getUserPhone());
-                        }
-                    }
-        }
+                        });
+    }
+    
+    /**
+     * 批量设置用户信息(用于SellGoodsVo列表)
+     * @param sellGoodsList 搜索结果
+     */
+    private void batchSetSellUserInfo(IPage<SellGoodsVo> sellGoodsList) {
+        batchSetUserInfo(sellGoodsList, 
+                        SellGoodsVo::getUserId,
+                        (goods, userInfo) -> {
+                            goods.setUserName(userInfo.getUserName());
+                            goods.setRealName(userInfo.getRealName());
+                            goods.setUserImage(userInfo.getUserImage());
+                            goods.setUserId(userInfo.getId());
+                            goods.setUserPhone(userInfo.getUserPhone());
+                        });
     }
 
     /**
@@ -696,4 +714,37 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
                     }
         }
     }
+
+
+    /**
+     * 批量设置用户信息
+     * @param <T> 任意商品VO类型
+     * @param goodsList 商品列表
+     * @param userIdMapper 从商品VO获取用户ID的函数
+     * @param userSetter 从用户信息设置到商品VO的函数
+     */
+    private <T> void batchSetUserInfo(IPage<T> goodsList,
+                                      java.util.function.Function<T, Integer> userIdMapper,
+                                      java.util.function.BiConsumer<T, LifeUserVo> userSetter) {
+        if (CollectionUtil.isNotEmpty(goodsList.getRecords())) {
+            List<Integer> userIds = goodsList.getRecords().stream()
+                    .map(userIdMapper)
+                    .collect(Collectors.toList());
+
+            QueryWrapper<LifeUserVo> queryWrapper = new QueryWrapper<>();
+            queryWrapper.in("id", userIds)
+                    .eq("delete_flag", 0);
+
+            List<LifeUserVo> userInfoList = lifeUserMapper.getUserByIds(queryWrapper);
+            Map<Integer, LifeUserVo> userInfoMap = userInfoList.stream()
+                    .collect(Collectors.toMap(LifeUserVo::getId, lifeUserVo -> lifeUserVo));
+
+            for (T goods : goodsList.getRecords()) {
+                LifeUserVo userInfo = userInfoMap.get(userIdMapper.apply(goods));
+                if (userInfo != null && userSetter != null) {
+                    userSetter.accept(goods, userInfo);
+                }
+            }
+        }
+    }
 }