订单新增统计查询
This commit is contained in:
parent
f23fe4982f
commit
d8f31648f8
@ -6,6 +6,7 @@ import com.red.circle.order.inner.model.dto.inapp.CountUserInAppPurchaseDTO;
|
||||
import com.red.circle.order.inner.model.dto.inapp.InAppPurchaseDetailsDTO;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -43,4 +44,11 @@ public interface InAppPurchaseDetailsClientApi {
|
||||
@RequestParam("startTime")LocalDateTime startTime,
|
||||
@RequestParam("endTime")LocalDateTime endTime,
|
||||
@RequestParam("limit")Integer limit);
|
||||
|
||||
/**
|
||||
* 订单统计查询 - 返回金额总数和订单总数
|
||||
*/
|
||||
@PostMapping("/statistics")
|
||||
ResultResponse<Map<String, Object>> statistics(
|
||||
@RequestBody @Validated InAppPurchaseDetailsQryCmd qryCmd);
|
||||
}
|
||||
|
||||
@ -80,6 +80,8 @@ public class InAppPurchaseDetailsQryCmd extends Command {
|
||||
*/
|
||||
private InAppPurchaseStatus status;
|
||||
|
||||
private String countryCode;
|
||||
|
||||
/**
|
||||
* 开始时间.
|
||||
*/
|
||||
|
||||
@ -5,8 +5,11 @@ import com.red.circle.console.app.service.app.order.InAppPurchaseBackService;
|
||||
import com.red.circle.framework.web.controller.BaseController;
|
||||
import com.red.circle.order.inner.model.cmd.inapp.InAppPurchaseDetailsQryCmd;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -39,4 +42,12 @@ public class InAppPurchaseRestController extends BaseController {
|
||||
return inAppPurchaseBackService.listDetails(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单统计查询 - 返回金额总数和订单总数
|
||||
*/
|
||||
@GetMapping("/statistics")
|
||||
public Map<String, Object> statistics(InAppPurchaseDetailsQryCmd query) {
|
||||
return inAppPurchaseBackService.statistics(query);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -126,4 +126,11 @@ public class InAppPurchaseBackServiceImpl implements InAppPurchaseBackService {
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> statistics(InAppPurchaseDetailsQryCmd query) {
|
||||
return ResponseAssert.requiredSuccess(
|
||||
inAppPurchaseDetailsClient.statistics(query)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.red.circle.console.app.service.app.order;
|
||||
import com.red.circle.console.app.dto.clienobject.order.InAppPurchaseDetailsCO;
|
||||
import com.red.circle.order.inner.model.cmd.inapp.InAppPurchaseDetailsQryCmd;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 内购服务.
|
||||
@ -21,4 +22,9 @@ public interface InAppPurchaseBackService extends IOrderService {
|
||||
*/
|
||||
List<InAppPurchaseDetailsCO> listDetails(InAppPurchaseDetailsQryCmd query);
|
||||
|
||||
/**
|
||||
* 订单统计查询 - 返回金额总数和订单总数
|
||||
*/
|
||||
Map<String, Object> statistics(InAppPurchaseDetailsQryCmd query);
|
||||
|
||||
}
|
||||
|
||||
@ -74,6 +74,11 @@ public interface InAppPurchaseDetailsService {
|
||||
*/
|
||||
List<InAppPurchaseDetails> list(InAppPurchaseDetailsQuery query);
|
||||
|
||||
/**
|
||||
* 订单统计查询 - 返回金额总数和订单总数
|
||||
*/
|
||||
Map<String, Object> statistics(InAppPurchaseDetailsQuery query);
|
||||
|
||||
/**
|
||||
* 统计用户内购.
|
||||
*/
|
||||
|
||||
@ -16,6 +16,7 @@ import com.red.circle.tool.core.text.StringUtils;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -195,6 +196,9 @@ public class InAppPurchaseDetailsServiceImpl implements InAppPurchaseDetailsServ
|
||||
if (Objects.nonNull(query.getStatus())) {
|
||||
criteria.and("status").is(query.getStatus());
|
||||
}
|
||||
if (Objects.nonNull(query.getCountryCode())) {
|
||||
criteria.and("countryCode").is(query.getCountryCode());
|
||||
}
|
||||
|
||||
if (Objects.nonNull(query.getStartTime()) && Objects.nonNull(query.getEndTime())) {
|
||||
criteria.andOperator(
|
||||
@ -217,6 +221,84 @@ public class InAppPurchaseDetailsServiceImpl implements InAppPurchaseDetailsServ
|
||||
.limit(query.getLimit()), InAppPurchaseDetails.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> statistics(InAppPurchaseDetailsQuery query) {
|
||||
Criteria criteria = new Criteria();
|
||||
|
||||
if (StringUtils.isNotBlank(query.getId())) {
|
||||
criteria.and("id").is(query.getId());
|
||||
}
|
||||
if (Objects.nonNull(query.getReceiptType())) {
|
||||
criteria.and("receiptType").is(query.getReceiptType());
|
||||
}
|
||||
if (StringUtils.isNotBlank(query.getTrackId())) {
|
||||
criteria.and("trackId").is(query.getTrackId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(query.getSysOrigins())) {
|
||||
List<String> sysOrigins = Arrays.stream(query.getSysOrigins().split(","))
|
||||
.map(String::trim)
|
||||
.filter(StringUtils::isNotBlank).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(sysOrigins)) {
|
||||
criteria.and("sysOrigin").in(sysOrigins);
|
||||
}
|
||||
}
|
||||
if (Objects.nonNull(query.getAcceptUserId())) {
|
||||
criteria.and("acceptUserId").is(query.getAcceptUserId());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(query.getSubscribeId())) {
|
||||
criteria.and("subscribeId").is(query.getSubscribeId());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(query.getOrderId())) {
|
||||
criteria.and("orderId").is(query.getOrderId());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(query.getEnv())) {
|
||||
criteria.and("env").is(query.getEnv());
|
||||
}
|
||||
if (StringUtils.isNotBlank(query.getFactoryPlatform())) {
|
||||
criteria.and("factory.platform").is(query.getFactoryPlatform());
|
||||
}
|
||||
if (Objects.nonNull(query.getStatus())) {
|
||||
criteria.and("status").is(query.getStatus());
|
||||
}
|
||||
if (Objects.nonNull(query.getCountryCode())) {
|
||||
criteria.and("countryCode").is(query.getCountryCode());
|
||||
}
|
||||
if (Objects.nonNull(query.getStartTime()) && Objects.nonNull(query.getEndTime())) {
|
||||
criteria.andOperator(
|
||||
Criteria.where("createTime").gte(query.getStartTime()),
|
||||
Criteria.where("createTime").lte(query.getEndTime())
|
||||
);
|
||||
}
|
||||
|
||||
// 使用聚合管道计算统计
|
||||
AggregationResults<BasicDBObject> results = mongoTemplate.aggregate(
|
||||
Aggregation.newAggregation(
|
||||
Aggregation.match(criteria),
|
||||
Aggregation.group()
|
||||
.count().as("totalOrderCount")
|
||||
.sum("amount").as("totalAmount")
|
||||
.sum("amountUsd").as("totalAmountUsd")
|
||||
.avg("amount").as("averageOrderAmount")
|
||||
),
|
||||
InAppPurchaseDetails.class,
|
||||
BasicDBObject.class);
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
if (CollectionUtils.isNotEmpty(results.getMappedResults())) {
|
||||
BasicDBObject obj = results.getMappedResults().get(0);
|
||||
resultMap.put("totalOrderCount", obj.getLong("totalOrderCount"));
|
||||
resultMap.put("totalAmount", obj.get("totalAmount") != null ? new BigDecimal(obj.get("totalAmount").toString()) : BigDecimal.ZERO);
|
||||
resultMap.put("totalAmountUsd", obj.get("totalAmountUsd") != null ? new BigDecimal(obj.get("totalAmountUsd").toString()) : BigDecimal.ZERO);
|
||||
resultMap.put("averageOrderAmount", obj.get("averageOrderAmount") != null ? new BigDecimal(obj.get("averageOrderAmount").toString()) : BigDecimal.ZERO);
|
||||
} else {
|
||||
resultMap.put("totalOrderCount", 0L);
|
||||
resultMap.put("totalAmount", BigDecimal.ZERO);
|
||||
resultMap.put("totalAmountUsd", BigDecimal.ZERO);
|
||||
resultMap.put("averageOrderAmount", BigDecimal.ZERO);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CountUserInAppPurchase> countUserInAppPurchase(String sysOrigin,
|
||||
LocalDateTime startTime,
|
||||
|
||||
@ -78,6 +78,8 @@ public class InAppPurchaseDetailsQuery implements Serializable {
|
||||
*/
|
||||
private InAppPurchaseStatus status;
|
||||
|
||||
private String countryCode;
|
||||
|
||||
/**
|
||||
* 开始时间.
|
||||
*/
|
||||
|
||||
@ -8,6 +8,7 @@ import com.red.circle.order.inner.model.dto.inapp.InAppPurchaseDetailsDTO;
|
||||
import com.red.circle.order.inner.service.InAppPurchaseDetailsClientService;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -41,6 +42,13 @@ public class InAppPurchaseDetailsClientEndpoint implements InAppPurchaseDetailsC
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultResponse<Map<String, Object>> statistics(InAppPurchaseDetailsQryCmd qryCmd) {
|
||||
return ResultResponse.success(
|
||||
inAppPurchaseDetailsClientService.statistics(qryCmd)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultResponse<List<CountUserInAppPurchaseDTO>> countUserInAppPurchase(String sysOrigin,
|
||||
LocalDateTime startTime, LocalDateTime endTime, Integer limit) {
|
||||
|
||||
@ -5,6 +5,7 @@ import com.red.circle.order.inner.model.dto.inapp.CountUserInAppPurchaseDTO;
|
||||
import com.red.circle.order.inner.model.dto.inapp.InAppPurchaseDetailsDTO;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 内购详情.
|
||||
@ -23,6 +24,11 @@ public interface InAppPurchaseDetailsClientService {
|
||||
*/
|
||||
List<InAppPurchaseDetailsDTO> list(InAppPurchaseDetailsQryCmd qryCmd);
|
||||
|
||||
/**
|
||||
* 订单统计查询 - 返回金额总数和订单总数
|
||||
*/
|
||||
Map<String, Object> statistics(InAppPurchaseDetailsQryCmd qryCmd);
|
||||
|
||||
List<CountUserInAppPurchaseDTO> countUserInAppPurchase(String sysOrigin, LocalDateTime startTime, LocalDateTime endTime, Integer limit);
|
||||
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import com.red.circle.order.inner.model.dto.inapp.InAppPurchaseDetailsDTO;
|
||||
import com.red.circle.order.inner.service.InAppPurchaseDetailsClientService;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -39,6 +40,13 @@ public class InAppPurchaseDetailsClientServiceImpl implements InAppPurchaseDetai
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> statistics(InAppPurchaseDetailsQryCmd qryCmd) {
|
||||
return inAppPurchaseDetailsService.statistics(
|
||||
inAppPurchaseDetailsInnerConvert.toInAppPurchaseDetailsQuery(qryCmd)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CountUserInAppPurchaseDTO> countUserInAppPurchase(String sysOrigin,
|
||||
LocalDateTime startTime, LocalDateTime endTime, Integer limit) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user