Merge branch 'test' into dev

# Conflicts:
#	eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java
This commit is contained in:
2024-08-16 09:23:43 +08:00
16 changed files with 269 additions and 154 deletions

View File

@@ -37,7 +37,7 @@ public interface SummaryService {
*/
void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException;
List<TbOrderPayCountVo> summaryCount(String shopId, Date startTime, Date endTime);
List<TbOrderPayCountVo> summaryCount(ShopSummaryDto summaryDto, Date startTime, Date endTime);
List<ShopTableSaleInfoVo> selectSummaryTable(Integer shopId, Date startTime, Date endTime);

View File

@@ -4,16 +4,12 @@ import cn.ysk.cashier.dto.ShopSummaryDto;
import cn.ysk.cashier.dto.shop.ShopTableSeleInfoDto;
import cn.ysk.cashier.enums.PayTypeEnum;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.mybatis.mapper.TbOrderInfoMapper;
import cn.ysk.cashier.mybatis.service.TbShopUserFlowService;
import cn.ysk.cashier.pojo.shop.TbShopTable;
import cn.ysk.cashier.repository.ShopUserDutyDetailRepository;
import cn.ysk.cashier.repository.ShopUserDutyRepository;
import cn.ysk.cashier.repository.TbTokenRepository;
import cn.ysk.cashier.repository.order.TbOrderDetailRepository;
import cn.ysk.cashier.repository.order.TbOrderInfoRepository;
import cn.ysk.cashier.repository.shop.TbShopAreaRepository;
import cn.ysk.cashier.repository.shop.TbShopTableRepository;
import cn.ysk.cashier.repository.shop.TbShopUserRepository;
import cn.ysk.cashier.service.SummaryService;
import cn.ysk.cashier.utils.DateUtil;
@@ -22,6 +18,7 @@ import cn.ysk.cashier.vo.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@@ -34,13 +31,11 @@ import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -64,13 +59,8 @@ public class SummaryServiceImpl implements SummaryService {
@Resource
private TbShopUserFlowService tbShopUserFlowService;
@Resource
private TbShopTableRepository shopTableRepository;
@Resource
TbShopAreaRepository tbShopAreaRepository;
private final TbOrderInfoMapper orderInfoMapper;
@Autowired
private TbOrderDetailRepository tbOrderDetailRepository;
@Override
@@ -369,7 +359,7 @@ public class SummaryServiceImpl implements SummaryService {
@Override
public <T> Page<T> selectSummaryByDay(ShopSummaryDto summaryDto, Integer page, Integer size) {
Pageable pageable = PageRequest.of(page, size);
if(StringUtils.isBlank(summaryDto.getCateId())){
if (StringUtils.isBlank(summaryDto.getCateId())) {
summaryDto.setCateId(null);
}
if (summaryDto.getType() != null && summaryDto.getType() == 1) {//金额
@@ -403,19 +393,18 @@ public class SummaryServiceImpl implements SummaryService {
summaryDto.setStartTime(DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L)));
summaryDto.setEndTime(new Date());
}
return (Page<T>) detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime(), pageable);
return (Page<T>) detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()), summaryDto.getCateId(), summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime(), pageable);
}
}
@Override
public void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException {
// List<Map<String, Object>> list = new ArrayList<>();
ConcurrentLinkedQueue<Map<String, Object>> list = new ConcurrentLinkedQueue();
if(StringUtils.isBlank(summaryDto.getCateId())){
List<Map<String, Object>> list = new ArrayList<>();
if (StringUtils.isBlank(summaryDto.getCateId())) {
summaryDto.setCateId(null);
}
List<Integer> mergeRowIndex = Collections.synchronizedList(new ArrayList<>());
if (summaryDto.getType() != null && summaryDto.getType() == 1) {//金额
Long start = 1704038400000L;
Long end = Instant.now().toEpochMilli();
@@ -440,71 +429,28 @@ public class SummaryServiceImpl implements SummaryService {
summaryDto.setEndTime(new Date());
}
List<TbOrderSalesCountByDayVo> tbOrderSalesCountByDayVos = detailRepository
.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime());
ArrayList<Integer> skuIds = new ArrayList<>();
for (TbOrderSalesCountByDayVo tbOrderSalesCountByDayVo : tbOrderSalesCountByDayVos) {
if (tbOrderSalesCountByDayVo.getProductSkuId() != null) {
skuIds.add(tbOrderSalesCountByDayVo.getProductSkuId());
}
}
HashMap<String, List<TbOrderSaleVO>> saleOrderMap = new HashMap<>();
if (!skuIds.isEmpty()) {
List<TbOrderSaleVO> tbOrderSaleVOS = orderInfoMapper.selectAllSaleInfo(new Timestamp(summaryDto.getStartTime().getTime()),
new Timestamp(summaryDto.getEndTime().getTime()), skuIds, Integer.valueOf(summaryDto.getShopId()));
for (TbOrderSaleVO tbOrderSaleVO : tbOrderSaleVOS) {
List<TbOrderSaleVO> orderSaleVOS = saleOrderMap.get(tbOrderSaleVO.getSkuId().toString());
if (orderSaleVOS == null) {
orderSaleVOS = new ArrayList<>();
}
orderSaleVOS.add(tbOrderSaleVO);
saleOrderMap.put(tbOrderSaleVO.getSkuId().toString(), orderSaleVOS);
}
}
.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()), summaryDto.getCateId(), summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime());
tbOrderSalesCountByDayVos.forEach(all -> {
List<TbOrderSaleVO> tbOrderSaleVOS = saleOrderMap.get(all.getProductSkuId().toString());
if (tbOrderSaleVOS == null) {
return;
}
// List<TbOrderSaleVO> tbOrderSaleVOS = detailRepository.querySaleOrderInfo(new Timestamp(summaryDto.getStartTime().getTime()),
// new Timestamp(summaryDto.getEndTime().getTime()), all.getProductId(), all.getProductSkuId(), Integer.valueOf(summaryDto.getShopId()));
for (TbOrderSaleVO tbOrderSaleVO : tbOrderSaleVOS) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("商品分类", all.getCateName());
map.put("商品名称", all.getProductName());
map.put("单 位", all.getUnitName());
map.put("商品规格", StringUtils.isBlank(all.getProductSkuName()) ? "" : all.getProductSkuName());
map.put("销 售 额", all.getSalesAmount());
map.put("销 量", all.getSalesNum());
map.put("单 价", all.getPrice());
map.put("退 单 量", all.getRefNum());
map.put("退 单 额", all.getRefAmount().compareTo(BigDecimal.ZERO)==0?all.getRefAmount():"-"+all.getRefAmount());
map.put("总 量", all.getNum()-all.getRefNum());
map.put("订单编号", tbOrderSaleVO.getOrderNo());
map.put("售出数量", tbOrderSaleVO.getNum());
list.add(map);
}
if (!tbOrderSaleVOS.isEmpty()) {
if (mergeRowIndex.isEmpty()) {
mergeRowIndex.add(tbOrderSaleVOS.size());
}else {
mergeRowIndex.add(mergeRowIndex.get(mergeRowIndex.size() - 1) + tbOrderSaleVOS.size());
}
}
Map<String, Object> map = new LinkedHashMap<>();
map.put("商品分类", all.getCateName());
map.put("商品名称", all.getProductName());
map.put("单 位", all.getUnitName());
map.put("商品规格", StringUtils.isBlank(all.getProductSkuName()) ? "" : all.getProductSkuName());
map.put("单 价", all.getPrice());
map.put("销 售 额", all.getSalesAmount());
map.put("退 单 额", all.getRefAmount().compareTo(BigDecimal.ZERO) == 0 ? all.getRefAmount() : "-" + all.getRefAmount());
map.put("总 销 量", all.getNum() - all.getRefNum());
map.put("实际销量", all.getSalesNum());
map.put("退 单 量", all.getRefNum());
list.add(map);
});
}
FileUtil.downloadExcelAndMerge(list, 10, response, mergeRowIndex);
FileUtil.downloadExcel(list, response);
}
@Override
public List<TbOrderPayCountVo> summaryCount(String shopId, Date startTime, Date endTime) {
public List<TbOrderPayCountVo> summaryCount(ShopSummaryDto summaryDto, Date startTime, Date endTime) {
List<TbOrderPayCountVo> list = new ArrayList<>();
Long start = 1704038400000L;
Long end = Instant.now().toEpochMilli();
@@ -515,23 +461,35 @@ public class SummaryServiceImpl implements SummaryService {
startTime = DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L));
endTime = new Date();
}
TbOrderPayCountVo payCount = tbOrderInfoRepository.queryOrderPayCount(shopId, start, end);
TbOrderPayCountVo refCount = tbOrderInfoRepository.queryTbOrderRefund(shopId, null,start, end);
payCount.setPayAmount(new BigDecimal(payCount.getPayAmount().toString()).subtract(new BigDecimal(refCount.getPayAmount().toString())));
payCount.setIcon("el-icon-coin");
list.add(payCount);
TbOrderPayCountVo cashCount = tbOrderInfoRepository.queryOrderPayCash(shopId, start, end);
cashCount.setIcon("el-icon-circle-check");
list.add(cashCount);
refCount.setPayType("退款金额");
refCount.setIcon("el-icon-money");
list.add(refCount);
if (summaryDto.getType() != null && summaryDto.getType() == 1) {
TbOrderPayCountVo payCount = tbOrderInfoRepository.queryOrderPayCount(summaryDto.getShopId(), start, end);
TbOrderPayCountVo refCount = tbOrderInfoRepository.queryTbOrderRefund(summaryDto.getShopId(), null,start, end);
payCount.setPayAmount(new BigDecimal(payCount.getPayAmount().toString()).subtract(new BigDecimal(refCount.getPayAmount().toString())));
payCount.setIcon("el-icon-coin");
list.add(payCount);
TbOrderPayCountVo cashCount = tbOrderInfoRepository.queryOrderPayCash(summaryDto.getShopId(), start, end);
cashCount.setIcon("el-icon-circle-check");
list.add(cashCount);
refCount.setPayType("退款金额");
refCount.setIcon("el-icon-money");
list.add(refCount);
TbOrderSalesCountByDayVo numCount = detailRepository.queryTbOrderSalesCount(Integer.valueOf(shopId), startTime, endTime);
TbOrderPayCountVo salesNum =new TbOrderPayCountVo("el-icon-goods","销售量","0",numCount.getSalesNum()-numCount.getRefNum());
TbOrderPayCountVo refNum =new TbOrderPayCountVo("el-icon-goods","退单量","0",numCount.getRefNum());
list.add(salesNum);
list.add(refNum);
TbOrderSalesCountByDayVo numCount = detailRepository.queryTbOrderSalesCount(Integer.valueOf(summaryDto.getShopId()), startTime, endTime);
TbOrderPayCountVo salesNum =new TbOrderPayCountVo("el-icon-goods","销售量","0",numCount.getSalesNum()-numCount.getRefNum());
TbOrderPayCountVo refNum =new TbOrderPayCountVo("el-icon-goods","退单量","0",numCount.getRefNum());
list.add(salesNum);
list.add(refNum);
}else {
TbOrderSalesCountByDayVo tbOrderSalesCountByDayVo = detailRepository.queryTbOrderSalesCountByDaysummaryCount(Integer.valueOf(summaryDto.getShopId()), summaryDto.getCateId(), summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime());
TbOrderPayCountVo zong =new TbOrderPayCountVo("el-icon-coin","总金额","1",tbOrderSalesCountByDayVo.getSalesAmount());
TbOrderPayCountVo tuikuan =new TbOrderPayCountVo("el-icon-money","退款金额","1",tbOrderSalesCountByDayVo.getRefAmount());
TbOrderPayCountVo xiaoliang =new TbOrderPayCountVo("el-icon-goods","销售量","0",tbOrderSalesCountByDayVo.getSalesNum());
TbOrderPayCountVo tuidan =new TbOrderPayCountVo("el-icon-goods","退单量","0",tbOrderSalesCountByDayVo.getRefNum());
list.add(zong);
list.add(tuikuan);
list.add(xiaoliang);
list.add(tuidan);
}
return list;
}
@@ -594,20 +552,43 @@ public class SummaryServiceImpl implements SummaryService {
List<ShopTableSaleInfoVo> infoVos = selectSummaryTable(shopTableSeleInfoDto.getShopId(), shopTableSeleInfoDto.getStartTime(), shopTableSeleInfoDto.getEndTime());
List<Map<String, Object>> list = new ArrayList<>();
List<TbOrderSalesCountByTable> countByTables = tbOrderDetailRepository.queryTbOrderSalesCountByTable(shopTableSeleInfoDto.getShopId(), shopTableSeleInfoDto.getStartTime(), shopTableSeleInfoDto.getEndTime());
Map<String, List<TbOrderSalesCountByTable>> countByTableMap = countByTables.stream()
.collect(Collectors.groupingBy(TbOrderSalesCountByTable::getTableId));
ConcurrentLinkedQueue<Map<String, Object>> list = new ConcurrentLinkedQueue<>();
ArrayList<Integer> mergeRowIndex = new ArrayList<>();
for (ShopTableSaleInfoVo all : infoVos) {
Map<String, Object> map = new LinkedHashMap<>();
List<TbOrderSalesCountByTable> tables = countByTableMap.get(all.getTableCode());
if (tables == null) {
continue;
}
map.put("开始时间", shopTableSeleInfoDto.getStartTime());
map.put("结束时间", shopTableSeleInfoDto.getEndTime());
map.put("区域名称", all.getAreaName());
map.put("桌台名称", all.getTableName());
map.put("订单数量", all.getOrderCount());
map.put("销售额", all.getOrderAmount());
for (TbOrderSalesCountByTable table : tables) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("开始时间", shopTableSeleInfoDto.getStartTime());
map.put("结束时间", shopTableSeleInfoDto.getEndTime());
map.put("区域名称", all.getAreaName());
map.put("桌台名称", all.getTableName());
map.put("商品分类", table.getCateName());
map.put("商品名称", table.getProductName());
map.put("单位", table.getUnitName());
map.put("商品规格", table.getProductSkuName());
map.put("销量", table.getSalesNum());
map.put("销售额", table.getSalesAmount());
list.add(map);
}
list.add(map);
if (!tables.isEmpty()) {
if (mergeRowIndex.isEmpty()) {
mergeRowIndex.add(tables.size());
}else {
mergeRowIndex.add(mergeRowIndex.get(mergeRowIndex.size() - 1) + tables.size());
}
}
}
FileUtil.downloadExcel(list, response);
FileUtil.downloadExcelAndMerge(list, 4, response, mergeRowIndex);
}
}

