From 92cb62d60d38be56312be20cfae8638a5a9aa57a Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期日, 27 十月 2024 11:15:09 +0800
Subject: [PATCH] 计划任务优化

---
 src/api/tigerapi/system.ts |  105 +++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 82 insertions(+), 23 deletions(-)

diff --git a/src/api/tigerapi/system.ts b/src/api/tigerapi/system.ts
index 0d53fb4..3dababe 100644
--- a/src/api/tigerapi/system.ts
+++ b/src/api/tigerapi/system.ts
@@ -28,9 +28,12 @@
   EntityParams,
   EntityList,
   iSYS_ROLE_PROD,
+  pParams,
 } from './model/systemModel';
 import { defHttp } from '/@/utils/http/axios';
-import { isArray, isNullOrEmpty, isTimeViaRegExp8601 } from '/@/utils/is';
+import { isArray, isNullOrEmpty, isNullOrUnDef, isTimeViaRegExp8601 } from '/@/utils/is';
+import { isNumber } from 'xe-utils';
+import { dateUtil, formatToDateTime } from '/@/utils/dateUtil';
 
 export enum Api {
   QueryUrl = '/Base/Query',
@@ -43,6 +46,7 @@
   MenuList = '/SYS/getMenuListAll',
   SaveMenu = '/SYS/SaveMenu',
   SaveRole = '/SYS/SaveRole',
+  getSysParam = '/SYS/getSysParam',
   AddEntity = '/Base/Add',
   AddListEntity = '/Base/AddList',
   UpdateEntity = '/Base/Update',
@@ -63,6 +67,7 @@
   StopJob = '/Tsk/PauseJob',
   AddJob = '/Tsk/AddJob',
   UpdateJob = '/Tsk/UpdateJob',
+  SaveTskJob = '/Tsk/SaveTskJob',
   urlQueryEnum = '/Base/QueryEnum',
   DeleteWareHouse = '/WMS/DelWareHouseModel',
   AddLocation = '/WMS/AddLoctionModel',
@@ -130,7 +135,7 @@
 /*
  * 鐢熸垚Action
  */
-export function genAction<T>(datatype: string, data: T, option?: object) {
+export function genAction<T>(datatype: string, data: T, option?: object, NeedInclude?: boolean) {
   const time = new Date();
   const params: ApiAction<T> = {
     ID: buildUUID(),
@@ -144,6 +149,7 @@
     StatusCode: 0,
     Data: data,
     LocaleMsg: undefined,
+    NeedInclude: isNullOrEmpty(NeedInclude) ? false : NeedInclude,
   };
   return params;
 }
@@ -285,7 +291,7 @@
  * @param {T} data
  * @param {string} parentField 鐖跺瓧娈靛悕
  * @param {string} idField 鍞竴key瀛楁鍚�
- * @param {string} pid_val 鐖秈d鍊�
+ * @param {string} pid 鐖秈d鍊�
  * @return {*}
  */
 export function convertToTree<T>(data: T[], parentField: string, idField: string, pid?: string) {
@@ -304,6 +310,30 @@
     }
   }
   return result;
+}
+
+/**
+ * @description: 鑾峰彇鐖堕」
+ * @param {any} nodes
+ * @param {string} childId
+ * @return {*}
+ */
+export function findParent(tree: any[], nodeId: string): any | undefined {
+  for (const node of tree) {
+    if (node.children) {
+      for (const child of node.children) {
+        if (child.tid === nodeId) {
+          return node;
+        }
+        // 閫掑綊鏌ユ壘瀛愭爲
+        const potentialParent = findParent(node.children, nodeId);
+        if (potentialParent) {
+          return potentialParent;
+        }
+      }
+    }
+  }
+  return undefined; // 娌℃湁鎵惧埌瀵瑰簲鐨勭埗浜茶妭鐐�
 }
 
 /*
@@ -709,22 +739,29 @@
   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);
+  const rParams = genAction(
+    params['TABLE_NAME'],
+    !isNullOrEmpty(params['apiUrl'])
+      ? params
+      : {
+          QueryAble_T: '',
+          where: sqlcmd,
+          order: order,
+          page: {
+            pageAble_T: 'string',
+            draw: 1,
+            pageIndex: params['page'],
+            pageSize: params['pageSize'],
+          },
+        },
+    params['option'],
+    params['NeedInclude'],
+  );
+  return getListByPageAsync(rParams, params['apiUrl']); //濡傛灉涓嶆兂鐢ㄩ粯璁ょ殑鍩虹鏂规硶鑾峰彇鍒嗛〉鏁版嵁锛屽彲浠ユ崲鍏朵粬鐨刟pi
 }
-async function getListByPageAsync(params: any) {
+async function getListByPageAsync(params: any, apiUrl: string | null | undefined) {
   const data = await defHttp.post(
-    { url: Api.QueryUrl, params, timeout: 50000 },
+    { url: !isNullOrEmpty(apiUrl) ? apiUrl : Api.QueryUrl, params, timeout: 50000 },
     {
       isTransformResponse: false,
     },
@@ -753,12 +790,21 @@
       Keys[k] != 'TABLE_NAME' &&
       Keys[k] != 'order' &&
       Keys[k] != 'field' &&
+      Keys[k] != 'option' &&
       Keys[k] != '0' &&
+      Keys[k] != 'apiUrl' &&
+      Keys[k] != 'NeedInclude' &&
       !Keys[k].toString().endsWith('PSelect_0')
     ) {
-      if (!isNullOrEmpty(params[Keys[k]].length) && isTimeViaRegExp8601(params[Keys[k]][0])) {
-        sqlcmd += ` And ${Keys[k]} > '${params[Keys[k]][0]}'`;
-        sqlcmd += ` And ${Keys[k]} < '${params[Keys[k]][1]}'`;
+      if (!isNullOrEmpty(params[Keys[k]].length) && isArray(params[Keys[k]])) {
+        if (isTimeViaRegExp8601(params[Keys[k]][0])) {
+          sqlcmd += ` And ${Keys[k]} > '${params[Keys[k]][0]}'`;
+          sqlcmd += ` And ${Keys[k]} < '${params[Keys[k]][1]}'`;
+        } else {
+          sqlcmd += `And '${params[Keys[k]].join(',')}' like '%'+${Keys[k]}+'%'`;
+        }
+      } else if (isNumber(params[Keys[k]])) {
+        sqlcmd += `And ${Keys[k]} = ${params[Keys[k]]}`;
       } else {
         sqlcmd += `And ${Keys[k]} like '%${params[Keys[k]]}%'`;
       }
@@ -784,7 +830,7 @@
       check.Message = '璁板綍宸茬粡瀛樺湪锛屼笉鑳芥柊澧烇紒';
       return check;
     }
-    params.ID = buildUUID(); //鐢熸垚GUID
+    params['ID'] = args[1] == true ? params['ID'] : buildUUID(); //鐢熸垚GUID
     data = await defHttp.post(
       { url: Api.AddEntity, params: genAction(entityName, params) },
       {
@@ -919,11 +965,11 @@
 }
 
 /* 閫氱敤鑾峰彇瀹炰綋璁板綍 */
-export const getEntity = async (params: { sqlcmd: string; entityName: string }) => {
+export const getEntity = async (params: { sqlcmd: string; entityName: string; order: string }) => {
   const usParams = genAction(params.entityName, {
     QueryAble_T: '',
     where: params.sqlcmd,
-    order: '',
+    order: params.order,
   });
   return await defHttp.post(
     { url: Api.QueryUrl, params: usParams },
@@ -948,3 +994,16 @@
   }
   return values;
 }
+
+/**
+ * @description: 鑾峰彇鍙傛暟
+ * @param {pParams} params
+ * @return {*}
+ */
+export const getSysParam = (params?: pParams) =>
+  defHttp.get<ApiAction<treeParamsListItem[]>>(
+    { url: Api.getSysParam, params },
+    {
+      isTransformResponse: false,
+    },
+  );

--
Gitblit v1.9.3