Commit be5c5306 by Sxy

fix: 代码规范

parent 8963ffd5
...@@ -34,19 +34,19 @@ class OSSAPI extends APIBase { ...@@ -34,19 +34,19 @@ class OSSAPI extends APIBase {
}; };
return system.getResult(data); return system.getResult(data);
}; }
async upfile(srckey, dest) { async upfile(srckey, dest) {
const oss = System.getObject('util.ossClient'); const oss = System.getObject('util.ossClient');
const result = await oss.upfile(srckey, `/tmp/${dest}`); const result = await oss.upfile(srckey, `/tmp/${dest}`);
return result; return result;
}; }
async downfile(srckey) { async downfile(srckey) {
const oss = System.getObject('util.ossClient'); const oss = System.getObject('util.ossClient');
var downfile = await oss.downfile(srckey).then(() => { let downfile = await oss.downfile(srckey).then(() => {
downfile = `/tmp/${srckey}`; downfile = `/tmp/${srckey}`;
return downfile; return downfile;
}); });
return downfile; return downfile;
}; }
} }
module.exports = OSSAPI; module.exports = OSSAPI;
...@@ -27,9 +27,9 @@ class UserCtl extends CtlBase { ...@@ -27,9 +27,9 @@ class UserCtl extends CtlBase {
// let v = await this.smsS.sendVCode(mobile); // let v = await this.smsS.sendVCode(mobile);
// return system.getResult({ vcodestr: v }); // return system.getResult({ vcodestr: v });
// } // }
async exit(pobj, qobj, req) { // async exit(pobj, qobj, req) {
} // }
// 应用的自由用户注册,无需验证,需要前端头设置公司KEY // 应用的自由用户注册,无需验证,需要前端头设置公司KEY
async pmregisterByFreeUser(p, q, req) { async pmregisterByFreeUser(p, q, req) {
// 检查是否有用户名和密码 // 检查是否有用户名和密码
......
...@@ -575,9 +575,9 @@ class DeliverybillCtl extends CtlBase { ...@@ -575,9 +575,9 @@ class DeliverybillCtl extends CtlBase {
} }
if (pobj.type == 'salesman') { if (pobj.type == 'salesman') {
sInfo.salesmanInfo = { sInfo.salesmanInfo = {
oldOpcode: res.sales_man_opcode, oldOpcode: res.salesman_opcode,
oldClerkName: res.sales_man_name, oldClerkName: res.salesman_name,
oldClerkId: res.sales_man_id, oldClerkId: res.salesman_id,
newOpcode: pobj.salesmanOpcode, newOpcode: pobj.salesmanOpcode,
newClerkName: pobj.salesmanName, newClerkName: pobj.salesmanName,
newClerkId: pobj.salesmanId, newClerkId: pobj.salesmanId,
...@@ -841,7 +841,7 @@ class DeliverybillCtl extends CtlBase { ...@@ -841,7 +841,7 @@ class DeliverybillCtl extends CtlBase {
if (pobj.companyInfo.companyProperties && pobj.companyInfo.companyProperties != 'undefined') { if (pobj.companyInfo.companyProperties && pobj.companyInfo.companyProperties != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.companyProperties = pobj.companyInfo.companyProperties; pobj.cacheInfo.cmpDeliverInfo.companyProperties = pobj.companyInfo.companyProperties;
} else { } else {
if (pobj.cacheInfo.cmpDeliverInfo.companyType && pobj.cacheInfo.cmpDeliverInfo.companyType) { if (pobj.cacheInfo.cmpDeliverInfo.companyType) {
pobj.cacheInfo.cmpDeliverInfo.companyProperties = pobj.cacheInfo.cmpDeliverInfo.companyType; pobj.cacheInfo.cmpDeliverInfo.companyProperties = pobj.cacheInfo.cmpDeliverInfo.companyType;
} }
} }
...@@ -884,7 +884,7 @@ class DeliverybillCtl extends CtlBase { ...@@ -884,7 +884,7 @@ class DeliverybillCtl extends CtlBase {
if (pobj.companyInfo.engagedIndustry && pobj.companyInfo.engagedIndustry != 'undefined') { if (pobj.companyInfo.engagedIndustry && pobj.companyInfo.engagedIndustry != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.engagedIndustry = pobj.companyInfo.engagedIndustry; pobj.cacheInfo.cmpDeliverInfo.engagedIndustry = pobj.companyInfo.engagedIndustry;
} }
if (pobj.companyInfo.engagedIndName && pobj.companyInfo.engagedIndName) { if (pobj.companyInfo.engagedIndName) {
pobj.cacheInfo.cmpDeliverInfo.engagedIndName = pobj.companyInfo.engagedIndName; pobj.cacheInfo.cmpDeliverInfo.engagedIndName = pobj.companyInfo.engagedIndName;
} }
if (pobj.companyInfo.fullAddress && pobj.companyInfo.fullAddress != 'undefined') { if (pobj.companyInfo.fullAddress && pobj.companyInfo.fullAddress != 'undefined') {
......
...@@ -41,21 +41,21 @@ class SchemeCtl extends CtlBase { ...@@ -41,21 +41,21 @@ class SchemeCtl extends CtlBase {
rarr.servicerName = rs.facilitator_name;// 服务商名称 rarr.servicerName = rs.facilitator_name;// 服务商名称
rarr.clerkName = rs.salesman_name;// 业务员名称 rarr.clerkName = rs.salesman_name;// 业务员名称
rarr.clerkPhone = rs.salesman_phone;// 业务员联系方式 rarr.clerkPhone = rs.salesman_phone;// 业务员联系方式
rarr.createdTime = this.timeFormat(rs.created_at);// 创建方案的日期 rarr.createdTime = this.timeFormat(rs.created_at);// 创建方案的日期
rarr.statusTime = this.timeFormat(rs.updated_at);// 当前状态的日期 rarr.statusTime = this.timeFormat(rs.updated_at);// 当前状态的日期
const baseInfo = {}; const baseInfo = {};
if (rs.scheme_info.companyName && rs.scheme_info.companyName != 'undefined') { // 公司名称 if (rs.scheme_info.companyName && rs.scheme_info.companyName != 'undefined') { // 公司名称
rarr.companyName = rs.scheme_info.companyName; rarr.companyName = rs.scheme_info.companyName;
} }
if (rarr.businessName == '公司注册' || rarr.businessName == '园区注册' if (rarr.businessName == '公司注册' || rarr.businessName == '园区注册'
|| rarr.businessName == '税控申请' || rarr.businessName == '代理记账') { || rarr.businessName == '税控申请' || rarr.businessName == '代理记账') {
baseInfo.taxpayerType = rs.scheme_info.taxpayerType; baseInfo.taxpayerType = rs.scheme_info.taxpayerType;
} }
if (rarr.businessName == '园区注册') { if (rarr.businessName == '园区注册') {
baseInfo.registeredType = rs.scheme_info.registeredType; baseInfo.registeredType = rs.scheme_info.registeredType;
} }
if (rarr.businessName == '公司注册' || rarr.businessName == '园区注册') { if (rarr.businessName == '公司注册' || rarr.businessName == '园区注册') {
baseInfo.companyProperties = rs.scheme_info.companyProperties; baseInfo.companyProperties = rs.scheme_info.companyProperties;
baseInfo.engagedIndustry = rs.scheme_info.engagedIndustry; baseInfo.engagedIndustry = rs.scheme_info.engagedIndustry;
baseInfo.addressType = rs.scheme_info.addressType; baseInfo.addressType = rs.scheme_info.addressType;
baseInfo.fullAddress = rs.scheme_info.fullAddress; baseInfo.fullAddress = rs.scheme_info.fullAddress;
...@@ -123,7 +123,7 @@ class SchemeCtl extends CtlBase { ...@@ -123,7 +123,7 @@ class SchemeCtl extends CtlBase {
rarr.clerkId = rs.salesman_id;// 业务员id; rarr.clerkId = rs.salesman_id;// 业务员id;
rarr.clerkName = rs.salesman_name;// 业务员名称 rarr.clerkName = rs.salesman_name;// 业务员名称
rarr.clerkPhone = rs.salesman_phone;// 业务员联系方式 rarr.clerkPhone = rs.salesman_phone;// 业务员联系方式
rarr.createdTime = this.timeFormat(rs.created_at);// 创建方案的日期 rarr.createdTime = this.timeFormat(rs.created_at);// 创建方案的日期
rarr.statusTime = this.timeFormat(rs.updated_at);// 当前状态的日期 rarr.statusTime = this.timeFormat(rs.updated_at);// 当前状态的日期
rarr.baseInfo = rs.scheme_info; rarr.baseInfo = rs.scheme_info;
} }
...@@ -288,13 +288,13 @@ class SchemeCtl extends CtlBase { ...@@ -288,13 +288,13 @@ class SchemeCtl extends CtlBase {
} }
// 修改方案的时候,需要把修改的方案传给商城 // 修改方案的时候,需要把修改的方案传给商城
const ttype = pobj.businessType; const ttype = pobj.businessType;
console.log(`ttype:${ttype}`); console.log(`ttype:${ttype}`);
pobj.businessType = appconfig.pdict.fdyDict[pobj.businessType]; pobj.businessType = appconfig.pdict.fdyDict[pobj.businessType];
console.log(`businessType:${pobj.businessType}`); console.log(`businessType:${pobj.businessType}`);
const rc = system.getObject('util.execClient'); const rc = system.getObject('util.execClient');
const requrl = this.receiveUrl; const requrl = this.receiveUrl;
const params = { const params = {
actionType: 'submitSolution', actionType: 'submitSolution',
actionBody: { actionBody: {
needNum: pobj.businessMode, needNum: pobj.businessMode,
...@@ -453,12 +453,12 @@ class SchemeCtl extends CtlBase { ...@@ -453,12 +453,12 @@ class SchemeCtl extends CtlBase {
} }
// 调商城的接口,把商机详情返回给商城 // 调商城的接口,把商机详情返回给商城
const btype = pobj.businessType; const btype = pobj.businessType;
pobj.businessType = appconfig.pdict.fdyDict[pobj.businessType]; pobj.businessType = appconfig.pdict.fdyDict[pobj.businessType];
const rc = system.getObject('util.execClient'); const rc = system.getObject('util.execClient');
const requrl = this.receiveUrl; const requrl = this.receiveUrl;
const params = { const params = {
actionType: 'submitSolution', actionType: 'submitSolution',
actionBody: { actionBody: {
needNum: pobj.businessMode, needNum: pobj.businessMode,
...@@ -510,9 +510,3 @@ class SchemeCtl extends CtlBase { ...@@ -510,9 +510,3 @@ class SchemeCtl extends CtlBase {
} }
module.exports = SchemeCtl; module.exports = SchemeCtl;
// var task = new SchemeCtl();
// var obj={"businessMode":"202006100002","baseInfo":{"memoInfo":"sfdsff","whetherType":"individual","creditCode":"1223345455","companyType":"有限公司","companyName":"三个五","establishedTime":"2010-5-6","registeredCapital":"5万元","shareholderName":"2B","businessTerm":"500","businessScope":"sgrgdrgghhh","residenceAddress":"北京市"}};
// task.insertInfo(obj,{},{}).then(d=>{
// console.log(d);
// //console.log(d[0].analyse)
// })
...@@ -11,7 +11,7 @@ class OplogCtl extends CtlBase { ...@@ -11,7 +11,7 @@ class OplogCtl extends CtlBase {
async initNewInstance(qobj) { async initNewInstance(qobj) {
const u = uuidv4(); const u = uuidv4();
const aid = u.replace(/\-/g, ''); const aid = u.replace(/-/g, '');
const rd = { name: '', appid: aid }; const rd = { name: '', appid: aid };
return system.getResult(rd); return system.getResult(rd);
} }
...@@ -40,7 +40,7 @@ class OplogCtl extends CtlBase { ...@@ -40,7 +40,7 @@ class OplogCtl extends CtlBase {
返回20位业务订单号 返回20位业务订单号
prefix:业务前缀 prefix:业务前缀
*/ */
async getBusUid_Ctl(prefix) { async getBusUidCtl(prefix) {
prefix = (prefix || ''); prefix = (prefix || '');
if (prefix) { if (prefix) {
prefix = prefix.toUpperCase(); prefix = prefix.toUpperCase();
...@@ -49,7 +49,7 @@ prefix:业务前缀 ...@@ -49,7 +49,7 @@ prefix:业务前缀
const subLen = 8 - prefixlength; const subLen = 8 - prefixlength;
let uidStr = ''; let uidStr = '';
if (subLen > 0) { if (subLen > 0) {
uidStr = await this.getUidInfo_Ctl(subLen, 60); uidStr = await this.getUidInfoCtl(subLen, 60);
} }
const timStr = moment().format('YYYYMMDDHHmm'); const timStr = moment().format('YYYYMMDDHHmm');
return prefix + timStr + uidStr; return prefix + timStr + uidStr;
...@@ -58,7 +58,7 @@ prefix:业务前缀 ...@@ -58,7 +58,7 @@ prefix:业务前缀
len:返回长度 len:返回长度
radix:参与计算的长度,最大为62 radix:参与计算的长度,最大为62
*/ */
async getUidInfo_Ctl(len, radix) { async getUidInfoCtl(len, radix) {
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');// 长度62,到yz长度为长36 const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');// 长度62,到yz长度为长36
const uuid = []; let i; const uuid = []; let i;
radix = radix || chars.length; radix = radix || chars.length;
...@@ -66,7 +66,10 @@ prefix:业务前缀 ...@@ -66,7 +66,10 @@ prefix:业务前缀
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]; for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else { } else {
let r; let r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; uuid[23] = '-';
uuid[18] = uuid[23];
uuid[13] = uuid[18];
uuid[8] = uuid[13];
uuid[14] = '4'; uuid[14] = '4';
for (i = 0; i < 36; i++) { for (i = 0; i < 36; i++) {
if (!uuid[i]) { if (!uuid[i]) {
......
const system = require('../../../system'); const system = require('../../../system');
const settings = require('../../../../config/settings'); const settings = require('../../../../config/settings');
class SocketNotifyCtl { class SocketNotifyCtl {
constructor() {
}
setSocketServer(s) { setSocketServer(s) {
this.socketServer = s; this.socketServer = s;
} }
......
...@@ -38,15 +38,15 @@ class UploadCtl extends CtlBase { ...@@ -38,15 +38,15 @@ class UploadCtl extends CtlBase {
}; };
return data; return data;
}; }
async upfile(srckey, dest) { async upfile(srckey, dest) {
const oss = system.getObject('util.ossClient'); const oss = system.getObject('util.ossClient');
const result = await oss.upfile(srckey, `/tmp/${dest}`); const result = await oss.upfile(srckey, `/tmp/${dest}`);
return result; return result;
}; }
async downfile(srckey) { async downfile(srckey) {
const oss = system.getObject('util.ossClient'); const oss = system.getObject('util.ossClient');
var downfile = await oss.downfile(srckey).then(() => { let downfile = await oss.downfile(srckey).then(() => {
downfile = `/tmp/${srckey}`; downfile = `/tmp/${srckey}`;
return downfile; return downfile;
}); });
...@@ -62,10 +62,10 @@ class UploadCtl extends CtlBase { ...@@ -62,10 +62,10 @@ class UploadCtl extends CtlBase {
fs.unlink(`/tmp/${srckey}`); fs.unlink(`/tmp/${srckey}`);
const result = await this.upfile(`${srckey.split('.pdf')[0]}.html`, `${srckey.split('.pdf')[0]}.html`); const result = await this.upfile(`${srckey.split('.pdf')[0]}.html`, `${srckey.split('.pdf')[0]}.html`);
return result.url; return result.url;
}; }
async insertToFile(path) { async insertToFile(path) {
const cmd = `${this.cmdInsertToFilePattern} ${path}`; const cmd = `${this.cmdInsertToFilePattern} ${path}`;
return await this.restS.exec(cmd); return this.restS.exec(cmd);
}; }
} }
module.exports = UploadCtl; module.exports = UploadCtl;
...@@ -24,8 +24,8 @@ class VCodeCache extends CacheBase { ...@@ -24,8 +24,8 @@ class VCodeCache extends CacheBase {
const vcode = await this.smsUtil.getUidStr(6, 10); const vcode = await this.smsUtil.getUidStr(6, 10);
if (!tmplCode && !signName) { if (!tmplCode && !signName) {
this.smsUtil.sendMsg(mobile, vcode); this.smsUtil.sendMsg(mobile, vcode);
} // tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息,二者没有传递则用默认的发送验证码 // tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息,二者没有传递则用默认的发送验证码
else { } else {
this.smsUtil.aliSendMsg(mobile, tmplCode, signName, JSON.stringify({ code: vcode })); this.smsUtil.aliSendMsg(mobile, tmplCode, signName, JSON.stringify({ code: vcode }));
} }
return JSON.stringify({ vcode }); return JSON.stringify({ vcode });
......
...@@ -50,9 +50,11 @@ class Dao { ...@@ -50,9 +50,11 @@ class Dao {
const en = null; const en = null;
if (t != null && t != 'undefined') { if (t != null && t != 'undefined') {
whereParam.transaction = t; whereParam.transaction = t;
return await this.model.destroy(whereParam); const result = await this.model.destroy(whereParam);
return result;
} }
return await this.model.destroy(whereParam); const result = await this.model.destroy(whereParam);
return result;
} }
async delete(qobj, t) { async delete(qobj, t) {
let en = null; let en = null;
...@@ -179,9 +181,11 @@ class Dao { ...@@ -179,9 +181,11 @@ class Dao {
} }
async bulkCreate(ids, t) { async bulkCreate(ids, t) {
if (t != null && t != 'undefined') { if (t != null && t != 'undefined') {
return await this.model.bulkCreate(ids, { transaction: t }); const result = await this.model.bulkCreate(ids, { transaction: t });
return result;
} }
return await this.model.bulkCreate(ids); const result = await this.model.bulkCreate(ids);
return result;
} }
async updateByWhere(setObj, whereObj, t) { async updateByWhere(setObj, whereObj, t) {
...@@ -220,7 +224,8 @@ class Dao { ...@@ -220,7 +224,8 @@ class Dao {
} }
async customQuery(sql, paras, t) { async customQuery(sql, paras, t) {
let tmpParas = null;// ||paras=='undefined'?{type: this.db.QueryTypes.SELECT }:{ replacements: paras, type: this.db.QueryTypes.SELECT }; let tmpParas = null;
// ||paras=='undefined'?{type: this.db.QueryTypes.SELECT }:{ replacements: paras, type: this.db.QueryTypes.SELECT };
if (t && t != 'undefined') { if (t && t != 'undefined') {
if (paras == null || paras == 'undefined') { if (paras == null || paras == 'undefined') {
tmpParas = { type: this.db.QueryTypes.SELECT }; tmpParas = { type: this.db.QueryTypes.SELECT };
...@@ -259,7 +264,8 @@ class Dao { ...@@ -259,7 +264,8 @@ class Dao {
} else { } else {
tmpWhere.raw = true; tmpWhere.raw = true;
} }
return await this.model.findAndCountAll(tmpWhere); const result = await this.model.findAndCountAll(tmpWhere);
return result;
} }
async findOne(obj) { async findOne(obj) {
return this.model.findOne({ where: obj }); return this.model.findOne({ where: obj });
......
...@@ -5,7 +5,7 @@ class RoleDao extends Dao { ...@@ -5,7 +5,7 @@ class RoleDao extends Dao {
super(Dao.getModelName(RoleDao)); super(Dao.getModelName(RoleDao));
} }
async findOne(paramappid, t) { async findOne(paramappid, t) {
const app = await this.model.findOne({ where: { appid: paramappid } }, { transaction: t }); const app = await this.model.findOne({ where: { appid: paramappid } }, { transaction: t });
return app; return app;
} }
extraWhere(obj, w, qc, linkAttrs) { extraWhere(obj, w, qc, linkAttrs) {
...@@ -38,10 +38,10 @@ class RoleDao extends Dao { ...@@ -38,10 +38,10 @@ class RoleDao extends Dao {
const self = this; const self = this;
const u2 = await this.preCreate(u); const u2 = await this.preCreate(u);
if (t) { if (t) {
var role = await this.model.create(u2, { transaction: t }); const role = await this.model.create(u2, { transaction: t });
return role; return role;
} }
var role = await this.model.create(u2); const role = await this.model.create(u2);
return role; return role;
} }
} }
......
...@@ -53,21 +53,19 @@ class UserDao extends Dao { ...@@ -53,21 +53,19 @@ class UserDao extends Dao {
tUser = tUser.get({ plain: true }); tUser = tUser.get({ plain: true });
tUser.partnerinfo = await this.partnerinfoDao.model.findOne({ where: { onlyCode: tUser.onlyCode }, raw: true }); tUser.partnerinfo = await this.partnerinfoDao.model.findOne({ where: { onlyCode: tUser.onlyCode }, raw: true });
} }
// console.log("tUser.partnerinfo...................................>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>999sy");
// console.log(tUser); // console.log(tUser);
return tUser; return tUser;
} }
async setAccount(user, account, t) { async setAccount(user, account, t) {
var user = await user.setAccount(account, { transaction: t }); const user = await user.setAccount(account, { transaction: t });
return user; return user;
} }
async setApp(user, app, t) { async setApp(user, app, t) {
// 按照APPId,获取app对象 // 按照APPId,获取app对象
var user = await user.setApp(app, { transaction: t }); const user = await user.setApp(app, { transaction: t });
return user; return user;
} }
extraModelFilter() { extraModelFilter() {
// return {"key":"include","value":[{model:this.db.models.app,},{model:this.db.models.role,as:"Roles",attributes:["id","name"],joinTableAttributes:['created_at']}]};
return { return {
key: 'include', value: [ key: 'include', value: [
{ model: this.db.models.app }, { model: this.db.models.app },
...@@ -131,8 +129,8 @@ class UserDao extends Dao { ...@@ -131,8 +129,8 @@ class UserDao extends Dao {
} }
// 修改用户(user表)公司的唯一码 // 修改用户(user表)公司的唯一码
async putUserCompanyOnlyCode(userId, company_only_code, result) { async putUserCompanyOnlyCode(userId, companyOnlyCode, result) {
const customerObj = { companyOnlyCode: company_only_code }; const customerObj = { companyOnlyCode };
const putSqlWhere = { where: { id: userId } }; const putSqlWhere = { where: { id: userId } };
this.updateByWhere(customerObj, putSqlWhere); this.updateByWhere(customerObj, putSqlWhere);
return result; return result;
......
...@@ -54,7 +54,8 @@ class DeliverybillDao extends Dao { ...@@ -54,7 +54,8 @@ class DeliverybillDao extends Dao {
/* 根据交付单编号获取订单详情*/ /* 根据交付单编号获取订单详情*/
async findInfoByDeliverCode(qobj) { async findInfoByDeliverCode(qobj) {
const qcwhere = { delivery_code: qobj.deliverNumber }; const qcwhere = { delivery_code: qobj.deliverNumber };
return await this.findOne(qcwhere); const result = await this.findOne(qcwhere);
return result;
} }
/* 根据交付单编号更新状态信息*/ /* 根据交付单编号更新状态信息*/
...@@ -77,7 +78,8 @@ class DeliverybillDao extends Dao { ...@@ -77,7 +78,8 @@ class DeliverybillDao extends Dao {
} }
setobj.delivery_info = rs.delivery_info; setobj.delivery_info = rs.delivery_info;
} }
return await this.updateByWhere(setobj, whereobj, t); const result = await this.updateByWhere(setobj, whereobj, t);
return result;
} }
/* 更新业务员/交付员信息*/ /* 更新业务员/交付员信息*/
...@@ -110,12 +112,13 @@ class DeliverybillDao extends Dao { ...@@ -110,12 +112,13 @@ class DeliverybillDao extends Dao {
// }; // };
if (qobj.facilitatorId && qobj.facilitatorId != 'undefined') { if (qobj.facilitatorId && qobj.facilitatorId != 'undefined') {
setobj.facilitator_id = qobj.facilitatorId; setobj.facilitator_id = qobj.facilitatorId;
}; }
if (qobj.facilitatorName && qobj.facilitatorName != 'undefined') { if (qobj.facilitatorName && qobj.facilitatorName != 'undefined') {
setobj.facilitator_name = qobj.facilitatorName; setobj.facilitator_name = qobj.facilitatorName;
}; };
const whereobj = { delivery_code: qobj.deliverNumber }; const whereobj = { delivery_code: qobj.deliverNumber };
return await this.updateByWhere(setobj, whereobj, t); const result = await this.updateByWhere(setobj, whereobj, t);
return result;
} }
/* 根据交付单更新交付材料信息*/ /* 根据交付单更新交付材料信息*/
...@@ -204,7 +207,8 @@ class DeliverybillDao extends Dao { ...@@ -204,7 +207,8 @@ class DeliverybillDao extends Dao {
if (qobj.statusReason && qobj.statusReason != 'undefined') { if (qobj.statusReason && qobj.statusReason != 'undefined') {
obj.close_reason = qobj.statusReason; obj.close_reason = qobj.statusReason;
} }
return await this.create(obj, t); const result = await this.create(obj, t);
return result;
} }
} }
module.exports = DeliverybillDao; module.exports = DeliverybillDao;
...@@ -8,7 +8,8 @@ class MaterialDao extends Dao { ...@@ -8,7 +8,8 @@ class MaterialDao extends Dao {
/* 根据交付单编号获取注册材料信息详情*/ /* 根据交付单编号获取注册材料信息详情*/
async findInfoByDeliverNumber(qobj) { async findInfoByDeliverNumber(qobj) {
const qcwhere = { delivery_code: qobj.deliverNumber }; const qcwhere = { delivery_code: qobj.deliverNumber };
return await this.findOne(qcwhere); const result = await this.findOne(qcwhere);
return result;
} }
/* 根据id更新zip信息 */ /* 根据id更新zip信息 */
async updateZipById(qobj, t) { async updateZipById(qobj, t) {
...@@ -18,7 +19,8 @@ class MaterialDao extends Dao { ...@@ -18,7 +19,8 @@ class MaterialDao extends Dao {
is_download: 1, is_download: 1,
download_url: qobj.url, download_url: qobj.url,
}; };
return await this.updateByWhere(setobj, whereobj, t); const result = await this.updateByWhere(setobj, whereobj, t);
return result;
} catch (error) { } catch (error) {
console.log(`error----------${error}`); console.log(`error----------${error}`);
return error; return error;
...@@ -50,7 +52,8 @@ class MaterialDao extends Dao { ...@@ -50,7 +52,8 @@ class MaterialDao extends Dao {
if (qobj.expressInfo && qobj.expressInfo != 'undefined') { if (qobj.expressInfo && qobj.expressInfo != 'undefined') {
setobj.express_info = qobj.expressInfo; setobj.express_info = qobj.expressInfo;
} }
return await this.updateByWhere(setobj, whereobj, t); const result = await this.updateByWhere(setobj, whereobj, t);
return result;
} }
/* 插入注册材料信息*/ /* 插入注册材料信息*/
...@@ -76,7 +79,8 @@ class MaterialDao extends Dao { ...@@ -76,7 +79,8 @@ class MaterialDao extends Dao {
if (pobj.expressInfo && pobj.expressInfo != 'undefined') { if (pobj.expressInfo && pobj.expressInfo != 'undefined') {
obj.express_info = pobj.expressInfo; obj.express_info = pobj.expressInfo;
} }
return await this.create(obj, t); const result = await this.create(obj, t);
return result;
} }
} }
module.exports = MaterialDao; module.exports = MaterialDao;
...@@ -13,7 +13,7 @@ class SalesmanhisDao extends Dao { ...@@ -13,7 +13,7 @@ class SalesmanhisDao extends Dao {
flow_code: qobj.flowCode, flow_code: qobj.flowCode,
salesman_info: qobj.salesmanInfo, salesman_info: qobj.salesmanInfo,
}; };
return await this.create(obj, t); return this.create(obj, t);
} }
} }
module.exports = SalesmanhisDao; module.exports = SalesmanhisDao;
...@@ -8,7 +8,7 @@ class SchemeDao extends Dao { ...@@ -8,7 +8,7 @@ class SchemeDao extends Dao {
/* 根据商机编号获取方案信息详情*/ /* 根据商机编号获取方案信息详情*/
async findInfoByDemandCode(qobj) { async findInfoByDemandCode(qobj) {
const qcwhere = { demand_code: qobj.businessMode }; const qcwhere = { demand_code: qobj.businessMode };
return await this.findOne(qcwhere); return this.findOne(qcwhere);
} }
/* 根据方案编号更新方案状态及原因*/ /* 根据方案编号更新方案状态及原因*/
...@@ -20,7 +20,7 @@ class SchemeDao extends Dao { ...@@ -20,7 +20,7 @@ class SchemeDao extends Dao {
setobj.reject_reason = ''; setobj.reject_reason = '';
} }
const whereobj = { demand_code: qobj.businessMode }; const whereobj = { demand_code: qobj.businessMode };
return await this.updateByWhere(setobj, whereobj, t); return this.updateByWhere(setobj, whereobj, t);
} }
/* 根据商机编号更新方案详情*/ /* 根据商机编号更新方案详情*/
...@@ -35,14 +35,14 @@ class SchemeDao extends Dao { ...@@ -35,14 +35,14 @@ class SchemeDao extends Dao {
} else { } else {
setobj.reject_reason = ''; setobj.reject_reason = '';
} }
return await this.updateByWhere(setobj, whereobj, t); return this.updateByWhere(setobj, whereobj, t);
} }
/* 根据方案编号更新方案编号*/ /* 根据方案编号更新方案编号*/
async updateSchemeNumberByDemandCode(qobj, t) { async updateSchemeNumberByDemandCode(qobj, t) {
const setobj = { scheme_number: qobj.schemeNumber }; const setobj = { scheme_number: qobj.schemeNumber };
const whereobj = { demand_code: qobj.businessMode }; const whereobj = { demand_code: qobj.businessMode };
return await this.updateByWhere(setobj, whereobj, t); return this.updateByWhere(setobj, whereobj, t);
} }
/* 插入方案信息*/ /* 插入方案信息*/
...@@ -84,7 +84,7 @@ class SchemeDao extends Dao { ...@@ -84,7 +84,7 @@ class SchemeDao extends Dao {
if (qobj.clerkPhone && qobj.clerkPhone != 'undefined') { if (qobj.clerkPhone && qobj.clerkPhone != 'undefined') {
obj.salesman_phone = qobj.clerkPhone; obj.salesman_phone = qobj.clerkPhone;
} }
return await this.create(obj, t); return this.create(obj, t);
} }
} }
module.exports = SchemeDao; module.exports = SchemeDao;
...@@ -23,7 +23,7 @@ class StatuslogDao extends Dao { ...@@ -23,7 +23,7 @@ class StatuslogDao extends Dao {
if (qobj.clerkId && qobj.clerkId != 'undefined') { if (qobj.clerkId && qobj.clerkId != 'undefined') {
obj.salesman_id = qobj.clerkId; obj.salesman_id = qobj.clerkId;
} }
return await this.create(obj, t); return this.create(obj, t);
} }
} }
module.exports = StatuslogDao; module.exports = StatuslogDao;
...@@ -8,7 +8,7 @@ class MsgNoticeDao extends Dao { ...@@ -8,7 +8,7 @@ class MsgNoticeDao extends Dao {
async saveNotice(msg, t) { async saveNotice(msg, t) {
let noticeFrom = await super.findOne({ fromId: msg.senderId, toId: msg.targetId }); let noticeFrom = await super.findOne({ fromId: msg.senderId, toId: msg.targetId });
if (noticeFrom) { if (noticeFrom) {
var set = { lastMsgId: msg.id }; const set = { lastMsgId: msg.id };
if (msg.businessLicense_id) { if (msg.businessLicense_id) {
set.businessLicense_id = msg.businessLicense_id; set.businessLicense_id = msg.businessLicense_id;
} }
...@@ -28,7 +28,7 @@ class MsgNoticeDao extends Dao { ...@@ -28,7 +28,7 @@ class MsgNoticeDao extends Dao {
let noticeTo = await super.findOne({ fromId: msg.targetId, toId: msg.senderId }); let noticeTo = await super.findOne({ fromId: msg.targetId, toId: msg.senderId });
if (noticeTo) { if (noticeTo) {
var set = { lastMsgId: msg.id }; const set = { lastMsgId: msg.id };
if (msg.businessLicense_id) { if (msg.businessLicense_id) {
set.businessLicense_id = msg.businessLicense_id; set.businessLicense_id = msg.businessLicense_id;
} }
......
...@@ -11,7 +11,7 @@ class OrgService extends ServiceBase { ...@@ -11,7 +11,7 @@ class OrgService extends ServiceBase {
const uone = await this.db.models.user.findOne({ where: { org_id: orgid } }); const uone = await this.db.models.user.findOne({ where: { org_id: orgid } });
if (!uone) { if (!uone) {
// 先检查是否组织下有人员存在 // 先检查是否组织下有人员存在
return this.db.transaction(async (t) => { return this.db.transaction(async (t) => {
const inst = await self.dao.model.findById(orgid); const inst = await self.dao.model.findById(orgid);
const parentid = inst.org_id; const parentid = inst.org_id;
await inst.destroy({ force: true, transaction: t }); await inst.destroy({ force: true, transaction: t });
...@@ -22,10 +22,13 @@ class OrgService extends ServiceBase { ...@@ -22,10 +22,13 @@ class OrgService extends ServiceBase {
order: [['code', 'ASC']], order: [['code', 'ASC']],
where: { id: parentid }, transaction: t, where: { id: parentid }, transaction: t,
include: [ include: [
{ model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [ {
{ model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']] }, model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [
] }, { model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']] },
] }); ],
},
],
});
return orgparent.orgs; return orgparent.orgs;
}); });
} }
...@@ -34,14 +37,14 @@ class OrgService extends ServiceBase { ...@@ -34,14 +37,14 @@ class OrgService extends ServiceBase {
async update(p, q, req) { async update(p, q, req) {
const self = this; const self = this;
const cmkey = p.comkey;// 如果是来自租户界面的修改 const cmkey = p.comkey;// 如果是来自租户界面的修改
return this.db.transaction(async (t) => { return this.db.transaction(async (t) => {
p.isLeaf = p.isPosition; p.isLeaf = p.isPosition;
const orgupdate = await self.dao.model.findOne({ where: { id: p.id }, transaction: t }); const orgupdate = await self.dao.model.findOne({ where: { id: p.id }, transaction: t });
await self.dao.model.update(p, { where: { id: p.id }, transaction: t }); await self.dao.model.update(p, { where: { id: p.id }, transaction: t });
const usersupdate = await self.db.models.user.findAll({ where: { org_id: orgupdate.id } }); const usersupdate = await self.db.models.user.findAll({ where: { org_id: orgupdate.id } });
// 如果节点名称或岗位性质发生变化 // 如果节点名称或岗位性质发生变化
// if(p.name!=orgupdate.name || p.isMain!=orgupdate.isMain){ // if(p.name!=orgupdate.name || p.isMain!=orgupdate.isMain){
for (var ud of usersupdate) { for (const ud of usersupdate) {
ud.opath = p.orgpath; ud.opath = p.orgpath;
const n = p.orgpath.lastIndexOf('/'); const n = p.orgpath.lastIndexOf('/');
ud.ppath = p.isMain ? p.orgpath.substring(0, n) : p.orgpath; ud.ppath = p.isMain ? p.orgpath.substring(0, n) : p.orgpath;
...@@ -52,7 +55,7 @@ class OrgService extends ServiceBase { ...@@ -52,7 +55,7 @@ class OrgService extends ServiceBase {
const roles = await self.db.models.role.findAll({ where: { id: { [self.db.Op.in]: p.Roles } } }); const roles = await self.db.models.role.findAll({ where: { id: { [self.db.Op.in]: p.Roles } } });
await orgupdate.setRoles(roles, { transaction: t }); await orgupdate.setRoles(roles, { transaction: t });
// 同时要给这个岗位下的user,更新角色 todo // 同时要给这个岗位下的user,更新角色 todo
for (var ud of usersupdate) { for (const ud of usersupdate) {
await ud.setRoles(roles, { transaction: t }); await ud.setRoles(roles, { transaction: t });
} }
} }
...@@ -60,14 +63,19 @@ class OrgService extends ServiceBase { ...@@ -60,14 +63,19 @@ class OrgService extends ServiceBase {
order: [['code', 'ASC']], order: [['code', 'ASC']],
where: { id: orgupdate.org_id }, transaction: t, where: { id: orgupdate.org_id }, transaction: t,
include: [ include: [
{ model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [ {
{ model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [ model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [
{
model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [
{ model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] },
],
},
{ model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] }, { model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] },
] }, ],
{ model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] }, },
] },
{ model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] }, { model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] },
] }); ],
});
return orgparent.orgs; return orgparent.orgs;
}); });
} }
...@@ -78,10 +86,10 @@ class OrgService extends ServiceBase { ...@@ -78,10 +86,10 @@ class OrgService extends ServiceBase {
} }
return null; return null;
} }
async changePos(toorgid, uid) { async changePos(toorgid, uid) {
// 查询出当前用户,设置当前用户的orgid为修改目标 // 查询出当前用户,设置当前用户的orgid为修改目标
const self = this; const self = this;
return this.db.transaction(async (t) => { return this.db.transaction(async (t) => {
const ufind = await self.db.models.user.findById(uid); const ufind = await self.db.models.user.findById(uid);
...@@ -89,7 +97,8 @@ class OrgService extends ServiceBase { ...@@ -89,7 +97,8 @@ class OrgService extends ServiceBase {
where: { id: toorgid }, where: { id: toorgid },
include: [ include: [
{ model: self.db.models.role, as: 'roles' }, { model: self.db.models.role, as: 'roles' },
] }); ],
});
ufind.org_id = toorgid; ufind.org_id = toorgid;
ufind.opath = org.orgpath; ufind.opath = org.orgpath;
if (org.isMain) { // 如果是主岗 if (org.isMain) { // 如果是主岗
...@@ -110,9 +119,9 @@ class OrgService extends ServiceBase { ...@@ -110,9 +119,9 @@ class OrgService extends ServiceBase {
const self = this; const self = this;
const cmkey = p.comkey; const cmkey = p.comkey;
return this.db.transaction(async (t) => { return this.db.transaction(async (t) => {
if (cmkey) { if (cmkey) {
const tmpcompany = await self.db.models.company.findOne({ where: { companykey: cmkey }, transaction: t }); const tmpcompany = await self.db.models.company.findOne({ where: { companykey: cmkey }, transaction: t });
p.company_id = tmpcompany.id; p.company_id = tmpcompany.id;
} }
const roles = await self.db.models.role.findAll({ where: { id: { [self.db.Op.in]: p.Roles } } }); const roles = await self.db.models.role.findAll({ where: { id: { [self.db.Op.in]: p.Roles } } });
...@@ -126,15 +135,20 @@ class OrgService extends ServiceBase { ...@@ -126,15 +135,20 @@ class OrgService extends ServiceBase {
order: [['code', 'ASC']], order: [['code', 'ASC']],
where: { id: orgnew.org_id }, transaction: t, where: { id: orgnew.org_id }, transaction: t,
include: [ include: [
{ model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [ {
{ model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [ model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [
{
model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [
{ model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] },
],
},
{ model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] }, { model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] },
] }, ],
{ model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] }, },
] },
{ model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] }, { model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] },
] }); ],
});
return orgparent.orgs; return orgparent.orgs;
}); });
} }
...@@ -143,32 +157,42 @@ class OrgService extends ServiceBase { ...@@ -143,32 +157,42 @@ class OrgService extends ServiceBase {
order: [['code', 'ASC']], order: [['code', 'ASC']],
where: { id }, where: { id },
include: [ include: [
{ model: this.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [ {
{ model: this.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [ model: this.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [
{
model: this.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [
{ model: this.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] },
],
},
{ model: this.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] }, { model: this.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] },
] }, ],
{ model: this.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] }, },
] },
{ model: this.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] }, { model: this.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] },
] }); ],
});
return org.orgs; return org.orgs;
} }
async initOrgs(company, appid) { async initOrgs(company, appid) {
const self = this; const self = this;
return this.db.transaction(async (t) => { return this.db.transaction(async (t) => {
const org = await self.dao.model.findOne({ const org = await self.dao.model.findOne({
order: [['code', 'ASC']], order: [['code', 'ASC']],
// where:{name:company.name,company_id:company.id,app_id:appid},transaction:t, // where:{name:company.name,company_id:company.id,app_id:appid},transaction:t,
where: { name: company.name, company_id: company.id }, transaction: t, where: { name: company.name, company_id: company.id }, transaction: t,
include: [ include: [
{ model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [ {
{ model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [ model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [
{
model: self.db.models.org, as: 'orgs', order: [['code', 'ASC']], include: [
{ model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] },
],
},
{ model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] }, { model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] },
] }, ],
{ model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] }, },
] },
{ model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] }, { model: self.db.models.role, as: 'roles', attributes: ['id', 'code', 'name'] },
] }); ],
});
if (org != null) { if (org != null) {
return org; return org;
} }
......
...@@ -60,7 +60,13 @@ class UserService extends ServiceBase { ...@@ -60,7 +60,13 @@ class UserService extends ServiceBase {
// 设置默认普通角色,由于有了租户概念,所以注册时,需要知道当前租户和应用的id 才可以设置默认角色 todo // 设置默认普通角色,由于有了租户概念,所以注册时,需要知道当前租户和应用的id 才可以设置默认角色 todo
// 如果是非租户,那么按照当前应用ID是找不到指定的角色,所以是空的 // 如果是非租户,那么按照当前应用ID是找不到指定的角色,所以是空的
const roles = await self.roleDao.model.findAll({ where: { id: { [self.db.Op.in]: rolecodes }, app_id: roleappid, company_id: p.company_id }, transaction: t }); const roles = await self.roleDao.model.findAll({
where: {
id: { [self.db.Op.in]: rolecodes },
app_id: roleappid,
company_id: p.company_id,
}, transaction: t,
});
if (roles && roles.length > 0) { if (roles && roles.length > 0) {
await u.setRoles(roles, { transaction: t }); await u.setRoles(roles, { transaction: t });
} }
...@@ -180,7 +186,13 @@ class UserService extends ServiceBase { ...@@ -180,7 +186,13 @@ class UserService extends ServiceBase {
return rtn; return rtn;
} }
// 先按照用户名查续身份信息,获取key,secret, // 先按照用户名查续身份信息,获取key,secret,
const regrtn = await this.pmregister({ userName: mobile, nickName: mobile, rolecodes: p.rolecodes, company_id: p.company_id, app_id: p.app_id }); const regrtn = await this.pmregister({
userName: mobile,
nickName: mobile,
rolecodes: p.rolecodes,
company_id: p.company_id,
app_id: p.app_id,
});
const token = await this.cmakejwt(regrtn.user.jwtkey, regrtn.user.jwtsecret, null); const token = await this.cmakejwt(regrtn.user.jwtkey, regrtn.user.jwtsecret, null);
// rtn.token = token; // rtn.token = token;
// rtn.user = u; // rtn.user = u;
...@@ -276,14 +288,14 @@ class UserService extends ServiceBase { ...@@ -276,14 +288,14 @@ class UserService extends ServiceBase {
// 登录统一账号 // 登录统一账号
async clogin(uname) { // async clogin(uname) {
// 检查是否存在重名 // // 检查是否存在重名
} // }
// 按用户名查询统一用户 // // 按用户名查询统一用户
async findCUser(uname) { // async findCUser(uname) {
} // }
async resetPassword(uname, pwd) { async resetPassword(uname, pwd) {
const inpassword = this.getEncryptStr(pwd); const inpassword = this.getEncryptStr(pwd);
const self = this; const self = this;
......
...@@ -128,7 +128,6 @@ class DeliverybillService extends ServiceBase { ...@@ -128,7 +128,6 @@ class DeliverybillService extends ServiceBase {
return this.db.transaction(async (t) => { return this.db.transaction(async (t) => {
// 先按照ids查询出交付单的合计服务成本 // 先按照ids查询出交付单的合计服务成本
const d = await self.dao.customQuery('select sum(cost_price) as settleAmount from delivery_bill where id in (:idstr)', { idstr: ids }); const d = await self.dao.customQuery('select sum(cost_price) as settleAmount from delivery_bill where id in (:idstr)', { idstr: ids });
// let settleAmount=await self.dao.model.sum("cost_price",{where:{id:{[self.db.Op.In]:['40','41','42']}},transaction:t})
let { settleAmount } = d[0]; let { settleAmount } = d[0];
settleAmount = isNaN(settleAmount) ? 0 : settleAmount; settleAmount = isNaN(settleAmount) ? 0 : settleAmount;
const settlecode = await self.getBusUid('JSD'); const settlecode = await self.getBusUid('JSD');
...@@ -163,7 +162,6 @@ class DeliverybillService extends ServiceBase { ...@@ -163,7 +162,6 @@ class DeliverybillService extends ServiceBase {
return this.db.transaction(async (t) => { return this.db.transaction(async (t) => {
// 先按照ids查询出交付单的合计服务成本 // 先按照ids查询出交付单的合计服务成本
const d = await self.dao.customQuery('select sum(cost_price) as settleAmount from delivery_bill where id in (:idstr)', { idstr: ids }); const d = await self.dao.customQuery('select sum(cost_price) as settleAmount from delivery_bill where id in (:idstr)', { idstr: ids });
// let settleAmount=await self.dao.model.sum("cost_price",{where:{id:{[self.db.Op.In]:['40','41','42']}},transaction:t})
let { settleAmount } = d[0]; let { settleAmount } = d[0];
settleAmount = isNaN(settleAmount) ? 0 : settleAmount; settleAmount = isNaN(settleAmount) ? 0 : settleAmount;
const settlecode = await self.getBusUid('JSD'); const settlecode = await self.getBusUid('JSD');
...@@ -194,27 +192,40 @@ class DeliverybillService extends ServiceBase { ...@@ -194,27 +192,40 @@ class DeliverybillService extends ServiceBase {
} }
async findInfoByDeliverCode(qobj) { //* 根据交付单编号获取交付单详情*/ async findInfoByDeliverCode(qobj) { //* 根据交付单编号获取交付单详情*/
return await this.dao.findInfoByDeliverCode(qobj); const result = await this.dao.findInfoByDeliverCode(qobj);
return result;
} }
async updateStatusByDeliverCode(qobj) { //* 根据交付单编号更新交付单状态 */ async updateStatusByDeliverCode(qobj) { //* 根据交付单编号更新交付单状态 */
const self = this; const self = this;
return self.db.transaction(async t => await self.dao.updateStatusByDeliverCode(qobj, t)); return self.db.transaction(async (t) => {
const result = await self.dao.updateStatusByDeliverCode(qobj, t);
return result;
});
} }
/* 更新业务员信息*/ /* 更新业务员信息*/
async updateSalesmanInfoByDeliverCode(qobj) { async updateSalesmanInfoByDeliverCode(qobj) {
const self = this; const self = this;
return self.db.transaction(async t => await self.dao.updateSalesmanInfoByDeliverCode(qobj, t)); return self.db.transaction(async (t) => {
const result = await self.dao.updateSalesmanInfoByDeliverCode(qobj, t);
return result;
});
} }
async updateInfoByDeliverCode(qobj) { //* 更新交付单信息 */ async updateInfoByDeliverCode(qobj) { //* 更新交付单信息 */
console.log('--------------------------------------------------------------------------------------------------------------------------------------'); console.log('--------------------------------------------------------------------------------------------------------------------------------------');
const self = this; const self = this;
return self.db.transaction(async t => await self.dao.updateInfoByDeliverCode(qobj, t)); return self.db.transaction(async (t) => {
const result = await self.dao.updateInfoByDeliverCode(qobj, t);
return result;
});
} }
async insertInfo(qobj) { //* 插入交付单信息*/从队列取数据的时候用 async insertInfo(qobj) { //* 插入交付单信息*/从队列取数据的时候用
const self = this; const self = this;
return self.db.transaction(async t => await self.dao.insertInfo(qobj, t)); return self.db.transaction(async (t) => {
const result = await self.dao.insertInfo(qobj, t);
return result;
});
} }
async insertInfoall(pobj) { //* 插入交付单信息,大事务*/从队列取数据的时候用 async insertInfoall(pobj) { //* 插入交付单信息,大事务*/从队列取数据的时候用
......
...@@ -14,18 +14,24 @@ class MaterialService extends ServiceBase { ...@@ -14,18 +14,24 @@ class MaterialService extends ServiceBase {
/* 根据交付单编号获取注册材料信息详情*/ /* 根据交付单编号获取注册材料信息详情*/
async findInfoByDeliverNumber(qobj) { async findInfoByDeliverNumber(qobj) {
return await this.dao.findInfoByDeliverNumber(qobj); return this.dao.findInfoByDeliverNumber(qobj);
} }
/* 根据交付单编号更新交付单编号信息 */ /* 根据交付单编号更新交付单编号信息 */
async updateInfoByDeliverNumber(qobj) { async updateInfoByDeliverNumber(qobj) {
const self = this; const self = this;
return self.db.transaction(async t => await self.dao.updateInfoByDeliverNumber(qobj, t)); return self.db.transaction(async (t) => {
const result = await self.dao.updateInfoByDeliverNumber(qobj, t);
return result;
});
} }
/* 根据id更新zip信息 */ /* 根据id更新zip信息 */
async updateZipById(qobj) { async updateZipById(qobj) {
const self = this; const self = this;
return self.db.transaction(async t => await self.dao.updateZipById(qobj, t)); return self.db.transaction(async (t) => {
const result = await self.dao.updateZipById(qobj, t);
return result;
});
} }
/* 获取没有压缩文件的信息*/ /* 获取没有压缩文件的信息*/
...@@ -48,7 +54,10 @@ class MaterialService extends ServiceBase { ...@@ -48,7 +54,10 @@ class MaterialService extends ServiceBase {
/* 插入信息*/ /* 插入信息*/
async insertInfo(qobj) { async insertInfo(qobj) {
const self = this; const self = this;
return self.db.transaction(async t => await self.dao.insertInfo(qobj, t)); return self.db.transaction(async (t) => {
const result = await self.dao.insertInfo(qobj, t);
return result;
});
} }
} }
module.exports = MaterialService; module.exports = MaterialService;
...@@ -10,7 +10,10 @@ class SalesmanhisService extends ServiceBase { ...@@ -10,7 +10,10 @@ class SalesmanhisService extends ServiceBase {
/* 插入状态信息*/ /* 插入状态信息*/
async insertInfo(qobj) { async insertInfo(qobj) {
const self = this; const self = this;
return self.db.transaction(async t => await self.dao.insertInfo(qobj, t)); return self.db.transaction(async (t) => {
const result = await self.dao.insertInfo(qobj, t);
return result;
});
} }
} }
module.exports = SalesmanhisService; module.exports = SalesmanhisService;
...@@ -17,22 +17,34 @@ class SchemeService extends ServiceBase { ...@@ -17,22 +17,34 @@ class SchemeService extends ServiceBase {
async updateStatusByDemandCode(qobj) { // 根据商机编号号更新方案状态及原因 async updateStatusByDemandCode(qobj) { // 根据商机编号号更新方案状态及原因
const self = this; const self = this;
return self.db.transaction(async t => await self.dao.updateStatusByDemandCode(qobj, t)); return self.db.transaction(async (t) => {
const result = await self.dao.updateStatusByDemandCode(qobj, t);
return result;
});
} }
async updateInfoByDemandCode(qobj) { // 根据商机编号更新方案详情 async updateInfoByDemandCode(qobj) { // 根据商机编号更新方案详情
const self = this; const self = this;
return self.db.transaction(async t => await self.dao.updateInfoByDemandCode(qobj, t)); return self.db.transaction(async (t) => {
const result = await self.dao.updateInfoByDemandCode(qobj, t);
return result;
});
} }
async updateSchemeNumberByDemandCode(qobj) { // 根据商机编号更新方案编号 async updateSchemeNumberByDemandCode(qobj) { // 根据商机编号更新方案编号
const self = this; const self = this;
return self.db.transaction(async t => await self.dao.updateSchemeNumberByDemandCode(qobj, t)); return self.db.transaction(async (t) => {
const result = await self.dao.updateSchemeNumberByDemandCode(qobj, t);
return result;
});
} }
async insertInfo(qobj) { // 插入方案信息 async insertInfo(qobj) { // 插入方案信息
const self = this; const self = this;
const result = await self.db.transaction(async t => await self.dao.insertInfo(qobj, t)); const result = await self.db.transaction(async (t) => {
const result = await self.dao.insertInfo(qobj, t);
return result;
});
return result; return result;
} }
} }
......
...@@ -10,7 +10,10 @@ class StatusLogService extends ServiceBase { ...@@ -10,7 +10,10 @@ class StatusLogService extends ServiceBase {
/* 插入状态信息*/ /* 插入状态信息*/
async insertInfo(qobj) { async insertInfo(qobj) {
const self = this; const self = this;
return self.db.transaction(async t => await self.dao.insertInfo(qobj, t)); return self.db.transaction(async (t) => {
const result = await self.dao.insertInfo(qobj, t);
return result;
});
} }
} }
module.exports = StatusLogService; module.exports = StatusLogService;
...@@ -16,7 +16,12 @@ class RouteService extends ServiceBase { ...@@ -16,7 +16,12 @@ class RouteService extends ServiceBase {
let rtn = null; let rtn = null;
try { try {
// 添加路由 // 添加路由
const routeobj = await self.cjsonregister(RouteService.newRouteUrl(serviceName), { name: routedata.name, hosts: routedata.hosts, paths: routedata.paths, strip_path: routedata.isstrip }); const routeobj = await self.cjsonregister(RouteService.newRouteUrl(serviceName), {
name: routedata.name,
hosts: routedata.hosts,
paths: routedata.paths,
strip_path: routedata.isstrip
});
routedata.center_id = routeobj.id; routedata.center_id = routeobj.id;
rtn = await self.dao.create(routedata, t); rtn = await self.dao.create(routedata, t);
} catch (e) { } catch (e) {
......
const system = require('../../../system');
const ServiceBase = require('../../sve.base');
class MsgNoticeService extends ServiceBase {
constructor() {
super(ServiceBase.getDaoName(MsgNoticeService));
this.userDao = system.getObject('db.auth.userDao');
this.msghistoryDao = system.getObject('db.msg.msghistoryDao');
}
getApp(appkey) {
return this.cacheManager.AppCache.cacheApp(appkey);
}
async getUserList(userId) {
const list = await this.dao.model.findAll({
where: {
fromId: userId,
},
order: [
['updated_at', 'DESC'],
],
raw: true,
});
if (!list || list.length == 0) {
return [];
}
const msgIds = [];
const businessLicenseIds = [];
const userIds = [];
for (var item of list) {
msgIds.push(item.lastMsgId);
businessLicenseIds.push(item.businessLicense_id);
userIds.push(item.toId);
}
const msgMap = [];
const businessLicenseMap = [];
const userMap = [];
const unreadMap = [];
// 最后一条聊天记录
if (msgIds.length > 0) {
const msgList = await this.msghistoryDao.customQuery(`SELECT * FROM msghistory WHERE id IN (${msgIds.join(',')}) `);
msgList.forEach((item) => {
msgMap[`id${item.id}`] = item;
});
}
// 最后一次聊天关联执照
if (businessLicenseIds.length > 0) {
const licenseList = await this.businesslicenseDao.customQuery(`SELECT * FROM yz_business_license WHERE id IN (${businessLicenseIds.join(',')}) `);
const serviceTypeIds = [];
for (var item of licenseList) {
serviceTypeIds.push(item.serviceTypeOneId);
serviceTypeIds.push(item.serviceTypeTwoId);
}
if (serviceTypeIds.length > 0) {
const sql = `SELECT id, name FROM \`p_service_type\` WHERE id IN (${serviceTypeIds.join(',')}) `;
const typeList = await this.dao.customQuery(sql);
var typeMap = [];
if (typeList && typeList.length > 0) {
for (const t of typeList) {
typeMap[`type_id_${t.id}`] = t.name;
if (t.id == item.serviceTypeOneId) {
item.serviceTypeOneName = t.name;
} else if (t.id == item.serviceTypeTwoId) {
item.serviceTypeTwoName = t.name;
} else {}
}
}
}
for (var item of licenseList) {
item.serviceTypeOneName = typeMap[`type_id_${item.serviceTypeOneId}`];
item.serviceTypeTwoName = typeMap[`type_id_${item.serviceTypeTwoId}`];
}
licenseList.forEach((item) => {
businessLicenseMap[`id${item.id}`] = item;
});
}
// 聊天好友用户信息
if (userIds.length > 0) {
const userList = await this.userDao.customQuery(`SELECT * FROM p_user WHERE id IN (${userIds.join(',')}) `);
userList.forEach((item) => {
userMap[`id${item.id}`] = item;
});
}
// 未读消息数量
const unreadList = await this.userDao.customQuery(`SELECT senderId, COUNT(1) AS num FROM \`msghistory\` WHERE isRead = 0 AND targetId = ${userId} GROUP BY senderId `);
unreadList.forEach((item) => {
unreadMap[`id${item.senderId}`] = item.num;
});
const rs = [];
for (const i in list) {
var item = list[i];
item.lastMsg = msgMap[`id${item.lastMsgId}`];
item.businessLicense = businessLicenseMap[`id${item.businessLicense_id}`];
item.friend = userMap[`id${item.toId}`];
item.unreadCount = unreadMap[`id${item.toId}`] || 0;
rs.push(item);
}
return rs;
}
async countUnread(userId) {
debugger;
const unreadList = await this.userDao.customQuery(`SELECT COUNT(1) AS num FROM \`msghistory\` WHERE isRead = 0 AND targetId = ${userId}`);
let count = 0;
if (unreadList && unreadList.length > 0) {
count = unreadList[0].num || 0;
}
return count;
}
}
module.exports = MsgNoticeService;
...@@ -22,7 +22,7 @@ class ServiceBase { ...@@ -22,7 +22,7 @@ class ServiceBase {
} }
getUUID() { getUUID() {
const uuid = uuidv4(); const uuid = uuidv4();
const u = uuid.replace(/\-/g, ''); const u = uuid.replace(/-/g, '');
return u; return u;
} }
static getDaoName(ClassObj) { static getDaoName(ClassObj) {
...@@ -79,7 +79,7 @@ class ServiceBase { ...@@ -79,7 +79,7 @@ class ServiceBase {
返回20位业务订单号 返回20位业务订单号
prefix:业务前缀 prefix:业务前缀
*/ */
async getBusUid(prefix) { async getBusUid(prefix) {
prefix = (prefix || ''); prefix = (prefix || '');
if (prefix) { if (prefix) {
prefix = prefix.toUpperCase(); prefix = prefix.toUpperCase();
...@@ -97,7 +97,7 @@ class ServiceBase { ...@@ -97,7 +97,7 @@ class ServiceBase {
len:返回长度 len:返回长度
radix:参与计算的长度,最大为62 radix:参与计算的长度,最大为62
*/ */
async getUidInfo(len, radix) { async getUidInfo(len, radix) {
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');// 长度62,到yz长度为长36 const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');// 长度62,到yz长度为长36
const uuid = []; let i; const uuid = []; let i;
radix = radix || chars.length; radix = radix || chars.length;
...@@ -105,7 +105,10 @@ class ServiceBase { ...@@ -105,7 +105,10 @@ class ServiceBase {
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]; for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else { } else {
let r; let r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; uuid[23] = '-';
uuid[18] = uuid[23];
uuid[13] = uuid[18];
uuid[8] = uuid[13];
uuid[14] = '4'; uuid[14] = '4';
for (i = 0; i < 36; i++) { for (i = 0; i < 36; i++) {
if (!uuid[i]) { if (!uuid[i]) {
...@@ -132,7 +135,7 @@ class ServiceBase { ...@@ -132,7 +135,7 @@ class ServiceBase {
throw new Error(rtn.data); throw new Error(rtn.data);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
return null; return null;
} }
} }
async cget(opurl) { async cget(opurl) {
...@@ -151,11 +154,9 @@ class ServiceBase { ...@@ -151,11 +154,9 @@ class ServiceBase {
return rtn.data; return rtn.data;
} }
throw new Error(rtn.data); throw new Error(rtn.data);
return null;
} catch (e) { } catch (e) {
console.log(e); console.log(e);
return null; return null;
} }
} }
async cdel(opurl) { async cdel(opurl) {
...@@ -167,7 +168,7 @@ class ServiceBase { ...@@ -167,7 +168,7 @@ class ServiceBase {
throw new Error(rtn.data); throw new Error(rtn.data);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
return null; return null;
} }
} }
static bindPluginUrl(rname) { static bindPluginUrl(rname) {
......
...@@ -128,11 +128,11 @@ class System { ...@@ -128,11 +128,11 @@ class System {
} }
/** /**
* 请求返回成功 * 请求返回成功
* @param {*} data 操作成功返回的数据,有值为成功,无值为失败 * @param {*} data 操作成功返回的数据,有值为成功,无值为失败
* @param {*} okmsg 操作成功的描述 * @param {*} okmsg 操作成功的描述
* @param {*} req 请求头信息 * @param {*} req 请求头信息
*/ */
static getResult(data, opmsg = '操作成功', req) { static getResult(data, opmsg = '操作成功', req) {
return { return {
status: !data ? -1 : 0, status: !data ? -1 : 0,
...@@ -142,10 +142,10 @@ class System { ...@@ -142,10 +142,10 @@ class System {
}; };
} }
/** /**
* 请求返回成功 * 请求返回成功
* @param {*} data 操作成功返回的数据 * @param {*} data 操作成功返回的数据
* @param {*} okmsg 操作成功的描述 * @param {*} okmsg 操作成功的描述
*/ */
static getResultSuccess(data, okmsg = 'success') { static getResultSuccess(data, okmsg = 'success') {
return { return {
status: 0, status: 0,
...@@ -154,11 +154,11 @@ class System { ...@@ -154,11 +154,11 @@ class System {
}; };
} }
/** /**
* 请求返回失败 * 请求返回失败
* @param {*} status 操作失败状态,默认为-1 * @param {*} status 操作失败状态,默认为-1
* @param {*} errmsg 操作失败的描述,默认为fail * @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据 * @param {*} data 操作失败返回的数据
*/ */
static getResultFail(status = -1, errmsg = 'fail', data = null) { static getResultFail(status = -1, errmsg = 'fail', data = null) {
return { return {
status, status,
...@@ -167,10 +167,10 @@ class System { ...@@ -167,10 +167,10 @@ class System {
}; };
} }
/** /**
* 请求处理异常 * 请求处理异常
* @param {*} errmsg 操作失败的描述,默认为fail * @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据 * @param {*} data 操作失败返回的数据
*/ */
static getResultError(errmsg = 'fail', data = null) { static getResultError(errmsg = 'fail', data = null) {
return { return {
status: -200, status: -200,
...@@ -243,27 +243,27 @@ class System { ...@@ -243,27 +243,27 @@ class System {
const configValue = require(configPath); const configValue = require(configPath);
return configValue.config; return configValue.config;
} }
static get_client_ip(req) { static getClientIp(req) {
const ip = req.headers['x-forwarded-for'] const ip = req.headers['x-forwarded-for']
|| req.ip || req.ip
|| req.connection.remoteAddress || req.connection.remoteAddress
|| req.socket.remoteAddress || req.socket.remoteAddress
|| (req.connection.socket && req.connection.socket.remoteAddress) || ''; || (req.connection.socket && req.connection.socket.remoteAddress) || '';
const x = ip.match(/(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/); const x = ip.match(/(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/);
if (x) { if (x) {
return x[0]; return x[0];
} }
return 'localhost'; return 'localhost';
}; }
/** /**
* 记录日志信息 * 记录日志信息
* @param {*} opTitle 操作的标题 * @param {*} opTitle 操作的标题
* @param {*} params 参数 * @param {*} params 参数
* @param {*} identifyCode 业务标识 * @param {*} identifyCode 业务标识
* @param {*} resultInfo 返回结果 * @param {*} resultInfo 返回结果
* @param {*} errorInfo 错误信息 * @param {*} errorInfo 错误信息
*/ */
static execLogs(opTitle, params, identifyCode, resultInfo, errorInfo) { static execLogs(opTitle, params, identifyCode, resultInfo, errorInfo) {
const reqUrl = settings.logUrl(); const reqUrl = settings.logUrl();
let isLogData = true; let isLogData = true;
...@@ -310,9 +310,9 @@ class System { ...@@ -310,9 +310,9 @@ class System {
return cipherStr; return cipherStr;
} }
/** /**
* 解密信息 * 解密信息
* @param {*} opStr * @param {*} opStr
*/ */
static decryptStr(opStr) { static decryptStr(opStr) {
if (!opStr) { if (!opStr) {
return opStr; return opStr;
......
const moment = require('moment'); const moment = require('moment');
class DateClient { class DateClient {
constructor() {
}
betweenDay() { betweenDay() {
return [moment().startOf('day') return [moment().startOf('day')
.format('YYYY-MM-DD HH:mm:ss'), moment().endOf('day') .format('YYYY-MM-DD HH:mm:ss'), moment().endOf('day')
.format('YYYY-MM-DD HH:mm:ss')]; .format('YYYY-MM-DD HH:mm:ss')];
} }
betweenMonth() { betweenMonth() {
return [moment().startOf('month') return [moment().startOf('month')
.format('YYYY-MM-DD HH:mm:ss'), moment().endOf('month') .format('YYYY-MM-DD HH:mm:ss'), moment().endOf('month')
.format('YYYY-MM-DD HH:mm:ss')]; .format('YYYY-MM-DD HH:mm:ss')];
} }
betweenYear() { betweenYear() {
return [moment().startOf('year') return [moment().startOf('year')
.format('YYYY-MM-DD HH:mm:ss'), moment().endOf('year') .format('YYYY-MM-DD HH:mm:ss'), moment().endOf('year')
.format('YYYY-MM-DD HH:mm:ss')]; .format('YYYY-MM-DD HH:mm:ss')];
} }
betweenTime(type) { betweenTime(type) {
let times = []; let times = [];
......
...@@ -49,8 +49,8 @@ class ExcelClient { ...@@ -49,8 +49,8 @@ class ExcelClient {
wb.xlsx.writeFile(filePath).then(async (d) => { wb.xlsx.writeFile(filePath).then(async (d) => {
const rtn = await self.ossClient.upfile(fileName, filePath); const rtn = await self.ossClient.upfile(fileName, filePath);
fs.unlink(filePath, (err) => {}); fs.unlink(filePath, (err) => { });
var obj = { let obj = {
user_id: user.id || 0, user_id: user.id || 0,
userName: user.userName || '', userName: user.userName || '',
code, code,
...@@ -58,7 +58,7 @@ class ExcelClient { ...@@ -58,7 +58,7 @@ class ExcelClient {
filePath: rtn.url || '', filePath: rtn.url || '',
isDownload: false, isDownload: false,
}; };
var obj = await self.filedownloadDao.create(obj); obj = await self.filedownloadDao.create(obj);
}); });
} }
} }
......
...@@ -3,11 +3,9 @@ const settings = require('../../config/settings'); ...@@ -3,11 +3,9 @@ const settings = require('../../config/settings');
const uuidv4 = require('uuid/v4'); const uuidv4 = require('uuid/v4');
const system = require('../system'); const system = require('../system');
class LogClient { class LogClient {
constructor() {
}
getUUID() { getUUID() {
const uuid = uuidv4(); const uuid = uuidv4();
const u = uuid.replace(/\-/g, ''); const u = uuid.replace(/-/g, '');
return u; return u;
} }
async log(pobj, req, rtninfo, errinfo) { async log(pobj, req, rtninfo, errinfo) {
......
...@@ -88,7 +88,7 @@ class RedisClient { ...@@ -88,7 +88,7 @@ class RedisClient {
} }
if (self.chatserver) { if (self.chatserver) {
if (channel != 'task') { if (channel != 'task') {
var message = JSON.parse(message); const message = JSON.parse(message);
console.log(message, '------------------------------------------ publish message'); console.log(message, '------------------------------------------ publish message');
if (channel == 'brc') { // 如果是广播频道,则发送广播到客户端 if (channel == 'brc') { // 如果是广播频道,则发送广播到客户端
self.chatserver.server.emit('brc', message); self.chatserver.server.emit('brc', message);
...@@ -248,7 +248,8 @@ module.exports = RedisClient; ...@@ -248,7 +248,8 @@ module.exports = RedisClient;
// client.sismember("h","ok").then(function(r){ // client.sismember("h","ok").then(function(r){
// console.log(r); // console.log(r);
// }); // });
// console.dir(client);ti.exec( callback )回调函数参数err:返回null或者Array,出错则返回对应命令序列链中发生错误的错误信息,这个数组中最后一个元素是源自exec本身的一个EXECABORT类型的错误 // console.dir(client);ti.exec( callback )
// 回调函数参数err:返回null或者Array,出错则返回对应命令序列链中发生错误的错误信息,这个数组中最后一个元素是源自exec本身的一个EXECABORT类型的错误
// r.set("hello","oooo").then(function(result){ // r.set("hello","oooo").then(function(result){
// console.log(result); // console.log(result);
// }); // });
......
...@@ -38,7 +38,7 @@ class SmsClient { ...@@ -38,7 +38,7 @@ class SmsClient {
}; };
return this.restClient.execPost(txtObj, this.smsTeml); return this.restClient.execPost(txtObj, this.smsTeml);
} }
async getUidStr(len, radix) { async getUidStr(len, radix) {
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
const uuid = []; let i; const uuid = []; let i;
radix = radix || chars.length; radix = radix || chars.length;
...@@ -46,7 +46,10 @@ class SmsClient { ...@@ -46,7 +46,10 @@ class SmsClient {
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]; for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else { } else {
let r; let r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; uuid[23] = '-';
uuid[18] = uuid[23];
uuid[13] = uuid[18];
uuid[8] = uuid[13];
uuid[14] = '4'; uuid[14] = '4';
for (i = 0; i < 36; i++) { for (i = 0; i < 36; i++) {
if (!uuid[i]) { if (!uuid[i]) {
......
...@@ -21,8 +21,8 @@ module.exports = function (app) { ...@@ -21,8 +21,8 @@ module.exports = function (app) {
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true })); app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
routes(app);// 初始化路由 routes(app);// 初始化路由
app.use(express.static(path.join(settings.basepath, '/app/front/entry/public'))); app.use(express.static(path.join(settings.basepath, '/app/front/entry/public')));
// development only // development only
if ('development' == app.get('env')) { if (app.get('env') === 'development') {
app.use(errorHandler()); app.use(errorHandler());
} else { } else {
app.use((err, req, res) => { app.use((err, req, res) => {
......
...@@ -6,7 +6,7 @@ module.exports = function (app) { ...@@ -6,7 +6,7 @@ module.exports = function (app) {
const methodName = req.params.method; const methodName = req.params.method;
const { gname } = req.params; const { gname } = req.params;
classPath = `${gname}.${classPath}`; classPath = `${gname}.${classPath}`;
const tClientIp = System.get_client_ip(req); const tClientIp = System.getClientIp(req);
req.clientIp = tClientIp; req.clientIp = tClientIp;
req.uagent = req.headers['user-agent']; req.uagent = req.headers['user-agent'];
// req.classname=classPath; // req.classname=classPath;
...@@ -21,10 +21,10 @@ module.exports = function (app) { ...@@ -21,10 +21,10 @@ module.exports = function (app) {
const invokeObj = System.getObject(`api.${classPath}`); const invokeObj = System.getObject(`api.${classPath}`);
if (invokeObj.doexec) { if (invokeObj.doexec) {
p = invokeObj.doexec.apply(invokeObj, params); p = invokeObj.doexec.apply(invokeObj, params);
p.then((r) => {
res.end(JSON.stringify(r));
});
} }
p.then((r) => {
res.end(JSON.stringify(r));
});
}); });
app.post('/api/:gname/:qname/:method', (req, res) => { app.post('/api/:gname/:qname/:method', (req, res) => {
let classPath = req.params.qname; let classPath = req.params.qname;
...@@ -34,7 +34,7 @@ module.exports = function (app) { ...@@ -34,7 +34,7 @@ module.exports = function (app) {
classPath = `${gname}.${classPath}`; classPath = `${gname}.${classPath}`;
console.log('===================='); console.log('====================');
console.log(classPath); console.log(classPath);
const tClientIp = System.get_client_ip(req); const tClientIp = System.getClientIp(req);
req.clientIp = tClientIp; req.clientIp = tClientIp;
req.uagent = req.headers['user-agent']; req.uagent = req.headers['user-agent'];
// req.classname=classPath; // req.classname=classPath;
...@@ -48,9 +48,9 @@ module.exports = function (app) { ...@@ -48,9 +48,9 @@ module.exports = function (app) {
const invokeObj = System.getObject(`api.${classPath}`); const invokeObj = System.getObject(`api.${classPath}`);
if (invokeObj.doexec) { if (invokeObj.doexec) {
p = invokeObj.doexec.apply(invokeObj, params); p = invokeObj.doexec.apply(invokeObj, params);
p.then((r) => {
res.end(JSON.stringify(r));
});
} }
p.then((r) => {
res.end(JSON.stringify(r));
});
}); });
}; };
...@@ -16,10 +16,10 @@ module.exports = function (app) { ...@@ -16,10 +16,10 @@ module.exports = function (app) {
const invokeObj = system.getObject(`web.${classPath}`); const invokeObj = system.getObject(`web.${classPath}`);
if (invokeObj.doexec) { if (invokeObj.doexec) {
p = invokeObj.doexec.apply(invokeObj, params); p = invokeObj.doexec.apply(invokeObj, params);
p.then((r) => {
res.end(JSON.stringify(r));
});
} }
p.then((r) => {
res.end(JSON.stringify(r));
});
}); });
app.post('/web/:gname/:qname/:method', (req, res) => { app.post('/web/:gname/:qname/:method', (req, res) => {
req.codepath = req.headers.codepath; req.codepath = req.headers.codepath;
...@@ -28,7 +28,7 @@ module.exports = function (app) { ...@@ -28,7 +28,7 @@ module.exports = function (app) {
const { gname } = req.params; const { gname } = req.params;
const params = []; const params = [];
classPath = `${gname}.${classPath}`; classPath = `${gname}.${classPath}`;
const tClientIp = system.get_client_ip(req); const tClientIp = system.getClientIp(req);
req.body.clientIp = tClientIp; req.body.clientIp = tClientIp;
req.body.agent = req.headers['user-agent']; req.body.agent = req.headers['user-agent'];
req.body.classname = classPath; req.body.classname = classPath;
...@@ -40,9 +40,9 @@ module.exports = function (app) { ...@@ -40,9 +40,9 @@ module.exports = function (app) {
const invokeObj = system.getObject(`web.${classPath}`); const invokeObj = system.getObject(`web.${classPath}`);
if (invokeObj.doexec) { if (invokeObj.doexec) {
p = invokeObj.doexec.apply(invokeObj, params); p = invokeObj.doexec.apply(invokeObj, params);
p.then((r) => {
res.end(JSON.stringify(r));
});
} }
p.then((r) => {
res.end(JSON.stringify(r));
});
}); });
}; };
const Server = require('socket.io');
const system = require('../base/system');
const redisClient = system.getObject('util.redisClient');
const notifyCtl = system.getObject('web.socketNotifyCtl');
const msgHistoryService = system.getObject('service.msghistorySve');
class MsgHandler {
constructor(server, client) {
this.server = server;
this.client = client;
this.init();
}
notifyClient(ukchannel, msg) {
const msgH = { msgType: 'system', sender: 's¥s¥s¥s', target: msg.to, content: msg.content };
msgHistoryService.create(msgH).then((m) => {
redisClient.publish(ukchannel, JSON.stringify(msg));
})
.catch((e) => {
console.log(e);
});
}
init() {
const self = this;
// 转发通信消息
this.client.on('chatmsg', (msg) => {
const { from } = msg;
const { to } = msg;
const msgContent = msg.content;
const arrs = to.split('¥');
const tochannel = `${arrs[0]}${arrs[1]}`;
// 发布消息
// 持久化消息
const msgH = { msgType: 'single', sender: msg.from, target: msg.to, content: msg.content };
msgHistoryService.create(msgH).then((m) => {
redisClient.publish(tochannel, JSON.stringify(msg));
})
.catch((e) => {
console.log(e);
});
// self.server.users[to].emit("chatmsg",msg);
});
// 响应消息处理
this.client.on('replymsg', (msg, fn) => {
let p = null;
const invokeObj = system.getObject(`web.${msg.pkgname}.${msg.cls}`);
if (invokeObj[msg.method]) {
p = invokeObj[msg.method].apply(invokeObj, [msg.data]);
}
p.then((r) => {
fn(r);
}).then(() => {
console.log('call success');
})
.catch((err) => {
console.log(err);
});
});
}
}
class SocketServer {
constructor(httpServer) {
this.server = Server(httpServer, {
serveClient: false,
});
this.users = {};
this.init();
this.onlines = 0;
}
init() {
const self = this;
// 挂载到web应用的控制器
notifyCtl.setSocketServer(self);
// 订阅广播频道
redisClient.subscribe('brc', self);
// 中间件可以在链接事件发出前调用一次
this.server.use((socket, next) => {
next();
});
this.server.on('connection', (client) => {
console.log('connection.....socket');
// 链接登录事件
client.on('login', (data) => {
console.log('login...........................................................success');
console.log(data);
console.log(client.remoteAddress);
const uk = `${data.appid}${data.id}`;
client.uk = uk;
client.uid = data.id;
client.username = data.nickName;
client.appname = data.appname;
client.appkey = data.appkey;
client.sex = data.sex;
client.imgUrl = data.imgUrl;
self.users[uk] = new MsgHandler(self, client);
// 订阅uk私人频道
const ss = redisClient.subscribe(uk, self);
// 加入redisClient列表
redisClient.sadd(`${'onlineset' + '¥'}${data.appkey}`, [`${uk}${data.nickName}${data.imgUrl}`]).then((n) => {
// 当前在线
self.onlines = n;
redisClient.publish('brc', JSON.stringify({ type: 'online', content: n }));
});
});
// 链接断开事件
client.on('disconnect', async (r) => {
console.log('connection.........................................dismiss.............');
if (client.uk) {
await redisClient.srem(`${'onlineset' + '¥'}${client.appkey}`, `${client.uk}${client.username}${client.imgUrl}`);
await redisClient.publish('brc', JSON.stringify({ type: 'online', content: (self.onlines--) }));
delete self.users[client.uk];
redisClient.unsubscribe(client.uk);
// redisClient.unsubscribe("brc");
console.log(`${client.uk}${client.username}${client.imgUrl}`);
}
});
});
}
}
module.exports = SocketServer;
var fs = require('fs'); const fs = require('fs');
// function to encode file data to base64 encoded string // function to encode file data to base64 encoded string
function base64_encode(file) { function base64Encode(file) {
// read binary data // read binary data
var bitmap = fs.readFileSync("./imgs/sp.png"); const bitmap = fs.readFileSync('./imgs/sp.png');
// convert binary data to base64 encoded string // convert binary data to base64 encoded string
var bf=Buffer.alloc(bitmap.length,bitmap); const bf = Buffer.alloc(bitmap.length, bitmap);
return bf.toString('base64'); return bf.toString('base64');
} }
// function to create file from base64 encoded string // function to create file from base64 encoded string
function base64_decode(base64str, file) { function base64Decode(base64str, file) {
// create buffer object from base64 encoded string, it is important to tell the constructor that the string is base64 encoded // create buffer object from base64 encoded string,
var bitmap = new Buffer(base64str, 'base64'); // it is important to tell the constructor that the string is base64 encoded
// write buffer to file const bitmap = new Buffer(base64str, 'base64');
fs.writeFileSync(file, bitmap); // write buffer to file
console.log('******** File created from base64 encoded string ********'); fs.writeFileSync(file, bitmap);
console.log('******** File created from base64 encoded string ********');
} }
function getDataUrl(filepath){ function getDataUrl(filepath) {
var str=base64_encode(filepath); const str = base64Encode(filepath);
var mime=""; let mime = '';
if(filepath.indexOf("png")>=0){ if (filepath.indexOf('png') >= 0) {
mime="image/png"; mime = 'image/png';
} }
if(filepath.indexOf("jpg")>=0 || filepath.indexOf("jpeg")>=0){ if (filepath.indexOf('jpg') >= 0 || filepath.indexOf('jpeg') >= 0) {
mime="image/jpg"; mime = 'image/jpg';
} }
if(filepath.indexOf("gif")>=0){ if (filepath.indexOf('gif') >= 0) {
mime="image/gif"; mime = 'image/gif';
} }
var dataurl=`data:${mime};base64,`+str; const dataurl = `data:${mime};base64,${str}`;
return dataurl; return dataurl;
} }
var str=getDataUrl("./imgs/sp.png");
console.log(str);
\ No newline at end of file
var gulp = require('gulp');
const fs = require('fs');
const tap = require('gulp-tap');
const minimist = require('minimist');
const merge = require('merge-stream');
const rename = require('gulp-rename');
const del = require('del');
const concat = require('gulp-concat');
const gulpif = require('gulp-if');
const knownOptions = {
string: 'name',
string: 'bizfile',
default: { name: process.env.NODE_ENV || 'Test' },
};
const options = minimist(process.argv.slice(2), knownOptions);
const { name } = options;
const { bizfile } = options;
const BUILD_PATH = './extra/build';
const DEST_PATH = './extra/dest';
const CTL_PATH = './app/base/controller/impl';
const SERVICE_PATH = './app/base/service/impl';
const DAO_PATH = './app/base/db/impl';
const PAGE_PATH = './app/front/vues/pages';
const VUECOM_PATH = './app/front/vues';
const CSS_PATH = './app/front/entry/public/css';
const IMG_PATH = './extra/imgs';
const DEST_IMGPATH = './app/front/entry/public/imgs';
const METABIZ_PATH = './app/base/db/metadata/bizs/wx76a324c5d201d1a4';
gulp.task('makefile', (done) => {
// 将你的默认的任务代码放在这
del('./extra/dest/*');
const tmpName = name.toLowerCase();
const fstream = gulp.src('./extra/build/*.js')
.pipe(tap((file) => {
const sfile = file.contents.toString('utf-8');
const rpstr = sfile.replace(/\$\{Name\}/g, name);
file.contents = new Buffer(rpstr, 'utf-8');
}))
.pipe(rename((path) => {
path.basename = path.basename.replace('templ', tmpName);
}))
.pipe(gulp.dest('./extra/dest'));
return fstream;
// var pageStream=gulp.src("./extra/build/page/**/*").pipe(
// gulp.dest("./extra/dest")
// );
// return merge(fstream, pageStream);
});
gulp.task('page', (cbk) => {
const tmpName = name.toLowerCase();
return gulp.src('./extra/build/page/templPage/*.*')
.pipe(rename((path) => {
path.basename = path.basename.replace('templ', tmpName);
}))
.pipe(tap((file) => {
const sfile = file.contents.toString();
const rpstr = sfile.replace(/\$\{COMNAME\}/g, `gsb_${tmpName}`);
file.contents = new Buffer(rpstr, 'utf-8');
}))
.pipe(gulp.dest(`./extra/dest/${tmpName}/`));
});
gulp.task('cpctl', (cbk) => {
const tmpName = name.toLowerCase();
return gulp.src(`./extra/dest/${tmpName}Ctl.js`).pipe(rename((path) => {
path.basename = path.basename.substring(0, 1).toLowerCase() + path.basename.substring(1);
}))
.pipe(gulp.dest(CTL_PATH));
});
gulp.task('cpsve', (cbk) => {
const tmpName = name.toLowerCase();
return gulp.src(`./extra/dest/${tmpName}Sve.js`).pipe(rename((path) => {
path.basename = path.basename.substring(0, 1).toLowerCase() + path.basename.substring(1);
}))
.pipe(gulp.dest(SERVICE_PATH));
});
gulp.task('cpdao', (cbk) => {
const tmpName = name.toLowerCase();
return gulp.src(`./extra/dest/${tmpName}Dao.js`).pipe(rename((path) => {
path.basename = path.basename.substring(0, 1).toLowerCase() + path.basename.substring(1);
}))
.pipe(gulp.dest(DAO_PATH));
});
gulp.task('cppage', (cbk) => {
const tmpName = name.toLowerCase();
return gulp.src(`./extra/dest/${tmpName}/*.*`).pipe(gulp.dest(`${PAGE_PATH}/${tmpName}/`));
});
gulp.task('cpbizfile', cbk => gulp.src('./extra/build/page/meta.js').pipe(rename((path) => {
if (bizfile) {
path.basename = bizfile;
} else {
path.basename = name;
}
}))
.pipe(gulp.dest(`${METABIZ_PATH}/`)));
gulp.task('simple', ['page', 'cppage', 'cpbizfile'], (done) => {
done();
});
gulp.task('all', ['makefile', 'page', 'cpctl', 'cpsve', 'cpdao', 'cppage', 'cpbizfile'], (done) => {
done();
});
const minifycss = require('gulp-minify-css');
gulp.task('pagecss', (cbk) => {
function defaultcondition(file) {
if (file.path.indexOf('spring') >= 0) {
return false;
} if (file.path.indexOf('summer') >= 0) {
return false;
} if (file.path.indexOf('autumn') >= 0) {
return false;
} if (file.path.indexOf('winter') >= 0) {
return false;
}
return true;
}
return gulp.src(`${VUECOM_PATH}/**/*/*.css`).pipe(gulpif(defaultcondition, concat('pagecom.css')))
.pipe(minifycss())
.pipe(gulp.dest(`${CSS_PATH}/`));
});
gulp.task('springcss', (cbk) => {
function springcondition(file) {
if (file.path.indexOf('spring') >= 0) {
return true;
}
return false;
}
return gulp.src(`${VUECOM_PATH}/**/*/*.css`).pipe(gulpif(springcondition, concat('spring.css')))
.pipe(minifycss())
.pipe(gulp.dest(`${CSS_PATH}/`));
});
gulp.task('summercss', (cbk) => {
function summercondition(file) {
if (file.path.indexOf('summer') >= 0) {
return true;
}
return false;
}
return gulp.src(`${VUECOM_PATH}/**/*/*.css`).pipe(gulpif(summercondition, concat('summer.css')))
.pipe(minifycss())
.pipe(gulp.dest(`${CSS_PATH}/`));
});
gulp.task('autumncss', (cbk) => {
function autumncondition(file) {
if (file.path.indexOf('autumn') >= 0) {
return true;
}
return false;
}
return gulp.src(`${VUECOM_PATH}/**/*/*.css`).pipe(gulpif(autumncondition, concat('autumn.css')))
.pipe(minifycss())
.pipe(gulp.dest(`${CSS_PATH}/`));
});
gulp.task('wintercss', (cbk) => {
function wintercondition(file) {
if (file.path.indexOf('winter') >= 0) {
return true;
}
return false;
}
return gulp.src(`${VUECOM_PATH}/**/*/*.css`).pipe(gulpif(wintercondition, concat('winter.css')))
.pipe(minifycss())
.pipe(gulp.dest(`${CSS_PATH}/`));
});
gulp.task('1', (cbk) => {
function mobilecondition(file) {
if (file.path.indexOf('mobile') >= 0) {
return true;
}
return false;
}
return gulp.src(`${VUECOM_PATH}/**/*/*.css`).pipe(gulpif(mobilecondition, concat('mobile.css')))
.pipe(minifycss())
.pipe(gulp.dest(`${CSS_PATH}/`));
});
gulp.task('allcss', ['pagecss', 'springcss', 'summercss', 'autumncss', 'wintercss'], (done) => {
done();
});
gulp.task('watch', () => {
gulp.watch(`${VUECOM_PATH}/**/*/*.css`, gulp.series(['allcss']));
});
gulp.task('basehandle', cbk => gulp.src(`${VUECOM_PATH}/base/**/*.vue`).
pipe(tap((file) => {
file.contents = new Buffer(require(file.path).replace(/\n/g, ''), 'utf-8');
}))
.pipe(gulp.dest(`${VUECOM_PATH}/allie/base/`)));
var gulp = require('gulp');
const imagemin = require('gulp-imagemin');
pngquant = require('imagemin-pngquant'),
gulp.task('testimg', () => {
del('./extra/testimgs/*');
return gulp.src(`${IMG_PATH}/**/*.{png,jpg,gif,ico}`)
.pipe(imagemin({
optimizationLevel: 1, // 类型:Number 默认:3 取值范围:0-7(优化等级)
progressive: true, // 类型:Boolean 默认:false 无损压缩jpg图片
interlaced: true, // 类型:Boolean 默认:false 隔行扫描gif进行渲染
multipass: true, // 类型:Boolean 默认:false 多次优化svg直到完全优化
use: [pngquant({
quality: [0.3],
})],
}))
// .pipe(gulp.dest(DEST_IMGPATH));
.pipe(gulp.dest('./extra/testimgs/'));
});
var http = require('http'); const http = require('http');
var express = require('express'); const express = require('express');
var app = express(); const app = express();
var setttings=require("./app/config/settings"); const setttings = require('./app/config/settings');
var environment = require('./app/config/environment'); const environment = require('./app/config/environment');
// var SocketServer=require("./app/config/socket.server"); // var SocketServer=require("./app/config/socket.server");
//const cluster = require('cluster'); // const cluster = require('cluster');
//const numCPUs = require('os').cpus().length; // const numCPUs = require('os').cpus().length;
// all environments // all environments
environment(app);//初始化环境 environment(app);// 初始化环境
// 错误处理中间件应当在路由加载之后才能加载 // 错误处理中间件应当在路由加载之后才能加载
// if (cluster.isMaster) { // if (cluster.isMaster) {
// console.log(`Master ${process.pid} is running`); // console.log(`Master ${process.pid} is running`);
...@@ -26,9 +26,9 @@ environment(app);//初始化环境 ...@@ -26,9 +26,9 @@ environment(app);//初始化环境
// console.log('Express server listening on port ' + app.get('port')); // console.log('Express server listening on port ' + app.get('port'));
// }); // });
// } // }
var server = http.createServer(app); const server = http.createServer(app);
//var socketServer = new SocketServer(server); // var socketServer = new SocketServer(server);
server.listen(setttings.port, function(){ server.listen(setttings.port, () => {
console.log('Express server listening on port ' + app.get('port')); console.log(`Express server listening on port ${app.get('port')}`);
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment