huliguo
2 天以前 5d7b65670282a4fad015e37d567cfa171b162052
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
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, "订单管理");
    }
}