import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders, HttpParams} from
'@angular/common/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/Rx';
import {Meter, HatItResponseModel} from '../_models/index';
import {InitHatResponseModel, MeterInfoResponseModel} from
'../_models/requestresp.model';
import {HttpErrorResponse} from '@angular/common/http/src/response';
import {AuthenticationService} from './authentication.service';
import {environment} from '../../environments/environment';
@Injectable()
export class DaqService {
private hatItUrl = environment.AMICommunicationServiceUrl;
private versionExt = 'hat/v3/'
constructor(private http: HttpClient,
private authService: AuthenticationService) {
}
initDaqMeterHat(meter: Meter) {
if (this.authService.isUserAuthenticated()) {
const url = this.hatItUrl + '/meter';
const params = new HttpParams()
// Auth Parameters
.set('uid', this.authService.username)
// Hat Options
.set('meterSerialNum', meter.MeterNumber)
.set('communicationStatus',
String(meter.CommunicationStatusChecked))
.set('lineSideVoltage', String(meter.LineSideChecked))
.set('loadSideVoltage', String(meter.LoadSideChecked))
.set('connectionStatus', String(meter.MeterStatusChecked))
.set('tsp', String(new Date()));
return this.http.post<InitHatResponseModel>(url, null, {
params: params
}).catch(this.handleInitError);
}
}
getDaqMeterResults(meter: Meter) {
const url = this.hatItUrl + 'hatit/result/';
const params = new HttpParams()
.set('token', String(meter.pingItResponse.token))
.set('tsp', String(new Date()));
return this.http.get<hatItResponseModel>(url, {
params: params
}).catch(this.handleResultsError);
}
getVersion() {
const url = this.hatItUrl + this.versionExt + 'hatit/version';
const params = new HttpParams()
.set('landId', this.authService.username)
.set('domain', 'NAM');
return this.http.get<string>(url, {
params: params
});
}
private handleInitError(error: HttpErrorResponse | any) {
const meterInfoResponse: MeterInfoResponseModel = new
MeterInfoResponseModel();
meterInfoResponse.errorMessage = error.error;
const hatItInitResponse: InitHatResponseModel = new
InitPingResponseModel(meterInfoResponse, 0);
return Observable.of(pingItInitResponse);
}
private handleResultsError(error: HttpErrorResponse | any) {
const hatItResponse: HatItResponseModel = new
HatItResponseModel(0);
hatItResponse.meterInfo.errorMessage = error.error;
return Observable.of(pingItResponse);
}
}
为什么我收到此错误?
HttpErrorResponse {headers: HttpHeaders, status: 400, statusText:
"OK", url: "https://emp-dev-api.duke-
energy.com/hat/v1/hatit/version?landId=somename&domain=NAM", ok:
false, …
error:
error:"Bad Request"exception:"org.springframework.web.bind.
MissingServletRequestParameterException"
message:"Required String parameter 'lanId' is not present"
path:"hatit/version" status:400 timestamp :1525301325947
请帮忙!我没有看到我在这里做错了什么,但我确信我可能会弄错,请帮忙!我一直收到错误,错误也无法读取未定义的长度属性。但它只在我构建时才这样做。所以我不确定为什么!如果有人看到这些错误,请随时提供帮助!