%DE_PKGPATH%-service-base.ts.ftl 28.7 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
<#ibiztemplate>
TARGET=PSAPPDATAENTITY
</#ibiztemplate>
import { Http,Util } from '@/utils';
import EntityService from '../entity-service';
<#if item.getAllPSAppDELogics()??>
<#list item.getAllPSAppDELogics() as singleLogic>
<#if !P.exists("importService", singleLogic.getId(), "")>
<#if singleLogic.getLogicHolder() == 2 || singleLogic.getLogicHolder() == 3>
import ${srfclassname('${singleLogic.getCodeName()}')}Logic from '@/service/${srffilepath2(singleLogic.getPSAppDataEntity().getCodeName())}/${srffilepath2(singleLogic.getCodeName())}-logic';
</#if>
</#if>
</#list>
</#if>

<#-- 设置本地缓存 -->
<#macro setStore appEntity>
        <#if appEntity.getMajorPSAppDERSs()??>
        <#list appEntity.getMajorPSAppDERSs() as deReRs>
        <#-- 主实体 -->
        <#assign majorPSAppDataEntity = deReRs.getMajorPSAppDataEntity() />
        <#-- 从实体 -->
        <#assign minorPSAppDataEntity = deReRs.getMinorPSAppDataEntity() />
            this.tempStorage.setItem(context.srfsessionkey+'_${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}',JSON.stringify(res.data.${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}));
        </#list>
        </#if>
</#macro>

