返回是否可售卖
This commit is contained in:
parent
7c10b29b2a
commit
fdee14d77f
|
|
@ -16,4 +16,5 @@ import java.util.List;
|
|||
public class ProductVO extends Product {
|
||||
private BigDecimal lowPrice;
|
||||
private List<ProdSku> skuList;
|
||||
private Integer isSaleTime;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.dto.pad.*;
|
||||
import com.czg.account.entity.*;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.enums.YesNoEnum;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.product.entity.ProdSku;
|
||||
import com.czg.product.entity.Product;
|
||||
|
|
@ -20,8 +24,13 @@ import jakarta.annotation.Resource;
|
|||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.TextStyle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
|
|
@ -49,6 +58,40 @@ public class PadProdServiceImpl implements PadProdService {
|
|||
return PageUtil.convert(new PageInfo<>(padProductCategoryDetailMapper.selectPageByKeyAndShopId(shopId, productCategoryId)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算是否在可售时间内
|
||||
*
|
||||
* @param days 星期几,例如 "Monday,Tuesday"
|
||||
* @param startTime 起售时间
|
||||
* @param endTime 停售时间
|
||||
* @return 是否可售时间 1-是,0-否
|
||||
*/
|
||||
public Integer calcIsSaleTime(String days, LocalTime startTime, LocalTime endTime) {
|
||||
if (StrUtil.isBlank(days) || ObjUtil.isNull(startTime) || ObjUtil.isNull(endTime)) {
|
||||
return YesNoEnum.NO.value();
|
||||
}
|
||||
String today = getWeekDayEnName();
|
||||
List<String> dayList = StrUtil.split(days, ",");
|
||||
LocalTime now = LocalTime.now().withNano(0);
|
||||
if (CollUtil.contains(dayList, today) && now.isAfter(startTime) && now.isBefore(endTime)) {
|
||||
return YesNoEnum.YES.value();
|
||||
}
|
||||
return YesNoEnum.NO.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前日期是星期几的英文名称
|
||||
*
|
||||
* @return 星期几的英文名称,例如 "Monday" 或 "Friday"
|
||||
*/
|
||||
private String getWeekDayEnName() {
|
||||
// 获取当前日期
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
// 获取当前日期是星期几,返回一个 DayOfWeek 枚举类型的实例
|
||||
DayOfWeek dayOfWeek = currentDate.getDayOfWeek();
|
||||
return dayOfWeek.getDisplayName(TextStyle.FULL, Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PadDetailDTO detail(Long shopId, Long padProductCategory) {
|
||||
PadProductCategory padCategory = padProductCategoryService.getOne(new QueryWrapper().eq(PadProductCategory::getShopId, shopId).eq(PadProductCategory::getId, padProductCategory));
|
||||
|
|
@ -66,10 +109,13 @@ public class PadProdServiceImpl implements PadProdService {
|
|||
products.parallelStream().forEach(item -> {
|
||||
List<ProdSku> skuList = prodSkuService.list(new QueryWrapper().eq(ProdSku::getProductId, item.getId()));
|
||||
item.setSkuList(skuList);
|
||||
item.setIsSaleTime(calcIsSaleTime(item.getDays(), item.getStartTime(), item.getEndTime()));
|
||||
|
||||
});
|
||||
padDetailDTO.setProductList(products);
|
||||
}
|
||||
|
||||
|
||||
return padDetailDTO;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue