Commit 694f7900 by lihui.wang

将 payaccountplatform list 转换为 object

parent ea49182b
......@@ -184,8 +184,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
......
......@@ -2,6 +2,8 @@ package com.freemud.pay.job.dao.repository;
import com.freemud.pay.job.dao.dbModel.PayPlatformAccountDM;
import java.util.List;
/**
* All rights Reserved, Designed By www.freemud.cn
*
......@@ -15,5 +17,5 @@ import com.freemud.pay.job.dao.dbModel.PayPlatformAccountDM;
*/
public interface PayPlatformAccountRepository extends IBaseRepository{
PayPlatformAccountDM selectByPartnerId(Integer partnerId);
List<PayPlatformAccountDM> selectByPartnerId(Integer partnerId);
}
......@@ -8,6 +8,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* All rights Reserved, Designed By www.freemud.cn
*
......@@ -33,7 +35,7 @@ public class PayPlatformAccountRepositoryImpl extends BaseRepositoryImpl impleme
@Override
public PayPlatformAccountDM selectByPartnerId(Integer partnerId) {
public List<PayPlatformAccountDM> selectByPartnerId(Integer partnerId) {
return payPlatformAccountDMMapper.selectByPartnerId(partnerId);
}
}
\ No newline at end of file
package com.freemud.pay.job.entity.dto;
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title:
* @Package com.freemud.pay
* @Description:
* @author: lihui.wang
* @date:
* @Copyright: 2017 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
public class PayPlatformAcountKey {
private Integer partnerId;
private String storeId;
private String platform;
public Integer getPartnerId() {
return partnerId;
}
public void setPartnerId(Integer partnerId) {
this.partnerId = partnerId;
}
public String getStoreId() {
return storeId;
}
public void setStoreId(String storeId) {
this.storeId = storeId;
}
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
@Override
public String toString() {
return "PayPlatformAcountKey{" +
"partnerId=" + partnerId +
", storeId='" + storeId + '\'' +
", platform='" + platform + '\'' +
'}';
}
}
\ No newline at end of file
......@@ -2,6 +2,8 @@ package com.freemud.pay.job.service;
import com.freemud.pay.job.dao.dbModel.PayPlatformAccountDM;
import java.util.List;
/**
* All rights Reserved, Designed By www.freemud.cn
*
......
......@@ -6,10 +6,11 @@ import com.freemud.pay.job.dao.dbModel.PayMessageDM;
import com.freemud.pay.job.dao.repository.IPayMessageRepository;
import com.freemud.pay.job.entity.BaseParam;
import com.freemud.pay.job.entity.PayMessage;
import com.freemud.pay.job.service.IMessageProcessor;
import com.freemud.pay.job.service.processorfactory.IMessageProcessor;
import com.freemud.pay.job.service.IPayMessageService;
import com.freemud.pay.job.service.MessageProcessorFactory;
import com.freemud.pay.job.service.processorfactory.MessageProcessorFactory;
import com.freemud.pay.job.service.IPayMessageActiveService;
import com.freemud.pay.job.service.util.SpringUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -44,6 +45,9 @@ public class PayMessageServiceImpl implements IPayMessageService {
@Autowired
IPayMessageActiveService iPayMessageActiveService;
@Autowired
private SpringUtil springUtil;
@Override
public void pushMessage(BaseParam baseParam) {
......@@ -60,6 +64,10 @@ public class PayMessageServiceImpl implements IPayMessageService {
//第一步:获取数据
List<PayMessageDM> payMessages=getPayMessages(baseParam);
if (payMessages.size()>0){
logger.info("获取payMessage数据成功");
}
for (PayMessageDM message :payMessages){
if (message.getPayMessageActiveId()<0)
......@@ -89,11 +97,14 @@ public class PayMessageServiceImpl implements IPayMessageService {
result = (processor == null)
? false
: processor.Process(payMessage);
logger.info("消息推送成功");
if (result){
logger.info("消息推送成功");
}
}
catch (Exception ex)
{
//Logger.Warn(string.Format("failed process #{0},exception:{1}", message.Id, ex));
ex.printStackTrace();
logger.error("消息推送失败");
}
......@@ -105,7 +116,7 @@ public class PayMessageServiceImpl implements IPayMessageService {
else
{
markMessageAsFailed(message);
logger.error("消息状态更新失败,状态码为-1");
logger.error("消息状态更新为1失败,状态码改为-1");
}
}
......
......@@ -2,10 +2,21 @@ package com.freemud.pay.job.service.impl;
import com.freemud.pay.job.dao.dbModel.PayPlatformAccountDM;
import com.freemud.pay.job.dao.repository.PayPlatformAccountRepository;
import com.freemud.pay.job.dao.repository.impl.PayMessageRepositoryImpl;
import com.freemud.pay.job.entity.PayMessage;
import com.freemud.pay.job.entity.dto.PayPlatformAcountKey;
import com.freemud.pay.job.service.IPayMessageService;
import com.freemud.pay.job.service.IPayPlatformAccountService;
import com.freemud.pay.job.service.util.EncryptionHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* All rights Reserved, Designed By www.freemud.cn
*
......@@ -20,12 +31,42 @@ import org.springframework.stereotype.Service;
@Service("iPayPlatformAccountService")
public class PayPlatformAccountServiceImpl implements IPayPlatformAccountService {
protected final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
PayPlatformAccountRepository payPlatformAccountRepository;
@Autowired
IPayMessageService iPayMessageService;
@Autowired
IPayPlatformAccountService iPayPlatformAccountService;
@Autowired
PayPlatformAcountKey payPlatformAcountKey;
@Autowired
PayMessage payMessage;
@Autowired
EncryptionHelper encryptionHelper;
@Override
public PayPlatformAccountDM getPayPlatformAccount(Integer partnerId) {
return payPlatformAccountRepository.selectByPartnerId(partnerId);
List<PayPlatformAccountDM> payPlatformAccountDMList = payPlatformAccountRepository.selectByPartnerId(partnerId);
payPlatformAcountKey.setPartnerId(iPayMessageService.selectByPrimaryKey(payMessage.getPayMessage().getId()).getPartnerid());
payPlatformAcountKey.setPlatform(iPayMessageService.selectByPrimaryKey(payMessage.getPayMessage().getId()).getPlatform());
payPlatformAcountKey.setStoreId(iPayMessageService.selectByPrimaryKey(payMessage.getPayMessage().getId()).getStore_id());
List<PayPlatformAccountDM> payPlatformAccountDMList1 = new ArrayList<>();
payPlatformAccountDMList.stream().forEach(p->{
if(p.getEnable() == true && p.getPlatform().equalsIgnoreCase(payPlatformAcountKey.getPlatform()) ){
if (p != null && p.getPassword() != null){
payPlatformAccountDMList1.add(p);
}
}
});
PayPlatformAccountDM payPlatformAccountDM = payPlatformAccountDMList1.get(0);
return payPlatformAccountDM;
}
}
\ No newline at end of file
package com.freemud.pay.job.service;
package com.freemud.pay.job.service.processorfactory;
import com.freemud.pay.job.entity.PayMessage;
import org.springframework.stereotype.Service;
......
package com.freemud.pay.job.service;
package com.freemud.pay.job.service.processorfactory;
import com.freemud.pay.job.dao.dbModel.PayMessageActiveDM;
import com.freemud.pay.job.dao.dbModel.PayMessageDM;
import com.freemud.pay.job.service.impl.AliFuWuChuangSingleMessageSender;
import com.freemud.pay.job.service.processorfactory.processimpl.AliFuWuChuangSingleMessageSender;
import com.freemud.pay.job.service.util.SpringUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* All rights Reserved, Designed By www.freemud.cn
......@@ -18,16 +21,19 @@ import org.apache.commons.lang.StringUtils;
*/
public class MessageProcessorFactory {
protected static final Logger logger = LoggerFactory.getLogger(MessageProcessorFactory.class);
public static IMessageProcessor GetMessageProcessor(PayMessageDM messasge, PayMessageActiveDM active)
{
if (active == null
|| StringUtils.isEmpty(active.getAction()))
{
logger.info("推送action为空");
return null;
}
String s = active.getAction().toLowerCase();
if ("ali.single.send".equals(s)) {
return new AliFuWuChuangSingleMessageSender();
return SpringUtil.getBean(AliFuWuChuangSingleMessageSender.class);
} else {
return null;
}
......
package com.freemud.pay.job.service.impl;
package com.freemud.pay.job.service.processorfactory.processimpl;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
......@@ -7,11 +7,18 @@ import com.alipay.api.response.AlipayMobilePublicMessageSingleSendResponse;
import com.freemud.pay.job.config.AliPayConfig;
import com.freemud.pay.job.dao.dbModel.PayPlatformAccountDM;
import com.freemud.pay.job.entity.PayMessage;
import com.freemud.pay.job.entity.dto.PayPlatformAcountKey;
import com.freemud.pay.job.service.*;
import com.freemud.pay.job.service.processorfactory.IMessageProcessor;
import com.freemud.pay.job.service.util.EncryptionHelper;
import com.freemud.pay.job.service.util.InterrprentUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* All rights Reserved, Designed By www.freemud.cn
......@@ -24,12 +31,13 @@ import org.springframework.beans.factory.annotation.Autowired;
* @Copyright: 2017 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
@Component
public class AliFuWuChuangSingleMessageSender implements IMessageProcessor {
protected final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
IPayPlatformAccountService IPayPlatformAccountService;
IPayPlatformAccountService iPayPlatformAccountService;
@Autowired
IPayMessageService iPayMessageService;
......@@ -46,18 +54,45 @@ public class AliFuWuChuangSingleMessageSender implements IMessageProcessor {
@Autowired
private InterrprentUtil interrprentUtil;
@Autowired
private EncryptionHelper encryptionHelper;
@Override
public Boolean Process(PayMessage payMessage) {
PayPlatformAccountDM payPlatformAccountDM = IPayPlatformAccountService.getPayPlatformAccount(payMessage.getPayMessage().getPartnerid());
logger.info("向第三方发送请求");
System.out.println(payMessage.getPayMessage().getPartnerid());
// List<PayPlatformAccountDM> payPlatformAccountDMList = iPayPlatformAccountService.getPayPlatformAccount(payMessage.getPayMessage().getPartnerid());
// PayPlatformAcountKey payPlatformAcountKey = new PayPlatformAcountKey();
// payPlatformAcountKey.setPartnerId(iPayMessageService.selectByPrimaryKey(payMessage.getPayMessage().getId()).getPartnerid());
// payPlatformAcountKey.setPlatform(iPayMessageService.selectByPrimaryKey(payMessage.getPayMessage().getId()).getPlatform());
// payPlatformAcountKey.setStoreId(iPayMessageService.selectByPrimaryKey(payMessage.getPayMessage().getId()).getStore_id());
// payPlatformAccountDMList.stream().forEach(p->{
// if(p.getEnable() == true && p.getPlatform().equalsIgnoreCase(payPlatformAcountKey.getPlatform()) ){
// PayPlatformAccountDM payPlatformAccountDM = payPlatformAccountDMList.get(0);
// if (payPlatformAccountDM != null && payPlatformAccountDM.getPassword() != null){
// payPlatformAccountDM.setPassword(encryptionHelper.Decode(payPlatformAccountDM.getPassword()));
// }
// return payPlatformAccountDM;
// }
//
// });
PayPlatformAccountDM payPlatformAccountDM = iPayPlatformAccountService.getPayPlatformAccount(payMessage.getPayMessage().getPartnerid());
System.out.println(payPlatformAccountDM.getId());
if (payPlatformAccountDM == null){
payMessage.setNoRetry(true);
logger.info("平台信息为空");
return false;
}
logger.info("获取第三方");
try {
AlipayClient alipayClient = new DefaultAlipayClient(config.getServerUrl(),payPlatformAccountDM.getPlatformappid(),payPlatformAccountDM.getCerfile());
System.out.println(config.getServerUrl()+" "+payPlatformAccountDM.getPlatformappid()+" "+payPlatformAccountDM.getCerfile());
logger.info("获取alipayClient成功");
AlipayMobilePublicMessageSingleSendRequest request = new AlipayMobilePublicMessageSingleSendRequest();
request.setBizContent(interrprentUtil.Interrprent(payMessage));
......@@ -66,22 +101,25 @@ public class AliFuWuChuangSingleMessageSender implements IMessageProcessor {
if (response.getCode() == "200"){
logger.info("消息推送成功");
return true;
}
else if (response.getCode() == "12007") //未关注
{
iPayMessageService.updateMessageTryTimes(3,payMessage.getPayMessage().getId());
logger.info("此消息推送重试次数为:3");
return false;
}
else
{
logger.error("消息推送状态码未知");
return false;
}
}catch (Exception e){
logger.error("消息推送失败");
return false;
}
return null;
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import com.freemud.pay.job.service.IStoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.*;
import java.text.SimpleDateFormat;
......@@ -23,6 +24,7 @@ import java.text.SimpleDateFormat;
* @Copyright: 2017 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
@Component
public class InterrprentUtil {
protected final Logger logger = LoggerFactory.getLogger(getClass());
......
package com.freemud.pay.job.service.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
/**
* Created by Dongguabai on 2018-06-22 14:44
*/
@Component
@Lazy(false)
public class SpringUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext;
//获取applicationContext
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
//通过name获取 Bean.
public static Object getBean(String name) {
return getApplicationContext().getBean(name);
}
//通过class获取Bean.
public static <T> T getBean(Class<T> clazz) {
return getApplicationContext().getBean(clazz);
}
//通过name,以及Clazz返回指定的Bean
public static <T> T getBean(String name, Class<T> clazz) {
return getApplicationContext().getBean(name, clazz);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if (SpringUtil.applicationContext == null) {
SpringUtil.applicationContext = applicationContext;
}
}
private SpringUtil() {
}
}
......@@ -21,7 +21,7 @@
<select id="getPayMessages" parameterType="Map" resultMap="BaseResultMap">
<![CDATA[
SELECT TOP 1000
SELECT TOP 10
a.[Id] ,
a.[PartnerId] ,
a.[FMId] ,
......@@ -43,7 +43,7 @@
p.Code AS PayCode
FROM [Freemud_ThirdParty].[dbo].[Pay_Message] a WITH ( NOLOCK )
INNER JOIN ${linkServer}zhuihu.dbo.Pay p WITH ( NOLOCK ) ON a.FMId = p.ZhuiHuOrderId
INNER JOIN zhuihu.dbo.[Partner] part WITH(NOLOCK) ON part.ID=a.PartnerId
INNER JOIN zhuihu.dbo.[Partner] part WITH(NOLOCK) ON part.ID=a.PartnerId where a.pay_message_active_id='100001433'
]]>
</select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment