统计和导出
This commit is contained in:
@ -48,20 +48,18 @@ public class CustomizeExcelController {
|
||||
@GetMapping("/orderExcel")
|
||||
@Operation(summary = "导出订单详情")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportBusinessExcel(String startTime,String endTime,
|
||||
public void exportBusinessExcel(String startTime,String endTime,Long carteenId,
|
||||
HttpServletResponse response) throws IOException {
|
||||
|
||||
List<OrderExcelVO> orderExcelVOS = excelService.exportOrderExcel(startTime, endTime);
|
||||
List<OrderExcelVO> orderExcelVOS = excelService.exportOrderExcel(startTime, endTime,carteenId);
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "订单详情统计.xls", "数据", OrderExcelVO.class,
|
||||
orderExcelVOS);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据时间导出多个sheet 页
|
||||
* @param list
|
||||
* @param
|
||||
* @param response
|
||||
* @throws IOException
|
||||
*/
|
||||
|
@ -9,7 +9,7 @@ import java.util.List;
|
||||
@Data
|
||||
public class BusinessDataVO {
|
||||
|
||||
private BusinessRespVO old;
|
||||
private BusinessRespVO now;
|
||||
private List<BusinessRespVO> businessList;
|
||||
|
||||
|
||||
|
@ -11,5 +11,5 @@ import java.util.List;
|
||||
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
|
||||
public BusinessDataVO getDay(String time,Long carteenId) {
|
||||
|
||||
Integer nowDay = MemberTimeUtils.getDay(time);
|
||||
time = MemberTimeUtils.getYearMonth(time);
|
||||
|
||||
BusinessDataVO businessDataVO = new BusinessDataVO();
|
||||
|
||||
LambdaQueryWrapper<BusinessDO> wrapper = new LambdaQueryWrapper<>();
|
||||
@ -210,17 +213,14 @@ public class BusinessServiceImpl implements BusinessService {
|
||||
if(CollectionUtil.isNotEmpty(previousList)){
|
||||
BeanUtil.copyProperties(previousList.get(0), old);
|
||||
}else {
|
||||
old.setTurnover(BigDecimal.ZERO).setOrderSum(0).setReduce(BigDecimal.ZERO).setWeigh(BigDecimal.ZERO)
|
||||
.setBreakfast(BigDecimal.ZERO).setLunch(BigDecimal.ZERO).setDinner(BigDecimal.ZERO);
|
||||
old = getInitBusinessRespVO();
|
||||
}
|
||||
|
||||
// 循环遍历该月的每一天
|
||||
for (int day = 1; day <= daysInMonth; day++) {
|
||||
BusinessRespVO bean = new BusinessRespVO();
|
||||
if(map.get(day) == null){
|
||||
bean.setTurnover(BigDecimal.ZERO).setOrderSum(0).setReduce(BigDecimal.ZERO).setWeigh(BigDecimal.ZERO)
|
||||
.setBreakfast(BigDecimal.ZERO).setLunch(BigDecimal.ZERO).setDinner(BigDecimal.ZERO)
|
||||
.setTime(String.valueOf(day));
|
||||
bean = getInitBusinessRespVO().setTime(String.valueOf(day));
|
||||
}else {
|
||||
bean = BeanUtils.toBean(map.get(day), BusinessRespVO.class);
|
||||
bean.setTime(String.valueOf(day));
|
||||
@ -234,7 +234,7 @@ public class BusinessServiceImpl implements BusinessService {
|
||||
monthData.put(day,bean);
|
||||
|
||||
}
|
||||
|
||||
businessDataVO.setNow(monthData.get(nowDay));
|
||||
businessDataVO.setBusinessList(new ArrayList<>(monthData.values()));
|
||||
return businessDataVO;
|
||||
}
|
||||
@ -254,10 +254,7 @@ public class BusinessServiceImpl implements BusinessService {
|
||||
|
||||
int totalWeeksOfMonth = MemberTimeUtils.getTotalWeeksOfMonth(time);
|
||||
for (int i = 1; i <= totalWeeksOfMonth; i++) {
|
||||
BusinessRespVO bean = new BusinessRespVO();
|
||||
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));
|
||||
BusinessRespVO bean = getInitBusinessRespVO().setTime(String.valueOf(i));
|
||||
map.put(i,bean);
|
||||
}
|
||||
|
||||
@ -281,6 +278,7 @@ public class BusinessServiceImpl implements BusinessService {
|
||||
|
||||
@Override
|
||||
public BusinessDataVO getMonth(String time,Long carteenId) {
|
||||
time = MemberTimeUtils.getYearMonth(time);
|
||||
|
||||
BusinessDataVO businessDataVO = new BusinessDataVO();
|
||||
|
||||
@ -295,10 +293,8 @@ public class BusinessServiceImpl implements BusinessService {
|
||||
Map<Integer,BusinessRespVO> map = new HashMap<>();
|
||||
//时间处理
|
||||
for (int i = 1; i <= 12; i++) {
|
||||
BusinessRespVO bean = new BusinessRespVO();
|
||||
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));
|
||||
BusinessRespVO bean = getInitBusinessRespVO();
|
||||
bean.setTime(String.valueOf(i));
|
||||
map.put(i,bean);
|
||||
}
|
||||
//数据统计
|
||||
@ -319,9 +315,7 @@ public class BusinessServiceImpl implements BusinessService {
|
||||
previousWrapper.orderByAsc(BusinessDO::getCreateTime);
|
||||
previousWrapper.apply("DATE_FORMAT(create_time, '%Y-%m') = {0}", previousYear+"-12");
|
||||
List<BusinessDO> previousList = businessMapper.selectList(previousWrapper);
|
||||
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);
|
||||
BusinessRespVO previousVO = getInitBusinessRespVO();
|
||||
for (BusinessDO businessDO : previousList) {
|
||||
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()));
|
||||
|
||||
return businessDataVO;
|
||||
@ -367,4 +363,11 @@ public class BusinessServiceImpl implements BusinessService {
|
||||
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 {
|
||||
|
||||
|
||||
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
|
||||
public List<OrderExcelVO> exportOrderExcel(String startTime, String endTime) {
|
||||
return customizeExcelMapper.selectOrder(startTime,endTime);
|
||||
public List<OrderExcelVO> exportOrderExcel(String startTime, String endTime,Long carteenId) {
|
||||
return customizeExcelMapper.selectOrder(startTime,endTime,carteenId);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.member.util;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.WeekFields;
|
||||
import java.util.Locale;
|
||||
|
||||
@ -41,4 +42,25 @@ public class MemberTimeUtils {
|
||||
// 返回年份
|
||||
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
|
||||
left join member_dish_order mo on md.order_id = mo.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
|
||||
</select>
|
||||
|
||||
|
Reference in New Issue
Block a user