<#-- 获取本地缓存 -->
<#macro getStore appEntity>
        <#if appEntity.getMajorPSAppDERSs()??>
        <#list appEntity.getMajorPSAppDERSs() as deReRs>
        <#-- 主实体 -->
        <#assign majorPSAppDataEntity = deReRs.getMajorPSAppDataEntity() />
        <#-- 从实体 -->
        <#assign minorPSAppDataEntity = deReRs.getMinorPSAppDataEntity() />
        let ${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}Data:any = [];
        if(!Object.is(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}'),'undefined')){
            ${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}Data = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}') as any);
            if(${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}Data && ${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}Data.length && ${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}Data.length > 0){
                ${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}Data.forEach((item:any) => {
                    if(item.srffrontuf){
                        if(Object.is(item.srffrontuf,"0")){
                            item.${minorPSAppDataEntity.getKeyPSAppDEField().getCodeName()?lower_case} = null;
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.${srfpluralize(minorPSAppDataEntity.codeName)?lower_case} = ${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}Data;
        </#list>
        </#if>
</#macro>

<#-- 定义service_block start -->
<#macro service_block item singleAppMethod>
 <#if item.getPSAppDERSPathCount() gt 0 && singleServiceApi??>
    <#list 1..item.getPSAppDERSPathCount() as count>
        <#assign path = ''/>
        <#assign condition = ''/>
        <#list item.getPSAppDERSPath(count_index)  as deRSPath>
            <#if deRSPath.getMajorPSAppDataEntity?? && deRSPath.getMajorPSAppDataEntity()??>
                <#assign _dataEntity = deRSPath.getMajorPSAppDataEntity()/>
                <#assign condition>${condition}context.${_dataEntity.getCodeName()?lower_case} && </#assign>
                <#assign path>${path}${srfpluralize(_dataEntity.codeName)?lower_case}/<#noparse>$</#noparse>{context.${_dataEntity.getCodeName()?lower_case}}/</#assign>
            </#if>
        </#list>
        <#-- 方法类型为SELECT -->
        <#if singleAppMethod.getMethodType() == "SELECT">
        if(${condition}context.${item.getCodeName()?lower_case}){
            <#if singleServiceApi.getRequestMethod() == 'PUT' ||  singleServiceApi.getRequestMethod() == 'POST'>
73
            return Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${path}${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,data,isloading);
74
            <#else>
75
            return Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${path}${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,isloading);
76 77 78 79 80 81
            </#if>
        }
        <#-- 方法类型为FETCH -->
        <#elseif singleAppMethod.getMethodType() == "FETCH">
        if(${condition}true){
            let tempData:any = JSON.parse(JSON.stringify(data));
82
            return Http.getInstance().get(`/${path}${srfpluralize(item.codeName)?lower_case}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,tempData,isloading);
83 84 85 86
        }
        <#-- 方法类型为FETCHTEMP -->
        <#elseif singleAppMethod.getMethodType() == "FETCHTEMP">
        if(${condition}true){
87
            return Http.getInstance().get(`/${path}${srfpluralize(item.codeName)?lower_case}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,data,isloading);
88 89 90 91 92 93
        }
        <#else>
        <#-- 方法类型为DEACTION start -->
            <#if singleServiceApi.getRequestParamType() == "NONE">
            <#-- 无参数情况start -->
        if(${condition}true){
94 95 96
            let res:any = await Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${path}${srfpluralize(item.codeName)?lower_case}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,isloading);
            res.data.${item.getCodeName()?lower_case} = data.${item.getCodeName()?lower_case};
            <@setStore appEntity=item />
97
            return res;
98 99 100 101 102
        }
            <#-- 无参数情况end -->
            <#elseif singleServiceApi.getRequestParamType() == "FIELD">
            <#-- 指定属性情况start -->
        if(${condition}context.${item.getCodeName()?lower_case}){
103 104 105 106 107
            <#-- 指定属性情况start -->
            <#-- GET -->
            <#if singleServiceApi.getRequestMethod() == "GET">
            let res:any = await Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${path}${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,isloading);
            <@setStore appEntity=item />
108
            return res;
109
            <#elseif singleServiceApi.getRequestMethod() == "POST">
110
            return Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${path}${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,data,isloading);
111
            <#else>
112
            return Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${path}${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,isloading);
113 114
            </#if>
            <#-- 指定属性情况end -->
115 116 117 118 119 120
        }
            <#-- 指定属性情况start -->
            <#elseif singleServiceApi.getRequestParamType() == "ENTITY">
            <#-- 提交对象数据情况start -->
            <#if singleAppMethod.getCodeName() == 'Create'>
        if(${condition}true){
121 122 123
            let masterData:any = {};
            <@getStore appEntity=item />
            Object.assign(data,masterData);
124 125 126 127 128 129
            if(!data.srffrontuf || data.srffrontuf !== "1"){
                data[this.APPDEKEY] = null;
            }
            if(data.srffrontuf){
                delete data.srffrontuf;
            }
130 131 132 133 134 135 136 137 138 139 140
            let tempContext:any = JSON.parse(JSON.stringify(context));
            let res:any = await Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${path}${srfpluralize(item.codeName)?lower_case}`,data,isloading);
            <#if item.getMajorPSAppDERSs()??>
            <#list item.getMajorPSAppDERSs() as deReRs>
            <#-- 主实体 -->
            <#assign majorPSAppDataEntity = deReRs.getMajorPSAppDataEntity() />
            <#-- 从实体 -->
            <#assign minorPSAppDataEntity = deReRs.getMinorPSAppDataEntity() />
            this.tempStorage.setItem(tempContext.srfsessionkey+'_${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}',JSON.stringify(res.data.${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}));
            </#list>
            </#if>
141
            return res;
142 143 144
        }
            <#else>
        if(${condition}context.${item.getCodeName()?lower_case}){
145 146 147 148 149
            let masterData:any = {};
            <@getStore appEntity=item />
            Object.assign(data,masterData);
            let res:any = await Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${path}${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,data,isloading);
            <@setStore appEntity=item />
150
            return res;
151 152
        }
            </#if>
153
            <#-- 提交对象数据情况end -->
154 155 156 157 158 159 160 161 162 163 164 165 166 167
            <#else>
            <#-- URI参数传递情况start -->
        // URI参数传递情况未实现
            <#-- URI参数传递情况start -->
            </#if>
         <#-- 方法类型为DEACTION end -->
        </#if>
    </#list>
    </#if>
    <#if item.isMajor()>
        <#-- 方法类型为SELECT -->
        <#if singleAppMethod.getMethodType() == "SELECT">
        <#--  if(context.${item.getCodeName()?lower_case}){  -->
            <#if singleServiceApi.getRequestMethod() == 'PUT' ||  singleServiceApi.getRequestMethod() == 'POST'>
168
            return Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,data,isloading);
169
            <#else>
170
            return Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,isloading);
171 172 173 174 175
            </#if>
        <#--  }  -->
        <#-- 方法类型为FETCH -->
        <#elseif singleAppMethod.getMethodType() == "FETCH">
        let tempData:any = JSON.parse(JSON.stringify(data));
176
        return Http.getInstance().get(`/${srfpluralize(item.codeName)?lower_case}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,tempData,isloading);
177 178
        <#-- 方法类型为FETCHTEMP -->
        <#elseif singleAppMethod.getMethodType() == "FETCHTEMP">
179
        return Http.getInstance().get(`/${srfpluralize(item.codeName)?lower_case}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,data,isloading);
180 181 182 183 184 185 186
        <#else>
        <#-- 方法类型为DEACTION start -->
            <#if singleServiceApi.getRequestParamType() == "NONE">
        <#-- 无参数情况start -->
        let res:any = await  Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${srfpluralize(item.codeName)?lower_case}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,isloading);
        res.data.${item.getCodeName()?lower_case} = data.${item.getCodeName()?lower_case};
        <@setStore appEntity=item />
187
        return res;
188 189 190 191 192 193
            <#-- 无参数情况end -->
            <#elseif singleServiceApi.getRequestParamType() == "FIELD">
            <#-- 指定属性情况start -->
            <#-- GET -->
            <#if singleServiceApi.getRequestMethod() == "GET">
        <#--  if(context.${item.getCodeName()?lower_case}){  -->
194
            let res:any = await Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,isloading);
195
            <@setStore appEntity=item />
196
            return res;
197 198 199 200
        <#--  }  -->
            <#elseif singleServiceApi.getRequestMethod() == "POST">
            <#-- REMOVE -->
        <#--  if(context.${item.getCodeName()?lower_case}){  -->
201
            return Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,data,isloading);
202 203 204
        <#--  }    -->
            <#else>
        <#--  if(context.${item.getCodeName()?lower_case}){  -->
205
            return Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,isloading);
206 207
        <#--  }     -->
            </#if>
208
            <#-- 指定属性情况end -->
209 210 211 212 213 214 215 216 217
            <#elseif singleServiceApi.getRequestParamType() == "ENTITY">
            <#-- 提交对象数据情况start -->
        <#if singleAppMethod.getCodeName() == 'Update'>
        let masterData:any = {};
        <@getStore appEntity=item />
        Object.assign(data,masterData);
        <#--  if(context.${item.getCodeName()?lower_case}){  -->
            let res:any = await  Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,data,isloading);
            <@setStore appEntity=item />
218
            return res;
219 220 221 222 223 224 225 226
        <#--  }  -->
        <#elseif singleAppMethod.getCodeName() == 'Save'>
        let masterData:any = {};
        <@getStore appEntity=item />
        Object.assign(data,masterData);
        <#--  if(context.${item.getCodeName()?lower_case}){  -->
            let res:any = await  Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,data,isloading);
            <@setStore appEntity=item />
227
            return res;
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
        <#--  }  -->
        <#elseif singleAppMethod.getCodeName() == 'Create'>
        let masterData:any = {};
        <@getStore appEntity=item />
        Object.assign(data,masterData);
        if(!data.srffrontuf || data.srffrontuf !== "1"){
            data[this.APPDEKEY] = null;
        }
        if(data.srffrontuf){
            delete data.srffrontuf;
        }
        let tempContext:any = JSON.parse(JSON.stringify(context));
        let res:any = await Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${srfpluralize(item.codeName)?lower_case}`,data,isloading);
        <#if item.getMajorPSAppDERSs()??>
        <#list item.getMajorPSAppDERSs() as deReRs>
        <#-- 主实体 -->
        <#assign majorPSAppDataEntity = deReRs.getMajorPSAppDataEntity() />
        <#-- 从实体 -->
        <#assign minorPSAppDataEntity = deReRs.getMinorPSAppDataEntity() />
        this.tempStorage.setItem(tempContext.srfsessionkey+'_${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}',JSON.stringify(res.data.${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}));
        </#list>
        </#if>
250
        return res;
251 252
        <#else>
        <#--  if(context.${item.getCodeName()?lower_case}){  -->
253
            return Http.getInstance().${singleServiceApi.getRequestMethod()?lower_case}(`/${srfpluralize(item.codeName)?lower_case}/<#noparse>$</#noparse>{context.${item.getCodeName()?lower_case}}<#if singleServiceApi.getRequestPath()??>${singleServiceApi.getRequestPath()}</#if>`,data,isloading);
254 255
        <#--  }  -->
        </#if>
256
            <#-- 提交对象数据情况end -->
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
            <#else>
            <#-- URI参数传递情况start -->
        // URI参数传递情况未实现
            <#-- URI参数传递情况start -->
            </#if>
         <#-- 方法类型为DEACTION end -->
        </#if>
    </#if>
    <#-- 嵌套成员 -->
    <#if item.isMajor() == false && !singleServiceApi??>
     <#if singleAppMethod.getMethodType() == "SELECT">
        // ${singleAppMethod.getCodeName()} ---SELECT
        <#-- 方法类型为FETCH -->
     <#elseif singleAppMethod.getMethodType() == "FETCH">
        // ${singleAppMethod.getCodeName()} ---FETCH
        <#if item.getMinorPSAppDERSs()??>
        <#list item.getMinorPSAppDERSs() as singleDeRs>
        <#assign majorEntity = singleDeRs.getMajorPSAppDataEntity()/>
        if(context.srfsessionkey && !Object.is(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}'),'undefined')){
            let result:any = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}') as any);
            if(result){
278
                return {"status":200,"data":result};
279
            }else{
280
                return {"status":200,"data":[]};
281 282
            } 
        }else{
283
            return {"status":200,"data":[]};
284 285 286 287 288 289 290 291 292 293 294 295
        }
        </#list>
        </#if>
        <#-- 方法类型为FETCH -->
     <#elseif singleAppMethod.getMethodType() == "FETCHTEMP">
        // ${singleAppMethod.getCodeName()} ---FETCHTEMP
        <#if item.getMinorPSAppDERSs()??>
        <#list item.getMinorPSAppDERSs() as singleDeRs>
        <#assign majorEntity = singleDeRs.getMajorPSAppDataEntity()/>
        if(context.srfsessionkey && !Object.is(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}'),'undefined')){
            let result:any = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}') as any);
            if(result){
296
                return {"status":200,"data":result};
297
            }else{
298
                return {"status":200,"data":[]};
299 300
            } 
        }else{
301
            return {"status":200,"data":[]};
302 303 304 305 306 307 308 309 310 311 312 313 314 315
        }
        </#list>
        </#if>
     <#else>
        <#if singleAppMethod.getCodeName() == "Save">
        // 从实体Save 行为暂未实现
        <#elseif singleAppMethod.getCodeName() == "Remove">
        <#if item.getMinorPSAppDERSs()??>
        <#list item.getMinorPSAppDERSs() as singleDeRs>
        <#assign majorEntity = singleDeRs.getMajorPSAppDataEntity()/>
        if(context.srfsessionkey && !Object.is(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}'),'undefined')){
            let result:any = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}') as any);
            if(result){
                let tempResult:any = result.filter((item:any) =>{
316
                    return !Object.is(item.${item.getCodeName()?lower_case},data.${item.getCodeName()?lower_case});
317 318
                })
                this.tempStorage.setItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}',JSON.stringify(tempResult));
319
                 return {"status":200,"data":data};
320
            }else{
321
                return {"status":500,"data":null};
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
            } 
        }
        </#list>
        </#if>
        <#elseif singleAppMethod.getCodeName() == "Update">
        <#if item.getMinorPSAppDERSs()??>
        <#list item.getMinorPSAppDERSs() as singleDeRs>
        <#assign majorEntity = singleDeRs.getMajorPSAppDataEntity()/>
        if(context.srfsessionkey && !Object.is(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}'),'undefined')){
            let result:any = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}') as any);
            let tempData:Array<any> = [];
            if(result && result.length >0){
                result.forEach((item:any) => {
                    let singleData:any = {};
                    if(Object.is(item.${item.getCodeName()?lower_case},data.${item.getCodeName()?lower_case})){
                        Object.keys(item).forEach((field:any) =>{
                            singleData[field] = data[field]?data[field]:item[field];
                        })
                    }
                    if(Object.keys(singleData).length >0){
                        tempData.push(singleData);
                    }else{
                        tempData.push(item);
                    }  
                });
                this.tempStorage.setItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}',JSON.stringify(tempData));
