Merge remote-tracking branch 'origin/main'

This commit is contained in:
attiya 2025-11-13 15:37:59 +08:00
commit 82fd154968
7 changed files with 62 additions and 72 deletions

View File

@ -1,55 +0,0 @@
package com.cdzy.payment.component;
import cn.dev33.satoken.stp.StpUtil;
import com.cdzy.common.model.response.CommonEbikeRole;
import com.cdzy.common.model.response.CommonStaffInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.mybatisflex.core.tenant.TenantFactory;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import java.util.List;
import java.util.TimeZone;
/**
* @author: yanglei
* @since: 2025-10-15 09:41
*/
public class EbikeTenantFactory implements TenantFactory {
public Object[] getTenantIds() {
if (StpUtil.isLogin()) {
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
Object attribute = attributes.getAttribute("tenantId", RequestAttributes.SCOPE_REQUEST);
if (attribute != null) {
String id = (String) StpUtil.getLoginId();
Object object = StpUtil.getSessionByLoginId(id).get(id);
ObjectMapper objectMapper = new ObjectMapper()
.registerModule(new JavaTimeModule())
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
CommonStaffInfo staffInfo = objectMapper.convertValue(object, CommonStaffInfo.class);
List<CommonEbikeRole> roles = staffInfo.getRoles();
boolean isSysAdmin = false;
for (CommonEbikeRole role : roles) {
if (role.getSysAdmin()) {
isSysAdmin = true;
break;
}
}
long tenantId = Long.parseLong(attribute.toString());
//系统管理员
if (isSysAdmin) {
return null;
} else {
return new Object[]{tenantId};
}
}
}
return null;
}
}

View File

@ -1,17 +1,13 @@
package com.cdzy.payment.config;
import com.cdzy.common.enums.EbikeContents;
import com.cdzy.payment.component.EbikeTenantFactory;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.dialect.DbType;
import com.mybatisflex.core.keygen.KeyGenerators;
import com.mybatisflex.core.tenant.TenantFactory;
import com.mybatisflex.core.tenant.TenantManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
@ -54,15 +50,4 @@ public class MyBatisFlexConfiguration {
//设置数据已被删除时的值
globalConfig.setDeletedValueOfLogicDelete(Boolean.TRUE);
}
/**
* 详细的租户工厂配置
*/
@Bean
public static TenantFactory tenantFactory() {
logger.info("开始初始化租户工厂...");
EbikeTenantFactory factory = new EbikeTenantFactory();
TenantManager.setTenantFactory(factory);
return new EbikeTenantFactory();
}
}

View File

@ -0,0 +1,37 @@
package com.cdzy.user.controller;
import com.cdzy.common.model.response.JsonResult;
import com.cdzy.user.model.entity.EbikePayment;
import com.cdzy.user.service.EbikePaymentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 用户支付 控制层
*
* @author yanglei
* @since 2025-11-13 13:49
*/
@RestController
@RequestMapping("/ebikePayment")
public class EbikePaymentController {
@Resource
private EbikePaymentService ebikePaymentService;
/**
* 根据订单号获取支付订单
*
* @param orderId 用户订单号
* @return 支付订单信息
*/
@GetMapping("/queryPaymentInfo")
public JsonResult<?> queryPaymentInfo(@RequestParam(name = "orderId") Long orderId) {
EbikePayment ebikePayment = ebikePaymentService.queryPaymentInfo(orderId);
return JsonResult.success(ebikePayment);
}
}

View File

@ -11,4 +11,12 @@ import com.mybatisflex.core.service.IService;
*/
public interface EbikePaymentService extends IService<EbikePayment> {
/**
* 查询用户支付订单
*
* @param orderId 订单id
* @return 用户支付订单
*/
EbikePayment queryPaymentInfo(Long orderId);
}

View File

@ -95,7 +95,7 @@ public class EbikeOrderImpl extends ServiceImpl<EbikeOrderMapper, EbikeOrder> im
.updateTime(LocalDateTime.now())
.build();
updateById(orders);
return orders;
return getById(order.getOrderId());
} catch (Exception e) {
log.error("开锁失败, userId={}, bikeCode={}", userId, bikeCode, e);
throw new RuntimeException("开锁失败", e);

View File

@ -3,10 +3,13 @@ package com.cdzy.user.service.impl;
import com.cdzy.user.mapper.EbikePaymentMapper;
import com.cdzy.user.model.entity.EbikePayment;
import com.cdzy.user.service.EbikePaymentService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import static com.cdzy.user.model.entity.table.EbikePaymentTableDef.EBIKE_PAYMENT;
/**
* 用户支付服务层
*
@ -16,4 +19,16 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service
public class EbikePaymentServiceImpl extends ServiceImpl<EbikePaymentMapper, EbikePayment> implements EbikePaymentService {
@Override
public EbikePayment queryPaymentInfo(Long orderId) {
QueryWrapper queryWrapper = QueryWrapper.create()
.where(EBIKE_PAYMENT.ORDER_ID.eq(orderId));
EbikePayment ebikePayment = this.mapper.selectOneByQuery(queryWrapper);
if (ebikePayment == null) {
log.error("{}支付订单不存在!", orderId);
return null;
}
return ebikePayment;
}
}

View File

@ -298,7 +298,7 @@ CREATE TABLE "public"."ebike_payment" (
"user_id" int8 NOT NULL,
"order_id" int8 NOT NULL,
"operator_id" int8 NOT NULL,
"trade_id" varchar(64) COLLATE "pg_catalog"."default" NOT NULL,
"trade_id" varchar(64) COLLATE "pg_catalog"."default",
"transaction_id" varchar(64) COLLATE "pg_catalog"."default",
"payment_time" timestamp(6),
"payment_method" int2 NOT NULL,