Ver Código Fonte

修改北向接口,增加产品枚举

konghl 4 anos atrás
pai
commit
8cdd3e9f43

+ 66 - 89
ebc-sea-platform/src/main/java/com/ai/ipu/server/dao/impl/DeviceManageDaoImpl.java

@ -1,97 +1,74 @@
1 1
package com.ai.ipu.server.dao.impl;
2 2
3
import com.ai.ipu.data.JList;
4
import com.ai.ipu.data.JMap;
5
import com.ai.ipu.data.impl.JsonList;
6
import com.ai.ipu.data.impl.JsonMap;
7
import com.ai.ipu.server.dao.interfaces.DeviceManageDao;
8
import com.ai.ipu.sql.mgmt.ISqlMgmtDao;
9
import com.ai.ipu.sql.mgmt.SqlMgmtDaoFactory;
10
import com.alibaba.fastjson.JSON;
11
import com.alibaba.fastjson.JSONObject;
12
import com.github.pagehelper.PageHelper;
13
import com.github.pagehelper.PageInfo;
14
import org.springframework.stereotype.Component;
15
16
import java.util.ArrayList;
17
import java.util.HashMap;
18
import java.util.List;
3
import java.io.IOException;
19 4
import java.util.Map;
20 5
21
@Component
22
public class DeviceManageDaoImpl implements DeviceManageDao {
23
24
    private String connName = "ebc";
25
26
    @Override
27
    public PageInfo queryDeviceInfo(JMap params) throws Exception {
28
        JMap params1 = params.getJMap("params");
29
        PageHelper.startPage(params1.getInt("pageNum"),params1.getInt("pageSize"));
30
        ISqlMgmtDao dao = SqlMgmtDaoFactory.createFileSqlMgmtDao(connName);
31
        List<Map<String, Object>> mapTagList= dao.executeSelect("ipu.DeviceManageDao", "queryDeviceInfo", params1);
32
33
        List<Map<String, Object>> mapTagXyList= dao.executeSelect("ipu.DeviceManageDao", "queryDeviceXyInfo", params1);
34
35
        //将后台拼接成级联属性
36
        mapTagList.forEach((mapTag)->{
37
            ArrayList<Object> arrayList = new ArrayList<>();
38
            mapTagXyList.forEach((mapTagXy)->{
39
                if(mapTag.get("MAP_TAG_ID")==mapTagXy.get("MAP_TAG_ID")){
40
                    arrayList.add(mapTagXy);
41
                    System.out.println(arrayList.toString());
42
                }
43
            });
44
            mapTag.put("EBC_MAP_TAG_XY",arrayList);
45
        });
46
        PageInfo pageInfo = new PageInfo(mapTagList);
47
        return pageInfo;
48
49
    }
50
51
    @Override
52
    public int modifyDeviceInfo (JMap params) throws Exception {
53
54
        deleteDeviceXyInfo(params);
55
        //将新数据插入
56
        int num = addDeviceInfo(params);
57
        return num;
58
    }
59
60
    @Override
61
    public int addDeviceInfo(JMap params) throws Exception {
62
        Object mapTagContent = params.get("MAP_TAG_CONTENT");
63
        String mapTagContentStr = JSONObject.toJSONString(mapTagContent);
64
        params.put("MAP_TAG_CONTENT",mapTagContentStr);
65
        ISqlMgmtDao dao = SqlMgmtDaoFactory.createFileSqlMgmtDao(connName);
66
        int num = dao.executeInsert("ipu.DeviceManageDao", "addDeviceInfo", params);
67
        if(num>0){
68
            JMap paramsMap=new JsonMap();
69
            JList paramsList=new JsonList();
70
            JList paramsJList = params.getJList("EBC_MAP_TAG_XY");
71
72
            paramsJList.forEach(s->{
73
                HashMap hashMap = JSON.parseObject(JSONObject.toJSONString(s), HashMap.class);
74
                hashMap.put("MAP_TAG_ID",params.getInt("MAP_TAG_ID"));
75
                paramsList.add(hashMap);
76
            });
77
            paramsMap.put("paramsList",paramsList);
78
            int i = dao.executeInsert("ipu.DeviceManageDao", "addDevicexyInfo", paramsMap);
79
        }
80
        return num;
81
    }
82
83
    @Override
84
    public boolean deleteDeviceXyInfo(JMap params) throws Exception {
85
        ISqlMgmtDao dao = SqlMgmtDaoFactory.createFileSqlMgmtDao(connName);
86
        //先删除子表在删除父表
87
        dao.executeDelete( "ipu.DeviceManageDao", "deleteDeviceXyInfo", params);
88
        int num = dao.executeDelete("ipu.DeviceManageDao", "deleteDeviceInfo", params);
89
        if(num>0){
90
            return true;
91
        }
92
        return false;
93
    }
6
import org.springframework.stereotype.Component;
94 7
8
import com.ai.ipu.data.JMap;
9
import com.ai.ipu.database.dao.impl.AbstractBizDao;
10
import com.ai.ipu.server.dao.interfaces.DeviceManageDao;
11
import com.ai.ipu.server.model.IotUrlEnum;
12
import com.ai.ipu.server.util.EbcConstant;
13
import com.ai.ipu.server.util.HttpURLConnectionUtil;
95 14
15
@Component
16
public class DeviceManageDaoImpl extends AbstractBizDao implements DeviceManageDao {
17
18
	public DeviceManageDaoImpl() throws IOException {
19
		super("ebc");
20
	}
21
22
	@Override
23
	public Map<String, String> queryDeviceInfo(JMap params) throws Exception {
24
		// 拼接接口地址
25
		String url = IotUrlEnum.queryPageDevice.getUrl();
26
		// Map map = HttpURLConnectionUtil.iotCallMothod(url,params);
27
		return null;
28
	}
29
30
	@Override
31
	public Map<String, String> addDeviceInfo(Map<String, String> paramsMap) throws Exception {
32
		// 拼接接口地址
33
		String url = IotUrlEnum.addDevice.getUrl();
34
		Map map = HttpURLConnectionUtil.iotCallMothod(url, paramsMap);
35
		return map;
36
	}
37
38
	@Override
39
	public Map<String, String> modifyDeviceInfo(Map<String, String> paramsMap) throws Exception {
40
		// 拼接接口地址
41
		String url = IotUrlEnum.updateDevice.getUrl();
42
		Map map = HttpURLConnectionUtil.iotCallMothod(url, paramsMap);
43
		return map;
44
	}
45
46
	@Override
47
	public Map<String, String> deleteDeviceInfo(Map<String, String> paramsMap) throws Exception {
48
		// 拼接接口地址
49
		String url = IotUrlEnum.deleteDevice.getUrl();
50
		Map map = HttpURLConnectionUtil.iotCallMothod(url, paramsMap);
51
		return map;
52
	}
53
54
	@Override
55
	public int bindDevice(Map params, String type) throws Exception {
56
		if (EbcConstant.bind_device_type_user.equals(type)) {
57
			return dao.insert("LR_PARTY_TERMINAL", params);
58
		} else if (EbcConstant.bind_device_type_ship.equals(type)) {
59
			return dao.update("LR_FACILITY", params);
60
		}
61
		return 0;
62
	}
63
64
	@Override
65
	public int unbindDevice(Map params, String type) throws Exception {
66
		if (EbcConstant.bind_device_type_user.equals(type)) {
67
			return dao.delete("LR_PARTY_TERMINAL", params);
68
		} else if (EbcConstant.bind_device_type_ship.equals(type)) {
69
			return dao.update("LR_FACILITY", params);
70
		}
71
		return 0;
72
	}
96 73
97 74
}

+ 10 - 5
ebc-sea-platform/src/main/java/com/ai/ipu/server/dao/interfaces/DeviceManageDao.java

@ -1,15 +1,20 @@
1 1
package com.ai.ipu.server.dao.interfaces;
2 2
3
import java.util.Map;
4
3 5
import com.ai.ipu.data.JMap;
4
import com.github.pagehelper.PageInfo;
5 6
6 7
public interface DeviceManageDao {
7 8
8
    PageInfo queryDeviceInfo(JMap params) throws Exception;
9
	Map<String, String> queryDeviceInfo(JMap params) throws Exception;
10
11
	Map<String, String> addDeviceInfo(Map<String, String> paramsMap) throws Exception;
12
13
	Map<String, String> modifyDeviceInfo(Map<String, String> paramsMap) throws Exception;
9 14
10
    int modifyDeviceInfo(JMap params) throws Exception;
15
	Map<String, String> deleteDeviceInfo(Map<String, String> paramsMap) throws Exception;
11 16
12
    int addDeviceInfo(JMap params) throws Exception;
17
	int bindDevice(Map params,String type) throws Exception;
13 18
14
    boolean deleteDeviceXyInfo(JMap params) throws Exception;
19
	int unbindDevice(Map params,String type) throws Exception;
15 20
}

+ 33 - 0
ebc-sea-platform/src/main/java/com/ai/ipu/server/model/IotUrlEnum.java

@ -0,0 +1,33 @@
1
package com.ai.ipu.server.model;
2
3
/**
4
 * iot 北向接口业务数据的地址枚举
5
 * 
6
 * @author konghl@asiainfo.com
7
 * 2020-10-20
8
 */
9
public enum IotUrlEnum {
10
	// 注册设备
11
	addDevice("device"),
12
	// 删除设备
13
	deleteDevice("deleteDevice"),
14
	// 修改设备
15
	updateDevice("updateDevice"),
16
	// 查询指定设备
17
	queryDevice("device-detail"),
18
	// 分页查询设备
19
	queryPageDevice("findTerminal"),
20
	// 按产品id查询设备
21
	queryProductDevice("product/device-status");
22
23
	private String url;
24
25
	private IotUrlEnum(String url) {
26
		this.url = url;
27
	}
28
29
	public String getUrl() {
30
		return UrlAddress.IOT_URL1 + "/" + url;
31
	}
32
33
}

+ 6 - 3
ebc-sea-platform/src/main/java/com/ai/ipu/server/model/UrlAddress.java

@ -1,10 +1,13 @@
1 1
package com.ai.ipu.server.model;
2 2
3 3
public interface UrlAddress {
4
	// gis的token地址
5
	public static final String GIS_TOKEN = "http://192.168.74.189:9999/gisIntf/account/gettoken";
4 6
5
    public static final String IOT_URL="http://60.205.219.67:8300/dmp/terminalNorthApi/";
7
	// iot的北向接口注册地址
8
	public static final String IOT_LOGIN = "http://60.205.219.67:8300/sso/login";
6 9
7
    public static final String IOT_LOGIN="http://60.205.219.67:8300/sso/login";
10
	// iot的北向接口统一地址
11
	public static final String IOT_URL1 = "http://60.205.219.67:8300/dmp/terminalNorthApi";
8 12
9
    public static final String GIS_TOKEN="http://192.168.74.189:9999/gisIntf/account/gettoken";
10 13
}

+ 70 - 30
ebc-sea-platform/src/main/java/com/ai/ipu/server/service/impl/DeviceManageServiceImpl.java

@ -1,41 +1,81 @@
1 1
package com.ai.ipu.server.service.impl;
2 2
3
import com.ai.ipu.data.JMap;
4
import com.ai.ipu.server.dao.interfaces.DeviceManageDao;
5
import com.ai.ipu.server.service.interfaces.DeviceManageService;
6
import com.github.pagehelper.PageInfo;
3
import java.util.HashMap;
4
import java.util.Map;
5
7 6
import org.slf4j.Logger;
8 7
import org.slf4j.LoggerFactory;
9 8
import org.springframework.beans.factory.annotation.Autowired;
10 9
import org.springframework.stereotype.Service;
11 10
11
import com.ai.ipu.data.JMap;
12
import com.ai.ipu.server.dao.interfaces.DeviceManageDao;
13
import com.ai.ipu.server.service.interfaces.DeviceManageService;
14
import com.ai.ipu.server.util.EbcConstant;
15
import com.github.pagehelper.PageInfo;
12 16
13 17
@Service
14
public class DeviceManageServiceImpl implements DeviceManageService  {
15
    Logger logger = LoggerFactory.getLogger(DeviceManageServiceImpl.class);
16
17
    @Autowired
18
    DeviceManageDao deviceManageDao;
19
20
    @Override
21
    public PageInfo queryDeviceInfo(JMap params) throws Exception {
22
        return deviceManageDao.queryDeviceInfo(params);
23
    }
24
25
    @Override
26
    public int modifyDeviceInfo(JMap params) throws Exception{
27
        //將原來数据删除,然后在从新插入
28
        return deviceManageDao.modifyDeviceInfo(params);
29
    }
30
31
    @Override
32
    public int addDeviceInfo(JMap params) throws Exception{
33
        return deviceManageDao.addDeviceInfo(params);
34
    }
35
36
    @Override
37
    public boolean deleteDeviceXyInfo(JMap params) throws Exception{
38
        return deviceManageDao.deleteDeviceXyInfo(params);
39
    }
18
public class DeviceManageServiceImpl implements DeviceManageService {
19
	Logger logger = LoggerFactory.getLogger(DeviceManageServiceImpl.class);
20
21
	@Autowired
22
	DeviceManageDao deviceManageDao;
23
24
	@Override
25
	public PageInfo queryDeviceInfo(JMap params) throws Exception {
26
		PageInfo pageInfo = new PageInfo();
27
		Map map = deviceManageDao.queryDeviceInfo(params);
28
29
		return pageInfo;
30
	}
31
32
	@Override
33
	public Map<String, String> addDeviceInfo(JMap params) throws Exception {
34
		Map<String, String> paramsMap = new HashMap<String, String>();
35
		String deviceId = params.getString("deviceId");
36
37
		paramsMap.put("deviceId", deviceId);// 终端id
38
		paramsMap.put("terminalSN", deviceId); // 终端编号
39
		paramsMap.put("productId", EbcConstant.beidouDevice_product_id); // 所属产品
40
		paramsMap.put("deviceName", EbcConstant.beidouDevice_name + deviceId); // 设备名称
41
		paramsMap.put("remarks", params.getString("remarks")); // 备注
42
43
		Map map = deviceManageDao.addDeviceInfo(paramsMap);
44
		return map;
45
	}
46
47
	@Override
48
	public Map<String, String> modifyDeviceInfo(JMap params) throws Exception {
49
		Map<String, String> paramsMap = new HashMap<String, String>();
50
		String deviceId = params.getString("deviceId");
51
		
52
		paramsMap.put("deviceId", params.getString("deviceId"));// 终端id
53
		paramsMap.put("remarks", params.getString("remarks")); // 备注
54
55
		Map map = deviceManageDao.modifyDeviceInfo(paramsMap);
56
		return map;
57
	}
58
59
	@Override
60
	public Map<String, String> deleteDeviceInfo(JMap params) throws Exception {
61
		Map<String, String> paramsMap = new HashMap<String, String>();
62
		paramsMap.put("deviceId", params.getString("deviceId"));// 终端id (支持删多个,用逗号分隔)
63
		paramsMap.put("productId", EbcConstant.beidouDevice_product_id); // 所属产品
64
		
65
		Map map = deviceManageDao.deleteDeviceInfo(paramsMap);
66
		return map;
67
	}
68
69
	@Override
70
	public boolean bindDevice(JMap params) throws Exception {
71
		int num = deviceManageDao.bindDevice(params, params.getString("type"));
72
		return num > 0;
73
	}
74
75
	@Override
76
	public boolean unbindDevice(JMap params) throws Exception {
77
		int num = deviceManageDao.bindDevice(params, params.getString("type"));
78
		return num > 0;
79
	}
40 80
41 81
}

+ 12 - 14
ebc-sea-platform/src/main/java/com/ai/ipu/server/service/impl/EquipmentManageServiceImpl.java

@ -24,30 +24,28 @@ public class EquipmentManageServiceImpl implements EquipmentManageService {
24 24
    @Autowired
25 25
    EquipmentManageDao equipmentManageDao;
26 26
27
28
29 27
    @Override
30 28
    public PageInfo queryEquipmentInfo(JMap params) throws Exception {
31 29
        PageInfo pageInfo = new PageInfo();
32 30
        //拼接接口地址
33
        String IOT_URL=UrlAddress.IOT_URL+"device";
34
        Map map = HttpURLConnectionUtil.iotCallMothod(params, IOT_URL);
31
        //String IOT_URL=UrlAddress.IOT_URL+"device";
32
        //Map map = HttpURLConnectionUtil.iotCallMothod(params, IOT_URL);
35 33
        return pageInfo;
36 34
    }
37 35
38 36
    @Override
39 37
    public int modifyEquipmentInfo(JMap params) throws Exception{
40 38
        //拼接接口地址
41
        String IOT_URL=UrlAddress.IOT_URL+"device";
42
        Map map = HttpURLConnectionUtil.iotCallMothod(params, IOT_URL);
39
        //String IOT_URL=UrlAddress.IOT_URL+"device";
40
        //Map map = HttpURLConnectionUtil.iotCallMothod(params, IOT_URL);
43 41
        return 1;
44 42
    }
45 43
46 44
    @Override
47 45
    public int addEquipmentInfo(JMap params) throws Exception{
48 46
        //拼接接口地址
49
        String IOT_URL=UrlAddress.IOT_URL+"device";
50
        Map map = HttpURLConnectionUtil.iotCallMothod(params, IOT_URL);
47
        //String IOT_URL=UrlAddress.IOT_URL+"device";
48
        //Map map = HttpURLConnectionUtil.iotCallMothod(params, IOT_URL);
51 49
        return 1;
52 50
    }
53 51
@ -55,24 +53,24 @@ public class EquipmentManageServiceImpl implements EquipmentManageService {
55 53
    public boolean deleteEquipmentInfo(JMap params) throws Exception{
56 54
57 55
        //拼接接口地址
58
        String IOT_URL=UrlAddress.IOT_URL+"device";
59
        Map map = HttpURLConnectionUtil.iotCallMothod(params, IOT_URL);
56
        //String IOT_URL=UrlAddress.IOT_URL+"device";
57
        //Map map = HttpURLConnectionUtil.iotCallMothod(params, IOT_URL);
60 58
        return true;
61 59
    }
62 60
63 61
    @Override
64 62
    public boolean deleteEquipmentsInfo(JMap params) throws Exception {
65 63
        //拼接接口地址
66
        String IOT_URL=UrlAddress.IOT_URL+"device";
67
        Map map = HttpURLConnectionUtil.iotCallMothod(params, IOT_URL);
64
        //String IOT_URL=UrlAddress.IOT_URL+"device";
65
        //Map map = HttpURLConnectionUtil.iotCallMothod(params, IOT_URL);
68 66
        return false;
69 67
    }
70 68
71 69
    @Override
72 70
    public boolean importEquipmentInfo(JMap params) throws Exception {
73 71
        //拼接接口地址
74
        String IOT_URL=UrlAddress.IOT_URL+"device";
75
        Map map = HttpURLConnectionUtil.iotCallMothod(params, IOT_URL);
72
        //String IOT_URL=UrlAddress.IOT_URL+"device";
73
        //Map map = HttpURLConnectionUtil.iotCallMothod(params, IOT_URL);
76 74
        return false;
77 75
    }
78 76

+ 29 - 32
ebc-sea-platform/src/main/java/com/ai/ipu/server/service/impl/GisTokenServiceImpl.java

@ -1,43 +1,40 @@
1 1
package com.ai.ipu.server.service.impl;
2 2
3
import com.ai.ipu.data.JMap;
4
import com.ai.ipu.server.dao.interfaces.TrackAnalysisDao;
5
import com.ai.ipu.server.model.UrlAddress;
6
import com.ai.ipu.server.service.interfaces.GisTokenService;
7
import com.ai.ipu.server.service.interfaces.TrackAnalysisService;
8
import com.ai.ipu.server.util.HttpURLConnectionUtil;
9
import com.alibaba.fastjson.JSON;
10
import com.github.pagehelper.PageInfo;
3
import java.nio.charset.Charset;
4
import java.util.HashMap;
5
import java.util.Map;
6
11 7
import org.slf4j.Logger;
12 8
import org.slf4j.LoggerFactory;
13
import org.springframework.beans.factory.annotation.Autowired;
14 9
import org.springframework.beans.factory.annotation.Value;
15 10
import org.springframework.stereotype.Service;
16 11
17
import java.util.HashMap;
18
import java.util.Map;
19
12
import com.ai.ipu.server.model.UrlAddress;
13
import com.ai.ipu.server.service.interfaces.GisTokenService;
14
import com.ai.ipu.server.util.HttpServiceUtil;
15
import com.alibaba.fastjson.JSON;
20 16
21 17
@Service
22 18
public class GisTokenServiceImpl implements GisTokenService {
23
    Logger logger = LoggerFactory.getLogger(GisTokenServiceImpl.class);
24
25
    @Value("${aap.gis.userName}")
26
    private String gisUserName;
27
28
    @Value("${aap.gis.passwd}")
29
    private String gisPasswd;
30
31
32
    @Override
33
    public Map<String, Object> queryGisToken() {
34
        Map<String,String> mapParams=new HashMap<>();
35
        HashMap<Object, Object> requestParams = new HashMap<>();
36
        requestParams.put("userName", gisUserName);
37
        requestParams.put("passwd", gisPasswd);
38
        String  requestParamsJson= JSON.toJSONString(requestParams);
39
        String resultJson = HttpURLConnectionUtil.endoPost(UrlAddress.GIS_TOKEN, requestParamsJson, mapParams);
40
        Map<String,Object> resultMap = JSON.parseObject(resultJson, Map.class);
41
        return resultMap;
42
    }
19
	Logger logger = LoggerFactory.getLogger(GisTokenServiceImpl.class);
20
21
	@Value("${aap.gis.userName}")
22
	private String gisUserName;
23
24
	@Value("${aap.gis.passwd}")
25
	private String gisPasswd;
26
27
	@Override
28
	public Map<String, Object> queryGisToken() {
29
		Map<String, String> mapParams = new HashMap<>();
30
		HashMap<Object, Object> requestParams = new HashMap<>();
31
		requestParams.put("userName", gisUserName);
32
		requestParams.put("passwd", gisPasswd);
33
34
		Charset charset = Charset.forName("utf-8");
35
		String resultJson = HttpServiceUtil.senendPost(UrlAddress.GIS_TOKEN, mapParams, charset);
36
37
		Map<String, Object> resultMap = JSON.parseObject(resultJson, Map.class);
38
		return resultMap;
39
	}
43 40
}

+ 10 - 4
ebc-sea-platform/src/main/java/com/ai/ipu/server/service/interfaces/DeviceManageService.java

@ -1,15 +1,21 @@
1 1
package com.ai.ipu.server.service.interfaces;
2 2
3
import java.util.Map;
4
3 5
import com.ai.ipu.data.JMap;
4 6
import com.github.pagehelper.PageInfo;
5 7
6 8
public interface DeviceManageService {
7 9
8
    PageInfo queryDeviceInfo(JMap params) throws Exception;
10
	PageInfo queryDeviceInfo(JMap params) throws Exception;
11
12
	Map<String, String> addDeviceInfo(JMap params) throws Exception;
13
14
	Map<String, String> modifyDeviceInfo(JMap params) throws Exception;
9 15
10
    int modifyDeviceInfo(JMap params) throws Exception;
16
	Map<String, String> deleteDeviceInfo(JMap params) throws Exception;
11 17
12
    int addDeviceInfo(JMap params) throws Exception;
18
	boolean bindDevice(JMap params) throws Exception;
13 19
14
    boolean deleteDeviceXyInfo(JMap params) throws Exception;
20
	boolean unbindDevice(JMap params) throws Exception;
15 21
}

+ 21 - 0
ebc-sea-platform/src/main/java/com/ai/ipu/server/util/EbcConstant.java

@ -0,0 +1,21 @@
1
package com.ai.ipu.server.util;
2
3
/**
4
 * 业务常量
5
 * @author konghl@asiainfo.com
6
 * 2020-10-20
7
 */
8
public class EbcConstant {
9
	// 终端的产品id
10
	public static final String beidouDevice_product_id = "57700004344";
11
	
12
	// 终端的名称前缀
13
	public static final String beidouDevice_name = "康派北斗定位器";
14
15
	// 终端和人员绑定
16
	public static final String bind_device_type_user = "1";
17
18
	// 终端和船舶绑定
19
	public static final String bind_device_type_ship = "2";
20
21
}

+ 290 - 0
ebc-sea-platform/src/main/java/com/ai/ipu/server/util/HttpServiceUtil.java

@ -0,0 +1,290 @@
1
package com.ai.ipu.server.util;
2
3
import java.io.BufferedReader;
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.io.InputStreamReader;
7
import java.io.UnsupportedEncodingException;
8
import java.net.HttpURLConnection;
9
import java.net.URL;
10
import java.net.URLEncoder;
11
import java.nio.charset.Charset;
12
import java.util.Iterator;
13
import java.util.Map;
14
import java.util.Set;
15
16
import org.apache.http.HttpEntity;
17
import org.apache.http.HttpStatus;
18
import org.apache.http.client.ClientProtocolException;
19
import org.apache.http.client.HttpClient;
20
import org.apache.http.client.config.RequestConfig;
21
import org.apache.http.client.methods.CloseableHttpResponse;
22
import org.apache.http.client.methods.HttpGet;
23
import org.apache.http.client.methods.HttpPost;
24
import org.apache.http.client.methods.HttpPut;
25
import org.apache.http.entity.StringEntity;
26
import org.apache.http.entity.mime.MultipartEntityBuilder;
27
import org.apache.http.impl.client.CloseableHttpClient;
28
import org.apache.http.impl.client.HttpClients;
29
import org.apache.http.protocol.HTTP;
30
import org.apache.http.util.EntityUtils;
31
import org.slf4j.Logger;
32
import org.slf4j.LoggerFactory;
33
34
import com.ailk.common.BaseException;
35
import com.alibaba.fastjson.JSONObject;
36
37
import lombok.extern.slf4j.Slf4j;
38
39
/**
40
 * http服务请求工具类
41
 *
42
 * @author chencai
43
 */
44
@Slf4j
45
public class HttpServiceUtil {
46
	static Logger log = LoggerFactory.getLogger(HttpServiceUtil.class);
47
48
	private static final String HTTP_CONTENT_TYPE_JSON = "application/json; charset=utf-8";
49
50
	public static String buildUrl(Map<String, String> paramMap, String serviceUrl) {
51
		String url = null;
52
		StringBuffer urlString = new StringBuffer();
53
		urlString.append(serviceUrl);
54
55
		if (!paramMap.isEmpty()) {
56
			// 参数列表不为空,地址尾部增加'?'
57
			urlString.append('?');
58
			// 拼接参数
59
			Set<Map.Entry<String, String>> entrySet = paramMap.entrySet();
60
			for (Map.Entry<String, String> entry : entrySet) {
61
				try {
62
					urlString.append(entry.getKey()).append('=').append(URLEncoder.encode(entry.getValue(), "UTF-8"))
63
							.append('&');
64
				} catch (UnsupportedEncodingException e) {
65
					log.error(" Exception: " + e);
66
				}
67
			}
68
			// 去掉最后一个字符“&”
69
			url = urlString.substring(0, urlString.length() - 1);
70
		}
71
		return url;
72
	}
73
74
	public static String sendRequest(String url) {
75
		InputStream inputStream = null;
76
		BufferedReader bufferedReader = null;
77
		HttpURLConnection httpURLConnection = null;
78
		try {
79
			log.error("It's not error. request url: " + url);
80
			URL requestURL = new URL(url);
81
			// 获取连接
82
			httpURLConnection = (HttpURLConnection) requestURL.openConnection();
83
			httpURLConnection.setConnectTimeout(10000); // 建立连接的超时时间,毫秒
84
			httpURLConnection.setReadTimeout(25000); // 获得返回的超时时间,毫秒
85
			httpURLConnection.setRequestMethod("GET");
86
			httpURLConnection.setRequestProperty("Content-type", "text/html;charset=UTF-8");
87
			httpURLConnection.setRequestProperty("Accept",
88
					"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
89
			// 通过输入流获取请求的内容
90
			inputStream = httpURLConnection.getInputStream();
91
			bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
92
			String temp = null;
93
			StringBuffer stringBuffer = new StringBuffer();
94
			// 循环读取返回的结果
95
			while ((temp = bufferedReader.readLine()) != null) {
96
				stringBuffer.append(temp);
97
			}
98
99
			return stringBuffer.toString();
100
		} catch (Exception e) {
101
			log.error("sendRequest Exception: " + e);
102
		} finally {
103
			// 断开连接
104
			if (httpURLConnection != null) {
105
				httpURLConnection.disconnect();
106
			}
107
			// 关闭流
108
			if (bufferedReader != null) {
109
				try {
110
					bufferedReader.close();
111
				} catch (IOException e) {
112
					log.error("bufferedReader Exception: " + e);
113
				}
114
			}
115
			if (inputStream != null) {
116
				try {
117
					inputStream.close();
118
				} catch (IOException e) {
119
					log.error("inputStream Exception: " + e);
120
				}
121
			}
122
		}
123
		return null;
124
	}
125
126
	public static String sendPostRequest(String url, Map<String, String> map, String encoding) {
127
		String retStr = "";
128
		try {
129
			retStr = sendPostRequest(url, map, encoding, 0, 0);
130
		} catch (Exception ex) {
131
			log.error("sendPostRequest error: " + ex);
132
		}
133
134
		return retStr;
135
	}
136
137
	public static String sendPostRequest(String url, Map<String, String> map, String encoding, int ebossConnectTimeout,
138
			int ebossServiceTimeout) throws BaseException {
139
		CloseableHttpClient httpClient = HttpClients.createDefault();
140
		HttpPost httpPost = new HttpPost(url);
141
		String body = "";
142
143
		try {
144
			MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
145
			if (map != null) {
146
				for (Map.Entry<String, String> entry : map.entrySet()) {
147
					multipartEntityBuilder.addTextBody(entry.getKey(), entry.getValue());
148
				}
149
			}
150
151
			log.debug("ebossConnectTimeout:" + ebossConnectTimeout);
152
			log.debug("ebossServiceTimeout:" + ebossServiceTimeout);
153
154
			httpPost.setEntity(multipartEntityBuilder.build());
155
			if (ebossConnectTimeout != 0 && ebossServiceTimeout != 0) {
156
				RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(ebossServiceTimeout)
157
						.setConnectTimeout(ebossConnectTimeout).build();// 设置请求和传输超时时间
158
				httpPost.setConfig(requestConfig);
159
			}
160
161
			CloseableHttpResponse response = httpClient.execute(httpPost);
162
163
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
164
				HttpEntity entity = response.getEntity();
165
				if (entity != null) {
166
					// 按指定编码转换结果实体为String类型
167
					body = EntityUtils.toString(entity, encoding);
168
				}
169
				EntityUtils.consume(entity);
170
			}
171
		} catch (ClientProtocolException e) {
172
			log.error("ClientProtocolException Exception: " + e);
173
		} catch (UnsupportedEncodingException e) {
174
			log.error("UnsupportedEncodingException Exception: " + e);
175
		} catch (IOException e) {
176
			log.error("IOException Exception: " + e);
177
			// throw new BaseException("10", "调用Eboss超时");
178
		} finally {
179
			// 关闭连接,释放资源
180
			try {
181
				httpClient.close();
182
			} catch (IOException e) {
183
				log.error("httpClient Exception: " + e);
184
			}
185
		}
186
187
		return body;
188
	}
189
190
	public static String sendGet(String url, Charset encoding) {
191
		HttpClient httpClient = HttpClients.createDefault();
192
		String resp = "";
193
		HttpGet httpGet = new HttpGet(url);
194
		httpGet.addHeader(HTTP.CONTENT_TYPE, HTTP_CONTENT_TYPE_JSON);
195
		CloseableHttpResponse response = null;
196
		try {
197
			response = (CloseableHttpResponse) httpClient.execute(httpGet);
198
		} catch (IOException e) {
199
			log.error("请求错误");
200
		}
201
		return responseEx(httpClient, response, encoding);
202
	}
203
204
	public static String sendPost(String url, Map<String, String> params, Charset encoding) {
205
		HttpClient httpClient = HttpClients.createDefault();
206
		String resp = "";
207
		HttpPost httpPost = new HttpPost(url);
208
		httpPost.addHeader(HTTP.CONTENT_TYPE, HTTP_CONTENT_TYPE_JSON);
209
		if (params != null && params.size() > 0) {
210
			StringEntity se = new StringEntity(JSONObject.toJSONString(params), encoding);
211
			httpPost.setEntity(se);
212
		}
213
		CloseableHttpResponse response = null;
214
		try {
215
			response = (CloseableHttpResponse) httpClient.execute(httpPost);
216
		} catch (IOException e) {
217
			log.error("sendPost Exception: ", e.getMessage());
218
		}
219
		return responseEx(httpClient, response, encoding);
220
	}
221
222
	public static String sendPost(String url, Map<String, String> params, Charset encoding,
223
			Map<String, String> headerMap) {
224
		HttpClient httpClient = HttpClients.createDefault();
225
		String resp = "";
226
		HttpPost httpPost = new HttpPost(url);
227
228
		Iterator<String> iter = headerMap.keySet().iterator();
229
		String key = "";
230
		String value = "";
231
		while (iter.hasNext()) {
232
			key = iter.next();
233
			value = headerMap.get(key);
234
			httpPost.setHeader(key, value);
235
		}
236
237
		httpPost.addHeader(HTTP.CONTENT_TYPE, HTTP_CONTENT_TYPE_JSON);
238
		if (params != null && params.size() > 0) {
239
			StringEntity se = new StringEntity(JSONObject.toJSONString(params), encoding);
240
			httpPost.setEntity(se);
241
		}
242
		CloseableHttpResponse response = null;
243
		try {
244
			response = (CloseableHttpResponse) httpClient.execute(httpPost);
245
		} catch (IOException e) {
246
			log.error("sendPost Exception: ", e.getMessage());
247
		}
248
		return responseEx(httpClient, response, encoding);
249
	}
250
251
	public static String sendPut(String url, Map<String, String> params, Charset encoding) {
252
		HttpClient httpClient = HttpClients.createDefault();
253
		String resp = "";
254
		HttpPut httpPut = new HttpPut(url);
255
		httpPut.addHeader(HTTP.CONTENT_TYPE, HTTP_CONTENT_TYPE_JSON);
256
		if (params != null && params.size() > 0) {
257
			StringEntity se = new StringEntity(JSONObject.toJSONString(params), encoding);
258
			httpPut.setEntity(se);
259
		}
260
		CloseableHttpResponse response = null;
261
		try {
262
			response = (CloseableHttpResponse) httpClient.execute(httpPut);
263
		} catch (IOException e) {
264
			log.error("请求错误");
265
		}
266
267
		return responseEx(httpClient, response, encoding);
268
	}
269
270
	private static String responseEx(HttpClient httpClient, CloseableHttpResponse response, Charset encoding) {
271
		String resp = "";
272
		try {
273
			if (response != null && 200 == response.getStatusLine().getStatusCode()) {
274
				resp = EntityUtils.toString(response.getEntity(), encoding);
275
			}
276
		} catch (Exception e) {
277
			log.error(e.getMessage(), e);
278
		} finally {
279
			if (response != null) {
280
				try {
281
					response.close();
282
				} catch (IOException e) {
283
					log.error(e.getMessage(), e);
284
				}
285
			}
286
		}
287
		return resp;
288
	}
289
290
}

+ 128 - 253
ebc-sea-platform/src/main/java/com/ai/ipu/server/util/HttpURLConnectionUtil.java

@ -1,20 +1,19 @@
1 1
package com.ai.ipu.server.util;
2 2
3
import java.nio.charset.Charset;
4
import java.util.HashMap;
5
import java.util.Iterator;
6
import java.util.Map;
7
import java.util.Set;
8
import java.util.concurrent.ConcurrentHashMap;
3 9
4
import com.ai.ipu.data.JMap;
5
import com.ai.ipu.server.model.UrlAddress;
6
import com.alibaba.fastjson.JSON;
7
import com.sun.istack.internal.Nullable;
8 10
import org.springframework.beans.factory.annotation.Value;
9 11
import org.springframework.stereotype.Component;
10 12
11
import java.io.*;
12
import java.net.HttpURLConnection;
13
import java.net.MalformedURLException;
14
import java.net.URL;
15
import java.net.URLConnection;
16
import java.util.*;
17
import java.util.concurrent.ConcurrentHashMap;
13
import com.ai.ipu.basic.log.ILogger;
14
import com.ai.ipu.basic.log.IpuLoggerFactory;
15
import com.ai.ipu.server.model.UrlAddress;
16
import com.alibaba.fastjson.JSON;
18 17
19 18
/**
20 19
 *
@ -23,247 +22,123 @@ import java.util.concurrent.ConcurrentHashMap;
23 22
@Component
24 23
public class HttpURLConnectionUtil {
25 24
26
    private static String userCode;
27
    private static String passWord;
28
29
    @Value("${aap.iot.userCode}")
30
    public void setUserCode(String userCode) {
31
        HttpURLConnectionUtil.userCode = userCode;
32
    }
33
34
    @Value("${aap.iot.passWord}")
35
    public void setPassWord(String passWord) {
36
        HttpURLConnectionUtil.passWord = passWord;
37
    }
38
39
    //定义静态存储map空间存放sign与sessionId
40
    private volatile static Map<String, String> cacheMap = new ConcurrentHashMap<String, String>();// 缓存map
41
42
    //set
43
    public static void setMapCache(Map<String, String> map) {
44
        Set<String> set = map.keySet();
45
        Iterator<String> it = set.iterator();
46
        while (it.hasNext()) {
47
            String key = it.next();
48
            cacheMap.put(key, map.get(key));
49
        }
50
    }
51
    //get
52
    public static Map<String, String> getMapCache() {
53
54
        return cacheMap;
55
    }
56
    //清除cache
57
    public static void clear(){
58
        cacheMap.clear();
59
    }
60
61
    /**
62
     * Http get请求
63
     * @param httpUrl 连接
64
     * @return 响应数据
65
     */
66
    public static String doGet(String httpUrl){
67
        //链接
68
        HttpURLConnection connection = null;
69
        InputStream is = null;
70
        BufferedReader br = null;
71
        StringBuffer result = new StringBuffer();
72
        try {
73
            //创建连接
74
            URL url = new URL(httpUrl);
75
            connection = (HttpURLConnection) url.openConnection();
76
            //设置请求方式
77
            connection.setRequestMethod("GET");
78
            //设置连接超时时间
79
            connection.setReadTimeout(15000);
80
            //开始连接
81
            connection.connect();
82
            //获取响应数据
83
            if (connection.getResponseCode() == 200) {
84
                //获取返回的数据
85
                is = connection.getInputStream();
86
                if (null != is) {
87
                    br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
88
                    String temp = null;
89
                    while (null != (temp = br.readLine())) {
90
                        result.append(temp);
91
                    }
92
                }
93
            }
94
        } catch (IOException e) {
95
            e.printStackTrace();
96
        } finally {
97
            if (null != br) {
98
                try {
99
                    br.close();
100
                } catch (IOException e) {
101
                    e.printStackTrace();
102
                }
103
            }
104
            if (null != is) {
105
                try {
106
                    is.close();
107
                } catch (IOException e) {
108
                    e.printStackTrace();
109
                }
110
            }
111
            //关闭远程连接
112
            connection.disconnect();
113
        }
114
        return result.toString();
115
    }
116
117
    /**
118
     * Http post请求
119
     * @param httpUrl 连接
120
     * @param param 参数
121
     * @return
122
     */
123
    public static String doPost(String httpUrl, @Nullable String param, Map<String,String> pramMap) {
124
        StringBuffer result = new StringBuffer();
125
        //连接
126
        HttpURLConnection connection = null;
127
        OutputStream os = null;
128
        InputStream is = null;
129
        BufferedReader br = null;
130
        try {
131
            //创建连接对象
132
            URL url = new URL(httpUrl);
133
            //创建连接
134
            connection = (HttpURLConnection) url.openConnection();
135
            //设置请求方法
136
            connection.setRequestMethod("POST");
137
            //设置连接超时时间
138
            connection.setConnectTimeout(15000);
139
            //设置读取超时时间
140
            connection.setReadTimeout(15000);
141
            //DoOutput设置是否向httpUrlConnection输出,DoInput设置是否从httpUrlConnection读入,此外发送post请求必须设置这两个
142
            //设置是否可读取
143
            connection.setDoOutput(true);
144
            connection.setDoInput(true);
145
            //设置通用的请求属性
146
            connection.setRequestProperty("accept", "*/*");
147
            connection.setRequestProperty("connection", "Keep-Alive");
148
            connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
149
            connection.setRequestProperty("Content-Type", "application/json;charset=utf-8");
150
151
            //拼装参数
152
            if (null != param && !param.equals("")) {
153
                //设置参数
154
                os = connection.getOutputStream();
155
                //拼装参数
156
                os.write(param.getBytes("UTF-8"));
157
            }
158
            //设置权限
159
            //设置请求头等
160
            if(pramMap!=null&&pramMap.size()>0){
161
                connection.setRequestProperty("sign", pramMap.get("sign"));
162
                connection.setRequestProperty("session_id", pramMap.get("session_id"));
163
            }
164
            //开启连接
165
            connection.connect();
166
            //读取响应
167
            if (connection.getResponseCode() == 200) {
168
                is = connection.getInputStream();
169
                if (null != is) {
170
                    br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
171
                    String temp = null;
172
                    while (null != (temp = br.readLine())) {
173
                        result.append(temp);
174
                        result.append("\r\n");
175
                    }
176
                }
177
            }
178
179
        } catch (MalformedURLException e) {
180
            e.printStackTrace();
181
        } catch (IOException e) {
182
            e.printStackTrace();
183
        } finally {
184
            //关闭连接
185
            if(br!=null){
186
                try {
187
                    br.close();
188
                } catch (IOException e) {
189
                    e.printStackTrace();
190
                }
191
            }
192
            if(os!=null){
193
                try {
194
                    os.close();
195
                } catch (IOException e) {
196
                    e.printStackTrace();
197
                }
198
            }
199
            if(is!=null){
200
                try {
201
                    is.close();
202
                } catch (IOException e) {
203
                    e.printStackTrace();
204
                }
205
            }
206
            //关闭连接
207
            connection.disconnect();
208
        }
209
        return result.toString();
210
    }
211
212
213
    /**
214
     * 调用登录接口获取sessionId与sign
215
     * @return
216
     */
217
    public static Map<String,String> iotLogin() {
218
        HashMap<String, String> paramHashMap = new HashMap<>();
219
        //调用登录接口获取sessionId与sign
220
        //设置登录接口参数
221
        String loginParam=" {\"userCode\": "+userCode+",\"passWord\":"+passWord +"}";
222
        String loginResult =doPost(UrlAddress.IOT_LOGIN, loginParam,paramHashMap);
223
        Map mapType = JSON.parseObject(loginResult,Map.class);
224
        Map result = (Map) mapType.get("result");
225
226
        if ((int)mapType.get("resultCode")==0){
227
            //将数据存到
228
            HttpURLConnectionUtil.setMapCache(result);
229
        }
230
        return cacheMap;
231
    }
232
    /**
233
     * 调用北向接口方法
234
     * @return
235
     */
236
    public static Map iotCallMothod(JMap params, String str) throws Exception {
237
        //调用北向服务的接口
238
        //1.在缓存中获取sessionId与sign
239
        Map<String, String> mapCache = HttpURLConnectionUtil.getMapCache();
240
        if(mapCache.isEmpty()||mapCache.get("sign")==null||mapCache.get("sessionId")==null){
241
            //2.如果没有调用登录接口从新获取
242
            HttpURLConnectionUtil.iotLogin();
243
        }
244
        //3.调用北向服务接口
245
        //(1)将参数转为json
246
        String  jmapParam= JSON.toJSONString(params);
247
        //(2)调用接口
248
        String resultJson = HttpURLConnectionUtil.doPost(str, jmapParam,mapCache);
249
        //(3)将参数转为json
250
        Map<String,String> resultMap = JSON.parseObject(resultJson, Map.class);
251
        //判断是否调用成功
252
        if("0".equals(resultMap.get("resultCode"))){
253
            //成功返回
254
            return resultMap;
255
        }else{
256
            //4.调用不成功过期,清除缓存,在调用登录接口
257
            HttpURLConnectionUtil.clear();
258
            HttpURLConnectionUtil.iotLogin();
259
            //5.调用北向服务接口
260
            //(2)调用接口
261
            String fianlresultJson = HttpURLConnectionUtil.doPost(str, jmapParam,mapCache);
262
            //(3)将json转为f返回值
263
            Map<String,String> fianlresultMap = JSON.parseObject(fianlresultJson, Map.class);
264
            //返回
265
            return fianlresultMap;
266
        }
267
    }
25
	private static final ILogger logger = IpuLoggerFactory.createLogger(HttpURLConnectionUtil.class);
26
27
	private static String userCode;
28
	private static String passWord;
29
30
	@Value("${aap.iot.userCode}")
31
	public void setUserCode(String userCode) {
32
		HttpURLConnectionUtil.userCode = userCode;
33
	}
34
35
	@Value("${aap.iot.passWord}")
36
	public void setPassWord(String passWord) {
37
		HttpURLConnectionUtil.passWord = passWord;
38
	}
39
40
	// 定义静态存储map空间存放sign与sessionId
41
	private volatile static Map<String, String> cacheMap = new ConcurrentHashMap<String, String>();// 缓存map
42
43
	// set
44
	public static void setMapCache(Map<String, String> map) {
45
		Set<String> set = map.keySet();
46
		Iterator<String> it = set.iterator();
47
		while (it.hasNext()) {
48
			String key = it.next();
49
			cacheMap.put(key, map.get(key));
50
		}
51
	}
52
53
	// get
54
	public static Map<String, String> getMapCache() {
55
56
		return cacheMap;
57
	}
58
59
	// 清除cache
60
	public static void clear() {
61
		cacheMap.clear();
62
	}
63
64
	/**
65
	 * 调用登录接口获取sessionId与sign
66
	 * 
67
	 * @return
68
	 */
69
	public static Map<String, String> iotLogin() {
70
		logger.debug("登录北向接口");
71
72
		// 调用登录接口获取sessionId与sign
73
		HashMap<String, String> loginParamMap = new HashMap<>();
74
		loginParamMap.put("userCode", userCode);
75
		loginParamMap.put("passWord", passWord);
76
77
		// 设置字符集
78
		Charset charset = Charset.forName("utf-8");
79
80
		// 调用登录接口
81
		String loginResult = HttpServiceUtil.sendPost(UrlAddress.IOT_LOGIN, loginParamMap, charset);
82
83
		Map mapType = JSON.parseObject(loginResult, Map.class);
84
		Map result = (Map) mapType.get("result");
85
86
		if ("0".equals(String.valueOf(mapType.get("resultCode")))) {
87
			logger.info("登录北向接口成功");
88
			// 将数据存到缓存中
89
			HttpURLConnectionUtil.setMapCache(result);
90
		} else {
91
			logger.info("登录北向接口失败");
92
		}
93
		return cacheMap;
94
	}
95
96
	/**
97
	 * 调用北向接口方法
98
	 * 
99
	 * @return
100
	 */
101
	public static Map<String, String> iotCallMothod(String url, Map<String, String> params) throws Exception {
102
		// 调用北向服务的接口
103
		logger.debug("调用北向接口");
104
105
		// 1.在缓存中获取sessionId与sign
106
		Map<String, String> mapCache = HttpURLConnectionUtil.getMapCache();
107
		if (mapCache.isEmpty() || mapCache.get("sign") == null || mapCache.get("sessionId") == null) {
108
			// 2.如果没有调用登录接口从新获取
109
			HttpURLConnectionUtil.iotLogin();
110
		}
111
112
		// 3.调用北向服务接口
113
		// 设置字符集
114
		Charset charset = Charset.forName("utf-8");
115
		// (1)调用接口
116
		String resultJson = HttpServiceUtil.sendPost(url, params, charset);
117
		// (2)将参数转为Map<String,String>【将返回值统一为String】
118
		Map<String, String> resultMap = JSON.parseObject(resultJson, Map.class);
119
120
		// 登录超时,需重新登录
121
		if ("登录超时".equals(resultMap.get("resultMsg"))) {
122
			logger.info("调用北向接口失败,需重新登录");
123
			// 4.调用不成功可能是登录过期
124
			// (1)清除缓存
125
			HttpURLConnectionUtil.clear();
126
			// (2)重新登录
127
			HttpURLConnectionUtil.iotLogin();
128
			// (3)再次调用接口
129
			String fianlresultJson = HttpServiceUtil.sendPost(url, params, charset);
130
			// (4)获取返回值
131
			resultMap = JSON.parseObject(fianlresultJson, Map.class);
132
		}
133
134
		// 判断是否调用成功
135
		if ("0".equals(resultMap.get("resultCode"))) {
136
			logger.info("调用北向接口成功");
137
		} else {
138
			logger.info("调用北向接口失败");
139
		}
140
141
		return resultMap;
142
	}
268 143
269 144
}

+ 76 - 0
ebc-sea-platform/src/main/java/com/ai/ipu/server/util/ProductEnum.java

@ -0,0 +1,76 @@
1
package com.ai.ipu.server.util;
2
3
import java.util.HashMap;
4
import java.util.Map;
5
6
/**
7
 * 设备类型枚举
8
 * 
9
 * @author konghl@asiainfo.com 
10
 * 2020-10-19
11
 */
12
public enum ProductEnum {
13
	// 船舶
14
	ship("001", "船舶", 1),
15
	// 风机
16
	fan("002", "风机", 2),
17
	// 升压站
18
	booster("003", "升压站", 2),
19
	// 测风塔
20
	anemometer("004", "测风塔", 2);
21
22
	private String productId;
23
	private String productName;
24
	private int productType;
25
26
	private ProductEnum(String productId, String productName, int productType) {
27
		this.productId = productId;
28
		this.productName = productName;
29
		this.productType = productType;
30
	}
31
32
	public String getProductId() {
33
		return productId;
34
	}
35
36
	public String getProductName() {
37
		return productName;
38
	}
39
40
	public int getProductType() {
41
		return productType;
42
	}
43
44
	/**
45
	 * 根据类型获取对应的产品类型列表
46
	 * 
47
	 * @param type 类型(1:绑定终端,2:不绑定终端)
48
	 * @return
49
	 */
50
	public static Map<String, Object> getProductByType(int type) {
51
		Map<String, Object> map = new HashMap<String, Object>();
52
53
		for (ProductEnum productEnum : ProductEnum.values()) {
54
			if (productEnum.getProductType() == type) {
55
				map.put("id", productEnum.getProductId());
56
				map.put("name", productEnum.getProductName());
57
			}
58
		}
59
		return map;
60
	}
61
62
	/**
63
	 * 获取所有的产品类型列表
64
	 * 
65
	 * @return
66
	 */
67
	public static Map<String, Object> getAllProduct() {
68
		Map<String, Object> map = new HashMap<String, Object>();
69
70
		for (ProductEnum productEnum : ProductEnum.values()) {
71
			map.put("id", productEnum.getProductId());
72
			map.put("name", productEnum.getProductName());
73
		}
74
		return map;
75
	}
76
}