Explorar o código

中台 店铺列表

qxy hai 1 semana
pai
achega
2f183b0124

+ 28 - 0
alien-entity/src/main/java/shop/alien/mapper/StoreInfoMapper.java

@@ -98,6 +98,34 @@ public interface StoreInfoMapper extends BaseMapper<StoreInfo> {
             "${ew.customSqlSegment}")
     IPage<StoreInfoVo> getStoreInfoVoPage(IPage<StoreInfoVo> page, @Param(Constants.WRAPPER) QueryWrapper<StoreInfoVo> queryWrapper);
 
+    /**
+     * web端-门店列表
+     *
+     * @param page         分页
+     * @param queryWrapper 查询条件
+     * @return IPage<StoreInfoVo>
+     */
+    @Select("select a.*, " +
+            "b.name store_contact, " +
+            "b.phone store_phone, " +
+            "b.id_card idCard, " +
+            "b.password, " +
+            "c.dict_detail store_status_str, " +
+            "d.dict_detail business_status_str, " +
+            "e.dict_detail store_type_str,  " +
+            "( " +
+            " select ifnull(round(avg(score), 1), 0) " +
+            " from store_evaluation eval " +
+            " where eval.store_id = a.id and eval.delete_flag = 0 " +
+            ") score " +
+            "from store_info a " +
+            "left join store_user b on a.id = b.store_id and a.delete_flag = 0 and b.delete_flag = 0 " +
+            "left join store_dictionary c on a.store_status = c.dict_id and c.type_name = 'storeState' and c.delete_flag = 0 " +
+            "left join store_dictionary d on a.business_status = d.dict_id and d.type_name = 'businessStatus' and d.delete_flag = 0 " +
+            "left join store_dictionary e on e.type_name = 'storeType' and e.dict_id = a.store_type and e.delete_flag = 0 " +
+            "${ew.customSqlSegment}")
+    IPage<StoreInfoVo> getNewStoreInfoVoPage(IPage<StoreInfoVo> page, @Param(Constants.WRAPPER) QueryWrapper<StoreInfoVo> queryWrapper);
+
     @Select("select info.store_name, user.phone, img.img_url " +
             "from store_info info " +
             "join store_user user on user.store_id = info.id " +

+ 62 - 0
alien-store/src/main/java/shop/alien/store/controller/StoreInfoController.java

@@ -262,6 +262,68 @@ public class StoreInfoController {
     }
 
     /**
+     * 新web-分页查询店铺信息
+     *
+     * @param pageNum      页码
+     * @param pageSize     页容
+     * @param storeName    门店名称
+     * @param storeContact 联系人
+     * @param storePhone   门店电话
+     * @param storeType    门店类型
+     * @return IPage<StoreInfoVo>
+     */
+    @ApiOperation("新中台web-分页查询店铺信息")
+    @ApiOperationSupport(order = 20)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
+            @ApiImplicitParam(name = "pageSize", value = "页容", dataType = "int", paramType = "query", required = true),
+            @ApiImplicitParam(name = "storeName", value = "门店名称", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "storeContact", value = "门店联系人", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "storePhone", value = "门店电话", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "storeType", value = "门店类型", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "expiredState", value = "过期状态", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "businessSection", value = "经营板块", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "storeApplicationStatus", value = "门店审核状态", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "jingdu", value = "jingdu", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "weidu", value = "weidu", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "renewContractStatus", value = "门店续签合同状态", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "foodLicenceStatus", value = "门店经营许可证状态", dataType = "String", paramType = "query"),
+            @ApiImplicitParam(name = "foodLicenceWhetherExpiredStatus", value = "门店经营许可证是否过期状态", dataType = "String", paramType = "query")
+    })
+    @GetMapping("/getNewStorePage")
+    public R<IPage<StoreInfoVo>> getNewStorePage(
+            @RequestParam(defaultValue = "1") int pageNum,
+            @RequestParam(defaultValue = "10") int pageSize,
+            @RequestParam(required = false) String storeName,
+            @RequestParam(required = false) String storeContact,
+            @RequestParam(required = false) String id,
+            @RequestParam(required = false) String storePhone,
+            @RequestParam(required = false) String storeType,
+            @RequestParam(required = false) String expiredState,
+            @RequestParam(required = false) String storeApplicationStatus,
+            @RequestParam(required = false) String businessSection,
+            @RequestParam(required = false) String storeStatus,
+            @RequestParam(required = false) String jingdu,
+            @RequestParam(required = false) String weidu,
+            @RequestParam(required = false) String renewContractStatus,
+            @RequestParam(required = false) String foodLicenceStatus,
+            @RequestParam(required = false) String foodLicenceWhetherExpiredStatus)
+    {
+        log.info("StoreInfoController.getStoresPage?pageNum={}," +
+                        "pageSize={},storeName={},storeContact={}," +
+                        "id={},storePhone={},storeType={},expiredState={}," +
+                        "storeApplicationStatus={},storeStatus={}," +
+                        "businessSection={},jingdu={},weidu={}," +
+                        "renewContractStatus={},foodLicenceStatus={}" +
+                        ",foodLicenceWhetherExpiredStatus={}",
+                pageNum, pageSize, storeName, storeContact,
+                id, storePhone, storeType, expiredState, storeApplicationStatus,
+                storeStatus, businessSection, jingdu, weidu, renewContractStatus,
+                foodLicenceStatus, foodLicenceWhetherExpiredStatus);
+        return R.data(storeInfoService.getNewStorePage(pageNum, pageSize, storeName, storeContact, id, storePhone, storeType, expiredState, storeApplicationStatus, storeStatus, businessSection, jingdu, weidu, renewContractStatus, foodLicenceStatus, foodLicenceWhetherExpiredStatus));
+    }
+
+    /**
      * web-重置门店密码
      *
      * @param storeId 门店id

+ 13 - 0
alien-store/src/main/java/shop/alien/store/service/StoreInfoService.java

@@ -62,6 +62,19 @@ public interface StoreInfoService extends IService<StoreInfo> {
     IPage<StoreInfoVo> getStorePage(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);
 
     /**
+     * web-分页查询店铺信息
+     *
+     * @param page         页码
+     * @param size         页容
+     * @param storeName    门店名称
+     * @param storeContact 联系人
+     * @param storePhone   门店电话
+     * @param storeType    门店类型
+     * @return IPage<StoreInfoVo>
+     */
+    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);
+
+    /**
      * web-重置门店密码
      *
      * @param storeId 门店id

+ 174 - 0
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -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;
+    }
+
     /**
      * 重置门店密码
      *