统计数据归档查询、商品数据分类缓存、已知问题修复
This commit is contained in:
@@ -14,6 +14,7 @@ import com.czg.order.service.DataSummaryService;
|
||||
import com.czg.order.vo.DataSummaryDateAmountVo;
|
||||
import com.czg.order.vo.DataSummaryPayTypeVo;
|
||||
import com.czg.order.vo.DataSummaryProductSaleRankingVo;
|
||||
import com.czg.order.vo.TotalVo;
|
||||
import com.czg.service.order.mapper.OrderInfoMapper;
|
||||
import com.czg.service.order.mapper.ShopOrderStatisticMapper;
|
||||
import com.czg.service.order.mapper.ShopProdStatisticMapper;
|
||||
@@ -50,7 +51,15 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
private ShopProdStatisticMapper shopProdStatisticMapper;
|
||||
|
||||
@Override
|
||||
public ShopOrderStatistic getTradeData(DataSummaryTradeParam param) {
|
||||
public ShopOrderStatistic getArchiveTradeData(DataSummaryTradeParam param) {
|
||||
ShopOrderStatistic shopOrderStatistic = shopOrderStatisticMapper.getTradeData(param);
|
||||
shopOrderStatistic.setCustomerUnitPrice(shopOrderStatistic.getCustomerUnitPrice().setScale(2, java.math.RoundingMode.HALF_UP));
|
||||
shopOrderStatistic.setTableTurnoverRate(shopOrderStatistic.getTableTurnoverRate().setScale(2, java.math.RoundingMode.HALF_UP));
|
||||
return shopOrderStatistic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopOrderStatistic getRealTimeTradeData(DataSummaryTradeParam param) {
|
||||
List<String> funs = Arrays.asList("getPayTypeAmountCount", "getVipRechargeAmountCount", "getNewMemberCount", "getCustomerUnitPrice", "getTableTurnoverRate");
|
||||
Map<String, Object> collect = funs.parallelStream().collect(Collectors.toMap(fun -> fun, fun ->
|
||||
ReflectUtil.invoke(shopOrderStatisticMapper, fun, param)
|
||||
@@ -106,13 +115,6 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
data.setDiscountAmount(discountAmount);
|
||||
data.setDiscountCount(discountCount);
|
||||
return data;
|
||||
|
||||
/*ShopOrderStatistic shopOrderStatistic = shopOrderStatisticMapper.getTradeData(param);
|
||||
long newMemberCount = shopOrderStatisticMapper.getNewMemberCount(param);
|
||||
data.setNewMemberCount(newMemberCount);
|
||||
shopOrderStatistic.setCustomerUnitPrice(shopOrderStatistic.getCustomerUnitPrice().setScale(2, java.math.RoundingMode.HALF_UP));
|
||||
shopOrderStatistic.setTableTurnoverRate(shopOrderStatistic.getTableTurnoverRate().setScale(2, java.math.RoundingMode.HALF_UP));
|
||||
return shopOrderStatistic;*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,7 +131,7 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
param.setBeginDate(days.getFirst() + " 00:00:00");
|
||||
param.setEndDate(days.getLast() + " 23:59:59");
|
||||
PageHelper.startPage(PageUtil.buildPageHelp());
|
||||
PageInfo<DataSummaryProductSaleRankingVo> pageInfo = new PageInfo<>(shopProdStatisticMapper.findProdRandingSummaryPage2(param));
|
||||
PageInfo<DataSummaryProductSaleRankingVo> pageInfo = new PageInfo<>(shopProdStatisticMapper.findProdRandingSummaryPage(param));
|
||||
return PageUtil.convert(pageInfo);
|
||||
}
|
||||
|
||||
@@ -138,7 +140,7 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
LocalDate now = LocalDate.now();
|
||||
LocalDate beginDate = now.plusDays(-day);
|
||||
DataSummaryDateAmountVo data = new DataSummaryDateAmountVo();
|
||||
List<DataSummaryDateAmountVo.TotalVo> total = new ArrayList<>();
|
||||
List<TotalVo> total = new ArrayList<>();
|
||||
for (int i = 1; i <= day; i++) {
|
||||
String thisDay = beginDate.plusDays(i).format(DatePattern.NORM_DATE_FORMATTER);
|
||||
OrderInfo orderInfo = orderInfoMapper.selectOneByQuery(QueryWrapper.create()
|
||||
@@ -147,7 +149,7 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
.eq(OrderInfo::getTradeDay, thisDay)
|
||||
.isNotNull(OrderInfo::getPaidTime)
|
||||
);
|
||||
DataSummaryDateAmountVo.TotalVo totalVo = new DataSummaryDateAmountVo.TotalVo();
|
||||
TotalVo totalVo = new TotalVo();
|
||||
if (orderInfo != null) {
|
||||
totalVo.setOrderAmount(orderInfo.getOrderAmount());
|
||||
totalVo.setActualAmount(orderInfo.getPayAmount());
|
||||
@@ -209,4 +211,5 @@ public class DataSummaryServiceImpl implements DataSummaryService {
|
||||
public List<Long> getShopIdList() {
|
||||
return shopOrderStatisticMapper.getShopIdList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class SaleSummaryServiceImpl implements SaleSummaryService {
|
||||
|
||||
@Override
|
||||
public SaleSummaryCountVo summaryCount(SaleSummaryCountParam param) {
|
||||
SaleSummaryCountVo saleSummaryCount = shopProdStatisticMapper.getSaleSummaryCount2(param);
|
||||
SaleSummaryCountVo saleSummaryCount = shopProdStatisticMapper.getSaleSummaryCount(param);
|
||||
if (saleSummaryCount == null) {
|
||||
saleSummaryCount = new SaleSummaryCountVo();
|
||||
}
|
||||
@@ -37,12 +37,12 @@ public class SaleSummaryServiceImpl implements SaleSummaryService {
|
||||
@Override
|
||||
public Page<SaleSummaryInfoVo> summaryPage(SaleSummaryCountParam param) {
|
||||
PageHelper.startPage(PageUtil.buildPageHelp());
|
||||
PageInfo<SaleSummaryInfoVo> pageInfo = new PageInfo<>(shopProdStatisticMapper.findSaleSummaryList2(param));
|
||||
PageInfo<SaleSummaryInfoVo> pageInfo = new PageInfo<>(shopProdStatisticMapper.findSaleSummaryList(param));
|
||||
return PageUtil.convert(pageInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SaleSummaryInfoVo> summaryList(SaleSummaryCountParam param) {
|
||||
return shopProdStatisticMapper.findSaleSummaryList2(param);
|
||||
return shopProdStatisticMapper.findSaleSummaryList(param);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ import com.czg.order.service.ShopOrderStatisticService;
|
||||
import com.czg.service.order.mapper.ShopOrderStatisticMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@@ -23,34 +23,54 @@ import java.util.List;
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisticMapper, ShopOrderStatistic> implements ShopOrderStatisticService {
|
||||
@Resource
|
||||
private DataSummaryService dataSummaryService;
|
||||
|
||||
|
||||
@Override
|
||||
public void statistic() {
|
||||
// 获取前一天
|
||||
DateTime yesterday = DateUtil.yesterday();
|
||||
public void statistic(DateTime dateTime) {
|
||||
// 获取前一天的开始时间(00:00:00)
|
||||
DateTime startOfDay = DateUtil.beginOfDay(yesterday);
|
||||
DateTime startOfDay = DateUtil.beginOfDay(dateTime);
|
||||
// 获取前一天的结束时间(23:59:59)
|
||||
DateTime endOfDay = DateUtil.endOfDay(yesterday);
|
||||
DateTime endOfDay = DateUtil.endOfDay(dateTime);
|
||||
List<Long> shopIdList = dataSummaryService.getShopIdList();
|
||||
if (CollUtil.isEmpty(shopIdList)) {
|
||||
return;
|
||||
}
|
||||
shopIdList.parallelStream().forEach(shopId -> {
|
||||
DataSummaryTradeParam param = new DataSummaryTradeParam();
|
||||
param.setShopId(shopId);
|
||||
param.setBeginDate(startOfDay.toStringDefaultTimeZone());
|
||||
param.setEndDate(endOfDay.toStringDefaultTimeZone());
|
||||
ShopOrderStatistic statistic = dataSummaryService.getTradeData(param);
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setCreateDay(LocalDate.now());
|
||||
statistic.setUpdateTime(LocalDateTime.now());
|
||||
saveOrUpdate(statistic);
|
||||
});
|
||||
List<List<Long>> split = CollUtil.split(shopIdList, 5);
|
||||
for (List<Long> splitIdList : split) {
|
||||
splitIdList.parallelStream().forEach(shopId -> {
|
||||
DataSummaryTradeParam param = new DataSummaryTradeParam();
|
||||
param.setShopId(shopId);
|
||||
param.setBeginDate(startOfDay.toStringDefaultTimeZone());
|
||||
param.setEndDate(endOfDay.toStringDefaultTimeZone());
|
||||
ShopOrderStatistic statistic = dataSummaryService.getRealTimeTradeData(param);
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setCreateDay(dateTime.toLocalDateTime().toLocalDate());
|
||||
statistic.setUpdateTime(LocalDateTime.now());
|
||||
if (statistic.getNewMemberCount() != 0L) {
|
||||
System.out.println("newMemberCount:" + statistic.getNewMemberCount());
|
||||
}
|
||||
// 如果没有订单和退款,则不更新数据,否则会产出很多数据
|
||||
if (statistic.getSaleCount() == 0
|
||||
&& statistic.getRefundCount() == 0
|
||||
&& statistic.getMemberPayCount() == 0
|
||||
&& statistic.getNewMemberCount() == 0
|
||||
) {
|
||||
log.info("店铺:{},{},没有要存档的订单统计数据", shopId, dateTime.toDateStr());
|
||||
} else {
|
||||
ShopOrderStatistic entity = getMapper().selectOneByQuery(query().eq(ShopOrderStatistic::getShopId, shopId).eq(ShopOrderStatistic::getCreateDay, dateTime.toDateStr()));
|
||||
if (entity != null) {
|
||||
statistic.setId(entity.getId());
|
||||
updateById(statistic);
|
||||
} else {
|
||||
save(statistic);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,35 +1,41 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.czg.order.entity.ShopProdStatistic;
|
||||
import com.czg.order.param.DataSummaryProductSaleParam;
|
||||
import com.czg.order.service.DataSummaryService;
|
||||
import com.czg.order.service.ShopProdStatisticService;
|
||||
import com.czg.order.vo.DataSummaryProductSaleRankingVo;
|
||||
import com.czg.service.order.mapper.ShopProdStatisticMapper;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.ShopProdStatistic;
|
||||
import com.czg.order.service.ShopProdStatisticService;
|
||||
import com.czg.service.order.mapper.ShopProdStatisticMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 服务层实现。
|
||||
* 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Service
|
||||
public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticMapper, ShopProdStatistic> implements ShopProdStatisticService{
|
||||
@Slf4j
|
||||
public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticMapper, ShopProdStatistic> implements ShopProdStatisticService {
|
||||
@Resource
|
||||
private OrderDetailService orderDetailService;
|
||||
private DataSummaryService dataSummaryService;
|
||||
@Resource
|
||||
private ShopProdStatisticMapper shopProdStatisticMapper;
|
||||
|
||||
@Data
|
||||
private static class StatisticTask{
|
||||
private static class StatisticTask {
|
||||
private BigDecimal successCount = BigDecimal.ZERO;
|
||||
private BigDecimal successAmount = BigDecimal.ZERO;
|
||||
private BigDecimal refundCount = BigDecimal.ZERO;
|
||||
@@ -37,57 +43,42 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
|
||||
}
|
||||
|
||||
@Override
|
||||
public void statistic() {
|
||||
// 获取前一天
|
||||
DateTime yesterday = DateUtil.yesterday();
|
||||
public void statistic(DateTime dateTime) {
|
||||
// 获取前一天的开始时间(00:00:00)
|
||||
DateTime startOfDay = DateUtil.beginOfDay(yesterday);
|
||||
DateTime startOfDay = DateUtil.beginOfDay(dateTime);
|
||||
// 获取前一天的结束时间(23:59:59)
|
||||
DateTime endOfDay = DateUtil.endOfDay(yesterday);
|
||||
|
||||
List<OrderDetail> orderDetails = orderDetailService.list(new QueryWrapper()
|
||||
.ge(OrderDetail::getCreateTime, startOfDay)
|
||||
.le(OrderDetail::getCreateTime, endOfDay)
|
||||
.ne(OrderDetail::getStatus, "wait-pay"));
|
||||
|
||||
|
||||
HashMap<Long, Map<Long, StatisticTask>> countInfo = new HashMap<>();
|
||||
for (OrderDetail item : orderDetails) {
|
||||
Map<Long, StatisticTask> map = countInfo.computeIfAbsent(item.getShopId(), k -> new HashMap<>());
|
||||
StatisticTask statisticTask = map.get(item.getProductId());
|
||||
if (statisticTask == null) {
|
||||
map.put(item.getProductId(), statisticTask = new StatisticTask());
|
||||
}
|
||||
if ("refunding".equals(item.getStatus()) || "refund".equals(item.getStatus()) || "part-refund".equals(item.getStatus())) {
|
||||
statisticTask.setRefundAmount(statisticTask.getRefundAmount().add(item.getReturnAmount()));
|
||||
statisticTask.setRefundCount(statisticTask.getRefundCount().add(item.getRefundNum()));
|
||||
if (item.getReturnNum().compareTo(item.getNum()) < 0) {
|
||||
statisticTask.setSuccessAmount(statisticTask.getSuccessAmount().add(item.getPayAmount().subtract(item.getReturnAmount())));
|
||||
statisticTask.setSuccessCount(statisticTask.getSuccessCount().add(item.getNum().subtract(item.getReturnAmount())));
|
||||
}
|
||||
}else {
|
||||
statisticTask.setSuccessCount(statisticTask.getSuccessCount().add(item.getNum()));
|
||||
statisticTask.setSuccessAmount(statisticTask.getSuccessAmount().add(item.getPayAmount()));
|
||||
}
|
||||
DateTime endOfDay = DateUtil.endOfDay(dateTime);
|
||||
List<Long> shopIdList = dataSummaryService.getShopIdList();
|
||||
if (CollUtil.isEmpty(shopIdList)) {
|
||||
return;
|
||||
}
|
||||
List<List<Long>> split = CollUtil.split(shopIdList, 5);
|
||||
for (List<Long> splitIdList : split) {
|
||||
splitIdList.parallelStream().forEach(shopId -> {
|
||||
DataSummaryProductSaleParam param = new DataSummaryProductSaleParam();
|
||||
param.setShopId(shopId);
|
||||
param.setBeginDate(startOfDay.toStringDefaultTimeZone());
|
||||
param.setEndDate(endOfDay.toStringDefaultTimeZone());
|
||||
// 删除之前统计数据
|
||||
getMapper().deleteByQuery(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, dateTime.toDateStr()));
|
||||
// 重新统计数据
|
||||
List<DataSummaryProductSaleRankingVo> list = shopProdStatisticMapper.findProdRandingSummaryPage2(param);
|
||||
for (DataSummaryProductSaleRankingVo dto : list) {
|
||||
ShopProdStatistic entity = new ShopProdStatistic();
|
||||
entity.setProdId(dto.getProductId());
|
||||
entity.setSaleCount(dto.getNumber());
|
||||
entity.setSaleAmount(dto.getAmount());
|
||||
entity.setRefundCount(dto.getRefundCount());
|
||||
entity.setRefundAmount(dto.getRefundAmount());
|
||||
entity.setShopId(shopId);
|
||||
entity.setCreateDay(dateTime.toJdkDate());
|
||||
if (NumberUtil.isLessOrEqual(entity.getSaleCount(), BigDecimal.ZERO) && NumberUtil.isLessOrEqual(entity.getRefundCount(), BigDecimal.ZERO)) {
|
||||
log.info("店铺:{},{},没有要存档的商品统计数据", shopId, dateTime.toDateStr());
|
||||
} else {
|
||||
save(entity);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
countInfo.forEach((shopId, map) -> map.forEach((productId, statisticTask) -> {
|
||||
ShopProdStatistic statistic = getOne(new QueryWrapper().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, yesterday.toSqlDate()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopProdStatistic();
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setCreateDay(yesterday.toSqlDate());
|
||||
}
|
||||
statistic.setProdId(productId);
|
||||
statistic.setSaleCount(statisticTask.getSuccessCount());
|
||||
statistic.setSaleAmount(statisticTask.getSuccessAmount());
|
||||
statistic.setRefundCount(statisticTask.getRefundCount());
|
||||
statistic.setRefundAmount(statisticTask.getRefundAmount());
|
||||
saveOrUpdate(statistic);
|
||||
}));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.order.entity.ShopTableOrderStatistic;
|
||||
import com.czg.order.param.TableSummaryParam;
|
||||
import com.czg.order.service.DataSummaryService;
|
||||
import com.czg.order.service.ShopTableOrderStatisticService;
|
||||
import com.czg.order.vo.TableSummaryInfoVo;
|
||||
import com.czg.service.order.mapper.ShopTableOrderStatisticMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.ShopTableOrderStatistic;
|
||||
import com.czg.order.service.ShopTableOrderStatisticService;
|
||||
import com.czg.service.order.mapper.ShopTableOrderStatisticMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -29,35 +30,38 @@ import java.util.List;
|
||||
* @since 2025-03-07
|
||||
*/
|
||||
@Service
|
||||
public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrderStatisticMapper, ShopTableOrderStatistic> implements ShopTableOrderStatisticService{
|
||||
@Slf4j
|
||||
public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrderStatisticMapper, ShopTableOrderStatistic> implements ShopTableOrderStatisticService {
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
private DataSummaryService dataSummaryService;
|
||||
@Resource
|
||||
private ShopTableOrderStatisticMapper shopTableOrderStatisticMapper;
|
||||
|
||||
@Override
|
||||
public Page<ShopTableOrderStatistic> summary(Long shopId, String startTime, String endTime) {
|
||||
Page<Object> page = PageUtil.buildPage();
|
||||
PageHelper.startPage(Math.toIntExact(page.getPageNumber()),Math.toIntExact(page.getPageSize()));
|
||||
PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
|
||||
return PageUtil.convert(new PageInfo<>(mapper.selectSummary(shopId, startTime, endTime)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addInfo(long shopId, long tableId, long count, BigDecimal amount) {
|
||||
ShopTableOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopTableOrderStatistic::getShopId, shopId).eq(ShopTableOrderStatistic::getTableId, tableId)
|
||||
.eq(ShopTableOrderStatistic::getCreateDay, DateUtil.date().toDateStr()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopTableOrderStatistic();
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setTableId(tableId);
|
||||
statistic.setCreateDay(DateUtil.date().toSqlDate());
|
||||
statistic.setOrderCount(count);
|
||||
statistic.setOrderAmount(amount);
|
||||
save(statistic);
|
||||
}
|
||||
return mapper.incrInfo(shopId, tableId, count, amount, DateUtil.date().toDateStr());
|
||||
ShopTableOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopTableOrderStatistic::getShopId, shopId).eq(ShopTableOrderStatistic::getTableId, tableId)
|
||||
.eq(ShopTableOrderStatistic::getCreateDay, DateUtil.date().toDateStr()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopTableOrderStatistic();
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setTableId(tableId);
|
||||
statistic.setCreateDay(DateUtil.date().toSqlDate());
|
||||
statistic.setOrderCount(count);
|
||||
statistic.setOrderAmount(amount);
|
||||
save(statistic);
|
||||
}
|
||||
return mapper.incrInfo(shopId, tableId, count, amount, DateUtil.date().toDateStr());
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class StatisticTask{
|
||||
private static class StatisticTask {
|
||||
private long successCount = 0;
|
||||
private BigDecimal successAmount = BigDecimal.ZERO;
|
||||
private long refundCount = 0;
|
||||
@@ -65,53 +69,46 @@ public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrd
|
||||
}
|
||||
|
||||
@Override
|
||||
public void statistic() {
|
||||
// 获取前一天
|
||||
DateTime yesterday = DateUtil.yesterday();
|
||||
|
||||
public void statistic(DateTime dateTime) {
|
||||
// 获取前一天的开始时间(00:00:00)
|
||||
DateTime startOfDay = DateUtil.beginOfDay(yesterday);
|
||||
|
||||
DateTime startOfDay = DateUtil.beginOfDay(dateTime);
|
||||
// 获取前一天的结束时间(23:59:59)
|
||||
DateTime endOfDay = DateUtil.endOfDay(yesterday);
|
||||
List<OrderInfo> orderInfos = orderInfoService.list(new QueryWrapper()
|
||||
.ge(OrderInfo::getCreateTime, startOfDay)
|
||||
.le(OrderInfo::getCreateTime, endOfDay)
|
||||
.ne(OrderInfo::getStatus, "unpaid").ne(OrderInfo::getStatus, "cancelled"));
|
||||
|
||||
HashMap<Long, StatisticTask> countInfo = new HashMap<>();
|
||||
for (OrderInfo item : orderInfos) {
|
||||
StatisticTask statisticTask = countInfo.get(item.getShopId());
|
||||
if (statisticTask == null) {
|
||||
countInfo.put(item.getShopId(), statisticTask = new StatisticTask());
|
||||
}
|
||||
if ("refunding".equals(item.getStatus()) || "refund".equals(item.getStatus()) || "part-refund".equals(item.getStatus())) {
|
||||
statisticTask.setRefundAmount(statisticTask.getRefundAmount().add(item.getRefundAmount()));
|
||||
statisticTask.setRefundCount(statisticTask.getRefundCount() + 1);
|
||||
if (item.getRefundAmount().compareTo(item.getPayAmount()) < 0) {
|
||||
statisticTask.setSuccessAmount(statisticTask.getSuccessAmount().add(item.getPayAmount().subtract(item.getRefundAmount())));
|
||||
}
|
||||
}else {
|
||||
statisticTask.setSuccessCount(statisticTask.getSuccessCount() + 1);
|
||||
statisticTask.setSuccessAmount(statisticTask.getSuccessAmount().add(item.getPayAmount()));
|
||||
}
|
||||
DateTime endOfDay = DateUtil.endOfDay(dateTime);
|
||||
List<Long> shopIdList = dataSummaryService.getShopIdList();
|
||||
if (CollUtil.isEmpty(shopIdList)) {
|
||||
return;
|
||||
}
|
||||
List<List<Long>> split = CollUtil.split(shopIdList, 5);
|
||||
for (List<Long> splitIdList : split) {
|
||||
splitIdList.parallelStream().forEach(shopId -> {
|
||||
TableSummaryParam param = new TableSummaryParam();
|
||||
param.setShopId(shopId);
|
||||
param.setBeginDate(startOfDay.toStringDefaultTimeZone());
|
||||
param.setEndDate(endOfDay.toStringDefaultTimeZone());
|
||||
// 删除之前统计数据
|
||||
getMapper().deleteByQuery(QueryWrapper.create().eq(ShopTableOrderStatistic::getShopId, shopId).eq(ShopTableOrderStatistic::getCreateDay, dateTime.toDateStr()));
|
||||
// 重新统计数据
|
||||
List<TableSummaryInfoVo> list = shopTableOrderStatisticMapper.findSummaryList2(param);
|
||||
for (TableSummaryInfoVo dto : list) {
|
||||
ShopTableOrderStatistic entity = new ShopTableOrderStatistic();
|
||||
entity.setTableId(dto.getTableId());
|
||||
entity.setTableCode(dto.getTableCode());
|
||||
entity.setTableName(dto.getTableName());
|
||||
entity.setAreaName(dto.getAreaName());
|
||||
entity.setOrderCount(dto.getOrderCount());
|
||||
entity.setOrderAmount(dto.getOrderAmount());
|
||||
entity.setRefundCount(dto.getRefundCount());
|
||||
entity.setRefundAmount(dto.getRefundAmount());
|
||||
entity.setShopId(shopId);
|
||||
entity.setCreateDay(dateTime.toJdkDate());
|
||||
if (entity.getOrderCount() == 0L && entity.getRefundCount() == 0L) {
|
||||
log.info("店铺:{},{},没有要存档的台桌统计数据", shopId, dateTime.toDateStr());
|
||||
} else {
|
||||
save(entity);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
countInfo.forEach((shopId, statisticTask) -> {
|
||||
ShopTableOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopTableOrderStatistic::getShopId, shopId).eq(ShopTableOrderStatistic::getCreateDay, yesterday.toSqlDate()));
|
||||
if (statistic == null) {
|
||||
statistic = new ShopTableOrderStatistic();
|
||||
statistic.setShopId(shopId);
|
||||
statistic.setTableId(0L);
|
||||
statistic.setCreateDay(yesterday.toSqlDate());
|
||||
}
|
||||
statistic.setOrderCount(statisticTask.getSuccessCount());
|
||||
statistic.setOrderAmount(statisticTask.getSuccessAmount());
|
||||
statistic.setRefundCount(statisticTask.getRefundCount());
|
||||
statistic.setRefundAmount(statisticTask.getRefundAmount());
|
||||
saveOrUpdate(statistic);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class TableSummaryServiceImpl implements TableSummaryService {
|
||||
|
||||
@Override
|
||||
public List<TableSummaryInfoVo> summaryList(TableSummaryParam param) {
|
||||
return shopTableOrderStatisticMapper.findSummaryList2(param);
|
||||
return shopTableOrderStatisticMapper.findSummaryList(param);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
<foreach item="day" collection="days" open="(" separator="," close=")">
|
||||
#{day}
|
||||
</foreach>
|
||||
group by t1.prod_id
|
||||
group by t1.prod_id,t2.name
|
||||
order by sum(t1.sale_count) desc
|
||||
</select>
|
||||
<select id="getSaleSummaryCount" resultType="com.czg.order.vo.SaleSummaryCountVo">
|
||||
select
|
||||
@@ -146,10 +147,12 @@
|
||||
t1.product_id,
|
||||
t1.product_name,
|
||||
sum(t1.num) as number,
|
||||
sum(t1.pay_amount) as amount
|
||||
sum(t1.pay_amount) as amount,
|
||||
sum(t1.return_num) AS refundCount,
|
||||
sum(t1.return_amount) AS refundAmount
|
||||
from tb_order_detail t1
|
||||
where t1.shop_id = #{shopId}
|
||||
and t1.status = 'done'
|
||||
and t1.status in ('part-refund','refund','done')
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
and t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
|
||||
</if>
|
||||
|
||||
@@ -28,9 +28,10 @@
|
||||
</select>
|
||||
<select id="findSummaryList" resultType="com.czg.order.vo.TableSummaryInfoVo">
|
||||
select
|
||||
t1.table_code,
|
||||
t1.table_id,
|
||||
ifnull(t3.name,'N/A') as area_name,
|
||||
ifnull(t2.name,'N/A') as table_name,
|
||||
t1.table_name as table_name,
|
||||
t1.area_name as area_name,
|
||||
sum(t1.order_count) as order_count,
|
||||
sum(t1.order_amount) as order_amount,
|
||||
ifnull(sum(t1.refund_count),0) as refund_count,
|
||||
@@ -45,12 +46,13 @@
|
||||
<if test="endDate != null and endDate != ''">
|
||||
and t1.create_day <= str_to_date(#{endDate}, '%Y-%m-%d')
|
||||
</if>
|
||||
group by t1.table_id
|
||||
order by sum(t1.order_count) desc,max(t1.id) desc
|
||||
group by t1.table_code
|
||||
order by sum(t1.order_count) desc,sum(t1.order_amount) desc
|
||||
</select>
|
||||
<select id="findSummaryList2" resultType="com.czg.order.vo.TableSummaryInfoVo">
|
||||
SELECT
|
||||
t1.table_code,
|
||||
t2.id as table_id,
|
||||
ifnull(t2.NAME,t1.table_code) AS table_name,
|
||||
ifnull(t3.NAME,'未知') AS area_name,
|
||||
count( t1.id ) AS order_count,
|
||||
@@ -80,8 +82,8 @@
|
||||
SELECT
|
||||
t.product_name,
|
||||
date_format(t.create_time, '%Y-%m-%d') as create_date,
|
||||
if(t.table_name = '11111111','银收客',t.table_name) as table_name,
|
||||
concat(if(t.table_name = '11111111','银收客',t.table_name),'-',date_format(t.create_time, '%Y-%m-%d')) as tableConcatDate,
|
||||
if(t.table_name = 'NONE','银收客',t.table_name) as table_name,
|
||||
concat(if(t.table_name = 'NONE','银收客',t.table_name),'-',date_format(t.create_time, '%Y-%m-%d')) as tableConcatDate,
|
||||
t.category_name,
|
||||
t.unit_name,
|
||||
group_concat(distinct t.sku_name SEPARATOR ';') as sku_name,
|
||||
@@ -95,7 +97,7 @@
|
||||
SELECT
|
||||
t1.product_id,
|
||||
t2.table_code,
|
||||
IF(t2.table_code is null or t2.table_code = '' or t6.NAME is null, '11111111', t6.NAME) AS table_name,
|
||||
IF(t2.table_code is null or t2.table_code = '' or t6.NAME is null, 'NONE', t6.NAME) AS table_name,
|
||||
t1.create_time,
|
||||
t4.NAME AS category_name,
|
||||
t3.name as product_name,
|
||||
|
||||
@@ -14,29 +14,31 @@ import com.czg.exception.CzgException;
|
||||
import com.czg.product.dto.ProdConsRelationDTO;
|
||||
import com.czg.product.dto.ProdSkuDTO;
|
||||
import com.czg.product.dto.ProductDTO;
|
||||
import com.czg.product.dto.ShopProdCategoryDTO;
|
||||
import com.czg.product.entity.*;
|
||||
import com.czg.product.enums.*;
|
||||
import com.czg.product.param.*;
|
||||
import com.czg.product.service.ConsStockFlowService;
|
||||
import com.czg.product.service.ProductService;
|
||||
import com.czg.product.service.ProductStockFlowService;
|
||||
import com.czg.product.service.SensitiveOperationService;
|
||||
import com.czg.product.service.*;
|
||||
import com.czg.product.vo.ProductStatisticsVo;
|
||||
import com.czg.product.vo.ProductVO;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.product.mapper.*;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.row.DbChain;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -73,6 +75,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
private final ConsStockFlowService consStockFlowService;
|
||||
private final SensitiveOperationService sensitiveOperationService;
|
||||
private final ProdGroupRelationMapper prodGroupRelationMapper;
|
||||
private final RedisService redisService;
|
||||
@Resource
|
||||
@Lazy
|
||||
private ShopProdCategoryService shopProdCategoryService;
|
||||
|
||||
private QueryWrapper buildQueryWrapper(ProductDTO param) {
|
||||
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||
@@ -107,8 +113,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
queryWrapper.eq(Product::getIsSale, YesNoEnum.NO.value());
|
||||
}
|
||||
}
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
queryWrapper.eq(Product::getShopId, shopId);
|
||||
if (param.getShopId() == null) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
param.setShopId(shopId);
|
||||
}
|
||||
queryWrapper.eq(Product::getShopId, param.getShopId());
|
||||
queryWrapper.eq(Product::getIsDel, DeleteEnum.NORMAL.value());
|
||||
queryWrapper.orderBy(Product::getIsSoldStock, true);
|
||||
queryWrapper.orderBy(Product::getIsSale, false);
|
||||
@@ -162,7 +171,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = ADMIN_CLIENT_PRODUCT_LIST, key = "#param.shopId", unless = "#result.isEmpty()")
|
||||
public List<ProductDTO> getProductList(ProductDTO param) {
|
||||
QueryWrapper queryWrapper = buildFullQueryWrapper(param);
|
||||
//queryWrapper.eq(Product::getIsSale, YesNoEnum.YES.value());
|
||||
@@ -171,6 +179,92 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
return records;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductDTO> getProductCacheList(ProductDTO param) {
|
||||
Long shopId = param.getShopId();
|
||||
initProductCache(shopId);
|
||||
String prefix = ADMIN_CLIENT_PRODUCT_LIST + "::" + shopId + "::";
|
||||
List<ProductDTO> list;
|
||||
if (param.getCategoryId() == null) {
|
||||
list = new ArrayList<>();
|
||||
Set<String> keys = redisService.rightLikeKey(prefix);
|
||||
for (String key : keys) {
|
||||
List<ProductDTO> prodList = redisService.getJsonToBeanList(key, ProductDTO.class);
|
||||
list.addAll(prodList);
|
||||
}
|
||||
} else {
|
||||
String key = prefix + param.getCategoryId();
|
||||
list = redisService.getJsonToBeanList(key, ProductDTO.class);
|
||||
}
|
||||
if (StrUtil.isNotEmpty(param.getName())) {
|
||||
list = list.stream().filter(obj -> StrUtil.contains(obj.getName(), param.getName())).toList();
|
||||
}
|
||||
// 重新进行排序
|
||||
list = list.stream()
|
||||
.sorted(Comparator.comparingInt(ProductDTO::getIsSoldStock))
|
||||
.sorted(Comparator.comparingInt(ProductDTO::getIsSale).reversed())
|
||||
.sorted(Comparator.comparingInt(ProductDTO::getSort).reversed())
|
||||
.sorted(Comparator.comparingLong(ProductDTO::getId).reversed())
|
||||
.toList();
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化商品缓存数据
|
||||
*/
|
||||
private void initProductCache(Long shopId) {
|
||||
ProductDTO param = new ProductDTO();
|
||||
param.setShopId(shopId);
|
||||
List<ProductDTO> productList = getProductList(param);
|
||||
Map<Long, List<ProductDTO>> categoryMap = productList.stream().filter(item -> item.getCategoryId() != null).collect(Collectors.groupingBy(ProductDTO::getCategoryId));
|
||||
ShopProdCategoryDTO dto = new ShopProdCategoryDTO();
|
||||
dto.setShopId(shopId);
|
||||
List<ShopProdCategoryDTO> categoryList = shopProdCategoryService.getShopProdCategoryList(dto);
|
||||
String prefix = ADMIN_CLIENT_PRODUCT_LIST + "::" + shopId + "::";
|
||||
for (ShopProdCategoryDTO category : categoryList) {
|
||||
String key = prefix + category.getId();
|
||||
boolean b = redisService.hasKey(key);
|
||||
if (!b) {
|
||||
List<ProductDTO> list = categoryMap.get(category.getId());
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
redisService.setJsonStr(key, list);
|
||||
} else {
|
||||
List<ProductDTO> empty = new ArrayList<>();
|
||||
redisService.setJsonStr(key, empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除某个商品分类的缓存
|
||||
*/
|
||||
@Override
|
||||
public void clearProductCache(Long... categoryIds) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
String prefix = ADMIN_CLIENT_PRODUCT_LIST + "::" + shopId + "::";
|
||||
for (Long categoryId : categoryIds) {
|
||||
redisService.del(prefix + categoryId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统启动会一次性加载商品缓存数据,防止首次访问时加载缓慢的问题
|
||||
*/
|
||||
@PostConstruct
|
||||
public void initProductListCache() {
|
||||
log.info("系统启动后初始化商品列表缓存,开始...");
|
||||
List<Long> shopIdList = DbChain.table("tb_shop_info").select("id").objListAs(Long.class);
|
||||
for (Long shopId : shopIdList) {
|
||||
log.info("商品列表缓存>>当前店铺:{}", shopId);
|
||||
ProductDTO dto = new ProductDTO();
|
||||
dto.setShopId(shopId);
|
||||
getProductCacheList(dto);
|
||||
log.info("商品列表缓存>>当前店铺:{},初始化结束", shopId);
|
||||
}
|
||||
log.info("系统启动后初始化商品列表缓存,结束。");
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算是否在可售时间内
|
||||
*
|
||||
@@ -223,7 +317,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT, ADMIN_CLIENT_PRODUCT_LIST}, key = "#dto.shopId", allEntries = true)
|
||||
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#dto.shopId", allEntries = true)
|
||||
public void addProduct(ProductDTO dto) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
boolean exists = super.exists(query().eq(Product::getName, dto.getName()).eq(Product::getShopId, shopId).eq(Product::getIsDel, DeleteEnum.NORMAL.value()));
|
||||
@@ -246,6 +340,8 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
entity.setShopId(shopId);
|
||||
super.save(entity);
|
||||
dto.setId(entity.getId());
|
||||
// 清除商品分类列表缓存
|
||||
clearProductCache(entity.getCategoryId());
|
||||
List<ProdSkuDTO> skuList = dto.getSkuList();
|
||||
if (CollUtil.isNotEmpty(skuList)) {
|
||||
List<ProdSku> prodSkuList = new ArrayList<>();
|
||||
@@ -283,7 +379,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT, ADMIN_CLIENT_PRODUCT_LIST}, key = "#dto.shopId", allEntries = true)
|
||||
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#dto.shopId", allEntries = true)
|
||||
public void updateProduct(ProductDTO dto) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
dto.setShopId(shopId);
|
||||
@@ -307,11 +403,16 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
}
|
||||
entity.setIsDel(DeleteEnum.NORMAL.value());
|
||||
entity.setShopId(shopId);
|
||||
if(!ProductTypeEnum.SKU.value().equals(entity.getType())){
|
||||
if (!ProductTypeEnum.SKU.value().equals(entity.getType())) {
|
||||
entity.setSpecId(null);
|
||||
}
|
||||
entity.setSpecId(null);
|
||||
super.updateById(entity);
|
||||
// 清除商品分类列表缓存
|
||||
if (!old.getCategoryId().equals(dto.getCategoryId())) {
|
||||
// 清除旧分类缓存&新分类缓存
|
||||
clearProductCache(old.getCategoryId(), entity.getCategoryId());
|
||||
}
|
||||
List<ProdSkuDTO> skuList = dto.getSkuList();
|
||||
// 商品SKU-ID列表
|
||||
List<Long> skuIdList = prodSkuMapper.selectListByQueryAs(query().select(ProdSku::getId).eq(ProdSku::getProductId, dto.getId()), Long.class);
|
||||
@@ -425,8 +526,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT, ADMIN_CLIENT_PRODUCT_LIST}, key = "#shopId", allEntries = true)
|
||||
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#shopId", allEntries = true)
|
||||
public void deleteProduct(Long shopId, Long id) {
|
||||
Product old = getById(id);
|
||||
Long categoryId = old.getCategoryId();
|
||||
UpdateChain.of(Product.class)
|
||||
.set(Product::getIsDel, DeleteEnum.DELETED.value())
|
||||
.eq(Product::getId, id)
|
||||
@@ -434,11 +537,13 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
.update();
|
||||
prodGroupRelationMapper.deleteByQuery(query().eq(ProdGroupRelation::getProductId, id));
|
||||
prodConsRelationMapper.deleteByQuery(query().eq(ProdConsRelation::getProductId, id));
|
||||
// 清除商品分类列表缓存
|
||||
clearProductCache(categoryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT, ADMIN_CLIENT_PRODUCT_LIST}, key = "#param.shopId", allEntries = true, beforeInvocation = true)
|
||||
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#param.shopId", allEntries = true, beforeInvocation = true)
|
||||
public void onOffProduct(ProductIsSaleParam param) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
String type = param.getType();
|
||||
@@ -450,6 +555,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
} else {
|
||||
sensitiveOperation = "下架";
|
||||
}
|
||||
Long prodId = null;
|
||||
if (ProductIsSaleTypeEnum.SKU.value().equals(type)) {
|
||||
ProdSku prodSku = prodSkuMapper.selectOneById(id);
|
||||
if (prodSku == null) {
|
||||
@@ -468,6 +574,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
.eq(Product::getId, prodSku.getProductId())
|
||||
.eq(Product::getShopId, shopId)
|
||||
.update();
|
||||
prodId = prodSku.getProductId();
|
||||
}
|
||||
Long productId = prodSku.getProductId();
|
||||
Product product = mapper.selectOneById(productId);
|
||||
@@ -484,19 +591,25 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
.eq(ProdSku::getShopId, shopId)
|
||||
.update();
|
||||
Product product = mapper.selectOneById(id);
|
||||
prodId = product.getId();
|
||||
sensitiveOperation = sensitiveOperation + "商品:" + product.getName();
|
||||
}
|
||||
sensitiveOperationService.send(sensitiveOperation);
|
||||
// 清除商品分类列表缓存
|
||||
Product old = getById(prodId);
|
||||
Long categoryId = old.getCategoryId();
|
||||
clearProductCache(categoryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT, ADMIN_CLIENT_PRODUCT_LIST}, key = "#param.shopId", allEntries = true, beforeInvocation = true)
|
||||
@CacheEvict(value = {CacheConstant.USER_CLIENT_HOTS_PRODUCT, CacheConstant.USER_CLIENT_GROUPS_PRODUCT}, key = "#param.shopId", allEntries = true, beforeInvocation = true)
|
||||
public void markProductIsSoldOut(ProductIsSoldOutParam param) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
String type = param.getType();
|
||||
Long id = param.getId();
|
||||
Integer isSoldOut = param.getIsSoldOut();
|
||||
Long prodId = null;
|
||||
if (ProductIsSaleTypeEnum.SKU.value().equals(type)) {
|
||||
ProdSku prodSku = prodSkuMapper.selectOneById(id);
|
||||
if (prodSku == null) {
|
||||
@@ -516,6 +629,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
.eq(Product::getShopId, shopId)
|
||||
.update();
|
||||
}
|
||||
prodId = prodSku.getProductId();
|
||||
} else if (ProductIsSaleTypeEnum.PRODUCT.value().equals(type)) {
|
||||
UpdateChain.of(Product.class)
|
||||
.set(Product::getIsSoldStock, isSoldOut)
|
||||
@@ -527,7 +641,12 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
.eq(ProdSku::getProductId, id)
|
||||
.eq(ProdSku::getShopId, shopId)
|
||||
.update();
|
||||
prodId = id;
|
||||
}
|
||||
// 清除商品分类列表缓存
|
||||
Product old = getById(prodId);
|
||||
Long categoryId = old.getCategoryId();
|
||||
clearProductCache(categoryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.czg.enums.StatusEnum;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.product.dto.ShopProdCategoryDTO;
|
||||
import com.czg.product.entity.ShopProdCategory;
|
||||
import com.czg.product.service.ProductService;
|
||||
import com.czg.product.service.ShopProdCategoryService;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.product.mapper.ShopProdCategoryMapper;
|
||||
@@ -14,6 +15,8 @@ import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@@ -27,13 +30,20 @@ import java.util.List;
|
||||
@Service
|
||||
public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMapper, ShopProdCategory> implements ShopProdCategoryService {
|
||||
|
||||
@Resource
|
||||
@Lazy
|
||||
private ProductService productService;
|
||||
|
||||
private QueryWrapper buildQueryWrapper(ShopProdCategoryDTO param) {
|
||||
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||
if (StrUtil.isNotEmpty(param.getName())) {
|
||||
queryWrapper.like(ShopProdCategory::getName, param.getName());
|
||||
}
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
queryWrapper.eq(ShopProdCategory::getShopId, shopId);
|
||||
if (param.getShopId() == null) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
param.setShopId(shopId);
|
||||
}
|
||||
queryWrapper.eq(ShopProdCategory::getShopId, param.getShopId());
|
||||
queryWrapper.orderBy(ShopProdCategory::getSort, true);
|
||||
queryWrapper.orderBy(ShopProdCategory::getId, false);
|
||||
return queryWrapper;
|
||||
@@ -93,6 +103,7 @@ public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMap
|
||||
public void deleteShopProdCategory(Long id) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
super.remove(query().eq(ShopProdCategory::getId, id).eq(ShopProdCategory::getShopId, shopId));
|
||||
productService.clearProductCache(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,6 +114,7 @@ public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMap
|
||||
.eq(ShopProdCategory::getId, id)
|
||||
.eq(ShopProdCategory::getShopId, shopId)
|
||||
.update();
|
||||
productService.clearProductCache(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,6 +125,7 @@ public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMap
|
||||
.eq(ShopProdCategory::getId, id)
|
||||
.eq(ShopProdCategory::getShopId, shopId)
|
||||
.update();
|
||||
productService.clearProductCache(id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user