Compare commits
2 Commits
5b7c78e024
...
887ab084e9
Author | SHA1 | Date | |
---|---|---|---|
887ab084e9 | |||
ee76a4cfda |
@ -85,4 +85,10 @@ public interface CacheNames {
|
|||||||
*/
|
*/
|
||||||
String DELAY_ORDER_UNPAY = GlobalConstants.GLOBAL_REDIS_KEY + "order_unpay";
|
String DELAY_ORDER_UNPAY = GlobalConstants.GLOBAL_REDIS_KEY + "order_unpay";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 延时队列:订单支付未核销
|
||||||
|
*/
|
||||||
|
String DELAY_ORDER_TO_BE_USED = GlobalConstants.GLOBAL_REDIS_KEY + "order_tobe_used";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,9 +73,14 @@ public interface Constants {
|
|||||||
Long TOP_PARENT_ID = 0L;
|
Long TOP_PARENT_ID = 0L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单未支付自动取消时间(秒)
|
* 订单未支付自动取消时间(分钟)
|
||||||
*/
|
*/
|
||||||
Long ORDER_CANCEL_TIME = 900L;
|
Long ORDER_CANCEL_TIME = 15L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单支付未核销自动退款时间(天)
|
||||||
|
*/
|
||||||
|
Long ORDER_REFUND_TIME = 14L;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import org.dromara.common.core.domain.R;
|
|||||||
import org.dromara.common.log.annotation.Log;
|
import org.dromara.common.log.annotation.Log;
|
||||||
import org.dromara.common.log.enums.BusinessType;
|
import org.dromara.common.log.enums.BusinessType;
|
||||||
import org.dromara.common.web.core.BaseController;
|
import org.dromara.common.web.core.BaseController;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -29,6 +30,7 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/pms/product/category")
|
@RequestMapping("/pms/product/category")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Validated
|
||||||
public class ProductCategoryController extends BaseController {
|
public class ProductCategoryController extends BaseController {
|
||||||
|
|
||||||
private final ProductCategoryService service;
|
private final ProductCategoryService service;
|
||||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.ibatis.type.JdbcType;
|
import org.apache.ibatis.type.JdbcType;
|
||||||
import org.dromara.common.core.domain.model.BaseAudit;
|
import org.dromara.common.core.domain.model.BaseAudit;
|
||||||
@ -30,6 +31,7 @@ public class ProductCategory extends BaseAudit {
|
|||||||
|
|
||||||
@Schema(description = "NAME")
|
@Schema(description = "NAME")
|
||||||
@Excel(name = "NAME")
|
@Excel(name = "NAME")
|
||||||
|
@NotBlank(message = "名称不能为空")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "分类级别:0->1级;1->2级")
|
@Schema(description = "分类级别:0->1级;1->2级")
|
||||||
@ -46,6 +48,7 @@ public class ProductCategory extends BaseAudit {
|
|||||||
|
|
||||||
@Schema(description = "图标")
|
@Schema(description = "图标")
|
||||||
@Excel(name = "图标")
|
@Excel(name = "图标")
|
||||||
|
@NotBlank(message = "图标不能为空")
|
||||||
private String icon;
|
private String icon;
|
||||||
|
|
||||||
@Schema(description = "删除标志(0代表存在,1代表删除)")
|
@Schema(description = "删除标志(0代表存在,1代表删除)")
|
||||||
|
@ -8,5 +8,10 @@ import com.wzj.soopin.goods.domain.vo.ProductCategoryVO;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ProductCategoryService extends IService<ProductCategory> {
|
public interface ProductCategoryService extends IService<ProductCategory> {
|
||||||
|
|
||||||
|
boolean save(ProductCategory productCategory);
|
||||||
|
|
||||||
|
boolean updateById(ProductCategory productCategory);
|
||||||
|
|
||||||
List<ProductCategoryVO> tree(Wrapper<ProductCategory> wrapper);
|
List<ProductCategoryVO> tree(Wrapper<ProductCategory> wrapper);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.wzj.soopin.goods.service.impl;
|
package com.wzj.soopin.goods.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.wzj.soopin.goods.convert.ProductCategoryConvert;
|
import com.wzj.soopin.goods.convert.ProductCategoryConvert;
|
||||||
import com.wzj.soopin.goods.domain.entity.ProductCategory;
|
import com.wzj.soopin.goods.domain.entity.ProductCategory;
|
||||||
@ -8,6 +10,7 @@ import com.wzj.soopin.goods.domain.vo.ProductCategoryVO;
|
|||||||
import com.wzj.soopin.goods.mapper.ProductCategoryMapper;
|
import com.wzj.soopin.goods.mapper.ProductCategoryMapper;
|
||||||
import com.wzj.soopin.goods.service.ProductCategoryService;
|
import com.wzj.soopin.goods.service.ProductCategoryService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@ -28,6 +31,32 @@ public class ProductCategoryServiceImpl extends ServiceImpl<ProductCategoryMappe
|
|||||||
|
|
||||||
private final ProductCategoryConvert convert;
|
private final ProductCategoryConvert convert;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean save(ProductCategory productCategory) {
|
||||||
|
if (productCategory.getParentId() == null || productCategory.getParentId() == 0) {
|
||||||
|
productCategory.setLevel(1);
|
||||||
|
productCategory.setParentId(0L);
|
||||||
|
} else {
|
||||||
|
ProductCategory parent = this.getById(productCategory.getParentId());
|
||||||
|
productCategory.setLevel(parent.getLevel() + 1);
|
||||||
|
}
|
||||||
|
boolean exists = this.exists(Wrappers.lambdaQuery(ProductCategory.class)
|
||||||
|
.eq(ProductCategory::getName, productCategory.getName())
|
||||||
|
.eq(ProductCategory::getParentId, productCategory.getParentId()));
|
||||||
|
Assert.isFalse(exists, () -> ServiceException.of("分类已存在"));
|
||||||
|
return super.save(productCategory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateById(ProductCategory productCategory) {
|
||||||
|
boolean exists = this.exists(Wrappers.lambdaQuery(ProductCategory.class)
|
||||||
|
.ne(ProductCategory::getId, productCategory.getId())
|
||||||
|
.eq(ProductCategory::getName, productCategory.getName())
|
||||||
|
.eq(ProductCategory::getParentId, productCategory.getParentId()));
|
||||||
|
Assert.isFalse(exists, () -> ServiceException.of("分类已存在"));
|
||||||
|
return super.updateById(productCategory);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ProductCategoryVO> tree(Wrapper<ProductCategory> wrapper) {
|
public List<ProductCategoryVO> tree(Wrapper<ProductCategory> wrapper) {
|
||||||
List<ProductCategory> list = this.list(wrapper);
|
List<ProductCategory> list = this.list(wrapper);
|
||||||
|
@ -64,8 +64,10 @@ import java.util.*;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.dromara.common.core.constant.CacheNames.DELAY_ORDER_TO_BE_USED;
|
||||||
import static org.dromara.common.core.constant.CacheNames.DELAY_ORDER_UNPAY;
|
import static org.dromara.common.core.constant.CacheNames.DELAY_ORDER_UNPAY;
|
||||||
import static org.dromara.common.core.constant.Constants.ORDER_CANCEL_TIME;
|
import static org.dromara.common.core.constant.Constants.ORDER_CANCEL_TIME;
|
||||||
|
import static org.dromara.common.core.constant.Constants.ORDER_REFUND_TIME;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -281,7 +283,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|||||||
}).toList();
|
}).toList();
|
||||||
orderItemMapper.insert(orderItemList);
|
orderItemMapper.insert(orderItemList);
|
||||||
// 添加订单到延迟队列
|
// 添加订单到延迟队列
|
||||||
QueueUtils.addDelayedQueueObject(DELAY_ORDER_UNPAY, order.getId(), ORDER_CANCEL_TIME, TimeUnit.SECONDS);
|
QueueUtils.addDelayedQueueObject(DELAY_ORDER_UNPAY, order.getId(), ORDER_CANCEL_TIME, TimeUnit.MINUTES);
|
||||||
return BeanUtil.copyProperties(order, OrderVO.class);
|
return BeanUtil.copyProperties(order, OrderVO.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,7 +567,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|||||||
.paymentTime(LocalDateTime.now())
|
.paymentTime(LocalDateTime.now())
|
||||||
.payType(payType)
|
.payType(payType)
|
||||||
.build());
|
.build());
|
||||||
|
// 添加已支付订单到延迟队列,14天未使用自动退款
|
||||||
|
QueueUtils.addDelayedQueueObject(DELAY_ORDER_TO_BE_USED, order.getId(), ORDER_REFUND_TIME, TimeUnit.DAYS);
|
||||||
//发出消息
|
//发出消息
|
||||||
MqUtil.sendIMMessage(buildMQMessage(order));
|
MqUtil.sendIMMessage(buildMQMessage(order));
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
import static org.dromara.common.core.constant.CacheNames.DELAY_ORDER_TO_BE_USED;
|
||||||
import static org.dromara.common.core.constant.CacheNames.DELAY_ORDER_UNPAY;
|
import static org.dromara.common.core.constant.CacheNames.DELAY_ORDER_UNPAY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,4 +66,26 @@ public class OrderScheduledTask {
|
|||||||
});
|
});
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订阅redis延迟队列退款已支付未核销的订单
|
||||||
|
*/
|
||||||
|
@PostConstruct
|
||||||
|
public void orderRefundByDelayedQueue() {
|
||||||
|
log.info("订单已支付未核销延时队列: {} 监听中......",DELAY_ORDER_TO_BE_USED);
|
||||||
|
// 项目初始化设置一次即可
|
||||||
|
QueueUtils.subscribeBlockingQueue(DELAY_ORDER_TO_BE_USED, (Long orderId) -> {
|
||||||
|
// 观察接收时间
|
||||||
|
log.info("订单未支付延时队列: {}, 收到订单id: {}", DELAY_ORDER_TO_BE_USED, orderId);
|
||||||
|
return CompletableFuture.runAsync(() -> {
|
||||||
|
// 异步处理数据逻辑 不要在上方处理业务逻辑
|
||||||
|
orderService.update(Wrappers.lambdaUpdate(Order.class)
|
||||||
|
.eq(Order::getId, orderId)
|
||||||
|
.eq(Order::getStatus, OrderStatusEnum.VERIFY.getValue())
|
||||||
|
.set(Order::getStatus, OrderStatusEnum.REFUNDED.getValue()));
|
||||||
|
// TODO退款
|
||||||
|
});
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user