| | |
| | | import com.ruoyi.system.domain.CmsVehicleDeviceResponse; |
| | | import com.ruoyi.system.domain.CmsVehicleDeviceListResponse; |
| | | import com.ruoyi.system.domain.CmsVehicleLocationResponse; |
| | | import com.ruoyi.system.domain.CmsTrackDetailResponse; |
| | | import com.ruoyi.system.domain.SysGpsConfig; |
| | | import com.ruoyi.system.service.ICmsGpsCollectService; |
| | | import com.ruoyi.system.service.IGpsConfigService; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import java.util.Date; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | |
| | | /** |
| | | * CMS GPS采集服务实现 |
| | |
| | | } |
| | | |
| | | // 构建请求URL |
| | | String url = baseUrlConfig.getDomain() + "/StandardApiAction_getDeviceByVehicle.action?jsession=" + baseUrlConfig.getToken(); |
| | | StringBuilder url = new StringBuilder(); |
| | | url.append(baseUrlConfig.getDomain()) |
| | | .append("/StandardApiAction_getDeviceByVehicle.action?jsession=") |
| | | .append(baseUrlConfig.getToken()); |
| | | |
| | | if (vehicleId != null && !vehicleId.isEmpty()) { |
| | | url += "&vehiIdno=" + vehicleId; |
| | | url.append("&vehiIdno=").append(vehicleId); |
| | | } |
| | | |
| | | // 发送查询请求 |
| | | String response = HttpUtil.get(url,null); |
| | | String response = HttpUtils.sendGet(url.toString()); |
| | | |
| | | // 解析响应 |
| | | CmsVehicleDeviceListResponse deviceListResponse = JSONObject.parseObject(response, CmsVehicleDeviceListResponse.class); |
| | |
| | | throw new RuntimeException("获取车辆位置信息异常:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public CmsTrackDetailResponse queryTrackDetail(String devIdno, String begintime, String endtime, |
| | | Double distance, Integer parkTime, Integer geoaddress, Integer currentPage, |
| | | Integer pageRecords, Integer toMap) { |
| | | |
| | | try { |
| | | // 从数据库获取CMS配置 |
| | | SysGpsConfig baseUrlConfig = gpsConfigService.selectGpsConfigByKey("gpscms"); |
| | | if (baseUrlConfig == null) { |
| | | throw new RuntimeException("未配置CMS系统地址"); |
| | | } |
| | | |
| | | // 检查token是否过期 |
| | | if (baseUrlConfig.getTokenExpireTime() == null || |
| | | baseUrlConfig.getTokenExpireTime().before(new Date())) { |
| | | // token过期,重新登录 |
| | | login(baseUrlConfig.getUsername(), baseUrlConfig.getPassword()); |
| | | baseUrlConfig = gpsConfigService.selectGpsConfigByKey("gpscms"); |
| | | } |
| | | |
| | | // 构建请求URL |
| | | StringBuilder url = new StringBuilder(baseUrlConfig.getDomain()) |
| | | .append("/StandardApiAction_queryTrackDetail.action?jsession=") |
| | | .append(baseUrlConfig.getToken()) |
| | | .append("&devIdno=").append(devIdno) |
| | | .append("&begintime=").append(begintime) |
| | | .append("&endtime=").append(endtime); |
| | | |
| | | // 添加可选参数 |
| | | if (distance != null) { |
| | | url.append("&distance=").append(distance); |
| | | } |
| | | if (parkTime != null) { |
| | | url.append("&parkTime=").append(parkTime); |
| | | } |
| | | if (geoaddress != null) { |
| | | url.append("&geoaddress=").append(geoaddress); |
| | | } |
| | | if (currentPage != null) { |
| | | url.append("¤tPage=").append(currentPage); |
| | | } |
| | | if (pageRecords != null) { |
| | | url.append("&pageRecords=").append(pageRecords); |
| | | } |
| | | if (toMap != null) { |
| | | url.append("&toMap=").append(toMap); |
| | | } |
| | | |
| | | // 发送查询请求 |
| | | String response = HttpUtils.sendGet(url.toString()); |
| | | |
| | | // 解析响应 |
| | | CmsTrackDetailResponse trackResponse = JSONObject.parseObject(response, CmsTrackDetailResponse.class); |
| | | |
| | | if (trackResponse.getResult() == 0) { |
| | | log.info("获取设备历史轨迹成功,设备号:{}", devIdno); |
| | | } else { |
| | | log.error("获取设备历史轨迹失败,设备号:{}", devIdno); |
| | | } |
| | | |
| | | return trackResponse; |
| | | } catch (Exception e) { |
| | | log.error("获取设备历史轨迹异常,设备号:{}", devIdno, e); |
| | | throw new RuntimeException("获取设备历史轨迹异常:" + e.getMessage()); |
| | | } |
| | | } |
| | | } |