|
|
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.ruoyi.app.utils.DateUtil;
|
|
|
import com.ruoyi.common.annotation.Anonymous;
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
@@ -56,6 +57,8 @@ public class UserAppIndexController extends BaseController {
|
|
|
private PosFoodMapper posFoodMapper;
|
|
|
@Autowired
|
|
|
private IInfoUserService infoUserService;
|
|
|
+ @Autowired
|
|
|
+ private IOperatingHoursService operatingHoursService;
|
|
|
|
|
|
/**
|
|
|
* 获取夜市列表
|
|
|
@@ -100,34 +103,54 @@ public class UserAppIndexController extends BaseController {
|
|
|
if ("en-US".equals(language)) {
|
|
|
lang = "1";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 收集所有门店ID(Integer类型)
|
|
|
List<Integer> storeIds = storeList.stream()
|
|
|
.map(PosStore::getId)
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
+
|
|
|
// 使用MyBatis Plus一次性查询所有门店的商品(避免N+1查询问题)
|
|
|
Map<Integer, List<PosFood>> foodMap = new java.util.HashMap<>();
|
|
|
+ List<OperatingHours> hourslist=new ArrayList<>();
|
|
|
if (!storeIds.isEmpty()) {
|
|
|
// 将Integer类型的门店ID转换为Long类型用于查询(因为mdid是Long类型)
|
|
|
List<Long> storeIdsLong = storeIds.stream()
|
|
|
.map(Integer::longValue)
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
+
|
|
|
// 使用MyBatis Plus的Mapper方法,在数据库查询时就限制每个门店只返回6条商品
|
|
|
List<PosFood> allFoods = posFoodMapper.selectFoodsByStoreIdsWithLimit(storeIdsLong, lang, 6);
|
|
|
-
|
|
|
+
|
|
|
// 按门店ID分组(查询结果已经限制为每个门店最多6条)
|
|
|
foodMap = allFoods.stream()
|
|
|
.collect(Collectors.groupingBy(food -> food.getMdid().intValue()));
|
|
|
+
|
|
|
+ QueryWrapper<OperatingHours> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.in("md_id", storeIdsLong);
|
|
|
+ hourslist = operatingHoursService.list(wrapper);
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 转换为StoreOutput并设置每个门店的商品列表(每个门店最多6条)
|
|
|
List<StoreOutput> storeOutputList = new ArrayList<>();
|
|
|
for (PosStore store : storeList) {
|
|
|
StoreOutput storeOutput = new StoreOutput();
|
|
|
// 复制PosStore的所有属性
|
|
|
BeanUtils.copyProperties(store, storeOutput);
|
|
|
+ DateUtil dateUtil = new DateUtil();
|
|
|
+ Boolean dayang = false;
|
|
|
+ List<OperatingHours> mdHours=hourslist.stream().filter(x-> store.getId().equals(x.getMdId().intValue())).collect(Collectors.toList());
|
|
|
+ //在营业时间范围内返回true
|
|
|
+ for (int i = 0; i < mdHours.size(); i++) {
|
|
|
+ Boolean sbsj = dateUtil.isLegalTime(mdHours.get(i).getStartTime(), mdHours.get(i).getEndTime());
|
|
|
+ if (sbsj == true) {
|
|
|
+ dayang = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //不在时间范围内标识为打烊
|
|
|
+ if (dayang == false) {
|
|
|
+ storeOutput.setState(1L);
|
|
|
+ }
|
|
|
// 从分组结果中获取该门店的商品列表(已限制为最多6条)
|
|
|
List<PosFood> foodList = foodMap.getOrDefault(store.getId(), new ArrayList<>());
|
|
|
storeOutput.setFoodList(foodList);
|