SERVICE.ts.ftl 4.5 KB
Newer Older
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
<#ibizinclude>
../@MACRO/SERVICE/SERVICE_HEADER.ts.ftl
</#ibizinclude>

    /**
     * 查询数据
     *
     * @param {string} action
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}Service
     */
    @Errorlog
    public search(action: string,context: any = {}, data: any = {}, isloading?: boolean): Promise<any> {
        const {data:Data,context:Context} = this.handleRequestData(action,context,data,true);
        return new Promise((resolve: any, reject: any) => {
            const _appEntityService: any = this.appEntityService;
            let result: Promise<any>;
            if (_appEntityService[action] && _appEntityService[action] instanceof Function) {
                result = _appEntityService[action](Context,Data, isloading);
            }else{
                result =_appEntityService.FetchDefault(Context,Data, isloading);
            }
            result.then((response) => {
                this.handleSeries(response);
                resolve(response);
            }).catch(response => {
                reject(response);
            });      
        });
    }
<#--  暂只支持第一个序列  -->
<#list ctrl.getPSDEChartSerieses() as series>
  <#if series_index == 0>
    <#assign chartSeries = series/>
  </#if>
</#list>
    /**
     * 生成图表数据
     *
     * @param {*} response
     * @memberof ${srfclassname('${ctrl.codeName}')}Service
     */
    public handleSeries(response: any) {
        let chartOption:any = {};
<#--  获取x轴的分类属性字段  -->
<#if chartSeries.getCatalogField?? && chartSeries.getCatalogField()??>
  <#assign catalogField = chartSeries.getCatalogField()>
        let catalogFields: any = [<#rt>
  <#list catalogField?split(";") as field>
            "${field?lower_case}",<#t>
  </#list>
        ];<#lt>
</#if>
<#--  获取y轴值属性字段和中文名称  -->
<#if chartSeries.getValueField?? && chartSeries.getValueField()??>
  <#assign valueField = chartSeries.getValueField()>
        let valueFields: any = [<#rt>
    <#list valueField?split(";") as field>
            [ "${field?lower_case}", "${de.getPSDEField(field).getLogicName()}" ],<#t>
    </#list>
        ];<#lt>
</#if>
        // 数据按分类属性分组处理
        let xFields:any = [];
        let yFields:any = [];
        valueFields.forEach((field: any,index: number) => {
            yFields[index] = [];
        });
        response.data.forEach((item:any) => {
            if(xFields.indexOf(item[catalogFields[0]]) > -1){
                let num = xFields.indexOf(item[catalogFields[0]]);
                valueFields.forEach((field: any,index: number) => {
                    yFields[index][num] += item[field[0]];
                });
            }else{
                xFields.push(item[catalogFields[0]]);
                valueFields.forEach((field: any,index: number) => {
                    yFields[index].push(item[field[0]]);
                });
            }
        });
<#--  折线图和柱状图需要配置xAxis,饼图不需要  -->
<#if chartSeries.getSeriesType() == 'line' || chartSeries.getSeriesType() == 'bar'>
        chartOption.xAxis = { data: xFields };
</#if>
<#--  配置series  -->
        let series: any = [];
        valueFields.forEach((field: any,index: number) => {
            let yData: any = [];
             xFields.forEach((item:any, num: number) => {
<#if chartSeries.getSeriesType() == 'line' || chartSeries.getSeriesType() == 'bar'>
                yData.push(yFields[index][num]);
<#elseif chartSeries.getSeriesType() == 'pie'>
                yData.push({value: yFields[index][num], name: item});
</#if>
            });
            yData.sort(function (a:any, b:any) { return a.value - b.value; });
            series.push({
              name:field[1],
              type:"${chartSeries.getSeriesType()}",
              data:yData,
<#--  饼图额外配置  -->
<#if chartSeries.getSeriesType() == 'pie'>
              top:"40px",
              left: (100/valueFields.length)*index+"%",
              right: (100/valueFields.length)*(valueFields.length-index-1)+"%",
              animationType: 'scale',
              animationEasing: 'elasticOut',
              animationDelay: function (idx: any) {
                  return Math.random() * 200;
              }
</#if>
            });
        });
        chartOption.series = series;
        response.data = chartOption;
    }
<#ibizinclude>
../@MACRO/SERVICE/SERVICE_BOTTOM.ts.ftl
</#ibizinclude>