%DE_PKGPATH%-service-base.ts.ftl 40.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
<#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() />
24 25 26 27
        <#-- 从实体支持临时数据模式为true,才设置本地缓存 start -->
        <#-- @author zpc -->
        <#-- @update 2020.7.13 15:00 -->
        <#if minorPSAppDataEntity.isEnableTempData()>
28
            this.tempStorage.setItem(context.srfsessionkey+'_${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}',JSON.stringify(res.data.${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}?res.data.${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}:[]));
29 30
        </#if>
        <#-- 从实体支持临时数据模式为true,才设置本地缓存 end -->
31 32 33 34 35 36 37 38 39 40 41 42
        </#list>
        </#if>
</#macro>

<#-- 获取本地缓存 -->
<#macro getStore appEntity>
        <#if appEntity.getMajorPSAppDERSs()??>
        <#list appEntity.getMajorPSAppDERSs() as deReRs>
        <#-- 主实体 -->
        <#assign majorPSAppDataEntity = deReRs.getMajorPSAppDataEntity() />
        <#-- 从实体 -->
        <#assign minorPSAppDataEntity = deReRs.getMinorPSAppDataEntity() />
43 44 45 46
        <#-- 从实体支持临时数据模式为true,才从前端缓存拿取数据,组装数据给后台 start -->
        <#-- @author zpc -->
        <#-- @update 2020.7.13 15:00 -->
        <#if minorPSAppDataEntity.isEnableTempData()>
47 48 49 50 51 52 53 54
        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;
55 56
                            <#-- 置空父键 -->
                            if(item.hasOwnProperty('${majorPSAppDataEntity.getKeyPSAppDEField().getCodeName()?lower_case}') && item.${majorPSAppDataEntity.getKeyPSAppDEField().getCodeName()?lower_case}) item.${majorPSAppDataEntity.getKeyPSAppDEField().getCodeName()?lower_case} = null;
57 58 59 60 61 62 63
                        }
                        delete item.srffrontuf;
                    }
                });
            }
        }
        masterData.${srfpluralize(minorPSAppDataEntity.codeName)?lower_case} = ${srfpluralize(minorPSAppDataEntity.codeName)?lower_case}Data;
64 65
        </#if>
        <#-- 从实体支持临时数据模式为true,才从前端缓存拿取数据,组装数据给后台 end -->
66 67 68 69
        </#list>
        </#if>
</#macro>

tony001's avatar
tony001 committed
70
<#-- 本地供数satrt -->
71
<#macro local_supply item singleAppMethod>
tony001's avatar
tony001 committed
72
<#if singleAppMethod.getPredefinedType?? && singleAppMethod.getPredefinedType()??>
73
<#-- 预定义类型为索引实体start -->
tony001's avatar
tony001 committed
74 75 76
<#if singleAppMethod.getPredefinedType() == "INDEXDE">
<#if singleAppMethod.getPSAppCodeList?? && singleAppMethod.getPSAppCodeList()??>
<#assign appCodeList = singleAppMethod.getPSAppCodeList() />
77 78 79 80 81 82 83 84 85 86
        let codelistModel:any = {tag:'${appCodeList.codeName}',codelistType:'${appCodeList.getCodeListType()}'};
        let res:any = await this.getCodeList(codelistModel.tag,codelistModel.codelistType,context,data);
        if(res && res.length > 0){
            res.forEach((ele:any) => {
                // 仿真返回数据集
                ele.${item.getKeyPSAppDEField().getCodeName()?lower_case} = ele.value;
                ele.${item.getMajorPSAppDEField().getCodeName()?lower_case} = ele.text
            });
        } 
        return {status:200,data:res};
tony001's avatar
tony001 committed
87 88
</#if>
</#if>
89
<#-- 预定义类型为索引实体end -->
tony001's avatar
tony001 committed
90 91 92 93
</#if>
</#macro>
<#-- 本地供数end -->

