Procházet zdrojové kódy

bugfix:评价修改

lyx před 3 měsíci
rodič
revize
756adc0a04

+ 48 - 19
alien-store/src/main/java/shop/alien/store/controller/StoreCommentController.java

@@ -40,15 +40,15 @@ public class StoreCommentController {
             @ApiImplicitParam(name = "replyStatus", value = "回复状态(0:全部, 1:已回复, 2:未回复)", dataType = "Integer", paramType = "query"),
             @ApiImplicitParam(name = "commentLevel", value = "评论等级(0:全部, 1:好评, 2:中评, 3:差评)", dataType = "Integer", paramType = "query"),
             @ApiImplicitParam(name = "days", value = "查询时间, 多少天前", dataType = "Integer", paramType = "query"),
-            @ApiImplicitParam(name = "phoneId", value = "消息标识", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String", paramType = "query"),
             @ApiImplicitParam(name = "userType", value = "评论的用户类型(0:商家, 其他:用户)", dataType = "String", paramType = "query"),
             @ApiImplicitParam(name = "tagId", value = "标签id)", dataType = "Integer", paramType = "query"),
             @ApiImplicitParam(name = "hasImage", value = "是否有图片(0否/1是)", dataType = "Boolean", paramType = "query")
     })
     @GetMapping("/getList")
