SUPPORT-8427: Add orgdata
This commit is contained in:
parent
3a430c93a8
commit
e0d18bbec2
3 changed files with 99 additions and 0 deletions
|
|
@ -1,9 +1,18 @@
|
|||
package esia.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import esia.model.Addresses;
|
||||
import esia.model.Contacts;
|
||||
import esia.model.EmployeeModel;
|
||||
import esia.model.OrganizationModel;
|
||||
import esia.service.EsiaAuthService;
|
||||
import esia.service.UlDataService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
|
@ -19,6 +28,9 @@ public class EsiaController {
|
|||
@Autowired
|
||||
private EsiaAuthService esiaAuthService;
|
||||
|
||||
@Autowired
|
||||
private UlDataService ulDataService;
|
||||
|
||||
@RequestMapping(value = "/esia/url")
|
||||
public String getEsiaUrl() {
|
||||
return esiaAuthService.generateAuthCodeUrl();
|
||||
|
|
@ -33,4 +45,59 @@ public class EsiaController {
|
|||
public void refreshToken(HttpServletRequest request, HttpServletResponse response) {
|
||||
esiaAuthService.getEsiaTokensByRefreshToken(request, response);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/esia/org")
|
||||
public Map<String, String> getOrgInfo(HttpServletRequest request) {
|
||||
String accessToken = null;
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (cookies != null) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if (cookie.getName().equals("access_token")) {
|
||||
accessToken = cookie.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, String> orgInfo = new HashMap<>();
|
||||
OrganizationModel organizationModel = ulDataService.getOrganizationModel(accessToken);
|
||||
EmployeeModel chiefEmployeeModel = ulDataService.getChiefEmployeeModel(accessToken);
|
||||
EmployeeModel employeeModel = ulDataService.getEmployeeModel(accessToken);
|
||||
orgInfo.put("empFullname",
|
||||
employeeModel.getPerson().getLastName() + " " + employeeModel.getPerson().getFirstName()
|
||||
+ " " + employeeModel.getPerson().getMiddleName()
|
||||
);
|
||||
orgInfo.put("empPosition", employeeModel.getPosition());
|
||||
orgInfo.put("fullName", organizationModel.getFullName());
|
||||
orgInfo.put("shortName", organizationModel.getShortName());
|
||||
Addresses addresses = organizationModel.getAddresses();
|
||||
if (addresses != null) {
|
||||
Arrays.stream(addresses.getElements()).forEach(addressModel -> {
|
||||
if (addressModel.getType().equals("OLG")) {
|
||||
orgInfo.put("olgAddress", addressModel.getAddressStr());
|
||||
}
|
||||
else if (addressModel.getType().equals("OPS")) {
|
||||
orgInfo.put("opsAddress", addressModel.getAddressStr());
|
||||
}
|
||||
} );
|
||||
}
|
||||
orgInfo.put("chiefFullname",
|
||||
chiefEmployeeModel.getPerson().getLastName() + " " + chiefEmployeeModel.getPerson()
|
||||
.getFirstName() + " " + chiefEmployeeModel.getPerson().getMiddleName()
|
||||
);
|
||||
orgInfo.put("chiefPosition", chiefEmployeeModel.getPosition());
|
||||
orgInfo.put("ogrn", organizationModel.getOgrn());
|
||||
orgInfo.put("kpp", organizationModel.getKpp());
|
||||
orgInfo.put("inn", organizationModel.getInn());
|
||||
Contacts contacts = organizationModel.getContacts();
|
||||
if (contacts != null) {
|
||||
Arrays.stream(contacts.getElements()).forEach(contactModel -> {
|
||||
if (contactModel.getType().equals("OPH") && contactModel.getVrfStu().equals("VERIFIED")) {
|
||||
orgInfo.put("mobile", contactModel.getValue());
|
||||
}
|
||||
else if (contactModel.getType().equals("OEM") && contactModel.getVrfStu().equals("VERIFIED")) {
|
||||
orgInfo.put("email", contactModel.getValue());
|
||||
}
|
||||
} );
|
||||
}
|
||||
return orgInfo;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
7
frontend/src/ts/esia/OrgData.ts
Normal file
7
frontend/src/ts/esia/OrgData.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import {Behavior, NotNull} from "@webbpm/base-package";
|
||||
|
||||
export class OrgData extends Behavior{
|
||||
|
||||
@NotNull()
|
||||
public dataId: string;
|
||||
}
|
||||
25
frontend/src/ts/esia/OrgDataRoot.ts
Normal file
25
frontend/src/ts/esia/OrgDataRoot.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import {AnalyticalScope, Behavior, Container, ControlWithValue} from "@webbpm/base-package";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {OrgData} from "./OrgData";
|
||||
|
||||
@AnalyticalScope(Container)
|
||||
export class OrgDataRoot extends Behavior{
|
||||
|
||||
private container: Container;
|
||||
|
||||
initialize() {
|
||||
super.initialize();
|
||||
this.container = this.getScript(Container);
|
||||
let orgScripts: OrgData[] = this.container.getScriptsInThisAndChildren(OrgData);
|
||||
let httpClient = this.injector.get(HttpClient);
|
||||
httpClient.get<Map<String, String>>("esia/org")
|
||||
.toPromise()
|
||||
.then(map => {
|
||||
for (let orgData of orgScripts) {
|
||||
let control: ControlWithValue = orgData.getScriptInObject(orgData.getObjectId(),
|
||||
'component.ControlWithValue');
|
||||
control.setValue(map.get(orgData.dataId))
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue