|
@@ -0,0 +1,72 @@
|
|
|
|
|
+package com.ruoyi.system.omgpay.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
|
|
+import com.ruoyi.system.omgpay.domain.OmgPaymentAttempt;
|
|
|
|
|
+import com.ruoyi.system.omgpay.domain.OmgPaymentOrderSnapshot;
|
|
|
|
|
+import com.ruoyi.system.omgpay.mapper.OmgPaymentAttemptMapper;
|
|
|
|
|
+import com.ruoyi.system.omgpay.service.IOmgPaymentAttemptService;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+public class OmgPaymentAttemptServiceImpl implements IOmgPaymentAttemptService {
|
|
|
|
|
+
|
|
|
|
|
+ private static final int ATTEMPT_STATUS_CREATED = 0;
|
|
|
|
|
+
|
|
|
|
|
+ private final OmgPaymentAttemptMapper mapper;
|
|
|
|
|
+
|
|
|
|
|
+ public OmgPaymentAttemptServiceImpl(OmgPaymentAttemptMapper mapper) {
|
|
|
|
|
+ this.mapper = mapper;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public OmgPaymentOrderSnapshot selectOrderForUpdate(String ddId) {
|
|
|
|
|
+ return StrUtil.isBlank(ddId) ? null : mapper.selectOrderForUpdate(ddId.trim());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public OmgPaymentAttempt selectActiveCreatedByDdId(String ddId) {
|
|
|
|
|
+ return StrUtil.isBlank(ddId) ? null : mapper.selectActiveCreatedByDdId(ddId.trim());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public OmgPaymentAttempt createCreated(String ddId, String merchantTradeNo, Long storeId,
|
|
|
|
|
+ String merchantId, Integer amount) {
|
|
|
|
|
+ validateCreatedFacts(ddId, merchantTradeNo, storeId, merchantId, amount);
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ OmgPaymentAttempt row = new OmgPaymentAttempt();
|
|
|
|
|
+ row.setDdId(ddId.trim());
|
|
|
|
|
+ row.setMerchantTradeNo(merchantTradeNo.trim());
|
|
|
|
|
+ row.setStoreId(storeId);
|
|
|
|
|
+ row.setMerchantId(merchantId.trim());
|
|
|
|
|
+ row.setAmount(amount);
|
|
|
|
|
+ row.setAttemptStatus(ATTEMPT_STATUS_CREATED);
|
|
|
|
|
+ row.setCreateTime(now);
|
|
|
|
|
+ row.setUpdateTime(now);
|
|
|
|
|
+ mapper.insertCreated(row);
|
|
|
|
|
+ return row;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static void validateCreatedFacts(String ddId, String merchantTradeNo, Long storeId,
|
|
|
|
|
+ String merchantId, Integer amount) {
|
|
|
|
|
+ if (StrUtil.isBlank(ddId)) {
|
|
|
|
|
+ throw new ServiceException("OMG payment ddId is required");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isBlank(merchantTradeNo)) {
|
|
|
|
|
+ throw new ServiceException("OMG payment merchantTradeNo is required");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (storeId == null) {
|
|
|
|
|
+ throw new ServiceException("OMG payment storeId is required");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isBlank(merchantId)) {
|
|
|
|
|
+ throw new ServiceException("OMG payment merchantId is required");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (amount == null || amount <= 0) {
|
|
|
|
|
+ throw new ServiceException("OMG payment amount must be positive");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|