94 95 96
<#-- 检查行为是否可以执行 start -->
<#-- @author zpc -->
<#-- @update 2020.7.13 18:00 -->
97 98
<#-- 获取测试行为的修饰符和名称 start -->
<#macro getTestActionModifier appdeAction>
99
<#compress>
100
<#if appdeAction.getTestActionMode() == 1>private</#if><#if appdeAction.getTestActionMode() == 3>public</#if>
101
</#compress>
102 103 104
</#macro>
<#-- 获取测试行为的修饰符和名称 end -->

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

509 510 511 512 513
<#-- 行为执行之前 start -->
<#-- @author zpc -->
<#-- @update 2020.7.14 11:00 -->
<#macro excuteBeforeAction appdeAction>
    <#if appdeAction.getBeforePSDEActionLogics?? && appdeAction.getBeforePSDEActionLogics()??>
514
        <#list appdeAction.getBeforePSDEActionLogics() as beforelogic>
515
        <#if beforelogic.getPSDELogic()?? && beforelogic.getPSDELogic().getLogicHolder?? && beforelogic.getPSDELogic().getLogicHolder()?? && (beforelogic.getPSDELogic().getLogicHolder() == 2 || beforelogic.getPSDELogic().getLogicHolder() == 3)>
516 517 518 519 520
        <#assign singleLogic = beforelogic.getPSDELogic() />
        let ${singleLogic.getCodeName()?lower_case}:${srfclassname('${singleLogic.getCodeName()}')}Logic = new ${srfclassname('${singleLogic.getCodeName()}')}Logic({context:JSON.parse(JSON.stringify(context)),data:JSON.parse(JSON.stringify(data))});
        data = await ${singleLogic.getCodeName()?lower_case}.onExecute(context,data,isloading?true:false);
        </#if>
        </#list>
521 522 523 524
    </#if>
</#macro>
<#-- 行为执行之前 end -->

525 526 527 528 529 530
<#-- 行为执行之后 start -->
<#-- @author zpc -->
<#-- @update 2020.7.14 14:00 -->
<#macro excuteAfterAction appdeAction>
    <#if appdeAction.getAfterPSDEActionLogics?? && appdeAction.getAfterPSDEActionLogics()??>
        <#list appdeAction.getAfterPSDEActionLogics() as afterlogic>
531
        <#if afterlogic.getPSDELogic()?? && afterlogic.getPSDELogic().getLogicHolder?? && afterlogic.getPSDELogic().getLogicHolder()?? && (afterlogic.getPSDELogic().getLogicHolder() == 2 || afterlogic.getPSDELogic().getLogicHolder() == 3)>
532
        <#assign singleLogic = afterlogic.getPSDELogic() />
533
    <@compress single_line=true>let ${singleLogic.getCodeName()?lower_case}:${srfclassname('${singleLogic.getCodeName()}')}Logic = new ${srfclassname('${singleLogic.getCodeName()}')}Logic({context:JSON.parse(JSON.stringify(context)),data:JSON.parse(JSON.stringify(res))});</@compress>
534 535
            <@compress single_line=true>let returndata:any = await ${singleLogic.getCodeName()?lower_case}.onExecute(context,res.data,isloading?true:false);</@compress>
            res ={status:200,data:returndata};
536 537 538 539 540 541
        </#if>
        </#list>
    </#if>
</#macro>
<#-- 行为执行之后 end -->

542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571

