%DE_PKGPATH%s.ts.ftl 23.1 KB
Newer Older
ibizdev's avatar
ibizdev committed
1 2 3
<#ibiztemplate>
TARGET=PSAPPDATAENTITY
</#ibiztemplate>
KK's avatar
KK committed
4
import qs from 'qs';
ibizdev's avatar
ibizdev committed
5 6
import { MockAdapter } from '@/mock/mock-adapter';
const mock = MockAdapter.getInstance();
KK's avatar
KK committed
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
<#--  日志方法: BEGIN  -->
<#macro startLog appMethod>
    console.groupCollapsed("实体:${item.codeName?lower_case} 方法: ${appMethod.getCodeName()}");
    console.table({url:config.url, method: config.method, data:config.data});
</#macro>
<#macro endLog appMethod dataName>
    console.groupCollapsed("response数据  status: "+status+" data: ");
    console.table(${dataName});
    console.groupEnd();
    console.groupEnd();
</#macro>
<#--  日志方法: END  -->

<#--  输出排序方法: BEGIN -->
<#--  排序宏  -->
<#macro outputSort priority position>
  <#assign outputSort_nested><#nested></#assign>
  <#if !outputSort_maxPriority?has_content>
    <#assign outputSort_maxPriority = priority>
  <#else>
    <#if priority gt outputSort_maxPriority >
      <#assign outputSort_maxPriority = priority>
    </#if>
  </#if>
  <#assign outputSort_template>${
    "<#if position == 'before'>
      <#assign outputSort_param"+priority+">
        "+r"${outputSort_nested}<#t>"+"
        <#if outputSort_param"+priority+"?has_content>"+r"${outputSort_param"+priority+"}</#if><#t>
      </#assign>
    </#if>
    <#if position== 'after'>
      <#assign outputSort_param"+priority+">
        <#if outputSort_param"+priority+"?has_content>"+r"${outputSort_param"+priority+"}</#if><#t>
        "+r"${outputSort_nested}<#t>"+"
      </#assign>
    </#if>"
  }</#assign>
  <@outputSort_template?interpret />
</#macro>
<#--  输出宏  -->
<#macro outputSort_print>
  <#if outputSort_maxPriority?has_content && outputSort_maxPriority?is_number>
    <#list 0..outputSort_maxPriority as i >
      <#assign outputSort_template>${
        "<#if outputSort_param"+i+"?has_content>"
        +r"${outputSort_param"+i+"}<#t>"
        +"</#if>"
      }</#assign>
      <@outputSort_template?interpret />
    </#list>
  </#if>
</#macro>
<#--  重置变量  -->
<#macro outputSort_clear>
  <#if outputSort_maxPriority?has_content && outputSort_maxPriority?is_number>
    <#list 0..outputSort_maxPriority as i >
      <#assign outputSort_template>${
        "<#if outputSort_param"+i+"?has_content>"
        +r"<#assign outputSort_param"+i+r"=''/>"
        +"</#if>"
      }</#assign>
      <@outputSort_template?interpret />
    </#list>
    <#assign outputSort_maxPriority='' />
  </#if>
</#macro>
<#--  输出排序方法: END -->
<@outputSort_clear />
ibizdev's avatar
ibizdev committed
76 77 78 79 80 81 82 83 84 85 86

// 模拟数据
const mockDatas: Array<any> = [
<#if de.getAllPSDESampleDatas?? &&  de.getAllPSDESampleDatas()??>
<#list de.getAllPSDESampleDatas() as data>
    ${data.getDataJO().toString()}<#if data_has_next>,</#if>
</#list>
</#if>
];


