| | |
| | | EntityList, |
| | | iSYS_ROLE_PROD, |
| | | pParams, |
| | | ImportEntityValidate, |
| | | ImportInput, |
| | | } from './model/systemModel'; |
| | | import { defHttp } from '/@/utils/http/axios'; |
| | | import { isArray, isNullOrEmpty, isNullOrUnDef, isTimeViaRegExp8601 } from '/@/utils/is'; |
| | | import { isArray, isNullOrEmpty, isTimeViaRegExp8601 } from '/@/utils/is'; |
| | | import { isNumber } from 'xe-utils'; |
| | | import { dateUtil, formatToDateTime } from '/@/utils/dateUtil'; |
| | | |
| | | export enum Api { |
| | | QueryUrl = '/Base/Query', |
| | |
| | | EntityPageList = '/Base/QueryCustomPage', |
| | | IsAccountExist = '/Base/IsExist', |
| | | AddAfterDelete = '/Base/AddAfterDelete', |
| | | ImportExcel = '/Base/ImportExcel', |
| | | BaseValidateTableImport = '/Base/ValidateTableImport', |
| | | setRoleStatus = '/system/setRoleStatus', |
| | | MenuList = '/SYS/getMenuListAll', |
| | | SaveMenu = '/SYS/SaveMenu', |
| | |
| | | StartJob = '/Tsk/StartJob', |
| | | StopJob = '/Tsk/PauseJob', |
| | | AddJob = '/Tsk/AddJob', |
| | | AddTskJob = '/Tsk/AddTskJob', |
| | | ImmediateRun = '/Tsk/ImmediateRun', |
| | | RemoveTskJob = '/Tsk/RemoveTskJob', |
| | | UpdateJob = '/Tsk/UpdateJob', |
| | | SaveTskJob = '/Tsk/SaveTskJob', |
| | | urlQueryEnum = '/Base/QueryEnum', |
| | | DeleteWareHouse = '/WMS/DelWareHouseModel', |
| | | AddLocation = '/WMS/AddLoctionModel', |
| | |
| | | /* |
| | | * 生成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(), |
| | |
| | | StatusCode: 0, |
| | | Data: data, |
| | | LocaleMsg: undefined, |
| | | NeedInclude: isNullOrEmpty(NeedInclude) ? false : NeedInclude, |
| | | }; |
| | | return params; |
| | | } |
| | | |
| | | /** |
| | | * @desc 生成Action |
| | | */ |
| | | export function generateAction<T>( |
| | | datatype: string, |
| | | DataAssembly: string, |
| | | data: T, |
| | | option?: object, |
| | | NeedInclude?: boolean, |
| | | ) { |
| | | const params = genAction(datatype, data, option, NeedInclude); |
| | | params.DataAssembly = DataAssembly; |
| | | return params; |
| | | } |
| | | export function genActionjob<sting>( |
| | |
| | | * @param {T} data |
| | | * @param {string} parentField 父字段名 |
| | | * @param {string} idField 唯一key字段名 |
| | | * @param {string} pid_val 父id值 |
| | | * @param {string} pid 父id值 |
| | | * @return {*} |
| | | */ |
| | | export function convertToTree<T>(data: T[], parentField: string, idField: string, pid?: string) { |
| | |
| | | } |
| | | } |
| | | 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; // 没有找到对应的父亲节点 |
| | | } |
| | | |
| | | /* |
| | |
| | | } |
| | | const rParams = genAction( |
| | | params['TABLE_NAME'], |
| | | { |
| | | QueryAble_T: '', |
| | | where: sqlcmd, |
| | | order: order, |
| | | page: { |
| | | pageAble_T: 'string', |
| | | draw: 1, |
| | | pageIndex: params['page'], |
| | | pageSize: params['pageSize'], |
| | | }, |
| | | }, |
| | | !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); |
| | | return getListByPageAsync(rParams, params['apiUrl']); //如果不想用默认的基础方法获取分页数据,可以换其他的api |
| | | } |
| | | 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, |
| | | }, |
| | |
| | | Keys[k] != 'field' && |
| | | Keys[k] != 'option' && |
| | | Keys[k] != '0' && |
| | | Keys[k] != 'apiUrl' && |
| | | Keys[k] != 'NeedInclude' && |
| | | Keys[k] != 'nolike' && |
| | | !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 if(Keys[k].toString().startsWith('IFEMPTY_')){ |
| | | sqlcmd +=params[Keys[k]]=='Y'? `And (${Keys[k].split('IFEMPTY_')[1]} != '' OR ${Keys[k].split('IFEMPTY_')[1]} is not NULL)`: `And (${Keys[k].split('IFEMPTY_')[1]} = '' OR ${Keys[k].split('IFEMPTY_')[1]} is NULL)`; |
| | | } else { |
| | | sqlcmd += `And ${Keys[k]} like '%${params[Keys[k]]}%'`; |
| | | sqlcmd += |
| | | params['nolike'] == 'Y' |
| | | ? `And ${Keys[k]} = '${params[Keys[k]]}'` |
| | | : `And ${Keys[k]} like '%${params[Keys[k]]}%'`; |
| | | } |
| | | } |
| | | } |
| | |
| | | }, |
| | | ); |
| | | } else { |
| | | var check = await isExist(genAction(entityName, args[0])); |
| | | const check = await isExist(genAction(entityName, args[0])); |
| | | if (check.Data) { |
| | | check.IsSuccessed = false; |
| | | check.Message = '记录已经存在,不能新增!'; |
| | |
| | | } |
| | | |
| | | export async function AddListEntity<T>(params: T, entityName: string) { |
| | | let data = await defHttp.post( |
| | | const data = await defHttp.post( |
| | | { url: Api.AddListEntity, params: genAction(entityName, params) }, |
| | | { |
| | | errorMessageMode: 'none', |
| | |
| | | * @return {*} |
| | | */ |
| | | export async function AddAfterDelete(entityName: string, items: [], where: string) { |
| | | let data = await defHttp.post( |
| | | const data = await defHttp.post( |
| | | { |
| | | url: Api.AddAfterDelete, |
| | | params: genAction(entityName, { |
| | |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | |
| | | /** |
| | | * @desc 导入Excel |
| | | */ |
| | | export async function ImportExcel(entityName: string, items: ImportInput) { |
| | | const data = await defHttp.post( |
| | | { |
| | | url: Api.ImportExcel, |
| | | params: genAction(entityName, items), |
| | | }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | return data; |
| | | } |
| | | |
| | | /** |
| | | * @desc 导入Excel |
| | | */ |
| | | export async function ValidateTableImport(entityName: string, items: ImportEntityValidate) { |
| | | const data = await defHttp.post( |
| | | { |
| | | url: Api.BaseValidateTableImport, |
| | | params: genAction(entityName, items), |
| | | }, |
| | | { |
| | | errorMessageMode: 'none', |
| | | isTransformResponse: false, |
| | | }, |
| | | ); |
| | | return data; |
| | | } |