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);
    }

    //导入知识库
    importKnowladage(data, params): Observable<any> {
        return this.http.post(SERVER_API_URL + '/knowledge/import/' + params, data);
    }

    //知识库翻页
    knowledgedFindPage(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/knowledge/findPage', data);
    }

    //下载
    knowledgedDownload(params): Observable<any> {
        return this.http.get(SERVER_API_URL + '/knowledge/download/' + params,{responseType: 'blob'});
    }

    //删除文件
    knowledgedDelete(data): Observable<any> {
        return this.http.post(SERVER_API_URL + '/knowledge/deleteKnowledge', 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);
    }

    //修改费用记录
    updateCost(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/cost/updateCost' ,data);
    }

    //分页筛选费用记录
    findPage(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/cost/findPage' ,data);
    }

    //批量删除费用记录
    deleteCost(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/cost/deleteCost' ,data);
    }

    //新增费用记录
    addCost(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/cost/addCost' ,data);
    }

    //根据费用id查询
    findById(data): Observable<any>{
        return this.http.post(SERVER_API_URL + '/cost/findById' ,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);
    }

    //查询系统信息
    getPreview(): Observable<any> {
        return this.http.get('./json/preview.json');
    }
}
