From 5d7b65670282a4fad015e37d567cfa171b162052 Mon Sep 17 00:00:00 2001 From: huliguo <2023611923@qq.com> Date: 星期二, 20 五月 2025 12:25:19 +0800 Subject: [PATCH] 基础代码 --- pt-admin/src/main/java/com/ruoyi/web/controller/errand/OrderController.java | 299 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 299 insertions(+), 0 deletions(-) diff --git a/pt-admin/src/main/java/com/ruoyi/web/controller/errand/OrderController.java b/pt-admin/src/main/java/com/ruoyi/web/controller/errand/OrderController.java new file mode 100644 index 0000000..9bc2d10 --- /dev/null +++ b/pt-admin/src/main/java/com/ruoyi/web/controller/errand/OrderController.java @@ -0,0 +1,299 @@ +package com.ruoyi.web.controller.errand; + +import com.alibaba.fastjson2.JSONObject; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.errand.domain.Order; +import com.ruoyi.errand.object.dto.app.ConfirmOrderDTO; +import com.ruoyi.errand.object.dto.app.OrderStatsDTO; +import com.ruoyi.errand.object.dto.app.OrderStatsVO; +import com.ruoyi.errand.object.dto.app.SetConfirmOrderDTO; +import com.ruoyi.errand.object.dto.sys.FinanceStatisticsDTO; +import com.ruoyi.errand.object.dto.sys.OrderPageListDTO; +import com.ruoyi.errand.object.dto.sys.UserStatsDTO; +import com.ruoyi.errand.object.vo.app.*; +import com.ruoyi.errand.object.vo.sys.FinanceStatisticsVO; +import com.ruoyi.errand.object.vo.sys.OrderPageListVO; +import com.ruoyi.errand.object.vo.sys.OrderSysDetailVO; +import com.ruoyi.errand.object.vo.sys.UserStatsVO; +import com.ruoyi.errand.service.OrderService; +import com.ruoyi.errand.utils.RefundCallbackResult; +import com.ruoyi.errand.utils.UniPayCallbackResult; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.annotations.Param; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.io.PrintWriter; +import java.time.*; +import java.util.List; + + +@RestController +@RequestMapping(value = "/app/order") +@Api(value = "订单表", tags = "订单表操作控制器") +@Slf4j +public class OrderController { + @Autowired + private OrderService orderService; + + /** + * 下单 + */ + @PostMapping("/confirmOrder") + @ApiOperation(value = "确认订单",tags = "app用户端-下单页") + public R<ConfirmOrderVO> confirmOrder(@RequestBody @Valid ConfirmOrderDTO confirmOrderDTO) { + return R.ok(orderService.confirmOrder(confirmOrderDTO)); + } + + /** + * 支付 需再次校验会员是否到期 是否设置规定时间? + */ + @PostMapping("/orderPayment") + @ApiOperation(value = "订单支付", tags = {"app用户端-订单支付"}) + public R orderPayment(@RequestBody @Valid ConfirmOrderDTO confirmOrderDTO){ + return orderService.orderPayment(confirmOrderDTO); + } + + /** + * 订单支付回调通知 + */ + @ResponseBody + @GetMapping("/orderPaymentCallback") + public void orderPaymentCallback(UniPayCallbackResult uniPayCallbackResult, HttpServletResponse response){ + String jsonString = JSONObject.toJSONString(uniPayCallbackResult); + log.info("订单支付回调json:{}", jsonString); + R callback = orderService.orderPaymentCallback(uniPayCallbackResult); + if(callback.getCode() == 200){ + response.setStatus(200); + PrintWriter out = null; + try { + out = response.getWriter(); + } catch (IOException e) { + throw new RuntimeException(e); + } + out.println("success"); + out.flush(); + out.close(); + } + } + + + /** + * 订单列表 1待确认2进行中3已取消4已完成 + */ + @GetMapping("/getAppUserOrderList") + @ApiOperation(value = "订单列表",tags = "app用户端-订单页面") + public R<IPage<AppUserOrderListVO>> getAppUserOrderList( + @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, + @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize, + @RequestParam(value = "orderStatus",required = false) Integer orderStatus) { + return R.ok(orderService.getAppUserOrderList(pageNum,pageSize,orderStatus)); + } + /** + * 查看订单详情 + */ + @GetMapping("/getOrderDetail") + @ApiOperation(value = "查看订单详情",tags = {"app用户端-订单页面","app用户端-跑腿员"}) + public R<OrderDetailVO> getOrderDetail(@RequestParam(value = "id") Integer id) { + return R.ok(orderService.getOrderDetail(id)); + } + + /** + * 修改订单信息 (在跑腿接单前,修改了还要提示跑腿) + */ + @PutMapping("/setOrderInfo") + @ApiOperation(value = "修改订单信息",tags = "app用户端-订单页面") + public R<Void> setOrderInfo(@RequestBody @Valid SetConfirmOrderDTO setConfirmOrderDTO) { + orderService.setOrderInfo(setConfirmOrderDTO); + return R.ok(); + } + + /** + * 取消订单 判断状态 回退金额 + */ + @PutMapping("/cancelOrder") + @ApiOperation(value = "取消订单",tags = "app用户端-订单页面") + public R<Void> cancelOrder(@RequestParam(value = "id") Integer id) { + orderService.cancelOrder(id); + return R.ok(); + } + + /** + * 订单取消支付回退 + * + * @param refundCallbackResult + * @param response + * @return + */ + @ResponseBody + @GetMapping("/refundPayMoneyCallback") + public void refundPayMoneyCallback(RefundCallbackResult refundCallbackResult, HttpServletResponse response) { + R callback = orderService.refundPayMoneyCallback(refundCallbackResult); + if (callback.getCode() == 200) { + response.setStatus(200); + PrintWriter out = null; + try { + out = response.getWriter(); + } catch (IOException e) { + throw new RuntimeException(e); + } + out.println("success"); + out.flush(); + out.close(); + } + } + /** + * 订单统计 + */ + @GetMapping("/orderTopInfo") + @PreAuthorize("@ss.hasPermi('system:index:statistics')") + @ApiOperation(value = "订单统计-顶部数据", tags = "系统后台-首页") + public R<OrderTopInfoVO> orderTopInfo(@RequestParam(value = "communityId" ,required = false) Integer communityId) { + return R.ok(orderService.orderTopInfo(communityId==null?0:communityId)); + } + + /** + * 订单统计 + */ + @PostMapping("/statistics") + @PreAuthorize("@ss.hasPermi('system:index:statistics')") + @ApiOperation(value = "订单统计-折线图", tags = "系统后台-首页") + public R<OrderStatsVO> statistics(@RequestBody @Valid OrderStatsDTO orderStatsDTO) { + LocalDateTime[] dateRange;//日期范围 + String datePattern;//日期格式 + + switch (orderStatsDTO.getType()) { + case 1: // 今日 当天数据,按小时划分 + dateRange = new LocalDateTime[]{ + LocalDateTime.now().with(LocalTime.MIN), + LocalDateTime.now().with(LocalTime.MAX) + }; + datePattern = "HH时"; + break; + case 2: // 本周 按星期一、二...划分 + LocalDate now = LocalDate.now(); + dateRange = new LocalDateTime[]{ + now.with(DayOfWeek.MONDAY).atStartOfDay(), // 本周一 + now.with(DayOfWeek.SUNDAY).atTime(LocalTime.MAX) // 本周日 + }; + datePattern = "EEEE"; + break; + case 3: // 本月 按1日至月末划分 + YearMonth currentMonth = YearMonth.now(); + dateRange = new LocalDateTime[]{ + currentMonth.atDay(1).atStartOfDay(), // 本月1日 + currentMonth.atEndOfMonth().atTime(LocalTime.MAX) // 本月最后一天 + }; + datePattern = "dd日"; + break; + case 4: // 本季度 按当前季度的月份划分 + YearMonth thisMonth = YearMonth.now(); + YearMonth firstMonthOfQuarter = thisMonth.with( + Month.of(((thisMonth.getMonthValue() - 1) / 3) * 3 + 1)); + YearMonth lastMonthOfQuarter = firstMonthOfQuarter.plusMonths(2); + dateRange = new LocalDateTime[]{ + firstMonthOfQuarter.atDay(1).atStartOfDay(), // 季度第一个月1日 + lastMonthOfQuarter.atEndOfMonth().atTime(LocalTime.MAX) // 季度最后一个月最后一天 + }; + datePattern = "MM月"; + break; + case 5: // 半年 上半年或下半年完整月份 + YearMonth current = YearMonth.now(); + YearMonth halfYearStart = current.getMonthValue() <= 6 ? + YearMonth.of(current.getYear(), Month.JANUARY) : + YearMonth.of(current.getYear(), Month.JULY); + YearMonth halfYearEnd = halfYearStart.plusMonths(5); + dateRange = new LocalDateTime[]{ + halfYearStart.atDay(1).atStartOfDay(), + halfYearEnd.atEndOfMonth().atTime(LocalTime.MAX) + }; + datePattern = "MM月"; + break; + case 6: // 本年 按1月至12月完整年份 + int year = Year.now().getValue(); + dateRange = new LocalDateTime[]{ + LocalDateTime.of(year, 1, 1, 0, 0), // 1月1日 + LocalDateTime.of(year, 12, 31, 23, 59, 59) // 12月31日 + }; + datePattern = "MM月"; + break; + case 7: // 自定义 按起始时间到终止时间之间的日期划分 + if (orderStatsDTO.getStartDate() == null || orderStatsDTO.getEndDate() == null) { + throw new ServiceException("自定义时间范围必须指定开始和结束日期"); + } + if (orderStatsDTO.getStartDate().isAfter(orderStatsDTO.getEndDate())) { + throw new ServiceException("开始日期不能晚于结束日期"); + } + dateRange = new LocalDateTime[]{ + orderStatsDTO.getStartDate().atStartOfDay(), + orderStatsDTO.getEndDate().atTime(LocalTime.MAX) + }; + datePattern = "yyyy-MM-dd"; + break; + default: + throw new ServiceException("无效的筛选类型: " + orderStatsDTO.getType()); + } + + return R.ok(orderService.getOrderStats(dateRange[0], dateRange[1], datePattern,orderStatsDTO.getCommunityId())); + } + + /** + * 财务统计列表 + */ + @PostMapping("/financeStatistics") + @PreAuthorize("@ss.hasPermi('system:finance:statistics')") + @ApiOperation(value = "财务统计-分页列表", tags = "系统后台-首页") + public R<IPage<FinanceStatisticsVO>> financeStatistics(@RequestBody @Valid FinanceStatisticsDTO financeStatisticsDTO) { + return R.ok(orderService.financeStatistics(financeStatisticsDTO)); + } + /** + * 导出 + */ + @PostMapping("/financeStatistics/export") + @PreAuthorize("@ss.hasPermi('system:finance:statistics')") + @ApiOperation(value = "财务统计-导出", tags = "系统后台-首页") + public void export(HttpServletResponse response,@RequestBody @Valid FinanceStatisticsDTO financeStatisticsDTO) { + List<FinanceStatisticsVO> exportList=orderService.export(financeStatisticsDTO); + ExcelUtil<FinanceStatisticsVO> util = new ExcelUtil<FinanceStatisticsVO>(FinanceStatisticsVO.class); + util.exportExcel(response, exportList, "财务统计"); + } + /** + * 订单管理列表 + */ + @PostMapping("/list") + @PreAuthorize("@ss.hasPermi('system:order:list')") + @ApiOperation(value = "订单管理-分页列表", tags = "系统后台-订单管理") + public R<IPage<OrderPageListVO>> getOrderPageList(@RequestBody @Valid OrderPageListDTO orderPageListDTO) { + return R.ok(orderService.getOrderPageList(orderPageListDTO)); + } + /** + * 查看详情 + */ + @GetMapping("/detail") + @PreAuthorize("@ss.hasPermi('system:order:list')") + @ApiOperation(value = "订单管理-订单详情", tags = "系统后台-订单管理") + public R<OrderSysDetailVO> detail(@RequestParam("id") Integer id) { + return R.ok(orderService.detail(id)); + } + + /** + * 导出 + */ + @PostMapping("/list/export") + @PreAuthorize("@ss.hasPermi('system:order:list')") + @ApiOperation(value = "订单管理-导出", tags = "系统后台-订单管理") + public void orderExport(HttpServletResponse response,@RequestBody @Valid OrderPageListDTO orderPageListDTO) { + List<OrderPageListVO> exportList=orderService.orderExport(orderPageListDTO); + ExcelUtil<OrderPageListVO> util = new ExcelUtil<OrderPageListVO>(OrderPageListVO.class); + util.exportExcel(response, exportList, "订单管理"); + } +} \ No newline at end of file -- Gitblit v1.7.1