View File

@@ -1,6 +1,7 @@
package cn.ysk.cashier.service.impl.productimpl;
import cn.ysk.cashier.dto.product.TbProductSortCriteria;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.pojo.product.TbProduct;
import cn.ysk.cashier.repository.product.TbProductRepository;
import cn.ysk.cashier.pojo.product.TbProductGroup;
@@ -14,6 +15,7 @@ import cn.ysk.cashier.config.security.service.dto.OnlineUserDto;
import lombok.RequiredArgsConstructor;
import cn.ysk.cashier.service.product.TbProductGroupService;
import cn.ysk.cashier.mapper.product.TbProductGroupMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
@@ -86,6 +88,10 @@ public class TbProductGroupServiceImpl implements TbProductGroupService {
@Override
@Transactional(rollbackFor = Exception.class)
public TbProductGroupDto create(TbProductGroup resources) {
if (resources.getUseTime() == 1) {
if (StringUtils.isBlank(resources.getSaleStartTime()) || StringUtils.isBlank(resources.getSaleEndTime()))
throw new BadRequestException("可售时间不可为空");
}
resources.setCreatedAt(Instant.now().toEpochMilli());
resources.setUpdatedAt(Instant.now().toEpochMilli());
TbProductGroup save = tbProductGroupRepository.save(resources);
@@ -96,7 +102,10 @@ public class TbProductGroupServiceImpl implements TbProductGroupService {
@Override
@Transactional(rollbackFor = Exception.class)
public void update(TbProductGroup resources) {
if (resources.getUseTime() == 1) {
if (StringUtils.isBlank(resources.getSaleStartTime()) || StringUtils.isBlank(resources.getSaleEndTime()))
throw new BadRequestException("可售时间不可为空");
}
TbProductGroup tbProductGroup = tbProductGroupRepository.findById(resources.getId()).orElseGet(TbProductGroup::new);
// TbProductGroup byName = tbProductGroupRepository.findByName(resources.getName(), resources.getShopId());
// if (byName != null){
@@ -191,7 +200,7 @@ public class TbProductGroupServiceImpl implements TbProductGroupService {
@Override
public ResponseEntity<Object> updateProductIds(AddProduct addProduct, String userName) {
OnlineUserDto onlineUser = onlineUserService.getOne(addProduct.getKey());
// OnlineUserDto onlineUser = onlineUserService.getOne(addProduct.getKey());
if (addProduct.getIds().size()<1){
return new ResponseEntity<>("错误", HttpStatus.NOT_ACCEPTABLE);