348
                return {"status":200,"data":data};
349
            }else{
350
                return {"status":500,"data":null};
351 352 353 354 355 356 357 358 359 360 361 362
            }
        }
        </#list>
        </#if>
        <#elseif singleAppMethod.getCodeName() == "GetDraft">
        let tempData = {${item.getCodeName()?lower_case}:data.${item.getCodeName()?lower_case},srfsessionkey:context.srfsessionkey};
        <#if item.getMinorPSAppDERSs()??>
        <#list item.getMinorPSAppDERSs() as singleDeRs>
        <#assign majorEntity = singleDeRs.getMajorPSAppDataEntity()/>
        Object.assign(tempData,{${majorEntity.getCodeName()?lower_case}:data.${majorEntity.getCodeName()?lower_case}});
        </#list>
        </#if>
363
        return {"status":200,"data":tempData}; 
364 365 366 367
        <#elseif singleAppMethod.getCodeName() == "Create">
        <#if item.getMinorPSAppDERSs()??>
        <#list item.getMinorPSAppDERSs() as singleDeRs>
        <#assign majorEntity = singleDeRs.getMajorPSAppDataEntity()/>
368
         if(context.srfsessionkey && !Object.is(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}'),'undefined')){
369 370 371 372 373 374 375 376 377
            let ${srfpluralize(item.codeName)?lower_case}:any = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}') as any);
            if(!data.srffrontuf || data.srffrontuf !== "1"){
                data[this.APPDEKEY] = null;
            }
            if(data.srffrontuf){
                delete data.srffrontuf;
            }
            ${srfpluralize(item.codeName)?lower_case}.push(data);
            this.tempStorage.setItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}',JSON.stringify(${srfpluralize(item.codeName)?lower_case}));
