Ben Lin
2024-06-07 aa0bc81d06736cc1a1bd210dde61f57736585d43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
import { UserConfigFn } from 'vite';
import { useGlobSetting } from '/@/hooks/setting';
import { buildUUID } from '../../utils/uuid';
import { DateFormat } from '../../utils/dataformat';
import { ApiAction, ApiActionJob, ApiActionPage } from '../model/baseModel';
import {
  MenuParams,
  RoleParams,
  RolePageParams,
  MenuListGetResultModel,
  RolePageListGetResultModel,
  RoleListGetResultModel,
  SaveMenuParams,
  FuncItem,
  SaveRoleParams,
  RoleItem,
  RoleMenuItem,
  UserGPParams,
  SpecificEntity,
  ParamsPageParams,
  ParamsListGetResultModel,
  ParamsListItem,
  treeParamsListItem,
  ParamsGroupListItem,
  LoginLogPageParams,
  LoginLogPageListGetResultModel,
  iSYS_ROLE_ORG,
  iSYS_ROLE_WH,
  EntityParams,
  EntityList,
  iSYS_ROLE_PROD,
} from './model/systemModel';
import { defHttp } from '/@/utils/http/axios';
import { isNullOrEmpty, isTimeType } from '/@/utils/is';
 
export enum Api {
  QueryUrl = '/Base/Query',
  EntityList = '/Base/QueryWhere',
  EntitySqlList = '/Base/QuerySQL',
  EntityPageList = '/Base/QueryCustomPage',
  IsAccountExist = '/Base/IsExist',
  setRoleStatus = '/system/setRoleStatus',
  MenuList = '/SYS/getMenuListAll',
  SaveMenu = '/SYS/SaveMenu',
  SaveRole = '/SYS/SaveRole',
  AddEntity = '/Base/Add',
  AddListEntity = '/Base/AddList',
  UpdateEntity = '/Base/Update',
  SaveEntity = '/Base/Save',
  SaveEntityList = '/Base/SaveList',
  DeleteList = '/Base/DeleteList',
  DeleteWhere = '/Base/DeleteWhere',
  GetOrgTreeList = '/SYS/getOrgTreeList',
  GetProdTreeList = '/SYS/getProdTreeList',
  GetHouseTreeList = '/WMS/GetHouseModel',
  GetHouseOrgTreeList = '/WMS/GetHouseModelOrg',
  GetCreateBillCode = '/WMS/CreateBillCode',
  GetCreateTFBillCode = '/WMS/CreateTFBillCode',
  GetAllRoleList = '/system/getAllRoleList',
  urlSetSysUserToGroup = '/SYS/SetSysUserToGroup',
  urlSetRoleToGroup = '/SYS/SetRoleToGroup',
  StartJob = '/Tsk/StartJob',
  StopJob = '/Tsk/PauseJob',
  AddJob = '/Tsk/AddJob',
  UpdateJob = '/Tsk/UpdateJob',
  urlQueryEnum = '/Base/QueryEnum',
  DeleteWareHouse = '/WMS/DelWareHouseModel',
  AddLocation = '/WMS/AddLoctionModel',
  CheckLocation = '/WMS/CheckLocation',
  SummaryCount = '/WMS/SummaryCount',
  GenerateCount = '/WMS/GenerateCount',
  GetUpdateOrg = '/WMS/GetUpdateOrg',
  GetQrCode = '/WMS/Item/GetQRCode',
  UpdateReq = '/WMS/UpdateReq',
  MaterialResale = '/WMS/MaterialResale',
  GetProdctResult = '/WMS/ProductInput/GetProdctResult',
  // 完工入库状态还原
  GetStatusRestored = '/WMS/ProductInput/StatusRestored',
  // 批量更新内容
  GetUpdateTime = '/MaterialInfo/UpdateTime',
  //导入
  ValidateTableImport = '/SMT/ValidateTableImport',
  SaveValidateTableImport = '/SMT/SaveValidateTableImport',
  GetEntityNameList = '/System/Entitys/Get',
}
 
