fengxiang
2018-07-04 7ca521e4267b987270f6ccbb9a6c076aeb467d96
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
56
57
58
59
60
61
62
 
import { Injectable } from '@angular/core';
 
export class  Criteria {
    private static CONDITION_SPLIT = '||';
     private conditions: string[] = [];
     public getConditions(): string[] {
       return this.conditions;
     }
 
     private addCondition(condition: string, colName: string, ...values: any[]) {
        const split = Criteria.CONDITION_SPLIT; // '||'
        let conditionStr = condition + split + colName;
        if (!!values && values.length > 0) {
            conditionStr += split + values.join(split);
        }
        this.conditions.push(conditionStr);
     }
     public andCondition(condition: string) {
        this.addCondition('andCondition', condition);
     }
     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(): Criteria {
        const cri = new Criteria();
        this.criterion.push(cri);
        return cri;
    }
}