/**
 * ${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>';
572 573
        this.APPNAME = '${app.getCodeName()?lower_case}';
        this.SYSTEMNAME = '${app.getPSSystem().getCodeName()?lower_case}';
574 575 576 577 578
    }

// 实体接口
<#-- 实体接口调用start -->
<#if item.getAllPSAppDEMethods?? && item.getAllPSAppDEMethods()??>
579 580
<#list item.getAllPSAppDEMethods() as singleAppMethod>
<#if singleAppMethod.getPSDEServiceAPIMethod?? &&  singleAppMethod.getPSDEServiceAPIMethod()??>
581
<#assign singleServiceApi = singleAppMethod.getPSDEServiceAPIMethod()/>
582
</#if>
583 584 585
    <#if singleAppMethod.render??>
        ${singleAppMethod.render.code}
    <#else>
586
    <#if singleAppMethod.isBuiltinMethod() == false>
587 588 589 590 591 592 593 594 595 596 597

    /**
     * ${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> {
598 599
    <#if singleAppMethod.getPSDEAction()??>
    <#assign appdeAction = singleAppMethod.getPSDEAction() /> 
600 601 602
    <#-- 检查行为是否可以执行 start -->
    <#-- @author zpc -->
    <#-- @update 2020.7.13 16:00 -->
603 604 605 606
    <#if appdeAction.getTestActionMode?? && appdeAction.getTestActionMode()?? && (appdeAction.getTestActionMode() == 1 || appdeAction.getTestActionMode() == 3)>
        let result:any = await this.test${srfclassname('${singleAppMethod.getCodeName()}')}(context,data);
		if(!result) return;
    </#if>
607
    <#-- 检查行为是否可以执行 end -->
608 609 610 611 612 613

    <#-- 行为执行之前 start -->
    <#-- @author zpc -->
    <#-- @update 2020.7.14 11:00 -->
    <@excuteBeforeAction appdeAction = appdeAction />
    <#-- 行为执行之前 end -->
614
    <#--是否存在前端处理逻辑start -->
615 616
    <#if appdeAction.getPSDELogic?? && appdeAction.getPSDELogic()?? && (appdeAction.getActionHolder() == 2 || appdeAction.getActionHolder() == 3)   >
    <#assign appdelogic = appdeAction.getPSDELogic() />
tony001's avatar
tony001 committed
617
        let appLogic:${srfclassname('${appdelogic.getCodeName()}')}Logic = new ${srfclassname('${appdelogic.getCodeName()}')}Logic({context:JSON.parse(JSON.stringify(context)),data:JSON.parse(JSON.stringify(data))});
618 619 620
        const res = await appLogic.onExecute(context,data,isloading?true:false);
        <@excuteAfterAction appdeAction = appdeAction />
        return {status:200,data:res};
621
    <#else>
622 623 624
    <#-- 行为执行之后 start -->
    <#-- @author zpc -->
    <#-- @update 2020.7.14 14:00 -->
625
    <#assign afterActionStr><@excuteAfterAction appdeAction = appdeAction /></#assign>
626 627
    <@service_block item=item singleAppMethod=singleAppMethod afterActionStr = afterActionStr/>
    <#-- 行为执行之后 end -->
628 629 630
    </#if>
    <#--是否存在前端处理逻辑end -->
    <#else>
tony001's avatar
tony001 committed
631
    <#-- 无实体行为,有接口走接口,无接口走本地供数 start -->
632
    <#-- @author zpc -->
tony001's avatar
tony001 committed
633
    <#-- @update 2020.7.22 17:00 -->
tony001's avatar
tony001 committed
634
    <#if singleAppMethod.getPSDEServiceAPIMethod?? &&  singleAppMethod.getPSDEServiceAPIMethod()??>
635
    <@service_block item=item singleAppMethod=singleAppMethod />
tony001's avatar
tony001 committed
636
    <#else>
637
    <@local_supply item=item singleAppMethod=singleAppMethod />
tony001's avatar
tony001 committed
638
    </#if>
tony001's avatar
tony001 committed
639
    <#-- 无实体行为,有接口走接口,无接口走本地供数 end -->
640
    </#if>
641
    }
642
    <#-- 查询数据集(post方式)start -->
643 644
    <#-- @author zpc -->
    <#-- @update 2020.7.13 15:00 -->
645 646
    <#--  <#if singleAppMethod.getMethodType?? && singleAppMethod.getMethodType()?? && singleAppMethod.getMethodType() == "FETCH">
    <#assign dataSet = singleAppMethod.getPSDEDataSet() />  -->
647

648
    <#--  /**
649 650 651 652 653 654 655 656
     * search${dataSet.getCodeName()}接口方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${item.getCodeName()}')}ServiceBase
     */
