🎨 优化规范部分代码

This commit is contained in:
Binary Wang 2020-06-30 16:54:40 +08:00
parent c60fda48d2
commit a00d67a58a
4 changed files with 39 additions and 45 deletions

View File

@ -70,7 +70,7 @@ public final class WxCpApiPathConsts {
@Deprecated
public static final String GET_APPROVAL_DATA = "/cgi-bin/corp/getapprovaldata";
public static final String GET_TEMPLATE_DETAIL = "/cgi-bin/oa/gettemplatedetail";
public static final String APPLY_EVENT="/cgi-bin/oa/applyevent";
public static final String APPLY_EVENT = "/cgi-bin/oa/applyevent";
}
public static class Tag {

View File

@ -46,35 +46,35 @@ public interface WxMaLiveService {
/**
* 获取所有直播间信息没有分页直接获取全部
*
* @return
* @throws WxErrorException
* @return .
* @throws WxErrorException .
*/
List<WxMaLiveResult.RoomInfo> getLiveinfos() throws WxErrorException;
List<WxMaLiveResult.RoomInfo> getLiveInfos() throws WxErrorException;
/**
* 获取直播房间回放数据信息.
*
* @param action 获取回放
* @param room_id 直播间 id
* @param start 起始拉取视频start = 0 表示从第 1 个视频片段开始拉取
* @param limit 每次拉取的个数上限不要设置过大建议 100 以内
* @return
* @throws WxErrorException
* @param action 获取回放
* @param roomId 直播间 id
* @param start 起始拉取视频start = 0 表示从第 1 个视频片段开始拉取
* @param limit 每次拉取的个数上限不要设置过大建议 100 以内
* @return .
* @throws WxErrorException .
*/
WxMaLiveResult getLiveReplay(String action, Integer room_id, Integer start, Integer limit) throws WxErrorException;
WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start, Integer limit) throws WxErrorException;
/**
* 获取直播房间回放数据信息.
* <p>
* 获取回放 默认get_replay
*
* @param room_id 直播间 id
* @param start 起始拉取视频start = 0 表示从第 1 个视频片段开始拉取
* @param limit 每次拉取的个数上限不要设置过大建议 100 以内
* @return
* @throws WxErrorException
* @param roomId 直播间 id
* @param start 起始拉取视频start = 0 表示从第 1 个视频片段开始拉取
* @param limit 每次拉取的个数上限不要设置过大建议 100 以内
* @return .
* @throws WxErrorException .
*/
WxMaLiveResult getLiveReplay(Integer room_id, Integer start, Integer limit) throws WxErrorException;
WxMaLiveResult getLiveReplay(Integer roomId, Integer start, Integer limit) throws WxErrorException;
/**
* 直播间导入商品

View File

@ -8,6 +8,7 @@ import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
@ -24,10 +25,11 @@ import java.util.Map;
*
* @author <a href="https://github.com/yjwang3300300">yjwang</a>
*/
@Slf4j
@AllArgsConstructor
public class WxMaLiveServiceImpl implements WxMaLiveService {
private static final JsonParser JSON_PARSER = new JsonParser();
private WxMaService wxMaService;
private final WxMaService wxMaService;
@Override
public Integer createRoom(WxMaLiveInfo.RoomInfo roomInfo) throws WxErrorException {
@ -41,19 +43,19 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
@Override
public WxMaLiveResult getLiveInfo(Integer start, Integer limit) throws WxErrorException {
JsonObject jsonObject = getJsonObject(start, limit, null);
JsonObject jsonObject = getLiveInfo(start, limit, null);
return WxMaLiveResult.fromJson(jsonObject.toString());
}
@Override
public List<WxMaLiveResult.RoomInfo> getLiveinfos() throws WxErrorException {
public List<WxMaLiveResult.RoomInfo> getLiveInfos() throws WxErrorException {
List<WxMaLiveResult.RoomInfo> results = new ArrayList<>();
Integer start = 0;
int start = 0;
Integer limit = 80;
Integer tatal = 0;
WxMaLiveResult liveInfo = null;
Integer total = 0;
WxMaLiveResult liveInfo;
do {
if (tatal != 0 && tatal <= start) {
if (total != 0 && total <= start) {
break;
}
liveInfo = getLiveInfo(start, limit);
@ -61,29 +63,30 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
return null;
}
results.addAll(liveInfo.getRoomInfos());
tatal = liveInfo.getTotal();
total = liveInfo.getTotal();
start = results.size();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
log.error("InterruptedException", e);
}
} while (results.size() <= tatal);
} while (results.size() <= total);
return results;
}
@Override
public WxMaLiveResult getLiveReplay(String action, Integer room_id, Integer start, Integer limit) throws WxErrorException {
Map<String, Object> map = new HashMap(4);
public WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start, Integer limit) throws WxErrorException {
Map<String, Object> map = new HashMap<>(4);
map.put("action", action);
map.put("room_id", room_id);
JsonObject jsonObject = getJsonObject(start, limit, map);
map.put("room_id", roomId);
JsonObject jsonObject = getLiveInfo(start, limit, map);
return WxMaLiveResult.fromJson(jsonObject.toString());
}
@Override
public WxMaLiveResult getLiveReplay(Integer room_id, Integer start, Integer limit) throws WxErrorException {
return getLiveReplay("get_replay", room_id, start, limit);
public WxMaLiveResult getLiveReplay(Integer roomId, Integer start, Integer limit) throws WxErrorException {
return getLiveReplay("get_replay", roomId, start, limit);
}
@Override
@ -99,18 +102,9 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
return true;
}
/**
* 包装一下
*
* @param start
* @param limit
* @param map
* @return
* @throws WxErrorException
*/
private JsonObject getJsonObject(Integer start, Integer limit, Map<String, Object> map) throws WxErrorException {
private JsonObject getLiveInfo(Integer start, Integer limit, Map<String, Object> map) throws WxErrorException {
if (map == null) {
map = new HashMap(2);
map = new HashMap<>(2);
}
map.put("start", start);
map.put("limit", limit);

View File

@ -70,7 +70,7 @@ public class WxMaLiveServiceImplTest {
@Test
public void getLiveinfos() throws Exception {
List<WxMaLiveResult.RoomInfo> list = this.wxService.getLiveService().getLiveinfos();
List<WxMaLiveResult.RoomInfo> list = this.wxService.getLiveService().getLiveInfos();
assertNotNull(list);
System.out.println(list.toString());
}