Merge branch 'ww' into test

# Conflicts:
#	eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java
This commit is contained in:
2024-10-11 09:45:35 +08:00
3 changed files with 95 additions and 133 deletions

View File

@@ -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.controller.shop;
import cn.ysk.cashier.annotation.Log;
@@ -30,11 +15,6 @@ import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @author lyf
* @date 2024-01-02
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "/shop/unit管理")
@@ -59,7 +39,7 @@ public class TbShopUnitController {
@PostMapping
@Log("新增单位:#resources.name")
@ApiOperation("新增/shop/unit")
public ResponseEntity<Object> createTbShopUnit(@Validated @RequestBody TbShopUnit resources)throws Exception{
public ResponseEntity<Object> createTbShopUnit(@Validated @RequestBody TbShopUnit resources){
return new ResponseEntity<>(tbShopUnitService.create(resources),HttpStatus.CREATED);
}

View File

@@ -1,15 +1,13 @@
package cn.ysk.cashier.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.ysk.cashier.dto.BaseQueryDto;
import cn.ysk.cashier.dto.ShopSummaryDto;
import cn.ysk.cashier.dto.shop.ExportTableStsDataDto;
import cn.ysk.cashier.dto.BaseQueryDto;
import cn.ysk.cashier.dto.shop.ShopTableSaleInfoDto;
import cn.ysk.cashier.enums.PayTypeEnum;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.mybatis.mapper.TbShopUserFlowMapper;
import cn.ysk.cashier.mybatis.service.TbShopUserFlowService;
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.TbShopTableRepository;
@@ -17,7 +15,6 @@ import cn.ysk.cashier.repository.shop.TbShopUserRepository;
import cn.ysk.cashier.service.SummaryService;
import cn.ysk.cashier.utils.DateUtil;
import cn.ysk.cashier.utils.FileUtil;
import cn.ysk.cashier.utils.FileUtils;
import cn.ysk.cashier.vo.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -52,9 +49,6 @@ public class SummaryServiceImpl implements SummaryService {
@Resource
private TbOrderDetailRepository detailRepository;
@Resource
private TbTokenRepository tbTokenRepository;
@Autowired
private TbShopUserFlowMapper tbShopUserFlowMapper;
@Resource
@@ -182,7 +176,7 @@ public class SummaryServiceImpl implements SummaryService {
payCountVos.add(new TbOrderPayCountVo("https://cashier-oss.oss-cn-beijing.aliyuncs.com/static/vipIn.png","充值","1",BigDecimal.ZERO));
// payCountVos.add(new TbOrderPayCountVo("","会员支付","1",BigDecimal.ZERO));
return payCountVos;
};
}
@@ -274,8 +268,8 @@ public class SummaryServiceImpl implements SummaryService {
@Override
public Map<String, Object> selectSummaryPayType(Integer shopId, Integer day) {
Long startTime;
Long endTime;
long startTime;
long endTime;
if (day == 7) {
startTime = DateUtil.getSevenDaysAgoInMilliseconds();
endTime = DateUtil.getTodayEndTimestamp();
@@ -357,13 +351,13 @@ public class SummaryServiceImpl implements SummaryService {
List<TbOrderSalesCountByDayV2Vo> products = detailRepository.queryTbOrderSalesCountByProduct(Integer.valueOf(summaryDto.getShopId()), summaryDto.getCateId(), summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime());
for (TbOrderSalesCountByDayV2Vo product : products) {
if(product.getTypeEnum().equals("sku")){
if("sku".equals(product.getTypeEnum())){
List<TbOrderSalesCountByDayV2Vo> skus = detailRepository.queryTbOrderSalesCountBySku(Integer.valueOf(summaryDto.getShopId()), product.getProductId(), summaryDto.getStartTime(), summaryDto.getEndTime());
product.setSkus(skus);
}
}
for (TbOrderSalesCountByDayV2Vo product : products) {
if(product.getTypeEnum().equals("sku")){
if("sku".equals(product.getTypeEnum())){
for (TbOrderSalesCountByDayV2Vo skus : product.getSkus()) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("商品分类", product.getCateName());
@@ -440,94 +434,78 @@ public class SummaryServiceImpl implements SummaryService {
@Override
public void downloadTableSaleInfo(ShopTableSaleInfoDto shopTableSaleInfoDto, HttpServletResponse response) throws IOException {
Date now = new Date();
if (shopTableSaleInfoDto.getStartTime() == null) {
shopTableSaleInfoDto.setStartTime(cn.hutool.core.date.DateUtil.beginOfMonth(now));
shopTableSaleInfoDto.setStartTime(DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L)));
}
if (shopTableSaleInfoDto.getEndTime() == null) {
shopTableSaleInfoDto.setEndTime(cn.hutool.core.date.DateUtil.endOfDay(now));
shopTableSaleInfoDto.setEndTime(new Date());
}
// 比较开始和结束日期 相差 天数
long betweenDay = cn.hutool.core.date.DateUtil.betweenDay(shopTableSaleInfoDto.getStartTime(), shopTableSaleInfoDto.getEndTime(), true);
if (betweenDay > 31) {
throw new BadRequestException("导出数据不能超过31天");
List<ShopTableSaleInfoVo> infoVos = selectSummaryTable(shopTableSaleInfoDto.getShopId(), shopTableSaleInfoDto.getStartTime(), shopTableSaleInfoDto.getEndTime());
infoVos.add(new ShopTableSaleInfoVo(99999, shopTableSaleInfoDto.getShopId(), null, "", "收银台", null, null, null, null));
List<TbOrderSalesCountByTable> countByTables = tbOrderDetailRepository.queryTbOrderSalesCountByTable(shopTableSaleInfoDto.getShopId(), shopTableSaleInfoDto.getStartTime(), shopTableSaleInfoDto.getEndTime());
Map<String, List<TbOrderSalesCountByTable>> countByTableMap = countByTables.stream()
.collect(Collectors.groupingBy(TbOrderSalesCountByTable::getTableId));
// 比较 shopTableSaleInfoDto 的 startTime 和 endTime 是不是同一天
boolean sameDay = cn.hutool.core.date.DateUtil.isSameDay(shopTableSaleInfoDto.getStartTime(), shopTableSaleInfoDto.getEndTime());
String queryDate = cn.hutool.core.date.DateUtil.format(shopTableSaleInfoDto.getStartTime(), "yyyy-MM-dd");
if (!sameDay) {
queryDate += "" + cn.hutool.core.date.DateUtil.format(shopTableSaleInfoDto.getEndTime(), "yyyy-MM-dd");
}
List<ExportTableStsDataDto> result = new ArrayList<>();
List<Map<String, Object>> list = new ArrayList<>();
for (int i = 0; i <= betweenDay; i++) {
Date date = cn.hutool.core.date.DateUtil.offsetDay(shopTableSaleInfoDto.getStartTime(), i);
String dateStr = cn.hutool.core.date.DateUtil.format(date, "yyyy-MM-dd");
ExportTableStsDataDto dataDto = new ExportTableStsDataDto();
dataDto.setDateStr(dateStr);
Date startTime = cn.hutool.core.date.DateUtil.beginOfDay(date);
Date endTime = cn.hutool.core.date.DateUtil.endOfDay(date);
List<ShopTableSaleInfoVo> infoVos = selectSummaryTable(shopTableSaleInfoDto.getShopId(), startTime, endTime);
infoVos.add(new ShopTableSaleInfoVo(99999, shopTableSaleInfoDto.getShopId(), null, "", "收银台", null, null, null, null));
List<TbOrderSalesCountByTable> countByTables = tbOrderDetailRepository.queryTbOrderSalesCountByTable(shopTableSaleInfoDto.getShopId(), startTime, endTime);
Map<String, List<TbOrderSalesCountByTable>> countByTableMap = countByTables.stream()
.collect(Collectors.groupingBy(TbOrderSalesCountByTable::getTableId));
List<Map<String, Object>> list = new ArrayList<>();
List<List<Integer>> mergeList = new ArrayList<>();
Map<String, Integer> tableStartIndexMap = new HashMap<>();
int rowIndex = 1;
for (ShopTableSaleInfoVo all : infoVos) {
List<TbOrderSalesCountByTable> tables = countByTableMap.get(all.getTableCode());
if (tables == null) {
continue;
}
BigDecimal total = BigDecimal.ZERO;
for (TbOrderSalesCountByTable table : tables) {
total = total.add(table.getSalesAmount().abs());
}
String tableCode = all.getTableName().toString();
if (!tableStartIndexMap.containsKey(tableCode)) {
tableStartIndexMap.put(tableCode, rowIndex);
}
for (TbOrderSalesCountByTable table : tables) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("日期", dateStr);
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.getPrice());
map.put("金额", table.getSalesAmount());
map.put("销售额", total);
map.put("退单量", table.getRefNum());
map.put("退单额", table.getRefAmount());
list.add(map);
rowIndex++;
}
int start = tableStartIndexMap.get(tableCode);
int end = rowIndex - 1;
if (end - start > 0) {
mergeList.add(Arrays.asList(start, end, 0, 0));
mergeList.add(Arrays.asList(start, end, 1, 1));
mergeList.add(Arrays.asList(start, end, 9, 9));
}
List<List<Integer>> mergeList = new ArrayList<>();
Map<String, Integer> tableStartIndexMap = new HashMap<>();
int rowIndex = 1;
for (ShopTableSaleInfoVo all : infoVos) {
List<TbOrderSalesCountByTable> tables = countByTableMap.get(all.getTableCode());
if (tables == null) {
continue;
}
dataDto.setMergeCells(mergeList);
dataDto.setData(list);
BigDecimal total = BigDecimal.ZERO;
for (TbOrderSalesCountByTable table : tables) {
total = total.add(table.getSalesAmount().abs());
}
result.add(dataDto);
String tableCode = all.getTableName().toString();
if (!tableStartIndexMap.containsKey(tableCode)) {
tableStartIndexMap.put(tableCode, rowIndex);
}
for (TbOrderSalesCountByTable table : tables) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("日期", queryDate);
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.getPrice());
map.put("金额", table.getSalesAmount());
map.put("销售额", total);
map.put("退单量", table.getRefNum());
map.put("退单额", table.getRefAmount());
list.add(map);
rowIndex++;
}
int start = tableStartIndexMap.get(tableCode);
int end = rowIndex - 1;
if (end - start > 0) {
mergeList.add(Arrays.asList(start, end, 0, 0));
mergeList.add(Arrays.asList(start, end, 1, 1));
mergeList.add(Arrays.asList(start, end, 9, 9));
}
}
List<String> keyList = new ArrayList<>();
@@ -544,6 +522,6 @@ public class SummaryServiceImpl implements SummaryService {
keyList.add("退单量");
keyList.add("退单额");
FileUtils.downloadTableDataStsToExcel(result, keyList, response);
FileUtil.downloadAndMergeExcel(list, mergeList, keyList, response);
}
}

View File

@@ -15,38 +15,34 @@
*/
package cn.ysk.cashier.service.impl.shopimpl;
import cn.ysk.cashier.exception.NewBadRequestException;
import cn.ysk.cashier.pojo.shop.TbShopUnit;
import cn.ysk.cashier.utils.ValidationUtil;
import cn.ysk.cashier.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import cn.ysk.cashier.repository.shop.TbShopUnitRepository;
import cn.ysk.cashier.service.shop.TbShopUnitService;
import cn.ysk.cashier.dto.shop.TbShopUnitDto;
import cn.ysk.cashier.dto.shop.TbShopUnitQueryCriteria;
import cn.ysk.cashier.exception.NewBadRequestException;
import cn.ysk.cashier.mapper.shop.TbShopUnitMapper;
import cn.ysk.cashier.pojo.shop.TbShopUnit;
import cn.ysk.cashier.repository.shop.TbShopUnitRepository;
import cn.ysk.cashier.service.shop.TbShopUnitService;
import cn.ysk.cashier.utils.FileUtil;
import cn.ysk.cashier.utils.PageUtil;
import cn.ysk.cashier.utils.QueryHelp;
import cn.ysk.cashier.utils.ValidationUtil;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
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.io.IOException;
import javax.persistence.criteria.Predicate;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @website https://eladmin.vip
* @description 服务实现
* @author lyf
* @date 2024-01-02
**/
@Service
@RequiredArgsConstructor
public class TbShopUnitServiceImpl implements TbShopUnitService {
@@ -55,8 +51,16 @@ public class TbShopUnitServiceImpl implements TbShopUnitService {
private final TbShopUnitMapper tbShopUnitMapper;
@Override
public Map<String,Object> queryAll(TbShopUnitQueryCriteria criteria, Pageable pageable){
Page<TbShopUnit> page = tbShopUnitRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
public Map<String, Object> queryAll(TbShopUnitQueryCriteria criteria, Pageable pageable) {
Page<TbShopUnit> page = tbShopUnitRepository.findAll((root, criteriaQuery, criteriaBuilder) -> {
Predicate predicate = QueryHelp.getPredicate(root, null, criteriaBuilder);
predicate = criteriaBuilder.or(predicate, criteriaBuilder.equal(root.get("shopId"), 1));
predicate = criteriaBuilder.and(predicate, criteriaBuilder.equal(root.get("shopId"), criteria.getShopId()));
if(StringUtils.isNotBlank(criteria.getName())){
predicate = criteriaBuilder.and(predicate, criteriaBuilder.like(root.get("name"), criteria.getName()));
}
return predicate;
}, pageable);
return PageUtil.toPage(page.map(tbShopUnitMapper::toDto));
}