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 CompanyService {

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

  /**
   * 增加公司
   * @param paramObject 参数
   * @param callBack
   */
  insertCompany(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'bsCompany/insert', paramObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 修改公司
   * @param paramObject 参数
   * @param callBack
   */
  updateCompany(paramObject: object, callBack) {
    this.http.post(environment.baseUrl + 'bsCompany/update', paramObject).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 获取公司列表
   * @param paramObject 参数
   * @param callBack
   */
  selectCompanyList(paramObject: object, callBack) {
    this.http.get(environment.baseUrl + 'bsCompany/selectCompanyList?' + this.commonsService.getWhereCondition(paramObject)).subscribe(data => {
      callBack(data);
    });
  }

  /**
   * 公司详情
   * @param paramObject 参数
   * @param callBack
   */
  companyView(companyId: number, callBack) {
    this.http.get(environment.baseUrl + 'bsCompany/companyView?companyId=' + companyId).subscribe(data => {
      callBack(data);
    });
  }

}
