|
@@ -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 - 办事处列表
|