From c35df24d2d1100bf98fcbaa5412ca2793b56fac3 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 14 Aug 2024 09:43:25 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=88=86=E7=BB=84=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=AF=E5=94=AE=E6=97=B6=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/TbProductGroupController.java | 12 ++++----- .../dto/product/TbProductGroupDto.java | 8 ++++++ .../cashier/pojo/product/TbProductGroup.java | 26 ++++++++----------- .../TbProductGroupServiceImpl.java | 12 ++++++++- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductGroupController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductGroupController.java index b5e82e5b..71eccc31 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductGroupController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/product/TbProductGroupController.java @@ -36,12 +36,12 @@ public class TbProductGroupController { @Resource private TbProductService tbProductService; - @ApiOperation("导出数据") - @GetMapping(value = "/download") - @PreAuthorize("@el.check('tbProductGroup:list')") - public void exportTbProductGroup(HttpServletResponse response, TbProductGroupQueryCriteria criteria) throws IOException { - tbProductGroupService.download(tbProductGroupService.queryAll(criteria), response); - } +// @ApiOperation("导出数据") +// @GetMapping(value = "/download") +// @PreAuthorize("@el.check('tbProductGroup:list')") +// public void exportTbProductGroup(HttpServletResponse response, TbProductGroupQueryCriteria criteria) throws IOException { +// tbProductGroupService.download(tbProductGroupService.queryAll(criteria), response); +// } @GetMapping @ApiOperation("查询product/group") diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/product/TbProductGroupDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/product/TbProductGroupDto.java index 66ed15a4..c377e6a6 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/product/TbProductGroupDto.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/product/TbProductGroupDto.java @@ -16,6 +16,8 @@ package cn.ysk.cashier.dto.product; import lombok.Data; + +import javax.persistence.Column; import java.io.Serializable; import java.util.List; @@ -60,4 +62,10 @@ public class TbProductGroupDto implements Serializable { private Long createdAt; private Long updatedAt; + + private Integer useTime; + + private String saleStartTime; + + private String saleEndTime; } \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/product/TbProductGroup.java b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/product/TbProductGroup.java index 3b21ef88..e36f5819 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/pojo/product/TbProductGroup.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/pojo/product/TbProductGroup.java @@ -1,18 +1,3 @@ -/* -* Copyright 2019-2020 Zheng Jie -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ package cn.ysk.cashier.pojo.product; import lombok.Data; @@ -86,6 +71,17 @@ public class TbProductGroup implements Serializable { @ApiModelProperty(value = "updatedAt") private Long updatedAt; + @NotNull + @Column(name = "`use_time`",nullable = false) + @ApiModelProperty(value = "是否开启时间管控") + private Integer useTime = 0; + + @Column(name = "`sale_start_time`") + private String saleStartTime; + + @Column(name = "`sale_end_time`") + private String saleEndTime; + public void copy(TbProductGroup source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java index bb84510a..67a188af 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductGroupServiceImpl.java @@ -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,6 +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){ @@ -187,7 +197,7 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { @Override public ResponseEntity 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); From 3d9e4ee511f671e975d45579dbb2b18968f63ad0 Mon Sep 17 00:00:00 2001 From: GYJ <1157756119@qq.com> Date: Thu, 15 Aug 2024 17:25:36 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=80=E9=87=8F?= =?UTF-8?q?=E5=92=8C=E5=8F=B0=E6=A1=8C=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/SummaryByDayController.java | 1 + .../controller/shop/SummaryController.java | 1 + .../order/TbOrderDetailRepository.java | 23 ++++ .../order/TbOrderInfoRepository.java | 1 + .../service/impl/SummaryServiceImpl.java | 120 +++++++++++------- .../ysk/cashier/vo/ShopTableSaleInfoVo.java | 5 +- .../cashier/vo/TbOrderSalesCountByTable.java | 64 ++++++++++ 7 files changed, 169 insertions(+), 46 deletions(-) create mode 100644 eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByTable.java diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryByDayController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryByDayController.java index 1ec74bb4..efa23af2 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryByDayController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryByDayController.java @@ -1,5 +1,6 @@ package cn.ysk.cashier.controller.shop; +import cn.ysk.cashier.annotation.rest.AnonymousPostMapping; import cn.ysk.cashier.dto.ShopSummaryDto; import cn.ysk.cashier.service.SummaryService; import cn.ysk.cashier.vo.TbOrderPayCountVo; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java index 3c98a5eb..b260c37e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryController.java @@ -67,6 +67,7 @@ public class SummaryController { } @PostMapping("/table/download") + @AnonymousPostMapping private void downloadShopSummaryTable(HttpServletResponse response, @RequestBody ShopTableSeleInfoDto exportRequest) throws IOException { summaryService.downloadTableSeleInfo(exportRequest, response); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java index 318e5807..b258dfe1 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java @@ -5,6 +5,7 @@ import cn.ysk.cashier.pojo.order.TbOrderDetail; import cn.ysk.cashier.vo.TbOrderPayCountVo; import cn.ysk.cashier.vo.TbOrderSaleVO; import cn.ysk.cashier.vo.TbOrderSalesCountByDayVo; +import cn.ysk.cashier.vo.TbOrderSalesCountByTable; import org.apache.ibatis.annotations.Param; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -165,4 +166,26 @@ public interface TbOrderDetailRepository extends JpaRepository :startTime AND info.createTime < :endTime " + + "AND (info.status = 'closed' OR info.status = 'refund') " + + "GROUP BY info.productId, info.productSkuId, orders.tableId " + + "ORDER BY salesNum DESC") + List queryTbOrderSalesCountByTable(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime); + } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java index aa889297..8988b82d 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderInfoRepository.java @@ -189,6 +189,7 @@ public interface TbOrderInfoRepository extends JpaRepository Page 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) {//金额 @@ -400,7 +404,7 @@ public class SummaryServiceImpl implements SummaryService { summaryDto.setStartTime(DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L))); summaryDto.setEndTime(new Date()); } - return (Page) detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime(), pageable); + return (Page) detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()), summaryDto.getCateId(), summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime(), pageable); } } @@ -408,12 +412,10 @@ public class SummaryServiceImpl implements SummaryService { @Override public void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException { List> list = new ArrayList<>(); -// ConcurrentLinkedQueue> list = new ConcurrentLinkedQueue(); - if(StringUtils.isBlank(summaryDto.getCateId())){ + if (StringUtils.isBlank(summaryDto.getCateId())) { summaryDto.setCateId(null); } - ArrayList mergeRowIndex = new ArrayList<>(); if (summaryDto.getType() != null && summaryDto.getType() == 1) {//金额 Long start = 1704038400000L; Long end = Instant.now().toEpochMilli(); @@ -438,38 +440,24 @@ public class SummaryServiceImpl implements SummaryService { summaryDto.setEndTime(new Date()); } List tbOrderSalesCountByDayVos = detailRepository - .queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime()); + .queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()), summaryDto.getCateId(), summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime()); tbOrderSalesCountByDayVos.forEach(all -> { - List 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 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 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 @@ -485,7 +473,7 @@ public class SummaryServiceImpl implements SummaryService { endTime = new Date(); } TbOrderPayCountVo payCount = tbOrderInfoRepository.queryOrderPayCount(shopId, start, end); - TbOrderPayCountVo refCount = tbOrderInfoRepository.queryTbOrderRefund(shopId, null,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); @@ -497,8 +485,8 @@ public class SummaryServiceImpl implements SummaryService { 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()); + 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); return list; @@ -563,20 +551,62 @@ public class SummaryServiceImpl implements SummaryService { List infoVos = selectSummaryTable(shopTableSeleInfoDto.getShopId(), shopTableSeleInfoDto.getStartTime(), shopTableSeleInfoDto.getEndTime()); + List countByTables = tbOrderDetailRepository.queryTbOrderSalesCountByTable(shopTableSeleInfoDto.getShopId(), shopTableSeleInfoDto.getStartTime(), shopTableSeleInfoDto.getEndTime()); + + Map> countByTableMap = countByTables.stream() + .collect(Collectors.groupingBy(TbOrderSalesCountByTable::getTableId)); + List> list = new ArrayList<>(); + ArrayList mergeRowIndex = new ArrayList<>(); for (ShopTableSaleInfoVo all : infoVos) { - Map map = new LinkedHashMap<>(); + List 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 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()); +// map.put("订单数量", all.getOrderCount()); +// map.put("销售额", all.getOrderAmount()); +// map.put("商品名称", table.getProductName()); +// map.put("销售数量", table.getSalesNum()); + list.add(map); + } - list.add(map); + + +// Map map = new LinkedHashMap<>(); +// +// map.put("开始时间", shopTableSeleInfoDto.getStartTime()); +// map.put("结束时间", shopTableSeleInfoDto.getEndTime()); +// map.put("区域名称", all.getAreaName()); +// map.put("桌台名称", all.getTableName()); +// map.put("订单数量", all.getOrderCount()); +// map.put("销售额", all.getOrderAmount()); +// +// 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.downloadExcel(list, response); + FileUtil.downloadExcelAndMerge(list, 4, response, mergeRowIndex); } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/ShopTableSaleInfoVo.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/ShopTableSaleInfoVo.java index b36e8168..156c46c1 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/vo/ShopTableSaleInfoVo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/ShopTableSaleInfoVo.java @@ -13,6 +13,8 @@ public class ShopTableSaleInfoVo { private Object tableId; + private String tableCode; + private Object tableName; private Object areaId; @@ -24,11 +26,12 @@ public class ShopTableSaleInfoVo { private Object orderAmount; - public ShopTableSaleInfoVo(Integer id, Object shopId, Object tableId, Object tableName, + public ShopTableSaleInfoVo(Integer id, Object shopId, Object tableId, String tableCode, Object tableName, Object areaId, Object areaName, Object orderCount, Object orderAmount) { this.id = id; this.shopId = shopId; this.tableId = tableId; + this.tableCode = tableCode; this.tableName = tableName; this.areaId = areaId; this.areaName = areaName; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByTable.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByTable.java new file mode 100644 index 00000000..c8875f73 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByTable.java @@ -0,0 +1,64 @@ +package cn.ysk.cashier.vo; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author GYJ + */ +@Data +public class TbOrderSalesCountByTable { + private String productName; + private String productSkuName; + private String cateName; + private String unitName; + private BigDecimal price; + private Long salesNum; + private Long refNum; + private BigDecimal salesAmount; + private BigDecimal refAmount; + private Long num; + private Integer productId; + private Integer productSkuId; + private String tableId; + + public TbOrderSalesCountByTable(String productName, String productSkuName, String cateName,String unitName,BigDecimal price, + Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount) { + this.productName = productName; + this.productSkuName = productSkuName; + this.cateName = cateName; + this.unitName = unitName; + this.price = price; + this.salesNum = salesNum; + this.refNum = refNum; + this.salesAmount = salesAmount; + this.refAmount = refAmount; + this.num = num; + count(); + } + + public TbOrderSalesCountByTable(String productName, String productSkuName, String cateName,String unitName,BigDecimal price, + Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount, + Integer productId, Integer productSkuId, String tableId) { + this.productName = productName; + this.productSkuName = productSkuName; + this.cateName = cateName; + this.unitName = unitName; + this.price = price; + this.salesNum = salesNum; + this.refNum = refNum; + this.salesAmount = salesAmount; + this.refAmount = refAmount; + this.num = num; + this.productId = productId; + this.productSkuId = productSkuId; + this.tableId = tableId; + count(); + } + + public void count(){ + salesNum=salesNum-refNum; + salesAmount=salesAmount.subtract(refAmount); + } +} From a183d2bfec0203d2dbca79b1e579e7a20340528c Mon Sep 17 00:00:00 2001 From: GYJ <1157756119@qq.com> Date: Thu, 15 Aug 2024 17:33:03 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=80=E9=87=8F?= =?UTF-8?q?=E5=92=8C=E5=8F=B0=E6=A1=8C=E5=AF=BC=E5=87=BA=20--=20=E5=90=88?= =?UTF-8?q?=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/TbOrderDetailRepository.java | 14 -------- .../service/impl/SummaryServiceImpl.java | 35 +------------------ 2 files changed, 1 insertion(+), 48 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java index 42df72f3..fe9f3be7 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java @@ -38,20 +38,6 @@ public interface TbOrderDetailRepository extends JpaRepository searchDetailByOrderIds(@Param("ids")List ids); - @Query(value = "SELECT " + - "new cn.ysk.cashier.vo.TbOrderSaleVO(oi.orderNo, od.num, od.price, od.status, 0)\n" + - "FROM\n" + - "TbOrderInfo oi\n" + - "LEFT JOIN TbOrderDetail od ON oi.id = od.orderId \n" + - "WHERE\n" + - "od.shopId = :shopId \n" + - "AND ( od.status = 'closed' OR od.status = 'refund' ) \n" + - "AND od.createTime > :startTime \n" + - "AND od.createTime < :endTime \n" + - "AND (:productId is null or od.productId = :productId)\n" + - "AND (:productId is null or od.productSkuId = :productSkuId)") - List querySaleOrderInfo(@Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime, @Param("productId") Integer productId, @Param("productSkuId") Integer productSkuId, @Param("shopId") Integer shopId); - @Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" + "info.productName, info.productSkuName, cate.name, unit.name,info.price," + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java index 47555a1c..b6ddca76 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java @@ -1,20 +1,15 @@ package cn.ysk.cashier.service.impl; -import cn.hutool.core.util.StrUtil; 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; @@ -36,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; @@ -66,15 +59,8 @@ public class SummaryServiceImpl implements SummaryService { @Resource private TbShopUserFlowService tbShopUserFlowService; - - @Resource - private TbShopTableRepository shopTableRepository; - - @Resource - TbShopAreaRepository tbShopAreaRepository; @Autowired private TbOrderDetailRepository tbOrderDetailRepository; - private final TbOrderInfoMapper orderInfoMapper; @Override @@ -559,7 +545,7 @@ public class SummaryServiceImpl implements SummaryService { Map> countByTableMap = countByTables.stream() .collect(Collectors.groupingBy(TbOrderSalesCountByTable::getTableId)); - List> list = new ArrayList<>(); + ConcurrentLinkedQueue> list = new ConcurrentLinkedQueue<>(); ArrayList mergeRowIndex = new ArrayList<>(); for (ShopTableSaleInfoVo all : infoVos) { @@ -580,27 +566,9 @@ public class SummaryServiceImpl implements SummaryService { map.put("商品规格", table.getProductSkuName()); map.put("销量", table.getSalesNum()); map.put("销售额", table.getSalesAmount()); -// map.put("订单数量", all.getOrderCount()); -// map.put("销售额", all.getOrderAmount()); -// map.put("商品名称", table.getProductName()); -// map.put("销售数量", table.getSalesNum()); list.add(map); } - - -// Map map = new LinkedHashMap<>(); -// -// map.put("开始时间", shopTableSeleInfoDto.getStartTime()); -// map.put("结束时间", shopTableSeleInfoDto.getEndTime()); -// map.put("区域名称", all.getAreaName()); -// map.put("桌台名称", all.getTableName()); -// map.put("订单数量", all.getOrderCount()); -// map.put("销售额", all.getOrderAmount()); -// -// list.add(map); - - if (!tables.isEmpty()) { if (mergeRowIndex.isEmpty()) { mergeRowIndex.add(tables.size()); @@ -609,7 +577,6 @@ public class SummaryServiceImpl implements SummaryService { } } } -// FileUtil.downloadExcel(list, response); FileUtil.downloadExcelAndMerge(list, 4, response, mergeRowIndex); } } From 7271e77b0505abcbedfc6db3fc776a6f0588c472 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 15 Aug 2024 18:23:46 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=8A=A5=E8=A1=A8-?= =?UTF-8?q?=E9=94=80=E9=87=8F-=E7=BB=9F=E8=AE=A1=20=E5=95=86=E5=93=81=20?= =?UTF-8?q?=E8=A7=84=E6=A0=BC=20=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/SummaryByDayController.java | 4 +- .../cn/ysk/cashier/dto/ShopSummaryDto.java | 4 +- .../order/TbOrderDetailRepository.java | 20 +++++++- .../ysk/cashier/service/SummaryService.java | 2 +- .../service/impl/SummaryServiceImpl.java | 46 ++++++++++++------- .../java/cn/ysk/cashier/vo/StockV2Vo.java | 4 +- .../main/java/cn/ysk/cashier/vo/StockVo.java | 4 +- .../cashier/vo/TbOrderSalesCountByDayVo.java | 18 ++++++-- 8 files changed, 71 insertions(+), 31 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryByDayController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryByDayController.java index efa23af2..7f0812c3 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryByDayController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/shop/SummaryByDayController.java @@ -42,10 +42,10 @@ public class SummaryByDayController { } @GetMapping(value = "count") - public List summaryCount(@RequestParam String shopId, + public List summaryCount(ShopSummaryDto summaryDto, @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime, @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) { - return summaryService.summaryCount(shopId, startTime, endTime); + return summaryService.summaryCount(summaryDto, startTime, endTime); } } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/ShopSummaryDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/ShopSummaryDto.java index 7f4a73b0..f762d716 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/ShopSummaryDto.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/ShopSummaryDto.java @@ -19,7 +19,9 @@ public class ShopSummaryDto { } public void setCateId(String cateId) { - this.cateId = cateId; + if(StringUtils.isNotBlank(cateId)){ + this.cateId = cateId; + } } public String getShopId() { diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java index fe9f3be7..c535a5f3 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java @@ -103,7 +103,7 @@ public interface TbOrderDetailRepository extends JpaRepository queryTbOrderSalesCountByDay(@Param("shopId") Integer shopId,@Param("cateId")String cateId,@Param("proName")String proName, @Param("startTime") Date startTime, @Param("endTime") Date endTime); @Query(value = "SELECT " + - "new cn.ysk.cashier.vo.TbOrderSaleVO(oi.orderNo, od.num, od.price, od.status)\n" + + "new cn.ysk.cashier.vo.TbOrderSaleVO(oi.orderNo, od.num, od.price, od.status,od.productSkuId)\n" + "FROM\n" + "TbOrderInfo oi\n" + "LEFT JOIN TbOrderDetail od ON oi.id = od.orderId \n" + @@ -115,8 +115,24 @@ public interface TbOrderDetailRepository extends JpaRepository querySaleOrderInfo(@Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime, @Param("productId") Integer productId, @Param("productSkuId") Integer productSkuId, @Param("shopId") Integer shopId); + @Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" + + "SUM(CASE WHEN orders.orderType!='return' THEN info.num ELSE 0 END)," + + "SUM(CASE WHEN orders.orderType='return' THEN info.num ELSE 0 END), " + + "SUM(info.num), " + + "SUM(CASE WHEN orders.orderType!='return' THEN info.priceAmount ELSE 0 END), " + + "SUM(CASE WHEN orders.orderType='return' THEN info.priceAmount ELSE 0 END)) " + + "FROM TbOrderInfo orders " + + "LEFT JOIN TbOrderDetail info on orders.id=info.orderId " + + "LEFT JOIN TbProduct pro ON info.productId = pro.id " + + "WHERE info.shopId = :shopId " + + "AND (:cateId IS NULL OR pro.categoryId = :cateId) " + + "AND (:proName IS NULL OR info.productName LIKE %:proName%) " + + "AND info.createTime > :startTime AND info.createTime < :endTime " + + "AND (info.status = 'closed' OR info.status = 'refund') ") + TbOrderSalesCountByDayVo queryTbOrderSalesCountByDaysummaryCount(@Param("shopId") Integer shopId,@Param("cateId")String cateId,@Param("proName")String proName, @Param("startTime") Date startTime, @Param("endTime") Date endTime); - @Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" + + + @Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" + "COALESCE(CAST(SUM(CASE WHEN orders.orderType!='return' THEN info.num ELSE 0 END) as long),0), " + "COALESCE(CAST(SUM(CASE WHEN orders.orderType='return' THEN info.num ELSE 0 END) as long),0))" + "FROM TbOrderInfo orders " + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/SummaryService.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/SummaryService.java index 475cde90..f1e751a3 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/SummaryService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/SummaryService.java @@ -37,7 +37,7 @@ public interface SummaryService { */ void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException; - List summaryCount(String shopId, Date startTime, Date endTime); + List summaryCount(ShopSummaryDto summaryDto, Date startTime, Date endTime); List selectSummaryTable(Integer shopId, Date startTime, Date endTime); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java index b6ddca76..3540f315 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java @@ -450,7 +450,7 @@ public class SummaryServiceImpl implements SummaryService { } @Override - public List summaryCount(String shopId, Date startTime, Date endTime) { + public List summaryCount(ShopSummaryDto summaryDto, Date startTime, Date endTime) { List list = new ArrayList<>(); Long start = 1704038400000L; Long end = Instant.now().toEpochMilli(); @@ -461,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; } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/StockV2Vo.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/StockV2Vo.java index 04f52a8a..9b0c44e2 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/vo/StockV2Vo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/StockV2Vo.java @@ -266,10 +266,10 @@ public class StockV2Vo { this.type = "称重商品"; break; case "currentPrice": - this.type = "套餐商品/团购卷"; + this.type = "时价商品"; break; case "group": - this.type = "时价商品"; + this.type = "套餐商品/团购卷"; break; default: this.type = type; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/StockVo.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/StockVo.java index 737b286a..5f943d94 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/vo/StockVo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/StockVo.java @@ -48,10 +48,10 @@ public class StockVo { this.type = "称重商品"; break; case "currentPrice": - this.type = "套餐商品/团购卷"; + this.type = "时价商品"; break; case "group": - this.type = "时价商品"; + this.type = "套餐商品/团购卷"; break; default: this.type = type; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java index de244a76..b994e4d1 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/vo/TbOrderSalesCountByDayVo.java @@ -152,11 +152,21 @@ public class TbOrderSalesCountByDayVo { count(); } - - + public TbOrderSalesCountByDayVo(Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount) { + this.salesNum = salesNum; + this.refNum = refNum; + this.salesAmount = salesAmount; + this.refAmount = refAmount; + this.num = num; + count(); + } public void count(){ - salesNum=salesNum-refNum; - salesAmount=salesAmount.subtract(refAmount); + if (salesNum == null) salesNum = 0l; + if (refNum == null) refNum = 0l; + salesNum = salesNum - refNum; + if (salesAmount == null) salesAmount = BigDecimal.ZERO; + if (refAmount == null) refAmount = BigDecimal.ZERO; + salesAmount = salesAmount.subtract(refAmount); } }