378
            return {"status":200,"data":data};
379
        }else{
380
            return {"status":200,"data":{}};
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
        }
        </#list>
        </#if>
        <#elseif singleAppMethod.getCodeName() == "CheckKey">
        <#if item.getMinorPSAppDERSs()??>
        <#list item.getMinorPSAppDERSs() as singleDeRs>
        <#assign majorEntity = singleDeRs.getMajorPSAppDataEntity()/>
        if(context.srfsessionkey && !Object.is(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}'),'undefined')){
            let result:any = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}') as any);
            if(result){
               let flag:boolean = false;
                result.forEach((item:any) => {
                    if(Object.is(item.${item.getCodeName()?lower_case},data.${item.getCodeName()?lower_case})){
                        flag = true;
                    }
                });
397
                return {"status":200,"data":flag};
398
            }else{
399
                return {"status":500,"data":null};
400 401 402 403 404 405 406 407 408 409 410 411
            } 
        }
        </#list>
        </#if>
        <#elseif singleAppMethod.getCodeName() == "Get">
        <#if item.getMinorPSAppDERSs()??>
        <#list item.getMinorPSAppDERSs() as singleDeRs>
        <#assign majorEntity = singleDeRs.getMajorPSAppDataEntity()/>
        if(context.srfsessionkey && !Object.is(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}'),'undefined')){
            let result:any = JSON.parse(this.tempStorage.getItem(context.srfsessionkey+'_${srfpluralize(item.codeName)?lower_case}') as any);
            if(result){
                let tempResult:any = result.filter((item:any) =>{
412
                    return Object.is(item.${item.getCodeName()?lower_case},data.${item.getCodeName()?lower_case});
413 414
                })
                let tempResultData:any = tempResult.length>0?tempResult[0]:Object.assign({},data);
415
                return {"status":200,"data":tempResultData};
416
            }else{
417
                return {"status":500,"data":null};
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
            } 
        }
        </#list>
        </#if>
        <#else>
            <#list 1..item.getPSAppDERSPathCount() as count>
                <#assign path = ''/>
                <#assign condition = ''/>
                <#list item.getPSAppDERSPath(count_index)  as deRSPath>
                    <#if deRSPath.getMajorPSAppDataEntity?? && deRSPath.getMajorPSAppDataEntity()??>
                        <#assign _dataEntity = deRSPath.getMajorPSAppDataEntity()/>
                        <#assign condition>${condition}context.${_dataEntity.getCodeName()?lower_case} && </#assign>
                        <#assign path>${path}${srfpluralize(_dataEntity.codeName)?lower_case}/<#noparse>$</#noparse>{context.${_dataEntity.getCodeName()?lower_case}}/</#assign>
                    </#if>
                </#list>
