25 changed files with 693 additions and 200 deletions
@ -1,19 +1,20 @@ |
|||
package com.base.springcloud.base; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.experimental.Accessors; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Data |
|||
@NoArgsConstructor |
|||
@Accessors(chain = true) |
|||
public class ReportResult<T> { |
|||
|
|||
//返回的数据
|
|||
private T data; |
|||
private List<T> data; |
|||
|
|||
public ReportResult(T data) { |
|||
public ReportResult(List<T> data) { |
|||
this.data = data; |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,35 @@ |
|||
package com.base.springcloud.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.File; |
|||
|
|||
@Data |
|||
public class MerchantConfigRspDTO { |
|||
|
|||
private File certFile; |
|||
|
|||
private String appId; |
|||
|
|||
private String appKey; |
|||
|
|||
private String certPath; |
|||
|
|||
private String merchantId; |
|||
|
|||
private String merchantName; |
|||
|
|||
private String cityStoreName; |
|||
|
|||
private String storeBrandName; |
|||
|
|||
private String signType; |
|||
|
|||
private String privateKey; |
|||
|
|||
private String deviceInfo; |
|||
|
|||
private String spbillCreateIp; |
|||
|
|||
private String notifyUrl; |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
package com.base.springcloud.handle; |
|||
|
|||
import com.base.springcloud.entity.Order; |
|||
import com.base.springcloud.service.PaymentService; |
|||
import org.springframework.amqp.rabbit.annotation.RabbitListener; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
@Component |
|||
public class RBSQueueHandler { |
|||
|
|||
@Autowired |
|||
private PaymentService paymentService; |
|||
|
|||
@RabbitListener(queues = "order_queue") |
|||
public void orderInfo(Order order) { |
|||
paymentService.queryOrder(order); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
package com.base.springcloud.schedule; |
|||
|
|||
import com.base.springcloud.service.PaymentService; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.scheduling.annotation.Scheduled; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Date; |
|||
|
|||
@Component |
|||
public class OrderTask { |
|||
|
|||
Logger logger = LoggerFactory.getLogger(OrderTask.class); |
|||
|
|||
@Autowired |
|||
private PaymentService paymentService; |
|||
|
|||
@Scheduled(cron = "0/10 * * * * ?") |
|||
public void syncOrderInfo(){ |
|||
paymentService.syncOrderInfo(new Date()); |
|||
} |
|||
} |
|||
@ -1,9 +1,27 @@ |
|||
package com.base.springcloud.service; |
|||
|
|||
import com.base.springcloud.bo.OrderBO; |
|||
import com.base.springcloud.entity.Order; |
|||
|
|||
import java.util.Date; |
|||
|
|||
public interface PaymentService { |
|||
|
|||
// 下单
|
|||
/** |
|||
* 下单 |
|||
* @param orderBO |
|||
* @return |
|||
*/ |
|||
String placeOrder(OrderBO orderBO); |
|||
|
|||
/** |
|||
* 订单查询 |
|||
*/ |
|||
void syncOrderInfo(Date date); |
|||
|
|||
/** |
|||
* 订单信息同步 |
|||
* @param order |
|||
*/ |
|||
void queryOrder(Order order); |
|||
} |
|||
|
|||
@ -1,14 +1,118 @@ |
|||
package com.base.springcloud.service.imp; |
|||
|
|||
import com.base.springcloud.bo.MerchantConfigBO; |
|||
import com.base.springcloud.dao.MerchantConfigMapper; |
|||
import com.base.springcloud.dto.MerchantConfigRspDTO; |
|||
import com.base.springcloud.entity.MerchantConfig; |
|||
import com.base.springcloud.service.MerchantService; |
|||
import com.base.springcloud.util.FtpUtil; |
|||
import org.springframework.beans.BeanUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.io.File; |
|||
import java.io.FileInputStream; |
|||
import java.io.FileNotFoundException; |
|||
import java.io.InputStream; |
|||
import java.util.List; |
|||
import java.util.Optional; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Service |
|||
public class MerchantServiceImp implements MerchantService { |
|||
|
|||
@Autowired |
|||
private MerchantConfigMapper merchantConfigMapper; |
|||
|
|||
@Autowired |
|||
private FtpUtil ftpUtil; |
|||
|
|||
/** |
|||
* 支付信息配置 |
|||
* @param merchantConfigBO |
|||
*/ |
|||
@Override |
|||
public void paymentConfigure(MerchantConfigBO merchantConfigBO) { |
|||
// 证书上传服务器
|
|||
String certPath = uplodWecPayCert(merchantConfigBO.getMerchantId(),merchantConfigBO.getCertfile()); |
|||
// 商户支付信息保存
|
|||
merchantConfigBO.setCertPath(certPath); |
|||
MerchantConfig merchantConfig = new MerchantConfig(); |
|||
BeanUtils.copyProperties(merchantConfig,merchantConfigBO); |
|||
merchantConfigMapper.insert(merchantConfig); |
|||
} |
|||
|
|||
/** |
|||
* 支付信息配置删除 |
|||
* @param merchantId |
|||
*/ |
|||
@Override |
|||
public void removeMerchantConfig(String merchantId) { |
|||
int count = merchantConfigMapper.removeMerchantConfig(merchantId); |
|||
if(count > 0) return; |
|||
// TODO 抛业务异常
|
|||
} |
|||
|
|||
/** |
|||
* 支付信息修改 |
|||
* @param merchantConfigBO |
|||
*/ |
|||
@Override |
|||
public void updateMerchantConfig(MerchantConfigBO merchantConfigBO) { |
|||
// 证书上传服务器
|
|||
String certPath = uplodWecPayCert(merchantConfigBO.getMerchantId(),merchantConfigBO.getCertfile()); |
|||
// 商户支付信息保存
|
|||
merchantConfigBO.setCertPath(certPath); |
|||
MerchantConfig merchantConfig = new MerchantConfig(); |
|||
BeanUtils.copyProperties(merchantConfig,merchantConfigBO); |
|||
int count = merchantConfigMapper.updateMerchantConfig(merchantConfig); |
|||
if(count > 0) return; |
|||
// TODO 抛业务异常
|
|||
} |
|||
|
|||
/** |
|||
* 支付信息配置查询 |
|||
* @param merchantConfigBO |
|||
* @return |
|||
*/ |
|||
@Override |
|||
public List<MerchantConfigBO> queryMerchantConfig(MerchantConfigBO merchantConfigBO) { |
|||
MerchantConfig merchantConfig = new MerchantConfig(); |
|||
BeanUtils.copyProperties(merchantConfig,merchantConfigBO); |
|||
List<MerchantConfig> merchantConfigList = merchantConfigMapper.queryMerchantConfig(merchantConfig); |
|||
if(!Optional.ofNullable(merchantConfigList).isPresent()){ |
|||
// TODO 抛出业务异常
|
|||
} |
|||
List<MerchantConfigBO> merchantConfigBOList = merchantConfigList.stream().map(t -> { |
|||
MerchantConfigBO result = new MerchantConfigBO(); |
|||
BeanUtils.copyProperties(result, t); |
|||
return result; |
|||
}).collect(Collectors.toList()); |
|||
return merchantConfigBOList; |
|||
} |
|||
|
|||
/** |
|||
* 证书上传服务器 |
|||
* @param mchId |
|||
* @param certfile |
|||
* @return |
|||
*/ |
|||
private String uplodWecPayCert(String mchId,File certfile){ |
|||
//获取文件名
|
|||
String fileName = certfile.getName(); |
|||
//获取文件的后缀名
|
|||
String suffixName = fileName.substring(fileName.lastIndexOf(".")); |
|||
fileName = mchId + suffixName; |
|||
//上传的文件名也需要加上后缀,不然虚拟机不知道文件格式
|
|||
try{ |
|||
InputStream inputStream = new FileInputStream(certfile); |
|||
Boolean flag = ftpUtil.uploadFile(fileName, inputStream); |
|||
if (flag == true) { |
|||
return ftpUtil.FTP_BASEPATH + fileName; |
|||
} |
|||
}catch (FileNotFoundException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return null; |
|||
} |
|||
} |
|||
@ -1,9 +1,16 @@ |
|||
package com.base.springcloud.service; |
|||
|
|||
import com.base.springcloud.bo.OrderBO; |
|||
import com.base.springcloud.entity.Order; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
public interface OrderService { |
|||
|
|||
// 订单登记
|
|||
void registerOrder(Order order); |
|||
void registerOrder(OrderBO orderBO); |
|||
|
|||
// 查询订单
|
|||
List<OrderBO> queryOrder(Date date); |
|||
} |
|||
|
|||
@ -0,0 +1,71 @@ |
|||
package com.base.springcloud.util; |
|||
|
|||
import org.apache.commons.net.ftp.FTPClient; |
|||
import org.apache.commons.net.ftp.FTPReply; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.io.IOException; |
|||
import java.io.InputStream; |
|||
|
|||
@Component |
|||
public class FtpUtil { |
|||
|
|||
Logger logger = LoggerFactory.getLogger(FtpUtil.class); |
|||
|
|||
//ftp服务器ip地址
|
|||
@Value("${ftp.ftp_ip}") |
|||
private static String FTP_ADDRESS; |
|||
//端口号
|
|||
@Value("${ftp.ftp_port}") |
|||
private static int FTP_PORT = 21; |
|||
//用户名
|
|||
@Value("${ftp.ftp_username}") |
|||
private static String FTP_USERNAME; |
|||
//密码
|
|||
@Value("${ftp.ftp_password}") |
|||
private static String FTP_PASSWORD; |
|||
|
|||
//路径都是/home/加上用户名
|
|||
@Value("${ftp.ftp_basepath}") |
|||
public final String FTP_BASEPATH = "/home/huanglong"; |
|||
|
|||
|
|||
// 文件上传
|
|||
public boolean uploadFile(String originFileName, InputStream input) { |
|||
//这是最开始引入的依赖里的方法
|
|||
FTPClient ftp = new FTPClient(); |
|||
ftp.setControlEncoding("utf-8"); |
|||
try { |
|||
int reply; |
|||
ftp.connect(FTP_ADDRESS, FTP_PORT);// 连接FTP服务器
|
|||
ftp.login(FTP_USERNAME, FTP_PASSWORD);// 登录
|
|||
reply = ftp.getReplyCode();//连接成功会的到一个返回状态码
|
|||
System.out.println(reply);//可以输出看一下是否连接成功
|
|||
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);//设置文件类型
|
|||
ftp.changeWorkingDirectory(FTP_BASEPATH);//修改操作空间
|
|||
//对了这里说明一下你所操作的文件夹必须要有可读权限,chomd 777 文件夹名//这里我就是用的我的home文件夹
|
|||
ftp.storeFile(originFileName, input); |
|||
if (!FTPReply.isPositiveCompletion(reply)) { |
|||
logger.warn("ftp connect fail...."); |
|||
ftp.disconnect(); |
|||
return false; |
|||
} |
|||
input.close(); |
|||
ftp.logout(); |
|||
return true; |
|||
}catch (Exception e){ |
|||
e.printStackTrace(); |
|||
}finally { |
|||
if (ftp.isConnected()) { |
|||
try { |
|||
ftp.disconnect(); |
|||
} catch (IOException ioe) { |
|||
} |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue