完善首页数据
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.ysk.cashier.enums.PayTypeEnum;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.repository.ShopUserDutyDetailRepository;
|
||||
import cn.ysk.cashier.repository.ShopUserDutyRepository;
|
||||
import cn.ysk.cashier.repository.TbTokenRepository;
|
||||
import cn.ysk.cashier.repository.mapping.CountPayTypeMapping;
|
||||
import cn.ysk.cashier.repository.mapping.SumDateMapping;
|
||||
import cn.ysk.cashier.repository.order.TbOrderInfoRepository;
|
||||
@@ -36,6 +37,8 @@ public class SummaryServiceImpl implements SummaryService {
|
||||
private TbShopUserRepository tbShopUserRepository;
|
||||
@Resource
|
||||
private TbOrderInfoRepository tbOrderInfoRepository;
|
||||
@Resource
|
||||
private TbTokenRepository tbTokenRepository;
|
||||
@Override
|
||||
public SummaryVO selectSummary(Integer shopId) {
|
||||
SummaryVO summaryVO = new SummaryVO();
|
||||
@@ -88,53 +91,81 @@ public class SummaryServiceImpl implements SummaryService {
|
||||
countDateLists.add(countDateVO);
|
||||
}
|
||||
summaryVO.setCountDateList(countDateLists);
|
||||
//用户数折线图
|
||||
//访问量
|
||||
Tuple tuple = tbTokenRepository.countByAccountId(shopId);
|
||||
summaryVO.setTotalVisits(tuple.get(0, Long.class));
|
||||
//访问量柱状图
|
||||
List<Object[]> objectsVisits = tbTokenRepository.countByMonth(shopId, DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd());
|
||||
List<CountVisitsVO> visitsList = new ArrayList<>();
|
||||
for (Object[] o :objectsVisits){
|
||||
CountVisitsVO countDateVO = new CountVisitsVO();
|
||||
countDateVO.setCount((BigInteger) o[0]);
|
||||
countDateVO.setTradeDay((String) o[1]);
|
||||
visitsList.add(countDateVO);
|
||||
}
|
||||
//填充日期
|
||||
Map<String, CountVisitsVO> dataVisitsMap = new HashMap<>();
|
||||
for (CountVisitsVO entry : visitsList) {
|
||||
String tradeDay = entry.getTradeDay();
|
||||
BigInteger countOrder = entry.getCount();
|
||||
dataVisitsMap.put(tradeDay, new CountVisitsVO(tradeDay, countOrder));
|
||||
}
|
||||
// 转换为字符串
|
||||
List<CountVisitsVO> countVisitsLists = new ArrayList<>();
|
||||
for (int i = 0; i < 30; i++) {
|
||||
LocalDate tradeDayLocalDate = today.minusDays(i);
|
||||
String tradeDayString = tradeDayLocalDate.format(formatter);
|
||||
CountVisitsVO countDateVO;
|
||||
// 检查数据Map中是否存在该日期的数据
|
||||
if (dataVisitsMap.containsKey(tradeDayString)) {
|
||||
countDateVO = dataVisitsMap.get(tradeDayString);
|
||||
} else {
|
||||
// 如果不存在,则创建新的SumDateVO对象,amount设为0
|
||||
countDateVO = new CountVisitsVO(tradeDayString, BigInteger.ZERO);
|
||||
}
|
||||
// 将SumDateVO对象添加到列表中
|
||||
countVisitsLists.add(countDateVO);
|
||||
}
|
||||
summaryVO.setVisitsCountList(countVisitsLists);
|
||||
return summaryVO;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String,Object> selectSummaryDate(Integer shopId, Integer day) {
|
||||
Date startTime = new Date();
|
||||
Date endTime = new Date();
|
||||
List<Object[]> sumDateMappings = new ArrayList<>();
|
||||
if (day == 7){
|
||||
startTime = DateUtil.getDate7DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
sumDateMappings=shopUserDutyRepository.sumByDate(shopId,startTime,endTime);
|
||||
}else if (day == 30){
|
||||
startTime = DateUtil.getDate30DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
sumDateMappings=shopUserDutyRepository.sumByDate(shopId,startTime,endTime);
|
||||
}else if (day == 360){
|
||||
startTime = DateUtil.getBeginDayOfYear();
|
||||
endTime = DateUtil.getDateOneYearAgo();
|
||||
sumDateMappings=shopUserDutyRepository.sumByDate(shopId,DateUtil.getDate30DaysAgo(),DateUtil.getDayEnd());
|
||||
}
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
// //根据时间商品排行
|
||||
// List<Object[]> objects = shopUserDutyDetailRepository.searchByDutyId(shopId,startTime,endTime);
|
||||
Tuple tuple = shopUserDutyDetailRepository.searchByDutyIdSum(shopId, startTime, endTime);
|
||||
List<Object[]> objects = shopUserDutyDetailRepository.searchByDutyGroup(shopId, DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd());
|
||||
List<CountDateVO> numList = new ArrayList<>();
|
||||
for (Object[] o :objects) {
|
||||
CountDateVO countDateVO = new CountDateVO();
|
||||
countDateVO.setCount((BigDecimal) o[0]);
|
||||
countDateVO.setTradeDay((String) o[1]);
|
||||
numList.add(countDateVO);
|
||||
}
|
||||
List<Object[]> objects1 = shopUserDutyDetailRepository.searchByGroup(shopId, DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd());
|
||||
List<CountDateVO> amountList = new ArrayList<>();
|
||||
for (Object[] o :objects1) {
|
||||
CountDateVO countDateVO = new CountDateVO();
|
||||
countDateVO.setCount((BigDecimal) o[0]);
|
||||
countDateVO.setTradeDay((String) o[1]);
|
||||
amountList.add(countDateVO);
|
||||
}
|
||||
map.put("productCount",tuple.get(0, BigDecimal.class));
|
||||
map.put("productSum",tuple.get(1, BigDecimal.class));
|
||||
//商品销量排行前五
|
||||
List<ProductVO> list = new ArrayList<>();
|
||||
// for (Object[] o :objects) {
|
||||
// ProductVO productVO = new ProductVO();
|
||||
// productVO.setProductId((Integer) o[0]);
|
||||
// productVO.setProductName((String) o[1]);
|
||||
// productVO.setProductNum((BigDecimal)o[2]);
|
||||
// list.add(productVO);
|
||||
// }
|
||||
// list = list.stream()
|
||||
// .sorted(Comparator.comparing(ProductVO::getProductNum).reversed()) // 降序排序
|
||||
// .collect(Collectors.toList());
|
||||
//
|
||||
// map.put("totalProduct",list);
|
||||
//支付类型占比
|
||||
// List<CountPayTypeMapping> countPayTypeMappings = tbOrderInfoRepository.countByShopId(shopId.toString());
|
||||
// map.put("countPayType",countPayTypeMappings);
|
||||
map.put("numList",numList);
|
||||
map.put("amountList",amountList);
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -169,10 +200,12 @@ public class SummaryServiceImpl implements SummaryService {
|
||||
}
|
||||
//汇总数据
|
||||
Tuple tuple = shopUserDutyDetailRepository.searchByDutyIdSum(shopId, startTime, endTime);
|
||||
//分页数据
|
||||
Tuple tuple1 = shopUserDutyDetailRepository.searchCount(shopId, startTime, endTime);
|
||||
map.put("productCount",tuple.get(0, BigDecimal.class));
|
||||
map.put("productSum",tuple.get(1, BigDecimal.class));
|
||||
// List<Object[]> objects1 = shopUserDutyDetailRepository.searchByDayToAmount(shopId, startTime, endTime);
|
||||
map.put("totalProduct",list);
|
||||
map.put("total",tuple1.get(0, BigInteger.class));
|
||||
return map;
|
||||
}
|
||||
@Override
|
||||
@@ -226,6 +259,9 @@ public class SummaryServiceImpl implements SummaryService {
|
||||
// 将SumDateVO对象添加到列表中
|
||||
sumDateList.add(sumDateVO);
|
||||
}
|
||||
|
||||
|
||||
sumDateList.sort((a,b)->a.getTradeDay().compareTo(b.getTradeDay()));
|
||||
map.put("total",sumDateList);
|
||||
return map;
|
||||
}
|
||||
@@ -238,6 +274,8 @@ public class SummaryServiceImpl implements SummaryService {
|
||||
map.put("totalSalesToday", tuple.get(1, BigDecimal.class) == null? new BigDecimal("0") : tuple.get(1, BigDecimal.class));
|
||||
Tuple tuple1 = tbShopUserRepository.searchByCountToday(shopId.toString(), DateUtil.getTodayStartTimestamp(), DateUtil.getTodayEndTimestamp());
|
||||
map.put("userToday", tuple1.get(0, Long.class));
|
||||
Tuple tupleToday = tbTokenRepository.countByAccountId(shopId, DateUtil.getDayBegin(), DateUtil.getDayEnd());
|
||||
map.put("totalVisitsToday",tupleToday);
|
||||
return map;
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -319,16 +319,22 @@ public class TbProductServiceImpl implements TbProductService {
|
||||
|
||||
//sku
|
||||
if (resources.getSkuList() != null) {
|
||||
if ("sku".equals(save.getTypeEnum())) {
|
||||
tbProductSkuRepository.deleteByProductId(String.valueOf(save.getId()));
|
||||
}
|
||||
List<TbProductSku> skuList = new ArrayList<>();
|
||||
for (TbProductSku sku : resources.getSkuList()) {
|
||||
sku.setProductId(String.valueOf(save.getId()));
|
||||
sku.setShopId(save.getShopId());
|
||||
sku.setCreatedAt(Instant.now().toEpochMilli());
|
||||
sku.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
skuList.add(sku);
|
||||
TbProductSku tbProductSku = tbProductSkuRepository.searchBarCode(sku.getBarCode());
|
||||
if (tbProductSku != null){
|
||||
tbProductSkuRepository.updateByBarCode(sku.getBarCode(),sku.getCostPrice(),sku.getCoverImg(),sku.getFirstShared(),sku.getMemberPrice(),
|
||||
sku.getOriginPrice(),sku.getSalePrice(),sku.getSpecSnap(),sku.getStockNumber(),tbProductSku.getId());
|
||||
}else {
|
||||
if ("sku".equals(save.getTypeEnum())) {
|
||||
tbProductSkuRepository.deleteByProductId(String.valueOf(save.getId()));
|
||||
}
|
||||
sku.setProductId(String.valueOf(save.getId()));
|
||||
sku.setShopId(save.getShopId());
|
||||
sku.setCreatedAt(Instant.now().toEpochMilli());
|
||||
sku.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
skuList.add(sku);
|
||||
}
|
||||
}
|
||||
tbProductSkuRepository.saveAll(skuList);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user