-    public R<IPage<StoreCommentVo>> getList(Integer pageNum, Integer pageSize, Integer businessId, Integer businessType, Integer storeId, Integer replyStatus, Integer commentLevel, Integer days, String phoneId, Integer userType, Integer tagId,@RequestParam(required = false, defaultValue = "false") Boolean hasImage) {
-        log.info("StoreCommentController.getList?pageNum={}&pageSize={}&businessId={}&businessType={}&storeId={}&replyStatus={}&commentLevel={}&days={}&phoneId={}&userType={}&tagId={}&hasImage={}", pageNum, pageSize, businessId, businessType, storeId, replyStatus, commentLevel, days, phoneId, userType, tagId, hasImage);
-        return R.data(storeCommentService.getList(pageNum, pageSize, businessId, businessType, storeId, replyStatus, commentLevel, days, phoneId, userType, tagId, hasImage));
+    public R<IPage<StoreCommentVo>> getList(Integer pageNum, Integer pageSize, Integer businessId, Integer businessType, Integer storeId, Integer replyStatus, Integer commentLevel, Integer days, String userId, Integer userType, Integer tagId,@RequestParam(required = false, defaultValue = "false") Boolean hasImage) {
+        log.info("StoreCommentController.getList?pageNum={}&pageSize={}&businessId={}&businessType={}&storeId={}&replyStatus={}&commentLevel={}&days={}&userId={}&userType={}&tagId={}&hasImage={}", pageNum, pageSize, businessId, businessType, storeId, replyStatus, commentLevel, days, userId, userType, tagId, hasImage);
+        return R.data(storeCommentService.getList(pageNum, pageSize, businessId, businessType, storeId, replyStatus, commentLevel, days, userId, userType, tagId, hasImage));
     }
 
     @ApiOperation("获取最新一条评论/评价")
@@ -143,27 +143,56 @@ public class StoreCommentController {
 //        log.info("StoreCommentController.saveComment?id={}&businessType={}&storeId={}&userId={}&replyId={}&commentContent={}&score={}&otherScore={}&isAnonymous={}", id, businessType, storeId, userId, replyId, commentContent, score, otherScore, isAnonymous);
 //        log.info(String.valueOf(imageUrls));
         String imageUrls = map.get("imageUrls");
-        String s = map.get("id");
-        Integer id = null;
-        if(null != s) {
-            id =  Integer.parseInt(s);
-        }
-        Integer businessType = Integer.parseInt(map.get("businessType"));
-        Integer storeId = Integer.parseInt(map.get("storeId"));
-        Integer userId = Integer.parseInt(map.get("userId"));
-        String b = map.get("replyId");
-        Integer replyId = null;
-        if(null != b) {
-            replyId =  Integer.parseInt(b);
-        }
+
+        Integer id = parseInteger(map, "id", false);
+        Integer businessType = parseInteger(map, "businessType", true);
+        Integer storeId = parseInteger(map, "storeId", true);
+        Integer userId = parseInteger(map, "userId", true);
+        Integer replyId = parseInteger(map, "replyId", false);
 
         String commentContent = map.get("commentContent");
-        Double score = Double.parseDouble(map.get("score"));
+        Double score = parseDouble(map, "score", true);
         String otherScore = map.get("otherScore");
-        Integer isAnonymous = Integer.parseInt(map.get("isAnonymous"));
+        Integer isAnonymous = parseInteger(map, "isAnonymous", true);
         return R.data(storeCommentService.saveCommentOnlyStore(imageUrls, id, businessType, storeId, userId, replyId, commentContent, score, otherScore, isAnonymous));
     }
 
+    /**
+     * 解析 Integer 类型参数,支持必填/选填,并在缺失或格式错误时抛出清晰异常。
+     */
+    private Integer parseInteger(Map<String, String> map, String key, boolean required) {
+        String value = map.get(key);
+        if (value == null || value.trim().isEmpty()) {
+            if (required) {
+                throw new IllegalArgumentException("参数[" + key + "]不能为空");
+            }
+            return null;
+        }
+        try {
+            return Integer.parseInt(value.trim());
+        } catch (NumberFormatException e) {
+            throw new IllegalArgumentException("参数[" + key + "]格式不正确,应为整数", e);
+        }
+    }
+
+    /**
+     * 解析 Double 类型参数,支持必填/选填,并在缺失或格式错误时抛出清晰异常。
+     */
+    private Double parseDouble(Map<String, String> map, String key, boolean required) {
+        String value = map.get(key);
+        if (value == null || value.trim().isEmpty()) {
+            if (required) {
+                throw new IllegalArgumentException("参数[" + key + "]不能为空");
+            }
+            return null;
+        }
+        try {
+            return Double.parseDouble(value.trim());
+        } catch (NumberFormatException e) {
+            throw new IllegalArgumentException("参数[" + key + "]格式不正确,应为数字", e);
+        }
+    }
+
     @ApiOperation(value = "回复率, 评价比例")
     @ApiImplicitParams({@ApiImplicitParam(name = "storeId", value = "门店id", dataType = "Integer", paramType = "query", required = true)})
     @GetMapping("/getCommitPercent")

+ 17 - 1
alien-store/src/main/java/shop/alien/store/service/LifeCommentService.java

@@ -8,6 +8,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.ObjectUtils;
 import org.springframework.util.StringUtils;
@@ -68,6 +69,7 @@ public class LifeCommentService {
      * @param type    点赞类型(1-评论 2-社区动态 3-活动 4-推荐菜 5-店铺打卡 6-二手商品 7-律师评分 8-点赞员工)
      * @return 更新影响的行数,0表示已点赞或操作失败
      */
+    @Transactional(rollbackFor = Exception.class)
     public int like(String userId, String huifuId, String type) {
         log.info("执行点赞操作,userId={},huifuId={},type={}", userId, huifuId, type);
         
@@ -180,6 +182,12 @@ public class LifeCommentService {
                 updateWrapper.eq(StoreStaffConfig::getId, huifuId)
                         .setSql("like_count = like_count + 1");
                 return storeStaffConfigMapper.update(null, updateWrapper);
+            } if (CommonConstant.LIKE_TYPE_STORE.equals(type)) {
+                // 类型1:评论
+                LambdaUpdateWrapper<StoreComment> updateWrapper = new LambdaUpdateWrapper<>();
+                updateWrapper.eq(StoreComment::getId, huifuId)
+                        .setSql("like_count = like_count + 1");
+                return storeCommentMapper.update(null, updateWrapper);
             } else {
                 log.warn("未知的点赞类型,type={},huifuId={}", type, huifuId);
                 return 0;
@@ -218,6 +226,7 @@ public class LifeCommentService {
      * @param type    点赞类型(1-评论 2-社区动态 3-活动 4-推荐菜 5-店铺打卡 6-二手商品 7-律师评分 8-点赞员工)
      * @return 更新影响的行数,0表示未点赞或操作失败
      */
+    @Transactional
     public int cancelLike(String userId, String huifuId, String type) {
         log.info("执行取消点赞操作,userId={},huifuId={},type={}", userId, huifuId, type);
         
@@ -331,7 +340,14 @@ public class LifeCommentService {
                 updateWrapper.eq(StoreStaffConfig::getId, Integer.parseInt(huifuId))
                         .setSql("like_count = IF(like_count > 0, like_count - 1, 0)");
                 return storeStaffConfigMapper.update(null, updateWrapper);
-            } else {
+            } else if (CommonConstant.LIKE_TYPE_STORE.equals(type)) {
+            // 类型8:点赞店铺
+                LambdaUpdateWrapper<StoreComment> updateWrapper = new LambdaUpdateWrapper<>();
+                updateWrapper.eq(StoreComment::getId, huifuId)
+                        .gt(StoreComment::getLikeCount, 0)
+                        .setSql("like_count = like_count - 1");
+                return storeCommentMapper.update(null, updateWrapper);
+        } else {
                 log.warn("未知的点赞类型,type={},huifuId={}", type, huifuId);
                 return 0;
             }

+ 2 - 2
alien-store/src/main/java/shop/alien/store/service/StoreCommentService.java

@@ -31,13 +31,13 @@ public interface StoreCommentService extends IService<StoreComment> {
      * @param replyStatus  回复状态(0:全部, 1:已回复, 2:未回复)
      * @param commentLevel 评论等级(0:全部, 1:好评, 2:中评, 3:差评)
      * @param days         查询时间, 多少天前
-     * @param phoneId      消息标识
+     * @param userId       用户id
      * @param userType     评论的用户类型(0:商家, 其他:用户)
      * @param tagId        标签id
      * @param hasImage     是否有图片(0否/1是)
      * @return IPage<StoreComment>
      */
-    IPage<StoreCommentVo> getList(Integer pageNum, Integer pageSize, Integer businessId, Integer businessType, Integer storeId, Integer replyStatus, Integer commentLevel, Integer days, String phoneId, Integer userType, Integer tagId, Boolean hasImage);
+    IPage<StoreCommentVo> getList(Integer pageNum, Integer pageSize, Integer businessId, Integer businessType, Integer storeId, Integer replyStatus, Integer commentLevel, Integer days, String userId, Integer userType, Integer tagId, Boolean hasImage);
 
     /**
      * 获取最新一条评论/评价

+ 1 - 1
alien-store/src/main/java/shop/alien/store/service/impl/StoreCommentServiceImpl.java

@@ -94,7 +94,7 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
      * @param replyStatus  回复状态(0:全部, 1:已回复, 2:未回复)
      * @param commentLevel 评论等级(0:全部, 1:好评, 2:中评, 3:差评)
      * @param days         查询时间, 多少天前
-     * @param phoneId      消息标识
+     * @param phoneId(userId)      用户id
      * @param userType     评论的用户类型(0:商家, 其他:用户)
      * @param tagId        标签id
      * @param hasImage     是否有图片(0否/1是)

+ 2 - 1
alien-store/src/main/java/shop/alien/store/util/CommonConstant.java

@@ -98,7 +98,7 @@ public class CommonConstant {
     public static final String PERFORMANCE_FREQUENCY_WEEKLY = "2";
 
     /**
-     * 点赞类型:1-评论 2-社区动态 3-活动 4-推荐菜 5-店铺打卡 6-二手商品 7-律师评分 8-点赞员工
+     * 点赞类型:1-评论 2-社区动态 3-活动 4-推荐菜 5-店铺打卡 6-二手商品 7-律师评分 8-点赞员工,9-点赞店铺
      */
     public static final String LIKE_TYPE_COMMENT = "1";
     public static final String LIKE_TYPE_DYNAMICS = "2";
@@ -108,4 +108,5 @@ public class CommonConstant {
     public static final String LIKE_TYPE_SECOND_GOODS = "6";
     public static final String LIKE_TYPE_LAWYER_SCORE = "7";
     public static final String LIKE_TYPE_STAFF = "8";
+    public static final String LIKE_TYPE_STORE = "9";
 }