657
    public async search${dataSet.getCodeName()}(context: any = {},data: any = {}, isloading?: boolean): Promise<any> {  -->
658 659 660
    <#-- 检查行为是否可以执行 start -->
    <#-- @author zpc -->
    <#-- @update 2020.7.13 16:00 -->
661
    <#--  <#if singleAppMethod.getPSDEAction()??>
662
    <#assign appdeAction = singleAppMethod.getPSDEAction() />
663 664 665 666
    <#if appdeAction.getTestActionMode?? && appdeAction.getTestActionMode()?? && (appdeAction.getTestActionMode() == 1 || appdeAction.getTestActionMode() == 3)>
        let result:any = await this.test${srfclassname('search${dataSet.getCodeName()}')}(context,data);
		if(!result) return;
    </#if>
667
    </#if>  -->
668
    <#-- 检查行为是否可以执行 end -->
669
    <#--  <#if item.getPSAppDERSPathCount() gt 0 && singleServiceApi??>
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
        <#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>
        if(${condition}true){
            let tempData:any = JSON.parse(JSON.stringify(data));
            return Http.getInstance().post(`/${path}${srfpluralize(item.codeName)?lower_case}/search${dataSet.getCodeName()?lower_case}`,tempData,isloading);
        }
        </#list>
    </#if>
    <#if item.isMajor()>
        let tempData:any = JSON.parse(JSON.stringify(data));
        return Http.getInstance().post(`/${srfpluralize(item.codeName)?lower_case}/search${dataSet.getCodeName()?lower_case}`,tempData,isloading);
    </#if>
690
    }
691
    </#if>  -->
692
    <#-- 查询数据集(post方式)end -->
693 694 695
    <#-- 检查行为是否可以执行 start -->
    <#-- @author zpc -->
    <#-- @update 2020.7.13 17:00 -->
696 697
    <#if singleAppMethod.getPSDEAction()??>
    <#assign appdeAction = singleAppMethod.getPSDEAction() />
698
    <#if appdeAction.getTestActionMode?? && appdeAction.getTestActionMode()?? && (appdeAction.getTestActionMode() == 1 || appdeAction.getTestActionMode() == 3)>
699 700 701 702 703 704 705 706 707
    
    /**
     * test${srfclassname('${singleAppMethod.getCodeName()}')}方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${item.getCodeName()}')}ServiceBase
     */
708
    <@getTestActionModifier appdeAction=appdeAction/> async test${srfclassname('${singleAppMethod.getCodeName()}')}(context: any = {},data: any = {}): Promise<any> {
709 710
        return true;
    }
tony001's avatar
tony001 committed
711
    <#--  <#if singleAppMethod.getMethodType?? && singleAppMethod.getMethodType()?? && singleAppMethod.getMethodType() == "FETCH">
712 713 714 715 716 717 718 719 720 721
    <#assign dataSet = singleAppMethod.getPSDEDataSet() />

    /**
     * test${srfclassname('search${dataSet.getCodeName()}')}方法
     *
     * @param {*} [context={}]
     * @param {*} [data={}]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${item.getCodeName()}')}ServiceBase
     */
722
    <@getTestActionModifier appdeAction=appdeAction/> async test${srfclassname('search${dataSet.getCodeName()}')}(context: any = {},data: any = {}): Promise<any> {
723 724
        return true;
    }
tony001's avatar
tony001 committed
725
    </#if>  -->
726
    </#if>
727
    </#if>
728
    <#-- 检查行为是否可以执行 end -->
729
    </#if>
730 731
    </#if>
</#list>
732 733 734
</#if>
<#-- 实体接口调用end -->
}