日期范围

This commit is contained in:
2025-11-24 14:04:31 +08:00
parent 87d6399e35
commit 57d4c8f794
3 changed files with 8 additions and 14 deletions

View File

@@ -13,8 +13,6 @@ import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
import com.czg.service.RedisService; import com.czg.service.RedisService;
import com.czg.utils.AssertUtil; import com.czg.utils.AssertUtil;
import com.czg.validator.ValidatorUtil;
import com.czg.validator.group.DefaultGroup;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@@ -69,12 +67,9 @@ public class DataSummaryController {
@GetMapping("productSaleDate") @GetMapping("productSaleDate")
@OperationLog("商品销售-右下") @OperationLog("商品销售-右下")
@SaAdminCheckPermission(value = "dataSummary:productSaleData", name = "商品销售-右下") @SaAdminCheckPermission(value = "dataSummary:productSaleData", name = "商品销售-右下")
public CzgResult<List<ShopProdStatistic>> getProductSaleData(@Validated DataSummaryTradeParam param) { public CzgResult<List<ShopProdStatistic>> getProductSaleData(@RequestParam Integer day) {
Long shopId = StpKit.USER.getShopId(); Long shopId = StpKit.USER.getShopId();
if (param.getShopId() == null) { List<ShopProdStatistic> data = prodStatisticService.getArchiveTradeDataBy20(shopId,day);
param.setShopId(shopId);
}
List<ShopProdStatistic> data = prodStatisticService.getArchiveTradeDataBy20(param.getShopId(), param.getRangeType(), param.getBeginDate(), param.getEndDate());
return CzgResult.success(data); return CzgResult.success(data);
} }

View File

@@ -18,7 +18,6 @@ public interface ShopProdStatisticService extends IService<ShopProdStatistic> {
/** /**
* 统计一段时间内的商品交易数据 * 统计一段时间内的商品交易数据
* *
* @param param 入参
* @return 商品数据 * @return 商品数据
*/ */
SaleSummaryCountVo summaryCount(Long shopId, String productName, String rangeType, LocalDate start, LocalDate end); SaleSummaryCountVo summaryCount(Long shopId, String productName, String rangeType, LocalDate start, LocalDate end);
@@ -40,14 +39,12 @@ public interface ShopProdStatisticService extends IService<ShopProdStatistic> {
* @return 商品数据 * @return 商品数据
*/ */
List<ShopProdStatistic> getArchiveTradeData(Long shopId, String productName, String rangeType, LocalDate start, LocalDate end); List<ShopProdStatistic> getArchiveTradeData(Long shopId, String productName, String rangeType, LocalDate start, LocalDate end);
List<ShopProdStatistic> getArchiveTradeDataBy20(Long shopId, String rangeType, LocalDate start, LocalDate end); List<ShopProdStatistic> getArchiveTradeDataBy20(Long shopId, Integer day);
//------------------------------------------------------------下列为 后台使用------------------------------------------------------------ //------------------------------------------------------------下列为 后台使用------------------------------------------------------------
/** /**
* 统计某天数据并插入数据库 * 统计某天数据并插入数据库
*
* @param day
*/ */
void statisticAndInsert(Long shopId, LocalDate day); void statisticAndInsert(Long shopId, LocalDate day);

View File

@@ -31,8 +31,10 @@ import java.util.stream.Stream;
public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticMapper, ShopProdStatistic> implements ShopProdStatisticService { public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticMapper, ShopProdStatistic> implements ShopProdStatisticService {
@Override @Override
public List<ShopProdStatistic> getArchiveTradeDataBy20(Long shopId, String rangeType, LocalDate start, LocalDate end) { public List<ShopProdStatistic> getArchiveTradeDataBy20(Long shopId, Integer day) {
List<ShopProdStatistic> archiveTradeData = getArchiveTradeData(shopId, null, rangeType, start, end); LocalDate currentDate = LocalDate.now();
LocalDate startDate = currentDate.minusDays(day - 1);
List<ShopProdStatistic> archiveTradeData = getArchiveTradeData(shopId, null, "", startDate, currentDate);
// 按照 saleCount 降序排序 // 按照 saleCount 降序排序
return archiveTradeData.stream() return archiveTradeData.stream()
.sorted( .sorted(
@@ -110,7 +112,7 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
realTimeData = realTimeData.stream() realTimeData = realTimeData.stream()
.filter(ShopProdStatistic::isValid) .filter(ShopProdStatistic::isValid)
.toList(); .toList();
if(CollUtil.isNotEmpty(realTimeData)) { if (CollUtil.isNotEmpty(realTimeData)) {
boolean exists = exists(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, day)); boolean exists = exists(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, day));
if (exists) { if (exists) {
remove(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, day)); remove(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, day));