import { AppStateType, DvaModelType, DvaStateType, EntityMeta, IrsBrokerRankDto, IrsRankStateType, ModelAction, } from '@amc-udk/types' import { IrsConfiger } from '../configer' import { LoggerFactory, PermissionUtils, TimerUtils } from '@amc-udk/utils' import { RankUtils } from '../utils' const namespace = 'rank' const Logger = LoggerFactory.get(namespace) export const IrsRankModel: DvaModelType = { namespace, effects: { /** * 用户成功登录后 * @param param0 * @param param1 * @returns */ *afterAppAuthenticated({ type, payload }: ModelAction, { select, call, put }) { const { loginUserInfo }: AppStateType = yield select(_ => _.app) if (loginUserInfo && loginUserInfo.realname) { const isAdmin = PermissionUtils.matchUserRoles( { roles: ['ROLE_IRS_ADMIN'], }, loginUserInfo.roles.map(role => role.code), ) yield put({ type: 'updateState', payload: { username: loginUserInfo.username, voter: loginUserInfo.realname, isAdmin, }, }) /** 非管理员需要添加额外查询条件 */ if (!isAdmin) { yield put({ type: 'specification/push', payload: { namespace: 'preconfig', specs: [ { field: 'voter', type: 'eq', valueType: 'string', value: loginUserInfo.realname, conjunct: 'and', }, ], }, }) yield put({ type: 'specification/push', payload: { namespace: 'service', specs: [ { field: 'receiver', type: 'eq', valueType: 'string', value: loginUserInfo.realname, conjunct: 'and', }, ], }, }) yield put({ type: 'specification/push', payload: { namespace: 'vote', specs: [ { field: 'receiver', type: 'eq', valueType: 'string', value: loginUserInfo.realname, conjunct: 'and', }, ], }, }) yield put({ type: 'specification/push', payload: { namespace: 'preconfig', specs: [ { field: 'voter', type: 'eq', valueType: 'string', value: loginUserInfo.realname, conjunct: 'and', }, ], }, }) // yield put({ // type: 'specification/push', // payload: { // namespace: 'points', // specs: [ // { // field: 'name', // type: 'eq', // valueType: 'string', // value: loginUserInfo.realname, // conjunct: 'and', // }, // ], // }, // }) } } yield TimerUtils.sleep(100) IrsConfiger.getLifecycleManager().phaseChange('rank', 'authorized') }, *postProcessAllData( { type, payload }: ModelAction<{ meta: EntityMeta; data: IrsBrokerRankDto[] }>, { select, call, put }, ) { if (!payload || !payload.data) { return } if (!Array.isArray(payload.data)) { return Logger.error('无法处理非数组类全量数据!') } payload.data.forEach(dto => { RankUtils.setStatusByDate(dto) }) yield put({ type: 'updateState', payload: { all: payload.data, }, }) }, }, }