2
2
3
3
import cn .binarywang .wx .miniapp .api .WxMaLiveGoodsService ;
4
4
import cn .binarywang .wx .miniapp .api .WxMaService ;
5
- import cn .binarywang .wx .miniapp .bean .WxMaLiveInfo ;
6
- import cn .binarywang .wx .miniapp .bean .WxMaLiveResult ;
5
+ import cn .binarywang .wx .miniapp .bean .live . WxMaLiveGoodInfo ;
6
+ import cn .binarywang .wx .miniapp .bean .live . WxMaLiveResult ;
7
7
import cn .binarywang .wx .miniapp .util .json .WxMaGsonBuilder ;
8
8
import com .google .common .base .Joiner ;
9
9
import com .google .common .collect .ImmutableMap ;
10
10
import com .google .gson .JsonArray ;
11
11
import com .google .gson .JsonObject ;
12
12
import lombok .AllArgsConstructor ;
13
- import me .chanjar .weixin .common .enums .WxType ;
14
- import me .chanjar .weixin .common .error .WxError ;
15
13
import me .chanjar .weixin .common .error .WxErrorException ;
16
14
import me .chanjar .weixin .common .util .json .GsonParser ;
17
15
@@ -32,27 +30,17 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
32
30
private final WxMaService wxMaService ;
33
31
34
32
@ Override
35
- public WxMaLiveResult addGoods (WxMaLiveInfo .Goods goods ) throws WxErrorException {
36
- Map <String , Object > map = new HashMap <>(2 );
37
- map .put ("goodsInfo" , goods );
38
- String responseContent = this .wxMaService .post (ADD_GOODS , WxMaGsonBuilder .create ().toJson (map ));
39
- JsonObject jsonObject = GsonParser .parse (responseContent );
40
- if (jsonObject .get ("errcode" ).getAsInt () != 0 ) {
41
- throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
42
- }
43
- return WxMaLiveResult .fromJson (jsonObject .toString ());
33
+ public WxMaLiveResult addGoods (WxMaLiveGoodInfo goods ) throws WxErrorException {
34
+ return WxMaLiveResult .fromJson (this .wxMaService .post (ADD_GOODS ,
35
+ WxMaGsonBuilder .create ().toJson (ImmutableMap .of ("goodsInfo" , goods ))));
44
36
}
45
37
46
38
@ Override
47
39
public boolean resetAudit (Integer auditId , Integer goodsId ) throws WxErrorException {
48
40
Map <String , Integer > map = new HashMap <>(4 );
49
41
map .put ("auditId" , auditId );
50
42
map .put ("goodsId" , goodsId );
51
- String responseContent = this .wxMaService .post (RESET_AUDIT_GOODS , WxMaGsonBuilder .create ().toJson (map ));
52
- JsonObject jsonObject = GsonParser .parse (responseContent );
53
- if (jsonObject .get ("errcode" ).getAsInt () != 0 ) {
54
- throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
55
- }
43
+ this .wxMaService .post (RESET_AUDIT_GOODS , WxMaGsonBuilder .create ().toJson (map ));
56
44
return true ;
57
45
}
58
46
@@ -62,33 +50,22 @@ public String auditGoods(Integer goodsId) throws WxErrorException {
62
50
map .put ("goodsId" , goodsId );
63
51
String responseContent = this .wxMaService .post (AUDIT_GOODS , WxMaGsonBuilder .create ().toJson (map ));
64
52
JsonObject jsonObject = GsonParser .parse (responseContent );
65
- if (jsonObject .get ("errcode" ).getAsInt () != 0 ) {
66
- throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
67
- }
68
53
return jsonObject .get ("auditId" ).getAsString ();
69
54
}
70
55
71
56
@ Override
72
57
public boolean deleteGoods (Integer goodsId ) throws WxErrorException {
73
58
Map <String , Integer > map = new HashMap <>(2 );
74
59
map .put ("goodsId" , goodsId );
75
- String responseContent = this .wxMaService .post (DELETE_GOODS , WxMaGsonBuilder .create ().toJson (map ));
76
- JsonObject jsonObject = GsonParser .parse (responseContent );
77
- if (jsonObject .get ("errcode" ).getAsInt () != 0 ) {
78
- throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
79
- }
60
+ this .wxMaService .post (DELETE_GOODS , WxMaGsonBuilder .create ().toJson (map ));
80
61
return true ;
81
62
}
82
63
83
64
@ Override
84
- public boolean updateGoods (WxMaLiveInfo . Goods goods ) throws WxErrorException {
65
+ public boolean updateGoods (WxMaLiveGoodInfo goods ) throws WxErrorException {
85
66
Map <String , Object > map = new HashMap <>(2 );
86
67
map .put ("goodsInfo" , goods );
87
- String responseContent = this .wxMaService .post (UPDATE_GOODS , WxMaGsonBuilder .create ().toJson (map ));
88
- JsonObject jsonObject = GsonParser .parse (responseContent );
89
- if (jsonObject .get ("errcode" ).getAsInt () != 0 ) {
90
- throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
91
- }
68
+ this .wxMaService .post (UPDATE_GOODS , WxMaGsonBuilder .create ().toJson (map ));
92
69
return true ;
93
70
}
94
71
@@ -97,21 +74,14 @@ public WxMaLiveResult getGoodsWareHouse(List<Integer> goodsIds) throws WxErrorEx
97
74
Map <String , Object > map = new HashMap <>(2 );
98
75
map .put ("goods_ids" , goodsIds );
99
76
String responseContent = this .wxMaService .post (GET_GOODS_WARE_HOUSE , WxMaGsonBuilder .create ().toJson (map ));
100
- JsonObject jsonObject = GsonParser .parse (responseContent );
101
- if (jsonObject .get ("errcode" ).getAsInt () != 0 ) {
102
- throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
103
- }
104
- return WxMaLiveResult .fromJson (jsonObject .toString ());
77
+ return WxMaLiveResult .fromJson (responseContent );
105
78
}
106
79
107
80
@ Override
108
81
public WxMaLiveResult getApprovedGoods (Integer offset , Integer limit , Integer status ) throws WxErrorException {
109
82
ImmutableMap <String , ? extends Serializable > params = ImmutableMap .of ("status" , status , "offset" , offset , "limit" , limit );
110
83
String responseContent = wxMaService .get (GET_APPROVED_GOODS , Joiner .on ("&" ).withKeyValueSeparator ("=" ).join (params ));
111
84
JsonObject jsonObject = GsonParser .parse (responseContent );
112
- if (jsonObject .get ("errcode" ).getAsInt () != 0 ) {
113
- throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
114
- }
115
85
JsonArray goodsArr = jsonObject .getAsJsonArray ("goods" );
116
86
if (goodsArr .size () > 0 ) {
117
87
for (int i = 0 ; i < goodsArr .size (); i ++) {
0 commit comments