const globSetting = useGlobSetting();
 
/**
 * 生成apiaction,带分页
 * @param datatype
 * @param sqlcmd
 * @param page
 * @param pageSize
 * @returns
 */
export function genActionPage(
  datatype: string,
  sqlcmd: string,
  page: number,
  pageSize: number,
  option?: object,
) {
  const time = new Date();
  const params: ApiActionPage = {
    id: buildUUID(),
    dataType: datatype,
    Options: option,
    isAsync: true,
    timestamp: time.toDateString(),
    isSuccessed: true,
    message: '',
    statusCode: 0,
    Data: {
      pageAble_T: 'string',
      draw: 1,
      pageIndex: page,
      pageSize: pageSize,
      recordsTotal: 0,
      recordsFiltered: 0,
      data: [],
      data2: {},
      sqlcmd: ' 1 = 1 ' + sqlcmd,
      totals: 0,
    },
  };
  return params;
}
 
/*
 * 生成Action
 */
export function genAction<T>(datatype: string, data: T, option?: object) {
  const time = new Date();
  const params: ApiAction<T> = {
    ID: buildUUID(),
    DataAssembly: '',
    Options: option,
    DataType: datatype,
    IsAsync: true,
    Timestamp: time.toDateString(),
    IsSuccessed: true,
    Message: '',
    StatusCode: 0,
    Data: data,
    LocaleMsg: undefined,
  };
  return params;
}
export function genActionjob<sting>(
  datatype: string,
  assembly: string,
  data: string,
  timeone: number,
  remark: string,
) {
  const time = new Date();
  const params: ApiActionJob<string> = {
    ID: buildUUID(),
    DataAssembly: assembly,
    DataType: datatype,
    IsAsync: true,
    Timestamp: time.toDateString(),
    IsSuccessed: true,
    Message: '',
    StatusCode: 0,
    Data: {
      jobName: data,
      period: timeone,
      remark: remark,
    },
  };
  return params;
}
/*
 * 是否存在共用
 */
export const isExist = (params: ApiAction<string>) =>
  defHttp.post<ApiAction<boolean>>(
    {
      url: Api.IsAccountExist,
      params,
    },
    {
      errorMessageMode: 'modal',
      isTransformResponse: false,
    },
  );
 
export const getParamListByPage = async (params: ParamsPageParams) => {
  let sqlcmd = '';
  if (params?.PARAM_CODE != undefined && params?.PARAM_CODE != '') {
    sqlcmd += " And PARAM_CODE = '" + params?.PARAM_CODE + "'";
  }
  if (params?.PARAM_NAME != undefined && params?.PARAM_NAME != '') {
    sqlcmd += "And PARAM_NAME like '%" + params?.PARAM_NAME + "%'";
  }
  const rParams = genActionPage('SYS_PARAMGROUP', sqlcmd, params.page, params.pageSize);
  return getParamListByPageAsync(rParams);
};
async function getParamListByPageAsync(params: ApiActionPage) {
  const data = await defHttp.post<ApiActionPage>(
    { url: Api.EntityPageList, params },
    {
      isTransformResponse: false,
    },
  );
  let sqlcmd = '';
  let list = '';
  for (let i = 0; i < data.Data.data.length; i++) {
    if (list != '') {
      list += ',';
    }
    list += `'${data.Data.data[i]['PRMG_CODE']}'`;
  }
  sqlcmd += ` PRMG_CODE in (${list}) or PARAM_CODE in (${list})`;
  const _data = await defHttp.post<ApiAction<treeParamsListItem[]>>(
    { url: Api.EntityList, params: genAction('V_SYS_PARAM', sqlcmd) },
    {
      isTransformResponse: false,
    },
  );
  const TreeData = convertToTreeData(
    _data.Data as treeParamsListItem[],
    'PRMG_CODE',
    'PARAM_CODE',
    undefined,
  );
  const model: ParamsListGetResultModel = {
    items: TreeData,
    total: data.Data.totals,
  };
  return model;
}
 
