Pārlūkot izejas kodu

编办人工系数改为从数据库获取

olym 7 gadi atpakaļ
vecāks
revīzija
429151d3e6

+ 34 - 0
modules/common/std/schemas/std_labour_coes.js

@@ -0,0 +1,34 @@
+/**
+ * 人工系数数据模型
+ *
+ * @author CaiAoLin
+ * @date 2017/9/11
+ * @version
+ */
+import mongoose from "mongoose";
+
+let Schema = mongoose.Schema;
+let collectionName = 'std_labour_coes';
+let coesSchema = new Schema({
+    // 自增id
+    ID: Number,
+    // 父级id
+    ParentID: Number,
+    // 名称
+    name: String,
+    // 系数
+    coe: Number
+});
+let modelSchema = {
+    // 自增id
+    ID: Number,
+    // 所在地
+    region: String,
+    // 标准名称
+    libName: String,
+    // 人工系数数据
+    coes: [coesSchema]
+};
+
+let model = mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));
+export {model as default, collectionName as collectionName};

+ 50 - 0
modules/common/std/std_labour_coes_model.js

@@ -0,0 +1,50 @@
+/**
+ * 人工系数业务模型
+ *
+ * @author CaiAoLin
+ * @date 2017/9/11
+ * @version
+ */
+import BaseModel from "../base/base_model";
+import STDLabourCoesSchema from "./schemas/std_labour_coes";
+
+class STDLabourCoesModel extends BaseModel {
+
+    /**
+     * 构造函数
+     *
+     * @return {void}
+     */
+    constructor() {
+        let parent = super();
+        parent.model = STDLabourCoesSchema;
+        parent.init();
+    }
+
+    /**
+     * 获取人工系数列表
+     *
+     * @return {Promise}
+     */
+    async getLabourCoesList() {
+        let result = [];
+        let field = {ID: 1, libName: 1};
+        let feeRateList = await this.findDataByCondition({ID: {$ne: ''}}, field, false);
+
+        if (feeRateList === null) {
+            return result;
+        }
+        // 整理数据
+        for(let feeRate of feeRateList) {
+            let tmpData = {
+                id: feeRate.ID,
+                name: feeRate.libName
+            };
+            result.push(tmpData);
+        }
+        return result;
+    }
+
+}
+
+export default STDLabourCoesModel;

+ 4 - 2
modules/users/controllers/compilation_controller.js

@@ -15,6 +15,7 @@ import {default as EngineeringConst, List as EngineeringList} from "../../common
 import BillsTemplateModel from "../models/bills_template_model";
 import {default as BillsFixedFlagConst, List as BillsFixedFlagList} from "../../common/const/bills_fixed.js";
 import EngineeringLibModel from "../models/engineering_lib_model";
+import STDLabourCoesModel from "../../common/std/std_labour_coes_model";
 
 class CompilationController extends BaseController {
 
@@ -204,8 +205,9 @@ class CompilationController extends BaseController {
             let stdFeeRateLibsModel = new STDFeeRateLibsModel();
             feeRateList = await stdFeeRateLibsModel.getFeeRateList();
 
-            // 获取人工系数标准库 @todo 更改为数据库获取
-            artificialCoefficientList = [{name: '2006标准', id: 1}];
+            // 获取人工系数标准库
+            let stdLabourCoesModel = new STDLabourCoesModel();
+            artificialCoefficientList = await stdLabourCoesModel.getLabourCoesList();
 
             // 获取对应的计价规则数据
             [valuationData, valuationList] = await compilationModel.getValuation(selectedCompilation._id, valuationId, section);