This commit is contained in:
2023-08-26 18:01:25 +08:00
parent 85ae33240f
commit ef8cd011e4
10 changed files with 1089 additions and 928 deletions

View File

@@ -20,6 +20,7 @@ import com.jsowell.pile.dto.SettleOrderReportDTO;
import com.jsowell.pile.service.*;
import com.jsowell.pile.vo.uniapp.MemberBalanceVO;
import com.jsowell.service.OrderService;
import com.jsowell.service.TempService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -37,6 +38,9 @@ import java.util.Map;
@RequestMapping("/temp")
public class TempController extends BaseController {
@Autowired
private TempService tempService;
@Autowired
private IOrderBasicInfoService orderBasicInfoService;
@@ -73,7 +77,7 @@ public class TempController extends BaseController {
logger.info("临时刷数据接口 param:{}", dto);
RestApiResponse<?> response = null;
try {
String s = orderBasicInfoService.tempUpdateVirtualAmount(dto);
String s = tempService.tempUpdateVirtualAmount(dto);
response = new RestApiResponse<>(s);
} catch (BusinessException e) {
logger.warn("临时刷数据接口 warn", e);
@@ -355,7 +359,7 @@ public class TempController extends BaseController {
logger.info("查询未分账订单param:{}", JSON.toJSONString(dto));
RestApiResponse<?> response;
try {
Map<String, Object> map = settleOrderReportService.queryUndividedOrder(dto);
Map<String, Object> map = tempService.queryUndividedOrder(dto);
response = new RestApiResponse<>(map);
} catch (BusinessException e) {
logger.error("查询未分账订单接口 error,", e);
@@ -378,7 +382,7 @@ public class TempController extends BaseController {
public RestApiResponse<?> splitTheBillForOrderTemp(@RequestBody QueryOrderDTO dto) {
RestApiResponse<?> response;
try {
orderBasicInfoService.splitTheBillForOrderTemp(dto.getMerchantId(), dto.getOrderCodeList());
tempService.splitTheBillForOrderTemp(dto.getMerchantId(), dto.getOrderCodeList());
response = new RestApiResponse<>();
} catch (BusinessException e) {
logger.error("余额支付订单分账工具 error,", e);

View File

@@ -0,0 +1,431 @@
package com.jsowell.service;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse;
import com.jsowell.adapay.service.AdapayService;
import com.jsowell.adapay.vo.OrderSettleResult;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.ykc.*;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.dto.ApplyRefundDTO;
import com.jsowell.pile.dto.QueryOrderDTO;
import com.jsowell.pile.dto.SettleOrderReportDTO;
import com.jsowell.pile.mapper.OrderBasicInfoMapper;
import com.jsowell.pile.service.*;
import com.jsowell.pile.transaction.service.TransactionService;
import com.jsowell.pile.vo.web.ClearingBillVO;
import com.jsowell.pile.vo.web.OrderListVO;
import com.jsowell.wxpay.service.WxAppletRemoteService;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
public class TempService {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private OrderBasicInfoMapper orderBasicInfoMapper;
@Autowired
private IOrderBasicInfoService orderBasicInfoService;
@Autowired
private ClearingWithdrawInfoService clearingWithdrawInfoService;
@Autowired
private TransactionService transactionService;
@Autowired
private RedisCache redisCache;
@Autowired
private WxAppletRemoteService wxAppletRemoteService;
@Autowired
private IOrderPayRecordService orderPayRecordService;
@Autowired
private IMemberBasicInfoService memberBasicInfoService;
@Autowired
private WxpayCallbackRecordService wxpayCallbackRecordService;
@Autowired
private AdapayCallbackRecordService adapayCallbackRecordService;
@Autowired
private WechatPayService wechatPayService;
@Autowired
private IOrderAbnormalRecordService orderAbnormalRecordService;
@Autowired
private TransactionService pileTransactionService;
@Autowired
private IPileBasicInfoService pileBasicInfoService;
@Autowired
private IPileConnectorInfoService pileConnectorInfoService;
@Autowired
private WxpayRefundCallbackService wxpayRefundCallbackService;
@Autowired
private IPileBillingTemplateService pileBillingTemplateService;
@Autowired
private IPileAuthCardService pileAuthCardService;
@Autowired
private OrderMonitorDataService orderMonitorDataService;
@Autowired
private IPileStationInfoService pileStationInfoService;
@Autowired
private IPileMerchantInfoService pileMerchantInfoService;
@Autowired
private IMemberPlateNumberRelationService memberPlateNumberRelationService;
@Autowired
private IMemberTransactionRecordService memberTransactionRecordService;
@Autowired
private ISettleOrderReportService settleOrderReportService;
@Autowired
private IAdapayMemberAccountService adapayMemberAccountService;
@Autowired
private PileRemoteService pileRemoteService;
@Autowired
private IPileStationWhitelistService pileStationWhitelistService;
@Autowired
private AdapayService adapayService;
@Autowired
private MemberAdapayRecordService memberAdapayRecordService;
/**
* 手动接口执行订单分账逻辑
*/
public void tempOrderSplittingOperations(String merchantId, String tradeDate) {
logger.info("手动接口执行订单分账逻辑-运营商:{}, 交易日期:{}, 进行分账处理start", merchantId, tradeDate);
// 查询运营商有没有开通结算账户
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService.selectByMerchantId(merchantId);
if (adapayMemberAccount == null) {
logger.error("手动接口执行订单分账逻辑-订单分账逻辑error, 运营商id:{}, 未配置结算账户", merchantId);
return;
}
String appId = pileMerchantInfoService.queryAppIdByMerchantId(merchantId);
// 根据交易日期查询运营商下面所有站点的交易日报
List<SettleOrderReport> stationReportList = settleOrderReportService.selectByMerchantIdAndDate(merchantId, tradeDate);
for (SettleOrderReport orderReport : stationReportList) {
String orderCodes = orderReport.getOrderCodes();
if (StringUtils.isBlank(orderCodes)) {
logger.info("手动接口执行订单分账逻辑-站点:{}, 日期:{}, 没有查到订单数据", orderReport.getStationId(), tradeDate);
continue;
}
List<String> orderCodeList = Lists.newArrayList(StringUtils.split(orderCodes, ","));
List<OrderBasicInfo> orderBasicInfos = orderBasicInfoService.queryOrderList(orderCodeList);
if (CollectionUtils.isEmpty(orderBasicInfos)) {
logger.info("手动接口执行订单分账逻辑-站点:{}, 日期:{}, 没有查到订单数据", orderReport.getStationId(), tradeDate);
continue;
}
// 执行分账
for (OrderBasicInfo orderBasicInfo : orderBasicInfos) {
try {
OrderSettleResult orderSettleResult = null;
logger.info("手动接口执行订单分账逻辑-orderCode:{}, payMode:{}", orderBasicInfo.getOrderCode(), orderBasicInfo.getPayMode());
if (OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue().equals(orderBasicInfo.getPayMode())) {
logger.info("手动接口执行订单分账逻辑-order:{}, result:{}", JSON.toJSONString(orderBasicInfo), JSON.toJSONString(orderSettleResult));
// 余额支付的订单 只用余额支付转账
// orderSettleResult = doBalancePayment(orderBasicInfo, adapayMemberAccount);
} else {
// 在线支付,进行支付确认分账
// orderSettleResult = orderBasicInfo.doPaymentConfirmWithDelay(orderBasicInfo, adapayMemberAccount, appId);
}
// if (orderSettleResult != null && AdapayStatusEnum.SUCCEEDED.getValue().equals(orderSettleResult.getStatus())) {
// JSONObject jsonObject = JSON.parseObject(orderSettleResult.getDescription());
// String orderCode = (String) jsonObject.get("orderCode");
// }
} catch (Exception e) {
logger.error("手动接口执行订单分账逻辑-订单交易确认失败:{}", orderBasicInfo.getOrderCode(), e);
}
}
}
logger.info("手动接口执行订单分账逻辑-运营商:{}, 交易日期:{}, 进行分账处理end", merchantId, tradeDate);
}
public String tempUpdateVirtualAmount(QueryOrderDTO dto) {
dto.setOrderStatus(OrderStatusEnum.ORDER_COMPLETE.getValue());
List<OrderListVO> orderListVOS = orderBasicInfoMapper.selectOrderBasicInfoList(dto);
if (CollectionUtils.isEmpty(orderListVOS)) {
return "没有订单需要修改";
}
int i = 0;
for (OrderListVO orderListVO : orderListVOS) {
try {
tempUpdateVirtualAmount(orderListVO);
i += 1;
} catch (Exception e) {
logger.error("修改虚拟金额字段失败", e);
}
}
return "共查询到" + orderListVOS.size() + "条订单,修改成功" + i + "条订单数据";
}
private void tempUpdateVirtualAmount(OrderListVO orderListVO) {
if (orderListVO.getVirtualAmount() != null) {
return;
}
// 订单总消费金额
BigDecimal orderAmount = new BigDecimal(orderListVO.getOrderAmount());
// 支付金额
BigDecimal payAmount = new BigDecimal(orderListVO.getPayAmount());
if (orderAmount.compareTo(payAmount) > 0) {
orderAmount = payAmount;
}
// 使用虚拟金额消费 金额
BigDecimal virtualAmount = BigDecimal.ZERO;
// 结算金额
BigDecimal settleAmount = BigDecimal.ZERO;
if (orderAmount.compareTo(BigDecimal.ZERO) > 0) {
if (StringUtils.equals(orderListVO.getPayMode(), OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) {
/*
余额支付 查询支付记录如全部用本金支付则虚拟金额为0结算金额为订单消费金额
如果使用了赠送金额,虚拟金额为赠送金额支付部分,结算金额=订单消费金额-虚拟金额消费部分
*/
// 查询支付记录
List<OrderPayRecord> orderPayRecordList = orderPayRecordService.getOrderPayRecordList(orderListVO.getOrderCode());
for (OrderPayRecord orderPayRecord : orderPayRecordList) {
if (StringUtils.equals(orderPayRecord.getPayMode(), OrderPayRecordEnum.GIFT_BALANCE_PAYMENT.getValue())) {
BigDecimal refundAmount = orderPayRecord.getRefundAmount();
if (refundAmount == null) {
// 退款金额为null, 需要退款的金额 = 支付金额 - 订单金额
refundAmount = orderPayRecord.getPayAmount().subtract(orderAmount);
}
// 赠送金额消费部分 = 支付金额 - 需要退款金额
virtualAmount = orderPayRecord.getPayAmount().subtract(refundAmount);
// 结算金额 = 订单金额 - 赠送金额消费部分
settleAmount = orderAmount.subtract(virtualAmount);
} else {
// 没有使用赠送金额支付那么虚拟金额就是0结算金额就等于订单金额
settleAmount = orderAmount;
}
}
} else {
/*
微信支付 虚拟金额为0 结算金额等于订单消费金额
*/
settleAmount = orderAmount;
}
}
OrderBasicInfo build = OrderBasicInfo.builder()
.id(Long.parseLong(orderListVO.getId()))
.orderCode(orderListVO.getOrderCode())
.orderAmount(orderAmount)
.virtualAmount(virtualAmount)
.settleAmount(settleAmount)
.build();
orderBasicInfoService.updateOrderBasicInfo(build);
}
/**
* 临时订单退款
*/
public void tempOrderRefund() {
// 查询出2023-05-29 12:00:00到2023-05-30 23:59:59中使用微信支付并且有退款金额的订单
String startTime = "2023-05-29 12:00:00";
String endTime = "2023-05-30 23:59:59";
List<OrderBasicInfo> orderList = orderBasicInfoMapper.tempQueryWeChatRefundOrders(startTime, endTime);
Map<String, OrderBasicInfo> orderBasicInfoMap = orderList.stream().collect(Collectors.toMap(OrderBasicInfo::getOrderCode, Function.identity(), (k1, k2) -> k1));
Set<String> orderCodes = orderBasicInfoMap.keySet();
// 根据上面的订单号,查微信退款回调,找出没有记录的订单,重新发起一遍退款
List<WxpayRefundCallback> wxpayRefundCallbacks = wxpayRefundCallbackService.selectByOrderCodeList(Lists.newArrayList(orderCodes));
Set<String> refundOrders = wxpayRefundCallbacks.stream().map(WxpayRefundCallback::getOrderCode).collect(Collectors.toSet());
// orderCodeList refundOrders 取差集
Sets.SetView<String> difference = Sets.difference(orderCodes, refundOrders);
for (String orderCode : difference) {
OrderBasicInfo orderBasicInfo = orderBasicInfoMap.get(orderCode);
if (orderBasicInfo == null) {
continue;
}
BigDecimal refundAmount = orderBasicInfo.getRefundAmount();
// 微信退款逻辑
ApplyRefundDTO weChatRefundDTO = new ApplyRefundDTO();
weChatRefundDTO.setOrderCode(orderBasicInfo.getOrderCode());
weChatRefundDTO.setRefundType("1");
weChatRefundDTO.setRefundAmount(refundAmount);
try {
orderBasicInfoService.weChatRefund(weChatRefundDTO);
} catch (Exception e) {
logger.error("临时订单退款接口发生异常 orderCode:{}", orderBasicInfo.getOrderCode(), e);
}
}
}
public void splitTheBillForOrderTemp(String merchantId, List<String> orderCodeList) {
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(merchantId);
if (StringUtils.isBlank(wechatAppId)) {
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_WECHAT_APP_ID_IS_NULL);
}
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService.selectByMerchantId(merchantId);
if (adapayMemberAccount == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_MEMBER_IS_NULL_ERROR);
}
List<OrderBasicInfo> orderBasicInfos = orderBasicInfoService.queryOrderList(orderCodeList);
for (OrderBasicInfo orderBasicInfo : orderBasicInfos) {
try {
splitTheBillForOrderTemp(adapayMemberAccount, orderBasicInfo, wechatAppId);
} catch (BaseAdaPayException e) {
logger.error("余额支付订单分账工具, 发生异常", e);
throw new RuntimeException(e);
}
}
}
public void splitTheBillForOrderTemp(AdapayMemberAccount adapayMemberAccount, OrderBasicInfo orderBasicInfo, String wechatAppId) throws BaseAdaPayException {
logger.info("");
// 查询会员余额支付记录
List<MemberAdapayRecord> recordList = memberAdapayRecordService.selectAdapayRecordList(orderBasicInfo.getMemberId(), ScenarioEnum.BALANCE.getValue());
if (CollectionUtils.isEmpty(recordList)) {
logger.info("余额支付订单分账工具, memberId:{}, 未查询到余额充值记录", orderBasicInfo.getMemberId());
return;
}
String orderCode = orderBasicInfo.getOrderCode();
if (recordList.size() > 1) {
logger.info("余额支付订单分账工具, 会员充值记录存在多条orderCode:{}由人工手动处理", orderCode);
return;
}
// 订单分账金额
BigDecimal amount = queryBalanceOrderSettleInfo(orderCode, orderBasicInfo.getMemberId(), wechatAppId);
// 判断分账金额 和结算金额是否相等
if (amount.compareTo(BigDecimal.ZERO) == 0) {
logger.info("余额支付订单分账工具, orderCode:{}, 已分账金额为0, 订单结算金额为:{}, 重试执行订单分账", orderCode, orderBasicInfo.getSettleAmount());
// 修改会员的汇付支付记录
for (MemberAdapayRecord memberAdapayRecord : recordList) {
BigDecimal spendAmt = memberAdapayRecord.getSpendAmt();
spendAmt = spendAmt.subtract(orderBasicInfo.getOrderAmount());
memberAdapayRecord.setSpendAmt(spendAmt);
BigDecimal balanceAmt = memberAdapayRecord.getBalanceAmt();
balanceAmt = balanceAmt.add(orderBasicInfo.getOrderAmount());
memberAdapayRecord.setBalanceAmt(balanceAmt);
memberAdapayRecordService.updateByPrimaryKeySelective(memberAdapayRecord);
}
// 分账金额为0表示该订单没有执行过分账再次执行分账
if (OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue().equals(orderBasicInfo.getPayMode())) {
// 余额支付的订单
orderBasicInfoService.doBalancePaymentWithDelay(orderBasicInfo, adapayMemberAccount, wechatAppId);
}
// 再次查询分账
BigDecimal bigDecimal = queryBalanceOrderSettleInfo(orderCode, orderBasicInfo.getMemberId(), wechatAppId);
logger.info("余额支付订单分账工具, orderCode:{}, 重新分账完成, 分账金额:{}, 订单结算金额:{}", orderCode, bigDecimal, orderBasicInfo.getSettleAmount());
} else {
logger.info("余额支付订单分账工具, orderCode:{}, 已分账金额为:{}, 订单结算金额为:{}, 不再执行订单分账", orderCode, amount, orderBasicInfo.getSettleAmount());
}
}
private BigDecimal queryBalanceOrderSettleInfo(String orderCode, String memberId, String wechatAppId) {
BigDecimal resultAmt = BigDecimal.ZERO;
// 查询会员余额支付记录
List<MemberAdapayRecord> recordList = memberAdapayRecordService.selectAdapayRecordList(memberId, ScenarioEnum.BALANCE.getValue());
if (CollectionUtils.isEmpty(recordList)) {
return resultAmt;
}
// 用汇付api查询分账信息
for (MemberAdapayRecord record : recordList) {
QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO();
dto.setWechatAppId(wechatAppId);
dto.setPaymentId(record.getPaymentId());
QueryPaymentConfirmDetailResponse response = adapayService.queryPaymentConfirmList(dto);
if (response != null && CollectionUtils.isNotEmpty(response.getPaymentConfirms())) {
for (QueryPaymentConfirmDetailResponse.PaymentConfirmInfo paymentConfirm : response.getPaymentConfirms()) {
JSONObject jsonObject = JSON.parseObject(paymentConfirm.getDescription());
if (StringUtils.equals(jsonObject.getString("orderCode"), orderCode)) {
// 订单号对的上,累计分账金额
resultAmt = resultAmt.add(new BigDecimal(paymentConfirm.getConfirmAmt()));
}
}
}
}
return resultAmt;
}
public Map<String, Object> queryUndividedOrder(SettleOrderReportDTO dto) {
Map<String, Object> resultMap = Maps.newHashMap();
SettleOrderReport orderReport = settleOrderReportService.selectByStationIdAndDate(dto.getStationId(), dto.getTradeDate());
if (orderReport == null) {
throw new BusinessException("00300002", "查询站点订单日报为空");
}
String orderCodes = orderReport.getOrderCodes();
List<String> orderCodeList = Lists.newArrayList(StringUtils.split(orderCodes, ","));
List<ClearingBillVO> clearingBillVOList = clearingWithdrawInfoService.selectWithdrawInfoByOrderCodeList(orderCodeList);
if (org.springframework.util.CollectionUtils.isEmpty(clearingBillVOList)) {
throw new BusinessException("00300005", "查询清分信息为空");
}
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(orderReport.getMerchantId());
// clearing
List<ClearingBillVO> clearingList = Lists.newArrayList();
List<ClearingBillVO> unClearingList = Lists.newArrayList();
for (ClearingBillVO clearingBillVO : clearingBillVOList) {
String paymentId = clearingBillVO.getPaymentId();
QueryPaymentConfirmDTO build = QueryPaymentConfirmDTO.builder()
.wechatAppId(wechatAppId)
.paymentId(paymentId)
.build();
QueryPaymentConfirmDetailResponse response = adapayService.queryPaymentConfirmList(build);
List<QueryPaymentConfirmDetailResponse.PaymentConfirmInfo> paymentConfirms = response.getPaymentConfirms();
if (!org.springframework.util.CollectionUtils.isEmpty(paymentConfirms)) {
clearingBillVO.setConfirmInfo(paymentConfirms.get(0));
clearingList.add(clearingBillVO);
} else {
unClearingList.add(clearingBillVO);
}
}
resultMap.put("clearingList", clearingList);
resultMap.put("unClearingList", unClearingList);
return resultMap;
}
}

View File

@@ -20,6 +20,11 @@ public class SettleOrderReport {
*/
private Integer id;
/**
* 结算单编号
*/
private String settleCode;
/**
* 运营商id
*/
@@ -62,13 +67,11 @@ public class SettleOrderReport {
/**
* 收入金额
* 订单主表中orderAmount的累计金额
*/
private BigDecimal totalAmount;
/**
* 虚拟金额
* 也就是不对账的部分消费
*/
private BigDecimal virtualAmount;
@@ -79,13 +82,11 @@ public class SettleOrderReport {
/**
* 交易金额
* 结算金额拆分为 交易金额 + 交易手续费
*/
private BigDecimal tradeAmount;
/**
* 交易手续费
* 结算金额拆分为 交易金额 + 交易手续费
*/
private BigDecimal tradeFee;
@@ -94,6 +95,11 @@ public class SettleOrderReport {
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 删除标识0-正常1-删除)
*/

View File

@@ -4,11 +4,9 @@ import com.jsowell.pile.domain.SettleOrderReport;
import com.jsowell.pile.dto.MerchantOrderReportDTO;
import com.jsowell.pile.vo.web.SettleOrderReportVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface SettleOrderReportMapper {
/**
* delete by primary key
@@ -64,10 +62,10 @@ public interface SettleOrderReportMapper {
int updateBatch(List<SettleOrderReport> list);
int updateBatchSelective(List<SettleOrderReport> list);
int batchInsert(@Param("list") List<SettleOrderReport> list);
int updateBatchSelective(List<SettleOrderReport> list);
/**
* 查询结算订单报
*

View File

@@ -151,8 +151,6 @@ public interface IOrderBasicInfoService {
void orderSplittingOperations(String merchantId, String tradeDate);
void tempOrderSplittingOperations(String merchantId, String tradeDate);
List<BalanceDeductionAmountVO> calculateTheBalanceDeductionAmount(String memberId, BigDecimal amount);
/**
@@ -173,8 +171,6 @@ public interface IOrderBasicInfoService {
*/
List<OrderBasicInfo> queryOrderList(List<String> orderCodeList);
void tempOrderRefund();
void realTimeMonitorDataRedis2DB(String transactionCode, String orderCode);
/**
@@ -292,9 +288,6 @@ public interface IOrderBasicInfoService {
List<OrderPeriodAmountVO> transformPeriodAmountByOrderDetail(OrderDetail orderDetail);
String tempUpdateVirtualAmount(QueryOrderDTO dto);
/**
* 汇付支付 订单退款
* @param dto
@@ -347,5 +340,4 @@ public interface IOrderBasicInfoService {
*/
void retryRefundOrder(String orderCode) throws BaseAdaPayException;
void splitTheBillForOrderTemp(String merchantId, List<String> orderCodeList);
}

View File

@@ -7,7 +7,6 @@ import com.jsowell.pile.dto.SettleOrderReportDTO;
import com.jsowell.pile.vo.web.MerchantOrderReportVO;
import java.util.List;
import java.util.Map;
/**
* 结算订单报Service接口
@@ -101,5 +100,4 @@ public interface ISettleOrderReportService {
List<SettleOrderReport> queryOrderReport(List<String> stationIdList, String startTime, String endTime);
Map<String, Object> queryUndividedOrder(SettleOrderReportDTO dto);
}

View File

@@ -0,0 +1,28 @@
package com.jsowell.pile.service;
import java.util.List;
import com.jsowell.pile.domain.SettleOrderReport;
public interface SettleOrderReportService{
int deleteByPrimaryKey(Integer id);
int insert(SettleOrderReport record);
int insertOrUpdate(SettleOrderReport record);
int insertOrUpdateSelective(SettleOrderReport record);
int insertSelective(SettleOrderReport record);
SettleOrderReport selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(SettleOrderReport record);
int updateByPrimaryKey(SettleOrderReport record);
int updateBatch(List<SettleOrderReport> list);
int batchInsert(List<SettleOrderReport> list);
}

View File

@@ -6,7 +6,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
import com.jsowell.adapay.operation.PaymentConfirmOperation;
@@ -1210,62 +1209,6 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
orderSplittingOperations(adapayMemberAccount, stationReportList);
}
/**
* 手动接口执行订单分账逻辑
*/
@Override
public void tempOrderSplittingOperations(String merchantId, String tradeDate) {
logger.info("手动接口执行订单分账逻辑-运营商:{}, 交易日期:{}, 进行分账处理start", merchantId, tradeDate);
// 查询运营商有没有开通结算账户
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService.selectByMerchantId(merchantId);
if (adapayMemberAccount == null) {
logger.error("手动接口执行订单分账逻辑-订单分账逻辑error, 运营商id:{}, 未配置结算账户", merchantId);
return;
}
String appId = pileMerchantInfoService.queryAppIdByMerchantId(merchantId);
// 根据交易日期查询运营商下面所有站点的交易日报
List<SettleOrderReport> stationReportList = settleOrderReportService.selectByMerchantIdAndDate(merchantId, tradeDate);
for (SettleOrderReport orderReport : stationReportList) {
String orderCodes = orderReport.getOrderCodes();
if (StringUtils.isBlank(orderCodes)) {
logger.info("手动接口执行订单分账逻辑-站点:{}, 日期:{}, 没有查到订单数据", orderReport.getStationId(), tradeDate);
continue;
}
List<String> orderCodeList = Lists.newArrayList(StringUtils.split(orderCodes, ","));
List<OrderBasicInfo> orderBasicInfos = queryOrderList(orderCodeList);
if (CollectionUtils.isEmpty(orderBasicInfos)) {
logger.info("手动接口执行订单分账逻辑-站点:{}, 日期:{}, 没有查到订单数据", orderReport.getStationId(), tradeDate);
continue;
}
// 执行分账
for (OrderBasicInfo orderBasicInfo : orderBasicInfos) {
try {
OrderSettleResult orderSettleResult = null;
logger.info("手动接口执行订单分账逻辑-orderCode:{}, payMode:{}", orderBasicInfo.getOrderCode(), orderBasicInfo.getPayMode());
if (OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue().equals(orderBasicInfo.getPayMode())) {
logger.info("手动接口执行订单分账逻辑-order:{}, result:{}", JSON.toJSONString(orderBasicInfo), JSON.toJSONString(orderSettleResult));
// 余额支付的订单 只用余额支付转账
// orderSettleResult = doBalancePayment(orderBasicInfo, adapayMemberAccount);
} else {
// 在线支付,进行支付确认分账
orderSettleResult = doPaymentConfirmWithDelay(orderBasicInfo, adapayMemberAccount, appId);
}
// if (orderSettleResult != null && AdapayStatusEnum.SUCCEEDED.getValue().equals(orderSettleResult.getStatus())) {
// JSONObject jsonObject = JSON.parseObject(orderSettleResult.getDescription());
// String orderCode = (String) jsonObject.get("orderCode");
// }
} catch (Exception e) {
logger.error("手动接口执行订单分账逻辑-订单交易确认失败:{}", orderBasicInfo.getOrderCode(), e);
}
}
}
logger.info("手动接口执行订单分账逻辑-运营商:{}, 交易日期:{}, 进行分账处理end", merchantId, tradeDate);
}
/**
* 余额支付订单,使用余额分账
*
@@ -1437,43 +1380,6 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
return orderBasicInfoMapper.queryOrderList(orderCodeList);
}
/**
* 临时订单退款
*/
@Override
public void tempOrderRefund() {
// 查询出2023-05-29 12:00:00到2023-05-30 23:59:59中使用微信支付并且有退款金额的订单
String startTime = "2023-05-29 12:00:00";
String endTime = "2023-05-30 23:59:59";
List<OrderBasicInfo> orderList = orderBasicInfoMapper.tempQueryWeChatRefundOrders(startTime, endTime);
Map<String, OrderBasicInfo> orderBasicInfoMap = orderList.stream().collect(Collectors.toMap(OrderBasicInfo::getOrderCode, Function.identity(), (k1, k2) -> k1));
Set<String> orderCodes = orderBasicInfoMap.keySet();
// 根据上面的订单号,查微信退款回调,找出没有记录的订单,重新发起一遍退款
List<WxpayRefundCallback> wxpayRefundCallbacks = wxpayRefundCallbackService.selectByOrderCodeList(Lists.newArrayList(orderCodes));
Set<String> refundOrders = wxpayRefundCallbacks.stream().map(WxpayRefundCallback::getOrderCode).collect(Collectors.toSet());
// orderCodeList refundOrders 取差集
Sets.SetView<String> difference = Sets.difference(orderCodes, refundOrders);
for (String orderCode : difference) {
OrderBasicInfo orderBasicInfo = orderBasicInfoMap.get(orderCode);
if (orderBasicInfo == null) {
continue;
}
BigDecimal refundAmount = orderBasicInfo.getRefundAmount();
// 微信退款逻辑
ApplyRefundDTO weChatRefundDTO = new ApplyRefundDTO();
weChatRefundDTO.setOrderCode(orderBasicInfo.getOrderCode());
weChatRefundDTO.setRefundType("1");
weChatRefundDTO.setRefundAmount(refundAmount);
try {
this.weChatRefund(weChatRefundDTO);
} catch (Exception e) {
logger.error("临时订单退款接口发生异常 orderCode:{}", orderBasicInfo.getOrderCode(), e);
}
}
}
/**
* 从redis中取出实时记录保存到表中j
* 当订单完成的时候调用
@@ -2431,25 +2337,6 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
return Lists.newArrayList(sharp, peak, flat, valley);
}
@Override
public String tempUpdateVirtualAmount(QueryOrderDTO dto) {
dto.setOrderStatus(OrderStatusEnum.ORDER_COMPLETE.getValue());
List<OrderListVO> orderListVOS = orderBasicInfoMapper.selectOrderBasicInfoList(dto);
if (CollectionUtils.isEmpty(orderListVOS)) {
return "没有订单需要修改";
}
int i = 0;
for (OrderListVO orderListVO : orderListVOS) {
try {
tempUpdateVirtualAmount(orderListVO);
i += 1;
} catch (Exception e) {
logger.error("修改虚拟金额字段失败", e);
}
}
return "共查询到" + orderListVOS.size() + "条订单,修改成功" + i + "条订单数据";
}
/**
* 汇付支付-订单退款处理逻辑
* 汇付支付订单退款
@@ -2690,6 +2577,8 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
// 计算报表
SettleOrderReport settleOrderReport = new SettleOrderReport();
String settleCode = "SETTLE_" + IdUtils.getOrderCode();
settleOrderReport.setSettleCode(settleCode);
settleOrderReport.setMerchantId(stationInfo.getMerchantId());
settleOrderReport.setStationId(stationId);
settleOrderReport.setUseElectricity(useElectricity);
@@ -2994,77 +2883,6 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
}
}
@Override
public void splitTheBillForOrderTemp(String merchantId, List<String> orderCodeList) {
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(merchantId);
if (StringUtils.isBlank(wechatAppId)) {
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_WECHAT_APP_ID_IS_NULL);
}
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService.selectByMerchantId(merchantId);
if (adapayMemberAccount == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_MEMBER_IS_NULL_ERROR);
}
List<OrderBasicInfo> orderBasicInfos = queryOrderList(orderCodeList);
for (OrderBasicInfo orderBasicInfo : orderBasicInfos) {
try {
splitTheBillForOrderTemp(adapayMemberAccount, orderBasicInfo, wechatAppId);
} catch (BaseAdaPayException e) {
logger.error("余额支付订单分账工具, 发生异常", e);
throw new RuntimeException(e);
}
}
}
/**
* 余额支付订单分账工具
*/
public void splitTheBillForOrderTemp(AdapayMemberAccount adapayMemberAccount, OrderBasicInfo orderBasicInfo, String wechatAppId) throws BaseAdaPayException {
logger.info("");
// 查询会员余额支付记录
List<MemberAdapayRecord> recordList = memberAdapayRecordService.selectAdapayRecordList(orderBasicInfo.getMemberId(), ScenarioEnum.BALANCE.getValue());
if (CollectionUtils.isEmpty(recordList)) {
logger.info("余额支付订单分账工具, memberId:{}, 未查询到余额充值记录", orderBasicInfo.getMemberId());
return;
}
String orderCode = orderBasicInfo.getOrderCode();
if (recordList.size() > 1) {
logger.info("余额支付订单分账工具, 会员充值记录存在多条orderCode:{}由人工手动处理", orderCode);
return;
}
// 订单分账金额
BigDecimal amount = queryBalanceOrderSettleInfo(orderCode, orderBasicInfo.getMemberId(), wechatAppId);
// 判断分账金额 和结算金额是否相等
if (amount.compareTo(BigDecimal.ZERO) == 0) {
logger.info("余额支付订单分账工具, orderCode:{}, 已分账金额为0, 订单结算金额为:{}, 重试执行订单分账", orderCode, orderBasicInfo.getSettleAmount());
// 修改会员的汇付支付记录
for (MemberAdapayRecord memberAdapayRecord : recordList) {
BigDecimal spendAmt = memberAdapayRecord.getSpendAmt();
spendAmt = spendAmt.subtract(orderBasicInfo.getOrderAmount());
memberAdapayRecord.setSpendAmt(spendAmt);
BigDecimal balanceAmt = memberAdapayRecord.getBalanceAmt();
balanceAmt = balanceAmt.add(orderBasicInfo.getOrderAmount());
memberAdapayRecord.setBalanceAmt(balanceAmt);
memberAdapayRecordService.updateByPrimaryKeySelective(memberAdapayRecord);
}
// 分账金额为0表示该订单没有执行过分账再次执行分账
if (OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue().equals(orderBasicInfo.getPayMode())) {
// 余额支付的订单
doBalancePaymentWithDelay(orderBasicInfo, adapayMemberAccount, wechatAppId);
}
// 再次查询分账
BigDecimal bigDecimal = queryBalanceOrderSettleInfo(orderCode, orderBasicInfo.getMemberId(), wechatAppId);
logger.info("余额支付订单分账工具, orderCode:{}, 重新分账完成, 分账金额:{}, 订单结算金额:{}", orderCode, bigDecimal, orderBasicInfo.getSettleAmount());
} else {
logger.info("余额支付订单分账工具, orderCode:{}, 已分账金额为:{}, 订单结算金额为:{}, 不再执行订单分账", orderCode, amount, orderBasicInfo.getSettleAmount());
}
}
/**
* 查询余额订单分账信息
*

View File

@@ -3,12 +3,10 @@ package com.jsowell.pile.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse;
import com.jsowell.adapay.service.AdapayService;
import com.jsowell.common.core.page.PageResponse;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.StringUtils;
@@ -31,7 +29,6 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 结算订单报Service业务层处理
@@ -73,43 +70,6 @@ public class SettleOrderReportServiceImpl implements ISettleOrderReportService {
}
@Override
public Map<String, Object> queryUndividedOrder(SettleOrderReportDTO dto) {
Map<String, Object> resultMap = Maps.newHashMap();
SettleOrderReport orderReport = selectByStationIdAndDate(dto.getStationId(), dto.getTradeDate());
if (orderReport == null) {
throw new BusinessException("00300002", "查询站点订单日报为空");
}
String orderCodes = orderReport.getOrderCodes();
List<String> orderCodeList = Lists.newArrayList(StringUtils.split(orderCodes, ","));
List<ClearingBillVO> clearingBillVOList = clearingWithdrawInfoService.selectWithdrawInfoByOrderCodeList(orderCodeList);
if (CollectionUtils.isEmpty(clearingBillVOList)) {
throw new BusinessException("00300005", "查询清分信息为空");
}
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(orderReport.getMerchantId());
// clearing
List<ClearingBillVO> clearingList = Lists.newArrayList();
List<ClearingBillVO> unClearingList = Lists.newArrayList();
for (ClearingBillVO clearingBillVO : clearingBillVOList) {
String paymentId = clearingBillVO.getPaymentId();
QueryPaymentConfirmDTO build = QueryPaymentConfirmDTO.builder()
.wechatAppId(wechatAppId)
.paymentId(paymentId)
.build();
QueryPaymentConfirmDetailResponse response = adapayService.queryPaymentConfirmList(build);
List<QueryPaymentConfirmDetailResponse.PaymentConfirmInfo> paymentConfirms = response.getPaymentConfirms();
if (!CollectionUtils.isEmpty(paymentConfirms)) {
clearingBillVO.setConfirmInfo(paymentConfirms.get(0));
clearingList.add(clearingBillVO);
} else {
unClearingList.add(clearingBillVO);
}
}
resultMap.put("clearingList", clearingList);
resultMap.put("unClearingList", unClearingList);
return resultMap;
}
/**
* 查询站点订单日报明细

View File

@@ -5,6 +5,7 @@
<!--@mbg.generated-->
<!--@Table settle_order_report-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="settle_code" jdbcType="VARCHAR" property="settleCode" />
<result column="merchant_id" jdbcType="VARCHAR" property="merchantId" />
<result column="station_id" jdbcType="VARCHAR" property="stationId" />
<result column="order_codes" jdbcType="LONGVARCHAR" property="orderCodes" />
@@ -19,26 +20,14 @@
<result column="trade_amount" jdbcType="DECIMAL" property="tradeAmount" />
<result column="trade_fee" jdbcType="DECIMAL" property="tradeFee" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="del_flag" jdbcType="VARCHAR" property="delFlag" />
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id,
merchant_id,
station_id,
order_codes,
use_electricity,
charge_num,
charge_time,
electricity_amount,
service_amount,
total_amount,
virtual_amount,
trade_date,
trade_amount,
trade_fee,
create_time,
del_flag
id, settle_code, merchant_id, station_id, order_codes, use_electricity, charge_num,
charge_time, electricity_amount, service_amount, total_amount, virtual_amount, trade_date,
trade_amount, trade_fee, create_time, update_time, del_flag
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!--@mbg.generated-->
@@ -49,30 +38,31 @@
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
<!--@mbg.generated-->
delete
from settle_order_report
delete from settle_order_report
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.SettleOrderReport"
useGeneratedKeys="true">
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.SettleOrderReport" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into settle_order_report (merchant_id, station_id, order_codes,
use_electricity, charge_num, charge_time,
electricity_amount, service_amount, total_amount,
virtual_amount, trade_date, trade_amount,
trade_fee, create_time, del_flag)
values (#{merchantId,jdbcType=VARCHAR}, #{stationId,jdbcType=VARCHAR}, #{orderCodes,jdbcType=LONGVARCHAR},
#{useElectricity,jdbcType=DECIMAL}, #{chargeNum,jdbcType=VARCHAR}, #{chargeTime,jdbcType=VARCHAR},
#{electricityAmount,jdbcType=DECIMAL}, #{serviceAmount,jdbcType=DECIMAL},
#{totalAmount,jdbcType=DECIMAL},
#{virtualAmount,jdbcType=DECIMAL}, #{tradeDate,jdbcType=VARCHAR}, #{tradeAmount,jdbcType=DECIMAL},
#{tradeFee,jdbcType=DECIMAL}, #{createTime,jdbcType=TIMESTAMP}, #{delFlag,jdbcType=VARCHAR})
insert into settle_order_report (settle_code, merchant_id, station_id,
order_codes, use_electricity, charge_num,
charge_time, electricity_amount, service_amount,
total_amount, virtual_amount, trade_date,
trade_amount, trade_fee, create_time,
update_time, del_flag)
values (#{settleCode,jdbcType=VARCHAR}, #{merchantId,jdbcType=VARCHAR}, #{stationId,jdbcType=VARCHAR},
#{orderCodes,jdbcType=LONGVARCHAR}, #{useElectricity,jdbcType=DECIMAL}, #{chargeNum,jdbcType=VARCHAR},
#{chargeTime,jdbcType=VARCHAR}, #{electricityAmount,jdbcType=DECIMAL}, #{serviceAmount,jdbcType=DECIMAL},
#{totalAmount,jdbcType=DECIMAL}, #{virtualAmount,jdbcType=DECIMAL}, #{tradeDate,jdbcType=VARCHAR},
#{tradeAmount,jdbcType=DECIMAL}, #{tradeFee,jdbcType=DECIMAL}, #{createTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP}, #{delFlag,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id"
parameterType="com.jsowell.pile.domain.SettleOrderReport" useGeneratedKeys="true">
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.SettleOrderReport" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into settle_order_report
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="settleCode != null">
settle_code,
</if>
<if test="merchantId != null">
merchant_id,
</if>
@@ -115,11 +105,17 @@
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="delFlag != null">
del_flag,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="settleCode != null">
#{settleCode,jdbcType=VARCHAR},
</if>
<if test="merchantId != null">
#{merchantId,jdbcType=VARCHAR},
</if>
@@ -162,6 +158,9 @@
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
#{delFlag,jdbcType=VARCHAR},
</if>
@@ -171,6 +170,9 @@
<!--@mbg.generated-->
update settle_order_report
<set>
<if test="settleCode != null">
settle_code = #{settleCode,jdbcType=VARCHAR},
</if>
<if test="merchantId != null">
merchant_id = #{merchantId,jdbcType=VARCHAR},
</if>
@@ -213,6 +215,9 @@
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
del_flag = #{delFlag,jdbcType=VARCHAR},
</if>
@@ -222,7 +227,8 @@
<update id="updateByPrimaryKey" parameterType="com.jsowell.pile.domain.SettleOrderReport">
<!--@mbg.generated-->
update settle_order_report
set merchant_id = #{merchantId,jdbcType=VARCHAR},
set settle_code = #{settleCode,jdbcType=VARCHAR},
merchant_id = #{merchantId,jdbcType=VARCHAR},
station_id = #{stationId,jdbcType=VARCHAR},
order_codes = #{orderCodes,jdbcType=LONGVARCHAR},
use_electricity = #{useElectricity,jdbcType=DECIMAL},
@@ -236,6 +242,7 @@
trade_amount = #{tradeAmount,jdbcType=DECIMAL},
trade_fee = #{tradeFee,jdbcType=DECIMAL},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
del_flag = #{delFlag,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
@@ -243,6 +250,11 @@
<!--@mbg.generated-->
update settle_order_report
<trim prefix="set" suffixOverrides=",">
<trim prefix="settle_code = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.settleCode,jdbcType=VARCHAR}
</foreach>
</trim>
<trim prefix="merchant_id = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.merchantId,jdbcType=VARCHAR}
@@ -313,124 +325,14 @@
when id = #{item.id,jdbcType=INTEGER} then #{item.createTime,jdbcType=TIMESTAMP}
</foreach>
</trim>
<trim prefix="del_flag = case" suffix="end,">
<trim prefix="update_time = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.delFlag,jdbcType=VARCHAR}
</foreach>
</trim>
</trim>
where id in
<foreach close=")" collection="list" item="item" open="(" separator=", ">
#{item.id,jdbcType=INTEGER}
</foreach>
</update>
<update id="updateBatchSelective" parameterType="java.util.List">
<!--@mbg.generated-->
update settle_order_report
<trim prefix="set" suffixOverrides=",">
<trim prefix="merchant_id = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.merchantId != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.merchantId,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="station_id = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.stationId != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.stationId,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="order_codes = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.orderCodes != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.orderCodes,jdbcType=LONGVARCHAR}
</if>
</foreach>
</trim>
<trim prefix="use_electricity = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.useElectricity != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.useElectricity,jdbcType=DECIMAL}
</if>
</foreach>
</trim>
<trim prefix="charge_num = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.chargeNum != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.chargeNum,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="charge_time = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.chargeTime != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.chargeTime,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="electricity_amount = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.electricityAmount != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.electricityAmount,jdbcType=DECIMAL}
</if>
</foreach>
</trim>
<trim prefix="service_amount = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.serviceAmount != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.serviceAmount,jdbcType=DECIMAL}
</if>
</foreach>
</trim>
<trim prefix="total_amount = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.totalAmount != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.totalAmount,jdbcType=DECIMAL}
</if>
</foreach>
</trim>
<trim prefix="virtual_amount = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.virtualAmount != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.virtualAmount,jdbcType=DECIMAL}
</if>
</foreach>
</trim>
<trim prefix="trade_date = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.tradeDate != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.tradeDate,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="trade_amount = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.tradeAmount != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.tradeAmount,jdbcType=DECIMAL}
</if>
</foreach>
</trim>
<trim prefix="trade_fee = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.tradeFee != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.tradeFee,jdbcType=DECIMAL}
</if>
</foreach>
</trim>
<trim prefix="create_time = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.createTime != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.createTime,jdbcType=TIMESTAMP}
</if>
when id = #{item.id,jdbcType=INTEGER} then #{item.updateTime,jdbcType=TIMESTAMP}
</foreach>
</trim>
<trim prefix="del_flag = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.delFlag != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.delFlag,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
</trim>
@@ -442,31 +344,28 @@
<insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into settle_order_report
(merchant_id, station_id, order_codes, use_electricity, charge_num, charge_time,
electricity_amount, service_amount, total_amount, virtual_amount, trade_date, trade_amount,
trade_fee, create_time, del_flag)
(settle_code, merchant_id, station_id, order_codes, use_electricity, charge_num,
charge_time, electricity_amount, service_amount, total_amount, virtual_amount,
trade_date, trade_amount, trade_fee, create_time, update_time, del_flag)
values
<foreach collection="list" item="item" separator=",">
(#{item.merchantId,jdbcType=VARCHAR}, #{item.stationId,jdbcType=VARCHAR},
#{item.orderCodes,jdbcType=LONGVARCHAR},
#{item.useElectricity,jdbcType=DECIMAL}, #{item.chargeNum,jdbcType=VARCHAR},
#{item.chargeTime,jdbcType=VARCHAR},
#{item.electricityAmount,jdbcType=DECIMAL}, #{item.serviceAmount,jdbcType=DECIMAL},
#{item.totalAmount,jdbcType=DECIMAL}, #{item.virtualAmount,jdbcType=DECIMAL},
#{item.tradeDate,jdbcType=VARCHAR},
#{item.tradeAmount,jdbcType=DECIMAL}, #{item.tradeFee,jdbcType=DECIMAL},
#{item.createTime,jdbcType=TIMESTAMP},
#{item.delFlag,jdbcType=VARCHAR})
(#{item.settleCode,jdbcType=VARCHAR}, #{item.merchantId,jdbcType=VARCHAR}, #{item.stationId,jdbcType=VARCHAR},
#{item.orderCodes,jdbcType=LONGVARCHAR}, #{item.useElectricity,jdbcType=DECIMAL},
#{item.chargeNum,jdbcType=VARCHAR}, #{item.chargeTime,jdbcType=VARCHAR}, #{item.electricityAmount,jdbcType=DECIMAL},
#{item.serviceAmount,jdbcType=DECIMAL}, #{item.totalAmount,jdbcType=DECIMAL}, #{item.virtualAmount,jdbcType=DECIMAL},
#{item.tradeDate,jdbcType=VARCHAR}, #{item.tradeAmount,jdbcType=DECIMAL}, #{item.tradeFee,jdbcType=DECIMAL},
#{item.createTime,jdbcType=TIMESTAMP}, #{item.updateTime,jdbcType=TIMESTAMP}, #{item.delFlag,jdbcType=VARCHAR}
)
</foreach>
</insert>
<insert id="insertOrUpdate" keyColumn="id" keyProperty="id"
parameterType="com.jsowell.pile.domain.SettleOrderReport" useGeneratedKeys="true">
<insert id="insertOrUpdate" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.SettleOrderReport" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into settle_order_report
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
settle_code,
merchant_id,
station_id,
order_codes,
@@ -480,12 +379,16 @@
trade_date,
trade_amount,
trade_fee,
create_time,
update_time,
del_flag,
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
#{settleCode,jdbcType=VARCHAR},
#{merchantId,jdbcType=VARCHAR},
#{stationId,jdbcType=VARCHAR},
#{orderCodes,jdbcType=LONGVARCHAR},
@@ -499,12 +402,16 @@
#{tradeDate,jdbcType=VARCHAR},
#{tradeAmount,jdbcType=DECIMAL},
#{tradeFee,jdbcType=DECIMAL},
#{createTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP},
#{delFlag,jdbcType=VARCHAR},
</trim>
on duplicate key update
<trim suffixOverrides=",">
<if test="id != null">
id = #{id,jdbcType=INTEGER},
</if>
settle_code = #{settleCode,jdbcType=VARCHAR},
merchant_id = #{merchantId,jdbcType=VARCHAR},
station_id = #{stationId,jdbcType=VARCHAR},
order_codes = #{orderCodes,jdbcType=LONGVARCHAR},
@@ -518,16 +425,21 @@
trade_date = #{tradeDate,jdbcType=VARCHAR},
trade_amount = #{tradeAmount,jdbcType=DECIMAL},
trade_fee = #{tradeFee,jdbcType=DECIMAL},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
del_flag = #{delFlag,jdbcType=VARCHAR},
</trim>
</insert>
<insert id="insertOrUpdateSelective" keyColumn="id" keyProperty="id"
parameterType="com.jsowell.pile.domain.SettleOrderReport" useGeneratedKeys="true">
<insert id="insertOrUpdateSelective" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.SettleOrderReport" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into settle_order_report
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="settleCode != null">
settle_code,
</if>
<if test="merchantId != null">
merchant_id,
</if>
@@ -570,6 +482,9 @@
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="delFlag != null">
del_flag,
</if>
@@ -579,6 +494,9 @@
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="settleCode != null">
#{settleCode,jdbcType=VARCHAR},
</if>
<if test="merchantId != null">
#{merchantId,jdbcType=VARCHAR},
</if>
@@ -621,6 +539,9 @@
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
#{delFlag,jdbcType=VARCHAR},
</if>
@@ -630,6 +551,9 @@
<if test="id != null">
id = #{id,jdbcType=INTEGER},
</if>
<if test="settleCode != null">
settle_code = #{settleCode,jdbcType=VARCHAR},
</if>
<if test="merchantId != null">
merchant_id = #{merchantId,jdbcType=VARCHAR},
</if>
@@ -672,6 +596,9 @@
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
del_flag = #{delFlag,jdbcType=VARCHAR},
</if>
@@ -702,8 +629,7 @@
from settle_order_report
</sql>
<select id="selectSettleOrderReportList" parameterType="com.jsowell.pile.domain.SettleOrderReport"
resultMap="SettleOrderReportResult">
<select id="selectSettleOrderReportList" parameterType="com.jsowell.pile.domain.SettleOrderReport" resultMap="SettleOrderReportResult">
<include refid="selectSettleOrderReportVo" />
<where>
<if test="merchantId != null and merchantId != ''">
@@ -967,7 +893,7 @@
where del_flag = '0'
<if test="stationIdList != null and stationIdList.size() != 0">
and station_id in
<foreach collection="stationIdList" item="stationId" open="(" separator="," close=")">
<foreach close=")" collection="stationIdList" item="stationId" open="(" separator=",">
#{stationId,jdbcType=VARCHAR}
</foreach>
</if>