caipin 4 years ago
parent
commit
13c26d5c43

+ 2 - 2
app/base/base_service.js

@@ -174,10 +174,10 @@ class BaseService extends Service {
         if (this.ctx.sort !== undefined && this.ctx.sort.length > 0) {
             this.sqlBuilder.orderBy = [this.ctx.sort];
         }
-
+        
         const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
         const list = await this.db.query(sql, sqlParam);
-
+        
         return list;
     }
 

+ 1 - 1
app/controller/manager_controller.js

@@ -25,7 +25,7 @@ module.exports = app => {
             ctx.service.manager.searchFilter(ctx.request.query, managerSession);
             const managerList = await ctx.service.manager.getListWithBuilder();
             const total = await ctx.service.manager.count();
-
+            
             // 判断用户权限和所属办事处(PS:只有总部非造价研究中心和超级管理员可查看所有管理员用户,其它只显示该分组用户)
             let officeList = [];
             const permission = managerSession.permission;

+ 30 - 8
app/controller/project_controller.js

@@ -24,7 +24,6 @@ module.exports = app => {
          */
         async index(ctx) {
             const page = ctx.page;
-
             // 过滤数据
             ctx.service.project.searchFilter(ctx.request.query, ctx.session.managerSession);
             // 获取项目列表
@@ -91,12 +90,10 @@ module.exports = app => {
             // 获取数据规则
             const rule = ctx.service.project.rule('project');
             const frontRule = ctx.helper.validateConvert(rule);
-            const managerList = await ctx.service.manager.getManagerList('office', false);
-
-            // 计价规范
-            ctx.service.valuationList.searchFilter(ctx.request.query);
-            const valuationList = await ctx.service.valuationList.getListWithBuilder();
 
+            //TODO 替换成获得cld人员
+            const managerList = await ctx.service.manager.getManagerList('office', false);
+            
             // 面包屑
             let breadCrumb = [
                 { name: ctx.topPermission.name },
@@ -108,7 +105,6 @@ module.exports = app => {
                 rule: JSON.stringify(frontRule),
                 officeList: JSON.stringify(cldOfficeConst.list),
                 managerList: JSON.stringify(managerList),
-                valuationList,
                 breadCrumb,
             };
             await this.layout('project/add.ejs', renderData);
@@ -181,8 +177,10 @@ module.exports = app => {
                 // 获取数据规则
                 const scene = id === 0 ? 'project' : 'projectModify';
                 const rule = ctx.service.project.rule(scene);
-                ctx.validate(rule);
 
+                ctx.validate(rule);
+   
+                
                 const result = await ctx.service.project.save(ctx.request.body, id);
                 if (!result) {
                     throw '保存项目数据失败';
@@ -576,6 +574,30 @@ module.exports = app => {
         }
 
         /**
+         * 检测工程建设项目是否容许创建
+         * @param {*} ctx -egg 全局变量
+         */
+        async codeValid(ctx) {
+            let result = false;
+            const projectCode = ctx.request.query.code;
+
+            try {
+                if (projectCode === undefined || projectCode === '') {
+                    throw '数据为空';
+                }
+                //工程建设项目编号不存在
+                const projectCodeData = await ctx.service.project.findOne('code', projectCode);
+                if (projectCodeData.length === 0) {
+                    //TODO - 验证计量支付项目编号 -- 存在验证成功:容许创建
+                    result = true;
+                }
+            } catch (error) {
+                result = false;
+            }
+            ctx.body = result;
+        }
+
+        /**
          * 获取共用面包屑
          *
          * @param {Object} projectData - 项目数据

+ 1 - 0
app/lib/cld.js

@@ -53,6 +53,7 @@ class Cld {
             if (responseData.err !== 0) {
                 throw '接口返回错误:' + responseData.err;
             }
+            
             // 如果验证成功,则新增CLD数据到数据库
             if (responseData.data !== '') {
                 const addResult = await this.ctx.service.manager.addCldUser(responseData.data);

+ 0 - 6
app/middleware/session_auth.js

@@ -1,9 +1,3 @@
-/*
- * @description: 
- * @Author: CP
- * @Date: 2020-08-18 12:29:01
- * @FilePath: \construction_management_backstage\app\middleware\session_auth.js
- */
 'use strict';
 
 // 加密类

+ 5 - 4
app/public/js/form_validate.js

@@ -5,11 +5,11 @@
  * @date 2017/9/29
  * @version
  */
-$(document).ready(function() {
+$(document).ready(function () {
     $("form").validate({
         rules: rule === undefined ? {} : rule,
         messages: message === undefined ? {} : message,
-        errorPlacement: function(error, element) {
+        errorPlacement: function (error, element) {
             $(element).addClass('is-invalid');
             $(element).parent().next("div.col-lg-4").append(error);
             $(element).parent().parent().next("div.col-lg-4").append(error);
@@ -17,14 +17,15 @@ $(document).ready(function() {
         errorClass: "invalid-feedback",
         errorElement: "div",
         highlight: false,
-        success: function(element) {
+        success: function (element) {
             $(element).parent().parent().find("input").removeClass('is-invalid');
             $(element).parent().parent().find("select").removeClass('is-invalid');
         }
     });
 
 
-    $("button[type='submit']").click(function() {
+    $("button[type='submit']").click(function () {
+        
         $("form").valid();
     });
 });

+ 3 - 0
app/router.js

@@ -19,6 +19,8 @@ module.exports = app => {
     // 控制面板相关
     app.get('/dashboard', sessionAuth, 'dashboardController.index');
 
+
+    
     // 管理员相关
     app.get('/manager', sessionAuth, permissionFilter, 'managerController.index');
     // app.get('/manager/add', sessionAuth, permissionFilter, 'managerController.add');
@@ -89,6 +91,7 @@ module.exports = app => {
     app.post('/project/office/share', sessionAuth, permissionFilter, 'projectController.officeShare');
     app.get('/project/pageshow', sessionAuth, permissionFilter, 'projectController.pageshow');
     app.post('/project/pageshow/set', sessionAuth, permissionFilter, 'projectController.pageshowSet');
+    app.get('/project/code/valid', sessionAuth, permissionFilter, 'projectController.codeValid');
 
     // 项目账户相关
     app.get('/project/account', sessionAuth, permissionFilter, 'projectAccountController.index');

+ 69 - 50
app/service/project.js

@@ -7,7 +7,9 @@
  * @date 2017/11/8
  * @version
  */
+//计量支付相关
 
+const Jl = require('../lib/jl');
 const cldOfficeConst = require('../const/cld_office');
 module.exports = app => {
 
@@ -50,12 +52,11 @@ module.exports = app => {
             switch (name) {
                 case 'project':
                     rule = {
+                        code: { type: 'string', required: true, min: 2 },
                         name: { type: 'string', required: true, min: 2 },
                         remark: { type: 'string', required: false, allowEmpty: true },
-                        office: { type: 'string', required: true },
                         manager_office: { type: 'string', required: true },
                         manager_id: { type: 'string', required: true },
-                        valuation: { type: 'array', required: true },
                     };
                     break;
                 case 'projectModify':
@@ -264,8 +265,8 @@ module.exports = app => {
             id = parseInt(id);
             delete data._csrf;
 
-            data.max_user = data.max_user !== '' ? parseInt(data.max_user) : 0;
-            data.valuation = data.valuation !== undefined && data.valuation !== null ? data.valuation.join(',') : '';
+            //data.max_user = data.max_user !== '' ? parseInt(data.max_user) : 0;
+            //data.valuation = data.valuation !== undefined && data.valuation !== null ? data.valuation.join(',') : '';
             // 初始化事务
             this.transaction = await this.db.beginTransaction();
             try {
@@ -273,28 +274,8 @@ module.exports = app => {
                     data.id = id;
                     delete data.create_time;
                 } else {
-                    // 生成项目code
-                    // const current = new Date();
-                    // // const year = current.getFullYear();
-                    // const year = 2031;
-                    // const month = current.getMonth() + 1 < 10 ? '0' + (current.getMonth() + 1) : current.getMonth() + 1;
-                    // const startYear = 2018;
-                    // // 65是A的ascii码
-                    // let startCharCode = 65 + year - startYear;
-                    // // 跳过I和O
-                    // if (year > 2025) {
-                    //     startCharCode += 1;
-                    // }
-                    // if (year > 2030) {
-                    //     startCharCode += 1;
-                    // }
-                    // // 原子计数器
-                    // const counterKey = month + 'counter';
-                    // let counter = await this.cache.incr(counterKey);
-                    // console.log(counter);
-                    // counter = counter < 10 ? '0' + counter : counter;
-                    // data.code = String.fromCharCode(startCharCode) + month + counter;
-                    data.code = await this.getNewCode();
+                    //TODO --项目编号--
+                    //data.code = await this.getNewCode();
 
                     // 获取当前创建者数据
                     const sessionUserData = this.ctx.session.managerSession;
@@ -307,8 +288,11 @@ module.exports = app => {
 
                     // 默认状态为试用
                     data.status = this.status.TRY;
+                    //detele -测试中
+                    // data.user_id=3;
+                    // data.user_account='caipin'
                 }
-
+                //创建项目或者更新
                 const operate = id === 0 ? await this.transaction.insert(this.tableName, data) :
                     await this.transaction.update(this.tableName, data);
 
@@ -316,31 +300,39 @@ module.exports = app => {
                     throw '保存项目数据失败';
                 }
 
-                // 新增项目账号
-                if (data.user_account) {
-                    const projectId = id === 0 ? operate.insertId : id;
-                    this.ctx.service.projectAccount.transaction = this.transaction;
-
-                    // 先判断表中是否已存在该账号
-                    const projectAccountData = await this.ctx.service.projectAccount.isAccountExist(data.user_account, projectId);
-
-                    if (projectAccountData !== null) {
-                        await this.ctx.service.projectAccount.checkAdminProjectAccount(projectAccountData);
-                    } else {
-                        // 再判断账号属于customer还是sso
-                        const result = await this.ctx.service.customer.getDataInfo(data.user_account);
-                        if (result !== null && result.type === 2) {
-                            // 添加到customer表
-                            this.ctx.service.customer.transaction = this.transaction;
-                            await this.ctx.service.customer.saveSSOUser(result.data);
-                        }
-                        this.ctx.service.projectAccount.transaction = this.transaction;
-                        await this.ctx.service.projectAccount.saveAdminProjectAccount(result.data, projectId);
-                    }
-
-
+                // 拉取计量支付管理用户---
+                const jl = new Jl(this.ctx);
+                result = await jl.getJlProjectAccountData(data.code);
+                if(result===null){
+                    throw '获取计量支付项目管理员失败';
                 }
+               
+                // 先判断表中是否已存在该账号
+                const projectId = id === 0 ? operate.insertId : id;
+                const projectAccountData = await this.ctx.service.projectAccount.isAccountExist(result.account, projectId);
+                if (projectAccountData) {
+                    await this.ctx.service.projectAccount.checkAdminProjectAccount(projectAccountData);
+                } else {
+                    // 新增项目账号
+                    this.ctx.service.projectAccount.transaction = this.transaction;//事务
+                    const accountData=await this.ctx.service.projectAccount.saveAdminProjectAccount(result, projectId);
+
+                    // 更新项目表
+                    data.user_id=accountData.insertId;
+                    data.user_account=result.account;
+                    data.id=projectId;
+                    await this.transaction.update(this.tableName, data);
+                }
+
 
+                
+                    // 再判断账号属于customer还是sso
+                    // const result = await this.ctx.service.customer.getDataInfo(data.user_account);
+                    // if (result !== null && result.type === 2) {
+                    //     // 添加到customer表
+                    //     this.ctx.service.customer.transaction = this.transaction;
+                    //     await this.ctx.service.customer.saveSSOUser(result.data);
+                    // }
                 result = await this.transaction.commit();
 
             } catch (error) {
@@ -432,6 +424,33 @@ module.exports = app => {
         }
 
         /**
+         * 获得一条项目数据
+         * @param {*} field 字段
+         * @param {*} value 值
+         */
+        async findOne(field,value) {
+            let result = [];
+            try{
+                this.initSqlBuilder();
+                this.sqlBuilder.setAndWhere(field, {
+                    value: value,
+                    operate: '=',
+                });
+                this.sqlBuilder.columns = ['id', 'code', 'name', 'status', 'create_time', 'user_id'];
+                const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
+                const projectData = await this.db.query(sql, sqlParam);
+                //建设工程项目不存在,验证计量支付的项目编号
+                if(projectData.length !==0){
+                    result=projectData;
+                }
+            }catch (error) {
+                console.log(error);
+                result= [];
+            }
+            return result;
+        }
+
+        /**
          * 获取办事处id
          *
          * @param {Object} data - 办事处列表

+ 18 - 17
app/service/project_account.js

@@ -257,26 +257,26 @@ module.exports = app => {
          */
         async saveAdminProjectAccount(data, projectId) {
             // 查找对应账号数据
-            const accountData = await this.db.get(this.tableName, { project_id: projectId, is_admin: 1 });
-            let type = null;
-            if (accountData !== null && (accountData.account === data.email || accountData.account === data.mobile)) {
-                return true;
-            } else if (accountData !== null && accountData.account !== data.email && accountData.account !== data.mobile) {
-                // 撤销原有管理员身份
-                const updateData = {
-                    id: accountData.id,
-                    is_admin: 0,
-                };
-                await this.transaction.update(this.tableName, updateData);
-            }
-
-            const account = data.email === null || data.email === '' ? data.mobile : data.email;
+            // console.log(data)
+            // const accountData = await this.db.get(this.tableName, { project_id: projectId, is_admin: 1 });
+            // let type = null;
+            // if (accountData !== null && (accountData.account === data.email || accountData.account === data.mobile)) {
+            //     return true;
+            // } else if (accountData !== null && accountData.account !== data.email && accountData.account !== data.mobile) {
+            //     // 撤销原有管理员身份
+            //     const updateData = {
+            //         id: accountData.id,
+            //         is_admin: 0,
+            //     };
+            //     await this.transaction.update(this.tableName, updateData);
+            // }
+            // const account = data.email === null || data.email === '' ? data.mobile : data.email;
 
             // 新增数据
             const insertData = {
                 project_id: projectId,
-                account: account,
-                password: 'SSO password',
+                account: data.account,
+                password: 'JL password',
                 account_group: data.account_group,
                 name: data.name,
                 mobile: data.mobile,
@@ -287,7 +287,8 @@ module.exports = app => {
                 // permission: 'all',
             };
             const result = await this.transaction.insert(this.tableName, insertData);
-            return result.affectedRows > 0;
+            return result;
+            //return result.affectedRows > 0;
         }
 
         /**

+ 1 - 1
app/view/layout/layout.ejs

@@ -2,7 +2,7 @@
 <html>
 <head lang="zh-CN">
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-    <title>计量支付SAAS</title>
+    <title>信息化后台</title>
     <link href="/public/css/bootstrap/bootstrap.min.css" rel="stylesheet">
     <link href="/public/css/main.css" rel="stylesheet">
     <link rel="stylesheet" href="/public/css/toast.css">

+ 20 - 51
app/view/project/add.ejs

@@ -1,28 +1,8 @@
 <div class="panel-body mt-3">
     <form id="save-form" action="/<%= ctx.controllerName %>/save/0" method="post">
+        <input-text name="code" id="code" placeholder="输入项目编号" label="项目编号" required="true"></input-text>
         <input-text name="name" id="name" placeholder="输入项目名称" label="项目名称" required="true"></input-text>
-        <% if (valuationList.length > 0) { %>
-            <div class="form-group row required">
-                <label class="col-sm-2 col-form-label text-right"><b class="text-danger">*</b>计价标准</label>
-                <div class="col-lg-4">
-                    <% for (const valuation of valuationList) { %>
-                        <div class="form-check form-check-inline mt-2">
-                            <input class="form-check-input" id="valuation_Checkbox<%= valuation.id %>" type="checkbox" value="<%= valuation.id %>" name="valuation[]">
-                            <label class="form-check-label" for="valuation_Checkbox<%= valuation.id %>"><%= valuation.name %></label>
-                        </div>
-                    <% } %>
-                </div>
-            </div>
-        <% } %>
-        <div class="form-group row required">
-            <label class="col-sm-2 text-right"><b class="text-danger">*</b>所在办事处</label>
-            <div class="col-lg-6 row">
-                <div class="col-lg-6">
-                    <dropdown name="office" placeholder="请选择办事处" :options="officeList"></dropdown>
-                </div>
-            </div>
-            <div class="col-lg-4"></div>
-        </div>
+        
         <div class="form-group row required">
             <label class="col-sm-2 text-right"><b class="text-danger">*</b>负责人</label>
             <div class="col-lg-6 row">
@@ -35,22 +15,7 @@
             </div>
             <div class="col-lg-4"></div>
         </div>
-        <div class="form-group row">
-            <label class="col-sm-2 col-form-label text-right"><b class="text-danger">*</b>最大账号
-                数</label>
-            <div class="col-lg-6">
-                <div class="input-group">
-                    <div class="input-group-prepend">
-                        <div class="input-group-text">
-                            <input type="checkbox" id="change_maxuser" class="mr-2"> 不限制
-                        </div>
-                    </div>
-                    <input type="number" name="max_user" id="max_user_input" min="1" step="1" class="form-control" value="50" placeholder="请输入项目内可添加的最大账号数">
-                    <input type="text" name="max_user" id="max_user_input2" class="form-control" readonly disabled placeholder="项目内可以无限添加账号" style="display: none">
-                </div>
-            </div>
-            <div class="col-lg-4" style="width: 100%;margin-top: .25rem;font-size: 80%;color: #dc3545;"></div>
-        </div>
+        
         <input-text name="remark" id="remark" placeholder="项目备注"
                     label="备注"></input-text>
         <input type="hidden" name="_csrf" value="<%= ctx.csrf %>">
@@ -68,27 +33,28 @@
     managerList = JSON.parse(managerList);
 
     let rule = '<%- rule %>';
+    
     rule = JSON.parse(rule);
-    rule['user_account'] = {
-        required: false,
-        minlength: 6,
+    rule['code'] = {
+        required: true,
+        minlength: 2,
         remote: {
-            type: "post",
+            type: "get",
             //请求方式
-            url: "/customer/exist",       //发送请求的url地址
+            url: "/project/code/valid",       //发送请求的url地址
             data: {
-                _csrf: function() {``
-                    return '<%= ctx.csrf %>';
-                },
-                account: function() {
-                    return $("#user-account").val();
-                }
+                // _csrf: function() {``
+                //     return '<%= ctx.csrf %>';
+                // },
+                // account: function() {
+                //     return $("#code").val();
+                // }
             }
         },
     };
     let message = {
-        user_account: {
-            remote: 'SSO账号不存在'
+        code: {
+            remote: '工程项目已创建或项目编号不存在'
         }
     };
 
@@ -99,6 +65,9 @@
             officeList: officeList,
         }
     });
+
+
+
 </script>
 <script type="text/javascript" src="/public/js/form_validate.js"></script>
 <script type="text/javascript" src="/public/js/validate.extend.js"></script>

+ 7 - 7
package.json

@@ -43,14 +43,14 @@
     "node": ">=6.0.0"
   },
   "scripts": {
-    "start": "egg-scripts start --daemon --port 8004",
+    "start": "egg-scripts start --daemon --port 8994",
     "stop": "egg-scripts stop",
-    "start-qa": "EGG_SERVER_ENV=qa egg-scripts start --daemon --port 8004",
-    "dev": "set EGG_SERVER_ENV=local&&egg-bin dev --port 8004",
-    "dev-local": "set EGG_SERVER_ENV=local&&egg-bin dev --port 8004",
-    "dev-remoteqa": "set EGG_SERVER_ENV=remoteqa&&egg-bin dev --port 8004",
-    "dev-temp": "set EGG_SERVER_ENV=temp&&egg-bin dev --port 8004",
-    "dev-qa": "set EGG_SERVER_ENV=qa&&egg-bin dev --port 8004",
+    "start-qa": "EGG_SERVER_ENV=qa egg-scripts start --daemon --port 8994",
+    "dev": "set EGG_SERVER_ENV=local&&egg-bin dev --port 8994",
+    "dev-local": "set EGG_SERVER_ENV=local&&egg-bin dev --port 8994",
+    "dev-remoteqa": "set EGG_SERVER_ENV=remoteqa&&egg-bin dev --port 8994",
+    "dev-temp": "set EGG_SERVER_ENV=temp&&egg-bin dev --port 8994",
+    "dev-qa": "set EGG_SERVER_ENV=qa&&egg-bin dev --port 8994",
     "test": "npm run lint -- --fix && npm run test-local",
     "test-local": "set EGG_SERVER_ENV=local&&egg-bin test",
     "test-qa": "set EGG_SERVER_ENV=qa&&egg-bin test",