From e33d593df8bf528ad793bf80eb8f391513ccc2ba Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期四, 30 五月 2024 21:01:05 +0800 Subject: [PATCH] 通用增删改 --- src/api/tigerapi/system.ts | 167 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 140 insertions(+), 27 deletions(-) diff --git a/src/api/tigerapi/system.ts b/src/api/tigerapi/system.ts index 579e8b0..3d0f4d5 100644 --- a/src/api/tigerapi/system.ts +++ b/src/api/tigerapi/system.ts @@ -1,7 +1,7 @@ import { UserConfigFn } from 'vite'; import { buildUUID } from '../../utils/uuid'; import { DateFormat } from '../../utils/dataformat'; -import { ApiAction,ApiActionJob, ApiActionPage } from '../model/baseModel'; +import { ApiAction, ApiActionJob, ApiActionPage } from '../model/baseModel'; import { MenuParams, RoleParams, @@ -27,7 +27,7 @@ iSYS_ROLE_WH, } from './model/systemModel'; import { defHttp } from '/@/utils/http/axios'; -import { isUnDef } from '/@/utils/is'; +import { isNullOrEmpty } from '/@/utils/is'; export enum Api { QueryUrl = '/Base/Query', @@ -49,7 +49,7 @@ GetOrgTreeList = '/SYS/getOrgTreeList', GetHouseTreeList = '/WMS/GetHouseModel', GetHouseOrgTreeList = '/WMS/GetHouseModelOrg', - GetCreateBillCode = '/WMS/CreateBillCode', + GetCreateBillCode = '/WMS/CreateBillCode', GetCreateTFBillCode = '/WMS/CreateTFBillCode', GetAllRoleList = '/system/getAllRoleList', urlSetSysUserToGroup = '/SYS/SetSysUserToGroup', @@ -57,22 +57,25 @@ 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', + 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' + GetUpdateTime = '/MaterialInfo/UpdateTime', + //瀵煎叆 + ValidateTableImport = '/SMT/ValidateTableImport', + SaveValidateTableImport = '/SMT/SaveValidateTableImport', } /** @@ -83,12 +86,18 @@ * @param pageSize * @returns */ -export function genActionPage(datatype: string, sqlcmd: string, page: number, pageSize: number,option?:object) { +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, + Options: option, isAsync: true, timestamp: time.toDateString(), isSuccessed: true, @@ -113,12 +122,12 @@ /* * 鐢熸垚Action */ -export function genAction<T>(datatype: string, data: T,option?:object) { +export function genAction<T>(datatype: string, data: T, option?: object) { const time = new Date(); const params: ApiAction<T> = { ID: buildUUID(), - DataAssembly:'', - Options:option, + DataAssembly: '', + Options: option, DataType: datatype, IsAsync: true, Timestamp: time.toDateString(), @@ -126,14 +135,21 @@ Message: '', StatusCode: 0, Data: data, + LocaleMsg: undefined, }; return params; } -export function genActionjob<sting>(datatype: string, assembly: string, data: string,timeone:number,remark:string) { +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, + DataAssembly: assembly, DataType: datatype, IsAsync: true, Timestamp: time.toDateString(), @@ -141,9 +157,9 @@ Message: '', StatusCode: 0, Data: { - jobName:data, - period:timeone, - remark: remark + jobName: data, + period: timeone, + remark: remark, }, }; return params; @@ -491,7 +507,7 @@ }, ); - export const setBasStatus = (params: any) => +export const setBasStatus = (params: any) => defHttp.post( { url: Api.UpdateEntity, params: genAction('BAS_ITEM', params) }, { @@ -613,3 +629,100 @@ }; 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 = ''; + 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' + ) { + sqlcmd += `And ${Keys[k]} like '%${params[Keys[k]]}%'`; + } + } + const rParams = genActionPage(params['TABLE_NAME'], sqlcmd, params['page'], params['pageSize']); + return getListByPageAsync(rParams); +} +async function getListByPageAsync(params: ApiActionPage) { + const data = await defHttp.post<ApiActionPage>( + { url: Api.EntityPageList, params }, + { + isTransformResponse: false, + }, + ); + const model = { + items: data.Data.data, + total: data.Data.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, + }, + ); +} + +//鑾峰彇鏈嶅姟鍣↗son鏂囦欢杩斿洖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; +} -- Gitblit v1.9.3