|
@@ -1,6 +1,7 @@
|
|
|
package shop.alien.second.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -13,11 +14,13 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import shop.alien.entity.second.SecondGoods;
|
|
|
+import shop.alien.entity.second.SecondGoodsAudit;
|
|
|
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.*;
|
|
|
+import shop.alien.mapper.second.SecondGoodsAuditMapper;
|
|
|
import shop.alien.mapper.second.SecondGoodsMapper;
|
|
|
import shop.alien.second.service.SecondGoodsService;
|
|
|
import shop.alien.util.common.VideoUtils;
|
|
@@ -56,6 +59,11 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
private final SecondGoodsMapper secondGoodsMapper;
|
|
|
|
|
|
/**
|
|
|
+ * 二手商品审核Mapper
|
|
|
+ */
|
|
|
+ private final SecondGoodsAuditMapper secondGoodsAuditMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
* 用户信息Mapper
|
|
|
*/
|
|
|
private final LifeUserMapper lifeUserMapper;
|
|
@@ -111,60 +119,54 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
|
|
|
@Override
|
|
|
public boolean createBasicInfo(SecondGoodsVo goodsDTO,Integer editFlag) throws Exception {
|
|
|
- // 实现基本信息保存逻辑
|
|
|
- SecondGoods goods = new SecondGoods();
|
|
|
- BeanUtils.copyProperties(goodsDTO, goods);
|
|
|
-
|
|
|
- if (editFlag == 1){
|
|
|
- goods.setId(goodsDTO.getId());
|
|
|
- // 保存商品基本信息
|
|
|
- if (!updateById(goods)) {
|
|
|
- return false; // 保存失败直接返回
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 保存商品基本信息
|
|
|
- if (!save(goods)) {
|
|
|
- return false; // 保存失败直接返回
|
|
|
+ try {
|
|
|
+ // 实现基本信息保存逻辑
|
|
|
+ SecondGoods goods = new SecondGoods();
|
|
|
+ BeanUtils.copyProperties(goodsDTO, goods);
|
|
|
+
|
|
|
+ if (editFlag == 1) {
|
|
|
+ goods.setId(goodsDTO.getId());
|
|
|
+ goods = secondGoodsMapper.selectById(goodsDTO.getId());
|
|
|
+ // 保存商品基本信息
|
|
|
+ if (!updateById(goods)) {
|
|
|
+ return false; // 保存失败直接返回
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 保存商品基本信息
|
|
|
+ if (!save(goods)) {
|
|
|
+ return false; // 保存失败直接返回
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 获取保存后的商品ID,用于后续业务处理
|
|
|
- Integer savedGoodsId = goods.getId();
|
|
|
- if (savedGoodsId == null) {
|
|
|
- return false; // 如果获取不到ID,视为操作失败
|
|
|
- }
|
|
|
-
|
|
|
- // 保存商品图片信息
|
|
|
- if (!saveStoreImages(savedGoodsId, goodsDTO.getImgUrl())) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- // 二手业务安全验证(调取阿里)
|
|
|
- if (!checkSafety(goods)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 获取保存后的商品ID,用于后续业务处理
|
|
|
+ Integer savedGoodsId = goods.getId();
|
|
|
+ if (savedGoodsId == null) {
|
|
|
+ return false; // 如果获取不到ID,视为操作失败
|
|
|
+ }
|
|
|
|
|
|
- // 执行内容审核(图片和文本)
|
|
|
- if (!performContentReviews(goods, goodsDTO)) {
|
|
|
- return true; // 审核不通过时已设置状态,返回成功但标记为审核失败
|
|
|
- }
|
|
|
+ // 保存商品图片信息
|
|
|
+ if (!saveStoreImages(savedGoodsId, goodsDTO.getImgUrl())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // 如果所有审核都通过,设置为上架状态
|
|
|
- goods.setGoodsStatus(3); // 上架
|
|
|
- goods.setReleaseTime(new Date()); // 上架时间
|
|
|
- updateById(goods);
|
|
|
+ // 执行内容审核(图片和文本)
|
|
|
+ if (!performContentReviews(goods, goodsDTO)) {
|
|
|
+ return true; // 审核不通过时已设置状态,返回成功但标记为审核失败
|
|
|
+ }
|
|
|
|
|
|
- // 发送消息
|
|
|
- sendMessage(goods);
|
|
|
- return true;
|
|
|
- }
|
|
|
+ // 如果所有审核都通过,设置为上架状态
|
|
|
+ goods.setGoodsStatus(3); // 上架
|
|
|
+ goods.setReleaseTime(new Date()); // 上架时间
|
|
|
+ updateById(goods);
|
|
|
|
|
|
- /**
|
|
|
- * 二手业务安全验证 (调取阿里)
|
|
|
- * @param goods 商品信息
|
|
|
- * @return 验证结果
|
|
|
- */
|
|
|
- private boolean checkSafety(SecondGoods goods) {
|
|
|
- return true;
|
|
|
+ // 发送消息
|
|
|
+ sendMessage(goods);
|
|
|
+ return true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 记录异常日志
|
|
|
+ log.error("创建或更新二手商品基本信息时发生异常", e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
/**
|
|
|
* 执行内容审核(图片和文本)
|
|
@@ -183,6 +185,10 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
// 文本审核不通过或存在高风险
|
|
|
goods.setGoodsStatus(2); // 审核失败
|
|
|
goods.setFailedReason("文本审核不通过:" + (textCheckResult.getRiskWords() != null ? textCheckResult.getRiskWords() : "存在高风险内容"));
|
|
|
+ // 插入审核记录
|
|
|
+ createGoodsAudit(goods, textCheckResult.getRiskWords());
|
|
|
+ // 发送审核失败消息
|
|
|
+ sendFailedMsg(goods);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -196,6 +202,10 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
// 文本审核不通过或存在高风险
|
|
|
goods.setGoodsStatus(2); // 审核失败
|
|
|
goods.setFailedReason("图片审核不通过:图片中包含" + (response.getDescriptions() != null ? response.getDescriptions() : "高风险内容"));
|
|
|
+ // 插入审核记录
|
|
|
+ createGoodsAudit(goods, response.getDescriptions());
|
|
|
+ // 发送审核失败消息
|
|
|
+ sendFailedMsg(goods);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -208,6 +218,27 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 创建商品审核记录
|
|
|
+ *
|
|
|
+ * @param goods 商品
|
|
|
+ * @param riskWords 文本审核结果
|
|
|
+ */
|
|
|
+ private void createGoodsAudit(SecondGoods goods, String riskWords) {
|
|
|
+ // 保存审核结果
|
|
|
+ secondGoodsMapper.updateById(goods);
|
|
|
+ // 插入审核记录
|
|
|
+ SecondGoodsAudit auditRecord = new SecondGoodsAudit();
|
|
|
+ auditRecord.setGoodsId(goods.getId());
|
|
|
+ auditRecord.setGoodsStatus(2); // 审核失败
|
|
|
+ auditRecord.setFailedReason("文本审核不通过:" + (riskWords != null ? riskWords : "存在高风险内容"));
|
|
|
+ auditRecord.setCreatedUserId(goods.getUserId());
|
|
|
+ auditRecord.setUpdatedUserId(goods.getUserId());
|
|
|
+ auditRecord.setCreatedTime(new Date());
|
|
|
+ auditRecord.setUpdatedTime(new Date());
|
|
|
+ secondGoodsAuditMapper.insert(auditRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 保存商品图片信息
|
|
|
* @param savedGoodsId 保存后的商品ID
|
|
|
* @param imgUrl 图片URL列表
|
|
@@ -261,12 +292,36 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
lifeNotice.setReceiverId("user_"+ phone);
|
|
|
lifeNotice.setBusinessId(goods.getId());
|
|
|
lifeNotice.setTitle("商品发布通知");
|
|
|
- lifeNotice.setContext("您有一笔新的二手商品发布成功,请及时查看");
|
|
|
+ lifeNotice.setContext("恭喜您的商品已发成功");
|
|
|
lifeNotice.setNoticeType(1); // 系统通知
|
|
|
lifeNotice.setIsRead(0);
|
|
|
lifeNoticeMapper.insert(lifeNotice);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送审核失败消息
|
|
|
+ * @param goods 商品审核信息
|
|
|
+ */
|
|
|
+ private void sendFailedMsg(SecondGoods goods) {
|
|
|
+ // 根据 goods.getUserId() 获取用户信息
|
|
|
+ LifeUser lifeUser = lifeUserMapper.selectById(goods.getUserId());
|
|
|
+ String phone = lifeUser.getUserPhone();
|
|
|
+ // 调取feign接口 发送消息 life_notice表
|
|
|
+ LifeNotice lifeNotice = new LifeNotice();
|
|
|
+ lifeNotice.setSenderId("system");
|
|
|
+ lifeNotice.setReceiverId("user_"+ phone);
|
|
|
+ lifeNotice.setBusinessId(goods.getId());
|
|
|
+ lifeNotice.setTitle("商品审核通知");
|
|
|
+ // TODO: 失败原因本期为固定文案,实际原因暂不保存
|
|
|
+// lifeNotice.setContext("商品审核失败,原因为:" + goods.getFailedReason());
|
|
|
+ lifeNotice.setContext("抱歉您的商品发布失败,图片或文字存在违规行为。请您修改后从新发布");
|
|
|
+ lifeNotice.setNoticeType(1); // 系统通知
|
|
|
+ lifeNotice.setIsRead(0);
|
|
|
+ lifeNoticeMapper.insert(lifeNotice);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 判断并获取商品封面图(若第一个链接是视频,则取第一帧)
|
|
|
* @param imgUrl 商品图片/视频链接列表
|
|
@@ -609,6 +664,23 @@ public class SecondGoodsServiceImpl extends ServiceImpl<SecondGoodsMapper, Secon
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<SecondGoods> getGoodsListByUserId(Integer userId, Integer goodsStatus) {
|
|
|
+ // 获取商品屏蔽列表
|
|
|
+ List<SecondGoods> shieldedGoodsList = getShieldedGoodsList(userId);
|
|
|
+ // 提取屏蔽商品ID
|
|
|
+ List<Integer> shieldedGoodsIds = shieldedGoodsList.stream()
|
|
|
+ .map(SecondGoods::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<SecondGoods> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(SecondGoods::getUserId, userId);
|
|
|
+ queryWrapper.eq(SecondGoods::getGoodsStatus, goodsStatus);
|
|
|
+ queryWrapper.notIn(CollectionUtil.isNotEmpty(shieldedGoodsIds), SecondGoods::getId, shieldedGoodsIds);
|
|
|
+ queryWrapper.orderByDesc(SecondGoods::getReleaseTime);
|
|
|
+ return secondGoodsMapper.selectList(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询搜索结果
|
|
|
* @param page 分页参数
|