import { HttpClient } from "@angular/common/http";
import {Observable} from "rxjs/Rx";
import { Injectable } from '@angular/core';
import {SERVER_API_URL} from "../app.constants";
import {ToTree} from '../shared/common/toTree';

@Injectable()
export class SystemService {

    constructor(private http: HttpClient,private toTree:ToTree) {
    }

    //角色列表
    role(): Observable<any>{
        return this.http.get(SERVER_API_URL + '/role');
    }

    //获取单个角色
    getRole(params): Observable<any>{
        return this.http.get(SERVER_API_URL + '/role/'+params);
    }

    //编辑角色
    editRole(data): Observable<any>{
        return this.http.put(SERVER_API_URL + '/role',data);
    }

    //新增角色
    addRole(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/role',data);
    }

    //删除用户
    deleteRole(params): Observable<any>{
        return this.http.delete(SERVER_API_URL + '/role/' +params);
    }

    //用户列表
    user(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/user/findUsers',data);
    }

    //新增用户
    adduser(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/user',data);
    }

    //删除用户
    deleteUser(params){
        return this.http.delete(SERVER_API_URL + '/user/'+ params);
    }

    //组织结构列表
    organization(): Observable<any>{
        return this.http.get(SERVER_API_URL + '/organization',);
    }

    //创建组织结构
    createOrg(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/organization',data);
    }

    //三员分立列表
    separationPowers(): Observable<any>{
        return this.http.get(SERVER_API_URL + '/approval/separationPowers',);
    }

    //审计列表
    logList(data): Observable<any>{
        return this.http.get(SERVER_API_URL + '/log?'+this.toTree.toQuery(data));
    }

    //对单一角色批量添加用户
    batchGrantUserToRole(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/role/batchGrantUserToRole',data);
    }

    //对单一用户批量授权角色
    batchGrantRoleToUser(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/role/batchGrantRoleToUser',data);
    }

    //查询三员分立是否开启
    separationPowerStatus(): Observable<any>{
        return this.http.get(SERVER_API_URL + '/approval/separationPowerStatus');
    }

    //修改三员分立状态
    updateSeparationPowerStatus(data): Observable<any>{
        return this.http.put(SERVER_API_URL + '/approval/separationPowers',data);
    }

    //获取当前登录人角色
    currentUserRoles(): Observable<any>{
        return this.http.get(SERVER_API_URL + '/role/currentUserRoles');
    }

    //单个用户角色获取
    roleList(data): Observable<any>{
        return this.http.get(SERVER_API_URL + '/user/roleList?'+this.toTree.toQuery(data) );
    }

    //获取当前安全管理员已审批记录
    approveListSafeManager(data): Observable<any>{
        return this.http.get(SERVER_API_URL + '/approval/approveListSafeManager?'+this.toTree.toQuery(data) );
    }

    //获取当前安全管理员未审批记录
    unapproveListSafeManager(data): Observable<any>{
        return this.http.get(SERVER_API_URL + '/approval/unapproveListSafeManager?'+this.toTree.toQuery(data) );
    }

    //获取当前系统管理员的已审批记录
    approveListSystemManager(data): Observable<any>{
        return this.http.get(SERVER_API_URL + '/approval/approveListSystemManager?'+this.toTree.toQuery(data) );
    }

    //获取当前系统管理员的未审批记录
    unApproveListSystemManager(data): Observable<any>{
        return this.http.get(SERVER_API_URL + '/approval/unApproveListSystemManager?'+this.toTree.toQuery(data) );
    }

    //批量审批通过
    approvalPass(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/approval/pass', data);
    }

    //批量审批退回
    approvalReject(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/approval/reject', data);
    }

    //批量撤回审批
    approvalRemove(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/approval/remove', data);
    }
}
