统计和导出
This commit is contained in:
@ -48,20 +48,18 @@ public class CustomizeExcelController {
|
|||||||
@GetMapping("/orderExcel")
|
@GetMapping("/orderExcel")
|
||||||
@Operation(summary = "导出订单详情")
|
@Operation(summary = "导出订单详情")
|
||||||
@OperateLog(type = EXPORT)
|
@OperateLog(type = EXPORT)
|
||||||
public void exportBusinessExcel(String startTime,String endTime,
|
public void exportBusinessExcel(String startTime,String endTime,Long carteenId,
|
||||||
HttpServletResponse response) throws IOException {
|
HttpServletResponse response) throws IOException {
|
||||||
|
|
||||||
List<OrderExcelVO> orderExcelVOS = excelService.exportOrderExcel(startTime, endTime);
|
List<OrderExcelVO> orderExcelVOS = excelService.exportOrderExcel(startTime, endTime,carteenId);
|
||||||
// 导出 Excel
|
// 导出 Excel
|
||||||
ExcelUtils.write(response, "订单详情统计.xls", "数据", OrderExcelVO.class,
|
ExcelUtils.write(response, "订单详情统计.xls", "数据", OrderExcelVO.class,
|
||||||
orderExcelVOS);
|
orderExcelVOS);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据时间导出多个sheet 页
|
* 根据时间导出多个sheet 页
|
||||||
* @param list
|
* @param
|
||||||
* @param response
|
* @param response
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
@ -9,7 +9,7 @@ import java.util.List;
|
|||||||
@Data
|
@Data
|
||||||
public class BusinessDataVO {
|
public class BusinessDataVO {
|
||||||
|
|
||||||
private BusinessRespVO old;
|
private BusinessRespVO now;
|
||||||
private List<BusinessRespVO> businessList;
|
private List<BusinessRespVO> businessList;
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,5 +11,5 @@ import java.util.List;
|
|||||||
public interface CustomizeExcelMapper {
|
public interface CustomizeExcelMapper {
|
||||||
|
|
||||||
|
|
||||||
List<OrderExcelVO> selectOrder(@Param("startTime")String startTime, @Param("endTime")String endTime);
|
List<OrderExcelVO> selectOrder(@Param("startTime")String startTime, @Param("endTime")String endTime, @Param("carteenId")Long carteenId);
|
||||||
}
|
}
|
||||||
|
@ -166,6 +166,9 @@ public class BusinessServiceImpl implements BusinessService {
|
|||||||
@Override
|
@Override
|
||||||
public BusinessDataVO getDay(String time,Long carteenId) {
|
public BusinessDataVO getDay(String time,Long carteenId) {
|
||||||
|
|
||||||
|
Integer nowDay = MemberTimeUtils.getDay(time);
|
||||||
|
time = MemberTimeUtils.getYearMonth(time);
|
||||||
|
|
||||||
BusinessDataVO businessDataVO = new BusinessDataVO();
|
BusinessDataVO businessDataVO = new BusinessDataVO();
|
||||||
|
|
||||||
LambdaQueryWrapper<BusinessDO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<BusinessDO> wrapper = new LambdaQueryWrapper<>();
|
||||||
@ -210,17 +213,14 @@ public class BusinessServiceImpl implements BusinessService {
|
|||||||
if(CollectionUtil.isNotEmpty(previousList)){
|
if(CollectionUtil.isNotEmpty(previousList)){
|
||||||
BeanUtil.copyProperties(previousList.get(0), old);
|
BeanUtil.copyProperties(previousList.get(0), old);
|
||||||
}else {
|
}else {
|
||||||
old.setTurnover(BigDecimal.ZERO).setOrderSum(0).setReduce(BigDecimal.ZERO).setWeigh(BigDecimal.ZERO)
|
old = getInitBusinessRespVO();
|
||||||
.setBreakfast(BigDecimal.ZERO).setLunch(BigDecimal.ZERO).setDinner(BigDecimal.ZERO);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 循环遍历该月的每一天
|
// 循环遍历该月的每一天
|
||||||
for (int day = 1; day <= daysInMonth; day++) {
|
for (int day = 1; day <= daysInMonth; day++) {
|
||||||
BusinessRespVO bean = new BusinessRespVO();
|
BusinessRespVO bean = new BusinessRespVO();
|
||||||
if(map.get(day) == null){
|
if(map.get(day) == null){
|
||||||
bean.setTurnover(BigDecimal.ZERO).setOrderSum(0).setReduce(BigDecimal.ZERO).setWeigh(BigDecimal.ZERO)
|
bean = getInitBusinessRespVO().setTime(String.valueOf(day));
|
||||||
.setBreakfast(BigDecimal.ZERO).setLunch(BigDecimal.ZERO).setDinner(BigDecimal.ZERO)
|
|
||||||
.setTime(String.valueOf(day));
|
|
||||||
}else {
|
}else {
|
||||||
bean = BeanUtils.toBean(map.get(day), BusinessRespVO.class);
|
bean = BeanUtils.toBean(map.get(day), BusinessRespVO.class);
|
||||||
bean.setTime(String.valueOf(day));
|
bean.setTime(String.valueOf(day));
|
||||||
@ -234,7 +234,7 @@ public class BusinessServiceImpl implements BusinessService {
|
|||||||
monthData.put(day,bean);
|
monthData.put(day,bean);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
businessDataVO.setNow(monthData.get(nowDay));
|
||||||
businessDataVO.setBusinessList(new ArrayList<>(monthData.values()));
|
businessDataVO.setBusinessList(new ArrayList<>(monthData.values()));
|
||||||
return businessDataVO;
|
return businessDataVO;
|
||||||
}
|
}
|
||||||
@ -254,10 +254,7 @@ public class BusinessServiceImpl implements BusinessService {
|
|||||||
|
|
||||||
int totalWeeksOfMonth = MemberTimeUtils.getTotalWeeksOfMonth(time);
|
int totalWeeksOfMonth = MemberTimeUtils.getTotalWeeksOfMonth(time);
|
||||||
for (int i = 1; i <= totalWeeksOfMonth; i++) {
|
for (int i = 1; i <= totalWeeksOfMonth; i++) {
|
||||||
BusinessRespVO bean = new BusinessRespVO();
|
BusinessRespVO bean = getInitBusinessRespVO().setTime(String.valueOf(i));
|
||||||
bean.setTurnover(BigDecimal.ZERO).setOrderSum(0).setReduce(BigDecimal.ZERO).setWeigh(BigDecimal.ZERO)
|
|
||||||
.setBreakfast(BigDecimal.ZERO).setLunch(BigDecimal.ZERO).setDinner(BigDecimal.ZERO)
|
|
||||||
.setTime(String.valueOf(i));
|
|
||||||
map.put(i,bean);
|
map.put(i,bean);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,6 +278,7 @@ public class BusinessServiceImpl implements BusinessService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BusinessDataVO getMonth(String time,Long carteenId) {
|
public BusinessDataVO getMonth(String time,Long carteenId) {
|
||||||
|
time = MemberTimeUtils.getYearMonth(time);
|
||||||
|
|
||||||
BusinessDataVO businessDataVO = new BusinessDataVO();
|
BusinessDataVO businessDataVO = new BusinessDataVO();
|
||||||
|
|
||||||
@ -295,10 +293,8 @@ public class BusinessServiceImpl implements BusinessService {
|
|||||||
Map<Integer,BusinessRespVO> map = new HashMap<>();
|
Map<Integer,BusinessRespVO> map = new HashMap<>();
|
||||||
//时间处理
|
//时间处理
|
||||||
for (int i = 1; i <= 12; i++) {
|
for (int i = 1; i <= 12; i++) {
|
||||||
BusinessRespVO bean = new BusinessRespVO();
|
BusinessRespVO bean = getInitBusinessRespVO();
|
||||||
bean.setTurnover(BigDecimal.ZERO).setOrderSum(0).setReduce(BigDecimal.ZERO).setWeigh(BigDecimal.ZERO)
|
bean.setTime(String.valueOf(i));
|
||||||
.setBreakfast(BigDecimal.ZERO).setLunch(BigDecimal.ZERO).setDinner(BigDecimal.ZERO)
|
|
||||||
.setTime(String.valueOf(i));
|
|
||||||
map.put(i,bean);
|
map.put(i,bean);
|
||||||
}
|
}
|
||||||
//数据统计
|
//数据统计
|
||||||
@ -319,9 +315,7 @@ public class BusinessServiceImpl implements BusinessService {
|
|||||||
previousWrapper.orderByAsc(BusinessDO::getCreateTime);
|
previousWrapper.orderByAsc(BusinessDO::getCreateTime);
|
||||||
previousWrapper.apply("DATE_FORMAT(create_time, '%Y-%m') = {0}", previousYear+"-12");
|
previousWrapper.apply("DATE_FORMAT(create_time, '%Y-%m') = {0}", previousYear+"-12");
|
||||||
List<BusinessDO> previousList = businessMapper.selectList(previousWrapper);
|
List<BusinessDO> previousList = businessMapper.selectList(previousWrapper);
|
||||||
BusinessRespVO previousVO = new BusinessRespVO();
|
BusinessRespVO previousVO = getInitBusinessRespVO();
|
||||||
previousVO.setTurnover(BigDecimal.ZERO).setOrderSum(0).setReduce(BigDecimal.ZERO).setWeigh(BigDecimal.ZERO)
|
|
||||||
.setBreakfast(BigDecimal.ZERO).setLunch(BigDecimal.ZERO).setDinner(BigDecimal.ZERO);
|
|
||||||
for (BusinessDO businessDO : previousList) {
|
for (BusinessDO businessDO : previousList) {
|
||||||
handleBusiness(businessDO,previousVO);
|
handleBusiness(businessDO,previousVO);
|
||||||
}
|
}
|
||||||
@ -334,6 +328,8 @@ public class BusinessServiceImpl implements BusinessService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int month = MemberTimeUtils.getMonthFromYearMonthString(time);
|
||||||
|
businessDataVO.setNow(map.get(month));
|
||||||
businessDataVO.setBusinessList(new ArrayList<>(map.values()));
|
businessDataVO.setBusinessList(new ArrayList<>(map.values()));
|
||||||
|
|
||||||
return businessDataVO;
|
return businessDataVO;
|
||||||
@ -367,4 +363,11 @@ public class BusinessServiceImpl implements BusinessService {
|
|||||||
today.setPriceAvgCompare(today.getPriceAvg().subtract(last.getPriceAvg()));
|
today.setPriceAvgCompare(today.getPriceAvg().subtract(last.getPriceAvg()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BusinessRespVO getInitBusinessRespVO() {
|
||||||
|
BusinessRespVO previousVO = new BusinessRespVO();
|
||||||
|
previousVO.setTurnover(BigDecimal.ZERO).setOrderSum(0).setReduce(BigDecimal.ZERO).setWeigh(BigDecimal.ZERO)
|
||||||
|
.setBreakfast(BigDecimal.ZERO).setLunch(BigDecimal.ZERO).setDinner(BigDecimal.ZERO).setPriceAvg(BigDecimal.ZERO);
|
||||||
|
return previousVO;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -10,5 +10,5 @@ import java.util.List;
|
|||||||
public interface CustomizeExcelService {
|
public interface CustomizeExcelService {
|
||||||
|
|
||||||
|
|
||||||
List<OrderExcelVO> exportOrderExcel(String startTime,String endTime);
|
List<OrderExcelVO> exportOrderExcel(String startTime,String endTime,Long carteenId);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public class CustomizeExcelServiceImpl implements CustomizeExcelService {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<OrderExcelVO> exportOrderExcel(String startTime, String endTime) {
|
public List<OrderExcelVO> exportOrderExcel(String startTime, String endTime,Long carteenId) {
|
||||||
return customizeExcelMapper.selectOrder(startTime,endTime);
|
return customizeExcelMapper.selectOrder(startTime,endTime,carteenId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.member.util;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.YearMonth;
|
import java.time.YearMonth;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.WeekFields;
|
import java.time.temporal.WeekFields;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -41,4 +42,25 @@ public class MemberTimeUtils {
|
|||||||
// 返回年份
|
// 返回年份
|
||||||
return yearMonth.getYear();
|
return yearMonth.getYear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getMonthFromYearMonthString(String yearMonthString) {
|
||||||
|
// 使用YearMonth类解析字符串
|
||||||
|
YearMonth yearMonth = YearMonth.parse(yearMonthString);
|
||||||
|
|
||||||
|
// 返回年份
|
||||||
|
return yearMonth.getMonth().getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getYearMonth(String time) {
|
||||||
|
// 解析成 LocalDate
|
||||||
|
LocalDate date = LocalDate.parse(time);
|
||||||
|
// 获取年份和月份,并格式化为 yyyy-MM 格式
|
||||||
|
return date.format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getDay(String time) {
|
||||||
|
LocalDate date = LocalDate.parse(time);
|
||||||
|
return date.getDayOfMonth();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
from member_order_detail md
|
from member_order_detail md
|
||||||
left join member_dish_order mo on md.order_id = mo.id
|
left join member_dish_order mo on md.order_id = mo.id
|
||||||
left join member_user mu on mu.id = mo.user_id
|
left join member_user mu on mu.id = mo.user_id
|
||||||
where DATE_FORMAT(md.create_time, '%Y%m%d') between #{startTime} and #{endTime}
|
where DATE_FORMAT(md.create_time, '%Y%m%d') between #{startTime} and #{endTime} and mo.store_id = #{carteenId}
|
||||||
order by mo.user_id,order_id
|
order by mo.user_id,order_id
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user