- 浏览: 12194 次
- 性别:
- 来自: 重庆
文章分类
最新评论
1)
package com.sfpay.sypay.msp.process;
public interface ServiceHolder<T> {
T getService();
}
2)
package com.sfpay.sypay.msp.process.service.impl;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sfpay.sypay.msp.common.enums.StatusCode;
import com.sfpay.sypay.msp.dao.ICourierSfjSendDao;
import com.sfpay.sypay.msp.process.ServiceHolder;
import com.sfpay.sypay.order.service.IPrefBusinessService;
import com.sfpay.sypay.order.valueobject.dto.PrefBusinessRequest;
import com.sfpay.sypay.order.valueobject.dto.PrefBusinessResponse;
/**
* 非线支付,给收派员送顺丰金任务
*
* @author sfhq703
*
*/
public class PrefSenderRun implements Runnable {
private Logger logger = LoggerFactory.getLogger(PrefSenderRun.class);
private BlockingQueue<List<PrefBusinessRequest>> senderQueue = null;
private ServiceHolder<IPrefBusinessService> prefBusinessService;// 发送奖励对象
private ServiceHolder<ICourierSfjSendDao> courierSfjSendDao;
private AtomicBoolean isTodayTaskCompletePref = null;
private int runNum = 0;
private AtomicBoolean isExecutePref = null;
/**
*
* @param senderQueue
* :下发队列
* @param voucherManagerService
* :下游系统service
* @param courierSfjSendDao
* :发送DAO
* @param isTodayTaskComplete
* :调度是否完成标示
*/
public PrefSenderRun(BlockingQueue<List<PrefBusinessRequest>> senderQueue,
ServiceHolder<IPrefBusinessService> prefBusinessService,
ServiceHolder<ICourierSfjSendDao> courierSfjSendDao,
AtomicBoolean isTodayTaskCompletePref, int runNum,
AtomicBoolean isExecutePref) {
super();
this.senderQueue = senderQueue;
this.prefBusinessService = prefBusinessService;
this.courierSfjSendDao = courierSfjSendDao;
this.isTodayTaskCompletePref = isTodayTaskCompletePref;
this.runNum = runNum;
this.isExecutePref = isExecutePref;
}
@Override
public void run() {
while (true) {
try {
List<PrefBusinessRequest> sendParamList = senderQueue.take();
if (isExecutePref.get()) {
isExecutePref.set(false);
}
logger.info(String.format("%s开始发送如下的顺丰金数据%s", runNum,
sendParamList));
if (null != sendParamList && !sendParamList.isEmpty()) {
try {
// 发送接口
List<PrefBusinessResponse> prefBusinessResponses = prefBusinessService
.getService().sendPrefBusiness(sendParamList);
updateError(prefBusinessResponses);
updateFin(sendParamList);
} catch (Exception e) {
logger.error("执行非线支付,处理给收派员送顺丰金线程异常,runNum=" + runNum,
e);
}
}
if (isTodayTaskCompletePref.get() && senderQueue.isEmpty()) {
isExecutePref.set(true);
logger.info("********************非线支付,给收派员送顺丰金线任务执行完毕********************runNum="
+ runNum);
}
} catch (InterruptedException e) {
logger.error("非线支付,给收派员送顺丰金线程被中断,runNum=" + runNum, e);
} catch (Exception ex) {
logger.error("执行非线支付,给收派员送顺丰金线程异常,runNum=" + runNum, ex);
}
}
}
/**
* 批量更新成功
*
* @param prefBusinessRequests
*/
private void updateFin(List<PrefBusinessRequest> prefBusinessRequests) {
List<Long> list = new ArrayList<Long>();
if (prefBusinessRequests != null && !prefBusinessRequests.isEmpty()) {
for (PrefBusinessRequest prefBusinessRequest : prefBusinessRequests) {
if (StringUtils.isNotBlank(prefBusinessRequest.getMarketId())) {
list.add(Long.valueOf(prefBusinessRequest.getMarketId()));
}
}
}
workStatusUpdate(list, StatusCode.FIN.name());
}
/**
* 批量更新失败
*
* @param businessResponses
*/
private void updateError(List<PrefBusinessResponse> businessResponses) {
List<Long> list = new ArrayList<Long>();
if (businessResponses != null && !businessResponses.isEmpty()) {
for (PrefBusinessResponse prefBusinessResponse : businessResponses) {
if (StringUtils.isNotBlank(prefBusinessResponse.getMarketId())) {
list.add(Long.valueOf(prefBusinessResponse.getMarketId()));
}
}
}
workStatusUpdate(list, StatusCode.ERROR.name());
}
/**
* 更新赠送的明细
*/
private void workStatusUpdate(List<Long> list, String status) {
try {
logger.info(String.format("[%s]更新非线支付,给收派员送顺丰金状态[%s],更新数量:[%s]",
runNum, status, list.size()));
if (!list.isEmpty()) {
courierSfjSendDao.getService().updateCourierSfjSendStatus(
StatusCode.SENDING.name(), status, list);
}
} catch (Exception e) {
logger.error(
"courierSfjSendDao.updateCourierSfjSendStatus 修改非线支付,给收派员送顺丰金状态失败,runNum="
+ runNum, e);
}
}
/**
*
* 方法说明:<br>
* 获取本机ip
*
* @return
*/
public static String getHostAddr() {
String hostIp = "";
// 定义网络接口枚举类
Enumeration<NetworkInterface> allNetInterfaces;
try {
// 获得网络接口
allNetInterfaces = NetworkInterface.getNetworkInterfaces();
// 声明一个InetAddress类型ip地址
InetAddress ip = null;
// 遍历所有的网络接口
while (allNetInterfaces.hasMoreElements()) {
NetworkInterface netInterface = allNetInterfaces.nextElement();
// 同样再定义网络地址枚举类
Enumeration<InetAddress> addresses = netInterface
.getInetAddresses();
while (addresses.hasMoreElements()) {
ip = addresses.nextElement();
// InetAddress类包括Inet4Address和Inet6Address
if (ip != null && (ip instanceof Inet4Address)) {
hostIp = ip.getHostAddress();
if ("127.0.0.1".equals(hostIp)) {
hostIp = "";
}
}
}
}
} catch (Exception e) {
}
if (StringUtils.isEmpty(hostIp)) {
// 如果无法获取本机Ip,给默认内网ip
hostIp = "192.168.0.1";
}
return hostIp;
}
}
3)
package com.sfpay.sypay.msp.process.service;
/**
* 方法说明:非线支付,短信发送任务
*
* @author sfhq703
*
*/
public interface IFxSmsSendTaskService {
/**
* 方法说明:方法说明:非线支付,短信发送任务
*
* @return
*/
public void presentPrefSend();
}
4)
package com.sfpay.sypay.msp.process.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.sfpay.framework.config.properties.Property;
import com.sfpay.sypay.common.enums.CcyType;
import com.sfpay.sypay.common.enums.TradeType;
import com.sfpay.sypay.msp.common.enums.StatusCode;
import com.sfpay.sypay.msp.dao.ICourierSfjSendDao;
import com.sfpay.sypay.msp.process.ServiceHolder;
import com.sfpay.sypay.msp.process.service.IFxPrefSendTaskService;
import com.sfpay.sypay.msp.valueobject.dto.CourierSfjSend;
import com.sfpay.sypay.order.service.IPrefBusinessService;
import com.sfpay.sypay.order.valueobject.dto.PrefBusinessRequest;
/**
* 非线支付,给收派员送顺丰金
*
* @author sfhq703
*
*/
@Service
public class PrefSendTaskServiceImpl implements IFxPrefSendTaskService {
private Logger logger = LoggerFactory
.getLogger(PrefSendTaskServiceImpl.class);
/**
* 字段说明:批次个数
*/
private static final int BATCH_COUNT = 800;
/**
* 调用订单系统单次发送条数
*/
private int one_send_size = 0;
/**
* 发送队列
*/
private BlockingQueue<List<PrefBusinessRequest>> senderQueue = null;
@Resource
private ICourierSfjSendDao courierSfjSendDao;
@Resource
private IPrefBusinessService prefBusinessService;
private AtomicBoolean isTodayTaskCompletePref = new AtomicBoolean(true);
private AtomicBoolean isExecutePref = new AtomicBoolean(true);
/**
* 非线支付,给收派员送顺丰金实现构造函数
*/
public PrefSendTaskServiceImpl() {
int sender_thread = Integer.parseInt(Property
.getProperty("MSP_PRESENT_SENDER_THREAD_CNT"));
one_send_size = Integer.parseInt(Property
.getProperty("MSP_PRESENT_ONE_SEND_SIZE"));
senderQueue = new LinkedBlockingQueue<List<PrefBusinessRequest>>(
Integer.parseInt(Property
.getProperty("MSP_PRESENT_DATA_QUEUE_SIZE")));
ExecutorService exec = Executors.newFixedThreadPool(sender_thread);// 创建一个定长线程池,可控制线程最大并发数,超出的线程会在队列中等待
for (int i = 0; i < sender_thread; i++) {
exec.submit(new PrefSenderRun(senderQueue,
new ServiceHolder<IPrefBusinessService>() {
public IPrefBusinessService getService() {
return prefBusinessService;
}
}, new ServiceHolder<ICourierSfjSendDao>() {
public ICourierSfjSendDao getService() {
return courierSfjSendDao;
}
}, isTodayTaskCompletePref, i, isExecutePref));
}
}
/**
* 方法说明:非线支付,给收派员送顺丰金任务实现
*
* @return
*/
@Override
public void presentPrefSend() {
if (!isExecutePref.get()) {
logger.info("非线支付,给收派员送顺丰金任务执行中………………………………");
if (isTodayTaskCompletePref.get() && senderQueue.isEmpty()) {
isExecutePref.set(true);
logger.info("********************非线支付,给收派员送顺丰金线任务执行列表以被线程取完,可继续执行本次个调度********************");
} else {
return;
}
}
isExecutePref.set(false);
isTodayTaskCompletePref.set(false);
int pgIndex = 0;
List<CourierSfjSend> oneBatchList = new ArrayList<CourierSfjSend>();
List<CourierSfjSend> allDataList = null;
try {
courierSfjSendDao.updateCourierSfjSendStatus(
StatusCode.SENDING.name(), StatusCode.INIT.name(), null);
allDataList = courierSfjSendDao.findCourierSfjSendList(pgIndex,
BATCH_COUNT);
} catch (Exception e) {
logger.info("非线支付,给收派员送顺丰金任务,初始化数据异常:", e);
}
if (allDataList == null || allDataList.isEmpty()) {
isExecutePref.set(true);
isTodayTaskCompletePref.set(true);
logger.info("非线支付,给收派员送顺丰金任务,没有需要发送的数据");
return;
}
while (allDataList != null && !allDataList.isEmpty()) {
try {
for (CourierSfjSend awardResult : allDataList) {
oneBatchList.add(awardResult);
// 每ONE_SEND_SIZE次调用一次订单接口
if (oneBatchList.size() > one_send_size) {
workOneJob(oneBatchList);
oneBatchList.clear();
}
}
// 没有凑足 ONE_SEND_SIZE,剩下的直接放入发送队列吧
if (!oneBatchList.isEmpty()) {
workOneJob(oneBatchList);
oneBatchList.clear();
}
} catch (Exception e) {
logger.error("非线支付,给收派员送顺丰金异常", e);
throw new RuntimeException(e);
}
try {
allDataList = courierSfjSendDao.findCourierSfjSendList(pgIndex,
BATCH_COUNT);
} catch (Exception e) {
logger.info("非线支付,给收派员送顺丰金任务,取数据异常:", e);
}
}
isTodayTaskCompletePref.set(true);
}
/**
* 执行赠送逻辑
*
* @param resultList
* @throws Exception
* @return 返回赠送失败id
*/
public void workOneJob(List<CourierSfjSend> resultList) throws Exception {
List<PrefBusinessRequest> sendParamList = new ArrayList<PrefBusinessRequest>();
workStatusUpdate(resultList);
try {
// 批次更新发放状态
// 构造请求报文,调用订单系统发放奖品
for (CourierSfjSend courierSfjSend : resultList) {
// TODO封装数据
PrefBusinessRequest prefBusiness = new PrefBusinessRequest();
prefBusiness.setAmount(courierSfjSend.getSfjinAmt());
// prefBusiness.setActivityId();
prefBusiness.setCcy(CcyType.SFP);
prefBusiness.setLoginName(courierSfjSend.getMobile());
prefBusiness.setMemberNo(courierSfjSend.getMemberNo());
prefBusiness.setMarketId(courierSfjSend.getId() + "");
prefBusiness.setMerchantNo(Property
.getProperty("FX_PREF_MERCHANT_NO"));
prefBusiness.setOutBusinessNo(courierSfjSend.getId() + "");
prefBusiness.setSendMerchantNo(Property
.getProperty("FX_SND_MERCHANT_NO"));
prefBusiness.setBusinessType("FX");
prefBusiness.setPrefType(TradeType.POINT_PREF);
// prefBusiness.setOrderAmont();
// prefBusiness.setCostEntity();
prefBusiness.setRemark("电子支付奖励");
// prefBusiness.setCostSubjectsNo();
// prefBusiness.setCostSubjectsName();
sendParamList.add(prefBusiness);
}
if (!sendParamList.isEmpty()) {
logger.info(String.format("非线支付,给收派员送顺丰金放入发送队列,当前队列长度%s",
senderQueue.size()));
senderQueue.put(sendParamList);
}
} catch (Exception e) {
logger.error("非线支付,给收派员送顺丰金异常", e);
}
}
/**
* 更新赠送的明细
*/
private void workStatusUpdate(List<CourierSfjSend> courierSfjSends) {
try {
List<Long> list = new ArrayList<Long>();
for (CourierSfjSend courierSfjSend : courierSfjSends) {
list.add(courierSfjSend.getId());
}
courierSfjSendDao.updateCourierSfjSendStatus(
StatusCode.INIT.name(), StatusCode.SENDING.name(), list);
} catch (Exception e) {
logger.error(
"courierSfjSendDao.updateCourierSfjSendStatus 修改非线支付,给收派员送顺丰金状态失败",
e);
}
}
}
package com.sfpay.sypay.msp.process;
public interface ServiceHolder<T> {
T getService();
}
2)
package com.sfpay.sypay.msp.process.service.impl;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sfpay.sypay.msp.common.enums.StatusCode;
import com.sfpay.sypay.msp.dao.ICourierSfjSendDao;
import com.sfpay.sypay.msp.process.ServiceHolder;
import com.sfpay.sypay.order.service.IPrefBusinessService;
import com.sfpay.sypay.order.valueobject.dto.PrefBusinessRequest;
import com.sfpay.sypay.order.valueobject.dto.PrefBusinessResponse;
/**
* 非线支付,给收派员送顺丰金任务
*
* @author sfhq703
*
*/
public class PrefSenderRun implements Runnable {
private Logger logger = LoggerFactory.getLogger(PrefSenderRun.class);
private BlockingQueue<List<PrefBusinessRequest>> senderQueue = null;
private ServiceHolder<IPrefBusinessService> prefBusinessService;// 发送奖励对象
private ServiceHolder<ICourierSfjSendDao> courierSfjSendDao;
private AtomicBoolean isTodayTaskCompletePref = null;
private int runNum = 0;
private AtomicBoolean isExecutePref = null;
/**
*
* @param senderQueue
* :下发队列
* @param voucherManagerService
* :下游系统service
* @param courierSfjSendDao
* :发送DAO
* @param isTodayTaskComplete
* :调度是否完成标示
*/
public PrefSenderRun(BlockingQueue<List<PrefBusinessRequest>> senderQueue,
ServiceHolder<IPrefBusinessService> prefBusinessService,
ServiceHolder<ICourierSfjSendDao> courierSfjSendDao,
AtomicBoolean isTodayTaskCompletePref, int runNum,
AtomicBoolean isExecutePref) {
super();
this.senderQueue = senderQueue;
this.prefBusinessService = prefBusinessService;
this.courierSfjSendDao = courierSfjSendDao;
this.isTodayTaskCompletePref = isTodayTaskCompletePref;
this.runNum = runNum;
this.isExecutePref = isExecutePref;
}
@Override
public void run() {
while (true) {
try {
List<PrefBusinessRequest> sendParamList = senderQueue.take();
if (isExecutePref.get()) {
isExecutePref.set(false);
}
logger.info(String.format("%s开始发送如下的顺丰金数据%s", runNum,
sendParamList));
if (null != sendParamList && !sendParamList.isEmpty()) {
try {
// 发送接口
List<PrefBusinessResponse> prefBusinessResponses = prefBusinessService
.getService().sendPrefBusiness(sendParamList);
updateError(prefBusinessResponses);
updateFin(sendParamList);
} catch (Exception e) {
logger.error("执行非线支付,处理给收派员送顺丰金线程异常,runNum=" + runNum,
e);
}
}
if (isTodayTaskCompletePref.get() && senderQueue.isEmpty()) {
isExecutePref.set(true);
logger.info("********************非线支付,给收派员送顺丰金线任务执行完毕********************runNum="
+ runNum);
}
} catch (InterruptedException e) {
logger.error("非线支付,给收派员送顺丰金线程被中断,runNum=" + runNum, e);
} catch (Exception ex) {
logger.error("执行非线支付,给收派员送顺丰金线程异常,runNum=" + runNum, ex);
}
}
}
/**
* 批量更新成功
*
* @param prefBusinessRequests
*/
private void updateFin(List<PrefBusinessRequest> prefBusinessRequests) {
List<Long> list = new ArrayList<Long>();
if (prefBusinessRequests != null && !prefBusinessRequests.isEmpty()) {
for (PrefBusinessRequest prefBusinessRequest : prefBusinessRequests) {
if (StringUtils.isNotBlank(prefBusinessRequest.getMarketId())) {
list.add(Long.valueOf(prefBusinessRequest.getMarketId()));
}
}
}
workStatusUpdate(list, StatusCode.FIN.name());
}
/**
* 批量更新失败
*
* @param businessResponses
*/
private void updateError(List<PrefBusinessResponse> businessResponses) {
List<Long> list = new ArrayList<Long>();
if (businessResponses != null && !businessResponses.isEmpty()) {
for (PrefBusinessResponse prefBusinessResponse : businessResponses) {
if (StringUtils.isNotBlank(prefBusinessResponse.getMarketId())) {
list.add(Long.valueOf(prefBusinessResponse.getMarketId()));
}
}
}
workStatusUpdate(list, StatusCode.ERROR.name());
}
/**
* 更新赠送的明细
*/
private void workStatusUpdate(List<Long> list, String status) {
try {
logger.info(String.format("[%s]更新非线支付,给收派员送顺丰金状态[%s],更新数量:[%s]",
runNum, status, list.size()));
if (!list.isEmpty()) {
courierSfjSendDao.getService().updateCourierSfjSendStatus(
StatusCode.SENDING.name(), status, list);
}
} catch (Exception e) {
logger.error(
"courierSfjSendDao.updateCourierSfjSendStatus 修改非线支付,给收派员送顺丰金状态失败,runNum="
+ runNum, e);
}
}
/**
*
* 方法说明:<br>
* 获取本机ip
*
* @return
*/
public static String getHostAddr() {
String hostIp = "";
// 定义网络接口枚举类
Enumeration<NetworkInterface> allNetInterfaces;
try {
// 获得网络接口
allNetInterfaces = NetworkInterface.getNetworkInterfaces();
// 声明一个InetAddress类型ip地址
InetAddress ip = null;
// 遍历所有的网络接口
while (allNetInterfaces.hasMoreElements()) {
NetworkInterface netInterface = allNetInterfaces.nextElement();
// 同样再定义网络地址枚举类
Enumeration<InetAddress> addresses = netInterface
.getInetAddresses();
while (addresses.hasMoreElements()) {
ip = addresses.nextElement();
// InetAddress类包括Inet4Address和Inet6Address
if (ip != null && (ip instanceof Inet4Address)) {
hostIp = ip.getHostAddress();
if ("127.0.0.1".equals(hostIp)) {
hostIp = "";
}
}
}
}
} catch (Exception e) {
}
if (StringUtils.isEmpty(hostIp)) {
// 如果无法获取本机Ip,给默认内网ip
hostIp = "192.168.0.1";
}
return hostIp;
}
}
3)
package com.sfpay.sypay.msp.process.service;
/**
* 方法说明:非线支付,短信发送任务
*
* @author sfhq703
*
*/
public interface IFxSmsSendTaskService {
/**
* 方法说明:方法说明:非线支付,短信发送任务
*
* @return
*/
public void presentPrefSend();
}
4)
package com.sfpay.sypay.msp.process.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.sfpay.framework.config.properties.Property;
import com.sfpay.sypay.common.enums.CcyType;
import com.sfpay.sypay.common.enums.TradeType;
import com.sfpay.sypay.msp.common.enums.StatusCode;
import com.sfpay.sypay.msp.dao.ICourierSfjSendDao;
import com.sfpay.sypay.msp.process.ServiceHolder;
import com.sfpay.sypay.msp.process.service.IFxPrefSendTaskService;
import com.sfpay.sypay.msp.valueobject.dto.CourierSfjSend;
import com.sfpay.sypay.order.service.IPrefBusinessService;
import com.sfpay.sypay.order.valueobject.dto.PrefBusinessRequest;
/**
* 非线支付,给收派员送顺丰金
*
* @author sfhq703
*
*/
@Service
public class PrefSendTaskServiceImpl implements IFxPrefSendTaskService {
private Logger logger = LoggerFactory
.getLogger(PrefSendTaskServiceImpl.class);
/**
* 字段说明:批次个数
*/
private static final int BATCH_COUNT = 800;
/**
* 调用订单系统单次发送条数
*/
private int one_send_size = 0;
/**
* 发送队列
*/
private BlockingQueue<List<PrefBusinessRequest>> senderQueue = null;
@Resource
private ICourierSfjSendDao courierSfjSendDao;
@Resource
private IPrefBusinessService prefBusinessService;
private AtomicBoolean isTodayTaskCompletePref = new AtomicBoolean(true);
private AtomicBoolean isExecutePref = new AtomicBoolean(true);
/**
* 非线支付,给收派员送顺丰金实现构造函数
*/
public PrefSendTaskServiceImpl() {
int sender_thread = Integer.parseInt(Property
.getProperty("MSP_PRESENT_SENDER_THREAD_CNT"));
one_send_size = Integer.parseInt(Property
.getProperty("MSP_PRESENT_ONE_SEND_SIZE"));
senderQueue = new LinkedBlockingQueue<List<PrefBusinessRequest>>(
Integer.parseInt(Property
.getProperty("MSP_PRESENT_DATA_QUEUE_SIZE")));
ExecutorService exec = Executors.newFixedThreadPool(sender_thread);// 创建一个定长线程池,可控制线程最大并发数,超出的线程会在队列中等待
for (int i = 0; i < sender_thread; i++) {
exec.submit(new PrefSenderRun(senderQueue,
new ServiceHolder<IPrefBusinessService>() {
public IPrefBusinessService getService() {
return prefBusinessService;
}
}, new ServiceHolder<ICourierSfjSendDao>() {
public ICourierSfjSendDao getService() {
return courierSfjSendDao;
}
}, isTodayTaskCompletePref, i, isExecutePref));
}
}
/**
* 方法说明:非线支付,给收派员送顺丰金任务实现
*
* @return
*/
@Override
public void presentPrefSend() {
if (!isExecutePref.get()) {
logger.info("非线支付,给收派员送顺丰金任务执行中………………………………");
if (isTodayTaskCompletePref.get() && senderQueue.isEmpty()) {
isExecutePref.set(true);
logger.info("********************非线支付,给收派员送顺丰金线任务执行列表以被线程取完,可继续执行本次个调度********************");
} else {
return;
}
}
isExecutePref.set(false);
isTodayTaskCompletePref.set(false);
int pgIndex = 0;
List<CourierSfjSend> oneBatchList = new ArrayList<CourierSfjSend>();
List<CourierSfjSend> allDataList = null;
try {
courierSfjSendDao.updateCourierSfjSendStatus(
StatusCode.SENDING.name(), StatusCode.INIT.name(), null);
allDataList = courierSfjSendDao.findCourierSfjSendList(pgIndex,
BATCH_COUNT);
} catch (Exception e) {
logger.info("非线支付,给收派员送顺丰金任务,初始化数据异常:", e);
}
if (allDataList == null || allDataList.isEmpty()) {
isExecutePref.set(true);
isTodayTaskCompletePref.set(true);
logger.info("非线支付,给收派员送顺丰金任务,没有需要发送的数据");
return;
}
while (allDataList != null && !allDataList.isEmpty()) {
try {
for (CourierSfjSend awardResult : allDataList) {
oneBatchList.add(awardResult);
// 每ONE_SEND_SIZE次调用一次订单接口
if (oneBatchList.size() > one_send_size) {
workOneJob(oneBatchList);
oneBatchList.clear();
}
}
// 没有凑足 ONE_SEND_SIZE,剩下的直接放入发送队列吧
if (!oneBatchList.isEmpty()) {
workOneJob(oneBatchList);
oneBatchList.clear();
}
} catch (Exception e) {
logger.error("非线支付,给收派员送顺丰金异常", e);
throw new RuntimeException(e);
}
try {
allDataList = courierSfjSendDao.findCourierSfjSendList(pgIndex,
BATCH_COUNT);
} catch (Exception e) {
logger.info("非线支付,给收派员送顺丰金任务,取数据异常:", e);
}
}
isTodayTaskCompletePref.set(true);
}
/**
* 执行赠送逻辑
*
* @param resultList
* @throws Exception
* @return 返回赠送失败id
*/
public void workOneJob(List<CourierSfjSend> resultList) throws Exception {
List<PrefBusinessRequest> sendParamList = new ArrayList<PrefBusinessRequest>();
workStatusUpdate(resultList);
try {
// 批次更新发放状态
// 构造请求报文,调用订单系统发放奖品
for (CourierSfjSend courierSfjSend : resultList) {
// TODO封装数据
PrefBusinessRequest prefBusiness = new PrefBusinessRequest();
prefBusiness.setAmount(courierSfjSend.getSfjinAmt());
// prefBusiness.setActivityId();
prefBusiness.setCcy(CcyType.SFP);
prefBusiness.setLoginName(courierSfjSend.getMobile());
prefBusiness.setMemberNo(courierSfjSend.getMemberNo());
prefBusiness.setMarketId(courierSfjSend.getId() + "");
prefBusiness.setMerchantNo(Property
.getProperty("FX_PREF_MERCHANT_NO"));
prefBusiness.setOutBusinessNo(courierSfjSend.getId() + "");
prefBusiness.setSendMerchantNo(Property
.getProperty("FX_SND_MERCHANT_NO"));
prefBusiness.setBusinessType("FX");
prefBusiness.setPrefType(TradeType.POINT_PREF);
// prefBusiness.setOrderAmont();
// prefBusiness.setCostEntity();
prefBusiness.setRemark("电子支付奖励");
// prefBusiness.setCostSubjectsNo();
// prefBusiness.setCostSubjectsName();
sendParamList.add(prefBusiness);
}
if (!sendParamList.isEmpty()) {
logger.info(String.format("非线支付,给收派员送顺丰金放入发送队列,当前队列长度%s",
senderQueue.size()));
senderQueue.put(sendParamList);
}
} catch (Exception e) {
logger.error("非线支付,给收派员送顺丰金异常", e);
}
}
/**
* 更新赠送的明细
*/
private void workStatusUpdate(List<CourierSfjSend> courierSfjSends) {
try {
List<Long> list = new ArrayList<Long>();
for (CourierSfjSend courierSfjSend : courierSfjSends) {
list.add(courierSfjSend.getId());
}
courierSfjSendDao.updateCourierSfjSendStatus(
StatusCode.INIT.name(), StatusCode.SENDING.name(), list);
} catch (Exception e) {
logger.error(
"courierSfjSendDao.updateCourierSfjSendStatus 修改非线支付,给收派员送顺丰金状态失败",
e);
}
}
}
- msp.zip (123.8 KB)
- 下载次数: 0
相关推荐
Java多线程是Java编程语言中一个非常重要的概念,它允许开发者在一个程序中创建多个执行线程并行运行,以提高程序的执行效率和响应速度。在Java中,线程的生命周期包含五个基本状态,分别是新建状态(New)、就绪...
### Java多线程操作数据库:深入解析与应用 在当今高度并发的应用环境中,Java多线程技术被广泛应用于处理数据库操作,以提升系统的响应速度和处理能力。本文将基于一个具体的Java多线程操作数据库的应用程序,深入...
Java多线程设计模式上传文件Java多线程设计模式上传文件Java多线程设计模式上传文件Java多线程设计模式上传文件Java多线程设计模式上传文件Java多线程设计模式上传文件Java多线程设计模式上传文件Java多线程设计模式...
Java多线程是Java编程中的重要概念,它允许程序同时执行多个任务,极大地提升了程序的效率和性能。在Java中,实现多线程有两种主要方式:通过实现Runnable接口或者继承Thread类。本案例将深入探讨Java多线程中的关键...
Java多线程是Java编程中的一个重要概念,它允许程序同时执行多个任务,提高了程序的效率和响应速度。在Java中,实现多线程有两种主要方式:继承Thread类和实现Runnable接口。 1. 继承Thread类: 当我们创建一个新...
Java多线程是Java编程中的重要概念,尤其在如今的多核处理器环境下,理解并熟练掌握多线程技术对于提高程序性能和响应速度至关重要。本资料详细讲解了Java多线程的原理,并提供了丰富的实战代码,非常适合Java初学者...
### Java多线程分页查询知识点详解 #### 一、背景与需求分析 在实际的软件开发过程中,尤其是在处理大量数据时,如何高效地进行数据查询成为了一个关键问题。例如,在一个用户众多的社交平台上,当用户需要查看...
《汪文君JAVA多线程编程实战》是一本专注于Java多线程编程的实战教程,由知名讲师汪文君倾力打造。这本书旨在帮助Java开发者深入理解和熟练掌握多线程编程技术,提升软件开发的效率和质量。在Java平台中,多线程是...
java多线程PPT 多线程基本概念 创建线程的方式 线程的挂起与唤醒 多线程问题
Java多线程读大文件 java多线程写文件:多线程往队列中写入数据
Java多线程机制是Java编程中至关重要的一部分,它允许程序同时执行多个任务,提升应用程序的效率和响应性。以下是对各个知识点的详细说明: 9.1 Java中的线程: Java程序中的线程是在操作系统级别的线程基础上进行...
在本文中,我们将深入浅出Java多线程编程的世界,探索多线程编程的基本概念、多线程编程的优点、多线程编程的缺点、多线程编程的应用场景、多线程编程的实现方法等内容。 一、多线程编程的基本概念 多线程编程是指...
在Java编程中,多线程并发是提升程序执行效率、充分利用多核处理器资源的重要手段。本文将基于"java 多线程并发实例"这个主题,深入探讨Java中的多线程并发概念及其应用。 首先,我们要了解Java中的线程。线程是...
《JAVA多线程教学演示系统》是一篇深入探讨JAVA多线程编程的论文,它针对教育领域中的教学需求,提供了一种生动、直观的演示方式,帮助学生更好地理解和掌握多线程技术。这篇论文的核心内容可能包括以下几个方面: ...
本项目以"java多线程实现大批量数据导入源码"为题,旨在通过多线程策略将大量数据切分,并进行并行处理,以提高数据处理速度。 首先,我们需要理解Java中的线程机制。Java通过`Thread`类来创建和管理线程。每个线程...
综上所述,"java多线程查询数据库"是一个涉及多线程技术、线程池管理、并发控制、分页查询等多个方面的复杂问题。通过理解和掌握这些知识点,我们可以有效地提高数据库操作的效率和系统的响应速度。
《Java多线程编程实战指南》这本书深入浅出地讲解了Java多线程的核心概念和实战技巧,分为核心篇和设计模式篇,旨在帮助开发者掌握并应用多线程技术。 1. **线程基础** - **线程的创建**:Java提供了两种创建线程...
这份“JAVA多线程编程技术PDF”是学习和掌握这一领域的经典资料,涵盖了多线程的全部知识点。 首先,多线程的核心概念包括线程的创建与启动。在Java中,可以通过实现Runnable接口或继承Thread类来创建线程。创建后...
Java多线程编程是Java开发中的重要组成部分,它允许程序同时执行多个任务,极大地提高了程序的效率和响应性。在Java中,多线程主要通过继承Thread类或实现Runnable接口来实现。本教程《Java多线程编程核心技术》将...
Java多线程编程实战指南(核心篇) 高清pdf带目录 随着现代处理器的生产工艺从提升处理器主频频率转向多核化,即在一块芯片上集成多个处理器内核(Core),多核处理器(Multicore Processor)离我们越来越近了――如今...