瀏覽代碼

商品发布业务代码初始化

wxd 1 月之前
父節點
當前提交
eb01e803df

+ 22 - 0
alien-entity/src/main/java/shop/alien/entity/second/vo/SecondGoodsVo.java

@@ -0,0 +1,22 @@
+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 java.util.List;
+
+@Data
+@JsonInclude
+@ApiModel(value = "二手商品发布", description = "发布")
+public class SecondGoodsVo extends SecondGoods {
+
+    @ApiModelProperty(value = "保存方式 0:草稿 1:发布")
+    private Integer saveType;
+
+//    @NotBlank(message = "商品图片不能为空")
+    @ApiModelProperty(value = "商品图片")
+    private List<String> imgUrl;
+}

+ 13 - 14
alien-second/src/main/java/shop/alien/second/controller/SecondGoodsController.java

@@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
 import shop.alien.entity.second.SecondGoods;
-import shop.alien.second.entity.SecondGoodsDTO;
+import shop.alien.entity.second.vo.SecondGoodsVo;
 import shop.alien.second.service.SecondGoodsService;
 
 import java.util.List;
@@ -75,20 +75,19 @@ public class SecondGoodsController {
      * 添加二手商品
      */
     @PostMapping("/save")
-    @ApiOperation("添加二手商品")
-    public R<Void> addSecondGoods(@ApiParam("二手商品信息") @RequestBody SecondGoodsDTO secondGoods) {
-        if (!secondGoodsService.createBasicInfo(secondGoods)) {
-            return R.fail("添加二手商品失败");
+    @ApiOperation("发布二手商品")
+    public R<Void> addSecondGoods(@ApiParam("二手商品信息") @RequestBody SecondGoodsVo secondGoods) {
+        if(secondGoods.getSaveType().equals(1)){
+            if (!secondGoodsService.saveAsDraft(secondGoods)) {
+                return R.fail("保存商品为草稿失败");
+            }
+            return R.success("保存商品为草稿成功");
+        } else {
+            if (!secondGoodsService.createBasicInfo(secondGoods)) {
+                return R.fail("添加二手商品失败");
+            }
+            return R.success("添加二手商品成功");
         }
-        return R.success("添加二手商品保存");
-    }
-    @PostMapping("/draft")
-    @ApiOperation("保存商品为草稿")
-    public R<Void> saveDraft(@RequestBody SecondGoods goods) {
-        if (!secondGoodsService.saveAsDraft(goods)) {
-            return R.fail("保存草稿失败");
-        }
-        return R.success("草稿已保存");
     }
 
     /**

+ 0 - 112
alien-second/src/main/java/shop/alien/second/entity/SecondGoodsDTO.java

@@ -1,112 +0,0 @@
-package shop.alien.second.entity;
-
-import com.baomidou.mybatisplus.annotation.*;
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.netease.yidun.sdk.core.validation.limitation.NotBlank;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-
-import java.math.BigDecimal;
-import java.util.Date;
-import java.util.List;
-
-@Data
-@Api
-public class SecondGoodsDTO {
-
-    @TableId(value = "id", type = IdType.AUTO)
-    @ApiModelProperty(value = "主键ID")
-    private Integer id;
-
-    @TableField("user_id")
-    @ApiModelProperty(value = "用户ID")
-    private Integer userId;
-
-    @NotBlank(message = "商品图片不能为空")
-    @ApiModelProperty(value = "商品图片")
-    private List<String> imgUrl;
-
-    @TableField("title")
-    @NotBlank(message = "商品标题不能为空")
-    @ApiModelProperty(value = "商品标题")
-    private String title;
-
-    @TableField("describe")
-    @NotBlank(message = "商品描述不能为空")
-    @ApiModelProperty(value = "商品描述")
-    private String describe;
-
-    @TableField("price")
-    @NotBlank(message = "商品价格不能为空")
-    @ApiModelProperty(value = "商品价格(元,保留小数后两位)")
-    private BigDecimal price;
-
-    @TableField("position")
-    @NotBlank(message = "商品位置不能为空")
-    @ApiModelProperty(value = "商品位置")
-    private String position;
-
-    @TableField("like_count")
-    @ApiModelProperty(value = "点赞数量")
-    private Integer likeCount;
-
-    @TableField("collect_count")
-    @ApiModelProperty(value = "收藏数量")
-    private Integer collectCount;
-
-    @TableField("category_one_id")
-    @NotBlank(message = "一级类别ID不能为空")
-    @ApiModelProperty(value = "一级类别ID")
-    private Integer categoryOneId;
-
-    @TableField("category_two_id")
-    @NotBlank(message = "二级类别ID不能为空")
-    @ApiModelProperty(value = "二级类别ID")
-    private Integer categoryTwoId;
-
-    @TableField("label")
-    @NotBlank(message = "标签不能为空")
-    @ApiModelProperty(value = "标签")
-    private String label;
-
-    @TableField("topic")
-    @NotBlank(message = "话题不能为空")
-    @ApiModelProperty(value = "话题(以逗号分隔)")
-    private String topic;
-
-    @TableField("trade_id")
-    @ApiModelProperty(value = "交易ID")
-    private Integer tradeId;
-
-    @TableField("goods_status")
-    @ApiModelProperty(value = "商品状态 0:草稿 1:审核中 2:审核失败 3:已上架 4:已下架 5:已售出")
-    private Integer goodsStatus;
-
-    @TableField("failed_reason")
-    @ApiModelProperty(value = "审核失败原因")
-    private String failedReason;
-
-    @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;
-}

+ 2 - 3
alien-second/src/main/java/shop/alien/second/service/SecondGoodsService.java

@@ -2,9 +2,8 @@ package shop.alien.second.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import org.springframework.web.multipart.MultipartFile;
 import shop.alien.entity.second.SecondGoods;
-import shop.alien.second.entity.SecondGoodsDTO;
+import shop.alien.entity.second.vo.SecondGoodsVo;
 
 /**
  * 二手商品服务接口
@@ -16,7 +15,7 @@ public interface SecondGoodsService extends IService<SecondGoods> {
      * @param goods 二手商品实体
      * @return 是否成功保存
      */
-    boolean createBasicInfo(SecondGoodsDTO goods);
+    boolean createBasicInfo(SecondGoodsVo goods);
 
     /**
      * 保存为草稿

+ 55 - 5
alien-second/src/main/java/shop/alien/second/service/impl/SecondGoodsServiceImpl.java

@@ -1,7 +1,6 @@
 package shop.alien.second.service.impl;
 
 import cn.hutool.core.collection.CollectionUtil;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.BeanUtils;
@@ -9,7 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import shop.alien.entity.second.SecondGoods;
 import shop.alien.entity.store.StoreImg;
-import shop.alien.second.entity.SecondGoodsDTO;
+import shop.alien.entity.second.vo.SecondGoodsVo;
 import shop.alien.second.mapper.SecondGoodsMapper;
 import shop.alien.second.service.SecondGoodsService;
 import shop.alien.util.common.netease.ImageCheckUtil;
@@ -48,7 +47,7 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
 
 
     @Override
-    public boolean createBasicInfo(SecondGoodsDTO goodsDTO) {
+    public boolean createBasicInfo(SecondGoodsVo goodsDTO) {
         // 实现基本信息保存逻辑
         SecondGoods goods = new SecondGoods();
         BeanUtils.copyProperties(goods, goodsDTO);
@@ -89,7 +88,7 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
      * @param goodsDTO 商品DTO信息
      * @return 审核结果
      */
-    private boolean performContentReviews(SecondGoods goods, SecondGoodsDTO goodsDTO) {
+    private boolean performContentReviews(SecondGoods goods, SecondGoodsVo goodsDTO) {
         // 文本审核
         Map<String, String> textCheckResult = TextCheckUtil.check(goodsDTO.getDescribe());
         if (!"200".equals(textCheckResult.get("code"))) {
@@ -132,6 +131,11 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
             return true; // 如果没有图片,则返回成功
         }
         for(int i = 0; i < imgUrl.size(); i++){
+            // 判断如果第一个值为视频地址,获取视频第一帧作为商品封面图
+            if (i == 0 && imgUrl.get(i).endsWith(".mp4")) {
+//                imgUrl.set(i, ImageCheckUtil.getFirstFrame(imgUrl.get(i)));
+                continue;
+            }
             StoreImg storeImg = new StoreImg();
             storeImg.setStoreId(savedGoodsId);
             storeImg.setImgType(15);
@@ -184,5 +188,51 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
 
         return goodsPage;
     }
-    
+
+    /**
+     * 判断并获取商品封面图(若第一个链接是视频,则取第一帧)
+     * @param imgUrl 商品图片/视频链接列表
+     * @return 封面图URL或处理后的图像标识
+     */
+    public String getCoverImageFromVideoOrImage(List<String> imgUrl) {
+        if (imgUrl == null || imgUrl.isEmpty()) {
+            return null;
+        }
+
+        String firstUrl = imgUrl.get(0);
+        if (isVideoUrl(firstUrl)) {
+            // 如果是视频,获取第一帧作为封面图
+            return extractFirstFrameAsCover(firstUrl);
+        } else {
+            // 否则直接返回第一个图片链接
+            return firstUrl;
+        }
+    }
+
+    /**
+     * 判断URL是否为视频地址(支持常见格式)
+     * @param url 输入URL
+     * @return 是否为视频地址
+     */
+    private boolean isVideoUrl(String url) {
+        if (url == null) return false;
+        url = url.toLowerCase();
+        return url.endsWith(".mp4") ||
+               url.endsWith(".avi") ||
+               url.endsWith(".mov") ||
+               url.endsWith(".flv") ||
+               url.endsWith(".wmv") ||
+               url.endsWith(".mkv");
+    }
+
+    /**
+     * 提取视频第一帧作为封面图(需根据实际环境实现)
+     * @param videoUrl 视频地址
+     * @return 封面图URL或Base64编码字符串
+     */
+    private String extractFirstFrameAsCover(String videoUrl) {
+        // TODO: 实现视频首帧提取逻辑,可基于FFmpeg、JavaCV等
+        // 示例返回占位符
+        return "http://example.com/covers/" + System.currentTimeMillis() + ".jpg";
+    }
 }