package com.iailab.module.device.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.iailab.common.enums.CommonConstant;
|
import com.iailab.module.data.api.IFeignDataApi;
|
import com.iailab.module.data.dto.FeignHttpApiDTO;
|
import com.iailab.framework.common.service.impl.BaseServiceImpl;
|
import com.iailab.common.utils.DateUtils;
|
import com.iailab.common.utils.HttpsRequest;
|
import com.iailab.module.device.dao.DeviceMainDao;
|
import com.iailab.module.device.dto.DeviceMainDTO;
|
import com.iailab.module.device.entity.DeviceMainEntity;
|
import com.iailab.module.device.service.DeviceMainService;
|
import lombok.extern.slf4j.Slf4j;
|
import javax.annotation.Resource;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.*;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年05月30日
|
*/
|
@Slf4j
|
@Service
|
public class DeviceMainServiceImpl extends BaseServiceImpl<DeviceMainDao, DeviceMainEntity> implements DeviceMainService {
|
|
private String HTTP_API_CODE = "Dev.DeviceMaintQuery";
|
|
@Resource
|
private IFeignDataApi feignDataApi;
|
|
@Resource
|
private HttpsRequest httpsRequest;
|
|
|
@Override
|
public Integer getCount(String devno, Date startTime, Date endTime) {
|
Integer result = 0;
|
Map<String, String> params = new HashMap<>(3);
|
params.put("devno", devno);
|
params.put("startdate", DateUtils.format(startTime));
|
params.put("enddate", DateUtils.format(endTime));
|
|
List<DeviceMainDTO> list = this.getList(params);
|
return list.size();
|
}
|
|
private List<DeviceMainDTO> getList(Map<String, String> params) {
|
List<DeviceMainDTO> result = new ArrayList<>();
|
FeignHttpApiDTO apiDTO = feignDataApi.getHttpApi(HTTP_API_CODE);
|
String responseStr = httpsRequest.doGet(apiDTO.getUrl(), params, "utf-8", "");
|
JSONObject responseObj = JSON.parseObject(responseStr);
|
if (!CommonConstant.STA_TRUE.equals(responseObj.get("sta").toString())) {
|
log.info("接口异常");
|
}
|
JSONArray dataArray = responseObj.getJSONArray(CommonConstant.ZX_RES);
|
if (CollectionUtils.isEmpty(dataArray)) {
|
return result;
|
}
|
return dataArray.toJavaList(DeviceMainDTO.class);
|
}
|
}
|