SERVICE.ts.ftl 7.4 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
<#assign import_block>
<#if ctrl.getPSSysCalendarItems()??>
  <#list ctrl.getPSSysCalendarItems() as calendarItem>
    <#if calendarItem.getPSAppDataEntity()??>
      <#assign _appde = calendarItem.getPSAppDataEntity() />
      <#if _appde.getId() != appde.getId()>
      <#if !P.exists("importService", _appde.getId(), "")>
import ${srfclassname('${_appde.getCodeName()}')}Service from '@/service/${srffilepath2(_appde.getCodeName())}/${srffilepath2(_appde.getCodeName())}-service';
      </#if>
      </#if>
    </#if>
  </#list>
</#if>
</#assign>
<#ibizinclude>
../@MACRO/SERVICE/SERVICE_HEADER.ts.ftl
</#ibizinclude>

<#if ctrl.getPSSysCalendarItems()??>
  <#list ctrl.getPSSysCalendarItems() as calendarItem>
    <#if calendarItem.getPSAppDataEntity()??>
      <#assign _appde = calendarItem.getPSAppDataEntity() />
      <#if _appde.getId() != appde.getId()>
      <#if !P.exists("importService2", _appde.getId(), "")>
    /**
     * ${_appde.getLogicName()}服务对象
     *
     * @type {${srfclassname('${_appde.getCodeName()}')}Service}
     * @memberof ${srfclassname('${ctrl.codeName}')}Service
     */
    public ${_appde.getCodeName()?lower_case}Service: ${srfclassname('${_appde.getCodeName()}')}Service = new ${srfclassname('${_appde.getCodeName()}')}Service();
      </#if>
      </#if>
    </#if>
  </#list>
</#if>

    /**
     * 事件配置集合
     *
41
     * @public
42 43 44
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
45
    public eventsConfig: any[] = [
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
<#if ctrl.getPSSysCalendarItems()??>
  <#list ctrl.getPSSysCalendarItems() as calendarItem>
        {
          itemName : '${calendarItem.getName()}',
          itemType : '${calendarItem.getItemType()}',
          color : '${calendarItem.getBKColor()}',
          textColor : '${calendarItem.getColor()}',
        },
  </#list>
</#if>
    ];

    /**
     * 查询数据
     *
     * @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> {
        let _this = this;
        return new Promise((resolve: any, reject: any) => {
            let promises:any = [];
            let tempRequest:any;
<#if ctrl.getPSSysCalendarItems()??>
  <#list ctrl.getPSSysCalendarItems() as calendarItem>
    <#if calendarItem.getPSAppDataEntity()?? && calendarItem.getPSDEDataSet()??>
      <#assign _appde = calendarItem.getPSAppDataEntity() />
      <#assign deDataSet = calendarItem.getPSDEDataSet() />
      <#if !P.exists("importService3", _appde.getId() + deDataSet.getCodeName(), "")>
        <#if _appde.getId() == appde.getId()>
            tempRequest = this.handleRequestData(action,context,data,true,"${calendarItem.getItemType()}");
            promises.push(this.appEntityService.Fetch${deDataSet.getCodeName()}(tempRequest.context, tempRequest.data, isloading));
        <#else>
            tempRequest = this.handleRequestData(action,context,data,true,"${calendarItem.getItemType()}");
            promises.push(this.${_appde.getCodeName()?lower_case}Service.Fetch${deDataSet.getCodeName()}(tempRequest.context, tempRequest.data, isloading));
        </#if>
      </#if>
    </#if>
  </#list>
</#if>
            Promise.all(promises).then((resArray: any) => {
                let _data:any = [];
                resArray.forEach((response:any,resIndex:number) => {
                    if (!response || response.status !== 200) {
                        return;
                    }
                    let _response: any = JSON.parse(JSON.stringify(response));
                    _response.data.forEach((item:any,index:number) =>{
                        _response.data[index].color = _this.eventsConfig[resIndex].color;
                        _response.data[index].textColor = _this.eventsConfig[resIndex].textColor;
                        _response.data[index].itemType = _this.eventsConfig[resIndex].itemType;
                    });
                    ;
                    _this.handleResponse(action, _response,false,_this.eventsConfig[resIndex].itemType);
                    _data.push(..._response.data);
                });
                // 排序
                _data.sort((a:any, b:any)=>{
                    let dateA = new Date(Date.parse(a.start.replace(/-/g, "/")));
                    let dateB = new Date(Date.parse(b.start.replace(/-/g, "/")));
                    return dateA > dateB ? 1 : -1 ;
                });
                let result = {status: 200, data: _data};
                resolve(result);
            }).catch((response: any) => {
                reject(response);
            });  
        });
    }

    /**
     * 修改数据
     *
     * @param {string} action
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${ctrl.codeName}')}Service
     */
    @Errorlog
    public update(itemType: string, context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
        return new Promise((resolve: any, reject: any) => {
            let result: any;
            let tempRequest:any;
            switch(itemType) {
<#if ctrl.getPSSysCalendarItems()??>
  <#list ctrl.getPSSysCalendarItems() as calendarItem>
    <#if calendarItem.getPSAppDataEntity()??>
      <#assign _appde = calendarItem.getPSAppDataEntity() />
        <#if _appde.getId() == appde.getId()>
                case "${calendarItem.getItemType()}":
                    tempRequest = this.handleRequestData("",context,data,false,"${calendarItem.getItemType()}");
                    result = this.appEntityService.Update(tempRequest.context, tempRequest.data, isloading);
                    break;
        <#else>
                case "${calendarItem.getItemType()}":
                    tempRequest = this.handleRequestData("",context,data,false,"${calendarItem.getItemType()}");
                    result = this.${_appde.getCodeName()?lower_case}Service.Update(tempRequest.context, tempRequest.data, isloading);
                    break;
        </#if>
    </#if>
  </#list>
</#if>
            }
            if(result){
                result.then((response: any) => {
                    this.handleResponse("", response);
                    resolve(response);
                }).catch((response: any) => {
                    reject(response);
                });
            }else{
              reject("没有匹配的实体服务");
            }
        });
    }

    /**
     * 处理request请求数据
     * 
     * @param action 行为 
     * @param data 数据
     * @memberof ControlService
     */
    public handleRequestData(action: string,context:any ={},data: any = {},isMerge:boolean = false,itemType:string=""){
        let model: any = this.getMode();
        model.itemType = itemType;
        return super.handleRequestData(action,context,data,isMerge);
    }

    /**
     * 处理response返回数据
     *
     * @param {string} action
     * @param {*} response
     * @memberof ControlService
     */
    public handleResponse(action: string, response: any,isCreate:boolean = false,itemType:string=""){
        let model: any = this.getMode();
        model.itemType = itemType;
        super.handleResponse(action,response,isCreate);
    }

<#ibizinclude>
../@MACRO/SERVICE/SERVICE_BOTTOM.ts.ftl
</#ibizinclude>