#1705 item.index optimizar velocidad
This commit is contained in:
parent
c6e8498281
commit
da2c763573
|
@ -62,13 +62,26 @@ module.exports = Self => {
|
|||
|
||||
Self.filter = async(ctx, filter) => {
|
||||
let conn = Self.dataSource.connector;
|
||||
let codeWhere;
|
||||
|
||||
if (ctx.args.search) {
|
||||
let items = await Self.app.models.ItemBarcode.find({
|
||||
where: {code: ctx.args.search},
|
||||
fields: ['itemFk']
|
||||
});
|
||||
let itemIds = [];
|
||||
for (const item of items)
|
||||
itemIds.push(item.itemFk);
|
||||
|
||||
codeWhere = {'i.id': {inq: itemIds}};
|
||||
}
|
||||
|
||||
let where = buildFilter(ctx.args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
return /^\d+$/.test(value)
|
||||
? {or: [{'i.id': value}, {'ib.code': value}]}
|
||||
: {or: [{'i.name': {like: `%${value}%`}}, {'ib.code': value}]};
|
||||
? {or: [{'i.id': value}, codeWhere]}
|
||||
: {or: [{'i.name': {like: `%${value}%`}}, codeWhere]};
|
||||
case 'id':
|
||||
return {'i.id': value};
|
||||
case 'description':
|
||||
|
@ -83,8 +96,8 @@ module.exports = Self => {
|
|||
return {'i.isActive': value};
|
||||
}
|
||||
});
|
||||
|
||||
filter = mergeFilters(filter, {where});
|
||||
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
|
||||
|
@ -123,8 +136,7 @@ module.exports = Self => {
|
|||
LEFT JOIN origin ori ON ori.id = i.originFk
|
||||
LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = t.warehouseFk
|
||||
LEFT JOIN vn.buy b ON b.id = lb.buy_id
|
||||
LEFT JOIN itemPlacement itn ON itn.itemFk = i.id AND itn.warehouseFk = t.warehouseFk
|
||||
LEFT JOIN itemBarcode ib ON ib.itemFk = i.id`
|
||||
LEFT JOIN itemPlacement itn ON itn.itemFk = i.id AND itn.warehouseFk = t.warehouseFk`
|
||||
);
|
||||
|
||||
if (ctx.args.tags) {
|
||||
|
@ -150,7 +162,6 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
stmt.merge(conn.makeWhere(filter.where));
|
||||
stmt.merge(`GROUP BY i.id`);
|
||||
stmt.merge(conn.makePagination(filter));
|
||||
|
||||
let itemsIndex = stmts.push(stmt) - 1;
|
||||
|
|
Loading…
Reference in New Issue