Parcourir la source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

# Conflicts:
#	svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/label/PatientLableService.java
yeshijie il y a 3 ans
Parent
commit
a84b769711

+ 5 - 1
svr/svr-cloud-device/pom.xml

@ -98,7 +98,11 @@
            <artifactId>HikariCP</artifactId>
            <!-- <scope>runtime</scope> -->
        </dependency>
        <dependency>
            <groupId>com.hikvision.ga</groupId>
            <artifactId>artemis-http-client</artifactId>
            <version>1.1.3</version>
        </dependency>
        <dependency>
            <groupId>io.github.swagger2markup</groupId>
            <artifactId>swagger2markup</artifactId>

+ 80 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/HvDeviceController.java

@ -0,0 +1,80 @@
package com.yihu.jw.care.endpoint;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
/**
 * Created with IntelliJ IDEA.
 * 海威烟感 气感
 * @Author: yeshijie
 * @Date: 2021/8/20
 * @Description:
 */
@RestController
@RequestMapping("/hvdevice")
@Api(value = "海威设备相关服务", description = "海威设备相关服务")
public class HvDeviceController {
    private static Logger logger = LoggerFactory.getLogger(HvDeviceController.class);
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @return
     */
    public String error(int code, String msg) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            map.put("status", code);
            map.put("msg", msg);
            map.put("success", false);
            return mapper.writeValueAsString(map);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 接口处理成功
     * @return
     */
    public String success() {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            map.put("status", 200);
            map.put("success", true);
            return mapper.writeValueAsString(map);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    public String write(int code, String msg) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            map.put("status", code);
            map.put("msg", msg);
            map.put("success", true);
            return mapper.writeValueAsString(map);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

+ 180 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/util/ArtemisPostTest.java

@ -0,0 +1,180 @@
package com.yihu.jw.care.util;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
public class ArtemisPostTest {
	/**
	 * 请根据自己的appKey和appSecret更换static静态块中的三个参数. [1 host]
	 * 如果你选择的是和现场环境对接,host要修改为现场环境的ip,https端口默认为443,http端口默认为80.例如10.33.25.22:443 或者10.33.25.22:80
	 * appKey和appSecret请按照或得到的appKey和appSecret更改.
	 * TODO 调用前先要清楚接口传入的是什么,是传入json就用doPostStringArtemis方法,下载图片doPostStringImgArtemis方法
	 */
	static {
		ArtemisConfig.host = "open.hikfirecloud.com";// 代理API网关nginx服务器ip端口
		ArtemisConfig.appKey = "23553385";// 秘钥appkey
		ArtemisConfig.appSecret = "HfjuKlQnzTbn0mfxm5Vk";// 秘钥appSecret
	}
	/**
	 * 能力开放平台的网站路径
	 * TODO 路径不用修改,就是/artemis
	 */
	private static final String ARTEMIS_PATH = "/artemis";
	/**
	 * 调用POST请求类型(application/json)接口,这里以入侵报警事件日志为例
	 * https://open.hikvision.com/docs/918519baf9904844a2b608e558b21bb6#e6798840
	 *
	 * @return
	 */
	public static String callPostStringApi(String url,String body){
		/**
		 * http://10.33.47.50/artemis/api/scpms/v1/eventLogs/searches
		 * 根据API文档可以看出来,这是一个POST请求的Rest接口,而且传入的参数值为一个json
		 * ArtemisHttpUtil工具类提供了doPostStringArtemis这个函数,一共六个参数在文档里写明其中的意思,因为接口是https,
		 * 所以第一个参数path是一个hashmap类型,请put一个key-value,query为传入的参数,body为传入的json数据
		 * 传入的contentType为application/json,accept不指定为null
		 * header没有额外参数可不传,指定为null
		 *
		 */
//		final String getCamsApi = ARTEMIS_PATH +"/api/scpms/v1/eventLogs/searches";
//		final String getCamsApi = ARTEMIS_PATH +"/api/firepro/v1/getCompany";
		final String getCamsApi = ARTEMIS_PATH + url;
		Map<String, String> path = new HashMap<String, String>(2) {
			{
				put("https://", getCamsApi);//根据现场环境部署确认是http还是https
			}
		};
		String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json",null);// post请求application/json类型参数
		return result;
	}
	/**
	 * 调用POST请求下载图片类型接口,这里以获取访客记录中的图片接口为例
	 * https://open.hikvision.com/docs/a0a1a0a24701a00aa904f7b151f97410#f11f3208
	 *
	 * @return
	 */
	public static void callPostImgStringApi(){
		/**
		 * http://10.33.47.50/api/visitor/v1/record/pictures
		 * 根据API文档可以看出来,这是一个POST请求的Rest接口,而且传入的参数值为一个json
		 * ArtemisHttpUtil工具类提供了doPostStringImgArtemis这个函数,一共六个参数在文档里写明其中的意思,因为接口是https,
		 * 所以第一个参数path是一个hashmap类型,请put一个key-value,query为传入的参数,body为传入的json数据
		 * 传入的contentType为application/json,accept不指定为null
		 * header没有额外参数可不传,指定为null
		 *
		 */
		final String VechicleDataApi = ARTEMIS_PATH +"/api/visitor/v1/record/pictures";
		Map<String,String> path = new HashMap<String,String>(2){
			{
				put("http://",VechicleDataApi);
			}
		};
		JSONObject jsonBody = new JSONObject();
		jsonBody.put("svrIndexCode", "8907fd9d-d090-43d3-bb3a-3a4b10dd7219");
		jsonBody.put("picUri", "/pic?0dd453i3c-e*046456451175m6ep=t=i2p*i=d1s*i3d0d*=*1b8i81f4747059503--bdf90a-855s5721z3b9i=1=");
		String body = jsonBody.toJSONString();
		System.out.println("body: "+body);
		HttpResponse result = ArtemisHttpUtil.doPostStringImgArtemis(path,body,null,null,"application/json",null);
		try {
			HttpResponse resp = result;
			if (200==resp.getStatusLine().getStatusCode()) {
				HttpEntity entity = resp.getEntity();
				InputStream in = entity.getContent();
				Tools.savePicToDisk(in, "d:/", "test4.jpg");
				System.out.println("下载成功");
			}else{
				System.out.println("下载出错");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 消息订阅
	 *
	 * 980001	资源信息变更通知	1
		 980002	报警实时信息	2
		 980003	报警处理信息	3
		 980004	故障实时信息	4
		 980005	故障处理信息	5
		 980006	设备在离线消息	6
		 980007	监控点在离线消息	7
		 980008	监测实时信息	8
     */
	public static void subscription_info(){
		String url = "/api/firepro/v1/subscription/info";
		//消息类型	msgType	String	是
		//回调URL	postUrl	String	是
		JSONObject jsonBody = new JSONObject();
		jsonBody.put("msgType", 1);
		jsonBody.put("postUrl", 3);
		//http://ehr.yihu.com/wlyy/aqg
		String body = jsonBody.toJSONString();
		String StringeResult = callPostStringApi(url,body);
		System.out.println("StringeResult结果示例: "+StringeResult);
	}
	/**
	 * 修改订阅
	 */
	public void subscription_update(){
		String url = "/api/firepro/v1/subscription/update";
		JSONObject jsonBody = new JSONObject();
		jsonBody.put("pageNo", 1);
		jsonBody.put("pageSize", 3);
		String body = jsonBody.toJSONString();
		String StringeResult = callPostStringApi(url,body);
		System.out.println("StringeResult结果示例: "+StringeResult);
	}
	/**
	 * 删除订阅
	 */
	public void subscription_deletion(){
		String url = "/api/firepro/v1/subscription/deletion";
		JSONObject jsonBody = new JSONObject();
		jsonBody.put("pageNo", 1);
		jsonBody.put("pageSize", 3);
		String body = jsonBody.toJSONString();
		String StringeResult = callPostStringApi(url,body);
		System.out.println("StringeResult结果示例: "+StringeResult);
	}
	/**
	 * 查询订阅
	 */
	public void subscription_list(){
		String url = "/api/firepro/v1/subscription/list";
		JSONObject jsonBody = new JSONObject();
		jsonBody.put("pageNo", 1);
		jsonBody.put("pageSize", 3);
		String body = jsonBody.toJSONString();
		String StringeResult = callPostStringApi(url,body);
		System.out.println("StringeResult结果示例: "+StringeResult);
	}
	public static void main(String[] args) {
		String url = "/api/firepro/v1/getCompany";
		JSONObject jsonBody = new JSONObject();
		jsonBody.put("pageNo", 1);
		jsonBody.put("pageSize", 3);
		String body = jsonBody.toJSONString();
		String StringeResult = callPostStringApi(url,body);
		System.out.println("StringeResult结果示例: "+StringeResult);
//		callPostImgStringApi();
	}
}

+ 60 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/util/Tools.java

@ -0,0 +1,60 @@
package com.yihu.jw.care.util;/**
 * Created by lifutao on 2019/1/11.
 */
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
 * 工具类
 *
 * @author
 * @create 2019-01-11 17:06
 **/
public class Tools {
    /**
     * 将图片写到 硬盘指定目录下
     *
     * @param in
     * @param dirPath
     * @param filePath
     */
    public static void savePicToDisk(InputStream in, String dirPath,
                                      String filePath) {
        try {
            File dir = new File(dirPath);
            if (dir == null || !dir.exists()) {
                dir.mkdirs();
            }
            //文件真实路径
            String realPath = dirPath.concat(filePath);
            File file = new File(realPath);
            if (file == null || !file.exists()) {
                file.createNewFile();
            }
            FileOutputStream fos = new FileOutputStream(file);
            byte[] buf = new byte[1024];
            int len = 0;
            while ((len = in.read(buf)) != -1) {
                fos.write(buf, 0, len);
            }
            fos.flush();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}