|
import { Injectable } from '@angular/core';
|
|
export class Criteria{
|
private static CONDITION_SPLIT = '||';
|
private conditions: string[] = [];
|
public getConditions(): string[]{
|
return this.conditions;
|
}
|
|
public addCondition(condition: string,colName:string,...values: any[]){
|
const split = Criteria.CONDITION_SPLIT; // '||'
|
this.conditions.push(condition+split+colName+split+ values.join(split));
|
}
|
public andLike(col: { name: string, value: any}): Criteria{
|
this.addCondition('andLike',col.name,col.value);
|
return this;
|
}
|
public andEqualTo(col: { name: string, value: any}): Criteria{
|
this.addCondition('andEqualTo',col.name,col.value);
|
return this;
|
}
|
}
|
|
@Injectable()
|
export class ExampleService {
|
private static OR_SPLIT = "or|";
|
private static CRITERIA_SPLIT = "|||";
|
private criterion: Criteria[]=[];
|
|
public getSqlParam():string{
|
let whereSql = '';
|
for(let cri of this.criterion){
|
const conditions = cri.getConditions();
|
whereSql += ExampleService.OR_SPLIT+conditions.join(ExampleService.CRITERIA_SPLIT);
|
}
|
return encodeURI(whereSql);
|
}
|
constructor() { }
|
public or(){
|
const cri = new Criteria();
|
this.criterion.push(cri);
|
return cri;
|
}
|
}
|