Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
SongZhang 2024-10-11 10:54:29 +08:00
commit 838265d73f
9 changed files with 185 additions and 155 deletions

View File

@ -223,6 +223,51 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
IoUtil.close(out);
}
public static void downloadAndMergeExcel(List<Map<String, Object>> list, List<List<Integer>> mergeData, List<String> keyList, HttpServletResponse response) throws IOException {
String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx";
// 创建工作簿
Workbook workbook = new XSSFWorkbook();
// 创建工作表
Sheet sheet = workbook.createSheet("Sheet1");
// 合并单元格从第 0 行第 0 列到第 0 行第 2
// sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 2));
for (List<Integer> mergeDatum : mergeData) {
sheet.addMergedRegion(new CellRangeAddress(mergeDatum.get(0), mergeDatum.get(1), mergeDatum.get(2), mergeDatum.get(3)));
}
Row row0 = sheet.createRow(0);
for (int i = 0; i < keyList.size(); i++) {
Cell cell = row0.createCell(i);
cell.setCellValue(keyList.get(i));
}
for (int i = 0; i < list.size(); i++) {
Map<String, Object> map = list.get(i);
Row row = sheet.createRow(i + 1);
for (int j = 0; j < keyList.size(); j++) {
Cell cell = row.createCell(j);
cell.setCellValue(map.get(keyList.get(j)) == null ? "" : map.get(keyList.get(j)).toString());
}
}
// response为HttpServletResponse对象
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename=file.xlsx");
try (FileOutputStream outputStream = new FileOutputStream(tempPath);
ServletOutputStream out = response.getOutputStream()) {
workbook.write(outputStream);
workbook.write(out);
} catch (IOException e) {
// 更详细的错误处理
e.printStackTrace();
// 可以考虑返回一个错误响应给客户端
}
}
/**
* 输入标题到excel
*

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

@ -40,7 +40,7 @@ public class ShopPrintLogDTO implements Serializable {
private String tablePrint;
@ApiModelProperty(value = "打印数量 c1m1^2=顾客+商家[2张] m1^1=商家[1张] c1^1顾客[1张] c2m1^3=顾客2+商家1[3张]")
private String printQty;
@ApiModelProperty(value = "打印方式 1-普通 2-单个菜")
@ApiModelProperty(value = "打印方式 normal-普通出单 one-一菜一品 callTicket-排队取号")
private String printMethod;
@ApiModelProperty(value = "打印类型 JSON数组字符串数据 1-确认退款单 2-交班单 3-排队取号,如:[1,2,3]")
private String printType;

View File

@ -62,10 +62,15 @@ public class ShopPrinterDTO implements Serializable {
private String shopId;
/**
* 冗余/遗留字段
* 部分分类id 用逗号隔开部分打印时必传1,2,3
*/
private String categoryIds;
/**
* 部分分类列表 分类打印选择部分打印时必传JsonArray字符串数据 [{"id":125,"name":"意式咖啡"},{"id":127,"name":"饮品"}]
*/
private String categoryList;
/**
* 打印机品牌
* 云想印 = yxyPrinter
@ -121,7 +126,7 @@ public class ShopPrinterDTO implements Serializable {
*/
private String printQty;
/**
* 打印方式 1-普通 2-单个菜
* 打印方式 normal-普通出单 one-一菜一品 callTicket-排队取号
*/
private String printMethod;
/**

View File

@ -59,7 +59,7 @@ public class TbPrintMachineEntity implements Serializable {
*/
private String printQty;
/**
* 打印方式 1-普通 2-单个菜
* 打印方式 normal-普通出单 one-一菜一品 callTicket-排队取号
*/
private String printMethod;
/**

View File

@ -64,7 +64,7 @@ public class TbPrintMachineLogEntity implements Serializable {
*/
private String printQty;
/**
* 打印方式 1-普通 2-单个菜
* 打印方式 normal-普通出单 one-一菜一品 callTicket-排队取号
*/
private String printMethod;
/**

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

@ -6,7 +6,9 @@ import cn.hutool.core.convert.Convert;
import cn.hutool.core.map.MapProxy;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.ysk.cashier.dto.shop.ShopPrinterDTO;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.mybatis.mapper.TbPrintMachineMapper;
import cn.ysk.cashier.pojo.shop.TbPrintMachineEntity;
import cn.ysk.cashier.service.shop.ShopPrinterService;
@ -99,6 +101,21 @@ public class ShopPrinterServiceImpl extends ServiceImpl<TbPrintMachineMapper, Tb
public void save(ShopPrinterDTO dto) {
CopyOptions options = new CopyOptions();
options.setIgnoreProperties("createdAt", "updatedAt");
//分类打印选择部分打印时必传JsonArray字符串数据 [{"id":125,"name":"意式咖啡"},{"id":127,"name":"饮品"}]
if ("1".equals(dto.getClassifyPrint()) || "2".equals(dto.getClassifyPrint())) {
if (StrUtil.isBlank(dto.getCategoryList())) {
throw new BadRequestException("分类打印选择部分打印时,必须勾选需要部分打印的菜品");
}
if (JSONUtil.isTypeJSONArray(dto.getCategoryList())) {
throw new BadRequestException("传递的部分打印菜品数据不合法");
}
if (StrUtil.isBlank(dto.getCategoryIds())) {
throw new BadRequestException("分类打印选择部分打印时传递的部分打印菜品id数据不能为空");
}
} else {
dto.setCategoryIds(null);
dto.setCategoryList(null);
}
TbPrintMachineEntity entity = BeanUtil.toBean(dto, TbPrintMachineEntity.class, options);
entity.setCreatedAt(System.currentTimeMillis());
entity.setUpdatedAt(System.currentTimeMillis());
@ -110,6 +127,21 @@ public class ShopPrinterServiceImpl extends ServiceImpl<TbPrintMachineMapper, Tb
TbPrintMachineEntity entity = baseMapper.selectById(dto.getId());
CopyOptions options = new CopyOptions();
options.setIgnoreProperties("createdAt", "updatedAt");
//分类打印选择部分打印时必传JsonArray字符串数据 [{"id":125,"name":"意式咖啡"},{"id":127,"name":"饮品"}]
if ("1".equals(dto.getClassifyPrint()) || "2".equals(dto.getClassifyPrint())) {
if (StrUtil.isBlank(dto.getCategoryList())) {
throw new BadRequestException("分类打印选择部分打印时,必须勾选需要部分打印的菜品");
}
if (JSONUtil.isTypeJSONArray(dto.getCategoryList())) {
throw new BadRequestException("传递的部分打印菜品数据不合法");
}
if (StrUtil.isBlank(dto.getCategoryIds())) {
throw new BadRequestException("分类打印选择部分打印时传递的部分打印菜品id数据不能为空");
}
} else {
dto.setCategoryIds(null);
dto.setCategoryList(null);
}
BeanUtil.copyProperties(dto, entity, options);
entity.setUpdatedAt(System.currentTimeMillis());
baseMapper.updateById(entity);

View File

@ -1,52 +1,30 @@
/*
* 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.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.util.ArrayList;
import java.util.LinkedHashMap;
import java.io.IOException;
import java.time.Instant;
import java.util.*;
/**
* @website https://eladmin.vip
* @description 服务实现
* @author lyf
* @date 2024-01-02
**/
@Service
@RequiredArgsConstructor
public class TbShopUnitServiceImpl implements TbShopUnitService {
@ -55,8 +33,20 @@ 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.and(predicate, criteriaBuilder.in(root.get("shopId")).value(criteria.getShopId()).value("1"));
predicate = criteriaBuilder.and(predicate, criteriaBuilder.or(
criteriaBuilder.equal(root.get("shopId"), criteria.getShopId()),
criteriaBuilder.equal(root.get("shopId"), "1")));
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));
}