2019-10-04 04:45:02 +00:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
|
|
|
import { Actions, ofType, createEffect } from '@ngrx/effects';
|
|
|
|
|
|
|
|
import { of } from 'rxjs';
|
|
|
|
import { catchError, map, tap, switchMap } from 'rxjs/operators';
|
|
|
|
|
2019-10-07 04:07:52 +00:00
|
|
|
import {
|
|
|
|
dept,
|
|
|
|
deptSuccess,
|
|
|
|
deptFailure,
|
|
|
|
deptUser,
|
|
|
|
deptUserSuccess,
|
2019-12-26 08:34:52 +00:00
|
|
|
deptUserFailure,
|
|
|
|
myDeptUserSuccess
|
2019-10-07 04:07:52 +00:00
|
|
|
} from './actions';
|
2019-10-04 04:45:02 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
QueryProtocolService,
|
|
|
|
DeptInfo,
|
|
|
|
SSVC_TYPE_QUERY_DEPT_DATA,
|
|
|
|
SSVC_TYPE_QUERY_DEPT_RES,
|
2019-10-07 04:07:52 +00:00
|
|
|
DeptData,
|
|
|
|
UserInfoSS,
|
|
|
|
SSVC_TYPE_QUERY_DEPT_USER_DATA,
|
|
|
|
DeptUserData,
|
|
|
|
SSVC_TYPE_QUERY_DEPT_USER_RES,
|
|
|
|
DeptUserResponse
|
2019-10-04 04:45:02 +00:00
|
|
|
} from '@ucap-webmessenger/protocol-query';
|
|
|
|
|
|
|
|
import { Store } from '@ngrx/store';
|
2019-12-26 08:34:52 +00:00
|
|
|
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
|
|
|
import { KEY_LOGIN_RES_INFO } from '@app/types';
|
|
|
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
2019-10-04 04:45:02 +00:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class Effects {
|
|
|
|
dept$ = createEffect(
|
|
|
|
() => {
|
|
|
|
let departmentInfoList: DeptInfo[];
|
|
|
|
|
|
|
|
return this.actions$.pipe(
|
|
|
|
ofType(dept),
|
|
|
|
tap(() => {
|
|
|
|
departmentInfoList = [];
|
|
|
|
}),
|
|
|
|
switchMap(req => {
|
|
|
|
return this.queryProtocolService.dept(req).pipe(
|
|
|
|
map(res => {
|
2019-10-10 03:14:01 +00:00
|
|
|
switch (res.SSVC_TYPE) {
|
2019-10-04 04:45:02 +00:00
|
|
|
case SSVC_TYPE_QUERY_DEPT_DATA:
|
|
|
|
departmentInfoList.push(...(res as DeptData).departmentInfos);
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_QUERY_DEPT_RES:
|
2019-12-26 02:19:43 +00:00
|
|
|
departmentInfoList.sort((a, b) =>
|
|
|
|
a.order < b.order ? -1 : a.order > b.order ? 1 : 0
|
|
|
|
);
|
2019-10-04 04:45:02 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
deptSuccess({
|
|
|
|
departmentInfoList
|
|
|
|
})
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
catchError(error => of(deptFailure({ error })))
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{ dispatch: false }
|
|
|
|
);
|
|
|
|
|
2019-10-07 04:07:52 +00:00
|
|
|
deptUser$ = createEffect(
|
|
|
|
() => {
|
|
|
|
let userInfos: UserInfoSS[];
|
|
|
|
|
|
|
|
return this.actions$.pipe(
|
|
|
|
ofType(deptUser),
|
|
|
|
tap(() => {
|
|
|
|
userInfos = [];
|
|
|
|
}),
|
|
|
|
switchMap(req => {
|
|
|
|
return this.queryProtocolService.deptUser(req).pipe(
|
|
|
|
map(res => {
|
2019-10-10 03:14:01 +00:00
|
|
|
switch (res.SSVC_TYPE) {
|
2019-10-07 04:07:52 +00:00
|
|
|
case SSVC_TYPE_QUERY_DEPT_USER_DATA:
|
|
|
|
userInfos.push(...(res as DeptUserData).userInfos);
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_QUERY_DEPT_USER_RES:
|
2019-12-27 08:17:10 +00:00
|
|
|
userInfos.sort((a, b) =>
|
|
|
|
a.order < b.order
|
|
|
|
? -1
|
|
|
|
: a.order > b.order
|
|
|
|
? 1
|
|
|
|
: a.name < b.name
|
|
|
|
? -1
|
|
|
|
: a.name > b.name
|
|
|
|
? 1
|
|
|
|
: 0
|
|
|
|
);
|
2019-12-05 05:37:40 +00:00
|
|
|
|
2019-10-07 04:07:52 +00:00
|
|
|
this.store.dispatch(
|
|
|
|
deptUserSuccess({
|
|
|
|
userInfos,
|
|
|
|
res: res as DeptUserResponse
|
|
|
|
})
|
|
|
|
);
|
2019-12-26 08:34:52 +00:00
|
|
|
|
|
|
|
const loginResInfo: LoginResponse = this.sessionStorageService.get<
|
|
|
|
LoginResponse
|
|
|
|
>(KEY_LOGIN_RES_INFO);
|
|
|
|
|
|
|
|
if (req.seq === loginResInfo.departmentCode) {
|
|
|
|
this.store.dispatch(
|
|
|
|
myDeptUserSuccess({
|
|
|
|
userInfos
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-10-07 04:07:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
catchError(error => of(deptUserFailure({ error })))
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{ dispatch: false }
|
|
|
|
);
|
|
|
|
|
2019-10-04 04:45:02 +00:00
|
|
|
constructor(
|
|
|
|
private actions$: Actions,
|
|
|
|
private store: Store<any>,
|
2019-12-26 08:34:52 +00:00
|
|
|
private queryProtocolService: QueryProtocolService,
|
|
|
|
private sessionStorageService: SessionStorageService
|
2019-10-04 04:45:02 +00:00
|
|
|
) {}
|
|
|
|
}
|