Browse Source

小程序修改食堂评论接口

wrh 2 years ago
parent
commit
861750e040

+ 6 - 3
nngkxxdp/src/main/java/com/example/nngkxxdp/controller/EvaluationController.java

@@ -85,11 +85,14 @@ public class EvaluationController {
      * @return
      */
     @GetMapping("/getDetailByDishesId")
-    public Map<String, Object> getDetailByDishesId(String canteenId, String dishesId) {
-        if (Blank.isEmpty(canteenId, dishesId)) {
+    public Map<String, Object> getDetailByDishesId(String canteenId, String dishesId, Integer page, Integer limit) {
+        if (Blank.isEmpty(canteenId, dishesId, page, limit)) {
             return SendUtil.send(false, ConstStr.RESULT_FAILED);
         }
-        return SendUtil.send(true, ConstStr.RESULT_SUCCESS, sEvaluationService.getDetailByDishesId(canteenId, dishesId));
+        if (page <= 0 || limit <= 0) {
+            return SendUtil.send(false, ConstStr.RESULT_FAILED);
+        }
+        return SendUtil.send(true, ConstStr.RESULT_SUCCESS, sEvaluationService.getDetailByDishesId(canteenId, dishesId,page,limit));
     }
 
     /**

+ 1 - 1
nngkxxdp/src/main/java/com/example/nngkxxdp/dao/SEvaluationDao.java

@@ -88,7 +88,7 @@ public interface SEvaluationDao {
 
     FoodGradeDo dishRating(String canteenid, String dishesId);
 
-    List<Map<String, Object>> getDetailByDishesId(@Param("canteenId") String canteenId, @Param("dishesId") String dishesId);
+    List<Map<String, Object>> getDetailByDishesId(@Param("canteenId") String canteenId, @Param("dishesId") String dishesId, @Param("count") Integer count, @Param("limit") Integer limit);
 
     Integer saveEvaluation(SEvaluation sEvaluation);
 }

+ 2 - 2
nngkxxdp/src/main/java/com/example/nngkxxdp/program/controller/CanteenMiniController.java

@@ -34,8 +34,8 @@ public class CanteenMiniController {
     }
 
     @GetMapping("/getDetailByDishesId")
-    public Map<String, Object> getDetailByDishesId(String canteenId, String dishesId) {
-        return canteenMiniService.getDetailByDishesId(canteenId, dishesId);
+    public Map<String, Object> getDetailByDishesId(String canteenId, String dishesId, Integer page, Integer limit) {
+        return canteenMiniService.getDetailByDishesId(canteenId, dishesId, page, limit);
     }
 
     /**

+ 1 - 1
nngkxxdp/src/main/java/com/example/nngkxxdp/program/service/CanteenMiniService.java

@@ -28,7 +28,7 @@ public interface CanteenMiniService {
      * @author wrh
      * @date 2022/10/26 11:35
      */
-    Map<String, Object> getDetailByDishesId(String canteenId, String dishesId);
+    Map<String, Object> getDetailByDishesId(String canteenId, String dishesId, Integer page, Integer limit);
 
     /**
      * description: 查询一天食堂的菜单

+ 8 - 2
nngkxxdp/src/main/java/com/example/nngkxxdp/program/service/Impl/CanteenMiniServiceImpl.java

@@ -82,8 +82,14 @@ public class CanteenMiniServiceImpl implements CanteenMiniService {
     }
 
     @Override
-    public Map<String, Object> getDetailByDishesId(String canteenId, String dishesId) {
-        return SendUtil.send(true, ConstMiNiStr.RESULT_SUCCESS, sEvaluationService.getDetailByDishesId(canteenId, dishesId));
+    public Map<String, Object> getDetailByDishesId(String canteenId, String dishesId, Integer page, Integer limit) {
+        if (Blank.isEmpty(canteenId, dishesId, page, limit)) {
+            return SendUtil.send(false, ConstStr.RESULT_FAILED);
+        }
+        if (page <= 0 || limit <= 0) {
+            return SendUtil.send(false, ConstStr.RESULT_FAILED);
+        }
+        return SendUtil.send(true, ConstMiNiStr.RESULT_SUCCESS, sEvaluationService.getDetailByDishesId(canteenId, dishesId, page, limit));
     }
 
     /**

+ 3 - 1
nngkxxdp/src/main/java/com/example/nngkxxdp/service/SEvaluationService.java

@@ -77,9 +77,11 @@ public interface SEvaluationService {
      * 根据菜品ID和食堂ID获取评论
      * @param canteenId
      * @param dishesId
+     * @param page
+     * @param limit
      * @return
      */
-    List<Map<String, Object>> getDetailByDishesId(String canteenId, String dishesId);
+    List<Map<String, Object>> getDetailByDishesId(String canteenId, String dishesId, Integer page, Integer limit);
 
     /**
      * 发布评价

+ 3 - 2
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/SEvaluationServiceImpl.java

@@ -125,8 +125,9 @@ public class SEvaluationServiceImpl implements SEvaluationService {
     }
 
     @Override
-    public List<Map<String, Object>> getDetailByDishesId(String canteenId, String dishesId) {
-        return sEvaluationDao.getDetailByDishesId(canteenId, dishesId);
+    public List<Map<String, Object>> getDetailByDishesId(String canteenId, String dishesId, Integer page, Integer limit) {
+        Integer count = (page - 1) * limit;
+        return sEvaluationDao.getDetailByDishesId(canteenId, dishesId, count, limit);
     }
 
     @Override

+ 1 - 0
nngkxxdp/src/main/resources/mapper/SEvaluationDao.xml

@@ -217,6 +217,7 @@
           and se.canteenId = #{canteenId}
           and se.dishesId = #{dishesId}
         order by se.create_time DESC
+        limit #{count}, #{limit}
     </select>
 
 </mapper>

+ 44 - 11
nngkxxdp/src/main/resources/static/nnzwminiapp/pages/commentList/commentList.js

@@ -19,7 +19,13 @@ Page({
 		// 点赞次数
 		compliment: '',
 		// 评论列表
-		commentList: []
+		commentList: [],
+		// 评论页数
+		page: 1,
+		// 餐厅ID
+		canteenId: '',
+		// 食品ID
+		dishesId: ''
 	},
 
 	/**
@@ -28,16 +34,11 @@ Page({
 	onLoad: function (options) {
 		this.setData({
 			commentCount: options.commentCount,
-			compliment: options.compliment
-		})
-		request({
-			url: '/mini/canteen/getDetailByDishesId?canteenId=' + options.canteenId + '&dishesId=' + options.dishesId,
-			method: 'GET'
-		}).then(res => {
-			this.setData({
-				commentList: res.data
-			})
+			compliment: options.compliment,
+			canteenId: options.canteenId,
+			dishesId: options.dishesId
 		})
+		this.getCommentById();
 	},
 	imageError(e) {
 		let temp = this.data.commentList;
@@ -46,7 +47,39 @@ Page({
 			commentList: temp
 		})
 	},
-
+	getCommentById() {
+		wx.showToast({
+			title: '加载中',
+			icon: 'loading',
+			duration: 1500
+		})
+		request({
+			url: '/mini/canteen/getDetailByDishesId?canteenId=' + this.data.canteenId + '&dishesId=' + this.data.dishesId + "&limit=10&page=" + this.data.page,
+			method: 'GET'
+		}).then(res => {
+			if (res.data.length > 0) {
+				let temp = res.data;
+				temp = this.data.commentList.concat(temp);
+				this.setData({
+					commentList: temp
+				})
+				wx.hideToast();
+			} else {
+				wx.showToast({
+					title: '已加载全部数据',
+					icon: 'success',
+					duration: 1000
+				})
+			}
+		})
+	},
+	// 触底
+	scrollBottom(e) {
+		this.setData({
+			page: this.data.page + 1
+		})
+		this.getCommentById()
+	},
 	/**
 	 * 生命周期函数--监听页面初次渲染完成
 	 */

+ 2 - 2
nngkxxdp/src/main/resources/static/nnzwminiapp/pages/commentList/commentList.wxml

@@ -1,7 +1,7 @@
 <wxs module="filter" src="./util.wxs"></wxs>
 <view>
 	<view class="top-cont">此菜品上周共获得<span>{{compliment}}</span>次点赞,获得<span>{{commentCount}}</span>次评论!</view>
-	<view class="content">
+	<scroll-view class="content" scroll-y="true" style="height: 93vh;" bindscrolltolower="scrollBottom">
 		<view wx:for="{{commentList}}" wx:key="index" class="cont-width">
 			<image class="logo" src="{{item.imgUrl ? item.imgUrl :'/pages/images/user_logo.png'}}" alt="" binderror="imageError" data-index="{{index}}"></image>
 			<view class="right">
@@ -20,5 +20,5 @@
 				</view>
 			</view>
 		</view>
-	</view>
+	</scroll-view>
 </view>

+ 1 - 0
nngkxxdp/src/main/resources/static/nnzwminiapp/pages/commentList/commentList.wxss

@@ -30,6 +30,7 @@
 .cont-width .right {
   width: 90%;
   margin-left: 15rpx;
+  margin-right: 45rpx;
 }
 
 .cont-width .right .name {