瀏覽代碼

修改版本管理相关操作

caiaolin 7 年之前
父節點
當前提交
047f0a9367

+ 33 - 0
modules/common/std/schemas/std_bills_lib_lists.js

@@ -0,0 +1,33 @@
+/**
+ * 标准清单库数据模型
+ *
+ * @author CaiAoLin
+ * @date 2017/8/3
+ * @version
+ */
+import mongoose from "mongoose";
+
+let Schema = mongoose.Schema;
+let collectionName = 'std_bills_lib_lists';
+let modelSchema = {
+    // 自增id
+    billsLibId: String,
+    // 添加信息的管理员
+    creator: String,
+    // 创建时间
+    createDate: String,
+    // 名称
+    billsLibName: String,
+    // 地区/省份字段
+    localeType: {
+        type: Number,
+        index: true
+    },
+    // 是否被删除
+    deleted: Boolean,
+    // 最近操作记录
+    recentOpr: Schema.Types.Mixed
+};
+
+let model = mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));
+export {model as default, collectionName as collectionName};

+ 53 - 0
modules/common/std/std_bills_lib_lists_model.js

@@ -0,0 +1,53 @@
+/**
+ * 标准清单库
+ *
+ * @author CaiAoLin
+ * @date 2017/8/4
+ * @version
+ */
+import BaseModel from "../../common/base/base_model";
+import STDBillsLibListsSchema from "./schemas/std_bills_lib_lists";
+
+class STDBillsLibListsModel extends BaseModel {
+
+    /**
+     * 构造函数
+     *
+     * @return {void}
+     */
+    constructor() {
+        let parent = super();
+        parent.model = STDBillsLibListsSchema;
+        parent.init();
+    }
+
+    /**
+     * 获取标准清单
+     *
+     * @return {Promise}
+     */
+    async getBillList() {
+        let result = false;
+        let billLib = await this.findDataByCondition({deleted: false}, null, false);
+        if (billLib.length <= 0) {
+            return result;
+        }
+
+        // 整理数据
+        let billList = {};
+        for(let tmp of billLib) {
+            let tmpRation = {id: tmp.billsLibId, name: tmp.billsLibName};
+            if (billList[tmp.localeType] === undefined) {
+                billList[tmp.localeType] = [tmpRation];
+            } else {
+                billList[tmp.localeType].push(tmpRation);
+            }
+        }
+
+        result = billList;
+        return result;
+    }
+
+}
+
+export default STDBillsLibListsModel;

+ 6 - 10
modules/users/controllers/version_controller.js

@@ -8,6 +8,7 @@
 import BaseController from "../../common/base/base_controller";
 import VersionModel from "../models/version_model";
 import STDRationLibMapModel from "../../common/std/std_ration_lib_map_model";
+import STDBillLibListsModel from "../../common/std/std_bills_lib_lists_model";
 import {default as ProvinceConst, List as ProvinceList} from "../../common/const/province_const";
 
 class VersionController extends BaseController {
@@ -24,20 +25,15 @@ class VersionController extends BaseController {
 
         let versionList = [];
 
-        let billList = {
-            1: [
-                {id: '1', name: '重庆2017标准清单'},
-                {id: '2', name: '重庆2015标准清单'}
-            ],
-            2: [
-                {id: '3', name: '广东2017标准清单'},
-                {id: '4', name: '广东2015标准清单'},
-            ]
-        };
 
         let rationList = {};
         let selectedVersion = {};
+        let billList = {};
         try {
+            // 获取标准清单
+            let stdBillLibListsModel = new STDBillLibListsModel();
+            billList = await stdBillLibListsModel.getBillList();
+
             // 获取定额库
             let stdRationLibMapModel = new STDRationLibMapModel();
             rationList = await stdRationLibMapModel.getRationLib();

+ 1 - 1
modules/users/models/schemas/version.js

@@ -24,7 +24,7 @@ let modelSchema = {
     // 创建时间
     create_time: Number,
     // 创建者id
-    creator: Number
+    creator: String
 };
 let model = mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));
 export {model as default, collectionName as collectionName};

+ 10 - 0
modules/users/models/version_model.js

@@ -45,6 +45,8 @@ class VersionModel extends BaseModel {
                 this.model.schema.path('name').required(true);
                 this.model.schema.path('standard_bill').required(true);
                 this.model.schema.path('ration_lib').required(true);
+                this.model.schema.path('creator').required(true);
+                this.model.schema.path('create_time').required(true);
                 break;
         }
     }
@@ -108,6 +110,14 @@ class VersionModel extends BaseModel {
             id: model === 'bill' ? standardBillId : rationLibId,
             name: model === 'bill' ? standardBill : rationLib
         };
+        // 判断是否有重复
+        if (versionData[field].length > 0) {
+            for (let tmp of versionData[field]) {
+                if (tmp.id === tmpData.id) {
+                    throw '已存在对应数据';
+                }
+            }
+        }
         versionData[field].push(tmpData);
         updateData[field] = versionData[field];