|
|
@@ -15,27 +15,30 @@ class SearchDao{
|
|
|
async getRationItem(userId, compilationId, rationRepIds, code, ID, callback){
|
|
|
let ration = null;
|
|
|
try{
|
|
|
+ let firstLib = rationRepIds.shift();//优先取第一个
|
|
|
+ if(rationRepIds.includes(firstLib)) {//去掉重复的库ID
|
|
|
+ rationRepIds.splice(rationRepIds.indexOf(firstLib), 1);
|
|
|
+ }
|
|
|
if(rationRepIds.includes(compleRationLib)) {
|
|
|
rationRepIds.splice(rationRepIds.indexOf(compleRationLib), 1);
|
|
|
}
|
|
|
- let stdQuery = {rationRepId: {$in: rationRepIds}, code: code, $or: [{isDeleted: null}, {isDeleted: false}]};
|
|
|
- if(ID){
|
|
|
- stdQuery = {ID: ID, $or: [{isDeleted: null}, {isDeleted: false}]};
|
|
|
- }
|
|
|
- let stdRation = await stdRationModel.findOne(stdQuery);
|
|
|
- if(isDef(stdRation)){
|
|
|
- ration = stdRation._doc;
|
|
|
- ration.type = 'std';
|
|
|
- } else{
|
|
|
- let compleQuery = {userId: userId, compilationId: compilationId, code: code, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]};
|
|
|
+ if(firstLib == compleRationLib){//说明选中的是补充定额库
|
|
|
+ ration = await this.getCompleRation(userId,compilationId,code,ID);
|
|
|
+ }else {
|
|
|
+ firstLib = parseInt(firstLib);
|
|
|
+ let firstQuery = {rationRepId: firstLib, code: code, $or: [{isDeleted: null}, {isDeleted: false}]};
|
|
|
if(ID){
|
|
|
- compleQuery.ID = ID;
|
|
|
+ firstQuery = {ID: ID, $or: [{isDeleted: null}, {isDeleted: false}]};
|
|
|
}
|
|
|
- let compleRation = await compleRationModel.findOne(compleQuery);
|
|
|
- if(isDef(compleRation)){
|
|
|
- ration = compleRation._doc;
|
|
|
- ration.type = 'complementary';
|
|
|
+ ration = await this.getStdRation(firstQuery);
|
|
|
+ }
|
|
|
+ if(ration == null){//选中的定额库或者默认的定额库中没有找到定额,才走常规的流程查找其它定额库
|
|
|
+ let stdQuery = {rationRepId: {$in: rationRepIds}, code: code, $or: [{isDeleted: null}, {isDeleted: false}]};
|
|
|
+ if(ID){
|
|
|
+ stdQuery = {ID: ID, $or: [{isDeleted: null}, {isDeleted: false}]};
|
|
|
}
|
|
|
+ ration = await this.getStdRation(stdQuery);
|
|
|
+ if(ration == null) ration = await this.getCompleRation(userId,compilationId,code,ID);
|
|
|
}
|
|
|
if(isDef(ration)){
|
|
|
if (ration.type === 'std') {
|
|
|
@@ -61,7 +64,28 @@ class SearchDao{
|
|
|
}
|
|
|
return ration;
|
|
|
}
|
|
|
-
|
|
|
+ async getCompleRation(userId,compilationId,code,ID){
|
|
|
+ let ration = null;
|
|
|
+ let compleQuery = {userId: userId, compilationId: compilationId, code: code, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}]};
|
|
|
+ if(ID){
|
|
|
+ compleQuery.ID = ID;
|
|
|
+ }
|
|
|
+ let compleRation = await compleRationModel.findOne(compleQuery);
|
|
|
+ if(isDef(compleRation)){
|
|
|
+ ration = compleRation._doc;
|
|
|
+ ration.type = 'complementary';
|
|
|
+ }
|
|
|
+ return ration
|
|
|
+ }
|
|
|
+ async getStdRation(query){
|
|
|
+ let ration = null;
|
|
|
+ let stdRation = await stdRationModel.findOne(query);
|
|
|
+ if(isDef(stdRation)){
|
|
|
+ ration = stdRation._doc;
|
|
|
+ ration.type = 'std';
|
|
|
+ }
|
|
|
+ return ration;
|
|
|
+ }
|
|
|
//@param {Object}skip({std: Number, comple: Number})
|
|
|
async findRation(userId, compilationId, rationRepId, keyword, skip, callback){
|
|
|
//每次限制结果数
|