KK's avatar
KK committed
87 88 89 90 91
//getwflink
mock.onGet(new RegExp(/^\/wfcore\/${app.getPSSystem().getCodeName()?lower_case}-app-${app.getCodeName()?lower_case}\/${srfpluralize(item.codeName)?lower_case}\/[a-zA-Z0-9\-\;]+\/usertasks\/[a-zA-Z0-9\-\;]+\/ways$/)).reply((config: any) => {
    console.groupCollapsed("实体:${item.codeName?lower_case} 方法: getwflink");
    console.table({url:config.url, method: config.method, data:config.data});
    console.groupEnd();
ibizdev's avatar
ibizdev committed
92 93
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
KK's avatar
KK committed
94
        return [status, {}];
ibizdev's avatar
ibizdev committed
95
    }
KK's avatar
KK committed
96 97 98 99 100 101 102 103
    return [status,[
        {"sequenceFlowId":"dfdsfdsfdsfdsfds","sequenceFlowName":"同意",
         "taskId":"aaaaddddccccddddd","processDefinitionKey":"support-workorders-approve-v1",
         "processInstanceId":"ddlfldldfldsfds","refViewKey":""},
        {"sequenceFlowId":"ddssdfdfdfdfsfdf","sequenceFlowName":"不同意",
         "taskId":"aaaaddddccccddddd","processDefinitionKey":"support-workorders-approve-v1",
         "processInstanceId":"ddfdsldlfdlldsf","refViewKey":"workorder_ltform_editview"}
        ]];
ibizdev's avatar
ibizdev committed
104 105
});

KK's avatar
KK committed
106 107 108 109 110
// getwfstep
mock.onGet(new RegExp(/^\/wfcore\/${app.getPSSystem().getCodeName()?lower_case}-app-${app.getCodeName()?lower_case}\/${srfpluralize(item.codeName)?lower_case}\/process-definitions-nodes$/)).reply((config: any) => {
    console.groupCollapsed("实体:${item.codeName?lower_case} 方法: getwfstep");
    console.table({url:config.url, method: config.method, data:config.data});
    console.groupEnd();
ibizdev's avatar
ibizdev committed
111 112
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
KK's avatar
KK committed
113
        return [status, {}];
ibizdev's avatar
ibizdev committed
114
    }
KK's avatar
KK committed
115 116 117 118 119 120 121 122 123 124 125 126 127
    return [status, [
        {"userTaskId":"sddfddfd-dfdf-fdfd-fdf-dfdfd",
        "userTaskName":"待审",
        "cnt":0,
        "processDefinitionKey":"support-workorders-approve-v1",
        "processDefinitionName":"工单审批流程v1"
        },
        {"userTaskId":"sddfddfd-dfdf-fdfd-fdf-87927",
        "userTaskName":"待分配",
        "cnt":3,
        "processDefinitionKey":"support-workorders-approve-v1",
        "processDefinitionName":"工单审批流程v1"}
        ]];
ibizdev's avatar
ibizdev committed
128 129
});

KK's avatar
KK committed
130 131 132 133 134
// createBatch
mock.onPost(new RegExp(/^\/${srfpluralize(item.codeName)?lower_case}\/batch$/)).reply((config: any) => {
    console.groupCollapsed("实体:${item.codeName?lower_case} 方法: createBatch");
    console.table({url:config.url, method: config.method, data:config.data});
    console.groupEnd();
ibizdev's avatar
ibizdev committed
135 136
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
KK's avatar
KK committed
137
        return [status, {}];
ibizdev's avatar
ibizdev committed
138
    }
KK's avatar
KK committed
139
    return [status, {}];
ibizdev's avatar
ibizdev committed
140 141
});

KK's avatar
KK committed
142 143 144 145 146
// updateBatch
mock.onPut(new RegExp(/^\/${srfpluralize(item.codeName)?lower_case}\/batch$/)).reply((config: any) => {
    console.groupCollapsed("实体:${item.codeName?lower_case} 方法: updateBatch");
    console.table({url:config.url, method: config.method, data:config.data});
    console.groupEnd();
ibizdev's avatar
ibizdev committed
147 148
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
KK's avatar
KK committed
149
        return [status, {}];
ibizdev's avatar
ibizdev committed
150
    }
KK's avatar
KK committed
151
    return [status, {}];
ibizdev's avatar
ibizdev committed
152 153
});

KK's avatar
KK committed
154 155 156 157 158
// removeBatch
mock.onDelete(new RegExp(/^\/${srfpluralize(item.codeName)?lower_case}\/batch$/)).reply((config: any) => {
    console.groupCollapsed("实体:${item.codeName?lower_case} 方法: removeBatch");
    console.table({url:config.url, method: config.method, data:config.data});
    console.groupEnd();
ibizdev's avatar
ibizdev committed
159 160
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
KK's avatar
KK committed
161
        return [status, {}];
ibizdev's avatar
ibizdev committed
162
    }
KK's avatar
KK committed
163 164
    return [status, {}];
});
ibizdev's avatar
ibizdev committed
165

