|
@@ -1,18 +1,24 @@
|
|
|
package com.fs.course.service.impl;
|
|
package com.fs.course.service.impl;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.company.domain.Company;
|
|
import com.fs.company.domain.Company;
|
|
|
import com.fs.company.domain.CompanyMoneyLogs;
|
|
import com.fs.company.domain.CompanyMoneyLogs;
|
|
|
import com.fs.company.mapper.CompanyMapper;
|
|
import com.fs.company.mapper.CompanyMapper;
|
|
|
import com.fs.company.mapper.CompanyMoneyLogsMapper;
|
|
import com.fs.company.mapper.CompanyMoneyLogsMapper;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
import com.fs.course.config.CourseConfig;
|
|
|
|
|
+import com.fs.course.config.RedPacketConfig;
|
|
|
import com.fs.course.domain.FsCourseWatchLog;
|
|
import com.fs.course.domain.FsCourseWatchLog;
|
|
|
import com.fs.course.mapper.FsCourseWatchLogMapper;
|
|
import com.fs.course.mapper.FsCourseWatchLogMapper;
|
|
|
import com.fs.course.param.FsCourseRedPacketLogParam;
|
|
import com.fs.course.param.FsCourseRedPacketLogParam;
|
|
@@ -22,9 +28,17 @@ import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.his.param.WxSendRedPacketParam;
|
|
import com.fs.his.param.WxSendRedPacketParam;
|
|
|
import com.fs.his.service.IFsStorePaymentService;
|
|
import com.fs.his.service.IFsStorePaymentService;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
|
|
+import com.github.binarywang.wxpay.bean.transfer.QueryTransferBatchesRequest;
|
|
|
|
|
+import com.github.binarywang.wxpay.bean.transfer.QueryTransferBatchesResult;
|
|
|
import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult;
|
|
import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult;
|
|
|
|
|
+import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
|
|
|
+import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
|
|
+import com.github.binarywang.wxpay.service.TransferService;
|
|
|
|
|
+import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
|
|
+import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.fs.course.mapper.FsCourseRedPacketLogMapper;
|
|
import com.fs.course.mapper.FsCourseRedPacketLogMapper;
|
|
@@ -49,6 +63,7 @@ public class FsCourseRedPacketLogServiceImpl implements IFsCourseRedPacketLogSer
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ISysConfigService configService;
|
|
private ISysConfigService configService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询短链课程看课记录
|
|
* 查询短链课程看课记录
|
|
|
*
|
|
*
|
|
@@ -390,4 +405,72 @@ public class FsCourseRedPacketLogServiceImpl implements IFsCourseRedPacketLogSer
|
|
|
company.getCompanyId(), moneyLog.getMoney());
|
|
company.getCompanyId(), moneyLog.getMoney());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Description: 查询微信红包转账结果 每10分钟查询上一个10分钟区间的红包转账结果
|
|
|
|
|
+ * @Param: startTime yyyy-MM-dd HH:mm:ss
|
|
|
|
|
+ * @Return:
|
|
|
|
|
+ * @Author xgb
|
|
|
|
|
+ * @Date 2025/10/15 17:42
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void queryRedPacketResult(String startTime, String endTime) {
|
|
|
|
|
+ LocalDateTime tenMinutesAgo;
|
|
|
|
|
+ LocalDateTime twentyMinutesAgo;
|
|
|
|
|
+ if(StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)){
|
|
|
|
|
+ // 获取前十分钟时间 和 前二十分钟时间
|
|
|
|
|
+ tenMinutesAgo = LocalDateTime.now().minusMinutes(10);
|
|
|
|
|
+ twentyMinutesAgo = tenMinutesAgo.minusMinutes(10);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ tenMinutesAgo = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
+ twentyMinutesAgo = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 获取前分钟时间
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ params.put("createTime", twentyMinutesAgo);
|
|
|
|
|
+ params.put("endTime",tenMinutesAgo);
|
|
|
|
|
+ // 获取前十分钟红包记录状态为发送中的记录
|
|
|
|
|
+ List<FsCourseRedPacketLog> redPacketLogs = fsCourseRedPacketLogMapper.selectFsCourseRedPacketLogListBySending();
|
|
|
|
|
+ if(redPacketLogs!=null && !redPacketLogs.isEmpty()){
|
|
|
|
|
+ String json = configService.selectConfigByKey("redPacket.config");
|
|
|
|
|
+ RedPacketConfig config = JSONUtil.toBean(json, RedPacketConfig.class);
|
|
|
|
|
+ //创建微信订单
|
|
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
|
|
+ BeanUtils.copyProperties(config,payConfig);
|
|
|
|
|
+ WxPayService wxPayService = new WxPayServiceImpl();
|
|
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
|
|
+ TransferService transferService=wxPayService.getTransferService();
|
|
|
|
|
+ for(FsCourseRedPacketLog redPacket:redPacketLogs){
|
|
|
|
|
+ // 获取批次号
|
|
|
|
|
+ // redPacket.getResult() {"msg":"发送红包成功","code":200,"mchId":"1703311381","data":{"createTime":"2025-06-26T18:00:48+08:00","outBillNo":"fsCourse1938175604536901632","packageInfo":"ABBQO+oYAAABAAAAAABRil0NtaWxBS5JURpdaBAAAADnGpepZahT9IkJjn90+1qgtzWOmCRNZJfek1QMbZ9ktG8idrj37//0xOSt0T67XUFE+PGeXO8qZoNKHYlU3RicIHExIjZr342xE+QjrpjaHIFYoPg=","state":"WAIT_USER_CONFIRM","transferBillNo":"1330007292140242506260028904279364"},"isNew":1}
|
|
|
|
|
+ // 获取 transferBillNo
|
|
|
|
|
+ String batchId;
|
|
|
|
|
+ try {
|
|
|
|
|
+ batchId = StringUtils.isNotEmpty(redPacket.getBatchId())?redPacket.getBatchId():JSON.parseObject(redPacket.getResult()).getJSONObject("data").getString("transferBillNo");
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ logger.error("【红包处理】获取批次号失败,FsCourseRedPacketLog-log_id:{}",redPacket.getLogId());
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ QueryTransferBatchesRequest request = new QueryTransferBatchesRequest();
|
|
|
|
|
+ request.setBatchId(batchId);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ QueryTransferBatchesResult queryRedPacketResult = transferService.transferBatchesBatchId(request);
|
|
|
|
|
+ logger.info("FsCourseRedPacketLog-log_id:{},【红包处理】查询批次结果:{}",redPacket.getLogId(),queryRedPacketResult);
|
|
|
|
|
+ if(queryRedPacketResult!=null && queryRedPacketResult.getTransferBatch()!=null && "SUCCESS".equals(queryRedPacketResult.getTransferBatch().getBatchStatus())){
|
|
|
|
|
+ FsCourseRedPacketLog fsCourseRedPacketLog=new FsCourseRedPacketLog();
|
|
|
|
|
+ fsCourseRedPacketLog.setLogId(redPacket.getLogId());
|
|
|
|
|
+ fsCourseRedPacketLog.setStatus(1); // 已发送
|
|
|
|
|
+ fsCourseRedPacketLog.setUpdateTime(new Date());
|
|
|
|
|
+ updateFsCourseRedPacketLog(redPacket);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|