定时任务处理未分帐订单

This commit is contained in:
Guoqs
2025-04-16 15:50:26 +08:00
parent 42f828a812
commit b7f04d2159
6 changed files with 100 additions and 14 deletions

View File

@@ -8,7 +8,9 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.jsowell.adapay.common.AdaPayment;
import com.jsowell.adapay.common.DivMember;
import com.jsowell.adapay.common.PaymentConfirmInfo;
import com.jsowell.adapay.dto.PaymentConfirmParam;
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
import com.jsowell.adapay.response.PaymentConfirmResponse;
import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse;
@@ -16,6 +18,7 @@ import com.jsowell.adapay.service.AdapayService;
import com.jsowell.adapay.vo.OrderSplitResult;
import com.jsowell.adapay.vo.PaymentInfo;
import com.jsowell.common.annotation.CostTime;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.constant.RabbitConstants;
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
import com.jsowell.common.core.redis.RedisCache;
@@ -23,7 +26,9 @@ import com.jsowell.common.enums.adapay.AdapayStatusEnum;
import com.jsowell.common.enums.adapay.MerchantDelayModeEnum;
import com.jsowell.common.enums.ykc.*;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.AdapayUtil;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.dto.AfterSettleOrderDTO;
@@ -115,6 +120,9 @@ public class TempService {
@Autowired
private RedisCache redisCache;
@Autowired
private OrderUnsplitRecordService orderUnsplitRecordService;
/**
* 计算订单耗电量
* 内蒙古站点
@@ -1056,8 +1064,5 @@ public class TempService {
orderBasicInfoService.splittingMethod(afterSettleOrderDTO);
}
/**
*
*/
}

View File

@@ -1,11 +1,12 @@
package com.jsowell.pile.mapper;
import com.jsowell.pile.domain.OrderUnsplitRecord;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import org.apache.ibatis.annotations.Param;
@Repository
public interface OrderUnsplitRecordMapper {
int deleteByPrimaryKey(Integer id);
@@ -24,4 +25,6 @@ public interface OrderUnsplitRecordMapper {
int insertOrUpdate(OrderUnsplitRecord record);
int insertOrUpdateSelective(OrderUnsplitRecord record);
}
List<OrderUnsplitRecord> queryUnsplitOrders(@Param("startTime") String startTime, @Param("endTime") String endTime);
}

View File

@@ -6,4 +6,8 @@ import java.util.List;
public interface OrderUnsplitRecordService {
void batchInsert(List<OrderUnsplitRecord> orderUnsplitRecordList);
List<OrderUnsplitRecord> queryUnsplitOrders(String startTime, String endTime);
void updateOrderUnsplitRecord(OrderUnsplitRecord orderUnsplitRecord);
}

View File

@@ -18,4 +18,14 @@ public class OrderUnsplitRecordServiceImpl implements OrderUnsplitRecordService
public void batchInsert(List<OrderUnsplitRecord> orderUnsplitRecordList) {
orderUnsplitRecordMapper.batchInsert(orderUnsplitRecordList);
}
@Override
public List<OrderUnsplitRecord> queryUnsplitOrders(String startTime, String endTime) {
return orderUnsplitRecordMapper.queryUnsplitOrders(startTime, endTime);
}
@Override
public void updateOrderUnsplitRecord(OrderUnsplitRecord orderUnsplitRecord) {
orderUnsplitRecordMapper.insertOrUpdateSelective(orderUnsplitRecord);
}
}

View File