KK's avatar
KK committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
<#-- 实体接口mock数据:BEGIN -->
<#if item.getAllPSAppDEMethods?? && item.getAllPSAppDEMethods()??>
  <#list item.getAllPSAppDEMethods() as singleAppMethod>
    <#if singleAppMethod.getPSDEServiceAPIMethod?? &&  singleAppMethod.getPSDEServiceAPIMethod()??>
      <#assign singleServiceApi = singleAppMethod.getPSDEServiceAPIMethod()/>
    </#if>
    <#-- 应用实体关系路径数大于0 && 拥有实体服务接口方法: BEGIN -->
    <#if item.getPSAppDERSPathCount() gt 0 && singleServiceApi??>
      <#list 1..item.getPSAppDERSPathCount() as count>
        <#assign path = ''/>
        <#assign param = ''/>
        <#list item.getPSAppDERSPath(count_index)  as deRSPath>
            <#if deRSPath.getMajorPSAppDataEntity?? && deRSPath.getMajorPSAppDataEntity()??>
                <#assign _dataEntity = deRSPath.getMajorPSAppDataEntity()/>
                <#assign param>${param}'${_dataEntity.getKeyPSAppDEField().getCodeName()?lower_case}'<#if deRSPath_has_next>,</#if></#assign>
                <#assign path>${path}${srfpluralize(_dataEntity.codeName)?lower_case}\/([a-zA-Z0-9\-\;]{1,35})\/</#assign>
            </#if>
        </#list>
ibizdev's avatar
ibizdev committed
184

KK's avatar
KK committed
185 186
        <#-- 方法类型为SELECT: BEGIN -->
        <#if singleAppMethod.getMethodType() == "SELECT">
ibizdev's avatar
ibizdev committed
187

KK's avatar
KK committed
188 189 190
// ${singleAppMethod.getCodeName()}
mock.on${srfclassname('${singleServiceApi.getRequestMethod()?lower_case}')}(new RegExp(/^\/${path}${srfpluralize(item.codeName)?lower_case}\/([a-zA-Z0-9\-\;]{1,35})<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/)).reply((config: any) => {
<@startLog singleAppMethod />
ibizdev's avatar
ibizdev committed
191 192 193 194
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
        return [status, null];
    }
KK's avatar
KK committed
195 196 197 198 199 200 201 202 203 204
    const paramArray:Array<any> = [${param},'${item.getKeyPSAppDEField().getCodeName()?lower_case}'];
    const matchArray:any = new RegExp(/^\/${path}${srfpluralize(item.codeName)?lower_case}\/([a-zA-Z0-9\-\;]{1,35})<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/).exec(config.url);
    let tempValue: any = {};
    if(matchArray && matchArray.length >1 && paramArray && paramArray.length >0){
        paramArray.forEach((item: any, index: number) => {
            Object.defineProperty(tempValue, item, {
                enumerable: true,
                value: matchArray[index + 1]
            });
        });
ibizdev's avatar
ibizdev committed
205
    }
KK's avatar
KK committed
206 207 208 209
    let items = mockDatas ? mockDatas : [];
    let _items = items.find((item: any) => Object.is(item.${item.getKeyPSAppDEField().getCodeName()?lower_case}, tempValue.${item.getKeyPSAppDEField().getCodeName()?lower_case}));
<@endLog appMethod=singleAppMethod dataName="_items"/>
    return [status, _items];
ibizdev's avatar
ibizdev committed
210
});
KK's avatar
KK committed
211 212 213
        <#-- 方法类型为SELECT: END -->
        <#-- 方法类型为FETCH: BEGIN -->
        <#elseif singleAppMethod.getMethodType() == "FETCH">
ibizdev's avatar
ibizdev committed
214

