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

@Injectable()
export class WorkService {

    constructor(private http: HttpClient) {
    }

    //事件转派
    transfer(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/sysevent/transfer' ,data);
    }

    //修改事件
    update(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/sysevent/update' ,data);
    }

    //删除事件
    deleteEvent(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/sysevent/delete' ,data);
    }

    //查找事件列表
    find(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/sysevent/find' ,data);
    }

    //根据事件编号查询
    findByNo(params): Observable<any>{
        return this.http.get(SERVER_API_URL + '/sysevent/findTransferAndInventory/' +params);
    }

    //添加事件
    create(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/sysevent/create' ,data);
    }

    //事件信息流转记录查询接口
    transferInfo(params): Observable<any>{
        return this.http.get(SERVER_API_URL + '/sysevent/transferInfo/' +params);
    }

    //处理事件
    deal(data): Observable<any>{
        return this.http.put(SERVER_API_URL + '/sysevent/deal' ,data);
    }

    //事件确认
    confirmEvent(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/sysevent/confirm' ,data);
    }

    //查询事件, 操作人, 流转记录, 资产
    findTransferAndInventory(params): Observable<any>{
        return this.http.get(SERVER_API_URL + '/sysevent/findTransferAndInventory/' +params);
    }

    //修改巡检计划
    updatePlan(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/plan/update' ,data);
    }

    //删除计划
    deletePlan(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/plan/delete' ,data);
    }

    //查找单个计划
    findPlan(params): Observable<any>{
        return this.http.get(SERVER_API_URL + '/plan/find/' +params);
    }

    //查询列表
    findPlanList(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/plan/find' ,data);
    }

    //添加巡检计划
    createPlan(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/plan/create' ,data);
    }

    //修改资产分类
    updateType(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/inventory/updateType' ,data);
    }

    //查询所有父级资产类型
    findByParentType(): Observable<any>{
        return this.http.get(SERVER_API_URL + '/inventory/findByParentType' );
    }

    //根据父级类型查询子级
    findByParentidCount(params): Observable<any>{
        return this.http.get(SERVER_API_URL + '/inventory/findByParentidCount/' +params);
    }

    //创建资产分类
    createType(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/inventory/createType' ,data);
    }

    //根据主键id查询资产类型
    findType(params): Observable<any>{
        return this.http.get(SERVER_API_URL + '/inventory/findType/' +params);
    }

    //根据资产类型id 查询没有配置主机的资产
    selectByInventoryTypeidAndHostidNull(params): Observable<any>{
        return this.http.get(SERVER_API_URL + '/inventory/selectByInventoryTypeidAndHostidNull/' ,params);
    }

    //设置资产匹配的主机
    updateHostid(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/inventory/updateHostid' ,data);
    }

    //根据type查找
    findByType(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/syseventType/findByType' ,data);
    }

    //创建资产
    createInventory(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/inventory/createInventory' ,data);
    }

    //修改资产
    updateInventory(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/inventory/updateInventory' ,data);
    }

    //根据资产类型id查询资产
    findInventory(params): Observable<any>{
        return this.http.get(SERVER_API_URL + '/inventory/findInventory/' +params);
    }

    //删除资产（可批量）
    deleteInventory(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/inventory/deleteInventory' ,data);
    }

    //导入资产
    importInventory(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/inventory/import' ,data);
    }

    //根据资产类型id查询资产
    selectByPrimaryKey(params): Observable<any>{
        return this.http.get(SERVER_API_URL + '/inventory/selectByPrimaryKey/' +params);
    }

    //删除资产分类
    deleteType(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/inventory/deleteType' ,data);
    }

    //根据type查找
    findParamsByType(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/syseventType/findByType' ,data);
    }

    //添加类型
    createTypeByparams(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/syseventType/create' ,data);
    }

    //修改分类
    updateTypeByparams(data): Observable<any>{
        return this.http.put(SERVER_API_URL + '/syseventType/update' ,data);
    }

    //删除分类
    deleteTypeByparams(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/syseventType/delete' ,data);
    }

    //查找当前事件编号前缀
    getEventNoPre(): Observable<any>{
        return this.http.get(SERVER_API_URL + '/sysevent/getEventNoPre' );
    }

    //修改事件编号前缀
    updateEventNoPre(data): Observable<any>{
        return this.http.put(SERVER_API_URL + '/sysevent/updateEventNoPre',data );
    }

    /**
     * 附件文件
     * @param pararms  参数
     * @param url  地址
     * @returns {Observable<any>}
     */
    downloadTemplate(pararmsType,paramsId): Observable<any>{
        return this.http.get( SERVER_API_URL + "/api/download/file/" + pararmsType +"/"+ paramsId,{responseType: 'blob'});
    }

    /**
     * 批量下载资产文件
     */
    getExportUrl(data): Observable<any>{
        return this.http.post( SERVER_API_URL + "/inventory/getExportUrl" ,data);
    }
}
