|
@@ -0,0 +1,47 @@
|
|
|
+/**
|
|
|
+ * Created by zhang on 2020/7/20
|
|
|
+ */
|
|
|
+module.exports={
|
|
|
+ getOptions,
|
|
|
+ getDataByCondition
|
|
|
+};
|
|
|
+
|
|
|
+const mongoose = require('mongoose');
|
|
|
+let infoLibModel = mongoose.model("std_price_info_lib");
|
|
|
+let infoItemsModel = mongoose.model("std_price_info_items");
|
|
|
+let _ = require("lodash");
|
|
|
+async function getOptions(data,compilation){//data 是预留对象,暂时不用
|
|
|
+ let compilationID = compilation._id;
|
|
|
+ let areaMap={};
|
|
|
+ let areas= [];
|
|
|
+ let periodMap={};
|
|
|
+ let libList = await infoLibModel.find({"compilationID":compilationID}).lean();
|
|
|
+ for(let l of libList){
|
|
|
+ for(let area of l.areas){
|
|
|
+ if(!areaMap[area]) areas.push(area);
|
|
|
+ }
|
|
|
+ //2020-05
|
|
|
+ let periodArray = l.period.split("-");
|
|
|
+ periodMap[periodArray[0]]?periodMap[periodArray[0]].push(periodArray[1]):periodMap[periodArray[0]]=[periodArray[1]]
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for(let key in periodMap){
|
|
|
+ periodMap[key] = _.sortBy(periodMap[key]);
|
|
|
+ }
|
|
|
+ return {areas:areas,periodMap:periodMap}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+async function getDataByCondition(data,compilation){
|
|
|
+ let result = {};
|
|
|
+ data.condition["compilationID"] = compilation._id;
|
|
|
+ if(data.keyWord) data.condition.name = {"$regex":new RegExp(data.keyWord, "i")};
|
|
|
+ if(data.lastID){ //有最后一行说明是查询下一页
|
|
|
+ data.condition["_id"] = {$gt:mongoose.Types.ObjectId(data.lastID)};
|
|
|
+ }else{
|
|
|
+ result.totalSize = await infoItemsModel.find(data.condition).count();
|
|
|
+ }
|
|
|
+ result.items = await infoItemsModel.find(data.condition).lean().sort({"_id":1}).limit(50);
|
|
|
+ return result;
|
|
|
+}
|