Commit 5afee49d by 孙亚楠

d

parent e9063be1
...@@ -4,7 +4,9 @@ var settings = require("../../../../config/settings"); ...@@ -4,7 +4,9 @@ var settings = require("../../../../config/settings");
class ActionAPI extends APIBase { class ActionAPI extends APIBase {
constructor() { constructor() {
super(); super();
// this.storderSve = system.getObject("service.trade.storderSve"); this.cclueSve = system.getObject("service.chance.cclueSve");
this.cfollowlogSve = system.getObject("service.chance.cfollowlogSve");
this.cschemeSve = system.getObject("service.chance.cschemeSve");
} }
/** /**
* 接口跳转 * 接口跳转
...@@ -32,10 +34,30 @@ class ActionAPI extends APIBase { ...@@ -32,10 +34,30 @@ class ActionAPI extends APIBase {
async handleRequest(action_process, action_type, action_body) { async handleRequest(action_process, action_type, action_body) {
var opResult = null; var opResult = null;
switch (action_type) { switch (action_type) {
case "test": case "saveClue"://保存线索
opResult = await this.storderSve.test(action_body); opResult = await this.cclueSve.saveClue(action_body);
break;
case "closeClue"://关闭商机
opResult = await this.cclueSve.closeClue(action_body);
break;
case "listClue"://列表商机
opResult = await this.cclueSve.listClue(action_body);
break;
case "clueStatusDict"://列表商机字典
opResult = await this.cclueSve.clueStatusDict(action_body);
break;
case "closeReasonDict"://关闭商机字典
opResult = await this.cclueSve.closeReasonDict(action_body);
break;
case "getClueById": //根据线索ID查询详细
opResult = await this.cclueSve.getClueById(action_body);
break;
case "saveCfollowLog": //保存跟进进度
opResult = await this.cfollowlogSve.saveCfollowLog(action_body);
break;
case "saveCscheme": //保存跟进进度
opResult = await this.cschemeSve.saveCscheme(action_body);
break; break;
default: default:
opResult = system.getResult(null, "action_type参数错误"); opResult = system.getResult(null, "action_type参数错误");
break; break;
......
const system=require("../../../system");
const Dao=require("../../dao.base");
class UserDao extends Dao{
constructor(){
super(Dao.getModelName(UserDao));
}
async getAuths(userid){
var self=this;
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"]}
]},
],
});
}
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){
if(obj.codepath && obj.codepath!=""){
// if(obj.codepath.indexOf("userarch")>0){//说明是应用管理员的查询
// console.log(obj);
// w["app_id"]=obj.appid;
// }
}
if(linkAttrs.length>0){
var search=obj.search;
var lnkKey=linkAttrs[0];
var strq="$"+lnkKey.replace("~",".")+"$";
w[strq]= {[this.db.Op.like]:"%"+search[lnkKey]+"%"};
}
return w;
}
async preUpdate(u){
if(u.roles && u.roles.length>0){
var roles=await this.db.models.role.findAll({where:{id:{[this.db.Op.in]:u.roles}}});
console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
console.log(roles);
u.roles=roles
}
return u;
}
async update(obj){
var obj2=await this.preUpdate(obj);
console.log("update....................");
console.log(obj2);
await this.model.update(obj2,{where:{id:obj2.id}});
var user=await this.model.findOne({where:{id:obj2.id}});
user.setRoles(obj2.roles);
return user;
}
async findAndCountAll(qobj,t){
var users=await super.findAndCountAll(qobj,t);
return users;
}
async preCreate(u){
// var roles=await this.db.models.role.findAll({where:{id:{[this.db.Op.like]:u.roles}}});
// console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
// console.log(roles);
// console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
// u.roles=roles
return u;
}
async create(u,t){
var self=this;
var u2=await this.preCreate(u);
if(t){
return this.model.create(u2,{transaction: t}).then(user=>{
return user;
});
}else{
return this.model.create(u2).then(user=>{
return user;
});
}
}
//修改用户(user表)公司的唯一码
async putUserCompanyOnlyCode(userId,company_only_code,result){
var customerObj={companyOnlyCode:company_only_code};
var putSqlWhere={where:{id:userId}};
this.updateByWhere(customerObj,putSqlWhere);
return result;
}
}
module.exports=UserDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
...@@ -5,6 +5,75 @@ class CclueDao extends Dao { ...@@ -5,6 +5,75 @@ class CclueDao extends Dao {
constructor() { constructor() {
super(Dao.getModelName(CclueDao)); super(Dao.getModelName(CclueDao));
} }
/**
* 线索列表统计
* @param params
* @returns {Promise<*>}
*/
async ordersCount(params){
let sql = [];
sql.push('SELECT COUNT(1) AS count FROM c_clue WHERE 1 = 1 ');
this.setClueCount(sql,params);
return await this.customQuery(sql.join(" "), params);
}
setClueCount(sql,params){
if(params.id){
sql.push(`and id=:id`);
}
if(params.deliver_id){
sql.push(`and deliver_id=:deliver_id`);
}
if(params.status){
sql.push(`and status=:status`);
}
if(params.status_arr && params.status_arr.length>0){
sql.push(`and status in (:status_arr)`);
}
if (params.createdBegin) {
sql.push("AND created_at >= :createdBegin");
}
if (params.createdEnd) {
sql.push("AND created_at <= :createdEnd");
}
if (params.operator_id) {
sql.push("AND operator_path = :operator_id");
}
if (params.operator_path) {
params.operator_path_alias = params.operator_path + "%";
sql.push("AND operator_path LIKE :operator_path_alias");
}
}
/**
* fn:线索列表
* @param params
* @returns {Promise<*|{count: number}>}
*/
async listClue(params){
var sql = [];
sql.push("SELECT * FROM `c_clue` WHERE 1 = 1");
this.setClueCount(sql,params);
sql.push("ORDER BY t1.created_at DESC");
sql.push("LIMIT :startRow, :pageSize");
let list = await this.customQuery(sql.join(" "), params);
if(!list || list.length==0){
return {count:0};
}
return list;
}
/**
* fn:查询明细
* @param params
* @returns {Promise<*|{count: number}>}
*/
async getCclueInfo(params){
var sql = [];
sql.push("SELECT * FROM `c_clue` WHERE 1 = 1");
this.setClueCount(sql,params);
return await this.customQuery(sql.join(" "), params) || {};
}
} }
module.exports = CclueDao; module.exports = CclueDao;
...@@ -6,6 +6,48 @@ class CfollowlogDao extends Dao { ...@@ -6,6 +6,48 @@ class CfollowlogDao extends Dao {
super(Dao.getModelName(CfollowlogDao)); super(Dao.getModelName(CfollowlogDao));
} }
/**
* fn:根据线索ID查询记录
* @param params
* @returns {Promise<void>}
*/
async followlogsByClueIds(params){
var sql = [];
sql.push("SELECT * FROM `c_follow_log` WHERE 1=1");
this.setcfollowlogCount(sql,params);
sql.push("ORDER BY created_at DESC");
let list = await this.customQuery(sql.join(" "), params);
let map = {};
for (let item of list) {
if(!map[item.clue_id]){
map[item.clue_id] = [];
}
map[item.clue_id].push(item);
}
return map;
}
setcfollowlogCount(sql,params){
if(params.clueIds && params.clueIds.length>0){
sql.push(`and clue_id in (:clueIds)`);
}
if(params.clue_id){
sql.push(`and clue_id =:clue_id`);
}
}
/**
* fn:根据线索ID查询所有的跟踪日志
* @param clue_id
* @returns {Promise<{}>}
*/
async followlogsByClueId(clue_id){
var sql = [];
sql.push("SELECT * FROM `c_follow_log` WHERE 1=1");
this.setcfollowlogCount(sql,params);
sql.push("ORDER BY created_at DESC");
return await this.customQuery(sql.join(" "), params);
}
} }
......
...@@ -6,6 +6,30 @@ class CschemeDao extends Dao { ...@@ -6,6 +6,30 @@ class CschemeDao extends Dao {
super(Dao.getModelName(CschemeDao)); super(Dao.getModelName(CschemeDao));
} }
/**
* fn:
* @param params
* @returns {Promise<void>}
*/
async cschemes(params){
let sql =[];
sql.push('SELECT * FROM c_scheme WHERE 1 = 1 ');
this.setCscheme(sql,params);
return await this.customQuery(sql.join(" "), params);
}
setCscheme(sql,params){
if(params.id){
sql.push(`and id=:id`);
}
if(params.ids && params.ids.length>0){
sql.push(`and id in(:ids)`);
}
if(params.deliver_id){
sql.push(`and deliver_id =:deliver_id`);
}
}
} }
module.exports = CschemeDao; module.exports = CschemeDao;
const system=require("../../../system");
const fs=require("fs");
const settings=require("../../../../config/settings");
var glob = require("glob");
class APIDocManager{
constructor(){
this.doc={};
this.buildAPIDocMap();
}
async buildAPIDocMap(){
var self=this;
//订阅任务频道
var apiPath=settings.basepath+"/app/base/api/impl";
var rs = glob.sync(apiPath + "/**/*.js");
if(rs){
for(let r of rs){
// var ps=r.split("/");
// var nl=ps.length;
// var pkname=ps[nl-2];
// var fname=ps[nl-1].split(".")[0];
// var obj=system.getObject("api."+pkname+"."+fname);
var ClassObj=require(r);
var obj=new ClassObj();
var gk=obj.apiDoc.group+"|"+obj.apiDoc.groupDesc
if(!this.doc[gk]){
this.doc[gk]=[];
this.doc[gk].push(obj.apiDoc);
}else{
this.doc[gk].push(obj.apiDoc);
}
}
}
}
}
module.exports=APIDocManager;
const fs = require("fs");
const settings = require("../../../../config/settings");
class CacheManager {
constructor() {
//await this.buildCacheMap();
this.buildCacheMap();
}
buildCacheMap() {
var self = this;
self.doc = {};
var cachePath = settings.basepath + "/app/base/db/cache/";
const files = fs.readdirSync(cachePath);
if (files) {
files.forEach(function (r) {
var classObj = require(cachePath + "/" + r);
if (classObj.name) {
self[classObj.name] = new classObj();
var refTmp = self[classObj.name];
if (refTmp.prefix) {
self.doc[refTmp.prefix] = refTmp.desc;
} else {
console.log("请在" + classObj.name + "缓存中定义prefix");
}
}
});
}
}
}
module.exports = CacheManager;
// var cm= new CacheManager();
// cm["InitGiftCache"].cacheGlobalVal("hello").then(function(){
// cm["InitGiftCache"].cacheGlobalVal().then(x=>{
// console.log(x);
// });
// });
\ No newline at end of file
const Sequelize = require('sequelize');
const settings = require("../../../../config/settings")
const fs = require("fs")
const path = require("path");
var glob = require("glob");
class DbFactory {
constructor() {
const dbConfig = settings.database();
this.db = new Sequelize(dbConfig.dbname,
dbConfig.user,
dbConfig.password,
dbConfig.config);
this.db.Sequelize = Sequelize;
this.db.Op = Sequelize.Op;
this.initModels();
this.initRelations();
}
async initModels() {
var self = this;
var modelpath = path.normalize(path.join(__dirname, '../..')) + "/models/";
console.log("modelpath=====================================================");
console.log(modelpath);
var models = glob.sync(modelpath + "/**/*.js");
console.log(models.length);
models.forEach(function (m) {
console.log(m);
self.db.import(m);
});
console.log("init models....");
}
async initRelations() {
/**
一个账户对应多个登陆用户
一个账户对应一个commany
一个APP对应多个登陆用户
一个APP有多个角色
登陆用户和角色多对多
**/
/*建立账户和用户之间的关系*/
//account--不属于任何一个app,是统一用户
//用户登录时首先按照用户名和密码检查account是否存在,如果不存在则提示账号或密码不对,如果
//存在则按照按照accountid和应用key,查看user,后台实现对应user登录
}
//async getCon(){,用于使用替换table模型内字段数据使用
getCon() {
var that = this;
// await this.db.authenticate().then(()=>{
// console.log('Connection has been established successfully.');
// }).catch(err => {
// console.error('Unable to connect to the database:', err);
// throw err;
// });
//同步模型
if (settings.env == "dev") {
//console.log(pa);
// pconfigObjs.forEach(p=>{
// console.log(p.get({plain:true}));
// });
// await this.db.models.user.create({nickName:"dev","description":"test user",openId:"testopenid",unionId:"testunionid"})
// .then(function(user){
// var acc=that.db.models.account.build({unionId:"testunionid",nickName:"dev"});
// acc.save().then(a=>{
// user.setAccount(a);
// });
// });
}
return this.db;
}
getConhb() {
var that = this;
if (settings.env == "dev") {
}
return this.dbhb;
}
}
module.exports = DbFactory;
// const dbf=new DbFactory();
// dbf.getCon().then((db)=>{
// //console.log(db);
// // db.models.user.create({nickName:"jy","description":"cccc",openId:"xxyy",unionId:"zz"})
// // .then(function(user){
// // var acc=db.models.account.build({unionId:"zz",nickName:"jy"});
// // acc.save().then(a=>{
// // user.setAccount(a);
// // });
// // console.log(user);
// // });
// // db.models.user.findAll().then(function(rs){
// // console.log("xxxxyyyyyyyyyyyyyyyyy");
// // console.log(rs);
// // })
// });
// const User = db.define('user', {
// firstName: {
// type: Sequelize.STRING
// },
// lastName: {
// type: Sequelize.STRING
// }
// });
// db
// .authenticate()
// .then(() => {
// console.log('Co+nnection has been established successfully.');
//
// User.sync(/*{force: true}*/).then(() => {
// // Table created
// return User.create({
// firstName: 'John',
// lastName: 'Hancock'
// });
// });
//
// })
// .catch(err => {
// console.error('Unable to connect to the database:', err);
// });
//
// User.findAll().then((rows)=>{
// console.log(rows[0].firstName);
// });
const system=require("../../../system");
const Dao=require("../../dao.base");
class MetaDao{
constructor(){
//super(Dao.getModelName(AppDao));
}
}
module.exports=MetaDao;
const system=require("../../../system");
const Dao=require("../../dao.base");
class OplogDao extends Dao{
constructor(){
super(Dao.getModelName(OplogDao));
}
}
module.exports=OplogDao;
const system=require("../../../system");
const Dao=require("../../dao.base");
class TaskDao extends Dao{
constructor(){
super(Dao.getModelName(TaskDao));
}
extraWhere(qobj,qw,qc){
qc.raw=true;
return qw;
}
async delete(task,qobj,t){
return task.destroy({where:qobj,transaction:t});
}
}
module.exports=TaskDao;
const system=require("../../../system");
const fs=require("fs");
const settings=require("../../../../config/settings");
var cron = require('node-cron');
class TaskManager{
constructor(){
this.taskDic={};
this.redisClient=system.getObject("util.redisClient");
this.buildTaskMap();
}
async buildTaskMap(){
var self=this;
//订阅任务频道
await this.redisClient.subscribeTask("task",this);
var taskPath=settings.basepath+"/app/base/db/task/";
const files=fs.readdirSync(taskPath);
if(files){
files.forEach(function(r){
var classObj=require(taskPath+"/"+r);
self[classObj.name]=new classObj();
});
}
}
async addTask(taskClassName,exp){
(async (tn,ep)=>{
if(!this.taskDic[tn]){
this.taskDic[tn]=cron.schedule(ep,()=>{
this[tn].doTask();
});
}
})(taskClassName,exp);
}
async deleteTask(taskClassName){
if(this.taskDic[taskClassName]){
this.taskDic[taskClassName].destroy();
delete this.taskDic[taskClassName];
}
}
async clearlist(){
var x=await this.redisClient.clearlist("tasklist");
return x;
}
async publish(channel,msg){
var x=await this.redisClient.publish(channel,msg);
return x;
}
async newTask(taskstr){
return this.redisClient.rpush("tasklist",taskstr);
}
}
module.exports=TaskManager;
// var cm= new CacheManager();
// cm["InitGiftCache"].cacheGlobalVal("hello").then(function(){
// cm["InitGiftCache"].cacheGlobalVal().then(x=>{
// console.log(x);
// });
// });
const system=require("../../../system");
const settings=require("../../../../config/settings");
const uiconfig=system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("user", {
userName: {
type:DataTypes.STRING,
allowNull: false,
},
password: {
type:DataTypes.STRING,
allowNull: false,
},
nickName: {
type:DataTypes.STRING,
allowNull: true,
},
sex: {
type:DataTypes.ENUM,
allowNull: true,
values: Object.keys(uiconfig.config.pdict.sex),
},
mobile:DataTypes.STRING,
mail: {
type:DataTypes.STRING,
allowNull: true,
},
headUrl: DataTypes.STRING,
isAdmin:{
type:DataTypes.BOOLEAN,
defaultValue: false
},
isSuper:{
type:DataTypes.BOOLEAN,
defaultValue: false
},
openId:DataTypes.STRING,
app_id:DataTypes.INTEGER,
account_id:DataTypes.INTEGER,
isEnabled:{
type:DataTypes.BOOLEAN,
defaultValue: true
},
},{
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'p_user',
validate: {
},
indexes:[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
...@@ -4,6 +4,7 @@ const uiconfig = system.getUiConfig2(settings.appKey); ...@@ -4,6 +4,7 @@ const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("cclue", { return db.define("cclue", {
product_id: DataTypes.STRING, comment:'线索类型ID(商品ID)', product_id: DataTypes.STRING, comment:'线索类型ID(商品ID)',
deliver_id: DataTypes.STRING ,defaultValue:'', comment:'交付商ID',
product_name: DataTypes.STRING, comment:'线索类型名称(商品名称)', product_name: DataTypes.STRING, comment:'线索类型名称(商品名称)',
contact_mobile: DataTypes.STRING, comment:'联系电话', contact_mobile: DataTypes.STRING, comment:'联系电话',
contacts: DataTypes.STRING ,comment:'联系人', contacts: DataTypes.STRING ,comment:'联系人',
......
...@@ -6,6 +6,7 @@ module.exports = (db, DataTypes) => { ...@@ -6,6 +6,7 @@ module.exports = (db, DataTypes) => {
clue_id: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '线索ID' }, clue_id: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '线索ID' },
record: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '沟通记录' }, record: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '沟通记录' },
operator: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '操作人' }, operator: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '操作人' },
follow_date:{type:DataTypes.DATE, allowNull: true, COMMENT: '跟进时间' }
}, { }, {
paranoid: true, //假的删除 paranoid: true, //假的删除
underscored: true, underscored: true,
......
...@@ -3,6 +3,7 @@ const settings = require("../../../../config/settings"); ...@@ -3,6 +3,7 @@ const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey); const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("cscheme", { return db.define("cscheme", {
deliver_id: DataTypes.STRING ,defaultValue:'', comment:'交付商ID',
product_type: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '商品类型' }, product_type: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '商品类型' },
name: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '个体户名称' }, name: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '个体户名称' },
business_place: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '注册场所' }, business_place: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '注册场所' },
......
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("oplog", {
appid: DataTypes.STRING,
appkey: DataTypes.STRING,
requestId: DataTypes.STRING,
logLevel: {
type: DataTypes.ENUM,
allowNull: false,
values: Object.keys(uiconfig.config.pdict.logLevel),
defaultValue: "info",
},
op: DataTypes.STRING,
content: DataTypes.STRING(5000),
resultInfo: DataTypes.TEXT,
clientIp: DataTypes.STRING,
agent: {
type: DataTypes.STRING,
allowNull: true,
},
opTitle: DataTypes.STRING(500),
}, {
paranoid: false,//假的删除
underscored: true,
version: true,
freezeTableName: true,
timestamps: true,
updatedAt: false,
//freezeTableName: true,
// define the table's name
tableName: 'op_log',
validate: {
},
indexes: [
]
});
}
module.exports = (db, DataTypes) => {
return db.define("task", {
app_id:DataTypes.STRING,//需要在后台补充
taskClassName: {
type:DataTypes.STRING(100),
allowNull: false,
unique: true
},//和user的from相同,在注册user时,去创建
taskexp: {
type:DataTypes.STRING,
allowNull: false,
},//和user的from相同,在注册user时,去创建
desc:DataTypes.STRING,//需要在后台补充
},{
paranoid: false,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'p_task',
validate: {
},
indexes:[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
class UserService extends ServiceBase {
constructor() {
super("auth", ServiceBase.getDaoName(UserService));
}
async authByCode(opencode) {
var existedUser = null;
var rawUser = null;
var openuser = await this.apiCallWithAk(settings.paasUrl() + "api/auth/accessAuth/authByCode", { opencode: opencode });
if (openuser) {
//先查看自己系统中是否已经存在当前用户
existedUser = await this.dao.model.findOne({ where: { ucname: openuser.userName, ucid: openuser.id }, raw: true });
if (!existedUser) {
existedUser = await this.register(openuser);
}
rawUser = existedUser.get({ raw: true });
rawUser.Roles = openuser.Roles;
}
return rawUser;
}
async getUserLoginInfo(token) {
var acckapp = await this.cacheManager["ApiUserCache"].cache(token, null, settings.usertimeout);
}
async register(openuser) {
var param = {
ucname: openuser.userName, ucid: openuser.id,
last_login_time: new Date()
}
var cruser = await this.dao.create(param);
return cruser;
}
//在平台进行登录,返回目标认证地址
async navSysSetting(user) {
var sysLoginUrl = settings.paasUrl() + "web/auth/userCtl/login?appKey=" + settings.appKey + "\&toKey=" + settings.paasKey;
var x = { userName: user.userName, password: user.password, mobile: user.mobile };
var restResult = await this.restS.execPost({ u: x }, sysLoginUrl);
if (restResult) {
var rtnres = JSON.parse(restResult.stdout);
if (rtnres.status == 0) {
return rtnres.data;
}
}
return null;
}
async getUserByUserNamePwd(u) {
var user = await this.dao.model.findOne({
where: { userName: u.userName, password: u.password, app_id: u.app_id },
include: [
{ model: this.db.models.role, as: "Roles", attributes: ["id", "code"] },
]
});
return user;
}
async checkSameName(uname, appid) {
var ac = await this.dao.model.findOne({ where: { userName: uname, app_id: appid } });
var rtn = { isExist: false };
if (ac) {
rtn.isExist = true;
}
return rtn;
}
}
module.exports = UserService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
...@@ -7,8 +7,239 @@ const moment = require("moment"); ...@@ -7,8 +7,239 @@ const moment = require("moment");
class CclueService extends ServiceBase { class CclueService extends ServiceBase {
constructor() { constructor() {
super("order", ServiceBase.getDaoName(CclueService)); super("order", ServiceBase.getDaoName(CclueService));
this.redisClient =system.getObject("util.redisClient"); this.cschemeDao = system.getObject("db.chance.cschemeDao");
// this.oorderinforegDao = system.getObject("db.order.oorderinforegDao"); this.cfollowlogDao = system.getObject("db.chance.cfollowlogDao");
}
/**
* fn:保存线索
* @param params
* @returns {Promise<void>}
*/
async saveClue(params){
if(!params.product_id){
return system.getResult(null, `参数错误 产品ID不能为空`);
}
if(!params.product_name){
return system.getResult(null, `参数错误 产品名称不能为空`);
}
if(!params.deliver_id){
return system.getResult(null, `参数错误 交付商ID不能为空`);
}
let clue_properties = {
product_id : this.trim(params.product_id),
product_name : this.trim(params.product_name),
contacts : this.trim(params.contacts),
contact_mobile : this.trim(params.contact_mobile),
operator_id : this.trim(params.operator_id),
operator_path : this.trim(params.operator_path),
callback_url : this.trim(params.callback_url),
status:"10",
deliver_id: this.trim(params.deliver_id)
};
try{
let res = await this.db.transaction(async t =>{
let cclueBean =await this.dao.create(clue_properties, t);
let scheme_properties = {
id:cclueBean.id,
product_name:clue_properties.product_name,
deliver_id:clue_properties.deliver_id,
};
await this.cschemeDao.create(scheme_properties,t);
});
return system.getResult(res);
}catch (e) {
console.log(e);
return system.getResult(null, `系统错误`);
}
}
/**
* fn:关闭线索
* @param params
* @returns {Promise<void>}
*/
async closeClue(params){
if(!params.id){
return system.getResult(null, `参数错误 ID不能为空`);
}
if(!params.close_reason){
return system.getResult(null, `参数错误 关闭原因不能为空`);
}
if(params.close_reason=="50" && !params.close_remarks){
return system.getResult(null, `参数错误 关闭原因不能为空`);
}
let _cclue = await this.dao.getById(this.trim(params.id));
if(!_cclue){
return system.getResult(null, `线索不存在`);
}
let upd = {
id: this.trim(params.id),
close_reason: this.trim(params.close_reason),
close_remarks: this.trim(params.close_remarks) || ""
};
try{
let res = await this.update(upd);
return system.getResult(res);
}catch (e) {
console.log(e);
system.getResult(null, `系统错误`);
}
}
/**
* fn:线索列表
* @param params
* @returns {Promise<void>}
*/
async listClue(params){
if(!params.product_id){
return system.getResult(null, `参数错误 产品ID不能为空`);
}
params.currentPage = Number(params.currentPage || 1);
params.pageSize = Number(params.pageSize || 10);
params.startRow = (params.currentPage - 1) * params.pageSize;
try{
let countRes = await this.dao.countClue(params);
if(countRes.count==0){
return system.getResult({count: 0, row: []});
}
let list =await this.dao.listClue(params);
let clueIds = [];
for(let element of list) {
this.handleDate(element, ["created_at"], null, null);
//线索状态 10 待跟进 20 跟进中 30 已完成 40 已关闭
if(element.status=='10'){
element.status_name = "待跟进";
}else if(element.status=='20'){
element.status_name = "跟进中";
}else if(element.status=='30'){
element.status_name = "已完成";
}else if(element.status=='40'){
element.status_name = "已关闭";
}else{
element.status_name = "";
}
clueIds.push(element.id);
}
await this.formatCscheme(list, clueIds);
await this.formatCfollowLog(list, clueIds);
return system.getResult(list);
}catch (e) {
cosnole.log(e);
return system.getResult(null, `系统错误`);
}
}
/**
* fn:格式化跟踪记录
* @param list
* @returns {Promise<void>}
*/
async formatCfollowLog(list,clueIds){
if(!list || list.length<=0){
return ;
}
let cschemeMap={};
if(clueIds && clueIds.length>0){
cschemeMap = await this.cfollowlogDao.followlogsByClueIds({clueIds:clueIds});
for (let key in cschemeMap) {
this.handleDate(cschemeMap[key], ["created_at"], null, null);
}
}
for (let ele of list) {
ele.cfollowlog = cschemeMap[ele.id] || [];
ele.cfollowlogIsShow =ele.cfollowlog.length>0?true:false;
}
}
/**
* fn:格式化方案
* @param list
* @returns {Promise<void>}
*/
async formatCscheme(list,clueIds){
if(!list || list.length<=0){
return ;
}
let map = {}, listCscheme=[];
if(clueIds && clueIds.length>0){
listCscheme = await this.cschemeDao.cschemes({ids:clueIds});
for (let item of listCscheme) {
this.handleDate(item, ["created_at"], null, null);
map[item.id]=item;
}
}
for (let ele of list) {
ele.cscheme = map[ele.id];
ele.cschemeIsShow =cscheme.name?true:false;
}
}
/**
* fn:线索状态列表 10 待跟进 20 跟进中 30 已完成 40 已关闭
* @returns {Promise<void>}
*/
async clueStatusDict(){
let res = [
{id:"10",name:"待跟进"},
{id:"20",name:"跟进中"},
{id:"30",name:"已完成"},
{id:"40",name:"已关闭"}
];
return system.getResult(res)
}
/**
* fn:线索关闭状态字典 10 客户无意向 20 客户联系不上 30 客户暂时不需要 40 客户已购买其他家 50 其他
* @returns {Promise<void>}
*/
async closeReasonDict(){
let res = [
{id:"10",name:"客户无意向"},
{id:"20",name:"客户联系不上"},
{id:"30",name:"客户暂时不需要"},
{id:"40",name:"客户已购买其他家"},
{id:"50",name:"其他"},
];
return system.getResult(res)
}
/**
* fn:根据ID查询详细信息
* @returns {Promise<void>}
*/
async getClueById(params){
if(!params.id){
return system.getResult(null, `参数错误 ID不能为空`);
}
let where={
deliver_id:this.trim(params.deliver_id),
id:this.trim(params.id)
};
try{
let cclueBean = await this.dao.getCclueInfo(where);
if(!cclueBean){
return system.getResult(null, `线索不存在`);
}
//查询方案
let cschemeBean = await this.cschemeDao.getById(cclueBean.id) || {};
this.handleDate(cschemeBean, ["created_at"], null, null);
cschemeBean.cschemeIsShow=cschemeBean.name?true:false;
//查询跟踪记录
let cfollowlog = await this.cfollowlogDao.followlogsByClueIds({clue_id:cschemeBean.id});
for(let item of cfollowlog){
this.handleDate(item, ["created_at"], null, null);
}
cclueBean.cfollowlog=cfollowlog;
cschemeBean.cfollowlogIsShow =cfollowlog.length>0?true:false;
return system.getResult(cclueBean);
}catch (e) {
console.log(e);
return system.getResult(null, `系统错误`);
}
} }
} }
......
const system = require("../../../system"); const system = require("../../../system");
const ServiceBase = require("../../sve.base") const ServiceBase = require("../../sve.base")
const moment = require("moment");
/** /**
* 订单产品表 * 订单产品表
*/ */
class CclueService extends ServiceBase { class CfollowlogService extends ServiceBase {
constructor() { constructor() {
super("order", ServiceBase.getDaoName(CclueService)); super("order", ServiceBase.getDaoName(CfollowlogService));
this.redisClient =system.getObject("util.redisClient"); this.cclueDao = system.getObject("db.chance.cclueDao");
// this.oorderinforegDao = system.getObject("db.order.oorderinforegDao"); }
/**
* fn:保存跟进进度
* @param params
* @returns {Promise<void>}
*/
async saveCfollowLog(params){
if(!params.deliver_id){
return system.getResult(null, `参数错误 交付商ID不能为空`);
}
if(!params.clue_id){
return system.getResult(null, `参数错误 线索ID不能为空`);
}
if(!params.follow_date){
return system.getResult(null, `参数错误 跟进时间不能为空`);
}
if(!params.record){
return system.getResult(null, `参数错误 沟通记录不能为空`);
}
let cclueBean = await this.cclueDao.getCclueInfo({id:this.trim(params.clue_id),deliver_id:this.trim(params.deliver_id)});
if(!cclueBean){
return system.getResult(null,`线索不存在`);
}
try{
let cfollowlogProperties = {
clue_id: this.trim(params.clue_id),
follow_date: this.trim(params.follow_date),
record: this.trim(params.record),
operator: this.trim(params.operator)
};
let res = await this.dao.create(cfollowlogProperties);
return system.getResult(res);
}catch (e) {
console.log(e);
return system.getResult(null, `系统错误`);
}
} }
} }
module.exports = CclueService; module.exports = CfollowlogService;
\ No newline at end of file \ No newline at end of file
const system = require("../../../system"); const system = require("../../../system");
const ServiceBase = require("../../sve.base") const ServiceBase = require("../../sve.base")
const moment = require("moment"); class CschemeService extends ServiceBase {
/**
* 订单产品表
*/
class CclueService extends ServiceBase {
constructor() { constructor() {
super("order", ServiceBase.getDaoName(CclueService)); super("order", ServiceBase.getDaoName(CschemeService));
this.redisClient =system.getObject("util.redisClient"); this.redisClient =system.getObject("util.redisClient");
// this.oorderinforegDao = system.getObject("db.order.oorderinforegDao");
} }
/**
* fn:保存线索方案
* @param params
* @returns {Promise<void>}
*/
async saveCscheme(params){
if(!params.deliver_id){
return system.getResult(null, `参数错误 交付商ID不能为空`);
}
if(!params.id){
return system.getResult(null, `参数错误 线索ID不能为空`);
}
if(!params.product_name){
return system.getResult(null, `参数错误 产品名称不能为空`);
}
if(!params.name){
return system.getResult(null, `参数错误 个体户名称不能为空`);
}
if(!params.business_place){
return system.getResult(null, `参数错误 注册地不能为空`);
}
if(!params.legal_name){
return system.getResult(null, `参数错误 法人不能为空`);
}
if(!params.legal_mobile){
return system.getResult(null, `参数错误 法人电话不能为空`);
}
if(!params.service_ids){
return system.getResult(null, `参数错误 服务项不能为空`);
}
if(!params.business_type){
return system.getResult(null, `参数错误 经营类型不能为空`);
}
if(!params.businessscope){
return system.getResult(null, `参数错误 经营范围不能为空`);
}
let cschemeBean = await this.dao.model.findOne({
where:{
id: this.trim(params.id),
deliver_id: this.trim(params.deliver_id)
}
});
if(cschemeBean){
return system.getResult(null, `线索已存在`);
}
try{
let cschemeProperties ={
id: this.trim(params.id),
deliver_id: this.trim(params.deliver_id),
product_name: this.trim(params.product_name),
name: this.trim(params.name),
business_place: this.trim(params.business_place),
legal_name: this.trim(params.legal_name),
legal_mobile: this.trim(params.legal_mobile),
service_ids: this.trim(params.service_ids) ,
business_type: this.trim(params.business_type),
businessscope: this.trim(params.businessscope),
remarks: this.trim(params.remarks) || ""
};
let res = await this.dao.update(cschemeProperties);
return system.getResult(res);
}catch (e) {
console.log(e);
return system.getResult(null,`系统错误`)
}
}
} }
module.exports = CclueService; module.exports = CschemeService;
\ No newline at end of file \ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
var settings = require("../../../../config/settings");
class CacheService {
constructor() {
this.cacheManager = system.getObject("db.common.cacheManager");
}
async buildCacheRtn(pageValues) {
var ps = pageValues.map(k => {
var tmpList = k.split("|");
if (tmpList.length == 2) {
return { name: tmpList[0], val: tmpList[1], key: k };
}
});
return ps;
}
async findAndCountAll(obj) {
const pageNo = obj.pageInfo.pageNo;
const pageSize = obj.pageInfo.pageSize;
const limit = pageSize;
const offset = (pageNo - 1) * pageSize;
var search_name = obj.search && obj.search.name ? obj.search.name : "";
var cacheCacheKeyPrefix = "sadd_children_appkeys:" + settings.appKey + "_cachekey";
var cacheList = await this.cacheManager["MagCache"].getCacheSmembersByKey(cacheCacheKeyPrefix);
if (search_name) {
cacheList = cacheList.filter(f => f.indexOf(search_name) >= 0);
}
var pageValues = cacheList.slice(offset, offset + limit);
var kobjs = await this.buildCacheRtn(pageValues);
var tmpList = { results: { rows: kobjs, count: cacheList.length } };
return system.getResultSuccess(tmpList);
}
async delCache(obj) {
var keyList = obj.del_cachekey.split("|");
if (keyList.length == 2) {
var cacheCacheKeyPrefix = "sadd_children_appkeys:" + settings.appKey + "_cachekey";
await this.cacheManager["MagCache"].delCacheBySrem(cacheCacheKeyPrefix, obj.del_cachekey);
await this.cacheManager["MagCache"].del(keyList[0]);
return { status: 0 };
}
}
async clearAllCache(obj) {
await this.cacheManager["MagCache"].clearAll();
return { status: 0 };
}
}
module.exports = CacheService;
const system=require("../../../system");
const ServiceBase=require("../../sve.base");
var settings=require("../../../../config/settings");
class MetaService extends ServiceBase{
constructor(){
super("common",ServiceBase.getDaoName(MetaService));
}
async getApiDoc(appid){
var p=settings.basepath+"/app/base/db/impl/common/apiDocManager.js";
var ClassObj= require(p) ;
var obj=new ClassObj();
return obj.doc;
}
async getUiConfig(appid){
const cfg=await this.cacheManager["UIConfigCache"].cache(appid,null,60);
return cfg;
}
async getBaseComp(){
var basecomp=await this.apiCallWithAk(settings.paasUrl()+"api/meta/baseComp/getBaseComp",{});
return basecomp.basecom;
}
async findAuthsByRole(rolesarray, appid){
var result =await this.apiCallWithAk(settings.paasUrl()+"api/auth/roleAuth/findAuthsByRole",{
roles:rolesarray,
appid:appid
});
return result;
}
}
module.exports=MetaService;
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
var settings = require("../../../../config/settings");
class OplogService extends ServiceBase {
constructor() {
super("common", ServiceBase.getDaoName(OplogService));
//this.appDao=system.getObject("db.appDao");
this.opLogUrl = settings.apiconfig.opLogUrl();
this.opLogEsIsAdd = settings.apiconfig.opLogEsIsAdd();
}
async create(qobj) {
if (!qobj || !qobj.op || qobj.op.indexOf("metaCtl/getUiConfig") >= 0 ||
qobj.op.indexOf("userCtl/checkLogin") >= 0 ||
qobj.op.indexOf("oplogCtl") >= 0 ||
qobj.op.indexOf("getDicConfig") >= 0 ||
qobj.op.indexOf("getRouteConfig") >= 0 ||
qobj.op.indexOf("getRsConfig") >= 0) {
return null;
}
var rc = system.getObject("util.execClient");
var rtn = null;
try {
// var myDate = new Date();
// var tmpTitle=myDate.toLocaleString()+":"+qobj.optitle;
qobj.optitle = (new Date()).Format("yyyy-MM-dd hh:mm:ss") + ":" + qobj.optitle;
if (this.opLogEsIsAdd == 1) {
qobj.content = qobj.content.replace("field list", "字段列表")
qobj.created_at = (new Date()).getTime();
//往Es中写入日志
var addEsData = JSON.stringify(qobj);
rc.execPost(qobj, this.opLogUrl);
} else {
//解决日志大于4000写入的问题
if (qobj.content.length > 4980) {
qobj.content = qobj.content.substring(0, 4980);
}
this.dao.create(qobj);
}
} catch (e) {
console.log(e.stack, "addLog------error-----------------------*****************");
qobj.content = e.stack;
//解决日志大于4000写入的问题
if (qobj.content.length > 4980) {
qobj.content = qobj.content.substring(0, 4980);
}
this.dao.create(qobj);
}
}
async createDb(qobj) {
if (!qobj || !qobj.op || qobj.op.indexOf("metaCtl/getUiConfig") >= 0 ||
qobj.op.indexOf("userCtl/checkLogin") >= 0 ||
qobj.op.indexOf("oplogCtl") >= 0 ||
qobj.op.indexOf("getDicConfig") >= 0 ||
qobj.op.indexOf("getRouteConfig") >= 0 ||
qobj.op.indexOf("getRsConfig") >= 0) {
return null;
}
try {
qobj.optitle = (new Date()).Format("yyyy-MM-dd hh:mm:ss") + ":" + qobj.optitle;
//解决日志大于4000写入的问题
if (qobj.content.length > 4980) {
qobj.content = qobj.content.substring(0, 4980);
}
this.dao.create(qobj);
} catch (e) {
console.log(e.stack, "addLog------error-----------------------*****************");
qobj.content = e.stack;
//解决日志大于4000写入的问题
if (qobj.content.length > 4980) {
qobj.content = qobj.content.substring(0, 4980);
}
this.dao.create(qobj);
}
}
}
module.exports = OplogService;
const system=require("../../../system");
const ServiceBase=require("../../sve.base");
const fs=require("fs");
var excel = require('exceljs');
const uuidv4 = require('uuid/v4');
var path= require('path');
class TaskService extends ServiceBase{
constructor(){
super(ServiceBase.getDaoName(TaskService));
//this.appDao=system.getObject("db.appDao");
this.taskManager=system.getObject("db.taskManager");
this.emailClient=system.getObject("util.mailClient");
this.personTaxDao=system.getObject("db.individualincometaxDao");
this.ossClient=system.getObject("util.ossClient");
}
//写文件并上传到阿里云,返回上传的路径
async writexls(wb,sharecode){
var that=this;
var uuid=uuidv4();
var u=uuid.replace(/\-/g,"");
var fname="zc_"+u+".xlsx";
var filepath="/tmp/"+fname;
var promise=new Promise((resv,rej)=>{
wb.xlsx.writeFile(filepath).then(async function(d) {
var rtn=await that.ossClient.upfile(fname,filepath);
fs.unlink(filepath,function(err){});
return resv(rtn);
}).catch(function(e){
return rej(e);
});
});
return promise;
}
//读取模板文件
async readxls(){
var promise=new Promise((resv,rej)=>{
var workbook = new excel.Workbook();
workbook.properties.date1904 = true;
var bpth=path.normalize(path.join(__dirname, '../'));
workbook.xlsx.readFile(bpth+"/tmpl/tmpl.xlsx")
.then(function() {
return resv(workbook);
}).catch(function(e){
return rej(e);
});
});
return promise;
}
async buildworkbook(taxCalcList){
var workbook = await this.readxls();
var sheet = workbook.getWorksheet(1);
sheet.columns = [
{ header: '年度', key: 'statisticalYear', width: 10 },
{ header: '月份', key: 'statisticalMonth', width: 10 },
{ header: '员工姓名', key: 'employeeName', width: 10 },
{ header: '本月税前薪资', key: 'preTaxSalary', width: 18 },
{ header: '累计税前薪资', key: 'accupreTaxSalary', width: 18 },
// { header: '五险一金比例', key: 'insuranceAndFund', width: 18, outlineLevel: 1 },
{ header: '本月五险一金', key: 'insuranceAndFund', width: 18, outlineLevel: 1 },
{ header: '累计五险一金', key: 'accuinsuranceAndFund', width: 18, outlineLevel: 1 },
{ header: '子女教育', key: 'childrenEducation', width: 10 },
{ header: '继续教育', key: 'continuingEducation', width: 10 },
{ header: '房贷利息', key: 'interestExpense', width: 10 },
{ header: '住房租金', key: 'housingRent', width: 10 },
{ header: '赡养老人', key: 'supportElderly', width: 10 },
{ header: '大病医疗', key: 'illnessMedicalTreatment', width: 10 },
{ header: '专项扣除合计', key: 'specialDeduction', width: 10 },
{ header: '累计已扣专项', key: 'accuSpecialDeduction', width: 18, outlineLevel: 1 },
{ header: '累计已纳个税', key: 'accuPersonalIncomeTax', width: 18 },
{ header: '累计免征额', key: 'accuExemptionAmount', width: 10 },
{ header: '适用税率', key: 'taxRate', width: 10 },
{ header: '速算扣除', key: 'deductionNumber', width: 10 },
{ header: '本月应纳个税', key: 'personalIncomeTax', width: 18 },
{ header: '本月税后薪资', key: 'postTaxSalary', width: 18, outlineLevel: 1 }
// (累计税前薪资-累计五险一金-累计免征额-累计已扣专项)*税率-速算扣除-累计已纳个税=本月应纳个税
];
taxCalcList.forEach(r=>{
sheet.addRow(r);
});
return workbook;
}
async makerpt(qobj){
var self=this;
return this.db.transaction(async t=>{
const sharecode=qobj.sharecode;
const email=qobj.email;
//按照sharecode获取单位某次个税计算
var taxCalcList=await this.personTaxDao.model.findAll({where:{shareOnlyCode:sharecode},transaction:t});
var sheetNameSufix="个税汇总表";
if(taxCalcList && taxCalcList.length>0){
var year=taxCalcList[0].statisticalYear;
var month=taxCalcList[0].statisticalMonth;
sheetNameSufix=year+month+sheetNameSufix;
}
var wb=await this.buildworkbook(taxCalcList);
//生成excel
var result=await this.writexls(wb,sharecode);
//异步不等待发送邮件给
var html='<a href="'+result.url+'">'+sheetNameSufix+'</a>'
self.emailClient.sendMsg(email,sheetNameSufix,null,html,null,null,[]);
//发送手机短信
//写到按咋回哦sharecode,修改下载的url
return result.url;
});
}
async create(qobj){
var self=this;
return this.db.transaction(async t=>{
var task=await this.dao.create(qobj,t);
//发布任务事件
var action="new";
var taskClassName=task.taskClassName;
var exp=task.taskexp;
var msg=action+"_"+taskClassName+"_"+exp;
await self.taskManager.newTask(msg);
await self.taskManager.publish("task","newtask");
return task;
});
}
async restartTasks2(qobj){
return this.restartTasks(qobj);
}
async restartTasks(qobj){
var self=this;
var rtn={};
var tasks=await this.dao.model.findAll({raw:true});
//清空任务列表
await this.taskManager.clearlist();
for(var i=0;i<tasks.length;i++){
var tmpTask2=tasks[i];
try {
(async (tmpTask,that)=>{
var action="new";
var taskClassName=tmpTask.taskClassName;
var exp=tmpTask.taskexp;
var msg=action+"_"+taskClassName+"_"+exp;
// await that.taskManager.newTask(msg);
// await that.taskManager.publish("task","newtask");
await that.taskManager.addTask(taskClassName,exp);
})(tmpTask2,self);
} catch (e) {
rtn=null;
}
}
return rtn;
}
async delete(qobj){
var self=this;
return this.db.transaction(async t=>{
var task= await this.dao.model.findOne({where:qobj});
await this.dao.delete(task,qobj,t);
//发布任务事件
var action="delete";
var taskName=task.taskClassName;
var exp=task.taskexp;
var msg=action+"_"+taskName;
//发布任务,消息是action_taskClassName
await this.taskManager.publish("task",msg,null);
return task;
});
}
}
module.exports=TaskService;
...@@ -14,7 +14,7 @@ var settings={ ...@@ -14,7 +14,7 @@ var settings={
// port: 3306, // port: 3306,
host: '43.247.184.35', host: '43.247.184.35',
port: 8899, port: 8899,
timezone: '+08:00',
dialect: 'mysql', dialect: 'mysql',
operatorsAliases: false, operatorsAliases: false,
pool: { pool: {
......
{ {
"name": "xggsve-trade", "name": "xggsve-chance",
"version": "1.0.0", "version": "1.0.0",
"description": "h5framework", "description": "h5framework",
"main": "main.js", "main": "main.js",
......
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