diff --git a/app/service/systemMethods/index.js b/app/service/systemMethods/index.js index de7eb76..4d4a4e5 100644 --- a/app/service/systemMethods/index.js +++ b/app/service/systemMethods/index.js @@ -1053,9 +1053,9 @@ class indexService extends MainService { constructor(ctx) { super(ctx); const _noNeedLogin = 'getI18nMessage,putI18nCollect,test,getCainiaoStfTemplates,polyapiAuthorizeUrl'; - const _noNeedRight = 'loginToIm,getI18nMessage,putI18nCollect,fastWhereTree,loadStores,loadWarehouses,loadExpressInterfaces,getImages,getCOSUploadConfig,uploadSuccessNotify,getMessageDetail,searchSpace,listInterfaceTypes,getLocationTypeList,getQimenAppList,getExpressList,getExpressProductTypeList,getPlatformList,getPrintPlatformList,getPlatformOauthLink,listenPlatformOauthBind,recognizeLicensePlate,getCainiaoStfTemplates,getPrintPlatformTemplateList,polyapiAuthorizeUrl,toOrder'; + const _noNeedRight = 'loginToIm,getI18nMessage,putI18nCollect,fastWhereTree,loadStores,loadWarehouses,loadExpressInterfaces,getImages,getCOSUploadConfig,uploadSuccessNotify,getMessageDetail,searchSpace,searchSpaces,listInterfaceTypes,getLocationTypeList,getQimenAppList,getExpressList,getExpressProductTypeList,getPlatformList,getPrintPlatformList,getPlatformOauthLink,listenPlatformOauthBind,recognizeLicensePlate,getCainiaoStfTemplates,getPrintPlatformTemplateList,polyapiAuthorizeUrl,toOrder'; const _noNeedLog = '*'; - const _noNeedAuth = 'loginToIm,getI18nMessage,putI18nCollect,fastWhereTree,loadStores,loadWarehouses,loadExpressInterfaces,getImages,getMessageDetail,searchSpace,listInterfaceTypes,getLocationTypeList,getQimenAppList,getExpressList,getExpressProductTypeList,getPlatformList,getPrintPlatformList,getPlatformOauthLink,listenPlatformOauthBind,recognizeLicensePlate,test,getCainiaoStfTemplates,getPrintPlatformTemplateList,polyapiAuthorizeUrl,toOrder'; + const _noNeedAuth = 'loginToIm,getI18nMessage,putI18nCollect,fastWhereTree,loadStores,loadWarehouses,loadExpressInterfaces,getImages,getMessageDetail,searchSpace,searchSpaces,listInterfaceTypes,getLocationTypeList,getQimenAppList,getExpressList,getExpressProductTypeList,getPlatformList,getPrintPlatformList,getPlatformOauthLink,listenPlatformOauthBind,recognizeLicensePlate,test,getCainiaoStfTemplates,getPrintPlatformTemplateList,polyapiAuthorizeUrl,toOrder'; this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth); } async fastWhereTree(data) { @@ -1578,6 +1578,11 @@ class indexService extends MainService { const result = await service.systems.space.searchSpace(data); return this.success('ok', result); } + async searchSpaces(data) { + const { service } = this; + const result = await service.systems.space.searchSpaces(data); + return this.success('ok', result); + } async listInterfaceTypes() { const { ctx } = this; const rows = await ctx.model.InterfaceType.findAll({ diff --git a/app/service/systems/space.js b/app/service/systems/space.js index 019a915..86d492e 100644 --- a/app/service/systems/space.js +++ b/app/service/systems/space.js @@ -2,9 +2,14 @@ const Service = require('egg').Service; class spaceService extends Service { - async searchSpace(data) { + /** + * 按关键字查询库位(单个关键字)。 + * + * @param {string} [keyword] 搜索关键字,为空时返回当前仓库下前 50 条。 + * @return {Promise} 库位列表(最多 50 条)。 + */ + async _searchByKeyword(keyword) { const { ctx, app } = this; - const { keyword } = data; const warehouseId = ctx.user.store_id; // 构建基础查询条件:warehouse_id 为当前仓库或 null @@ -46,7 +51,7 @@ class spaceService extends Service { }; } - const results = await app.model.LocationSpace.findAll({ + return app.model.LocationSpace.findAll({ where: whereCondition, attributes: [ 'id', 'space_code', 'custom_barcode', 'custom_name', @@ -55,8 +60,31 @@ class spaceService extends Service { limit: 50, subQuery: false, }); + } + + async searchSpace(data) { + const { keyword } = data; + const results = await this._searchByKeyword(keyword); return { code: 200, data: results, total: results.length }; } + + /** + * 批量按关键字查询库位。 + * + * @param {Object} data 请求数据。 + * @param {Array} data.keywords 搜索关键字数组。 + * @return {Promise} data 为与 keywords 一一对应的库位列表数组, + * 无记录时对应项为空数组 []。 + */ + async searchSpaces(data) { + const { keywords } = data; + const keywordList = Array.isArray(keywords) ? keywords : []; + const resultList = await Promise.all( + keywordList.map(keyword => this._searchByKeyword(keyword)) + ); + + return { code: 200, data: resultList, total: resultList.length }; + } } module.exports = spaceService;