|
@@ -0,0 +1,134 @@
|
|
|
|
+package info.aspirecn.cloud.yysj.controller;
|
|
|
|
+
|
|
|
|
+import info.aspirecn.cloud.yysj.exception.PageSizeErrorException;
|
|
|
|
+import info.aspirecn.cloud.yysj.model.ResponseInfo;
|
|
|
|
+import info.aspirecn.cloud.yysj.model.response.ChildOrderInfo;
|
|
|
|
+import info.aspirecn.cloud.yysj.model.response.OrderInfo;
|
|
|
|
+import info.aspirecn.cloud.yysj.model.response.OrderInfoList;
|
|
|
|
+import info.aspirecn.cloud.yysj.service.OrderService;
|
|
|
|
+import io.swagger.annotations.*;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 用户订单统计、消费信息、余额、产品消费比例等信息查询,适用于首页
|
|
|
|
+ *
|
|
|
|
+ * @author dingliqiang
|
|
|
|
+ */
|
|
|
|
+@Api(tags = "订单查询接口")
|
|
|
|
+@ApiResponses({
|
|
|
|
+ @ApiResponse(code = 200, message = "成功处理请求"),
|
|
|
|
+ @ApiResponse(code = 400, message = "没有找到该用户信息"),
|
|
|
|
+ @ApiResponse(code = 401, message = "没有权限访问该服务"),
|
|
|
|
+ @ApiResponse(code = 403, message = "权限不足无法访问该服务"),
|
|
|
|
+ @ApiResponse(code = 404, message = "未发现该微服务"),
|
|
|
|
+ @ApiResponse(code = 500, message = "服务器内部错误")
|
|
|
|
+})
|
|
|
|
+@Slf4j
|
|
|
|
+@RestController
|
|
|
|
+public class OrderQueryController {
|
|
|
|
+
|
|
|
|
+ private DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private OrderService orderService;
|
|
|
|
+
|
|
|
|
+ private static final int NUM_LIMIT = 5000;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取用户主订单列表
|
|
|
|
+ *
|
|
|
|
+ * @param userId 用户ID
|
|
|
|
+ * @param pageNum 请求第几页
|
|
|
|
+ * @param pageSize 一页的大小
|
|
|
|
+ * @return 主订单列表
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "主订单列表", notes = "获取用户主订单列表。")
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name = "orderId", value = "主订单ID", dataType = "string", required = false, paramType = "query"),
|
|
|
|
+ @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "string", required = false, paramType = "query"),
|
|
|
|
+ @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "string", required = false, paramType = "query"),
|
|
|
|
+ @ApiImplicitParam(name = "pageNum", value = "请求第几页", dataType = "string", required = false, paramType = "query"),
|
|
|
|
+ @ApiImplicitParam(name = "pageSize", value = "一页的大小", dataType = "string", required = false, paramType = "query"),
|
|
|
|
+ @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "string", required = true, paramType = "header")
|
|
|
|
+ })
|
|
|
|
+ @GetMapping("/orderList")
|
|
|
|
+ public ResponseInfo getOrderList(@RequestParam(required = false) String orderId,
|
|
|
|
+ @RequestParam(required = false) String startTime,
|
|
|
|
+ @RequestParam(required = false) String endTime,
|
|
|
|
+ @RequestParam(required = false, defaultValue = "1") Integer pageNum,
|
|
|
|
+ @RequestParam(required = false, defaultValue = "10") Integer pageSize,
|
|
|
|
+ @RequestHeader(required = true) String userId,
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
+ // 设置查询深度,不能太深,否则会影响ES
|
|
|
|
+ if (pageNum * pageSize >= NUM_LIMIT){
|
|
|
|
+ throw new PageSizeErrorException();
|
|
|
|
+ }
|
|
|
|
+ // 开始、结束时间
|
|
|
|
+ if (StringUtils.isEmpty(startTime)) {
|
|
|
|
+ startTime = dtf.format(LocalDateTime.now().minusDays(10));
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isEmpty(endTime)) {
|
|
|
|
+ endTime = dtf.format(LocalDateTime.now());
|
|
|
|
+ }
|
|
|
|
+ // 获取数据
|
|
|
|
+ OrderInfoList statisticsList = orderService.getOrderList(userId,orderId, startTime, endTime, pageNum, pageSize);
|
|
|
|
+ // 处理价格单位
|
|
|
|
+ for (OrderInfo orderInfo:statisticsList.getOrderInfos()){
|
|
|
|
+ orderInfo.setOrderAmount(priceProcess(orderInfo.getOrderAmount()));
|
|
|
|
+ }
|
|
|
|
+ // 设置分页
|
|
|
|
+ response.addHeader("pageNum",String.valueOf(statisticsList.getPageNum()));
|
|
|
|
+ response.addHeader("pageTotal",String.valueOf(statisticsList.getPageTotal()));
|
|
|
|
+ response.addHeader("pageSize",String.valueOf(statisticsList.getPageSize()));
|
|
|
|
+ response.addHeader("total",String.valueOf(statisticsList.getTotal()));
|
|
|
|
+ return new ResponseInfo().setData(statisticsList.getOrderInfos()).setMessage("请求成功");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 主订单详情查询
|
|
|
|
+ *
|
|
|
|
+ * @param orderId 主订单ID
|
|
|
|
+ * @return 主订单详情信息
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "主订单详情查询", notes = "查询主订单详情信息(子订单信息)。")
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name = "orderId", value = "主订单ID", dataType = "string", required = true, paramType = "path")
|
|
|
|
+ })
|
|
|
|
+ @GetMapping("/order/{orderId}")
|
|
|
|
+ public ResponseInfo getOrderDetail(@PathVariable(required = true) String orderId) {
|
|
|
|
+ List<ChildOrderInfo> consumptionList = orderService.getOrderDetail(orderId);
|
|
|
|
+ // 处理价格单位
|
|
|
|
+ for (ChildOrderInfo childOrderInfo : consumptionList){
|
|
|
|
+ childOrderInfo.setPrice(priceProcess(childOrderInfo.getPrice()));
|
|
|
|
+ }
|
|
|
|
+ return new ResponseInfo().setData(consumptionList).setMessage("请求成功");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理价格单位
|
|
|
|
+ */
|
|
|
|
+ private String priceProcess(String price){
|
|
|
|
+ // 获取签名部分
|
|
|
|
+ if (price.length() == 1){
|
|
|
|
+ return "0.00" + price;
|
|
|
|
+ } else if (price.length() == 2){
|
|
|
|
+ return "0.0" + price;
|
|
|
|
+ } else if (price.length() == 3){
|
|
|
|
+ return "0." + price;
|
|
|
|
+ }
|
|
|
|
+ // 获取签名部分
|
|
|
|
+ String pricePre = StringUtils.substring(price,0,price.length()-3);
|
|
|
|
+ // 获取后面部分
|
|
|
|
+ String pricePost = StringUtils.substring(price,price.length()-3,price.length());
|
|
|
|
+ // 拼接
|
|
|
|
+ return pricePre + "." + pricePost;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|