mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-23 22:11:40 +08:00
优化门店查询列表的接口, for issue #17
This commit is contained in:
parent
c7a04d5fe4
commit
94b42ee9ae
@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||||
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
|
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
|
||||||
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;
|
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;
|
||||||
|
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 门店管理的相关接口代码
|
* 门店管理的相关接口代码
|
||||||
@ -36,7 +37,7 @@ public interface WxMpStoreService {
|
|||||||
* @param limit 返回数据条数,最大允许50,默认为20
|
* @param limit 返回数据条数,最大允许50,默认为20
|
||||||
* @throws WxErrorException
|
* @throws WxErrorException
|
||||||
*/
|
*/
|
||||||
List<WxMpStoreInfo> list(int begin, int limit) throws WxErrorException;
|
WxMpStoreListResult list(int begin, int limit) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
|
@ -67,7 +67,7 @@ public class WxMpStoreServiceImpl implements WxMpStoreService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WxMpStoreInfo> list(int begin, int limit)
|
public WxMpStoreListResult list(int begin, int limit)
|
||||||
throws WxErrorException {
|
throws WxErrorException {
|
||||||
String url = API_BASE_URL + "/getpoilist";
|
String url = API_BASE_URL + "/getpoilist";
|
||||||
JsonObject params = new JsonObject();
|
JsonObject params = new JsonObject();
|
||||||
@ -80,33 +80,25 @@ public class WxMpStoreServiceImpl implements WxMpStoreService {
|
|||||||
throw new WxErrorException(wxError);
|
throw new WxErrorException(wxError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return WxMpStoreListResult.fromJson(response).getBusinessList();
|
return WxMpStoreListResult.fromJson(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WxMpStoreInfo> listAll() throws WxErrorException {
|
public List<WxMpStoreInfo> listAll() throws WxErrorException {
|
||||||
int limit = 10;
|
int limit = 50;
|
||||||
String url = API_BASE_URL + "/getpoilist";
|
WxMpStoreListResult list = this.list(0, limit);
|
||||||
JsonObject params = new JsonObject();
|
List<WxMpStoreInfo> stores = list.getBusinessList();
|
||||||
params.addProperty("begin", 0);
|
if (list.getTotalCount() > limit) {
|
||||||
params.addProperty("limit", limit);//返回数据条数,最大允许50,默认为20
|
int begin = limit;
|
||||||
String response = this.wxMpService.post(url, params.toString());
|
WxMpStoreListResult followingList = this.list(begin, limit);
|
||||||
|
while (followingList.getBusinessList().size() > 0) {
|
||||||
WxError wxError = WxError.fromJson(response);
|
stores.addAll(followingList.getBusinessList());
|
||||||
if (wxError.getErrorCode() != 0) {
|
begin += limit;
|
||||||
throw new WxErrorException(wxError);
|
if (begin >= list.getTotalCount()) {
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
WxMpStoreListResult listResult = WxMpStoreListResult.fromJson(response);
|
followingList = this.list(begin, limit);
|
||||||
List<WxMpStoreInfo> stores = Lists
|
}
|
||||||
.newArrayList(listResult.getBusinessList());
|
|
||||||
if (listResult.getTotalCount() > limit) {
|
|
||||||
params = new JsonObject();
|
|
||||||
params.addProperty("begin", limit);
|
|
||||||
params.addProperty("limit", listResult.getTotalCount() - limit);
|
|
||||||
stores.addAll(WxMpStoreListResult
|
|
||||||
.fromJson(this.wxMpService.post(url, params.toString()))
|
|
||||||
.getBusinessList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stores;
|
return stores;
|
||||||
|
@ -18,6 +18,7 @@ import me.chanjar.weixin.common.exception.WxErrorException;
|
|||||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
import me.chanjar.weixin.mp.api.ApiTestModule;
|
||||||
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
|
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
|
||||||
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;
|
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;
|
||||||
|
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 王彬 (Binary Wang)
|
* @author 王彬 (Binary Wang)
|
||||||
@ -37,17 +38,16 @@ public class WxMpStoreServiceImplTest {
|
|||||||
this.wxMpService.getStoreService()
|
this.wxMpService.getStoreService()
|
||||||
.add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc")
|
.add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc")
|
||||||
.province("aaa").district("aaa").telephone("122").address("abc")
|
.province("aaa").district("aaa").telephone("122").address("abc")
|
||||||
.categories(new String[] { "美食,江浙菜" })
|
.categories(new String[] { "美食,江浙菜" })
|
||||||
.longitude(new BigDecimal("115.32375"))
|
.longitude(new BigDecimal("115.32375"))
|
||||||
.latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1)
|
.latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testList() throws WxErrorException {
|
public void testList() throws WxErrorException {
|
||||||
List<WxMpStoreInfo> list = this.wxMpService.getStoreService().list(0, 10);
|
WxMpStoreListResult result = this.wxMpService.getStoreService().list(0, 10);
|
||||||
assertNotNull(list);
|
assertNotNull(result);
|
||||||
System.err.println(list.size());
|
System.err.println(result);
|
||||||
System.err.println(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListAll() throws WxErrorException {
|
public void testListAll() throws WxErrorException {
|
||||||
|
Loading…
Reference in New Issue
Block a user