limeng пре 1 месец
родитељ
комит
acaadbb797

+ 173 - 0
src/main/java/com/sooka/sponest/monitor/chinatower/controller/ChinaTowerController.java

@@ -0,0 +1,173 @@
+package com.sooka.sponest.monitor.chinatower.controller;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.dahuatech.hutool.core.util.HexUtil;
+import com.dahuatech.hutool.http.HttpRequest;
+import com.dahuatech.hutool.http.HttpResponse;
+import com.sooka.sponest.monitor.camera.domain.CentermonitorTCamera;
+import com.sooka.sponest.monitor.chinatower.service.ChinaTowerService;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.springframework.web.bind.annotation.RequestMethod.POST;
+
+@Api(tags = "铁塔视联控制器")
+@RestController
+@RequestMapping("ChinaTower")
+@Slf4j
+public class ChinaTowerController {
+
+    Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    @Resource
+    private ChinaTowerService chinaTowerService;
+
+    /**
+     * 根据铁塔设备编码获取大华摄像头实体
+     */
+    @GetMapping(value = "/getCameraByChinaTowerDeviceCode/{deviceCode}")
+    public CentermonitorTCamera getCameraByChinaTowerDeviceCode(@PathVariable String deviceCode) {
+        return chinaTowerService.getCameraByChinaTowerDeviceCode(deviceCode);
+    }
+
+    /**
+     * 根据铁塔设备编码获取铁塔订单号
+     */
+    @GetMapping("/getOrderCodeByChinaTowerDeviceCode/{deviceCode}")
+    public String getOrderCodeByChinaTowerDeviceCode(@PathVariable("deviceCode") String deviceCode){
+        return chinaTowerService.getOrderCodeByChinaTowerDeviceCode(deviceCode);
+    }
+
+    @RequestMapping(value = "/orderReceiver", method = POST)
+    public void orderReceiver(@RequestBody String body) {
+        logger.info("收到铁塔视联订单信息:" + body);
+    }
+
+
+
+
+
+
+    static String servicePath = "/file/obsFiles/getObsEncryptUrls";
+    /**
+     * 新网关
+     */
+    static String HOST_IP = "https://sl-neimenggu.chinatowercom.cn:9997";
+    /**
+     * AK 由运管这边提供
+     */
+    static String AK = "012626d75ab147858ff7fdf9ea44b74d";
+    /**
+     * SK 由运管这边提供
+     */
+    static String SK = "dce85f55cad140498936e7832e6528ad";
+    /**
+     * 行业编码 由运管这边提供
+     */
+    static String appCode = "700002";
+    /**
+     * 订购客户编码,用于订购鉴权,需要一一对应
+     */
+    static String customer = "124012301";
+    /**
+     * 订单号,用于订购鉴权,需要一一对应
+     */
+//    static String orderCode = "PO124012301202503303260509147136";
+//    static String orderCode = "PO124012301202503302702024986624";
+    static String orderCode = "PO124012301202504047918802915328";
+    /**
+     * 用户编码,暂可以填随意值
+     */
+    static String userCode = "0a97fb806ab24ca8bc788dc6ace3d4c2";
+
+    public static void main(String[] args) {
+        getObsEncryptUrls();
+    }
+
+    public static void getObsEncryptUrls(){
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        // 这里的 url是发送请求拼接url
+        String url = HOST_IP + servicePath;
+        String msgId = UUID.randomUUID().toString().replace("-", "");
+        System.out.println("msgId:" + msgId);
+        String requestTime = dateFormat.format(new Date());
+        System.out.println("requestTime:" + requestTime);
+        String signContext = getSignContext(servicePath, AK, msgId, requestTime, customer, userCode);
+        String sign = getGenerateSign(SK, signContext);
+        System.out.println("sign:" + sign);
+
+        // ********模拟请求头参数,以下参数为通用必填参数************
+        Map<String, String> headerMap = new HashMap<>();
+        headerMap.put("X-AppKey", AK);
+        headerMap.put("X-Signature", sign);
+        headerMap.put("X-MsgId", msgId);
+        headerMap.put("X-RequestTime", requestTime);
+        headerMap.put("X-CustomerCode", customer);
+        headerMap.put("X-UserCode", userCode);
+        headerMap.put("X-AppCode", appCode);
+        headerMap.put("X-OrderCode", orderCode);
+        postObject(url, headerMap);
+    }
+
+    public static void postObject(String appAddress,Map<String, String> headerMap) {
+        String[] files = {"/15000000005/ThirdAlarm/pic/ZGTT-1717140001_339b7c7fb9e14de5a7b2a3f75fb91628393ecd7a07524453a1d6237eb8f2529a_02_001.jpg"};
+//        String[] files = {"/15000000005/ThirdAlarm/video/20250411/d918a07284c54004be4722046ff94d78f9d8ef87d8e149a6a1a122f144556941_f550.mp4"};
+        JSONObject params = new JSONObject();
+        params.put("fileUrls", files);
+        HttpResponse result = null;
+        try {
+            result = HttpRequest.post(appAddress)
+                    .headerMap(headerMap,true)
+                    .body(params.toJSONString())
+                    .timeout(30000)
+                    .execute();
+            System.out.println(params.toJSONString());
+            log.info("\n请求地址{},\n返回状态:{},\n返回信息{}", appAddress, result.getStatus(), result.body());
+        } catch (Exception e) {
+            log.error("地址{},参数{},发送异常:{}", appAddress, params, e.getMessage());
+        }
+    }
+
+    private static String getSignContext(String path, String appkey, String msgId, String requestTime,
+                                         String customerCode, String userCode) {
+        StringBuilder append = new StringBuilder(path)
+                .append(appkey)
+                .append(msgId)
+                .append(requestTime);
+        if (customerCode != null) {
+            append.append(customerCode);
+        }
+        if (userCode != null) {
+            append.append(userCode);
+        }
+        return append.toString().toUpperCase();
+    }
+
+    public static String getGenerateSign(final String secret, final String signContext) {
+        String sign = null;
+        try {
+            Mac hmacSha256 = Mac.getInstance("HmacSHA1");
+            byte[] keyBytes = secret.getBytes();
+            hmacSha256.init(new SecretKeySpec(keyBytes, 0, keyBytes.length, "HmacSHA1"));
+            sign = HexUtil.encodeHexStr(hmacSha256.doFinal(signContext.getBytes()));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return sign;
+    }
+
+
+}

+ 10 - 0
src/main/java/com/sooka/sponest/monitor/chinatower/mapper/ChinaTowerMapper.java

@@ -0,0 +1,10 @@
+package com.sooka.sponest.monitor.chinatower.mapper;
+
+import com.sooka.sponest.monitor.camera.domain.CentermonitorTCamera;
+
+public interface ChinaTowerMapper {
+    CentermonitorTCamera getCameraByChinaTowerDeviceCode(String cameraCode);
+
+    String getOrderCodeByChinaTowerDeviceCode(String cameraCode);
+
+}

+ 12 - 0
src/main/java/com/sooka/sponest/monitor/chinatower/service/ChinaTowerService.java

@@ -0,0 +1,12 @@
+package com.sooka.sponest.monitor.chinatower.service;
+
+import com.sooka.sponest.monitor.camera.domain.CentermonitorTCamera;
+
+import java.util.List;
+
+public interface ChinaTowerService {
+
+    CentermonitorTCamera getCameraByChinaTowerDeviceCode(String deviceCode);
+    String getOrderCodeByChinaTowerDeviceCode(String deviceCode);
+
+}

+ 26 - 0
src/main/java/com/sooka/sponest/monitor/chinatower/service/impl/ChinaTowerServiceImpl.java

@@ -0,0 +1,26 @@
+package com.sooka.sponest.monitor.chinatower.service.impl;
+
+import com.sooka.sponest.monitor.camera.domain.CentermonitorTCamera;
+import com.sooka.sponest.monitor.chinatower.mapper.ChinaTowerMapper;
+import com.sooka.sponest.monitor.chinatower.service.ChinaTowerService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+@Service
+public class ChinaTowerServiceImpl implements ChinaTowerService {
+
+    @Resource
+    private ChinaTowerMapper chinaTowerMapper;
+    @Override
+    public CentermonitorTCamera getCameraByChinaTowerDeviceCode(String deviceCode) {
+        return chinaTowerMapper.getCameraByChinaTowerDeviceCode(deviceCode);
+    }
+
+    @Override
+    public String getOrderCodeByChinaTowerDeviceCode(String deviceCode) {
+        return chinaTowerMapper.getOrderCodeByChinaTowerDeviceCode(deviceCode);
+    }
+
+
+}

+ 73 - 0
src/main/resources/mapper/monitor/chianTower/CentermonitorTChinaTowerMapper.xml

@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.sooka.sponest.monitor.chinatower.mapper.ChinaTowerMapper">
+
+    <resultMap type="CentermonitorTCamera" id="CentermonitorTCameraResult">
+        <result property="id" column="id"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="dataStatus" column="data_status"/>
+        <result property="dataDeptId" column="data_dept_id"/>
+        <result property="cameraId" column="camera_id"/>
+        <result property="cameraName" column="camera_name"/>
+        <result property="cameraIp" column="camera_ip"/>
+        <result property="cameraPort" column="camera_port"/>
+        <result property="cameraAccount" column="camera_account"/>
+        <result property="cameraPasword" column="camera_pasword"/>
+        <result property="cameraCode" column="camera_code"/>
+        <result property="cameraFactory" column="camera_factory"/>
+        <result property="cameraRegion" column="camera_region"/>
+        <result property="cameraRadius" column="camera_radius"/>
+        <result property="height" column="height"/>
+        <result property="longitude" column="longitude"/>
+        <result property="latitude" column="latitude"/>
+        <result property="cameraType" column="camera_type"/>
+        <result property="channelCode" column="channel_code"/>
+        <result property="distance" column="distance"/>
+        <result property="deptLongitude" column="dept_longitude"/>
+        <result property="deptLatitude" column="dept_latitude"/>
+        <result property="operatorType" column="operator_type"/>
+        <result property="cameraUse" column="camera_use"/>
+        <result property="channelNum" column="channel_num"/>
+        <result property="workingStatus" column="working_status"/>
+        <result property="offlineReason" column="offline_reason"/>
+        <result property="convergencePlatform" column="convergence_platform"/>
+        <result property="cameraImg" column="camera_img"/>
+        <result property="deviceCode" column="device_code"/>
+        <result property="deviceSn" column="device_sn"/>
+        <result property="deviceProtocolType" column="device_protocol_type"/>
+        <result property="deviceLoginType" column="device_login_type"/>
+    </resultMap>
+
+    <select id="getCameraByChinaTowerDeviceCode" parameterType="String"
+            resultMap="CentermonitorTCameraResult">
+        SELECT
+            *
+        FROM
+            centermonitor_t_camera
+        WHERE
+            camera_code = (
+                SELECT
+                    dh_code
+                FROM
+                    centermonitor_t_chinatower_dh_code_mapping
+                WHERE
+                    china_tower_code = #{deviceCode}
+            )
+    </select>
+
+    <select id="getOrderCodeByChinaTowerDeviceCode" parameterType="String"
+            resultType="String">
+        SELECT
+            china_tower_order_code
+        FROM
+            centermonitor_t_chinatower_dh_code_mapping
+        WHERE
+            china_tower_code = #{deviceCode}
+    </select>
+
+</mapper>