/*
 * 获取所有参数表为树形json
 */
export const getAllParamList = async () => {
  const sqlcmd = '1=1';
  const rParams = genAction('V_SYS_PARAM', sqlcmd);
  return getAllParamListAsync(rParams);
};
 
async function getAllParamListAsync(params: ApiAction<string>) {
  const data = await defHttp.post<ApiAction<ParamsListItem[]>>(
    { url: Api.EntityList, params: params },
    {
      isTransformResponse: false,
    },
  );
  const TreeData = convertToTreeData(
    data.Data as treeParamsListItem[],
    'PRMG_CODE',
    'PARAM_CODE',
    undefined,
  );
  return TreeData;
}
 
/*
 * 转换参数表为树形json
 */
function convertToTreeData(data: treeParamsListItem[], parentId: string, id: string, pid?: string) {
  const result: treeParamsListItem[] = [];
  let temp: treeParamsListItem[] = [];
  const _pid = pid == undefined ? '' : pid;
  for (let i = 0; i < data.length; i++) {
    const currPid = data[i][parentId] == null ? '' : data[i][parentId];
    if (currPid === _pid) {
      const obj: treeParamsListItem = data[i];
      obj.PARAM_TYPE = _pid == '' ? '0' : '1'; //增加类型
      temp = convertToTreeData(data, parentId, id, data[i][id]);
      if (temp.length > 0) {
        obj.children = temp;
      }
      result.push(obj);
    }
  }
  return result;
}
 
/*
 * 保存参数
 */