KK's avatar
KK committed
215 216 217
// ${singleAppMethod.getCodeName()}
mock.onGet(new RegExp(/^\/${path}${srfpluralize(item.codeName)?lower_case}<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/)).reply((config: any) => {
<@startLog singleAppMethod />
ibizdev's avatar
ibizdev committed
218 219 220 221
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
        return [status, null];
    }
KK's avatar
KK committed
222 223 224 225 226 227 228 229 230 231
    const paramArray:Array<any> = [${param}];
    let tempValue: any = {};
    const matchArray:any = new RegExp(/^\/${path}${srfpluralize(item.codeName)?lower_case}<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/).exec(config.url);
    if(matchArray && matchArray.length >1 && paramArray && paramArray.length >0){
        paramArray.forEach((item: any, index: number) => {
            Object.defineProperty(tempValue, item, {
                enumerable: true,
                value: matchArray[index + 1]
            });
        });
ibizdev's avatar
ibizdev committed
232
    }
KK's avatar
KK committed
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
    let items = mockDatas ? mockDatas : [];
    if (items.length > 0 && paramArray.length > 0) {
        paramArray.forEach((paramkey: any) => {
            if (tempValue[paramkey] && tempValue[paramkey].indexOf(";") > 0) {
                let keysGrounp: Array<any> = tempValue[paramkey].split(new RegExp(/[\;]/));
                let tempArray: Array<any> = [];
                keysGrounp.forEach((singlekey: any) => {
                    let _items =  items.filter((item: any) => { return item[paramkey] == singlekey });
                   if(_items.length >0){
                    tempArray.push(..._items);
                   }
                })
                items = tempArray;
            } else {
                items = items.filter((item: any) => { return item[paramkey] == tempValue[paramkey] });
            }
        })
    }
<@endLog appMethod=singleAppMethod dataName="items"/>
    return [status, items];
ibizdev's avatar
ibizdev committed
253
});
KK's avatar
KK committed
254 255 256 257 258
        <#-- 方法类型为FETCH: END -->
        <#-- 方法类型为DEACTION: BEGIN -->
        <#else>
            <#-- 方法请求不需要参数情况: BEGIN -->
            <#if singleServiceApi.getRequestParamType() == "NONE">
ibizdev's avatar
ibizdev committed
259

KK's avatar
KK committed
260 261 262 263
// ${singleAppMethod.getCodeName()}
mock.on${srfclassname('${singleServiceApi.getRequestMethod()?lower_case}')}(new RegExp(/^\/${path}${srfpluralize(item.codeName)?lower_case}<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/)).reply((config: any) => {
<@startLog singleAppMethod />
    // ${singleAppMethod.getCodeName()}
ibizdev's avatar
ibizdev committed
264 265 266 267
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
        return [status, null];
    }
KK's avatar
KK committed
268 269
<@endLog appMethod=singleAppMethod dataName="{}"/>
    return [status, {}];
ibizdev's avatar
ibizdev committed
270
});
KK's avatar
KK committed
271 272 273 274 275 276 277 278
            <#-- 方法请求不需要参数情况: END -->
            <#-- 方法请求参数为指定字段属性值: BEGIN -->
            <#elseif singleServiceApi.getRequestParamType() == "FIELD">
<@outputSort 1 'after'>

// ${singleAppMethod.getCodeName()}
mock.on${srfclassname('${singleServiceApi.getRequestMethod()?lower_case}')}(new RegExp(/^\/${path}${srfpluralize(item.codeName)?lower_case}\/([a-zA-Z0-9\-\;]{1,35})<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/)).reply((config: any) => {
<@startLog singleAppMethod />
ibizdev's avatar
ibizdev committed
279 280 281
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
        return [status, null];
KK's avatar
KK committed
282 283 284 285 286 287 288 289 290 291 292
    }    
    const paramArray:Array<any> = [${param},'${item.getKeyPSAppDEField().getCodeName()?lower_case}'];
    const matchArray:any = new RegExp(/^\/${path}${srfpluralize(item.codeName)?lower_case}\/([a-zA-Z0-9\-\;]{1,35})<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/).exec(config.url);
    let tempValue: any = {};
    if(matchArray && matchArray.length >1 && paramArray && paramArray.length >0){
        paramArray.forEach((item: any, index: number) => {
            Object.defineProperty(tempValue, item, {
                enumerable: true,
                value: matchArray[index + 1]
            });
        });
ibizdev's avatar
ibizdev committed
293
    }
KK's avatar
KK committed
294 295 296 297
    let items = mockDatas ? mockDatas : [];
    let _items = items.find((item: any) => Object.is(item.${item.getKeyPSAppDEField().getCodeName()?lower_case}, tempValue.${item.getKeyPSAppDEField().getCodeName()?lower_case}));
<@endLog appMethod=singleAppMethod dataName="_items?_items:{}"/>
    return [status, _items?_items:{}];
ibizdev's avatar
ibizdev committed
298
});
KK's avatar
KK committed
299 300 301 302 303 304 305 306
</@outputSort>
            <#-- 方法请求参数为指定字段属性值: END -->
            <#-- 方法请求参数为实体对象数据: BEGIN -->
            <#elseif singleServiceApi.getRequestParamType() == "ENTITY">
    
