Commit 4de7ea92 by Sxy

fix: 代码规范

parent 386e8673
......@@ -34,19 +34,18 @@ class OSSAPI extends APIBase {
};
return system.getResult(data);
};
}
async upfile(srckey, dest) {
const oss = System.getObject('util.ossClient');
const result = await oss.upfile(srckey, `/tmp/${dest}`);
return result;
};
}
async downfile(srckey) {
const oss = System.getObject('util.ossClient');
var downfile = await oss.downfile(srckey).then(() => {
downfile = `/tmp/${srckey}`;
return downfile;
let downfile = await oss.downfile(srckey).then(() => {
return `/tmp/${srckey}`;
});
return downfile;
};
}
}
module.exports = OSSAPI;
......@@ -47,7 +47,6 @@ class CtlBase {
password: custtags ? custtags[lastindex].split('_')[1] : null,
username: req.headers['x-consumer-username'],
userid: req.headers['x-consumer-custom-id'],
username: req.headers['x-consumer-username'],
credid: req.headers['x-credential-identifier'],
regrole: req.headers.xregrole,
bizpath: req.headers.xbizpath,
......
......@@ -27,9 +27,6 @@ class UserCtl extends CtlBase {
// let v = await this.smsS.sendVCode(mobile);
// return system.getResult({ vcodestr: v });
// }
async exit(pobj, qobj, req) {
}
// 应用的自由用户注册,无需验证,需要前端头设置公司KEY
async pmregisterByFreeUser(p, q, req) {
// 检查是否有用户名和密码
......
......@@ -12,15 +12,18 @@ class CachSearchesCtl extends CtlBase {
async findAndCountAll(pobj, gobj, req) {
pobj.opCacheUrl = req.session.app.opCacheUrl;
pobj.appid = req.appid;
return await this.service.findAndCountAllCache(pobj);
let result = await this.service.findAndCountAllCache(pobj);
return result;
}
async delCache(queryobj, qobj, req) {
const param = { key: queryobj.key, appid: req.appid, opCacheUrl: req.session.app.opCacheUrl };
return await this.service.delCache(param);
let result = await this.service.delCache(param);
return result;
}
async clearAllCache(queryobj, qobj, req) {
const param = { appid: req.appid, opCacheUrl: req.session.app.opCacheUrl };
return await this.service.clearAllCache(param);
let result = await this.service.clearAllCache(param);
return result;
}
}
module.exports = CachSearchesCtl;
......@@ -40,7 +40,7 @@ class OplogCtl extends CtlBase {
返回20位业务订单号
prefix:业务前缀
*/
async getBusUid_Ctl(prefix) {
async getBusUidCtl(prefix) {
prefix = (prefix || '');
if (prefix) {
prefix = prefix.toUpperCase();
......@@ -58,7 +58,7 @@ prefix:业务前缀
len:返回长度
radix:参与计算的长度,最大为62
*/
async getUidInfo_Ctl(len, radix) {
async getUidInfoCtl(len, radix) {
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');// 长度62,到yz长度为长36
const uuid = []; let i;
radix = radix || chars.length;
......@@ -66,7 +66,10 @@ prefix:业务前缀
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else {
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';
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
......
const system = require('../../../system');
const settings = require('../../../../config/settings');
class SocketNotifyCtl {
constructor() {
}
setSocketServer(s) {
this.socketServer = s;
}
......
......@@ -38,12 +38,12 @@ class UploadCtl extends CtlBase {
};
return data;
};
}
async upfile(srckey, dest) {
const oss = system.getObject('util.ossClient');
const result = await oss.upfile(srckey, `/tmp/${dest}`);
return result;
};
}
async downfile(srckey) {
const oss = system.getObject('util.ossClient');
var downfile = await oss.downfile(srckey).then(() => {
......@@ -51,7 +51,7 @@ class UploadCtl extends CtlBase {
return downfile;
});
return downfile;
};
}
async pdf2html(obj) {
const srckey = obj.key;
const downfile = await this.downfile(srckey);
......@@ -62,10 +62,10 @@ class UploadCtl extends CtlBase {
fs.unlink(`/tmp/${srckey}`);
const result = await this.upfile(`${srckey.split('.pdf')[0]}.html`, `${srckey.split('.pdf')[0]}.html`);
return result.url;
};
}
async insertToFile(path) {
const cmd = `${this.cmdInsertToFilePattern} ${path}`;
return await this.restS.exec(cmd);
};
}
}
module.exports = UploadCtl;
......@@ -24,7 +24,14 @@ class MaterialCtl extends CtlBase {
const type = item.deliver.product_code;
const { proposerInfo, otherMaterialsInfo, implementationPlanInfo, safetyInfo, shareholderData } = item;
const { businessLicense, businessInformation, principalInfo, contactInfo } = proposerInfo;
const { webApp, targetUser, profitableWay, specialApproval, serviceProjectEdi, serviceProjectIcp } = implementationPlanInfo;
const {
webApp,
targetUser,
profitableWay,
specialApproval,
serviceProjectEdi,
serviceProjectIcp
} = implementationPlanInfo;
// 1. id ,type
// 2.注册认证
......@@ -115,18 +122,20 @@ class MaterialCtl extends CtlBase {
};
// 专项审批项目 ICP
if (type === 'ICP') {
implementationPlanData.files.push(...specialApproval.filter(item => (!!(item.file && item.file.url))).map(item => ({
file: item.file,
title: `专项审批项-${item.title}`,
})));
implementationPlanData.files.push(
...specialApproval.filter(item => (!!(item.file && item.file.url))).map(item => ({
file: item.file,
title: `专项审批项-${item.title}`,
})));
}
implementationPlanData.files.push(...otherMaterialsInfo.filter(item => item.title === '域名证书'));
if (type === 'EDI') {
implementationPlanData.files.push(...serviceProjectEdi.filter(item => (!!(item.file && item.file.url))).map(item => ({
title: item.title,
file: item.file,
})));
implementationPlanData.files.push(
...serviceProjectEdi.filter(item => (!!(item.file && item.file.url))).map(item => ({
title: item.title,
file: item.file,
})));
}
// 4. 增值电信申请表
......
......@@ -24,7 +24,8 @@ class VCodeCache extends CacheBase {
const vcode = await this.smsUtil.getUidStr(6, 10);
if (!tmplCode && !signName) {
this.smsUtil.sendMsg(mobile, vcode);
} // tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息,二者没有传递则用默认的发送验证码
}
// tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息,二者没有传递则用默认的发送验证码
else {
this.smsUtil.aliSendMsg(mobile, tmplCode, signName, JSON.stringify({ code: vcode }));
}
......
......@@ -5,7 +5,7 @@ class RoleDao extends Dao {
super(Dao.getModelName(RoleDao));
}
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;
}
extraWhere(obj, w, qc, linkAttrs) {
......@@ -38,11 +38,12 @@ class RoleDao extends Dao {
const self = this;
const u2 = await this.preCreate(u);
if (t) {
var role = await this.model.create(u2, { transaction: t });
let role = await this.model.create(u2, { transaction: t });
return role;
} else {
let role = await this.model.create(u2);
return role;
}
var role = await this.model.create(u2);
return role;
}
}
module.exports = RoleDao;
......@@ -9,11 +9,11 @@ class UserDao extends Dao {
return this.model.findOne({
where: { id: userid },
include: [{ model: self.db.models.account, attributes: ['id', 'isSuper', 'referrerOnlyCode'] },
{
model: self.db.models.role, as: 'Roles', attributes: ['id', 'code'], include: [
{ model: self.db.models.product, as: 'Products', attributes: ['id', 'code'] },
],
},
{
model: self.db.models.role, as: 'Roles', attributes: ['id', 'code'], include: [
{ model: self.db.models.product, as: 'Products', attributes: ['id', 'code'] },
],
},
],
});
}
......@@ -22,14 +22,12 @@ class UserDao extends Dao {
const tUser = await this.model.findOne({
where: { userName: username, app_id: app.id },
include: [{ model: this.db.models.app, raw: true },
// {model:this.db.models.partnerinfo,attributes:["id","user_id","app_id","userName","applyType","applyName","workPic","tagInfo","mobile","tel","applyProvince","applyCity",
// "applyArea","applyAddr","identityCardPic","identityCard","businessLicensePic","businessLicenseNum","entName","cardNo","realName"]},
{ model: this.db.models.account, attributes: ['id', 'isSuper', 'referrerOnlyCode'], raw: true },
{
model: this.db.models.role, as: 'Roles', attributes: ['id', 'code'], include: [
{ model: this.db.models.product, as: 'Products', attributes: ['id', 'code'], raw: true },
],
},
{ model: this.db.models.account, attributes: ['id', 'isSuper', 'referrerOnlyCode'], raw: true },
{
model: this.db.models.role, as: 'Roles', attributes: ['id', 'code'], include: [
{ model: this.db.models.product, as: 'Products', attributes: ['id', 'code'], raw: true },
],
},
],
}, { transaction: t });
// if(tUser!=null){
......@@ -43,35 +41,30 @@ class UserDao extends Dao {
let tUser = await this.model.findOne({
where: { openId: popenid },
include: [{ model: this.db.models.app, raw: true },
// {model:this.db.models.partnerinfo,attributes:["id","user_id","app_id","userName","applyType","applyName","workPic","tagInfo","mobile","tel","applyProvince","applyCity",
// "applyArea","applyAddr","identityCardPic","identityCard","businessLicensePic","businessLicenseNum","entName","cardNo","realName"]},
{ model: this.db.models.account, attributes: ['id', 'isSuper', 'referrerOnlyCode'], raw: true },
{
model: this.db.models.role, as: 'Roles', attributes: ['id', 'code'], include: [
{ model: this.db.models.product, as: 'Products', attributes: ['id', 'code'], raw: true },
],
},
{ model: this.db.models.account, attributes: ['id', 'isSuper', 'referrerOnlyCode'], raw: true },
{
model: this.db.models.role, as: 'Roles', attributes: ['id', 'code'], include: [
{ model: this.db.models.product, as: 'Products', attributes: ['id', 'code'], raw: true },
],
},
],
}, { transaction: t });
if (tUser != null) {
tUser = tUser.get({ plain: true });
tUser.partnerinfo = await this.partnerinfoDao.model.findOne({ where: { onlyCode: tUser.onlyCode }, raw: true });
}
// console.log("tUser.partnerinfo...................................>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>999sy");
// console.log(tUser);
return tUser;
}
async setAccount(user, account, t) {
var user = await user.setAccount(account, { transaction: t });
user = await user.setAccount(account, { transaction: t });
return user;
}
async setApp(user, app, t) {
// 按照APPId,获取app对象
var user = await user.setApp(app, { transaction: t });
user = await user.setApp(app, { transaction: t });
return user;
}
extraModelFilter() {
// return {"key":"include","value":[{model:this.db.models.app,},{model:this.db.models.role,as:"Roles",attributes:["id","name"],joinTableAttributes:['created_at']}]};
return { key: 'include', value: [{ model: this.db.models.app }, { model: this.db.models.role, as: 'Roles', attributes: ['id', 'name'] }] };
}
extraWhere(obj, w, qc, linkAttrs) {
......@@ -129,8 +122,8 @@ class UserDao extends Dao {
}
// 修改用户(user表)公司的唯一码
async putUserCompanyOnlyCode(userId, company_only_code, result) {
const customerObj = { companyOnlyCode: company_only_code };
async putUserCompanyOnlyCode(userId, companyOnlyCode, result) {
const customerObj = { companyOnlyCode: companyOnlyCode };
const putSqlWhere = { where: { id: userId } };
this.updateByWhere(customerObj, putSqlWhere);
return result;
......
......@@ -28,16 +28,19 @@ class DeliverDao extends Dao {
qc.raw = true;
const type = qobj.bizpath.split('/')[1];
if (type === 'deliveryManagement') {
qc.where.product_code = product_code && [system.SERVICECODE.EDI, system.SERVICECODE.ICP].includes(product_code) ? product_code : {
$in: [system.SERVICECODE.EDI, system.SERVICECODE.ICP],
};
qc.where.product_code =
(product_code && [system.SERVICECODE.EDI, system.SERVICECODE.ICP].includes(product_code))
? product_code
: {
$in: [system.SERVICECODE.EDI, system.SERVICECODE.ICP],
};
switch (qobj.bizpath) {
case '/deliveryManagement/wait':
qc.where.delivery_status = qc.where.delivery_status || {
$in: [system.SERVERSESTATUS.RECEIVED, system.SERVERSESTATUS.COLLECTING,
system.SERVERSESTATUS.SUBMITING, system.SERVERSESTATUS.DISPOSEING, system.SERVERSESTATUS.POSTING,
system.SERVERSESTATUS.SUBMITING, system.SERVERSESTATUS.DISPOSEING, system.SERVERSESTATUS.POSTING,
],
};
break;
......@@ -55,9 +58,12 @@ class DeliverDao extends Dao {
break;
}
} else if (type === 'annualReport') {
qc.where.product_code = product_code && [system.SERVICECODE.ICPANNUALREPORT, system.SERVICECODE.EDIANNUALREPORT].includes(product_code) ? product_code : {
$in: [system.SERVICECODE.EDIANNUALREPORT, system.SERVICECODE.ICPANNUALREPORT],
};
qc.where.product_code =
(product_code && [system.SERVICECODE.ICPANNUALREPORT, system.SERVICECODE.EDIANNUALREPORT].includes(product_code))
? product_code
: {
$in: [system.SERVICECODE.EDIANNUALREPORT, system.SERVICECODE.ICPANNUALREPORT],
};
// ---- 兼容 年报 状态 未申报、已申报 start
let status;
......@@ -114,7 +120,6 @@ class DeliverDao extends Dao {
include: [
{
model: this.db.models.qualification,
// attributes: ['id', 'certificateNumber', 'businessTypes', 'businessScope', 'serviceProject', 'startAt', 'endAt', 'file'],
raw: false,
}, {
model: this.db.models.material,
......@@ -133,7 +138,6 @@ class DeliverDao extends Dao {
include: [
{
model: this.db.models.annualreport,
// attributes: ['id', 'certificateNumber', 'businessTypes', 'businessScope', 'serviceProject', 'startAt', 'endAt', 'file'],
},
],
raw: false,
......
......@@ -8,7 +8,7 @@ class MsgNoticeDao extends Dao {
async saveNotice(msg, t) {
let noticeFrom = await super.findOne({ fromId: msg.senderId, toId: msg.targetId });
if (noticeFrom) {
var set = { lastMsgId: msg.id };
let set = { lastMsgId: msg.id };
if (msg.businessLicense_id) {
set.businessLicense_id = msg.businessLicense_id;
}
......@@ -28,7 +28,7 @@ class MsgNoticeDao extends Dao {
let noticeTo = await super.findOne({ fromId: msg.targetId, toId: msg.senderId });
if (noticeTo) {
var set = { lastMsgId: msg.id };
let set = { lastMsgId: msg.id };
if (msg.businessLicense_id) {
set.businessLicense_id = msg.businessLicense_id;
}
......
......@@ -11,7 +11,8 @@ class AuthService extends ServiceBase {
// var newattrs=rolecodestr.split(",");
const aths = await this.dao.model.findAll({
attributes: ['bizcode', 'authstrs', 'codepath'],
where: { role_id: { [this.db.Op.in]: roleids }, app_id: appid, company_id: comid } });
where: { role_id: { [this.db.Op.in]: roleids }, app_id: appid, company_id: comid }
});
return aths;
}
async saveAuths(auths, appid, cmid) {
......@@ -20,8 +21,8 @@ class AuthService extends ServiceBase {
console.log('yyyyyyyyyvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv');
console.log(auths);
return self.db.transaction(async (t) => {
for (let i = 0;i < auths.length;i++) {
var tmpAuth = auths[i];
for (let i = 0; i < auths.length; i++) {
let tmpAuth = auths[i];
tmpAuth.app_id = appid;
tmpAuth.company_id = cmid;
const objrtn = await self.dao.model.findOrCreate({
......@@ -33,10 +34,23 @@ class AuthService extends ServiceBase {
console.log(objrtn);
if (!objrtn[1].created) {
// 就执行更新操作
await objrtn[0].update(tmpAuth, { where: { role_id: tmpAuth.role_id, bizcode: tmpAuth.bizcode }, transaction: t });
await objrtn[0].update(tmpAuth, {
where:
{
role_id: tmpAuth.role_id,
bizcode: tmpAuth.bizcode
},
transaction: t
});
}
}
const aths = await self.dao.model.findAll({ where: { role_id: tmpAuth.role_id, app_id: tmpAuth.app_id }, transaction: t });
const aths = await self.dao.model.findAll({
where: {
role_id: tmpAuth.role_id,
app_id: tmpAuth.app_id
},
transaction: t
});
return aths;
});
}
......
......@@ -44,7 +44,7 @@ class OrgService extends ServiceBase {
const usersupdate = await self.db.models.user.findAll({ where: { org_id: orgupdate.id } });
// 如果节点名称或岗位性质发生变化
// if(p.name!=orgupdate.name || p.isMain!=orgupdate.isMain){
for (var ud of usersupdate) {
for (let ud of usersupdate) {
ud.opath = p.orgpath;
const n = p.orgpath.lastIndexOf('/');
ud.ppath = p.isMain ? p.orgpath.substring(0, n) : p.orgpath;
......@@ -55,7 +55,7 @@ class OrgService extends ServiceBase {
const roles = await self.db.models.role.findAll({ where: { id: { [self.db.Op.in]: p.Roles } } });
await orgupdate.setRoles(roles, { transaction: t });
// 同时要给这个岗位下的user,更新角色 todo
for (var ud of usersupdate) {
for (let ud of usersupdate) {
await ud.setRoles(roles, { transaction: t });
}
}
......
......@@ -60,7 +60,14 @@ class UserService extends ServiceBase {
// 设置默认普通角色,由于有了租户概念,所以注册时,需要知道当前租户和应用的id 才可以设置默认角色 todo
// 如果是非租户,那么按照当前应用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) {
await u.setRoles(roles, { transaction: t });
}
......@@ -180,7 +187,13 @@ class UserService extends ServiceBase {
return rtn;
}
// 先按照用户名查续身份信息,获取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);
// rtn.token = token;
// rtn.user = u;
......@@ -274,16 +287,6 @@ class UserService extends ServiceBase {
}
}
// 登录统一账号
async clogin(uname) {
// 检查是否存在重名
}
// 按用户名查询统一用户
async findCUser(uname) {
}
async resetPassword(uname, pwd) {
const inpassword = this.getEncryptStr(pwd);
const self = this;
......
......@@ -17,18 +17,26 @@ class SchemeService extends ServiceBase {
if (!bizData) {
throw new Error('查不到该商机');
}
if ([system.BUSSTATUS.CLOSED, system.BUSSTATUS.SUCCESS, system.BUSSTATUS.WAITINGCONFIRM].includes(bizData.business_status)) {
if ([system.BUSSTATUS.CLOSED,
system.BUSSTATUS.SUCCESS,
system.BUSSTATUS.WAITINGCONFIRM].includes(bizData.business_status)) {
throw new Error('此商机状态下不可操作');
}
const schemeData = await this.dao.findOne({
bizopt_id: data.bizopt_id,
});
if (schemeData && [system.SCHEMESTATUS.WAITINGCONFIRM, system.SCHEMESTATUS.CLOSED].includes(schemeData.scheme_status)) {
if (schemeData
&& [system.SCHEMESTATUS.WAITINGCONFIRM,
system.SCHEMESTATUS.CLOSED].includes(schemeData.scheme_status)) {
throw new Error('此方案状态下不可操作');
}
// scheme_number 提交到腾讯 获取更新 方案编号
data.scheme_number = await pushTx.pushScheme(bizData, schemeData ? { ...data, scheme_number: schemeData.scheme_number } : data);
data.scheme_number = await pushTx.pushScheme(bizData, schemeData
? {
...data,
scheme_number: schemeData.scheme_number
} : data);
return this.db.transaction(async (t) => {
......@@ -51,7 +59,7 @@ class SchemeService extends ServiceBase {
salesman_id: data.userid,
salesman_name: data.username,
});
let scheme_id = null;
let schemeId = null;
if (schemeData) {
await this.dao.updateByWhere({
...data,
......@@ -60,7 +68,7 @@ class SchemeService extends ServiceBase {
}, {
id: schemeData.id,
}, t);
scheme_id = schemeData.id;
schemeId = schemeData.id;
} else {
const schemeResult = await this.dao.create({
...data,
......@@ -68,11 +76,11 @@ class SchemeService extends ServiceBase {
scheme_status: system.SCHEMESTATUS.WAITINGCONFIRM,
bizopt_id: data.bizopt_id,
}, t);
scheme_id = schemeResult.id;
schemeId = schemeResult.id;
}
this.statuslogDao.create({
flow_type: system.FLOWCODE.SCHEME,
flow_id: scheme_id,
flow_id: schemeId,
status_code: system.SCHEMESTATUS.WAITINGCONFIRM,
salesman_id: data.userid,
salesman_name: data.username,
......
......@@ -14,7 +14,7 @@ class AppService extends ServiceBase {
const app = this.cacheManager.AppCache.cache(p.appkey, null);
return app;
}
async upFrontRoute(jsonObject, app_id) {
async upFrontRoute(jsonObject, appId) {
const self = this;
return this.db.transaction(async (t) => {
const keyfile = `${self.getUUID()}.json`;
......@@ -23,7 +23,7 @@ class AppService extends ServiceBase {
fs.writeFileSync(tmpdirfile, str);
const result = await self.ossC.upfile(keyfile, tmpdirfile);
fs.unlinkSync(tmpdirfile);
await self.db.models.app.update({ docUrl: result.url, id: app_id }, { where: { id: app_id }, transaction: t });
await self.db.models.app.update({ docUrl: result.url, id: appId }, { where: { id: appId }, transaction: t });
return result;
});
}
......
......@@ -27,24 +27,24 @@ class CachSearchesSve {
const { pageSize } = obj.pageInfo;
const limit = pageSize;
const offset = (pageNo - 1) * pageSize;
const search_name = obj.search && obj.search.name ? obj.search.name : '';
const searchName = obj.search && obj.search.name ? obj.search.name : '';
const cacheCacheKeyPrefix = `sadd_base_appkeys:${settings.appKey}_cachekey`;
if (obj.appid == settings.platformid) {
let cacheList = await this.cacheManager.MagCache.getCacheSmembersByKey(cacheCacheKeyPrefix);
if (search_name) {
cacheList = cacheList.filter(f => f.indexOf(search_name) >= 0);
if (searchName) {
cacheList = cacheList.filter(f => f.indexOf(searchName) >= 0);
}
const pageValues = cacheList.slice(offset, offset + limit);
const kobjs = await this.buildCacheRtn(pageValues);
var tmpList = { results: { rows: kobjs, count: cacheList.length } };
const tmpList = { results: { rows: kobjs, count: cacheList.length } };
return system.getResult(tmpList);
}
const body = {
pageInfo: obj.pageInfo,
search: obj.search,
};
var tmpList = await this.opOtherAppCache('findAndCountAll', body, obj.opCacheUrl);
const tmpList = await this.opOtherAppCache('findAndCountAll', body, obj.opCacheUrl);
return tmpList;
}
async delCache(obj) {
......@@ -60,7 +60,8 @@ class CachSearchesSve {
const body = {
del_cachekey: obj.key,
};
return await this.opOtherAppCache('delCache', body, obj.opCacheUrl);
const result = await this.opOtherAppCache('delCache', body, obj.opCacheUrl);
return result;
}
}
async clearAllCache(obj) {
......@@ -68,24 +69,25 @@ class CachSearchesSve {
await this.cacheManager.MagCache.clearAll();
return { status: 0 };
}
return await this.opOtherAppCache('clearAllCache', {}, obj.opCacheUrl);
const result = await this.opOtherAppCache('clearAllCache', {}, obj.opCacheUrl);
return result;
}
// app调用次数
async findAndCountAlldetail(obj) {
const apicallAccu = await this.cacheManager.ApiAccuCache.getApiCallAccu(obj);
const result = { rows: [], count: 0 };
const keys = await this.cacheManager.MagCache.keys(`api_call_${appkey}*`);
var detail = null;
let detail = null;
for (let j = 0; j < keys.length; j++) {
const d = keys[j];
const pathdetail = d.substr(d.lastIndexOf('_') + 1, d.length);
const apicalldetailAccu = await this.cacheManager.ApiCallCountCache.getApiCallCount(appkey, pathdetail);
var detail = { detailPath: d, detailCount: apicalldetailAccu.callcount };
detail = { detailPath: d, detailCount: apicalldetailAccu.callcount };
}
result.rows = detail;
}
// 操作别的应用的缓存
async opOtherAppCache(action_type, body = null, opCacheUrl) {
async opOtherAppCache(actionType, body = null, opCacheUrl) {
const appData = await this.authUtils.getTokenInfo(settings.appKey, settings.secret);
if (appData.status != 0) {
return appData;
......@@ -94,7 +96,7 @@ class CachSearchesSve {
const restS = await system.getObject('util.restClient');
const restResult = await restS.execPostWithAK(
{
action_type,
actionType,
body,
},
opCacheUrl, appData.data.accessKey,
......
......@@ -21,7 +21,17 @@ class CompanyService extends ServiceBase {
const us = await self.db.models.user.findAll({ where: { opath: opathstr }, transaction: t });
// 查询出角色
const roleids = curNodeData.roles;
const rs = await self.db.models.role.findAll({ where: { id: { [self.db.Op.in]: roleids }, app_id: p.app_id, company_id: p.company_id }, transaction: t });
const rs = await self.db.models.role.findAll({
where:
{
id: {
[self.db.Op.in]: roleids
},
app_id: p.app_id,
company_id: p.company_id
},
transaction: t
});
for (const u of us) {
await u.setRoles(rs, { transaction: t });
}
......
......@@ -16,7 +16,14 @@ class RouteService extends ServiceBase {
let rtn = null;
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;
rtn = await self.dao.create(routedata, t);
} catch (e) {
......
......@@ -186,7 +186,11 @@ class DeliverService extends ServiceBase {
if (!deliverData) {
throw new Error('查不到交付单');
}
if (![system.SERVERSESTATUS.DISPOSEING, system.SERVERSESTATUS.SUCCESS, system.SERVERSESTATUS.POSTING].includes(deliverData.delivery_status)) {
if (
![system.SERVERSESTATUS.DISPOSEING,
system.SERVERSESTATUS.SUCCESS,
system.SERVERSESTATUS.POSTING].includes(deliverData.delivery_status)
) {
throw new Error('该交付单状态下不可提交');
}
if ([system.SERVERSESTATUS.SUCCESS, system.SERVERSESTATUS.POSTING].includes(deliverData.delivery_status)) {
......@@ -346,7 +350,11 @@ class DeliverService extends ServiceBase {
if (!result.qualification) {
throw new Error('请先上传资质信息');
}
if (![system.SERVERSESTATUS.DISPOSEING, system.SERVERSESTATUS.SUCCESS, system.SERVERSESTATUS.POSTING].includes(result.delivery_status)) {
if (
![system.SERVERSESTATUS.DISPOSEING,
system.SERVERSESTATUS.SUCCESS,
system.SERVERSESTATUS.POSTING].includes(result.delivery_status)
) {
throw new Error('该状态下不可填写邮寄信息');
}
const { material } = result;
......
......@@ -108,7 +108,10 @@ class ServiceBase {
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else {
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';
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
......@@ -154,8 +157,6 @@ class ServiceBase {
return rtn.data;
}
throw new Error(rtn.data);
return null;
} catch (e) {
console.log(e);
return null;
......
......@@ -128,11 +128,11 @@ class System {
}
/**
* 请求返回成功
* @param {*} data 操作成功返回的数据,有值为成功,无值为失败
* @param {*} okmsg 操作成功的描述
* @param {*} req 请求头信息
*/
* 请求返回成功
* @param {*} data 操作成功返回的数据,有值为成功,无值为失败
* @param {*} okmsg 操作成功的描述
* @param {*} req 请求头信息
*/
static getResult(data, opmsg = '操作成功', req) {
return {
status: !data ? -1 : 0,
......@@ -142,10 +142,10 @@ class System {
};
}
/**
* 请求返回成功
* @param {*} data 操作成功返回的数据
* @param {*} okmsg 操作成功的描述
*/
* 请求返回成功
* @param {*} data 操作成功返回的数据
* @param {*} okmsg 操作成功的描述
*/
static getResultSuccess(data, okmsg = 'success') {
return {
status: 0,
......@@ -154,11 +154,11 @@ class System {
};
}
/**
* 请求返回失败
* @param {*} status 操作失败状态,默认为-1
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
*/
* 请求返回失败
* @param {*} status 操作失败状态,默认为-1
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
*/
static getResultFail(status = -1, errmsg = 'fail', data = null) {
return {
status,
......@@ -167,10 +167,10 @@ class System {
};
}
/**
* 请求处理异常
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
*/
* 请求处理异常
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
*/
static getResultError(errmsg = 'fail', data = null) {
return {
status: -200,
......@@ -244,12 +244,12 @@ class System {
const configValue = require(configPath);
return configValue.config;
}
static get_client_ip(req) {
static getClientIp(req) {
const ip = req.headers['x-forwarded-for']
|| req.ip
|| req.connection.remoteAddress
|| req.socket.remoteAddress
|| (req.connection.socket && req.connection.socket.remoteAddress) || '';
|| req.ip
|| req.connection.remoteAddress
|| req.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])$/);
if (x) {
return x[0];
......@@ -259,13 +259,13 @@ class System {
/**
* 记录日志信息
* @param {*} opTitle 操作的标题
* @param {*} params 参数
* @param {*} identifyCode 业务标识
* @param {*} resultInfo 返回结果
* @param {*} errorInfo 错误信息
*/
* 记录日志信息
* @param {*} opTitle 操作的标题
* @param {*} params 参数
* @param {*} identifyCode 业务标识
* @param {*} resultInfo 返回结果
* @param {*} errorInfo 错误信息
*/
static execLogs(opTitle, params, identifyCode, resultInfo, errorInfo) {
const reqUrl = settings.logUrl();
let isLogData = true;
......@@ -312,9 +312,9 @@ class System {
return cipherStr;
}
/**
* 解密信息
* @param {*} opStr
*/
* 解密信息
* @param {*} opStr
*/
static decryptStr(opStr) {
if (!opStr) {
return opStr;
......
......@@ -49,8 +49,8 @@ class ExcelClient {
wb.xlsx.writeFile(filePath).then(async (d) => {
const rtn = await self.ossClient.upfile(fileName, filePath);
fs.unlink(filePath, (err) => {});
var obj = {
fs.unlink(filePath, (err) => { });
let obj = {
user_id: user.id || 0,
userName: user.userName || '',
code,
......@@ -58,7 +58,7 @@ class ExcelClient {
filePath: rtn.url || '',
isDownload: false,
};
var obj = await self.filedownloadDao.create(obj);
obj = await self.filedownloadDao.create(obj);
});
}
}
......
......@@ -3,8 +3,6 @@ const settings = require('../../config/settings');
const uuidv4 = require('uuid/v4');
const system = require('../system');
class LogClient {
constructor() {
}
getUUID() {
const uuid = uuidv4();
const u = uuid.replace(/\-/g, '');
......
......@@ -88,7 +88,7 @@ class RedisClient {
}
if (self.chatserver) {
if (channel != 'task') {
var message = JSON.parse(message);
message = JSON.parse(message);
console.log(message, '------------------------------------------ publish message');
if (channel == 'brc') { // 如果是广播频道,则发送广播到客户端
self.chatserver.server.emit('brc', message);
......
......@@ -38,7 +38,7 @@ class SmsClient {
};
return this.restClient.execPost(txtObj, this.smsTeml);
}
async getUidStr(len, radix) {
async getUidStr(len, radix) {
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
const uuid = []; let i;
radix = radix || chars.length;
......@@ -46,7 +46,10 @@ class SmsClient {
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else {
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';
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
......
......@@ -228,7 +228,9 @@ function buildValue(value, cryptStr) {
}));
}
if (newValue.proposerInfo.businessInformation) {
newValue.proposerInfo.businessInformation.fixedTelephone = cryptStr(newValue.proposerInfo.businessInformation.fixedTelephone);
newValue.proposerInfo.businessInformation.fixedTelephone = cryptStr(
newValue.proposerInfo.businessInformation.fixedTelephone
);
}
}
if (newValue.shareholderData) {
......
......@@ -23,7 +23,7 @@ module.exports = function (app) {
routes(app);// 初始化路由
app.use(express.static(path.join(settings.basepath, '/app/front/entry/public')));
// development only
if ('development' == app.get('env')) {
if (app.get('env') == 'development') {
app.use(errorHandler());
} else {
app.use((err, req, res) => {
......
......@@ -6,7 +6,7 @@ module.exports = function (app) {
const methodName = req.params.method;
const { gname } = req.params;
classPath = `${gname}.${classPath}`;
const tClientIp = System.get_client_ip(req);
const tClientIp = System.getClientIp(req);
req.clientIp = tClientIp;
req.uagent = req.headers['user-agent'];
// req.classname=classPath;
......@@ -34,7 +34,7 @@ module.exports = function (app) {
classPath = `${gname}.${classPath}`;
console.log('====================');
console.log(classPath);
const tClientIp = System.get_client_ip(req);
const tClientIp = System.getClientIp(req);
req.clientIp = tClientIp;
req.uagent = req.headers['user-agent'];
// req.classname=classPath;
......
......@@ -28,7 +28,7 @@ module.exports = function (app) {
const { gname } = req.params;
const params = [];
classPath = `${gname}.${classPath}`;
const tClientIp = system.get_client_ip(req);
const tClientIp = system.getClientIp(req);
req.body.clientIp = tClientIp;
req.body.agent = req.headers['user-agent'];
req.body.classname = classPath;
......
var fs = require('fs');
const fs = require('fs');
// function to encode file data to base64 encoded string
function base64_encode(file) {
// read binary data
var bitmap = fs.readFileSync("./imgs/sp.png");
// convert binary data to base64 encoded string
var bf=Buffer.alloc(bitmap.length,bitmap);
return bf.toString('base64');
// read binary data
const bitmap = fs.readFileSync("./imgs/sp.png");
// convert binary data to base64 encoded string
const bf = Buffer.alloc(bitmap.length, bitmap);
return bf.toString('base64');
}
// function to create file from base64 encoded string
function base64_decode(base64str, file) {
// create buffer object from base64 encoded string, it is important to tell the constructor that the string is base64 encoded
var bitmap = new Buffer(base64str, 'base64');
// write buffer to file
fs.writeFileSync(file, bitmap);
console.log('******** File created from base64 encoded string ********');
// create buffer object from base64 encoded string, it is important to tell the constructor that the string is base64 encoded
const bitmap = new Buffer(base64str, 'base64');
// write buffer to file
fs.writeFileSync(file, bitmap);
console.log('******** File created from base64 encoded string ********');
}
function getDataUrl(filepath){
var str=base64_encode(filepath);
var mime="";
if(filepath.indexOf("png")>=0){
mime="image/png";
function getDataUrl(filepath) {
const str = base64_encode(filepath);
let mime = "";
if (filepath.indexOf("png") >= 0) {
mime = "image/png";
}
if(filepath.indexOf("jpg")>=0 || filepath.indexOf("jpeg")>=0){
mime="image/jpg";
if (filepath.indexOf("jpg") >= 0 || filepath.indexOf("jpeg") >= 0) {
mime = "image/jpg";
}
if(filepath.indexOf("gif")>=0){
mime="image/gif";
if (filepath.indexOf("gif") >= 0) {
mime = "image/gif";
}
var dataurl=`data:${mime};base64,`+str;
const dataurl = `data:${mime};base64,` + str;
return dataurl;
}
var str=getDataUrl("./imgs/sp.png");
const str = getDataUrl("./imgs/sp.png");
console.log(str);
\ No newline at end of file
var http = require('http');
var express = require('express');
var app = express();
var setttings=require("./app/config/settings");
var environment = require('./app/config/environment');
// var SocketServer=require("./app/config/socket.server");
const http = require('http');
const express = require('express');
const app = express();
const setttings = require("./app/config/settings");
const environment = require('./app/config/environment');
// const SocketServer=require("./app/config/socket.server");
//const cluster = require('cluster');
//const numCPUs = require('os').cpus().length;
// all environments
......@@ -20,15 +20,15 @@ environment(app);//初始化环境
// console.log(`worker ${worker.process.pid} died`);
// });
// }else{
// var server = http.createServer(app);
// var socketServer = new SocketServer(server);
// const server = http.createServer(app);
// const socketServer = new SocketServer(server);
// server.listen(setttings.port, function(){
// console.log('Express server listening on port ' + app.get('port'));
// });
// }
var server = http.createServer(app);
//var socketServer = new SocketServer(server);
server.listen(setttings.port, function(){
const server = http.createServer(app);
//const socketServer = new SocketServer(server);
server.listen(setttings.port, function () {
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