|
|
|
@ -229,7 +229,7 @@ public class PmDailyMenuDtlLikeController {
|
|
|
|
return CommonResult.failed("菜单明细不存在");
|
|
|
|
return CommonResult.failed("菜单明细不存在");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 通过PmDailyMenu 获取菜单日期
|
|
|
|
// 通过PmDailyMenu 获取菜单日期和餐别
|
|
|
|
PmDailyMenu menu = pmDailyMenuService.getById(menuDtl.getMenuId());
|
|
|
|
PmDailyMenu menu = pmDailyMenuService.getById(menuDtl.getMenuId());
|
|
|
|
if (menu == null) {
|
|
|
|
if (menu == null) {
|
|
|
|
return CommonResult.failed("菜单不存在");
|
|
|
|
return CommonResult.failed("菜单不存在");
|
|
|
|
@ -240,6 +240,11 @@ public class PmDailyMenuDtlLikeController {
|
|
|
|
return CommonResult.failed("菜单日期不存在");
|
|
|
|
return CommonResult.failed("菜单日期不存在");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String mealType = menu.getMealType();
|
|
|
|
|
|
|
|
if (StrUtil.isBlank(mealType)) {
|
|
|
|
|
|
|
|
return CommonResult.failed("餐别不存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否已经对该菜单明细进行过评价
|
|
|
|
// 检查是否已经对该菜单明细进行过评价
|
|
|
|
LambdaQueryWrapper<PmDailyMenuDtlLike> existQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
LambdaQueryWrapper<PmDailyMenuDtlLike> existQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
existQueryWrapper.eq(PmDailyMenuDtlLike::getUserId, userId);
|
|
|
|
existQueryWrapper.eq(PmDailyMenuDtlLike::getUserId, userId);
|
|
|
|
@ -252,16 +257,17 @@ public class PmDailyMenuDtlLikeController {
|
|
|
|
return CommonResult.failed("已经对该菜品进行过" + ("1".equals(likeType) ? "点赞" : "点踩"));
|
|
|
|
return CommonResult.failed("已经对该菜品进行过" + ("1".equals(likeType) ? "点赞" : "点踩"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查用户在该日期的评价次数
|
|
|
|
// 检查用户在该日期、该餐别的评价次数
|
|
|
|
LambdaQueryWrapper<PmDailyMenuDtlLike> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
LambdaQueryWrapper<PmDailyMenuDtlLike> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
queryWrapper.eq(PmDailyMenuDtlLike::getUserId, userId);
|
|
|
|
queryWrapper.eq(PmDailyMenuDtlLike::getUserId, userId);
|
|
|
|
queryWrapper.eq(PmDailyMenuDtlLike::getMenuDate, menuDate);
|
|
|
|
queryWrapper.eq(PmDailyMenuDtlLike::getMenuDate, menuDate);
|
|
|
|
|
|
|
|
queryWrapper.eq(PmDailyMenuDtlLike::getMealType, mealType);
|
|
|
|
queryWrapper.eq(PmDailyMenuDtlLike::getLikeType, likeType);
|
|
|
|
queryWrapper.eq(PmDailyMenuDtlLike::getLikeType, likeType);
|
|
|
|
queryWrapper.eq(PmDailyMenuDtlLike::getDelFlag, "0");
|
|
|
|
queryWrapper.eq(PmDailyMenuDtlLike::getDelFlag, "0");
|
|
|
|
|
|
|
|
|
|
|
|
int count = pmDailyMenuDtlLikeService.count(queryWrapper);
|
|
|
|
int count = pmDailyMenuDtlLikeService.count(queryWrapper);
|
|
|
|
if (count >= 3) {
|
|
|
|
if (count >= 3) {
|
|
|
|
return CommonResult.failed("同一日期内" + ("1".equals(likeType) ? "点赞" : "点踩") + "次数已达上限(3次)");
|
|
|
|
return CommonResult.failed("同一日期同一餐别内" + ("1".equals(likeType) ? "点赞" : "点踩") + "次数已达上限(3次)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 保存点赞/点踩记录
|
|
|
|
// 保存点赞/点踩记录
|
|
|
|
@ -269,6 +275,7 @@ public class PmDailyMenuDtlLikeController {
|
|
|
|
like.setMenuDtlId(menuDtlId);
|
|
|
|
like.setMenuDtlId(menuDtlId);
|
|
|
|
like.setUserId(userId);
|
|
|
|
like.setUserId(userId);
|
|
|
|
like.setMenuDate(menuDate);
|
|
|
|
like.setMenuDate(menuDate);
|
|
|
|
|
|
|
|
like.setMealType(mealType);
|
|
|
|
like.setLikeType(likeType);
|
|
|
|
like.setLikeType(likeType);
|
|
|
|
like.setRemark(remark);
|
|
|
|
like.setRemark(remark);
|
|
|
|
like.setDelFlag("0");
|
|
|
|
like.setDelFlag("0");
|
|
|
|
@ -454,33 +461,32 @@ public class PmDailyMenuDtlLikeController {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 计算总记录数
|
|
|
|
// 分页处理
|
|
|
|
int total = rankingList.size();
|
|
|
|
int total = rankingList.size();
|
|
|
|
|
|
|
|
int fromIndex = (page - 1) * limit;
|
|
|
|
// 实现真正的分页
|
|
|
|
int toIndex = Math.min(fromIndex + limit, total);
|
|
|
|
int startIndex = (page - 1) * limit;
|
|
|
|
|
|
|
|
int endIndex = Math.min(startIndex + limit, total);
|
|
|
|
if (fromIndex >= total) {
|
|
|
|
List<PmDailyMenuDtlLike> pageList;
|
|
|
|
// 如果起始索引超出范围,返回空列表
|
|
|
|
if (startIndex >= total) {
|
|
|
|
CommonPage<PmDailyMenuDtlLike> emptyPage = new CommonPage<>();
|
|
|
|
pageList = new ArrayList<>();
|
|
|
|
emptyPage.setList(new ArrayList<>());
|
|
|
|
} else {
|
|
|
|
emptyPage.setTotal((long) total);
|
|
|
|
pageList = rankingList.subList(startIndex, endIndex);
|
|
|
|
emptyPage.setPage(page);
|
|
|
|
}
|
|
|
|
emptyPage.setLimit(limit);
|
|
|
|
|
|
|
|
return CommonResult.success(emptyPage);
|
|
|
|
// 构建分页对象
|
|
|
|
}
|
|
|
|
CommonPage<PmDailyMenuDtlLike> pageResult = new CommonPage<>();
|
|
|
|
|
|
|
|
pageResult.setList(pageList);
|
|
|
|
List<PmDailyMenuDtlLike> pageList = rankingList.subList(fromIndex, toIndex);
|
|
|
|
pageResult.setTotal((long) total);
|
|
|
|
CommonPage<PmDailyMenuDtlLike> resultPage = new CommonPage<>();
|
|
|
|
pageResult.setPage(page);
|
|
|
|
resultPage.setList(pageList);
|
|
|
|
pageResult.setLimit(limit);
|
|
|
|
resultPage.setTotal((long) total);
|
|
|
|
|
|
|
|
resultPage.setPage(page);
|
|
|
|
return CommonResult.success(pageResult);
|
|
|
|
resultPage.setLimit(limit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return CommonResult.success(resultPage);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
return CommonResult.failed("查询失败:" + e.getMessage());
|
|
|
|
return CommonResult.failed("查询失败:" + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|