瀏覽代碼

1.接入定额库数据
2.省份数据定义为常量

caiaolin 8 年之前
父節點
當前提交
c07b709d5c

+ 18 - 0
modules/common/const/province_const.js

@@ -0,0 +1,18 @@
+/**
+ * 省份常量
+ *
+ * @author CaiAoLin
+ * @date 2017/8/1
+ * @version
+ */
+const province = {
+    CHONGQING: 1,
+    GUANGDONG: 2
+};
+
+const provinceList = [
+    {id: province.CHONGQING, name: '重庆省'},
+    {id: province.GUANGDONG, name: '广东省'}
+];
+
+export {province as default, provinceList as List};

+ 32 - 0
modules/common/std/schemas/std_ration_lib_map.js

@@ -0,0 +1,32 @@
+/**
+ * 定额库数据模型
+ *
+ * @author CaiAoLin
+ * @date 2017/8/1
+ * @version
+ */
+import mongoose from "mongoose";
+
+let Schema = mongoose.Schema;
+let collectionName = 'std_ration_lib_map';
+let modelSchema = {
+    // 自增id
+    ID: {
+        type: Number,
+        index: true
+    },
+    // 展示名称
+    dispName: String,
+    // app类型
+    appType: Number,
+    // 地区/省份类型
+    localeType: {
+        type: Number,
+        index: true
+    },
+    descr: String,
+    // 是否被删除
+    deleted: Boolean
+};
+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_ration_lib_map_model.js

@@ -0,0 +1,53 @@
+/**
+ * 定额库业务逻辑模型
+ *
+ * @author CaiAoLin
+ * @date 2017/8/1
+ * @version
+ */
+import BaseModel from "../base/base_model";
+import STDRationLibMapSchema from "./schemas/std_ration_lib_map";
+
+class STDRationLibMapModel extends BaseModel {
+
+    /**
+     * 构造函数
+     *
+     * @return {void}
+     */
+    constructor() {
+        let parent = super();
+        parent.model = STDRationLibMapSchema;
+        parent.init();
+    }
+
+    /**
+     * 获取定额库
+     *
+     * @return {Promise}
+     */
+    async getRationLib() {
+        let result = false;
+        let rationLib = await this.findDataByCondition({deleted: false}, null, false);
+        if (rationLib.length <= 0) {
+            return result;
+        }
+
+        // 整理数据
+        let rationData = {};
+        for(let tmp of rationLib) {
+            let tmpRation = {id: tmp.ID, name: tmp.dispName};
+            if (rationData[tmp.localeType] === undefined) {
+                rationData[tmp.localeType] = [tmpRation];
+            } else {
+                rationData[tmp.localeType].push(tmpRation);
+            }
+        }
+
+        result = rationData;
+        return result;
+    }
+
+}
+
+export default STDRationLibMapModel;

+ 8 - 16
modules/users/controllers/version_controller.js

@@ -7,6 +7,8 @@
  */
 import BaseController from "../../common/base/base_controller";
 import VersionModel from "../models/version_model";
+import STDRationLibMapModel from "../../common/std/std_ration_lib_map_model";
+import {default as ProvinceConst, List as ProvinceList} from "../../common/const/province_const";
 
 class VersionController extends BaseController {
 
@@ -21,11 +23,6 @@ class VersionController extends BaseController {
         let id = request.query.id;
 
         let versionList = [];
-        // @todo 后续从库中获取
-        let province = [
-            {id: 1, name: '重庆省'},
-            {id: 2, name: '广东省'},
-        ];
 
         let billList = {
             1: [
@@ -38,18 +35,13 @@ class VersionController extends BaseController {
             ]
         };
 
-        let rationList = {
-            1: [
-                {id: '1', name: '重庆2017定额'},
-                {id: '2', name: '重庆2015定额'}
-            ],
-            2: [
-                {id: '3', name: '广东2017定额'},
-                {id: '4', name: '广东2015定额'}
-            ]
-        };
+        let rationList = {};
         let selectedVersion = {};
         try {
+            // 获取定额库
+            let stdRationLibMapModel = new STDRationLibMapModel();
+            rationList = await stdRationLibMapModel.getRationLib();
+
             let versionModel = new VersionModel();
             versionList = await versionModel.getVersionList();
 
@@ -76,7 +68,7 @@ class VersionController extends BaseController {
             selectedVersion: selectedVersion,
             billList: JSON.stringify(billList),
             rationList: JSON.stringify(rationList),
-            province: JSON.stringify(province),
+            province: JSON.stringify(ProvinceList),
             layout: 'users/views/layout/layout'
         };
 

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

@@ -61,6 +61,7 @@ class VersionModel extends BaseModel {
             return result;
         }
 
+        this.setScene('add');
         result = this.db.create(data);
         return result;
     }