GA/T 1400协议 - 被订阅/取消订阅流程

需求:当下级平台保持在线时,上级平台可以向下级平台发送订阅请求。由于数据是从下级平台是推送至上级平台,所以下级平台是被订阅一方,需要提供出被订阅/取消订阅的接口。

目录

  • 一、订阅/被订阅接口
    • 1.接口文档
    • 2.入参对象
    • 3.请求头示例
    • 4.请求方法体示例
    • 5.被订阅响应参数示例
    • 6.被取消订阅响应参数示例
  • 二、被订阅代码示例
  • 三、取消订阅代码示例
  • 附录
    • 1.订阅类型
    • 2.图像类型
  • 参考文章

一、订阅/被订阅接口

1.接口文档

GA/T 1400协议 - 被订阅/取消订阅流程_第1张图片
GA/T 1400协议 - 被订阅/取消订阅流程_第2张图片

2.入参对象

GA/T 1400协议 - 被订阅/取消订阅流程_第3张图片GA/T 1400协议 - 被订阅/取消订阅流程_第4张图片

3.请求头示例

User-Identify20位数字平台编码(本平台)

4.请求方法体示例

/**
 * GA/T 1400 订阅 入参
 */
@Data
public class SubscribeRequestObject {

    private SubscribeListObject SubscribeListObject;

    @Data
    public static class SubscribeListObject {
        private List<Subscribe> SubscribeObject;
    }

    @Data
    public static class Subscribe {

        private String SubscribeID;
        private String Title;
        private String SubscribeDetail;
        private String ResourceURI;
        private String ApplicantName;
        private String ApplicantOrg;
        private String BeginTime;
        private String EndTime;
        private String ReceiveAddr;
        private Integer OperateType;	// 操作类型:0订阅 1取消订阅
        private Integer SubscribeStatus;
        private String Reason;

		private String ReportInterval;  // 信息上报时间间隔
        private String ResourceClass;   // 订阅类别
        private String ResultImageDeclare;  // 返回结果图片约定
        private String ResultFeatureDeclare;    // 返回结果特征值约定

		// 取消订阅-入参字段
        private String SubscribeCancelOrg;
        private String SubscribeCancelPerson;
        private String CancelTime;
        private String CancelReason;
    }
}

============================================================================

Json格式:订阅-入参
{
	"SubscribeListObject": {
		"SubscribeObject": [{
			// 订阅 id = 行政区划码 + ? + 时间戳(14位) +  5位数字
			"SubscribeID": "4000000000000020230406165810xxxxx",
			"Title": "人脸数据订阅",
			"SubscribeDetail": "12",	// 订阅类别	12 人脸数据
			"ResourceURI": "40000000000000000000",	// 订阅资源路径(下级平台编码)
			"ApplicantName": "申请人",
			"ApplicantOrg": "申请单位",
			"BeginTime": "开始时间",
			"EndTime": "结束时间",
			
			// 订阅方(上级平台)接收通知的地址
			"ReceiveAddr": "http://xx.xx.xx.xx:xx/VIID/SubscribeNotifications",
			
			// 信息上报间隔时间
			"ReportInterval": 3,
			"Reason": "原因",
			"OperateType": 0,	// 操作类型
			"SubscribeStatus": 0,	// SubscribeStatus
			"ResourceClass": 4,		// 订阅资源类别
			
			/** 
			 * 返回结果图片约定: 
			 * -1 不传图片;01 车辆大图;02 车牌彩色小图;11 人脸图;14 场景图
			 * 对应数据推送时的SubImageInfo对象中的type字段
			 */
			"ResultImageDeclare": "14",
			"ResultFeatureDeclare": 1	// 返回结果特征值约定	
		}]
	}
}

============================================================================
Json格式:取消订阅-入参
{
	"SubscribeObject": {
		// 订阅信息
		"SubscribeID": "4000000000000020230406165810xxxxx",
		"Title": "人脸数据订阅",
		"SubscribeDetail": "12",
		"ResourceURI": "40000000000000",
		"ApplicantName": "申请人",
		"ApplicantOrg": "申请单位",
		"BeginTime": "20230330145245",
		"EndTime": "20991231235959",
		"ReceiveAddr": "http://xx.xx.xx.xx:xx/VIID/SubscribeNotifications",
		"ReportInterval": 3,
		"Reason": "采集人脸图片信息",
		"OperateType": 1,
		"SubscribeStatus": 1,
		"ResourceClass": 4,
		"ResultImageDeclare": "14",
		"ResultFeatureDeclare": 1,

		// 取消订阅参数
		"CancelTime": "20230403175222",
		"CancelReason": "444",
		"SubscribeCancelOrg":"取消单位",
		"SubscribeCancelPerson":"取消人"
	}
}

5.被订阅响应参数示例

批量订阅请求,响应的格式也是批量格式。

/**
 *	GA/T 1400 批量请求 响应参数
 *	参数字段需要保持大写
 */
@Data
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY,getterVisibility = JsonAutoDetect.Visibility.NONE)
public class ResponseStatusListRequestObject {

    private ResponseStatusListObject ResponseStatusListObject;

    @Data
    @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY,getterVisibility = JsonAutoDetect.Visibility.NONE)
    public static class ResponseStatusListObject {
        private List<ResponseStatus> ResponseStatusObject;
    }

    @Data
    @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY,getterVisibility = JsonAutoDetect.Visibility.NONE)
    public static class ResponseStatus {
        private String Id;
        private String LocalTime;
        private String RequestURL;
        private String StatusCode;
        private String StatusString;
    }
}

========================================================================================

Json格式:
{
    "ResponseStatusListObject": {
        "ResponseStatusObject": [
            {
                "Id": "4000000000000320230406165810xxxxx",	// SubscribeID
                "LocalTime": "20230406164315",
                "RequestURL": "/VIID/Subscribes",
                "StatusCode": "0",
                "StatusString": "OK"
            }
        ]
    }
}

