|
|
@@ -518,6 +518,180 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
|
|
|
return storeInfoVoPage;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public IPage<StoreInfoVo> getNewStorePage(int page, int size, String storeName, String storeContact, String id, String storePhone, String storeType, String expiredState, String storeApplicationStatus, String storeStatus, String businessSection, String jingdu, String weidu, String renewContractStatus, String foodLicenceStatus, String foodLicenceWhetherExpiredStatus) {
|
|
|
+ checkAndUpdateExpiredRecords();
|
|
|
+ IPage<StoreInfoVo> iPage = new Page<>(page, size);
|
|
|
+ QueryWrapper<StoreInfoVo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.like(storeName != null && !storeName.isEmpty(), "a.store_name", storeName).like(storeContact != null && !storeContact.isEmpty(), "b.name", storeContact).like(storePhone != null && !storePhone.isEmpty(), "b.phone", storePhone).like(storeType != null && !storeType.isEmpty(), "a.store_type", storeType).eq(StringUtils.isNotEmpty(storeApplicationStatus), "a.store_application_status", storeApplicationStatus).eq(StringUtils.isNotEmpty(businessSection), "a.business_section", businessSection).eq(StringUtils.isNotEmpty(storeStatus), "a.store_status", storeStatus).eq(StringUtils.isNotEmpty(renewContractStatus), "a.renew_contract_status", renewContractStatus).eq(StringUtils.isNotEmpty(foodLicenceStatus), "a.food_licence_status", foodLicenceStatus).like(StringUtils.isNotEmpty(id), "a.id", id).eq("a.delete_flag", 0).eq("b.delete_flag", 0).orderByDesc("a.created_time");
|
|
|
+ //如果查询未过期
|
|
|
+ // 获取当前时刻
|
|
|
+ Date currentDate = new Date();
|
|
|
+ // 获取当前日期和时间
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ // 将时间设置为 0 点
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
+ // 加上 30 天
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, 30);
|
|
|
+ // 获取 Date 对象
|
|
|
+ Date thirtyDaysAgo = calendar.getTime();
|
|
|
+ if ("0".equals(expiredState)) {
|
|
|
+ queryWrapper.ge("a.expiration_time", thirtyDaysAgo);
|
|
|
+ } else if ("1".equals(expiredState)) {
|
|
|
+ queryWrapper.lt("a.expiration_time", thirtyDaysAgo);
|
|
|
+ queryWrapper.ge("a.expiration_time", currentDate);
|
|
|
+ } else if ("2".equals(expiredState)) {
|
|
|
+ queryWrapper.lt("a.expiration_time", currentDate);
|
|
|
+ }
|
|
|
+ // 获取当前时间
|
|
|
+ LocalDate nowDay = LocalDate.now();
|
|
|
+ //经营许可证到期状态筛选 0 查询食品经营许可证已到期
|
|
|
+ if (CommonConstant.FOOD_LICENCE_EXPIRE_STATUS.equals(foodLicenceWhetherExpiredStatus)) {
|
|
|
+ queryWrapper.lt("a.food_licence_expiration_time", nowDay);
|
|
|
+ } else if (CommonConstant.FOOD_LICENCE_ABOUT_TO_EXPIRE_STATUS.equals(foodLicenceWhetherExpiredStatus)) {//经营许可证筛选状态 1 查询食品经营许可证即将到期 距离到期时间30天内
|
|
|
+ queryWrapper.lt("a.food_licence_expiration_time", nowDay.plusDays(31))
|
|
|
+ .ge("a.food_licence_expiration_time", nowDay);
|
|
|
+ } else if (CommonConstant.FOOD_LICENCE_NOT_EXPIRED_STATUS.equals(foodLicenceWhetherExpiredStatus)) {//经营许可证筛选状态 2 查询食品经营许可证未到期 距离到期时间大于30天以上
|
|
|
+ queryWrapper.gt("a.food_licence_expiration_time", nowDay.plusDays(31));
|
|
|
+ }
|
|
|
+ //查出所有店铺
|
|
|
+ IPage<StoreInfoVo> storeInfoVoPage = storeInfoMapper.getNewStoreInfoVoPage(iPage, queryWrapper);
|
|
|
+ List<StoreInfoVo> records = storeInfoVoPage.getRecords();
|
|
|
+ if (!records.isEmpty()) {
|
|
|
+ // 提前查询所有需要的字典数据
|
|
|
+ List<StoreInfoVo> collect = records.stream().filter(record -> StringUtils.isNotEmpty(record.getStoreType())).collect(Collectors.toList());
|
|
|
+ Set<String> allTypes = collect.stream().map(StoreInfoVo::getStoreType).flatMap(type -> Arrays.stream(type.split(","))).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<StoreDictionary> storeDictionaries = storeDictionaryMapper.selectList(new LambdaQueryWrapper<StoreDictionary>().eq(StoreDictionary::getTypeName, "storeType").isNull(StoreDictionary::getParentId).in(!allTypes.isEmpty(), StoreDictionary::getDictId, allTypes));
|
|
|
+ Map<String, String> typeMap = storeDictionaries.stream().collect(Collectors.toMap(StoreDictionary::getDictId, StoreDictionary::getDictDetail));
|
|
|
+
|
|
|
+ Map<String, List<LifeCoupon>> quanListByStoreId = new HashMap<>();
|
|
|
+ Map<Object, List<Map<String, Object>>> avgScoreMap = new HashMap<>();
|
|
|
+ Map<Object, List<Map<String, Object>>> avgPriceMap = new HashMap<>();
|
|
|
+ Map<Integer, List<StoreComment>> commentMap = new HashMap<>();
|
|
|
+ // 如果获取美食列表进行以下前置操作
|
|
|
+ if (StringUtils.isNotEmpty(businessSection) && businessSection.equals("1")) {
|
|
|
+ List<Integer> storeIds = records.stream().map(StoreInfoVo::getId).collect(Collectors.toList());
|
|
|
+ LambdaUpdateWrapper<LifeCoupon> quanWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ quanWrapper.in(LifeCoupon::getStoreId, storeIds).eq(LifeCoupon::getStatus, 1).orderByDesc(LifeCoupon::getCreatedTime);
|
|
|
+ List<LifeCoupon> quanList = lifeCouponMapper.selectList(quanWrapper);
|
|
|
+ quanListByStoreId = quanList.stream().collect(Collectors.groupingBy(LifeCoupon::getStoreId));
|
|
|
+ // 获取全部店铺的评分与平均花销
|
|
|
+ // TODO sotre_comment 没有花销 怎么算平均花销
|
|
|
+ avgScoreMap = storeEvaluationMapper.allStoreAvgScore().stream().collect(Collectors.groupingBy(o -> o.get("store_id")));
|
|
|
+ commentMap = storeCommentMapper.selectList(new QueryWrapper<StoreComment>().eq("business_type", "5").eq("delete_flag", 0)).stream().collect(Collectors.groupingBy(StoreComment::getStoreId));
|
|
|
+ avgPriceMap = lifeUserOrderMapper.allStoreAvgPrice().stream().collect(Collectors.groupingBy(o -> o.get("store_id")));
|
|
|
+ }
|
|
|
+ for (StoreInfoVo record : records) {
|
|
|
+ //处理类型
|
|
|
+ if (StringUtils.isNotEmpty(record.getStoreType())) {
|
|
|
+ String[] types = record.getStoreType().split(",");
|
|
|
+ List<String> typeDetails = Arrays.stream(types).map(typeMap::get).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ record.setStoreTypeStr(String.join(",", typeDetails));
|
|
|
+ record.setStoreTypeList(Arrays.asList(types));
|
|
|
+ }
|
|
|
+ //写经纬度
|
|
|
+ String[] split = record.getStorePosition().split(",");
|
|
|
+ record.setStorePositionLongitude(split[0]);
|
|
|
+ record.setStorePositionLatitude(split[1]);
|
|
|
+ //处理一下到期状态
|
|
|
+ Date expirationTime = record.getExpirationTime();
|
|
|
+ if (expirationTime != null) {
|
|
|
+ // 获取当前时间
|
|
|
+ Calendar now = Calendar.getInstance();
|
|
|
+ Date nowCurrentDate = now.getTime();
|
|
|
+ // 计算 30 天后的时间
|
|
|
+ now.add(Calendar.DAY_OF_YEAR, 30);
|
|
|
+ Date thirtyDaysLater = now.getTime();
|
|
|
+ // 比较两个日期
|
|
|
+ if (expirationTime.after(currentDate)) {
|
|
|
+ record.setExpiredState("0");
|
|
|
+ if (expirationTime != null && (expirationTime.after(nowCurrentDate) || expirationTime.equals(nowCurrentDate)) && expirationTime.before(thirtyDaysLater)) {
|
|
|
+ record.setExpiredState("1");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ record.setExpiredState("2");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取当前时间
|
|
|
+ LocalDate nowLocal = LocalDate.now();
|
|
|
+ // 将 expirationTime 转换为 LocalDate
|
|
|
+ LocalDate expDate = expirationTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ // 计算距离到期的天数
|
|
|
+ long daysToExpire = ChronoUnit.DAYS.between(nowLocal, expDate);
|
|
|
+ record.setDaysToExpire(daysToExpire);
|
|
|
+ }
|
|
|
+ // 处理经营许可证到期时间回显状态 根据经营许可证筛选状态筛选
|
|
|
+ Date foodDate = record.getFoodLicenceExpirationTime();
|
|
|
+ if (foodDate != null) {
|
|
|
+ // 获取当前时间
|
|
|
+ LocalDate nowLocal = LocalDate.now();
|
|
|
+ LocalDate localDate = foodDate.toInstant() // Date -> Instant(UTC时间戳)
|
|
|
+ .atZone(ZoneId.systemDefault()) // Instant -> ZonedDateTime(系统默认时区)
|
|
|
+ .toLocalDate();
|
|
|
+ long remainingDays = ChronoUnit.DAYS.between(nowLocal, localDate);
|
|
|
+ if (remainingDays == -1) {
|
|
|
+ record.setFoodLicenceRemainingDays("0天");
|
|
|
+ record.setFoodLicenceExpireStatus("已到期");
|
|
|
+ } else if (remainingDays >= 0 && remainingDays <= 30) {
|
|
|
+ record.setFoodLicenceRemainingDays(remainingDays + "天");
|
|
|
+ record.setFoodLicenceExpireStatus("即将到期");
|
|
|
+ } else if (remainingDays > 30) {
|
|
|
+ record.setFoodLicenceRemainingDays(remainingDays + "天");
|
|
|
+ record.setFoodLicenceExpireStatus("未到期");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 处理状态
|
|
|
+ if (record.getLogoutFlag() == 1) {
|
|
|
+ record.setStoreStatusStr("已注销");
|
|
|
+ record.setStoreStatus(2);
|
|
|
+ }
|
|
|
+ // 根据八大类不同进行个性化操作
|
|
|
+ if (StringUtils.isNotEmpty(businessSection)) {
|
|
|
+ switch (businessSection) {
|
|
|
+ case "1":
|
|
|
+ record.setAvgScore("0");
|
|
|
+ record.setAvgPrice("0");
|
|
|
+ record.setTotalNum("0");
|
|
|
+
|
|
|
+ if ((jingdu != null && !jingdu.isEmpty()) && (weidu != null && !weidu.isEmpty())) {
|
|
|
+ double storeJing = Double.parseDouble(split[0]);
|
|
|
+ double storeWei = Double.parseDouble(split[1]);
|
|
|
+ double storeDistance = DistanceUtil.haversineCalculateDistance(Double.parseDouble(jingdu), Double.parseDouble(weidu), storeJing, storeWei);
|
|
|
+ record.setDistance(storeDistance);
|
|
|
+ } else {
|
|
|
+ record.setDistance(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置店铺得分,设置店铺人均消费,设置总评论数
|
|
|
+ if (avgScoreMap.containsKey(String.valueOf(record.getId()))) {
|
|
|
+ record.setAvgScore(String.valueOf(avgScoreMap.get(String.valueOf(record.getId())).get(0).get("avg_score")));
|
|
|
+ record.setAvgPrice(String.valueOf(avgPriceMap.get(String.valueOf(record.getId())).get(0).get("avg_price")));
|
|
|
+ }
|
|
|
+ // 设置店铺得分,设置店铺人均消费,设置总评论数
|
|
|
+ if (commentMap.containsKey(record.getId())) {
|
|
|
+ record.setTotalNum(String.valueOf(commentMap.get(record.getId()).size()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置店铺优惠券列表
|
|
|
+ if (!quanListByStoreId.isEmpty() && quanListByStoreId.containsKey(String.valueOf(record.getId()))) {
|
|
|
+ record.setQuanList(quanListByStoreId.get(String.valueOf(record.getId())));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ toExcel = storeInfoVoPage.getRecords();
|
|
|
+ return storeInfoVoPage;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 重置门店密码
|
|
|
*
|