|
|
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
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.ruoyi.app.mendian.dto.FoodSearchOutput;
|
|
|
import com.ruoyi.app.utils.ImageCompressUtils;
|
|
|
import com.ruoyi.common.annotation.Anonymous;
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
@@ -17,8 +18,10 @@ import com.ruoyi.common.utils.MessageUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
import com.ruoyi.system.domain.InfoUser;
|
|
|
+import com.ruoyi.system.domain.OperatingHours;
|
|
|
import com.ruoyi.system.domain.PosFood;
|
|
|
import com.ruoyi.system.domain.PosStore;
|
|
|
+import com.ruoyi.system.mapper.PosStoreMapper;
|
|
|
import com.ruoyi.system.service.IInfoUserService;
|
|
|
import com.ruoyi.system.service.IPosFenleiService;
|
|
|
import com.ruoyi.system.service.IPosFoodService;
|
|
|
@@ -32,9 +35,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -58,7 +59,8 @@ public class PosFoodController extends BaseController {
|
|
|
|
|
|
@Autowired //用户
|
|
|
private IInfoUserService infoUserService;
|
|
|
-
|
|
|
+ @Autowired //店铺Mapper
|
|
|
+ private PosStoreMapper posStoreMapper;
|
|
|
|
|
|
//删除商品
|
|
|
@Anonymous
|
|
|
@@ -249,6 +251,150 @@ public class PosFoodController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 客户端查询美食
|
|
|
+ *
|
|
|
+ * @param keyword
|
|
|
+ * @param language
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ @Anonymous
|
|
|
+ @GetMapping("/foodSearch")
|
|
|
+ public AjaxResult foodSearch(@RequestParam String keyword, @RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam(defaultValue = "") String language) {
|
|
|
+ if (keyword.isEmpty()) {
|
|
|
+ return error(MessageUtils.message("no.tip.lock.keywork"));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置默认分页参数
|
|
|
+ if (pageNum == null || pageNum < 1) {
|
|
|
+ pageNum = 1;
|
|
|
+ }
|
|
|
+ if (pageSize == null || pageSize < 1) {
|
|
|
+ pageSize = 10;
|
|
|
+ }
|
|
|
+
|
|
|
+ String lang = "0";
|
|
|
+ if (!"".equals(language)) {
|
|
|
+ lang = language;
|
|
|
+ }
|
|
|
+ keyword = hanlderKeyword(lang, keyword);
|
|
|
+
|
|
|
+ // 创建分页对象
|
|
|
+ Page<PosStore> page = new Page<>(pageNum, pageSize);
|
|
|
+
|
|
|
+ // 1. 先通过联表查询获取分页的店铺列表(包含总数)
|
|
|
+ IPage<PosStore> storePage = posStoreMapper.selectStoresByFoodKeyword(page, keyword, lang);
|
|
|
+ List<PosStore> stores = storePage.getRecords();
|
|
|
+
|
|
|
+ List<FoodSearchOutput> result = new ArrayList<>();
|
|
|
+
|
|
|
+ // 2. 一次性查询所有相关商品(避免循环查询数据库)
|
|
|
+ if (!stores.isEmpty()) {
|
|
|
+ // 提取所有店铺ID
|
|
|
+ List<Long> storeIds = stores.stream()
|
|
|
+ .map(store -> store.getId().longValue())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 一次性查询所有店铺下匹配关键词的商品
|
|
|
+ QueryWrapper<PosFood> foodQuery = new QueryWrapper<>();
|
|
|
+ foodQuery.in("mdid", storeIds)
|
|
|
+ .eq("language", lang)
|
|
|
+ .eq("to_examine", "1")
|
|
|
+ .apply(" CONCAT(name, ' ') LIKE CONCAT('%', {0}, '%') COLLATE utf8mb4_unicode_ci", keyword);
|
|
|
+
|
|
|
+ List<PosFood> allFoods = posFoodService.list(foodQuery);
|
|
|
+
|
|
|
+ // 按店铺ID分组商品
|
|
|
+ Map<Long, List<PosFood>> foodsByStore = allFoods.stream()
|
|
|
+ .collect(Collectors.groupingBy(PosFood::getMdid));
|
|
|
+ List<OperatingHours> storeHours = new ArrayList<>();
|
|
|
+// List<FoodOperatingHours> foodHours = new ArrayList<>();
|
|
|
+// if (!stores.isEmpty()) {
|
|
|
+// storeHours = operatingHoursService.list(new LambdaQueryWrapper<OperatingHours>().in(OperatingHours::getMdId, stores.stream().map(store -> store.getId().longValue()).collect(Collectors.toList())));
|
|
|
+// foodHours = foodOperatingHoursService.list(new LambdaQueryWrapper<FoodOperatingHours>().in(FoodOperatingHours::getFoodId, allFoods.stream().map(PosFood::getId).collect(Collectors.toList())));
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ // 3. 为每个店铺设置对应的商品
|
|
|
+ for (PosStore store : stores) {
|
|
|
+ FoodSearchOutput output = new FoodSearchOutput();
|
|
|
+ List<OperatingHours> hours = storeHours.stream().filter(hour -> hour.getMdId().equals(store.getId().longValue())).collect(Collectors.toList());
|
|
|
+// boolean isOperating = OperatingUtil.storeIsOperatingOfDay(hours);
|
|
|
+// store.setIsOperating(isOperating);
|
|
|
+ output.setPosStore(store);
|
|
|
+ // 从分组结果中获取该店铺的商品
|
|
|
+ List<PosFood> storeFoods = foodsByStore.getOrDefault(store.getId().longValue(), new ArrayList<>());
|
|
|
+// for (PosFood food : storeFoods) {
|
|
|
+// List<FoodOperatingHours> foodHour = foodHours.stream().filter(hour -> hour.getFoodId().equals(food.getId())).collect(Collectors.toList());
|
|
|
+// boolean isOperatingFood = getFoodIsOparetig(food, foodHour, storeHours, new HashMap<Long, Boolean>());
|
|
|
+// food.setIsOperating(isOperatingFood);
|
|
|
+// }
|
|
|
+ output.setPosFoodList(storeFoods);
|
|
|
+
|
|
|
+ result.add(output);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 返回分页结果
|
|
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
+ response.put("list", result);
|
|
|
+ response.put("total", storePage.getTotal());
|
|
|
+ return success(response);
|
|
|
+ }
|
|
|
+
|
|
|
+ //越南语搜索,添加空格,搜索的关键字变成有语意的
|
|
|
+ private String hanlderKeyword(String language, String keyword) {
|
|
|
+ if (language.equals("0")) {
|
|
|
+ if (!keyword.contains(" "))
|
|
|
+ keyword = keyword + " ";
|
|
|
+ }
|
|
|
+ return keyword;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 客户端查询门店
|
|
|
+ *
|
|
|
+ * @param keyword
|
|
|
+ * @param language
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ @Anonymous
|
|
|
+ @GetMapping("/storeSearch")
|
|
|
+ public AjaxResult storeSearch(@RequestParam String keyword, @RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam(defaultValue = "") String language) {
|
|
|
+ if (keyword.isEmpty()) {
|
|
|
+ return error(MessageUtils.message("no.tip.lock.keywork"));
|
|
|
+ }
|
|
|
+ QueryWrapper<PosFood> query = new QueryWrapper<>();
|
|
|
+ String lang = "0";
|
|
|
+ if (!"".equals(language)) {
|
|
|
+ lang = language;
|
|
|
+ }
|
|
|
+ keyword = hanlderKeyword(lang, keyword);
|
|
|
+ // 设置默认分页参数
|
|
|
+ if (pageNum == null || pageNum < 1) {
|
|
|
+ pageNum = 1;
|
|
|
+ }
|
|
|
+ if (pageSize == null || pageSize < 1) {
|
|
|
+ pageSize = 10;
|
|
|
+ }
|
|
|
+ Page<PosStore> page = new Page<>(pageNum, pageSize);
|
|
|
+ QueryWrapper<PosStore> wrapper = new QueryWrapper<>();
|
|
|
+ String finalKeyword = keyword;
|
|
|
+ wrapper.eq("off_shelf", "0")
|
|
|
+// .and(i->i.like("pos_name", keyword).or().like("brief_introduction",keyword));
|
|
|
+ .and(i -> i.apply(" CONCAT(pos_name,' ') LIKE CONCAT('%', {0}, '%') COLLATE utf8mb4_unicode_ci", finalKeyword).or().apply(" CONCAT(brief_introduction,' ') LIKE CONCAT('%', {0}, '%') COLLATE utf8mb4_unicode_ci", finalKeyword));
|
|
|
+ IPage<PosStore> data = posStoreService.page(page, wrapper);
|
|
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
+
|
|
|
+ response.put("list", data.getRecords());
|
|
|
+ response.put("total", data.getTotal());
|
|
|
+ return success(response);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Anonymous
|
|
|
@GetMapping("/getFoodPageList")
|
|
|
public AjaxResult getFoodPageList(@RequestHeader String token,
|