feat(space): 批量库位搜索 searchSpaces
- space.js 抽取 _searchByKeyword, searchSpace 与 searchSpaces 共用同一查询口径 - searchSpaces 按 keywords 并行查询并保持传入顺序, 无记录项返回空数组 - index.searchSpaces 加入免权限/免鉴权白名单
This commit is contained in:
parent
7f562bf1e7
commit
fe97adfda2
@ -1053,9 +1053,9 @@ class indexService extends MainService {
|
|||||||
constructor(ctx) {
|
constructor(ctx) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
const _noNeedLogin = 'getI18nMessage,putI18nCollect,test,getCainiaoStfTemplates,polyapiAuthorizeUrl';
|
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 _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);
|
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||||||
}
|
}
|
||||||
async fastWhereTree(data) {
|
async fastWhereTree(data) {
|
||||||
@ -1578,6 +1578,11 @@ class indexService extends MainService {
|
|||||||
const result = await service.systems.space.searchSpace(data);
|
const result = await service.systems.space.searchSpace(data);
|
||||||
return this.success('ok', result);
|
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() {
|
async listInterfaceTypes() {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
const rows = await ctx.model.InterfaceType.findAll({
|
const rows = await ctx.model.InterfaceType.findAll({
|
||||||
|
|||||||
@ -2,9 +2,14 @@
|
|||||||
const Service = require('egg').Service;
|
const Service = require('egg').Service;
|
||||||
|
|
||||||
class spaceService extends Service {
|
class spaceService extends Service {
|
||||||
async searchSpace(data) {
|
/**
|
||||||
|
* 按关键字查询库位(单个关键字)。
|
||||||
|
*
|
||||||
|
* @param {string} [keyword] 搜索关键字,为空时返回当前仓库下前 50 条。
|
||||||
|
* @return {Promise<Array>} 库位列表(最多 50 条)。
|
||||||
|
*/
|
||||||
|
async _searchByKeyword(keyword) {
|
||||||
const { ctx, app } = this;
|
const { ctx, app } = this;
|
||||||
const { keyword } = data;
|
|
||||||
const warehouseId = ctx.user.store_id;
|
const warehouseId = ctx.user.store_id;
|
||||||
|
|
||||||
// 构建基础查询条件:warehouse_id 为当前仓库或 null
|
// 构建基础查询条件: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,
|
where: whereCondition,
|
||||||
attributes: [
|
attributes: [
|
||||||
'id', 'space_code', 'custom_barcode', 'custom_name',
|
'id', 'space_code', 'custom_barcode', 'custom_name',
|
||||||
@ -55,8 +60,31 @@ class spaceService extends Service {
|
|||||||
limit: 50,
|
limit: 50,
|
||||||
subQuery: false,
|
subQuery: false,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async searchSpace(data) {
|
||||||
|
const { keyword } = data;
|
||||||
|
const results = await this._searchByKeyword(keyword);
|
||||||
|
|
||||||
return { code: 200, data: results, total: results.length };
|
return { code: 200, data: results, total: results.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量按关键字查询库位。
|
||||||
|
*
|
||||||
|
* @param {Object} data 请求数据。
|
||||||
|
* @param {Array<string>} data.keywords 搜索关键字数组。
|
||||||
|
* @return {Promise<Object>} 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;
|
module.exports = spaceService;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user