// ${singleAppMethod.getCodeName()}
mock.on${srfclassname('${singleServiceApi.getRequestMethod()?lower_case}')}(new RegExp(/^\/${path}${srfpluralize(item.codeName)?lower_case}\/([a-zA-Z0-9\-\;]{1,35})<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/)).reply((config: any) => {
<@startLog singleAppMethod />
ibizdev's avatar
ibizdev committed
307 308 309 310
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
        return [status, null];
    }
KK's avatar
KK committed
311 312 313 314 315 316 317 318 319 320 321 322 323
    const paramArray:Array<any> = [${param},'${item.getKeyPSAppDEField().getCodeName()?lower_case}'];
    const matchArray:any = new RegExp(/^\/${path}${srfpluralize(item.codeName)?lower_case}\/([a-zA-Z0-9\-\;]{1,35})<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/).exec(config.url);
    let tempValue: any = {};
    if(matchArray && matchArray.length >1 && paramArray && paramArray.length >0){
        paramArray.forEach((item: any, index: number) => {
            Object.defineProperty(tempValue, item, {
                enumerable: true,
                value: matchArray[index + 1]
            });
        });
    }
<@endLog appMethod=singleAppMethod dataName="{}"/>
    return [status, {}];
ibizdev's avatar
ibizdev committed
324
});
KK's avatar
KK committed
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
            <#-- 方法请求参数为实体对象数据: END -->
            <#-- 方法请求参数为URI参数数据: BEGIN -->
            <#else>
// URI参数传递情况未实现
            </#if>
            <#-- 方法请求参数为URI参数数据: END -->
        </#if>
        <#-- 方法类型为DEACTION: END -->
      </#list>
    </#if>
    <#-- 应用实体关系路径数大于0 && 拥有实体服务接口方法: END -->
    <#--  主实体方法: BEGIN  -->
    <#if item.isMajor()>
        <#-- 方法类型为SELECT: BEGIN -->
        <#if singleAppMethod.getMethodType() == "SELECT">

// ${singleAppMethod.getCodeName()}
mock.on${srfclassname('${singleServiceApi.getRequestMethod()?lower_case}')}(new RegExp(/^\/${srfpluralize(item.codeName)?lower_case}\/([a-zA-Z0-9\-\;]{1,35})<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/)).reply((config: any) => {
<@startLog singleAppMethod />
ibizdev's avatar
ibizdev committed
344 345 346
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
        return [status, null];
KK's avatar
KK committed
347 348 349 350 351 352 353 354 355 356 357
    }    
    const paramArray:Array<any> = ['${item.getKeyPSAppDEField().getCodeName()?lower_case}'];
    const matchArray:any = new RegExp(/^\/${srfpluralize(item.codeName)?lower_case}\/([a-zA-Z0-9\-\;]{1,35})<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/).exec(config.url);
    let tempValue: any = {};
    if(matchArray && matchArray.length >1 && paramArray && paramArray.length >0){
        paramArray.forEach((item: any, index: number) => {
            Object.defineProperty(tempValue, item, {
                enumerable: true,
                value: matchArray[index + 1]
            });
        });
ibizdev's avatar
ibizdev committed
358
    }
KK's avatar
KK committed
359 360 361 362
    let items = mockDatas ? mockDatas : [];
    let _items = items.find((item: any) => Object.is(item.${item.getKeyPSAppDEField().getCodeName()?lower_case}, tempValue.${item.getKeyPSAppDEField().getCodeName()?lower_case}));
<@endLog appMethod=singleAppMethod dataName="_items"/>
    return [status, _items];
ibizdev's avatar
ibizdev committed
363
});
KK's avatar
KK committed
364 365 366 367 368 369 370
        <#-- 方法类型为SELECT: EWND -->
        <#-- 方法类型为FETCH: BEGIN -->
        <#elseif singleAppMethod.getMethodType() == "FETCH">
    
