|
|
@ -1,24 +1,34 @@ |
|
|
|
package com.epmet.plugin.power.modules.hik.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.security.user.LoginUserUtil; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.plugin.power.dto.hik.HikCommunityInfoDTO; |
|
|
|
import com.epmet.plugin.power.modules.hik.dao.HikCommunityInfoDao; |
|
|
|
import com.epmet.plugin.power.modules.hik.dao.HikDeviceInfoDao; |
|
|
|
import com.epmet.plugin.power.dto.hik.HikDeviceInfoDTO; |
|
|
|
import com.epmet.plugin.power.modules.hik.entity.HikCommunityInfoEntity; |
|
|
|
import com.epmet.plugin.power.modules.hik.entity.HikDeviceInfoEntity; |
|
|
|
import com.epmet.plugin.power.modules.hik.redis.HikDeviceInfoRedis; |
|
|
|
import com.epmet.plugin.power.modules.hik.service.HikDeviceInfoService; |
|
|
|
import com.epmet.plugin.power.modules.utils.HkDeviceUtil; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* 海康设备信息 |
|
|
@ -32,6 +42,15 @@ public class HikDeviceInfoServiceImpl extends BaseServiceImpl<HikDeviceInfoDao, |
|
|
|
@Autowired |
|
|
|
private HikDeviceInfoRedis hikDeviceInfoRedis; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private HkDeviceUtil hkDeviceUtil; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private LoginUserUtil loginUserUtil; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private HikCommunityInfoDao hikCommunityInfoDao; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<HikDeviceInfoDTO> page(Map<String, Object> params) { |
|
|
|
IPage<HikDeviceInfoEntity> page = baseDao.selectPage( |
|
|
@ -84,4 +103,66 @@ public class HikDeviceInfoServiceImpl extends BaseServiceImpl<HikDeviceInfoDao, |
|
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@Override |
|
|
|
public Result getDeviceList() { |
|
|
|
// 请求路径
|
|
|
|
String url = "https://api2.hik-cloud.com/api/v1/estate/devices/actions/listByCommunityId"; |
|
|
|
|
|
|
|
// token
|
|
|
|
String token =hkDeviceUtil.getAccessToken(); |
|
|
|
token = "Bearer ".concat(token); |
|
|
|
|
|
|
|
Map<String, String> headerMap = new HashMap<>(4); |
|
|
|
headerMap.put("Authorization",token); |
|
|
|
|
|
|
|
// 获取社区列表
|
|
|
|
List<HikCommunityInfoDTO> communityList = hikCommunityInfoDao.getCommunityInfoAll(); |
|
|
|
|
|
|
|
for(HikCommunityInfoDTO hikCommunityInfoDTO : communityList){ |
|
|
|
// 参数
|
|
|
|
Integer pageNo = 1; |
|
|
|
Integer pageSize = 1000; |
|
|
|
Map<String, Object> paramsMap = new HashMap<>(4); |
|
|
|
paramsMap.put("pageNo", pageNo); |
|
|
|
paramsMap.put("pageSize", pageSize); |
|
|
|
paramsMap.put("communityId",hikCommunityInfoDTO.getCommunityId()); |
|
|
|
JSONArray jsonArray = getJSONArrayListPOST(url,JSON.toJSONString(paramsMap),headerMap,"请求设备列表信息失败"); |
|
|
|
|
|
|
|
List<HikDeviceInfoEntity> entityList = new ArrayList<HikDeviceInfoEntity>(); |
|
|
|
for (int i = 0; i < jsonArray.size(); i++) { |
|
|
|
JSONObject jsonObj = jsonArray.getJSONObject(i); |
|
|
|
// 转成对象实体
|
|
|
|
HikDeviceInfoEntity entity = JSONObject.toJavaObject(jsonObj ,HikDeviceInfoEntity.class); |
|
|
|
entity.setCustomerId(loginUserUtil.getLoginUserCustomerId() == null ? "0001" : loginUserUtil.getLoginUserCustomerId()); |
|
|
|
entityList.add(entity); |
|
|
|
} |
|
|
|
insertBatch(entityList); |
|
|
|
} |
|
|
|
|
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* sendGet请求 |
|
|
|
* @param url |
|
|
|
* @param jsonStrParam |
|
|
|
* @param headerMap |
|
|
|
* @param msg |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public JSONArray getJSONArrayListPOST(String url,String jsonStrParam,Map<String, String> headerMap,String msg){ |
|
|
|
// 请求接口
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSONAndHeader(url,jsonStrParam, headerMap).getData(); |
|
|
|
if (null == data) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), msg); |
|
|
|
} |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
|
|
|
|
JSONObject dataList = JSON.parseObject(toResult.get("data").toString()); |
|
|
|
|
|
|
|
JSONArray rows = JSONArray.parseArray(dataList.get("rows").toString()); |
|
|
|
|
|
|
|
return rows; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|