433 434
        if(${condition} true){
            return Http.getInstance().post(`${path}${srfpluralize(item.codeName)?lower_case}/${singleAppMethod.getCodeName()?lower_case}`,data,isloading);
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
        }
            </#list>
        </#if>
     </#if>
    </#if>
</#macro>
<#-- 定义service_block end -->


/**
 * ${de.getLogicName()}服务对象基类
 *
 * @export
 * @class ${srfclassname('${item.getCodeName()}')}ServiceBase
 * @extends {EntityServie}
 */
export default class ${srfclassname('${item.getCodeName()}')}ServiceBase extends EntityService {

    /**
     * Creates an instance of  ${srfclassname('${item.getCodeName()}')}ServiceBase.
     * 
     * @param {*} [opts={}]
     * @memberof  ${srfclassname('${item.getCodeName()}')}ServiceBase
     */
    constructor(opts: any = {}) {
        super(opts);
    }

    /**
     * 初始化基础数据
     *
     * @memberof ${srfclassname('${item.getCodeName()}')}ServiceBase
     */
    public initBasicData(){
        this.APPLYDEKEY ='${item.codeName?lower_case}';
        this.APPDEKEY = '${item.getKeyPSAppDEField().getCodeName()?lower_case}';
        this.APPDENAME = '${srfpluralize(item.codeName)?lower_case}';
        this.APPDETEXT = '<#if item.getMajorPSAppDEField?? && item.getMajorPSAppDEField()??>${item.getMajorPSAppDEField().getCodeName()?lower_case}</#if>';
473 474
        this.APPNAME = '${app.getCodeName()?lower_case}';
        this.SYSTEMNAME = '${app.getPSSystem().getCodeName()?lower_case}';
475 476 477 478 479
    }

// 实体接口
<#-- 实体接口调用start -->
<#if item.getAllPSAppDEMethods?? && item.getAllPSAppDEMethods()??>
480 481 482 483
<#list item.getAllPSAppDEMethods() as singleAppMethod>
<#if singleAppMethod.getPSDEServiceAPIMethod?? &&  singleAppMethod.getPSDEServiceAPIMethod()??>
 <#assign singleServiceApi = singleAppMethod.getPSDEServiceAPIMethod()/>
</#if>
484 485 486
    <#if singleAppMethod.render??>
        ${singleAppMethod.render.code}
    <#else>
487
    <#if singleAppMethod.isBuiltinMethod() == false>
488 489 490 491 492 493 494 495 496 497 498