// ${singleAppMethod.getCodeName()}
mock.onGet(new RegExp(/^\/${srfpluralize(item.codeName)?lower_case}<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/)).reply((config: any) => {
<@startLog singleAppMethod />
ibizdev's avatar
ibizdev committed
371 372 373 374
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
        return [status, null];
    }
KK's avatar
KK committed
375 376
<@endLog appMethod=singleAppMethod dataName="mockDatas"/>
    return [status, mockDatas ? mockDatas : []];
ibizdev's avatar
ibizdev committed
377 378
});

KK's avatar
KK committed
379 380 381 382 383 384 385 386
// ${singleAppMethod.getCodeName()}
mock.onGet(new RegExp(/^\/${srfpluralize(item.codeName)?lower_case}<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>(\?[\w-./?%&=,]*)*$/)).reply((config: any) => {
<@startLog singleAppMethod />
    if(config.url.includes('page')){
        let url = config.url.split('?')[1];
        let params  =  qs.parse(url);
        Object.assign(config, params);
    }
ibizdev's avatar
ibizdev committed
387 388 389 390
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
        return [status, null];
    }
KK's avatar
KK committed
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
    let total = mockDatas.length;
    let records: Array<any> = [];
    if(!config.page || !config.size){
        records = mockDatas;
    }else{
        if((config.page-1)*config.size < total){
          records = mockDatas.slice(config.page,config.size);
        }
    }
    <#--  if(config.query){
        records = records.filter(item => {
          return item.accountname.includes(config.query);
        })
    }  -->
<@endLog appMethod=singleAppMethod dataName="records ?  records : []"/>
    return [status, records ?  records : []];
ibizdev's avatar
ibizdev committed
407
});
KK's avatar
KK committed
408 409 410 411 412
        <#-- 方法类型为FETCH: END -->
        <#-- 方法类型为DEACTION: BEGIN -->
        <#else>
            <#-- 方法请求不需要参数情况: BEGIN -->
            <#if singleServiceApi.getRequestParamType() == "NONE">
ibizdev's avatar
ibizdev committed
413

KK's avatar
KK committed
414 415 416 417
// ${singleAppMethod.getCodeName()}
mock.on${srfclassname('${singleServiceApi.getRequestMethod()?lower_case}')}(new RegExp(/^\/${srfpluralize(item.codeName)?lower_case}<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/)).reply((config: any) => {
<@startLog singleAppMethod />
    // ${singleAppMethod.getCodeName()}
ibizdev's avatar
ibizdev committed
418 419 420 421
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
        return [status, null];
    }
KK's avatar
KK committed
422 423
<@endLog appMethod=singleAppMethod dataName="{}"/>
    return [status, {}];
ibizdev's avatar
ibizdev committed
424
});
KK's avatar
KK committed
425 426 427 428 429 430 431 432
            <#-- 方法请求不需要参数情况: END -->
            <#-- 方法请求参数为指定字段属性值: BEGIN -->
            <#elseif singleServiceApi.getRequestParamType() == "FIELD">
<@outputSort 1 'after'>

// ${singleAppMethod.getCodeName()}
mock.on${srfclassname('${singleServiceApi.getRequestMethod()?lower_case}')}(new RegExp(/^\/${srfpluralize(item.codeName)?lower_case}\/([a-zA-Z0-9\-\;]{1,35})<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/)).reply((config: any) => {
<@startLog singleAppMethod />
ibizdev's avatar
ibizdev committed
433 434 435
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
        return [status, null];
KK's avatar
KK committed
436 437 438 439 440 441 442 443 444 445 446
    }    
    const paramArray:Array<any> = ['${item.getKeyPSAppDEField().getCodeName()?lower_case}'];
    const matchArray:any = new RegExp(/^\/${srfpluralize(item.codeName)?lower_case}\/([a-zA-Z0-9\-\;]{1,35})<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/).exec(config.url);
    let tempValue: any = {};
    if(matchArray && matchArray.length >1 && paramArray && paramArray.length >0){
        paramArray.forEach((item: any, index: number) => {
            Object.defineProperty(tempValue, item, {
                enumerable: true,
                value: matchArray[index + 1]
            });
        });
ibizdev's avatar
ibizdev committed
447
    }
KK's avatar
KK committed
448 449 450 451
    let items = mockDatas ? mockDatas : [];
    let _items = items.find((item: any) => Object.is(item.${item.getKeyPSAppDEField().getCodeName()?lower_case}, tempValue.${item.getKeyPSAppDEField().getCodeName()?lower_case}));
<@endLog appMethod=singleAppMethod dataName="_items?_items:{}"/>
    return [status, _items?_items:{}];
ibizdev's avatar
ibizdev committed
452
});
KK's avatar
KK committed
453 454 455 456 457 458 459 460
</@outputSort>
            <#-- 方法请求参数为指定字段属性值: END -->
            <#-- 方法请求参数为实体对象数据: BEGIN -->
            <#elseif singleServiceApi.getRequestParamType() == "ENTITY">
        
