fix[订单模块]:排队,oss路径,自动任务,订单状态等逻辑
This commit is contained in:
+84
-8
@@ -88,7 +88,11 @@ public class OrderController {
|
||||
})
|
||||
@GetMapping
|
||||
public PageResult list(@RequestParam Map<String, Object> params) {
|
||||
params.put("userId", LoginUserContextHolder.getUser().getId());
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
if (user == null) {
|
||||
return new PageResult<>();
|
||||
}
|
||||
params.put("userId", user.getId());
|
||||
return orderService.findListByUser(params);
|
||||
}
|
||||
|
||||
@@ -106,7 +110,7 @@ public class OrderController {
|
||||
params.put("userId", user.getId());
|
||||
|
||||
// 获取当前日期,格式化为 yyyyMMdd
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
|
||||
PageResult<Order> result = orderService.findListByUser(params);
|
||||
if (result.getCount() > 0){
|
||||
@@ -121,10 +125,20 @@ public class OrderController {
|
||||
if (list.size() > 0){
|
||||
for (OrderFile orderFile : list){
|
||||
Map imgMap = new HashMap();
|
||||
imgMap.put("url", fileCenterService.getViewUrl(orderFile.getFileId()));
|
||||
OrderFile file = orderFileService.getOrderFileByFileId(orderFile.getFileId());
|
||||
if (file != null){
|
||||
imgMap.put("contentType", file.getFileType());
|
||||
String url = fileCenterService.getViewUrlByName(orderFile.getFilePath());
|
||||
url = url.replace("goflyapp.oss-cn-beijing.aliyuncs.com","cdn.goflytec.com");
|
||||
imgMap.put("url", url);
|
||||
//@TODO 待优化file_type获取方式
|
||||
if (url != null && !"".equals(url) ){
|
||||
if (url.contains(".jpeg")){
|
||||
imgMap.put("contentType", "image/jpeg");
|
||||
}else if (url.contains(".png")){
|
||||
imgMap.put("contentType", "image/png");
|
||||
}else if (url.contains(".gif")){
|
||||
imgMap.put("contentType", "image/gif");
|
||||
}else if (url.contains(".mp4")){
|
||||
imgMap.put("contentType", "video/mp4");
|
||||
}
|
||||
}
|
||||
resultList.add(imgMap);
|
||||
}
|
||||
@@ -205,16 +219,35 @@ public class OrderController {
|
||||
// 获取排队总览信息
|
||||
@GetMapping("/queue/info")
|
||||
public Result<Map> getQueueInfo() {
|
||||
Double price = 25.0;
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
Double price = 6.99;
|
||||
long execTime = 3; //一单执行时间默认3分钟
|
||||
Long count = orderService.getOrderCountByStatus(OrderStatus.PAID.getId());
|
||||
Long userOrderCount = orderService.getOrderCountByStatusAndUser(OrderStatus.PAID.getId(),user.getId());
|
||||
if (userOrderCount > 0){
|
||||
count = count - userOrderCount;
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("count", count);
|
||||
map.put("count", count == 0 ? -1 : count);
|
||||
map.put("time",Math.multiplyExact(count,execTime));
|
||||
map.put("price",price);
|
||||
return Result.succeed(map,"获取成功");
|
||||
}
|
||||
|
||||
// 获取排队总览信息
|
||||
@GetMapping("/queue/info/user")
|
||||
public Result<Integer> getQueueInfoByUser() {
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
Long count = orderService.getOrderCountByStatusAndUser(OrderStatus.PAID.getId(),user.getId());
|
||||
if (count == 0){
|
||||
return Result.succeed(0,"该用户未存在待执行订单");
|
||||
}else if (count > 0 ){
|
||||
return Result.succeed(1,"存在待执行订单");
|
||||
}
|
||||
return Result.succeed(0,"该用户未存在待执行订单");
|
||||
|
||||
}
|
||||
|
||||
// 获取排队中的订单列表
|
||||
@GetMapping("/queue")
|
||||
public Result<List<Order>> getOrdersInQueue() {
|
||||
@@ -222,6 +255,16 @@ public class OrderController {
|
||||
return Result.succeed(orders,"获取成功");
|
||||
}
|
||||
|
||||
// 获取排队中的订单列表
|
||||
@GetMapping("/queue/first")
|
||||
public Result<Order> getOrdersInQueueFirstOne() {
|
||||
List<Order> orders = orderService.getOrdersInQueue();
|
||||
if (orders.size() > 0){
|
||||
return Result.succeed(orders.get(0),"获取成功");
|
||||
}
|
||||
return Result.failed("未存在排队队列");
|
||||
}
|
||||
|
||||
// 处理排队中的订单(模拟消费通知等操作)
|
||||
@PutMapping("/queue/process")
|
||||
public Result<String> processOrdersInQueue() {
|
||||
@@ -243,6 +286,24 @@ public class OrderController {
|
||||
return Result.failed("未查询到订单数据");
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
public Result<String> updateOrderStatusComplete(@RequestBody Map payload) {
|
||||
Order order = orderService.getOrderByNumber(payload.get("orderNo").toString());
|
||||
if (order != null) {
|
||||
if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
|
||||
order.setOrderStatus(OrderStatus.COMPLETE.getId());
|
||||
boolean res = orderService.updateOrder(order);
|
||||
if (res){
|
||||
return Result.succeed("更新成功");
|
||||
}
|
||||
}else {
|
||||
return Result.failed("已更新");
|
||||
}
|
||||
|
||||
}
|
||||
return Result.failed("未查询到订单数据");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 商户订单号查询订单 */
|
||||
@@ -280,4 +341,19 @@ public class OrderController {
|
||||
}
|
||||
return Result.failed("请重试");
|
||||
}
|
||||
|
||||
@GetMapping("/status/{orderNo}")
|
||||
public Result getOrderExecStatus(@PathVariable("orderNo") String orderNo) {
|
||||
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null){
|
||||
return Result.failed("未查询到订单");
|
||||
}
|
||||
if (order.getOrderStatus().equals(OrderStatus.COMPLETE.getId())){
|
||||
return Result.failed("已执行");
|
||||
}else if (order.getOrderStatus().equals(OrderStatus.PAID.getId())){
|
||||
return Result.succeed("待执行");
|
||||
}
|
||||
return Result.failed("不满足执行条件");
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -102,6 +102,7 @@ public class OrderFileController {
|
||||
if (!CollectionUtils.isEmpty(orderFiles)) {
|
||||
for (OrderFile orderFile : orderFiles) {
|
||||
String viewUrl = fileCenterService.getViewUrl(orderFile.getFileId());
|
||||
System.out.println("viewUrl:"+ viewUrl);
|
||||
orderFile.setViewUrl(viewUrl);
|
||||
}
|
||||
}else {
|
||||
@@ -135,7 +136,7 @@ public class OrderFileController {
|
||||
if (orderFile.getFilePath() != null) {
|
||||
|
||||
FileInfo fileInfo = fileCenterService.creatFileInfo(orderFile.getFilePath());
|
||||
orderFile.setFileId(fileInfo.get);
|
||||
orderFile.setFileId(fileInfo.getId());
|
||||
orderFile.setFilePath(fileInfo.getPath());
|
||||
orderFile.setFileType(fileInfo.getContentType());
|
||||
orderFile.setTourismId(order.getTourismId());
|
||||
|
||||
@@ -40,4 +40,7 @@ public interface FileCenterService {
|
||||
|
||||
@PostMapping("/path")
|
||||
FileInfo creatFileInfo(@RequestBody String path);
|
||||
|
||||
@PostMapping("/files/name")
|
||||
String getViewUrlByName(@RequestBody String name) ;
|
||||
}
|
||||
|
||||
+5
@@ -45,6 +45,11 @@ public class FileCenterServiceFallbackFactory implements FallbackFactory<FileCen
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getViewUrlByName(String name) {
|
||||
return "";
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ public class OrderTimeoutScheduler {
|
||||
}
|
||||
|
||||
// 每隔一定时间(这里设置为每分钟检查一次,可根据实际情况调整)检查订单超时情况
|
||||
@Scheduled(fixedRate = 60 * 1000)
|
||||
@Scheduled(fixedRate = 1 * 1000)
|
||||
public void checkOrderPaySuccess() {
|
||||
orderService.updateOrderStatus();
|
||||
}
|
||||
|
||||
@@ -72,6 +72,8 @@ public interface IOrderService extends ISuperService<Order> {
|
||||
*/
|
||||
Long getOrderCountByStatus(Integer status);
|
||||
|
||||
Long getOrderCountByStatusAndUser(Integer status, Long userId);
|
||||
|
||||
/**
|
||||
* 获取user订单记录
|
||||
* @param params
|
||||
|
||||
+8
@@ -156,6 +156,14 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getOrderCountByStatusAndUser(Integer status, Long userId) {
|
||||
return baseMapper.selectCount(new QueryWrapper<Order>()
|
||||
.eq("order_status", status)
|
||||
.eq("user_id", userId));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult findListByUser(Map<String, Object> params) {
|
||||
Page<Order> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||
|
||||
@@ -4,10 +4,10 @@ server:
|
||||
spring:
|
||||
application:
|
||||
name: order-center
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# ip: 119.45.169.13
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
ip: 119.45.169.13
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</update>
|
||||
<!-- 查询所有处于排队状态的订单 -->
|
||||
<select id="getOrdersInQueue" resultType="com.central.order.model.Order">
|
||||
SELECT * FROM orders WHERE order_status = 1
|
||||
SELECT * FROM orders WHERE order_status = 1 order by id asc
|
||||
</select>
|
||||
|
||||
<!-- 根据店铺编号和创建时间(当天)查询订单数量 -->
|
||||
|
||||
Reference in New Issue
Block a user