export const SaveParams = async (params: ParamsListItem, isUpdate: boolean) => {
  let data;
  if (isUpdate) {
    data = await defHttp.post(
      { url: Api.UpdateEntity, params: genAction('SYS_PARAM', params) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  } else {
    params.ID = buildUUID(); //生成GUID
    data = await defHttp.post(
      { url: Api.AddEntity, params: genAction('SYS_PARAM', params) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  }
  return data;
};
 
export const SaveParamsGroup = async (params: ParamsGroupListItem, isUpdate: boolean) => {
  let data;
  if (isUpdate) {
    data = await defHttp.post(
      { url: Api.UpdateEntity, params: genAction('SYS_PARAMGROUP', params) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  } else {
    params.ID = buildUUID(); //生成GUID
    data = await defHttp.post(
      { url: Api.AddEntity, params: genAction('SYS_PARAMGROUP', params) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  }
  return data;
};
 
/*
 * 删除参数
 */
export const DeleteParams = async (params: Recordable) => {
  const usParams = genAction('SYS_PARAM', [params]);
  return await defHttp.post(
    { url: Api.DeleteList, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};
 
export const DeleteParamsGroup = async (params: Recordable) => {
  const usParams = genAction('SYS_PARAMGROUP', [params]);
  return await defHttp.post(
    { url: Api.DeleteList, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};
 
/*
 * 获取菜单列表
 */
export const getMenuList = (params?: MenuParams) =>
  defHttp.get<MenuListGetResultModel>(
    { url: Api.MenuList, params },
    {
      isTransformResponse: false,
    },
  );
 
/*
 * 获取角色分页列表
 */
export const getRoleListByPage = async (params: RolePageParams) => {
  let sqlcmd = '';
  if (params?.IS_ACTIVE != undefined && params?.IS_ACTIVE != '') {
    sqlcmd += " And IS_ACTIVE = '" + params?.IS_ACTIVE + "'";
  }
  if (params?.ROLE_DESC != undefined && params?.ROLE_DESC != '') {
    sqlcmd += "And ROLE_DESC like '%" + params?.ROLE_DESC + "%'";
  }
  const rParams = genActionPage('SYS_ROLE', sqlcmd, params.page, params.pageSize);
  return getRoleListByPageAsync(rParams);
};
async function getRoleListByPageAsync(params: ApiActionPage) {
  const data = await defHttp.post<ApiActionPage>(
    { url: Api.EntityPageList, params },
    {
      isTransformResponse: false,
    },
  );
  const model: RolePageListGetResultModel = {
    items: data.Data.data,
    total: data.Data.totals,
  };
  return model;
}
 
/*
 * 获取角色菜单列表,用于角色授权菜单列表
 */
export function getRMList(params: string) {
  const rmParams = genAction('SYS_ROLE_MENU', " ROLE_CODE = '" + params + "'");
  return getRoleMenu(rmParams);
}
async function getRoleMenu(params: ApiAction<string>) {
  const data = await defHttp.post<ApiAction<RoleMenuItem[]>>(
    {
      url: Api.EntityList,
      params,
    },
    {
      errorMessageMode: 'modal',
      isTransformResponse: false,
    },
  );
  return data.Data;
}
 
/*
 * 获取角色组织列表,用于角色授权组织列表
 */
export function getROList(params: string) {
  const rmParams = genAction('SYS_ROLE_ORG', " ROLE_CODE = '" + params + "'");
  return getRoleOrg(rmParams);
}
async function getRoleOrg(params: ApiAction<string>) {
  const data = await defHttp.post<ApiAction<iSYS_ROLE_ORG[]>>(
    {
      url: Api.EntityList,
      params,
    },
    {
      errorMessageMode: 'modal',
      isTransformResponse: false,
    },
  );
  return data.Data;
}
 
export function getProdList(params: string) {
  const rmParams = genAction('SYS_ROLE_PROD', " ROLE_CODE = '" + params + "'");
  return getRoleProd(rmParams);
}
async function getRoleProd(params: ApiAction<string>) {
  const data = await defHttp.post<ApiAction<iSYS_ROLE_PROD[]>>(
    {
      url: Api.EntityList,
      params,
    },
    {
      errorMessageMode: 'modal',
      isTransformResponse: false,
    },
  );
  return data.Data;
}
 
/*
 * 获取角色仓库列表,用于角色授权仓库列表
 */
export function getWhList(params: string) {
  const rmParams = genAction('SYS_ROLE_WH', " ROLE_CODE = '" + params + "'");
  return getRoleWh(rmParams);
}
async function getRoleWh(params: ApiAction<string>) {
  const data = await defHttp.post<ApiAction<iSYS_ROLE_WH[]>>(
    {
      url: Api.EntityList,
      params,
    },
    {
      errorMessageMode: 'modal',
      isTransformResponse: false,
    },
  );
  return data.Data;
}
 
/*
 * 获取所有角色列表
 */
export const getAllRoleList = (params?: RoleParams) =>
  defHttp.get<RoleListGetResultModel>(
    { url: Api.GetAllRoleList, params },
    {
      isTransformResponse: false,
    },
  );
export function getRoles() {
  const usParams = genAction('SYS_ROLE', '1=1');
  return getRoleListApi(usParams);
}
async function getRoleListApi(params: ApiAction<string>) {
  const data = await defHttp.post<ApiAction<RoleItem[]>>(
    {
      url: Api.EntityList,
      params,
    },
    {
      errorMessageMode: 'modal',
      isTransformResponse: false,
    },
  );
  return data.Data;
}
 
export function getTargetRole(params?: UserGPParams) {
  const sqlcmd =
    " select r.* from SYS_USERGROUP_ROLE t left join sys_usergroup g on t.usergroup_code = g.id left join SYS_ROLE r on r.id=t.role_code where g.usergroup_code = '" +
    params?.USERGROUP_CODE +
    "'";
  const usParams = genAction('SYS_ROLE', sqlcmd);
  return getTargetRoleListApi(usParams);
}
async function getTargetRoleListApi(params: ApiAction<string>) {
  const data = await defHttp.post<ApiAction<RoleItem[]>>(
    {
      url: Api.EntitySqlList,
      params,
    },
    {
      errorMessageMode: 'modal',
      isTransformResponse: false,
    },
  );
  return data.Data;
}
 
export const setRoleStatus = (params: RoleItem) =>
  defHttp.post(
    { url: Api.UpdateEntity, params: genAction('SYS_ROLE', params) },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
 
export const setBasStatus = (params: any) =>
  defHttp.post(
    { url: Api.UpdateEntity, params: genAction('BAS_ITEM', params) },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
 
export const SetRoleToGroup = async (params: SpecificEntity) => {
  return await defHttp.post(
    { url: Api.urlSetRoleToGroup, params: genAction('SYS_USERGROUP_ROLE', params) },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};
 
/*
 * 保存菜单
 */
export const SaveMenu = async (params: SaveMenuParams, isUpdate: boolean) => {
  params.isUpdate = isUpdate;
  const usParams = genAction('string', params);
  return await defHttp.post(
    { url: Api.SaveMenu, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};
 
/*
 * 删除菜单
 */
export const DeleteMenu = async (params: Recordable) => {
  const menuitem: FuncItem = {
    ID: params.id,
    FUNC_CODE: params.func_code,
    FUNC_NAME: params.menuName,
    FUNC_DESC: params.menuName,
    FUNC_GROUP: '',
    FUNC_TYPE: params.func_type,
    PFUNC_CODE: params.parentMenu,
    FUNC_CLASS: '',
    PATH: params.path,
    ICON_URL: params.icon,
    SEQ_NO: params.orderNo,
    IS_USE: params.status,
    COMPONENT: params.component,
  };
  const usParams = genAction('SYS_MENU', [menuitem]);
  return await defHttp.post(
    { url: Api.DeleteList, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};
 
/*
 * 保存角色
 */
export const SaveRole = async (params: SaveRoleParams, isUpdate: boolean) => {
  params.isUpdate = isUpdate;
  const usParams = genAction('string', params);
  return await defHttp.post(
    { url: Api.SaveRole, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};
 
/*
 * 删除角色
 */
export const DeleteRole = async (params: Recordable) => {
  const usParams = genAction('SYS_ROLE', [params]);
  return await defHttp.post(
    { url: Api.DeleteList, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};
 
/*
 * 获取登录日志分页列表
 */
export const getLoginLogListByPage = async (params: LoginLogPageParams) => {
  let sqlcmd = '';
  if (params?.LOGIN_FROM != undefined && params?.LOGIN_FROM != '') {
    sqlcmd += " And LOGIN_FROM like '%" + params?.LOGIN_FROM + "%'";
  }
  if (params?.LOGIN_TIME != undefined) {
    sqlcmd += ` And LOGIN_TIME >= '${DateFormat(
      params?.LOGIN_TIME[0],
      'yyyyMMddhhmmss',
    )}' And LOGIN_TIME < '${DateFormat(params?.LOGIN_TIME[1], 'yyyyMMddhhmmss')}'`;
  }
  const rParams = genActionPage('sys_loginlog', sqlcmd, params.page, params.pageSize);
  return getLoginLogListByPageAsync(rParams);
};
async function getLoginLogListByPageAsync(params: ApiActionPage) {
  const data = await defHttp.post<ApiActionPage>(
    { url: Api.EntityPageList, params },
    {
      isTransformResponse: false,
    },
  );
  const model: LoginLogPageListGetResultModel = {
    items: data.Data.data,
    total: data.Data.totals,
  };
  return model;
}
 
/*
 *通用方法========================================================
 */
 
export const GetEnum = async (enumName: { name: string }) => {
  const usParams = genAction(enumName.name, '');
  return await defHttp.post(
    { url: Api.urlQueryEnum, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
      //apiUrl: globSetting.taskApiUrl
    },
  );
};
 
/* 通用查询分页 */
export async function getListByPage<T>(params: T) {
  const Keys = Object.getOwnPropertyNames(params);
  let sqlcmd = '1=1 ';
  let order = '';
  for (const k in Keys) {
    console.log(`${k}:${Keys[k]}`);
    if (
      !isNullOrEmpty(params[Keys[k]]) &&
      Keys[k] != 'page' &&
      Keys[k] != 'pageSize' &&
      Keys[k] != 'TABLE_NAME' &&
      Keys[k] != 'order' &&
      Keys[k] != 'field' &&
      Keys[k] != '0'
    ) {
      if (!isNullOrEmpty(params[Keys[k]].length) && isTimeType(params[Keys[k]][0])) {
        sqlcmd += ` And ${Keys[k]} > '${params[Keys[k]][0]}'`;
        sqlcmd += ` And ${Keys[k]} < '${params[Keys[k]][1]}'`;
      } else {
        sqlcmd += `And ${Keys[k]} like '%${params[Keys[k]]}%'`;
      }
    }
  }
  if (!isNullOrEmpty(params['order'])) {
    order = params['order'] == 'descend' ? params['field'] + ' desc' : params['field'];
  }
  const rParams = genAction(params['TABLE_NAME'], {
    QueryAble_T: '',
    where: sqlcmd,
    order: order,
    page: {
      pageAble_T: 'string',
      draw: 1,
      pageIndex: params['page'],
      pageSize: params['pageSize'],
    },
  });
  return getListByPageAsync(rParams);
}
async function getListByPageAsync(params: any) {
  const data = await defHttp.post(
    { url: Api.QueryUrl, params },
    {
      isTransformResponse: false,
    },
  );
  const model = {
    items: data.Data.page.data,
    total: data.Data.page.totals,
  };
  return model;
}
 
export async function SaveEntity<T>(params: T, isUpdate: boolean, entityName: string) {
  let data;
  if (isUpdate) {
    data = await defHttp.post(
      { url: Api.UpdateEntity, params: genAction(entityName, params) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  } else {
    params.ID = buildUUID(); //生成GUID
    data = await defHttp.post(
      { url: Api.AddEntity, params: genAction(entityName, params) },
      {
        errorMessageMode: 'none',
        isTransformResponse: false,
      },
    );
  }
  return data;
}
 
export async function DeleteEntity<T>(params: T, entityName: string) {
  const usParams = genAction(entityName, [params]);
  return await defHttp.post(
    { url: Api.DeleteList, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
}
 
//获取服务器Json文件返回Json数据
export async function fetchJson(url: string) {
  try {
    const response = await fetch(url);
    return await response.json();
  } catch (error) {
    console.error('Error fetching columns:', error);
  }
}
 
// 泛型函数,获取类的名称
export function getClassName<T>(ctor: new () => T): string {
  return ctor.name;
}
 
export const getEntityList = (params?: EntityParams) =>
  defHttp.get<EntityList>(
    { url: Api.GetEntityNameList, params },
    {
      isTransformResponse: false,
      apiUrl: globSetting.sysApiUrl,
    },
  );
 
export async function getEntityNameList(params?: EntityParams) {
  const data = await defHttp.get<EntityList>(
    { url: Api.GetEntityNameList, params },
    {
      isTransformResponse: false,
      apiUrl: globSetting.sysApiUrl,
    },
  );
  const model = {
    items: data.Data,
    total: data.Total,
  };
  return model;
}
 
export async function getEntityPropertieList(params?: EntityParams) {
  const data = await defHttp.get<EntityList>(
    { url: Api.GetEntityNameList, params },
    {
      isTransformResponse: false,
      apiUrl: globSetting.sysApiUrl,
    },
  );
  const model = {
    items: data.Data.filter((x) => x.Name == params?.StartWith)[0].Properties,
    total: data.Total,
  };
  return model;
}
 
/* 通用获取实体记录 */
export const getEntity = async (params: { sqlcmd: string; entityName: string }) => {
  const usParams = genAction(params.entityName, {
    QueryAble_T: '',
    where: params.sqlcmd,
    order: '',
  });
  return await defHttp.post(
    { url: Api.QueryUrl, params: usParams },
    {
      errorMessageMode: 'none',
      isTransformResponse: false,
    },
  );
};