import { HttpClient } from "@angular/common/http";
import {Observable} from "rxjs/Rx";
import { Injectable } from '@angular/core';
import {SERVER_API_URL, SERVER_API_URL_COMS} from '../app.constants';
import {CommonService} from '../shared/common/common.service';
import {LocalStorageService, SessionStorageService} from 'ngx-webstorage';
import {Http, RequestOptions, ResponseContentType, ResponseOptions} from '@angular/http';

@Injectable()
export class SystemService {

    headers;
    options;
    constructor(private http: HttpClient,private commonSer:CommonService,private http1:Http,
                private localStorage:LocalStorageService,private sessionStorage:SessionStorageService) {
    }

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

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

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

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

    //删除用户
    deleteRole(params): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/role/deleteRoleById?' +this.commonSer.toQuery(params));
    }

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

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

    //编辑用户
    updateUser(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/user/updateUser',data);
    }

    //查找用户
    getUser(params): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/user/getUserById/'+params);
    }

    //查找用户角色
    getRoleByUserId(data): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/user/getRoleByUserId?'+ this.commonSer.toQuery(data) );
    }

    //删除用户
    deleteUser(data): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/user/deleteUser?' + this.commonSer.toQuery(data) );
    }

    //删除用户
    batchDeleteUser(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/user/batchDeleteUser' ,data);
    }

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

    //删除单个组织机构
    deleteOrg(params): Observable<any>{
        return this.http.delete(SERVER_API_URL_COMS + '/organization/' + params);
    }

    //编辑组织
    updateOrganization(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/organization/updateOrganization',data);
    }

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

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

    //审计列表
    logList(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/log/getLog',data);
    }

    //单个角色to多个用户
    batchAuthRoleToUser(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/role/batchAuthRoleToUser',data);
    }

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

    //对多个用户 批量授权角色
    batchUserToAuth(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/user/batchAuth',data);
    }

    //根据部门查询角色
    getUserByOrgIdAboutRole(data): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/user/getUserByOrgIdAboutRole?'+this.commonSer.toQuery(data) );
    }

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

    //修改三员分立状态
    updateValue(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/separationConfig/updateValue',data);
    }

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

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

    //获取当前已审批记录
    getApproveOfDone(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/approve/getApproveOfDone',data );
    }

    //获取未审批记录
    getUnApprove(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/approve/getUnApprove',data );
    }

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

    //审批不通过
    approvUnPass(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/approve/unPass', data);
    }

    //审批取消
    approvCancle(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/approve/cancle', data);
    }

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

    approveList(): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/approval/approveList');
    }

    unApproveList(): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/approval/unApproveList' );
    }

    //修改密码
    modifyPassword(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/modifyPassword',data );
    }

    //三员分立总开
    separationConfigOpen(): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/separationConfig/open' );
    }

    //三员分立总关
    separationConfigClose(): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/separationConfig/close' );
    }

    //组织系统用户 -关
    closeSystem(): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/separationConfig/closeSystem' );
    }

    //组织系统用户 -开
    openSystem(): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/separationConfig/openSystem' );
    }

    //角色与权限--开
    openAuth(): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/separationConfig/openAuth' );
    }

    //角色与权限--关
    closeAuth(): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/separationConfig/closeAuth' );
    }

    //菜单列表  --新增角色菜单
    getMenuBySeparation(): Observable<any>{
        return this.http.get(SERVER_API_URL_COMS + '/resources/getMenuBySeparation' );
    }

    //用户导入
    importUser(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/user/importUser',data);
    }

    //组织导入
    importOrg(data): Observable<any>{
        return this.http.post(SERVER_API_URL_COMS + '/organization/importOrg',data );
    }

    /**
     * 下载文件
     * @param pararms  参数
     * @param url  地址
     * @returns {Observable<any>}
     */
    downloadTemplate(pararms,url): Observable<any>{
        return this.http.get( url +pararms,{responseType: 'blob'});
    }

}
