增加时间方法,增加汇总部分数据,分类更改

This commit is contained in:
liuyingfang
2024-03-11 09:07:11 +08:00
parent e0291db00d
commit bcfa3f9984
17 changed files with 267 additions and 57 deletions

View File

@@ -1,10 +1,16 @@
package cn.ysk.cashier.service;
import cn.ysk.cashier.repository.mapping.SumDateMapping;
import cn.ysk.cashier.vo.SummaryVO;
import java.util.List;
import java.util.Map;
/**
* @author lyf
*/
public interface SummaryService {
SummaryVO selectSummary(Integer shop);
Map<String,Object> selectSummaryDate(Integer shopId, Integer day);
}

View File

@@ -1,10 +1,13 @@
package cn.ysk.cashier.service.impl;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import cn.ysk.cashier.repository.ShopUserDutyDetailRepository;
import cn.ysk.cashier.repository.ShopUserDutyRepository;
import cn.ysk.cashier.repository.mapping.CountPayTypeMapping;
import cn.ysk.cashier.repository.mapping.SumDateMapping;
import cn.ysk.cashier.repository.order.TbOrderInfoRepository;
import cn.ysk.cashier.repository.shop.TbShopUserRepository;
import cn.ysk.cashier.service.SummaryService;
import cn.ysk.cashier.utils.DateUtil;
import cn.ysk.cashier.vo.SummaryVO;
import cn.ysk.cashier.vo.ProductVO;
import lombok.RequiredArgsConstructor;
@@ -14,8 +17,7 @@ import javax.annotation.Resource;
import javax.persistence.Tuple;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
@@ -25,15 +27,57 @@ public class SummaryServiceImpl implements SummaryService {
private ShopUserDutyRepository shopUserDutyRepository;
@Resource
private ShopUserDutyDetailRepository shopUserDutyDetailRepository;
@Resource
private TbShopUserRepository tbShopUserRepository;
@Resource
private TbOrderInfoRepository tbOrderInfoRepository;
@Override
public SummaryVO selectSummary(Integer shopId) {
SummaryVO summaryVO = new SummaryVO();
//支付笔数
Tuple result = shopUserDutyRepository.sumByShopId(shopId);
summaryVO.setPaymentsNumber(result.get(0, Long.class));
summaryVO.setTotalSales(result.get(1, BigDecimal.class));
List<Object[]> objects = shopUserDutyDetailRepository.searchByDutyId(shopId);
summaryVO.setPaymentsNumber(result.get(0, Long.class) == null?0L : result.get(0, Long.class));
summaryVO.setTotalSales(result.get(1, BigDecimal.class) == null? new BigDecimal("0") : result.get(1, BigDecimal.class));
// List<Object[]> objects = shopUserDutyDetailRepository.searchByDutyId(shopId);
//商品销量排行前五
// 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);
// }
// summaryVO.setProductInfoList(list);
if (summaryVO.getPaymentsNumber() == 0){
summaryVO.setAverageSales(new BigDecimal("0"));
}else {
summaryVO.setAverageSales(summaryVO.getTotalSales().divide(new BigDecimal(summaryVO.getPaymentsNumber()), 2, RoundingMode.DOWN));
}
//用户数
Tuple count = tbShopUserRepository.searchByCount(shopId.toString());
summaryVO.setTotalUser(count.get(0, Long.class));
return summaryVO;
}
@Override
public Map<String,Object> selectSummaryDate(Integer shopId, Integer day) {
Date startTime = new Date();
Date endTime = new Date();
if (day == 7){
startTime = DateUtil.getBeginDayOfWeek();
endTime = DateUtil.getEndDayOfWeek();
}else if (day == 30){
startTime = DateUtil.getBeginDayOfMonth();
endTime = DateUtil.getEndDayOfMonth();
}
HashMap<String, Object> map = new HashMap<>();
//根据时间的营业额
List<SumDateMapping> sumDateMappings = shopUserDutyRepository.sumByDate(shopId,startTime,endTime);
//根据时间商品排行
List<Object[]> objects = shopUserDutyDetailRepository.searchByDutyId(shopId,startTime,endTime);
//商品销量排行前五
List<ProductVO> list = new ArrayList<>();
for (Object[] o :objects) {
ProductVO productVO = new ProductVO();
@@ -42,8 +86,15 @@ public class SummaryServiceImpl implements SummaryService {
productVO.setProductNum((BigDecimal)o[2]);
list.add(productVO);
}
summaryVO.setProductInfoList(list);
summaryVO.setAverageSales(summaryVO.getTotalSales().divide(new BigDecimal(summaryVO.getPaymentsNumber()),2, RoundingMode.DOWN));
return summaryVO;
list = list.stream()
.sorted(Comparator.comparing(ProductVO::getProductNum).reversed()) // 降序排序
.collect(Collectors.toList());
map.put("total",sumDateMappings);
map.put("totalProduct",list);
//支付类型占比
List<CountPayTypeMapping> countPayTypeMappings = tbOrderInfoRepository.countByShopId(shopId.toString());
map.put("countPayType",countPayTypeMappings);
return map;
}
}

View File

@@ -25,6 +25,7 @@ import cn.ysk.cashier.service.product.TbShopCategoryService;
import cn.ysk.cashier.dto.product.TbShopCategoryDto;
import cn.ysk.cashier.dto.product.TbShopCategoryQueryCriteria;
import cn.ysk.cashier.mapper.product.TbShopCategoryMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
@@ -36,12 +37,9 @@ import cn.ysk.cashier.utils.PageUtil;
import cn.ysk.cashier.utils.QueryHelp;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.stream.Collectors;
/**
@@ -58,9 +56,9 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
private final TbShopCategoryMapper tbShopCategoryMapper;
@Override
public Map<String,Object> queryAll(TbShopCategoryQueryCriteria criteria, Pageable pageable){
PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("sort"));
Page<TbShopCategory> page = tbShopCategoryRepository.findAllBy(criteria.getShopId(), pageable);
public Map<String,Object> queryAll(TbShopCategoryQueryCriteria criteria){
PageRequest sort = PageRequest.of(criteria.getPage(), criteria.getSize(), Sort.by("sort"));
Page<TbShopCategory> page = tbShopCategoryRepository.findAllBy(criteria.getShopId(), sort);
List<Integer> treeId = new ArrayList<>();
for (TbShopCategory category : page.getContent()) {
@@ -81,6 +79,7 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
tbShopCategoryChildren.add(tbShopCategory);
}
}
TbShopCategoryDto tbShopCategoryDto = new TbShopCategoryDto();
tbShopCategoryDto.setChildrenList(tbShopCategoryChildren);
BeanUtils.copyProperties(category, tbShopCategoryDto);
@@ -93,10 +92,10 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
return PageUtil.toPage(result, page.getTotalElements()-children.size());
}
@Override
public List<TbShopCategoryDto> queryAll(TbShopCategoryQueryCriteria criteria){
return tbShopCategoryMapper.toDto(tbShopCategoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
// @Override
// public List<TbShopCategoryDto> queryAll(TbShopCategoryQueryCriteria criteria){
// return tbShopCategoryMapper.toDto(tbShopCategoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
// }
@Override
@Transactional
@@ -115,9 +114,7 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
if (byName != null){
throw new BadRequestException("分类名称重复");
}
if (resources.getPid() == null || "".equals(resources.getPid())){
resources.setTree(resources.getId());
}else {
if (StringUtils.isNotBlank(resources.getPid())){
resources.setTree(Integer.valueOf(resources.getPid().trim()));
}
return tbShopCategoryRepository.save(resources);
@@ -130,8 +127,6 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
if (resources.getName() == null || resources.getShopId() == null){
throw new BadRequestException("必要参数为空");
}
TbShopCategory byName = tbShopCategoryRepository.findByName(resources.getName(), resources.getShopId());
resources.setUpdatedAt(Instant.now().toEpochMilli());
ValidationUtil.isNull( tbShopCategory.getId(),"TbShopCategory","id",resources.getId());
tbShopCategory.copy(resources);

View File

@@ -124,8 +124,9 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
}
}
TbShopInfo byAccount = tbShopInfoRepository.findByAccount(resources.getAccount());
if (byAccount != null){
throw new BadRequestException("登录名重复");
User byUsername = userRepository.findByUsername(resources.getAccount());
if (byAccount != null || byUsername.getId() != null){
throw new BadRequestException("登录名已注册");
}
TbShopInfo tbShopInfo = new TbShopInfo();
@@ -155,8 +156,6 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
tbMerchantRegister.setShopId(String.valueOf(save.getId()));
tbMerchantRegister.setName(save.getShopName());
merchantRegisterRepository.save(tbMerchantRegister);
}
//增加商户登录账号
TbMerchantAccount tbMerchantAccount = new TbMerchantAccount();

View File

@@ -35,17 +35,16 @@ public interface TbShopCategoryService {
/**
* 查询数据分页
* @param criteria 条件
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(TbShopCategoryQueryCriteria criteria, Pageable pageable);
Map<String,Object> queryAll(TbShopCategoryQueryCriteria criteria);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<TbShopCategoryDto>
*/
List<TbShopCategoryDto> queryAll(TbShopCategoryQueryCriteria criteria);
// List<TbShopCategoryDto> queryAll(TbShopCategoryQueryCriteria criteria);
/**
* 根据ID查询