    /**
     * ${singleAppMethod.getCodeName()}接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${item.getCodeName()}')}ServiceBase
     */
    public async ${singleAppMethod.getCodeName()}(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {
499 500 501 502 503
    <#--是否存在前端处理逻辑start -->
    <#if singleAppMethod.getPSDEAction()??>
    <#assign appdeAction = singleAppMethod.getPSDEAction() />
    <#if appdeAction.getPSDELogic?? && appdeAction.getPSDELogic()?? && (appdeAction.getActionHolder() == 2 || appdeAction.getActionHolder() == 3)   >
    <#assign appdelogic = appdeAction.getPSDELogic() />
tony001's avatar
tony001 committed
504
        let appLogic:${srfclassname('${appdelogic.getCodeName()}')}Logic = new ${srfclassname('${appdelogic.getCodeName()}')}Logic({context:JSON.parse(JSON.stringify(context)),data:JSON.parse(JSON.stringify(data))});
505
        const result = await appLogic.onExecute(context,data,isloading?true:false);
506 507
        return {status:200,data:result};
    <#else>
508
    <@service_block item=item singleAppMethod=singleAppMethod/>
509 510 511
    </#if>
    <#--是否存在前端处理逻辑end -->
    <#else>
512
    <@service_block item=item singleAppMethod=singleAppMethod/>
513
    </#if>
514 515
    }
    </#if>
516 517
    </#if>
</#list>
518 519 520
</#if>
<#-- 实体接口调用end -->
}