Commit e767aff8 by Sxy

feat: 批量创建需求

parent 4fb323fc
var system = require("../../../system");
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const moment = require("moment");
class BizbatchCtl extends CtlBase {
constructor() {
super("bizchance", CtlBase.getServiceName(BizbatchCtl));
}
async create(pobj, qobj, req) {
try {
if (!pobj.batchArray || !Array.isArray(pobj.batchArray) || pobj.batchArray.length > 20 || pobj.batchArray.length <= 0) {
throw new Error("参数错误");
}
const rs = await this.service.create(pobj);
return system.getResult(rs);
} catch (err) {
return system.getResult(null, err.message)
}
}
async detail(pobj, qobj, re) {
try {
if (!pobj.id) {
throw new Error("参数错误");
}
const rs = await this.service.detail(pobj);
return system.getResult(rs);
} catch (err) {
return system.getResult(null, err.message)
}
}
}
module.exports = BizbatchCtl;
const system = require("../../../system");
const Dao = require("../../dao.base");
class BizbatchDao extends Dao {
constructor() {
super(Dao.getModelName(BizbatchDao));
}
}
module.exports = BizbatchDao;
......@@ -5,25 +5,33 @@ const appconfig = system.getSysConfig();
* 商机批次表
*/
module.exports = (db, DataTypes) => {
return db.define("bizopt", {
business_bath: { // 需求批次
return db.define("bizbatch", {
batchNumber: { // 需求批次
allowNull: false,
type: DataTypes.STRING
},
business_type: { // 商机数量
allowNull: false,
type: DataTypes.INTEGER
},
business_info: { // 批次详情
batchInfo: { // 批次详情
allowNull: false,
type: DataTypes.JSON
},
business_salesman: { // 业务员
processingStatus: { // 处理状态 processing(处理中) success(成功)
allowNull: false,
type: DataTypes.STRING,
},
paymentLink: { // 支付链接
allowNull: true,
type: DataTypes.STRING
},
payment_link: {
allowNull: false,
createrId: { //创建人id
allowNull: true,
type: DataTypes.STRING
},
createrName: { // 创建人名称
allowNull: true,
type: DataTypes.STRING
},
createrOpcode: {// 创建人 组织结构路径
allowNull: true,
type: DataTypes.STRING
}
}, {
......@@ -33,7 +41,7 @@ module.exports = (db, DataTypes) => {
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'bussiness_opportunity_bath',
tableName: 'bussiness_bath',
validate: {
},
......
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const moment = require("moment");
const uuidv4 = require('uuid/v4');
const _ = require("lodash")
const pushQft = require("../../../utils/toqifutongClient")
class BizbatchService extends ServiceBase {
constructor() {
super("bizchance", ServiceBase.getDaoName(BizbatchService));
this.bizoptDao = system.getObject("db.bizchance.bizoptDao");
}
async create(pobj) {
let batchInfo = pobj.batchArray.map(item => {
item.uniqueCode = uuidv4()
return item;
})
let data = {
batchNumber: new Date().getTime(),
batchInfo,
processingStatus: 'processing',
createrId: pobj.userid,
createrName: pobj.username,
createrOpcode: pobj.opath
}
await pushQft.batchCreateBiz({
batchNumber: data.batchNumber,
demands: batchInfo
});
let result = await this.dao.create(data);
return result;
}
async findAndCountAll(pobj) {
let result = await this.dao.findAndCountAll(pobj);
if (result.results.count > 0) {
let rows = [];
let demandCodes = []
for (let val of result.results.rows) {
rows.push({
id: val.id,
batchNumber: val.batchNumber,
processingStatus: val.processingStatus,
payStatus: "waitPay",
paymentLink: val.paymentLink,
createrName: val.createrName,
createrId: val.createrId,
created_at: moment(val.created_at).format('YYYY-MM-DD HH:mm:ss'),
updated_at: moment(val.updated_at).format('YYYY-MM-DD HH:mm:ss'),
demandCodeSum: val.batchInfo.length,
demandCodes: val.batchInfo.filter(item => item.demandCode).map(item => {
return item.demandCode
})
})
if (val.processingStatus === "success") {
demandCodes.push(...val.batchInfo.map(item => {
return item.demandCode
}));
}
}
let demandData = await this.bizoptDao.findAll({
demand_code: {
$in: demandCodes,
},
business_status: system.BUSSTATUS.SUCCESS
});
demandCodes = demandData.map(item => item.demand_code);
for (let val of rows) {
if (val.processingStatus === "success") {
val.payStatus = _.intersection(val.demandCodes, demandCodes).length > 0 ? "successPay" : val.payStatus;
}
}
result.results.rows = rows;
}
return result;
}
async detail(pobj) {
let bizbatchData = await this.dao.findOne({
id: pobj.id
});
if (!bizbatchData) {
return []
} else {
let demandCodes = bizbatchData.batchInfo.filter(item => item.demandCode).map(item => {
return item.demandCode
});
let bizoptData = await this.bizoptDao.findAll({
demand_code: {
$in: demandCodes
}
});
return bizoptData.map(item => {
return {
id: item.id,
demand_code: item.demand_code,
business_type: item.business_type,
customer_name: item.business_info.contactsName,
customer_number: item.business_info.contactsPhone,
service_name: item.business_info.serviceName,
business_status: item.business_status,
memo_info: item.business_info.memoInfo,
created_at: moment(item.created_at).format('YYYY-MM-DD HH:mm:ss'),
}
})
}
}
}
module.exports = BizbatchService;
......@@ -3,8 +3,11 @@ const settings = require("../../config/settings");
const system = require("../system");
const centerChannelUrl = settings.centerChannelUrl();
const qifutongUrl = settings.qifutongUrl();
const queueUrl = settings.queueUrl();
const { appKey, secret } = settings;
const OSS = system.getObject("util.ossClient");
const uuidv4 = require('uuid/v4');
axios.defaults.timeout = 3 * 1000; // 4s
......@@ -18,7 +21,7 @@ const ALISTATUS = {
THROUGHFAIL: 512 // 工信部未通过
}
const getAppTokenByAppKey = async () => {
const getAppTokenByAppKey = async (appKey, secret) => {
const data = await postRequest(`${centerChannelUrl}/api/opreceive/accessAuth/getAppTokenByAppKey`,
{
"actionType": "getAppTokenByAppKey",
......@@ -30,8 +33,8 @@ const getAppTokenByAppKey = async () => {
return data.token
}
const getLoginByUserName = async (mobile) => {
const token = await getAppTokenByAppKey();
const getLoginByUserName = async (mobile, appKey, secret) => {
const token = await getAppTokenByAppKey(appKey, secret);
const data = await postRequest(`${centerChannelUrl}/api/opreceive/accessAuth/springBoard`,
{
"actionType": "getLoginByUserName",
......@@ -190,6 +193,28 @@ const closeDelivery = async (deliverData, sendMessage = {}) => {
});
}
/**
* 批量创建商机
* @param {*} data
*/
const batchCreateBiz = async (data) => {
const header = await getLoginByUserName('18911818357', "201912031344", "7cbb846246874167b5c7e01cd0016c88");
await pushQueue({
"actionType": "produceData",// Y 功能名称
"actionBody": {
"pushUrl": "http://center-tmtransaction-service/web/opreceive/need/springBoard",//"http://192.168.200.232:8002/testCallback" || Y 推送地址
"actionType": "needBatchUpload",// Y 推送地址接收时的功能名称
"notifyUrl": "http://paas-service.newtime/entService/order/springBoard",// N 推送成功后通知的Url
"identifyCode": "batchCreateBiz",// Y 操作的业务标识
"messageBody": data,
"headData": {
...header,
}
},
"requestId": uuidv4() // N 请求id
})
}
/**
......@@ -198,12 +223,11 @@ const closeDelivery = async (deliverData, sendMessage = {}) => {
* @param {*} data
*/
const pushQiFuTong = async (mobile, data) => {
const header = await getLoginByUserName(mobile);
const header = await getLoginByUserName(mobile, appKey, secret);
await postRequest(`${qifutongUrl}/web/action/qcapi/springBoard`, data, header);
}
/**
* 发送请求
* @param {*} url
......@@ -234,12 +258,34 @@ const postRequest = async (url, data, headers = {}) => {
}
}
/**
* 推送 队列 方法
* @param {*} data
*/
const pushQueue = async (data) => {
try {
console.log("推送消息队列请求数据 ------- ");
console.log(JSON.stringify(data))
let result = await axios.post(queueUrl, data);
result = result.data;
console.log("消息队列返回数据 ------- ");
console.log(result);
if (result.status === 1) {
return result.data
} else {
throw new Error(result.message)
}
} catch (err) {
console.log("------ 消息队列err -----");
console.log(err)
throw (err)
}
}
module.exports = {
submitMaterials,
ALISTATUS,
changeStatus,
closeDelivery
closeDelivery,
batchCreateBiz
}
\ No newline at end of file
......@@ -44,7 +44,7 @@ var settings = {
if (this.env == "dev") {
return "http://alitm.qifu-dev.gongsibao.com";
} else {
return "http://alitm.qifu.gongsibao.com";
return "http://center-channel-service.chaolai";
}
},
qifutongUrl: function () {//---------center-channel
......@@ -54,6 +54,13 @@ var settings = {
return "https://fqgsbweb.gongsibao.com";
}
},
queueUrl: function () {
if (this.env == "dev") {
return "http://192.168.18.101:4018/api/queueAction/producer/springBoard";
} else {
return "http://sytxpublic-msgq-service.chaolai/api/queueAction/producer/springBoard";
}
},
pmappid: 1,
pmcompanyid: 1,
pmroleid: { "ta": 1, "pr": 2 },
......
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