Merge pull request 'fix:退款订单按租户查询' (#3) from feature_dzc into test
Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
@@ -80,6 +80,11 @@
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
||||
+4
-2
@@ -210,8 +210,10 @@ public class AliPayController {
|
||||
throw new IllegalStateException("订单不存在: " + outTradeNo);
|
||||
}
|
||||
|
||||
if (OrderStatus.PAID.getId().equals(order.getOrderStatus())) {
|
||||
log.info("订单已支付,跳过: {}", outTradeNo);
|
||||
// 与微信回调保持一致:仅待支付订单受理,避免重复通知把已执行订单拉回排队队列
|
||||
if (!OrderStatus.UNPAID.getId().equals(order.getOrderStatus())) {
|
||||
log.warn("订单状态非待支付,忽略本次支付成功通知: orderNo={}, status={}, tradeNo:{}",
|
||||
outTradeNo, order.getOrderStatus(), tradeNo);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ public class RefundController {
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@Operation(summary = "查询全部列表")
|
||||
@Operation(summary = "按订单所属景区查询当前租户范围内的退款列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "page",description = "分页起始位置",required = true,in= ParameterIn.QUERY),
|
||||
@Parameter(name = "limit",description = "分页结束位置",required = true,in=ParameterIn.QUERY)
|
||||
|
||||
+20
-2
@@ -157,11 +157,20 @@ public class WxPayController {
|
||||
return;
|
||||
}
|
||||
|
||||
// 微信会重复推送同一笔通知,仅待支付订单受理,避免把已执行的订单重新拉回排队队列造成重复飞行
|
||||
if (!OrderStatus.UNPAID.getId().equals(order.getOrderStatus())) {
|
||||
log.warn("订单状态非待支付,忽略本次支付成功通知: orderNo={}, status={}, transactionId={}",
|
||||
outTradeNo, order.getOrderStatus(), transaction.getTransactionId());
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 更新订单状态
|
||||
order.setOrderStatus(OrderStatus.PAID.getId());
|
||||
order.setPayType(PayTypeEnum.WECHAT_PAY.getCode());
|
||||
order.setPayTime(new Date());
|
||||
orderService.updateOrder(order);
|
||||
if (!orderService.updateOrder(order)) {
|
||||
log.error("支付成功但订单状态未更新,订单可能仍停留在待支付: orderNo={}", outTradeNo);
|
||||
}
|
||||
|
||||
// === 携程分销订单创建 ===
|
||||
if (Integer.valueOf(1).equals(qrCode.getEnableCtripOrder())) {
|
||||
@@ -220,11 +229,20 @@ public class WxPayController {
|
||||
return;
|
||||
}
|
||||
|
||||
// 微信会重复推送同一笔通知,仅待支付订单受理,避免把已执行的订单重新拉回排队队列造成重复飞行
|
||||
if (!OrderStatus.UNPAID.getId().equals(order.getOrderStatus())) {
|
||||
log.warn("订单状态非待支付,忽略本次支付成功通知: orderNo={}, status={}, transactionId={}",
|
||||
outTradeNo, order.getOrderStatus(), transaction.getTransactionId());
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 更新订单状态
|
||||
order.setOrderStatus(OrderStatus.PAID.getId());
|
||||
order.setPayType(PayTypeEnum.WECHAT_PAY.getCode());
|
||||
order.setPayTime(new Date());
|
||||
orderService.updateOrder(order);
|
||||
if (!orderService.updateOrder(order)) {
|
||||
log.error("支付成功但订单状态未更新,订单可能仍停留在待支付: orderNo={}", outTradeNo);
|
||||
}
|
||||
|
||||
// === 携程分销订单创建 ===
|
||||
if (Integer.valueOf(1).equals(qrCode.getEnableCtripOrder())) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Order information
|
||||
@@ -17,13 +16,7 @@ import java.util.Map;
|
||||
*/
|
||||
@Mapper
|
||||
public interface RefundMapper extends SuperMapper<Refund> {
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
* @param page
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
List<Refund> findList(Page<Refund> page, @Param("p") Map<String, Object> params);
|
||||
List<Refund> findList(Page<Refund> page, @Param("tenantIds") List<String> tenantIds);
|
||||
|
||||
/**
|
||||
* 根据订单编码查询退款详情
|
||||
|
||||
+23
-1
@@ -2,6 +2,7 @@ package com.central.order.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.feign.UserService;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.SysUser;
|
||||
@@ -17,6 +18,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
@@ -48,8 +51,12 @@ public class RefundServiceImpl extends SuperServiceImpl<RefundMapper, Refund> im
|
||||
*/
|
||||
@Override
|
||||
public PageResult<Refund> findList(Map<String, Object> params){
|
||||
List<String> tenantIds = resolveRefundTenantIds(MapUtils.getString(params, "tenantId"));
|
||||
if (CollectionUtils.isEmpty(tenantIds)) {
|
||||
return PageResult.<Refund>builder().data(List.of()).resp_code(0).count(0L).build();
|
||||
}
|
||||
Page<Refund> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||
List<Refund> list = baseMapper.findList(page, params);
|
||||
List<Refund> list = baseMapper.findList(page, tenantIds);
|
||||
if(list!=null && list.size()>0){
|
||||
for (Refund refund: list){
|
||||
//用户手机号
|
||||
@@ -74,6 +81,21 @@ public class RefundServiceImpl extends SuperServiceImpl<RefundMapper, Refund> im
|
||||
return PageResult.<Refund>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
||||
}
|
||||
|
||||
private List<String> resolveRefundTenantIds(String requestedTenant) {
|
||||
String currentTenant = LoginUserContextHolder.getCurrentTenantId();
|
||||
if (!StringUtils.hasText(currentTenant)) {
|
||||
return List.of();
|
||||
}
|
||||
List<String> allowed = userService.getSonTenantIds(currentTenant);
|
||||
if (!StringUtils.hasText(requestedTenant) || currentTenant.equals(requestedTenant)) {
|
||||
return allowed;
|
||||
}
|
||||
if (CollectionUtils.isEmpty(allowed) || !allowed.contains(requestedTenant)) {
|
||||
return List.of();
|
||||
}
|
||||
return userService.getSonTenantIds(requestedTenant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createRefund(Refund refund) {
|
||||
|
||||
|
||||
@@ -4,7 +4,14 @@
|
||||
<mapper namespace="com.central.order.mapper.RefundMapper">
|
||||
|
||||
<select id="findList" resultType="com.central.order.model.Refund">
|
||||
select * from orders_refund t ORDER BY id DESC
|
||||
SELECT r.* FROM orders_refund r
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM orders o
|
||||
JOIN tourisms t ON t.id = o.tourism_id AND t.is_del = 0
|
||||
WHERE o.order_no = r.order_no AND t.tenant_id IN
|
||||
<foreach collection="tenantIds" item="tenantId" open="(" separator="," close=")">#{tenantId}</foreach>
|
||||
)
|
||||
ORDER BY r.id DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据订单编码查询退款详情 -->
|
||||
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
package com.central.order.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.feign.UserService;
|
||||
import com.central.common.model.LoginAppUser;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.order.mapper.RefundMapper;
|
||||
import com.central.order.model.Refund;
|
||||
import com.central.order.service.IOrderService;
|
||||
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
|
||||
import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
|
||||
import org.apache.ibatis.io.Resources;
|
||||
import org.apache.ibatis.mapping.Environment;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class RefundListTenantTest {
|
||||
private final RefundServiceImpl service = new RefundServiceImpl();
|
||||
private final UserService users = mock(UserService.class);
|
||||
private SqlSession session;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
var dataSource = new UnpooledDataSource("org.h2.Driver", "jdbc:h2:mem:" + UUID.randomUUID() + ";MODE=MySQL", "sa", "");
|
||||
var config = new MybatisConfiguration(new Environment("test", new JdbcTransactionFactory(), dataSource));
|
||||
var pagination = new MybatisPlusInterceptor();
|
||||
pagination.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
config.addInterceptor(pagination);
|
||||
String resource = "mapper/RefundMapper.xml";
|
||||
try (var xml = Resources.getResourceAsStream(resource)) {
|
||||
new XMLMapperBuilder(xml, config, resource, config.getSqlFragments()).parse();
|
||||
}
|
||||
session = new MybatisSqlSessionFactoryBuilder().build(config).openSession();
|
||||
try (var sql = session.getConnection().createStatement()) {
|
||||
sql.execute("CREATE TABLE tourisms (id BIGINT PRIMARY KEY, tenant_id VARCHAR(32), is_del INT)");
|
||||
sql.execute("CREATE TABLE orders (order_no VARCHAR(32) PRIMARY KEY, tourism_id BIGINT)");
|
||||
sql.execute("CREATE TABLE orders_refund (id BIGINT PRIMARY KEY, order_no VARCHAR(32), tenant_id VARCHAR(32))");
|
||||
sql.execute("INSERT INTO tourisms VALUES (1,'parent',0),(2,'child',0),(3,'other',0),(4,'parent',1)");
|
||||
sql.execute("INSERT INTO orders VALUES ('P',1),('C',2),('O',3),('D',4)");
|
||||
sql.execute("INSERT INTO orders_refund VALUES (1,'P','parent'),(2,'C','platform'),(3,'O','parent'),(4,'D','parent'),(5,'missing','parent')");
|
||||
}
|
||||
ReflectionTestUtils.setField(service, "baseMapper", session.getMapper(RefundMapper.class));
|
||||
ReflectionTestUtils.setField(service, "userService", users);
|
||||
ReflectionTestUtils.setField(service, "orderService", mock(IOrderService.class));
|
||||
when(users.getSonTenantIds("parent")).thenReturn(List.of("parent", "child"));
|
||||
when(users.getSonTenantIds("child")).thenReturn(List.of("child"));
|
||||
when(users.getSonTenantIds("other")).thenReturn(List.of("other"));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
LoginUserContextHolder.clear();
|
||||
if (session != null) session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void pagesByOriginalOrderScenicAreaIncludingChildren() {
|
||||
login("parent");
|
||||
assertPage(service.findList(Map.of("page", 1, "limit", 1)), 2, 2L);
|
||||
assertPage(service.findList(Map.of("page", 2, "limit", 1)), 2, 1L);
|
||||
login("other");
|
||||
assertPage(service.findList(Map.of("page", 1, "limit", 10)), 1, 3L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void tenantSelectionCanNarrowButNotExpandTheScope() {
|
||||
login("parent");
|
||||
assertPage(service.findList(Map.of("page", 1, "limit", 10, "tenantId", "child")), 1, 2L);
|
||||
assertPage(service.findList(Map.of("page", 1, "limit", 10, "tenantId", "other")), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noTenantOrNoVisibleScenicAreaReturnsEmptyPage() {
|
||||
assertPage(service.findList(Map.of("page", 1, "limit", 10, "tenantId", "parent")), 0);
|
||||
login("unresolved");
|
||||
assertPage(service.findList(Map.of("page", 1, "limit", 10)), 0);
|
||||
login("empty");
|
||||
when(users.getSonTenantIds("empty")).thenReturn(List.of("empty"));
|
||||
assertPage(service.findList(Map.of("page", 1, "limit", 10)), 0);
|
||||
}
|
||||
|
||||
private void login(String tenantId) {
|
||||
var user = new LoginAppUser();
|
||||
user.setCompany(tenantId);
|
||||
LoginUserContextHolder.setUser(user);
|
||||
}
|
||||
|
||||
private void assertPage(PageResult<Refund> page, long total, Long... ids) {
|
||||
assertEquals(total, page.getCount());
|
||||
assertEquals(List.of(ids), page.getData().stream().map(Refund::getId).toList());
|
||||
}
|
||||
}
|
||||
+4
@@ -12,6 +12,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 支付宝小程序二维码服务
|
||||
* <p>
|
||||
@@ -71,6 +74,7 @@ public class AlipayQrcodeService {
|
||||
biz.put("url_param", urlParam);
|
||||
biz.put("query_param", (queryKey == null || queryKey.isEmpty() ? "uuid" : queryKey) + "=" + codeId);
|
||||
biz.put("describe", trimDescribe(describe));
|
||||
log.info("支付宝小程序码 bizContent: {}", biz.toJSONString());
|
||||
request.setBizContent(biz.toJSONString());
|
||||
|
||||
if (Boolean.TRUE.equals(cfg.getIsServiceMode()) && cfg.getAuthToken() != null) {
|
||||
|
||||
Reference in New Issue
Block a user