定时任务 订单分账逻辑

This commit is contained in:
2023-07-26 19:41:13 +08:00
parent 85908b4c70
commit c25e90e9ff
7 changed files with 69 additions and 22 deletions

View File

@@ -1,17 +1,14 @@
package com.jsowell.web.controller.pile;
import com.google.common.collect.Lists;
import com.jsowell.common.annotation.Log;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.AjaxResult;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
import com.jsowell.common.core.page.PageResponse;
import com.jsowell.common.core.page.TableDataInfo;
import com.jsowell.common.enums.BusinessType;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.SecurityUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.poi.ExcelUtil;
import com.jsowell.pile.domain.PileMerchantInfo;
import com.jsowell.pile.dto.CreateMerchantDTO;
@@ -22,7 +19,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
/**
@@ -44,7 +40,7 @@ public class PileMerchantInfoController extends BaseController {
@GetMapping("/list")
public TableDataInfo list(PileMerchantInfo pileMerchantInfo) {
startPage();
List<PileMerchantInfo> list = pileMerchantInfoService.selectPileMerchantInfoList(pileMerchantInfo);
List<PileMerchantInfo> list = pileMerchantInfoService.selectPileMerchantInfoListWithAuth(pileMerchantInfo);
return getDataTable(list);
}
@@ -56,7 +52,7 @@ public class PileMerchantInfoController extends BaseController {
@PreAuthorize("@ss.hasPermi('pile:merchant:list')")
@GetMapping("/getMerchantList")
public TableDataInfo getMerchantList(PileMerchantInfo pileMerchantInfo) {
List<PileMerchantInfo> list = pileMerchantInfoService.selectPileMerchantInfoList(pileMerchantInfo);
List<PileMerchantInfo> list = pileMerchantInfoService.selectPileMerchantInfoListWithAuth(pileMerchantInfo);
return getDataTable(list);
}
@@ -67,7 +63,7 @@ public class PileMerchantInfoController extends BaseController {
@Log(title = "充电桩运营商信息", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, PileMerchantInfo pileMerchantInfo) {
List<PileMerchantInfo> list = pileMerchantInfoService.selectPileMerchantInfoList(pileMerchantInfo);
List<PileMerchantInfo> list = pileMerchantInfoService.selectPileMerchantInfoListWithAuth(pileMerchantInfo);
ExcelUtil<PileMerchantInfo> util = new ExcelUtil<PileMerchantInfo>(PileMerchantInfo.class);
util.exportExcel(response, list, "充电桩运营商信息数据");
}

View File

@@ -136,9 +136,18 @@ public interface IOrderBasicInfoService {
List<OrderVO> getListByMemberIdAndOrderStatus(String memberId, List<String> orderStatusList, LocalDateTime dateTime, String stationId);
void doPaymentConfirm(OrderBasicInfo orderBasicInfo, AdapayMemberAccount adapayMemberAccount) throws BaseAdaPayException;
void orderSplittingOperations(String merchantId, String tradeDate);
void tempOrderRefund();
void doPaymentConfirm(OrderBasicInfo orderBasicInfo, AdapayMemberAccount adapayMemberAccount) throws BaseAdaPayException;
/**
* 批量查询订单
* @param orderCodeList
* @return
*/
List<OrderBasicInfo> queryOrderList(List<String> orderCodeList);
void tempOrderRefund();
void realTimeMonitorDataRedis2DB(String transactionCode, String orderCode);

View File