@@ -16,12 +16,12 @@
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, payment_id, `status`, order_code, pay_amount, refund_amount, settle_amount, order_time,
id, payment_id, `status`, order_code, pay_amount, refund_amount, settle_amount, order_time,
create_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!--@mbg.generated-->
select
select
<include refid="Base_Column_List" />
from order_unsplit_record
where id = #{id,jdbcType=INTEGER}
@@ -237,12 +237,12 @@
<insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into order_unsplit_record
(payment_id, `status`, order_code, pay_amount, refund_amount, settle_amount, order_time,
(payment_id, `status`, order_code, pay_amount, refund_amount, settle_amount, order_time,
create_time)
values
<foreach collection="list" item="item" separator=",">
(#{item.paymentId,jdbcType=VARCHAR}, #{item.status,jdbcType=VARCHAR}, #{item.orderCode,jdbcType=VARCHAR},
#{item.payAmount,jdbcType=DECIMAL}, #{item.refundAmount,jdbcType=DECIMAL}, #{item.settleAmount,jdbcType=DECIMAL},
(#{item.paymentId,jdbcType=VARCHAR}, #{item.status,jdbcType=VARCHAR}, #{item.orderCode,jdbcType=VARCHAR},
#{item.payAmount,jdbcType=DECIMAL}, #{item.refundAmount,jdbcType=DECIMAL}, #{item.settleAmount,jdbcType=DECIMAL},
#{item.orderTime,jdbcType=TIMESTAMP}, #{item.createTime,jdbcType=TIMESTAMP})
</foreach>
</insert>
@@ -276,7 +276,7 @@
#{orderTime,jdbcType=TIMESTAMP},
#{createTime,jdbcType=TIMESTAMP},
</trim>
on duplicate key update
on duplicate key update
<trim suffixOverrides=",">
<if test="id != null">
id = #{id,jdbcType=INTEGER},
@@ -353,7 +353,7 @@
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
on duplicate key update
on duplicate key update
<trim suffixOverrides=",">
<if test="id != null">
id = #{id,jdbcType=INTEGER},
@@ -384,4 +384,13 @@
</if>
</trim>
</insert>
</mapper>
<select id="queryUnsplitOrders" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from order_unsplit_record
where status = 'unsplit'
and order_time between #{startTime,jdbcType=VARCHAR} and #{endTime,jdbcType=VARCHAR}
order by order_time
</select>
</mapper>

View File

@@ -1,15 +1,22 @@
package com.jsowell.quartz.task;
import com.google.common.collect.Lists;
import com.jsowell.adapay.common.DivMember;
import com.jsowell.adapay.dto.PaymentConfirmParam;
import com.jsowell.adapay.dto.WithdrawDTO;
import com.jsowell.adapay.response.PaymentConfirmResponse;
import com.jsowell.adapay.service.AdapayService;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.util.AdapayUtil;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.OrderUnsplitRecord;
import com.jsowell.pile.domain.PileMerchantInfo;
import com.jsowell.pile.domain.PileStationInfo;
import com.jsowell.pile.domain.ykcCommond.PublishPileBillingTemplateCommand;
@@ -68,6 +75,9 @@ public class JsowellTask {
@Autowired
private ThirdPartyStationRelationService thirdPartyStationRelationService;
@Autowired
private OrderUnsplitRecordService orderUnsplitRecordService;
/**
* 设置挡板, PRE环境不执行
*/
@@ -332,4 +342,49 @@ public class JsowellTask {
});
}
/**
* 处理未分帐订单
*/
public void processUnSettledOrder() {
String startTime = "2023-01-01 00:00:00";
String endTime = "2023-12-31 23:59:59";
String adapayMemberId = "0";
String wechatAppId1 = "wxbb3e0d474569481d"; // 万车充
// 查询未分帐订单
PageUtils.startPage(1, 500);
List<OrderUnsplitRecord> list = orderUnsplitRecordService.queryUnsplitOrders(startTime, endTime);
for (OrderUnsplitRecord orderUnsplitRecord : list) {
String paymentId = orderUnsplitRecord.getPaymentId();
String orderCode = orderUnsplitRecord.getOrderCode();
BigDecimal confirmAmt = orderUnsplitRecord.getSettleAmount();
DivMember divMember = new DivMember();
divMember.setMemberId(adapayMemberId);
divMember.setAmount(AdapayUtil.formatAmount(confirmAmt));
divMember.setFeeFlag(Constants.Y);
PaymentConfirmParam param = PaymentConfirmParam.builder()
.paymentId(paymentId)
.divMemberList(Lists.newArrayList(divMember))
.confirmAmt(confirmAmt)
.orderCode(orderCode)
.wechatAppId(wechatAppId1)
.build();
// 延时分账使用确认交易API
PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequest(param);
// 如果确认交易成功,则更新订单状态为已分账
if (paymentConfirmResponse.isSuccess()) {
log.info("processUnsplitOrders, 分账成功, paymentId:{}", paymentId);
orderUnsplitRecord.setStatus(paymentConfirmResponse.getStatus());
orderUnsplitRecordService.updateOrderUnsplitRecord(orderUnsplitRecord);
} else {
// 如果失败,打印日志
log.info("processUnsplitOrders, 分账失败, paymentId:{}, 错误信息:{}", paymentId, paymentConfirmResponse.getError_msg());
return;
}
}
}
}