Skip to content

Commit

Permalink
- 修复sqlite存储下订单重复发货
Browse files Browse the repository at this point in the history
- 数据库增加事务控制
- 增加
  - /apl so [订单编号] 用于手动发货订单
  - /apl info [订单编号] 查询订单状态
  • Loading branch information
meteorOSS committed Jan 3, 2024
1 parent 53f4467 commit 3c64447
Show file tree
Hide file tree
Showing 12 changed files with 362 additions and 70 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.meteor</groupId>
<artifactId>AifadianPay</artifactId>
<version>3.3-SNAPSHOT</version>
<version>3.4-SNAPSHOT</version>
<packaging>jar</packaging>

<name>AifadianPay</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void success(PackHttpResponse packHttpResponse) {

@Override
public void fail(Exception e) {

e.printStackTrace();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.gson.annotations.SerializedName;

public class AfdOrderReq {
@SerializedName("page")

private Integer page;
@SerializedName("out_trade_no")
private String out_trade_no;
Expand All @@ -12,11 +12,19 @@ public AfdOrderReq(Integer page) {
this.page = page;
}

public AfdOrderReq(Integer page, String out_trade_no) {
this.page = page;
public AfdOrderReq(String out_trade_no) {
this.out_trade_no = out_trade_no;
}

/**
* 当为0时防止被序列化以查询特定编号订单
* @return
*/
@SerializedName("page")
public Integer getPage(){
return page==0?null:page;
}

public void setPage(Integer page) {
this.page = page;
}
Expand All @@ -25,9 +33,6 @@ public void setOut_trade_no(String out_trade_no) {
this.out_trade_no = out_trade_no;
}

public Integer getPage() {
return page;
}

public String getOut_trade_no() {
return out_trade_no;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ public void init() {
register(new HelpCmd(AifadianPay.INSTANCE));
register(new PingCmd(AifadianPay.INSTANCE));
register(new DebugCmd(AifadianPay.INSTANCE));
register(new InfoCmd(AifadianPay.INSTANCE));
register(new SendOutCmd(AifadianPay.INSTANCE));
}
}
78 changes: 78 additions & 0 deletions src/main/java/com/meteor/aifadianpay/command/sub/InfoCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.meteor.aifadianpay.command.sub;

import com.meteor.aifadianpay.AifadianPay;
import com.meteor.aifadianpay.afdian.AfadianApi;
import com.meteor.aifadianpay.afdian.request.AfdOrderReq;
import com.meteor.aifadianpay.afdian.response.Order;
import com.meteor.aifadianpay.afdian.response.Orders;
import com.meteor.aifadianpay.afdian.response.QueryOrderResponse;
import com.meteor.aifadianpay.command.SubCmd;
import com.meteor.aifadianpay.httputil.callback.AsyncHttpResponseCallBack;
import com.meteor.aifadianpay.httputil.response.PackHttpResponse;
import com.meteor.aifadianpay.util.BaseConfig;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class InfoCmd extends SubCmd {
public InfoCmd(JavaPlugin plugin) {
super(plugin);
}

@Override
public String label() {
return "info";
}

@Override
public String getPermission() {
return "afadian.admin";
}

@Override
public boolean playersOnly() {
return false;
}

@Override
public String usage() {
return null;
}

@Override
public void perform(CommandSender p0, String[] p1) {

if(p1.length<2) return;

AfadianApi.afadianApi.queryOrders(new AfdOrderReq(p1[1]), new AsyncHttpResponseCallBack() {
@Override
public void success(PackHttpResponse packHttpResponse) {
QueryOrderResponse queryOrderResponse = AfadianApi.afadianApi.toOrders(packHttpResponse);
List<Order> orderList = queryOrderResponse.getOrders().getOrderList();
if(orderList.isEmpty()){
p0.sendMessage(BaseConfig.STORE.getMessageBox().getMessage(null,"message.order-info.notExistOrder"));
}else {
Order order = orderList.get(0);
Map<String,String> params = new HashMap<>();
params.put("@trade_no@",order.getOutTradeNo());
params.put("@state@", AifadianPay.INSTANCE.getiStorage().isHandleOrder(order.getOutTradeNo())
?"§a已处理":"§c未处理");
params.put("@remark@",order.getRemark()==null?"§c未留言":order.getRemark());
params.put("@plan@",order.getPlanTitle());
params.put("@price@",order.getTotalAmount());

BaseConfig.STORE.getMessageBox().getMessageList(params,"message.order-info.state")
.forEach(s->p0.sendMessage(s));
}
}

@Override
public void fail(Exception e) {

}
});
}
}
96 changes: 96 additions & 0 deletions src/main/java/com/meteor/aifadianpay/command/sub/SendOutCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.meteor.aifadianpay.command.sub;

import com.meteor.aifadianpay.AifadianPay;
import com.meteor.aifadianpay.afdian.AfadianApi;
import com.meteor.aifadianpay.afdian.request.AfdOrderReq;
import com.meteor.aifadianpay.afdian.response.Order;
import com.meteor.aifadianpay.afdian.response.QueryOrderResponse;
import com.meteor.aifadianpay.command.SubCmd;
import com.meteor.aifadianpay.httputil.callback.AsyncHttpResponseCallBack;
import com.meteor.aifadianpay.httputil.response.PackHttpResponse;
import com.meteor.aifadianpay.util.BaseConfig;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 手动发货订单
*/
public class SendOutCmd extends SubCmd {
public SendOutCmd(JavaPlugin plugin) {
super(plugin);
}

@Override
public String label() {
return "so";
}

@Override
public String getPermission() {
return "afadian.use.so";
}

@Override
public boolean playersOnly() {
return false;
}

@Override
public String usage() {
return null;
}

@Override
public void perform(CommandSender p0, String[] p1) {

if(p1.length<2) return;

AfadianApi.afadianApi.queryOrders(new AfdOrderReq(p1[1]), new AsyncHttpResponseCallBack() {
@Override
public void success(PackHttpResponse packHttpResponse) {
QueryOrderResponse queryOrderResponse = AfadianApi.afadianApi.toOrders(packHttpResponse);
List<Order> orderList = queryOrderResponse.getOrders().getOrderList();
if(orderList.isEmpty()){
p0.sendMessage(BaseConfig.STORE.getMessageBox().getMessage(null,"message.order-info.notExistOrder"));
}else {
Order order = orderList.get(0);
if(p0 instanceof Player){
Player player = (Player) p0;
if(!player.isOp() && (order.getRemark()==null|| !order.getRemark().equalsIgnoreCase(player.getName()))){
player.sendMessage(BaseConfig.STORE.getMessageBox().getMessage(null,"message.send-out.remark-error"));
return;
}
}

if(AifadianPay.INSTANCE.getiStorage().isHandleOrder(order.getOutTradeNo())){
p0.sendMessage(BaseConfig.STORE.getMessageBox().getMessage(null,"message.send-out.repeat"));
}else {
if(order.getRemark()==null|| Bukkit.getPlayerExact(order.getRemark())==null){
p0.sendMessage(BaseConfig.STORE.getMessageBox().getMessage(null,"message.send-out.not-online"));
return;
}
if(AifadianPay.INSTANCE.getiStorage().handeOrder(order,true)){
p0.sendMessage(BaseConfig.STORE.getMessageBox().getMessage(null,"message.send-out.success"));
}else {
p0.sendMessage(BaseConfig.STORE.getMessageBox().getMessage(null,"message.send-out.fail"));
}
}



}
}

@Override
public void fail(Exception e) {
e.printStackTrace();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public class FilterManager {
* @return
*/
public static List<Order> meet(List<Order> orders){


for (OrderFilter filter : filters) {
orders = filter.meet(orders);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/meteor/aifadianpay/storage/IStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IStorage {
/**
* 处理订单
*/
void handeOrder(Order order,boolean b);
boolean handeOrder(Order order,boolean b);

/**
* 获取玩家捐赠总数
Expand All @@ -18,4 +18,6 @@ public interface IStorage {
*/
int queryPlayerDonate(String p);

boolean isHandleOrder(String tradeNo);

}
Loading

0 comments on commit 3c64447

Please sign in to comment.