|
|
@@ -1,10 +1,8 @@
|
|
|
package shop.alien.store.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
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;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
@@ -22,11 +20,8 @@ import org.springframework.web.multipart.MultipartRequest;
|
|
|
import shop.alien.entity.store.*;
|
|
|
import shop.alien.entity.store.vo.*;
|
|
|
import shop.alien.mapper.*;
|
|
|
-import shop.alien.entity.store.vo.LawyerConsultationOrderVO;
|
|
|
-import shop.alien.entity.store.vo.UserOrderVo;
|
|
|
import shop.alien.store.config.WebSocketProcess;
|
|
|
import shop.alien.store.service.StoreCommentService;
|
|
|
-import shop.alien.store.service.StoreImgService;
|
|
|
import shop.alien.store.util.FileUploadUtil;
|
|
|
import shop.alien.util.common.DateUtils;
|
|
|
import shop.alien.util.common.netease.ImageCheckUtil;
|
|
|
@@ -582,7 +577,7 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
|
|
|
*/
|
|
|
@Override
|
|
|
public Integer addComment(MultipartRequest multipartRequest, Integer id, Integer businessId, Integer businessType, Integer storeId, Integer userId, Integer replyId, String commentContent, Double score, String otherScore, Integer isAnonymous, String evaluationTags, String phoneId) {
|
|
|
- try {
|
|
|
+ /* try {
|
|
|
List<String> servicesList = Lists.newArrayList();
|
|
|
servicesList.add(TextReviewServiceEnum.COMMENT_DETECTION_PRO.getService());
|
|
|
servicesList.add(TextReviewServiceEnum.LLM_QUERY_MODERATION.getService());
|
|
|
@@ -591,10 +586,10 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
|
|
|
return 2;
|
|
|
}
|
|
|
|
|
|
- /*Map<String, String> checkText = TextCheckUtil.check(commentContent);
|
|
|
+ *//*Map<String, String> checkText = TextCheckUtil.check(commentContent);
|
|
|
if (null == checkText || checkText.get("result").equals("1")) {
|
|
|
return 2;
|
|
|
- }*/
|
|
|
+ }*//*
|
|
|
StoreComment storeComment = new StoreComment();
|
|
|
storeComment.setId(id);
|
|
|
storeComment.setStoreId(storeId);
|
|
|
@@ -704,153 +699,10 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
|
|
|
log.error("StoreCommentService.userComment ERROR Msg={}", e.getMessage());
|
|
|
return 1;
|
|
|
}
|
|
|
-
|
|
|
+*/
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 新增或修改评论/评价
|
|
|
- *
|
|
|
- * @param multipartRequest 文件
|
|
|
- * @param id 主键
|
|
|
- * @param businessId 业务id
|
|
|
- * @param businessType 业务类型(1:订单评论, 2:动态社区评论, 3:活动评论,4:店铺打卡评论)
|
|
|
- * @param storeId 门店id
|
|
|
- * @param userId 用户id
|
|
|
- * @param replyId 回复id
|
|
|
- * @param commentContent 评价内容
|
|
|
- * @param score 评分
|
|
|
- * @param otherScore 其他评分
|
|
|
- * @param isAnonymous 是否匿名(0:否(默认), 1:是)
|
|
|
- * @param evaluationTags 评价标签
|
|
|
- * @param phoneId 用户id
|
|
|
- * @return 0:成功, 1:失败, 2:文本内容异常, 3:图片内容异常
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Integer addCommentNew(MultipartRequest multipartRequest, Integer id, Integer businessId, Integer businessType, Integer storeId, Integer orderId, Integer lawyerId, Integer userId, Integer replyId, String commentContent, Double score, String otherScore, Integer isAnonymous, String evaluationTags, String phoneId) {
|
|
|
- try {
|
|
|
- List<String> servicesList = Lists.newArrayList();
|
|
|
- servicesList.add(TextReviewServiceEnum.COMMENT_DETECTION_PRO.getService());
|
|
|
- servicesList.add(TextReviewServiceEnum.LLM_QUERY_MODERATION.getService());
|
|
|
- TextModerationResultVO textCheckResult = textModerationUtil.invokeFunction(commentContent, servicesList);
|
|
|
- if ("high".equals(textCheckResult.getRiskLevel())) {
|
|
|
- return 2;
|
|
|
- }
|
|
|
-
|
|
|
- /*Map<String, String> checkText = TextCheckUtil.check(commentContent);
|
|
|
- if (null == checkText || checkText.get("result").equals("1")) {
|
|
|
- return 2;
|
|
|
- }*/
|
|
|
- StoreComment storeComment = new StoreComment();
|
|
|
- storeComment.setId(id);
|
|
|
- storeComment.setStoreId(storeId);
|
|
|
- storeComment.setUserId(userId);
|
|
|
- storeComment.setCommentContent(commentContent);
|
|
|
- storeComment.setReplyId(replyId);
|
|
|
- storeComment.setBusinessId(businessId);
|
|
|
- storeComment.setBusinessType(businessType);
|
|
|
- storeComment.setScore(score);
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(otherScore)) {
|
|
|
- List<LifeCouponVo> lifeCouponVos = JSONArray.parseArray(otherScore, LifeCouponVo.class);
|
|
|
- lifeCouponVos.stream().filter(i -> "口味".equals(i.getName())).findFirst().ifPresent(item -> storeComment.setTasteScore(Double.valueOf(item.getRateScore())));
|
|
|
- lifeCouponVos.stream().filter(i -> "环境".equals(i.getName())).findFirst().ifPresent(item -> storeComment.setEnScore(Double.valueOf(item.getRateScore())));
|
|
|
- lifeCouponVos.stream().filter(i -> "服务".equals(i.getName())).findFirst().ifPresent(item -> storeComment.setServiceScore(Double.valueOf(item.getRateScore())));
|
|
|
- }
|
|
|
- storeComment.setOtherScore(otherScore);
|
|
|
- storeComment.setIsAnonymous(isAnonymous);
|
|
|
- storeComment.setEvaluationTags(evaluationTags);
|
|
|
- storeComment.setPhoneId(phoneId);
|
|
|
- List<String> fileNameSet = new ArrayList<>(multipartRequest.getMultiFileMap().keySet());
|
|
|
- if (!fileNameSet.isEmpty() && storeId != null) {
|
|
|
- StringBuilder imgId = new StringBuilder();
|
|
|
- for (int i = 0; i < fileNameSet.size(); i++) {
|
|
|
- MultipartFile multipartFile = multipartRequest.getFileMap().get(fileNameSet.get(i));
|
|
|
- //b
|
|
|
- System.out.println(multipartFile.getSize());
|
|
|
- //kb
|
|
|
- System.out.println(multipartFile.getSize() / 1024);
|
|
|
- if (null != multipartFile && multipartFile.getSize() / 1024 > 0) {
|
|
|
- byte[] fileByte;
|
|
|
- try {
|
|
|
- fileByte = multipartFile.getBytes();
|
|
|
- } catch (IOException e) {
|
|
|
- return 1;
|
|
|
- }
|
|
|
- String base64 = Base64.getEncoder().encodeToString(fileByte);
|
|
|
- Map<String, String> checkImage = ImageCheckUtil.check(base64, 2);
|
|
|
- if (checkImage != null && checkImage.get("result").equals("1")) {
|
|
|
- return 3;
|
|
|
- }
|
|
|
- StoreImg storeImg = new StoreImg();
|
|
|
- storeImg.setStoreId(storeComment.getStoreId());
|
|
|
- storeImg.setImgType(8);
|
|
|
- storeImg.setImgSort(i + 1);
|
|
|
- storeImg.setImgUrl(fileUploadUtil.uploadOneFile(multipartFile));
|
|
|
- storeImgMapper.insert(storeImg);
|
|
|
- imgId.append(storeImg.getId()).append(",");
|
|
|
- }
|
|
|
- }
|
|
|
- if (!imgId.toString().isEmpty()) {
|
|
|
- storeComment.setImgId(imgId.substring(0, imgId.length() - 1));
|
|
|
- }
|
|
|
- }
|
|
|
- storeComment.setCreatedUserId(storeComment.getUserId());
|
|
|
- int i = this.save(storeComment) ? 0 : 1;
|
|
|
-
|
|
|
- //判断类型如果为5是评价 更新订单表orderAppraise为1 订单已评价
|
|
|
- if(businessType == 5){
|
|
|
- LambdaUpdateWrapper<LifeUserOrder> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- lambdaUpdateWrapper.eq(LifeUserOrder :: getId, businessId );
|
|
|
- lambdaUpdateWrapper.set(LifeUserOrder :: getOrderAppraise, 1);
|
|
|
- lifeUserOrderMapper.update(null,lambdaUpdateWrapper);
|
|
|
- }
|
|
|
- StoreInfoScoreVo storeInfoScoreVo = storeCommentMapper.getCommentCountAndScoreInfo(storeId);
|
|
|
- double total = storeInfoScoreVo.getTotal();
|
|
|
- double scoreAvg = (total == 0 ? 0 : storeInfoScoreVo.getScore() / total);
|
|
|
- double tasteScore = (total == 0 ? 0 : storeInfoScoreVo.getTasteScore() / total);
|
|
|
- double enScore = (total == 0 ? 0 : storeInfoScoreVo.getEnScore() / total);
|
|
|
- double serviceScore = (total == 0 ? 0 : storeInfoScoreVo.getServiceScore() / total);
|
|
|
- StoreInfo storeInfo = new StoreInfo();
|
|
|
- storeInfo.setId(storeId);
|
|
|
- storeInfo.setScoreAvg(new BigDecimal(scoreAvg).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
- storeInfo.setTasteScore(new BigDecimal(tasteScore).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
- storeInfo.setEnScore(new BigDecimal(enScore).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
- storeInfo.setServiceScore(new BigDecimal(serviceScore).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
- storeInfoMapper.updateById(storeInfo);
|
|
|
- StoreUser storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, storeInfo.getId()).eq(StoreUser::getDeleteFlag, 0));
|
|
|
-
|
|
|
- // 如果差评,则发送差评提醒
|
|
|
- if(score != null && score >= 0.5 && score <= 2.5){
|
|
|
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- String commonDate = simpleDateFormat.format(new Date());
|
|
|
- LifeNotice lifeMessage = new LifeNotice();
|
|
|
- lifeMessage.setReceiverId("store_" + storeUser.getPhone());
|
|
|
- String text = "在"+commonDate+",您的店铺有一条差评记录,您可查看评价内容是否属实,如不属实,可向平台进行申诉。";
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("message", text);
|
|
|
- lifeMessage.setContext(jsonObject.toJSONString());
|
|
|
- lifeMessage.setTitle("差评通知");
|
|
|
- lifeMessage.setSenderId("system");
|
|
|
- lifeMessage.setIsRead(0);
|
|
|
- lifeMessage.setNoticeType(1);
|
|
|
- lifeNoticeMapper.insert(lifeMessage);
|
|
|
-
|
|
|
- WebSocketVo websocketVo = new WebSocketVo();
|
|
|
- websocketVo.setSenderId("system");
|
|
|
- websocketVo.setReceiverId("store_" + storeUser.getPhone());
|
|
|
- websocketVo.setCategory("notice");
|
|
|
- websocketVo.setNoticeType("1");
|
|
|
- websocketVo.setIsRead(0);
|
|
|
- websocketVo.setText(JSONObject.from(lifeMessage).toJSONString());
|
|
|
- webSocketProcess.sendMessage("store_" + storeUser.getPhone(), JSONObject.from(websocketVo).toJSONString());
|
|
|
- }
|
|
|
- return i;
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("StoreCommentService.userComment ERROR Msg={}", e.getMessage());
|
|
|
- return 1;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 回复率, 评价比例
|
|
|
@@ -1054,7 +906,7 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
|
|
|
return new LambdaQueryWrapper<StoreComment>()
|
|
|
.eq(StoreComment::getStoreId, storeId)
|
|
|
.gt(StoreComment::getScore,0 )
|
|
|
- .eq(StoreComment::getBusinessType, 5)
|
|
|
+ .eq(StoreComment::getBusinessType, 6)
|
|
|
.eq(StoreComment::getDeleteFlag, 0);
|
|
|
}
|
|
|
|
|
|
@@ -1189,6 +1041,138 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
|
|
|
return resultPage;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Integer saveCommentOnlyStore(String imageUrls, Integer id, Integer businessType, Integer storeId, Integer userId, Integer replyId, String commentContent, Double score, String otherScore, Integer isAnonymous) {
|
|
|
+ try {
|
|
|
+ // 1.文本审核,
|
|
|
+ List<String> servicesList = Lists.newArrayList();
|
|
|
+ servicesList.add(TextReviewServiceEnum.COMMENT_DETECTION_PRO.getService());
|
|
|
+ servicesList.add(TextReviewServiceEnum.LLM_QUERY_MODERATION.getService());
|
|
|
+ TextModerationResultVO textCheckResult = textModerationUtil.invokeFunction(commentContent, servicesList);
|
|
|
+ if ("high".equals(textCheckResult.getRiskLevel())) {
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
+ // 2.构造评价实体类
|
|
|
+ StoreComment storeComment = new StoreComment();
|
|
|
+ storeComment.setId(id);
|
|
|
+ storeComment.setStoreId(storeId);
|
|
|
+ storeComment.setUserId(userId);
|
|
|
+ storeComment.setCommentContent(commentContent);
|
|
|
+ storeComment.setReplyId(replyId);
|
|
|
+ storeComment.setBusinessType(businessType);
|
|
|
+ storeComment.setScore(score);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(otherScore)) {
|
|
|
+ JSONObject parse = JSONObject.parse(otherScore);
|
|
|
+ storeComment.setScoreOne(parse.getDouble("scoreOne"));
|
|
|
+ storeComment.setScoreTwo(parse.getDouble("scoreTwo"));
|
|
|
+ storeComment.setScoreThree(parse.getDouble("scoreThree"));
|
|
|
+ }
|
|
|
+ storeComment.setOtherScore(otherScore);
|
|
|
+ storeComment.setIsAnonymous(isAnonymous);
|
|
|
+// List<String> fileNameSet = new ArrayList<>(multipartRequest.getMultiFileMap().keySet());
|
|
|
+ StringBuilder imgId = new StringBuilder();
|
|
|
+ String[] split = imageUrls.split(",");
|
|
|
+
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ StoreImg storeImg = new StoreImg();
|
|
|
+ storeImg.setStoreId(storeComment.getStoreId());
|
|
|
+ storeImg.setImgType(8);
|
|
|
+ storeImg.setImgSort(i + 1);
|
|
|
+ storeImg.setImgUrl(split[i]);
|
|
|
+ storeImgMapper.insert(storeImg);
|
|
|
+ imgId.append(storeImg.getId()).append(",");
|
|
|
+ }
|
|
|
+ if (!imgId.toString().isEmpty()) {
|
|
|
+ storeComment.setImgId(imgId.substring(0, imgId.length() - 1));
|
|
|
+ }
|
|
|
+ storeComment.setCreatedUserId(storeComment.getUserId());
|
|
|
+
|
|
|
+/* List<MultipartFile> fileNameSet = multipartRequest.getMultiFileMap().get("file");
|
|
|
+ if (!fileNameSet.isEmpty() && storeId != null) {
|
|
|
+ StringBuilder imgId = new StringBuilder();
|
|
|
+ for (int i = 0; i < fileNameSet.size(); i++) {
|
|
|
+ MultipartFile multipartFile = fileNameSet.get(i);
|
|
|
+ //b
|
|
|
+ System.out.println(multipartFile.getSize());
|
|
|
+ //kb
|
|
|
+ System.out.println(multipartFile.getSize() / 1024);
|
|
|
+ if (null != multipartFile && !multipartFile.isEmpty()) {
|
|
|
+ byte[] fileByte;
|
|
|
+ try {
|
|
|
+ fileByte = multipartFile.getBytes();
|
|
|
+ } catch (IOException e) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ String base64 = Base64.getEncoder().encodeToString(fileByte);
|
|
|
+ Map<String, String> checkImage = ImageCheckUtil.check(base64, 2);
|
|
|
+ if (checkImage != null && checkImage.get("result").equals("1")) {
|
|
|
+ return 3;
|
|
|
+ }
|
|
|
+ StoreImg storeImg = new StoreImg();
|
|
|
+ storeImg.setStoreId(storeComment.getStoreId());
|
|
|
+ storeImg.setImgType(8);
|
|
|
+ storeImg.setImgSort(i + 1);
|
|
|
+ storeImg.setImgUrl(fileUploadUtil.uploadOneFile(multipartFile));
|
|
|
+ storeImgMapper.insert(storeImg);
|
|
|
+ imgId.append(storeImg.getId()).append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!imgId.toString().isEmpty()) {
|
|
|
+ storeComment.setImgId(imgId.substring(0, imgId.length() - 1));
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ storeComment.setCreatedUserId(storeComment.getUserId());
|
|
|
+ int i = this.save(storeComment) ? 0 : 1;
|
|
|
+
|
|
|
+ // 更新门店评价信息
|
|
|
+ StoreInfoScoreVo storeInfoScoreVo = storeCommentMapper.getCommentCountAndScoreInfo(storeId);
|
|
|
+ double total = storeInfoScoreVo.getTotal();
|
|
|
+ double scoreAvg = (total == 0 ? 0 : storeInfoScoreVo.getScore() / total);
|
|
|
+ double scoreOne = (total == 0 ? 0 : storeInfoScoreVo.getScoreOne() / total);
|
|
|
+ double scoreTwo = (total == 0 ? 0 : storeInfoScoreVo.getScoreTwo() / total);
|
|
|
+ double scoreThree = (total == 0 ? 0 : storeInfoScoreVo.getScoreThree() / total);
|
|
|
+ StoreInfo storeInfo = new StoreInfo();
|
|
|
+ storeInfo.setId(storeId);
|
|
|
+ storeInfo.setScoreAvg(new BigDecimal(scoreAvg).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
+ storeInfo.setScoreOne(new BigDecimal(scoreOne).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
+ storeInfo.setScoreTwo(new BigDecimal(scoreTwo).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
+ storeInfo.setScoreThree(new BigDecimal(scoreThree).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
+ storeInfoMapper.updateById(storeInfo);
|
|
|
+ StoreUser storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, storeInfo.getId()).eq(StoreUser::getDeleteFlag, 0));
|
|
|
+
|
|
|
+ // 如果差评,则发送差评提醒
|
|
|
+ if(score != null && score >= 0.5 && score <= 2.5){
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String commonDate = simpleDateFormat.format(new Date());
|
|
|
+ LifeNotice lifeMessage = new LifeNotice();
|
|
|
+ lifeMessage.setReceiverId("store_" + storeUser.getPhone());
|
|
|
+ String text = "在"+commonDate+",您的店铺有一条差评记录,您可查看评价内容是否属实,如不属实,可向平台进行申诉。";
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("message", text);
|
|
|
+ lifeMessage.setContext(jsonObject.toJSONString());
|
|
|
+ lifeMessage.setTitle("差评通知");
|
|
|
+ lifeMessage.setSenderId("system");
|
|
|
+ lifeMessage.setIsRead(0);
|
|
|
+ lifeMessage.setNoticeType(1);
|
|
|
+ lifeNoticeMapper.insert(lifeMessage);
|
|
|
+
|
|
|
+ WebSocketVo websocketVo = new WebSocketVo();
|
|
|
+ websocketVo.setSenderId("system");
|
|
|
+ websocketVo.setReceiverId("store_" + storeUser.getPhone());
|
|
|
+ websocketVo.setCategory("notice");
|
|
|
+ websocketVo.setNoticeType("1");
|
|
|
+ websocketVo.setIsRead(0);
|
|
|
+ websocketVo.setText(JSONObject.from(lifeMessage).toJSONString());
|
|
|
+ webSocketProcess.sendMessage("store_" + storeUser.getPhone(), JSONObject.from(websocketVo).toJSONString());
|
|
|
+ }
|
|
|
+ return i;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("StoreCommentService.saveCommentOnlyStore ERROR Msg={}", e.getMessage());
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 转换商户订单为统一VO
|
|
|
*/
|