6.被取消订阅响应参数示例

取消订阅是单个请求,响应格式也是单个请求格式。

/**
 *	GA/T 1400 单个请求 响应参数
 *	参数字段需要保持大写
 */
@Data
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY,getterVisibility = JsonAutoDetect.Visibility.NONE)
public class ResponseStatusRequestObject {

    private ResponseStatusRequestObject.ResponseStatus ResponseStatusObject;

    @Data
    @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY,getterVisibility = JsonAutoDetect.Visibility.NONE)
    public static class ResponseStatus {
        private String Id;
        private String LocalTime;
        private String RequestURL;
        private String StatusCode;
        private String StatusString;
    }
}

========================================================================================

Json格式:
{
    "ResponseStatusObject": {
        "Id": "4000000000000320230406165810xxxxx",
        "LocalTime": "20230406165337",
        "RequestURL": "/VIID/Subscribes/",
        "StatusCode": "0",
        "StatusString": "OK"
    }
}

二、被订阅代码示例

/**
     * 被订阅
     * @param request
     * @return
     */
    @PostMapping("/VIID/Subscribes")
    public ResponseEntity<ResponseStatusListRequestObject> Subscribes(HttpServletRequest request) {
        try {

            BufferedReader reader = request.getReader();
            String str = reader.readLine();

			String time = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now());
            // 响应参数
            ResponseStatusListRequestObject responseStatusListRequestObject = new ResponseStatusListRequestObject();
            ResponseStatusListRequestObject.ResponseStatusListObject responseStatusList = new ResponseStatusListRequestObject.ResponseStatusListObject();
            responseStatusListRequestObject.setResponseStatusListObject(responseStatusList);
            List<ResponseStatusListRequestObject.ResponseStatus> responseStatusesList = new ArrayList<>();
            if (StringUtils.hasLength(str)) {

                SubscribeRequestObject subscribeDTO = JSON.parseObject(str, SubscribeRequestObject.class);
                List<SubscribeRequestObject.Subscribe> subscribeObject = subscribeDTO.getSubscribeListObject().getSubscribeObject();

                for (SubscribeRequestObject.Subscribe listObject : subscribeObject) {
                    subscribeID subscribeID = listObject.getSubscribeID();
                    
                    // 记录订阅信息
                    redisCache.setCacheObject("subscribe_redis::" + subscribeID, subscribeDTO);
                    
                    // 响应参数
                    ResponseStatusListRequestObject.ResponseStatus responseStatus = new ResponseStatusListRequestObject.ResponseStatus();
                    responseStatus.setId(subscribeID);   // 订阅id
                    responseStatus.setLocalTime(time);
                    responseStatus.setRequestURL("/VIID/Subscribes");
                    responseStatus.setStatusCode("0");
                    responseStatus.setStatusString(HttpStatus.OK.getReasonPhrase());
                    responseStatusesList.add(responseStatus);
                }
                responseStatusList.setResponseStatusObject(responseStatusesList);
              
                LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
                headers.add("Content-Type", "application/*+JSON");
                ResponseEntity<ResponseStatusListRequestObject> responseEntity = new ResponseEntity<>(responseStatusListRequestObject, headers, HttpStatus.OK);
               
                return responseEntity;
            }

        } catch (IOException e) {
            log.info("/VIID/Subscribes-异常: ", e);
        }
        return null;
    }

三、取消订阅代码示例

    @PutMapping("/VIID/Subscribes/{ID}")
    public ResponseEntity<ResponseStatusRequestObject> cancelSubscribes(HttpServletRequest request) {
        try {

            BufferedReader reader = request.getReader();
            String str = reader.readLine();
            
            if (StringUtils.hasLength(str)) {
 				String time = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now());
                // 取消订阅入参
                SubscribeObjectReq subscribeDTO = JSON.parseObject(str, SubscribeObjectReq.class);
                if (subscribeDTO != null) {
                    // 响应参数
                    ResponseStatusRequestObject responseStatusRequestObject = new ResponseStatusRequestObject();
                    List<ResponseStatusListRequestObject.ResponseStatus> responseStatusesList = new ArrayList<>();
                    String subscribeID = subscribeDTO.getSubscribeObject().getSubscribeID();
                    
                    // 删除订阅信息
                    String key = "subscribe_redis::" + subscribeID;
                    boolean del = redisCache.deleteObject(key);
                    
                    if (del) {
                        ResponseStatusRequestObject.ResponseStatus responseStatus = new ResponseStatusRequestObject.ResponseStatus();
                        responseStatus.setId(subscribeID);   // 订阅id
                        responseStatus.setLocalTime(time);
                        responseStatus.setRequestURL("/VIID/Subscribes/");
                        responseStatus.setStatusCode("0");
                        responseStatus.setStatusString(HttpStatus.OK.getReasonPhrase());

                        responseStatusRequestObject.setResponseStatusObject(responseStatus);
                        LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
                        headers.add("Content-Type", "application/*+JSON");
                        ResponseEntity<ResponseStatusRequestObject> responseEntity = new ResponseEntity<>(responseStatusRequestObject, headers, HttpStatus.OK);
                        return responseEntity;
                    }
                }
            }
        } catch (IOException e) {
            log.info("/VIID/Subscribes/异常:", e);
        }
        return null;
    }

附录

1.订阅类型

GA/T 1400协议 - 被订阅/取消订阅流程_第5张图片

2.图像类型

GA/T 1400协议 - 被订阅/取消订阅流程_第6张图片

参考文章

GAT1400 视图库订阅

你可能感兴趣的:(工作日常,GA/T,1400,java,spring)