import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {environment} from '../../environments/environment';
import {CommonsService} from './commons.service';

/**
 * 胡锐
 */

@Injectable({
  providedIn: 'root'
})
export class SystemService {

  constructor(
      private http: HttpClient,
      private common: CommonsService
  ) { }

    /**
     * 删除菜单
     *
     * @param showOnMobile 是否是在手机的端展示     0：不展示  1：展示
     * @param  callBack   回调
     * @return data 返回结果
     */
    public findAllMenuTree(showOnMobile: number, callBack) {
        this.http.get(environment.baseUrl + '/secMenu/findAllMenuTree?showOnMobile=' + showOnMobile).subscribe(data => {
            callBack(data);
        });
    }

    /**
     * 根据菜单id查询
     *
     * @param menuId 菜单id
     * @param  callBack   回调
     * @return data 返回结果
     */
    public findMenuById(menuId: number, callBack) {
        this.http.get(environment.baseUrl + '/secMenu/findMenuById?menuId=' + menuId).subscribe(data => {
            callBack(data);
        });
    }

    /**
     * 删除菜单
     *
     * @param menuId 菜单id
     * @param  callBack   回调
     * @return data 返回结果
     */
    public deleteMenu(menuId: number, callBack) {
        this.http.get(environment.baseUrl + '/secMenu/deleteMenu?menuIds=' + menuId).subscribe(data => {
            callBack(data);
        });
    }


  /**
   * 根据专业名称获取培训专业列表
   * @param subjectName
   * @param callBack
   */
  public subjectList(subjectName: string, callBack) {
    this.http.get(environment.baseUrl + '/secSubjectJob/findSubject?subjectName=' + subjectName).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询职位类别树
   * @param
   * @param callBack
   */
  public jobTypeTree(callBack) {
    this.http.get(environment.baseUrl + '/secSubjectJob/findJobTypeTree').subscribe(data => {
      callBack(data);
    });
  }


  /**
   * 添加职位与专业关联关系
   * @param  subjectJobType 职位关联关系
   * @param  callback   回调
   */
  public addSubjectJob(subjectJobType , callback) {
    this.http.post(environment.baseUrl + '/secSubjectJob/addSubjectJob' , subjectJobType).subscribe(data => {
      callback(data);
    });
  }

  /**
   * 分页查询专业职位关联关系
   * @param pageIndex
   * @param pageSize
   * @param subjectName
   * @param callBack
   */
  public subjectJobTypeList(pageIndex:number, pageSize:number,subjectName: string, callBack) {
    this.http.get(environment.baseUrl + '/secSubjectJob/findSubjectJobList?pageNum=' + pageIndex + '&pageSize=' + pageSize + '&subjectName=' + subjectName).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 删除职位专业关联关系
   * @param id
   * @param callBack
   */
  public deleteSubjectJobType(id: number,callBack) {
    this.http.get(environment.baseUrl + '/secSubjectJob/deleteSubjectJob?id=' + id).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 查询中石化配置列表
   *
   * @param  paramsObject   对象
   * @param  callBack   回调
   */
  public getListSinopecConfig(paramsObject: object, callBack) {
    this.http.get(environment.baseUrl + 'secSinopecConfig/getListSinopecConfig?' + this.common.getWhereCondition(paramsObject)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 新增商户
   *
   * @param params 上传对象
   * @param  callBack   回调
   * @return data 返回结果
   */
  public insertMerchant(params: object, callBack) {
    this.http.post(environment.baseUrl + 'secSinopecConfig/insertSinopec', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 修改商户
   *
   * @param params 上传对象
   * @param  callBack   回调
   * @return data 返回结果
   */
  public updateMerchant(params: object, callBack) {
    this.http.post(environment.baseUrl + 'secSinopecConfig/updateSinopec', params).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 根据id查询详情
   *
   * @param  sinopecId   id
   * @param  callBack   回调
   */
  public findById(sinopecId: number, callBack) {
    this.http.get(environment.baseUrl + 'secSinopecConfig/findById?sinopecId=' + sinopecId).subscribe(data => {
      callBack(data);
    });
  }



}
