|
|
@@ -11,9 +11,11 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
+import shop.alien.entity.store.LifeMessage;
|
|
|
import shop.alien.entity.store.StoreInfo;
|
|
|
import shop.alien.entity.store.StoreRenovationRequirement;
|
|
|
import shop.alien.entity.store.dto.StoreRenovationRequirementDto;
|
|
|
+import shop.alien.mapper.LifeMessageMapper;
|
|
|
import shop.alien.mapper.StoreInfoMapper;
|
|
|
import shop.alien.mapper.StoreRenovationRequirementMapper;
|
|
|
import shop.alien.store.service.StoreRenovationRequirementService;
|
|
|
@@ -22,6 +24,7 @@ import shop.alien.util.common.JwtUtil;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -39,6 +42,7 @@ import java.util.stream.Collectors;
|
|
|
public class StoreRenovationRequirementServiceImpl extends ServiceImpl<StoreRenovationRequirementMapper, StoreRenovationRequirement> implements StoreRenovationRequirementService {
|
|
|
|
|
|
private final StoreInfoMapper storeInfoMapper;
|
|
|
+ private final LifeMessageMapper lifeMessageMapper;
|
|
|
|
|
|
@Override
|
|
|
public boolean saveOrUpdateRequirement(StoreRenovationRequirementDto dto) {
|
|
|
@@ -47,8 +51,12 @@ public class StoreRenovationRequirementServiceImpl extends ServiceImpl<StoreReno
|
|
|
StoreRenovationRequirement requirement = new StoreRenovationRequirement();
|
|
|
BeanUtils.copyProperties(dto, requirement);
|
|
|
|
|
|
- // 处理附件URL列表:List转逗号拼接字符串
|
|
|
+ // 验证附件数量:图片加视频不能超过9个
|
|
|
if (dto.getAttachmentUrls() != null && !dto.getAttachmentUrls().isEmpty()) {
|
|
|
+ if (dto.getAttachmentUrls().size() > 9) {
|
|
|
+ throw new RuntimeException("图片和视频总数不能超过9个");
|
|
|
+ }
|
|
|
+ // 处理附件URL列表:List转逗号拼接字符串
|
|
|
String attachmentUrlsStr = String.join(",", dto.getAttachmentUrls());
|
|
|
requirement.setAttachmentUrls(attachmentUrlsStr);
|
|
|
}
|
|
|
@@ -207,6 +215,55 @@ public class StoreRenovationRequirementServiceImpl extends ServiceImpl<StoreReno
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ // 检查是否已与发布商铺发生沟通
|
|
|
+ String currentUserPhone = null;
|
|
|
+ try {
|
|
|
+ com.alibaba.fastjson.JSONObject userInfo = JwtUtil.getCurrentUserInfo();
|
|
|
+ if (userInfo != null) {
|
|
|
+ currentUserPhone = userInfo.getString("phone");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.debug("获取当前用户手机号失败(用户可能未登录): {}", e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (currentUserPhone != null && StringUtils.hasText(currentUserPhone)) {
|
|
|
+ String currentUserPhoneId = "store_" + currentUserPhone;
|
|
|
+
|
|
|
+ // 批量查询沟通状态(优化:使用Map缓存结果,避免重复查询)
|
|
|
+ Map<String, Boolean> communicationStatusMap = new HashMap<>();
|
|
|
+
|
|
|
+ dtoPage.getRecords().forEach(dto -> {
|
|
|
+ String storeTel = dto.getStoreTel();
|
|
|
+ if (storeTel != null && StringUtils.hasText(storeTel)) {
|
|
|
+ String publishingShopPhoneId = "store_" + storeTel;
|
|
|
+
|
|
|
+ // 检查是否已查询过该商铺的沟通状态
|
|
|
+ String communicationKey = currentUserPhoneId + "_" + publishingShopPhoneId;
|
|
|
+ Boolean hasCommunicated = communicationStatusMap.get(communicationKey);
|
|
|
+
|
|
|
+ if (hasCommunicated == null) {
|
|
|
+ // 查询是否有消息记录(检查双向消息)
|
|
|
+ LambdaQueryWrapper<LifeMessage> messageWrapper = new LambdaQueryWrapper<>();
|
|
|
+ messageWrapper.eq(LifeMessage::getDeleteFlag, 0);
|
|
|
+ messageWrapper.and(w -> w.and(w1 -> w1.eq(LifeMessage::getSenderId, currentUserPhoneId)
|
|
|
+ .eq(LifeMessage::getReceiverId, publishingShopPhoneId))
|
|
|
+ .or(w2 -> w2.eq(LifeMessage::getSenderId, publishingShopPhoneId)
|
|
|
+ .eq(LifeMessage::getReceiverId, currentUserPhoneId)));
|
|
|
+ Integer messageCount = lifeMessageMapper.selectCount(messageWrapper);
|
|
|
+ hasCommunicated = messageCount != null && messageCount > 0;
|
|
|
+ communicationStatusMap.put(communicationKey, hasCommunicated);
|
|
|
+ }
|
|
|
+
|
|
|
+ dto.setHasCommunicated(hasCommunicated);
|
|
|
+ } else {
|
|
|
+ dto.setHasCommunicated(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 用户未登录,所有记录都设为未沟通
|
|
|
+ dtoPage.getRecords().forEach(dto -> dto.setHasCommunicated(false));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return dtoPage;
|