// ${singleAppMethod.getCodeName()}
mock.on${srfclassname('${singleServiceApi.getRequestMethod()?lower_case}')}(new RegExp(/^\/${srfpluralize(item.codeName)?lower_case}\/?([a-zA-Z0-9\-\;]{0,35})<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/)).reply((config: any) => {
<@startLog singleAppMethod />
ibizdev's avatar
ibizdev committed
461 462 463
    let status = MockAdapter.mockStatus(config);
    if (status !== 200) {
        return [status, null];
KK's avatar
KK committed
464 465 466 467 468 469 470 471 472 473 474
    }    
    const paramArray:Array<any> = ['${item.getKeyPSAppDEField().getCodeName()?lower_case}'];
    const matchArray:any = new RegExp(/^\/${srfpluralize(item.codeName)?lower_case}\/([a-zA-Z0-9\-\;]{1,35})<#if singleServiceApi.getRequestPath()??>\${singleServiceApi.getRequestPath()}</#if>$/).exec(config.url);
    let tempValue: any = {};
    if(matchArray && matchArray.length >1 && paramArray && paramArray.length >0){
        paramArray.forEach((item: any, index: number) => {
            Object.defineProperty(tempValue, item, {
                enumerable: true,
                value: matchArray[index + 1]
            });
        });
ibizdev's avatar
ibizdev committed
475
    }
KK's avatar
KK committed
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
       <#if singleAppMethod.getCodeName() == "Create">
<@endLog appMethod=singleAppMethod dataName="mockDatas[0]"/>
    return [status, mockDatas[0]];
              <#else>
    //let items = mockDatas ? mockDatas : [];
    //let _items = items.find((item: any) => Object.is(item.${item.getKeyPSAppDEField().getCodeName()?lower_case}, tempValue.${item.getKeyPSAppDEField().getCodeName()?lower_case}));
      let data = JSON.parse(config.data);
    mockDatas.forEach((item)=>{
        if(item['${item.getKeyPSAppDEField().getCodeName()?lower_case}'] == tempValue['${item.getKeyPSAppDEField().getCodeName()?lower_case}'] ){
            for(let value in data){
              if(item.hasOwnProperty(value)){
                  item[value] = data[value];
              }
            }
        }
    })
<@endLog appMethod=singleAppMethod dataName="data"/>
    return [status, data];
              </#if>
ibizdev's avatar
ibizdev committed
495
});
KK's avatar
KK committed
496 497 498 499
            <#-- 方法请求参数为实体对象数据: END -->
            <#-- 方法请求参数为URI参数数据: BEGIN -->
            <#else>
// URI参数传递情况未实现
ibizdev's avatar
ibizdev committed
500
            </#if>
KK's avatar
KK committed
501
            <#-- 方法请求参数为URI参数数据: END -->
ibizdev's avatar
ibizdev committed
502
        </#if>
KK's avatar
KK committed
503
        <#-- 方法类型为DEACTION: END -->
ibizdev's avatar
ibizdev committed
504
    </#if>
KK's avatar
KK committed
505
    <#--  主实体方法: END  -->
ibizdev's avatar
ibizdev committed
506 507
  </#list>
</#if>
KK's avatar
KK committed
508
<#-- 实体接口mock数据end -->
ibizdev's avatar
ibizdev committed
509

KK's avatar
KK committed
510
<@outputSort_print />