调整接口
This commit is contained in:
parent
a3f357ba55
commit
df6ea01c3e
@ -37,5 +37,11 @@ public class BaseResponse<T> implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public BaseResponse<T> error(CodeMsg codeMsg) {
|
||||
this.status = 1;
|
||||
this.code = codeMsg.getCode();
|
||||
this.msg = codeMsg.getMsg();
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ import java.util.List;
|
||||
@Schema(name = "运营商信息-> 站端信息-> 设备信息")
|
||||
public class DeviceDto {
|
||||
|
||||
@Schema(description = "id")
|
||||
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String id;
|
||||
@Schema(description = "父级Id")
|
||||
private String parentId;
|
||||
|
||||
@ -19,6 +19,10 @@ public interface HDConstant {
|
||||
|
||||
public static final String LIVE_EXISTS_CODE = "MP130007";
|
||||
|
||||
public static final String LIVE_NOT_EXISTS_CODE = "LV1002";
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ package com.evotech.hd.cloud.controller;
|
||||
|
||||
import com.evotech.hd.cloud.entity.request.IndependentAccountRequest;
|
||||
import com.evotech.hd.cloud.service.IndependentAccountService;
|
||||
import com.evotech.hd.common.core.entity.Result;
|
||||
import com.evotech.hd.common.core.Dto.BaseResponse;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -36,7 +36,7 @@ public class IndependentAccountController {
|
||||
@Operation(summary = "查询")
|
||||
@GetMapping("/list")
|
||||
@ApiOperationSupport(order = 4)
|
||||
public Result<Map<String, Object>> list(@ParameterObject IndependentAccountRequest params) {
|
||||
public BaseResponse<Map<String, Object>> list(@ParameterObject IndependentAccountRequest params) {
|
||||
return independentAccountService.pageList(params);
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package com.evotech.hd.cloud.controller.dh;
|
||||
|
||||
import com.evotech.hd.cloud.service.DHDeviceService;
|
||||
import com.evotech.hd.common.core.Dto.BaseResponse;
|
||||
import com.evotech.hd.common.core.Dto.DeviceDto;
|
||||
import com.evotech.hd.common.core.entity.Result;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -27,15 +28,16 @@ public class DHController {
|
||||
@Resource
|
||||
private DHDeviceService dhDeviceService;
|
||||
|
||||
@Operation(summary = "设备列表")
|
||||
@GetMapping("/device/list")
|
||||
public Result<List<DeviceDto>> deviceList() {
|
||||
return new Result().success(dhDeviceService.findList());
|
||||
public BaseResponse<List<DeviceDto>> deviceList() {
|
||||
return new BaseResponse().success(dhDeviceService.findList());
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "直播地址", description = "直接返回直播地址")
|
||||
@PostMapping("/device/live")
|
||||
public Result<String> live(@RequestParam String deviceId, @RequestParam String channelId) {
|
||||
return new Result().success(dhDeviceService.live(deviceId, channelId));
|
||||
public BaseResponse<String> live(@RequestParam String deviceId, @RequestParam String channelId) {
|
||||
return new BaseResponse().success(dhDeviceService.live(deviceId, channelId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ import lombok.EqualsAndHashCode;
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
public class IndependentAccountRequest extends BasePageRequest {
|
||||
|
||||
@Schema(description = "分账状态")
|
||||
@Schema(description = "分账状态", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "运营商ID")
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package com.evotech.hd.cloud.service;
|
||||
|
||||
import com.evotech.hd.cloud.entity.request.IndependentAccountRequest;
|
||||
import com.evotech.hd.common.core.entity.Result;
|
||||
import com.evotech.hd.common.core.Dto.BaseResponse;
|
||||
import com.evotech.hd.common.core.entity.cloud.TaxPoint;
|
||||
|
||||
import java.util.Map;
|
||||
@ -19,5 +19,5 @@ public interface IndependentAccountService {
|
||||
|
||||
void addIndependentAccount(TaxPoint taxPoint, String stationCode);
|
||||
|
||||
public Result<Map<String, Object>> pageList(IndependentAccountRequest params);
|
||||
public BaseResponse<Map<String, Object>> pageList(IndependentAccountRequest params);
|
||||
}
|
||||
|
||||
@ -15,11 +15,13 @@ import com.evotech.hd.common.core.utils.Collections;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -36,6 +38,8 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class DHDeviceServiceImpl implements DHDeviceService {
|
||||
|
||||
@Value("${yt.test:false}")
|
||||
Boolean ytTest;
|
||||
@Resource
|
||||
ResourceService resourceService;
|
||||
@Resource
|
||||
@ -55,21 +59,21 @@ public class DHDeviceServiceImpl implements DHDeviceService {
|
||||
@Override
|
||||
public Result<String> live(String deviceId, String channelId) {
|
||||
AtomicReference<String> url = new AtomicReference<>("");
|
||||
JSONObject liveJSON = DHRequestUtil.live(deviceId,channelId);
|
||||
JSONObject liveInfoJSON = DHRequestUtil.liveInfo(deviceId,channelId);
|
||||
JSONArray urlArray = null;
|
||||
if(HDConstant.DHConstant.LIVE_EXISTS_CODE.equals(liveJSON.getString("code"))){
|
||||
JSONObject liveInfoJSON = DHRequestUtil.liveInfo(deviceId,channelId);
|
||||
urlArray = liveInfoJSON.getJSONArray("streams");
|
||||
if(HDConstant.DHConstant.LIVE_NOT_EXISTS_CODE.equals(liveInfoJSON.getString("code"))){
|
||||
JSONObject liveJSON = DHRequestUtil.live(deviceId,channelId);
|
||||
urlArray = liveJSON.getJSONArray("streams");
|
||||
}else{
|
||||
//如果不包含code, 则成功了, 直接获取就行
|
||||
urlArray = liveJSON.getJSONArray("streams");
|
||||
urlArray = liveInfoJSON.getJSONArray("streams");
|
||||
}
|
||||
|
||||
if(urlArray != null){
|
||||
urlArray.stream().forEach( urlJSON ->{
|
||||
JSONObject urlObj = (JSONObject)urlJSON;
|
||||
// 码流类型(0:高清;1:标清)
|
||||
if("1".equals(urlObj.getString("streamId")) && urlObj.getString("hls").contains("proto=https")){
|
||||
if("0".equals(urlObj.getString("streamId")) && urlObj.getString("hls").contains("proto=https")){
|
||||
url.set(urlObj.getString("hls"));
|
||||
}
|
||||
});
|
||||
@ -88,16 +92,22 @@ public class DHDeviceServiceImpl implements DHDeviceService {
|
||||
Boolean findList = true;
|
||||
Integer page = 1;
|
||||
List<DeviceDto> result = Collections.emptyList();
|
||||
Map<String, Object> params = Collections.asMap("pageSize", 200);
|
||||
if(StringUtils.isNotEmpty(storeId) && ytTest){
|
||||
params.put("storeId",storeId);
|
||||
}
|
||||
while (findList){
|
||||
JSONObject jsonObject = DHRequestUtil.deviceList(Collections.asMap("pageNum", page, "pageSize", 200, "storeId",storeId));
|
||||
if(HDConstant.DHConstant.SUCCESS_CODE.equals(jsonObject.getString("code"))){
|
||||
JSONObject jsonData = jsonObject.getJSONObject("data");
|
||||
Long totalRows = jsonData.getLong("totalRows");
|
||||
params.put("pageNum", page);
|
||||
JSONObject jsonObject = DHRequestUtil.deviceList(params);
|
||||
//JSONObject jsonObject = DHRequestUtil.deviceList(Collections.asMap("pageNum", page, "pageSize", 200, "storeId",storeId));
|
||||
// if(HDConstant.DHConstant.SUCCESS_CODE.equals(jsonObject.getString("code"))){
|
||||
// JSONObject jsonData = jsonObject.getJSONObject("data");
|
||||
Long totalRows = jsonObject.getLong("totalRows");
|
||||
//如果totalRows.compareTo(page*pageSize) <= 0 则证明数据已经抓取完
|
||||
if(totalRows.compareTo(new BigDecimal(page).multiply(new BigDecimal(200)).longValue()) <= 0){
|
||||
findList = false;
|
||||
}
|
||||
JSONArray pageData = jsonData.getJSONArray("pageData");
|
||||
JSONArray pageData = jsonObject.getJSONArray("pageData");
|
||||
if(pageData != null && !pageData.isEmpty()){
|
||||
pageData.stream().forEach(pData ->{
|
||||
JSONObject pj = (JSONObject)pData;
|
||||
@ -113,10 +123,10 @@ public class DHDeviceServiceImpl implements DHDeviceService {
|
||||
});
|
||||
}
|
||||
page = page + 1;
|
||||
}else{
|
||||
findList = false;
|
||||
log.error("大华(DH)异常============{}", jsonObject.getString("msg"));
|
||||
}
|
||||
// }else{
|
||||
// findList = false;
|
||||
// log.error("大华(DH)异常============{}", jsonObject.getString("msg"));
|
||||
// }
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -141,9 +151,9 @@ public class DHDeviceServiceImpl implements DHDeviceService {
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Long.valueOf(201).compareTo(new BigDecimal(2).multiply(new BigDecimal(200)).longValue()));
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// System.out.println(Long.valueOf(201).compareTo(new BigDecimal(2).multiply(new BigDecimal(200)).longValue()));
|
||||
// }
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
@ -9,8 +9,8 @@ import com.evotech.hd.cloud.entity.request.IndependentAccountRequest;
|
||||
import com.evotech.hd.cloud.service.IndependentAccountDetailService;
|
||||
import com.evotech.hd.cloud.service.IndependentAccountService;
|
||||
import com.evotech.hd.cloud.service.rpc.ResourceService;
|
||||
import com.evotech.hd.common.core.Dto.BaseResponse;
|
||||
import com.evotech.hd.common.core.Dto.ResponseUtil;
|
||||
import com.evotech.hd.common.core.entity.Result;
|
||||
import com.evotech.hd.common.core.entity.cloud.BatteryStation;
|
||||
import com.evotech.hd.common.core.entity.cloud.IndependentAccount;
|
||||
import com.evotech.hd.common.core.entity.cloud.TaxPoint;
|
||||
@ -96,16 +96,16 @@ public class IndependentAccountServiceImpl implements IndependentAccountService
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Map<String, Object>> pageList(IndependentAccountRequest params) {
|
||||
public BaseResponse<Map<String, Object>> pageList(IndependentAccountRequest params) {
|
||||
Page<IndependentAccount> page = new Page<IndependentAccount>(params.getPageNo(), params.getPageSize());
|
||||
List<IndependentAccount> list = independentAccountDao.pageList(page, params);
|
||||
if (list.isEmpty()) {
|
||||
return new Result<Map<String, Object>>().error(CodeMsg.DATABASE_RESULT_NULL);
|
||||
return new BaseResponse<Map<String, Object>>().error(CodeMsg.DATABASE_RESULT_NULL);
|
||||
}
|
||||
|
||||
IndependentAccount totalAmount = independentAccountDao.countAmount(params);
|
||||
|
||||
return new Result<Map<String, Object>>().success(Collections.asMap("pageList", page.setRecords(list), "totalAmount", totalAmount));
|
||||
return new BaseResponse<Map<String, Object>>().success(Collections.asMap("pageList", page.setRecords(list), "totalAmount", totalAmount));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user