@@ -28,9 +28,11 @@ public interface IPileMerchantInfoService {
* @param pileMerchantInfo 充电桩运营商信息
* @return 充电桩运营商信息集合
*/
public List<PileMerchantInfo> selectPileMerchantInfoList(PileMerchantInfo pileMerchantInfo);
List<PileMerchantInfo> selectPileMerchantInfoListWithAuth(PileMerchantInfo pileMerchantInfo);
/**
List<PileMerchantInfo> selectPileMerchantInfoList(PileMerchantInfo pileMerchantInfo);
/**
* 新增充电桩运营商信息
*
* @param pileMerchantInfo 充电桩运营商信息

View File

@@ -874,12 +874,14 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
* orderSplittingOperations
* 只有开通结算账户的运营商才走分账逻辑
*/
private void orderSplittingOperations(String merchantId, String tradeDate) {
@Override
public void orderSplittingOperations(String merchantId, String tradeDate) {
// 查询运营商有没有开通结算账户
AdapayMemberAccount adapayMemberAccount = adapayMemberAccountService.selectByMerchantId(merchantId);
if (adapayMemberAccount == null) {
logger.error("订单分账逻辑error, 运营商id:{}, 未配置结算账户", merchantId);
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_MEMBER_IS_NULL_ERROR);
// throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_MEMBER_IS_NULL_ERROR);
return;
}
// 根据交易日期查询运营商下面所有站点的交易日报
@@ -913,6 +915,13 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
*/
@Override
public void doPaymentConfirm(OrderBasicInfo orderBasicInfo, AdapayMemberAccount adapayMemberAccount) throws BaseAdaPayException {
LocalDateTime now = LocalDateTime.now();
LocalDateTime dateTime = LocalDateTime.of(2023, 8, 1, 0, 0, 0);
if (now.isBefore(dateTime)) {
logger.info("当前时间:{}早于:{}, 此订单不进行分账处理, 订单信息:{}", DateUtils.formatDateTime(now), DateUtils.formatDateTime(dateTime), JSON.toJSONString(orderBasicInfo));
return;
}
// 查询订单的交易id
AdapayCallbackRecord adapayCallbackRecord = adapayCallbackRecordService.selectByOrderCode(orderBasicInfo.getOrderCode());
if (adapayCallbackRecord == null) {
@@ -967,6 +976,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
* @param orderCodeList
* @return
*/
@Override
public List<OrderBasicInfo> queryOrderList(List<String> orderCodeList) {
List<OrderBasicInfo> resultList = Lists.newArrayList();
if (CollectionUtils.isEmpty(orderCodeList)) {

View File

@@ -59,13 +59,12 @@ public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService {
/**
* 查询充电桩运营商信息列表
*
* 带权限校验
* @param pileMerchantInfo 充电桩运营商信息
* @return 充电桩运营商信息
*/
@Override
// @DataScope(deptAlias = "t")
public List<PileMerchantInfo> selectPileMerchantInfoList(PileMerchantInfo pileMerchantInfo) {
public List<PileMerchantInfo> selectPileMerchantInfoListWithAuth(PileMerchantInfo pileMerchantInfo) {
AuthorizedDeptVO authorizedMap = SecurityUtils.getAuthorizedMap();
if (authorizedMap == null) {
// 为空表示没有权限,返回空数组
@@ -73,7 +72,17 @@ public class PileMerchantInfoServiceImpl implements IPileMerchantInfoService {
}
pileMerchantInfo.setStationDeptIds(authorizedMap.getStationDeptIds());
pileMerchantInfo.setMerchantDeptIds(authorizedMap.getMerchantDeptIds());
return selectPileMerchantInfoList(pileMerchantInfo);
}
/**
* 查询充电桩运营商信息列表
* 无权限校验
* @param pileMerchantInfo 充电桩运营商信息
* @return 充电桩运营商信息
*/
@Override
public List<PileMerchantInfo> selectPileMerchantInfoList(PileMerchantInfo pileMerchantInfo) {
List<PileMerchantInfo> list = pileMerchantInfoMapper.selectPileMerchantInfoList(pileMerchantInfo);
if (Objects.nonNull(list)) {
for (PileMerchantInfo p:list) {

View File

@@ -807,7 +807,7 @@
order by t1.trade_date DESC
</select>
<select id="selectByStationIdAndDate" resultMap="SettleOrderReportResult">
<select id="selectByStationIdAndDate" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from settle_order_report
where del_flag = '0'
@@ -815,7 +815,7 @@
and trade_date = #{date,jdbcType=VARCHAR}
</select>
<select id="selectByMerchantIdAndDate" resultMap="SettleOrderReportResult">
<select id="selectByMerchantIdAndDate" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from settle_order_report
where del_flag = '0'

View File

@@ -6,13 +6,11 @@ import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.PileMerchantInfo;
import com.jsowell.pile.domain.PileStationInfo;
import com.jsowell.pile.domain.ykcCommond.PublishPileBillingTemplateCommand;
import com.jsowell.pile.domain.ykcCommond.StartChargingCommand;
import com.jsowell.pile.service.IOrderBasicInfoService;
import com.jsowell.pile.service.IPileBillingTemplateService;
import com.jsowell.pile.service.IPileStationInfoService;
import com.jsowell.pile.service.YKCPushCommandService;
import com.jsowell.pile.service.*;
import com.jsowell.pile.vo.web.BillingTemplateVO;
import com.jsowell.thirdparty.amap.service.AMapService;
import org.apache.commons.collections4.CollectionUtils;
@@ -42,6 +40,9 @@ public class JsowellTask {
@Autowired
private YKCPushCommandService ykcPushCommandService;
@Autowired
private IPileMerchantInfoService pileMerchantInfoService;
@Autowired
private IPileStationInfoService pileStationInfoService;
@@ -157,4 +158,24 @@ public class JsowellTask {
// 删除缓存
redisCache.deleteObject(CacheConstants.PUSH_STATION_CONNECTOR);
}
/**
* 定时任务,处理订单分账
* jsowellTask.processOrderSplitting()
*/
public void processOrderSplitting() {
// 查询运营商列表
List<PileMerchantInfo> pileMerchantInfos = pileMerchantInfoService.selectPileMerchantInfoList(null);
if (CollectionUtils.isEmpty(pileMerchantInfos)) {
log.info("定时任务,处理订单分账, 未查询到运营商列表,直接返回");
return;
}
// 获取日期
// LocalDate yesterday = LocalDate.now().plusDays(-1);
LocalDate yesterday = LocalDate.of(2023, 7, 8);
// 调分账方法
pileMerchantInfos.parallelStream().forEach(merchant -> {
orderBasicInfoService.orderSplittingOperations(merchant.getId()+"", yesterday.toString());
});
}
}