fengxiang
2018-05-02 5e502e366836b3577884bca89372541b42124cd3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
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;
     }
     public andNotEqualTo(col: { name: string, value: any}): Criteria {
        this.addCondition('andNotEqualTo', col.name, col.value);
        return this;
     }
     public andGreaterThanOrEqualTo(col: { name: string, value: any}): Criteria {
        this.addCondition('andGreaterThanOrEqualTo', col.name, col.value);
        return this;
     }
}
 
@Injectable()
export class ExampleService {
  private static OR_SPLIT = 'or|';
  private static  CRITERIA_SPLIT = '|||';
  private criterion: Criteria[] = [];
  public clear(): void {
      this.criterion = [];
  }
  public getSqlParam(): string {
      let whereSql = '';
     for (const 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;
    }
}