Commit 4931b83b by 庄冰

接口优化

parent 73995d85
......@@ -6,7 +6,9 @@ const system = require("../../../system");
*/
class AliyunQcService{
constructor() {
this.needsolutionSve = system.getObject("service.dbneed.needsolutionSve");
this.needsolutionDao = system.getObject("db.dbneed.needsolutionDao");
this.needinfoDao = system.getObject("db.dbneed.needinfoDao");
this.orderinfoDao = system.getObject("db.dbcorder.orderinfoDao");
this.icpSolutionStatusReference = {
SOLUTION_SUBMIT: "提交服务单",
UN_PAID: "未支付", PAID: "用户支付", USER_UPLOADED: "用户上传资料", MATERIAL_UNCONFIRM: "服务商递交⽂件"
......@@ -35,13 +37,13 @@ class AliyunQcService{
return system.getResultFail(-101, "需求号不能为空");
}
//获取需求信息
var needinfo = await this.needsolutionSve.needinfoDao.model.findOne({
var needinfo = await this.needinfoDao.model.findOne({
where: { channelNeedNo: ab.needNo }, raw: true
});
if (!needinfo || !needinfo.id) {
return system.getResultFail(-102, "未知需求信息");
}
var ns = await this.needsolutionSve.dao.model.findAll({
var ns = await this.needsolutionDao.model.findAll({
where: { needNo: needinfo.needNo, createUserId: user.id }, raw: true,
attributes: ["needNo", "solutionNo", "channelSolutionNo", "orderNo", "solutionContent", "status", "statusName"]
});
......@@ -54,7 +56,7 @@ class AliyunQcService{
return system.getResultFail(-101, "方案编号不能为空");
}
//获取方案信息
var ns = await this.needsolutionSve.dao.model.findAll({
var ns = await this.needsolutionDao.model.findAll({
where: { channelSolutionNo: ab.BizId }, raw: true
});
return system.getResultSuccess(ns);
......@@ -71,11 +73,11 @@ class AliyunQcService{
return system.getResultFail(-101, "方案编号不能为空");
}
//获取方案信息
var ns = await this.needsolutionSve.dao.model.findOne({
var ns = await this.needsolutionDao.model.findOne({
where: { solutionNo: ab.solutionNo, createUserId: user.id }, raw: true
});
if (ns && ns.needNo) {
var needinfo = await this.needsolutionSve.needinfoDao.model.findOne({
var needinfo = await this.needinfoDao.model.findOne({
where: { needNo: ns.needNo }, raw: true,
attributes: ["publishName", "publishMobile", "channelUserId"]
});
......@@ -99,7 +101,7 @@ class AliyunQcService{
return system.getResultFail(-102, "方案信息有误");
}
//获取需求信息
var needinfo = await this.needsolutionSve.needinfoDao.model.findOne({
var needinfo = await this.needinfoDao.model.findOne({
where: { channelNeedNo: ab.needNo }, raw: true
});
if (!needinfo || !needinfo.id) {
......@@ -117,27 +119,28 @@ class AliyunQcService{
}
ab.solutionContent.typeCode = needinfo.typeCode;
ab.solutionContent.typeName = needinfo.typeName;
var ns = await this.needsolutionSve.dao.model.findAll({
var ns = await this.needsolutionDao.model.findAll({
where: { channelNeedNo: ab.needNo }, raw: true
});
for (var i = 0; i < ns.length; i++) {
var fa = ns[i];
if (fa.status != "yzf") {
if (fa.status == "dqr" || fa.status == "ywc") {
return system.getResultFail(-207, "需求方案已存在,不能重复提交");
}
}
if (!ab.solutionContent.solution) {
return system.getResultFail(-104, "业务方案信息不能为空");
}
// if (!ab.solutionContent.solution) {
// return system.getResultFail(-104, "业务方案信息不能为空");
// }
var solution = ab.solutionContent.solution;
if (!solution) {
return system.getResultFail(-103, "方案交付信息有误");
}
if (needinfo.channelTypeCode == "7") {//edi
ab.solutionContent.solution.IcpType = 2;
}
if (needinfo.channelTypeCode == "5") {//icp
}else if (needinfo.channelTypeCode == "5") {//icp
ab.solutionContent.solution.IcpType = 1;
}else{
return system.getResultFail(-208, "需求业务类型有误");
}
// ab.solutionContent.applicationStatusList = [{
// "OfficialFileURL": "",
......@@ -162,18 +165,15 @@ class AliyunQcService{
ab.solutionContent.statusName = this.icpSolutionStatusReference.SOLUTION_SUBMIT;
ab.solutionContent.solutionFlowList = solutionFlowList;
ab["channelNeedNo"] = needinfo.channelNeedNo;
var solutionNo = await this.needsolutionSve.getBusUid("ns");
var solutionNo = await this.getBusUid("ns");
ab["solutionNo"] = solutionNo;
ab["status"] = "dqr";
// ab.solutionContent["notes"] = "";
// ab.solutionContent["totalSum"] = "";
ab.solutionContent = JSON.stringify(ab.solutionContent);
var self = this;
return await this.needsolutionSve.db.transaction(async function (t) {
return await this.needsolutionDao.db.transaction(async function (t) {
ab["needNo"] = needinfo.needNo;
var od = await self.needsolutionSve.dao.create(ab, t);
var od = await self.needsolutionDao.create(ab, t);
if (od && od.id) {
// var pushflag = 0;//推送标志 值为1推送小记
var needObj = {
id: needinfo.id
};
......@@ -187,22 +187,20 @@ class AliyunQcService{
};
}
if (!needinfo.followContent) {
var followContent = {
var followContent = [{
followDate: new Date(),
content: "icp提交方案"
};
}];
followContent = JSON.stringify(followContent);
needObj["followContent"] = followContent;
// pushflag = 1;
}
await self.needsolutionSve.needinfoDao.update(needObj, t);
needinfo = await self.needsolutionSve.needinfoDao.model.findOne({
await self.needinfoDao.update(needObj, t);
needinfo = await self.needinfoDao.model.findOne({
where: { id: needinfo.id }, raw: true
});
// needinfo["pushflag"] = pushflag;
return system.getResultSuccess({ needinfo: needinfo, needsolution: od });
} else {
return system.getResultFail(-202, "提交方案失败");
return system.getResultFail(-302, "提交方案失败");
}
})
......@@ -221,33 +219,33 @@ class AliyunQcService{
return system.getResultFail(-106, "关闭理由不能为空");
}
//获取方案信息
var ns = await this.needsolutionSve.dao.model.findOne({
var ns = await this.needsolutionDao.model.findOne({
where: { channelSolutionNo: ab.BizId, createUserId: user.id }, raw: true
});
if (!ns || !ns.id) {
return system.getResultFail(-102, "未知方案");
return system.getResultFail(-300, "未知方案");
}
var needinfo = await this.needsolutionSve.needinfoDao.model.findOne({
var needinfo = await this.needinfoDao.model.findOne({
where: { needNo: ns.needNo }, raw: true
});
if (!needinfo) {
return system.getResultFail(-104, "未知方案需求");
return system.getResultFail(-400, "未知方案需求");
}
if (needinfo.status == "ycd" || needinfo.status == "ygb") {
return system.getResultFail(-105, "该方案需求状态为" + needinfo.statusName + ",不能执行此操作");
return system.getResultFail(-401, "该方案需求状态为" + needinfo.statusName + ",不能执行此操作");
}
if (ns.status != "dqr") {
return system.getResultFail(-103, "方案状态错误,只能废弃待确认方案");
return system.getResultFail(-301, "方案状态错误,只能废弃待确认方案");
}
var solutionContent = ns.solutionContent;
if (!solutionContent.status || ["USER_UPLOADED", "MATERIAL_UNCONFIRM", "USER_CONFIRMED", "ACCOUNT_REGISTERED", "MATERIAL_SUBMITTED"].indexOf(solutionContent.status) < 0) {
return system.getResultFail(-108, "方案流程状态错误,不能执行此操作");
}
// if (!solutionContent.status || ["USER_UPLOADED", "MATERIAL_UNCONFIRM", "USER_CONFIRMED", "ACCOUNT_REGISTERED", "MATERIAL_SUBMITTED"].indexOf(solutionContent.status) < 0) {
// return system.getResultFail(-302, "方案流程状态错误,不能执行此操作");
// }
solutionContent.serviceProviderNote = ab.Note;
solutionContent = JSON.stringify(solutionContent);
await this.needsolutionSve.dao.update({ id: ns.id, status: "yzf", solutionContent: solutionContent });//方案废弃
await this.needsolutionDao.update({ id: ns.id, status: "yzf", solutionContent: solutionContent });//方案废弃
//获取方案信息
ns = await this.needsolutionSve.dao.model.findOne({
ns = await this.needsolutionDao.model.findOne({
where: { channelSolutionNo: ab.BizId, createUserId: user.id }, raw: true
});
return system.getResultSuccess(ns);
......@@ -261,13 +259,13 @@ class AliyunQcService{
}
ab["createUserId"] = user.id;
if (!ab.BizId) {
return system.getResultFail(-101, "方案编号不能为空");
return system.getResultFail(-101, "渠道方案编号不能为空");
}
if (!ab.material) {
return system.getResultFail(-102, "材料信息有误");
}
//获取方案信息
var needsolutioninfo = await this.needsolutionSve.dao.model.findOne({
var needsolutioninfo = await this.needsolutionDao.model.findOne({
where: { channelSolutionNo: ab.BizId }, raw: true
});
if (!needsolutioninfo || !needsolutioninfo.id) {
......@@ -284,7 +282,7 @@ class AliyunQcService{
return system.getResultFail(-403, "用户未上传材料,不能执行此操作");
}
//获取需求信息
var needinfo = await this.needsolutionSve.needinfoDao.model.findOne({
var needinfo = await this.needinfoDao.model.findOne({
where: { needNo: needsolutioninfo.needNo }, raw: true
});
if (!needinfo || !needinfo.id) {
......@@ -319,9 +317,9 @@ class AliyunQcService{
solutionContent.statusName = this.icpSolutionStatusReference.MATERIAL_UNCONFIRM;
needsolutioninfo.solutionContent = JSON.stringify(solutionContent);
var self = this;
return await this.needsolutionSve.db.transaction(async function (t) {
await self.needsolutionSve.dao.update(needsolutioninfo, t);
needsolutioninfo = await self.needsolutionSve.dao.model.findOne({
return await this.needsolutionDao.db.transaction(async function (t) {
await self.needsolutionDao.update(needsolutioninfo, t);
needsolutioninfo = await self.needsolutionDao.model.findOne({
where: { channelSolutionNo: ab.BizId }, raw: true
});
return system.getResultSuccess(needsolutioninfo);
......@@ -343,7 +341,7 @@ class AliyunQcService{
return system.getResultFail(-102, "通知状态不能为空");
}
//获取方案信息
var needsolutioninfo = await this.needsolutionSve.dao.model.findOne({
var needsolutioninfo = await this.needsolutionDao.model.findOne({
where: { channelSolutionNo: ab.BizId }, raw: true
});
if (!needsolutioninfo || !needsolutioninfo.id) {
......@@ -356,8 +354,9 @@ class AliyunQcService{
if (!solutionContent) {
return system.getResultFail(-402, "方案交付信息有误");
}
if(solutionContent.)
//获取需求信息
var needinfo = await this.needsolutionSve.needinfoDao.model.findOne({
var needinfo = await this.needinfoDao.model.findOne({
where: { needNo: needsolutioninfo.needNo }, raw: true
});
if (!needinfo || !needinfo.id) {
......@@ -431,9 +430,9 @@ class AliyunQcService{
solutionContent.solutionFlowList = solutionFlowList;
needsolutioninfo.solutionContent = JSON.stringify(solutionContent);
var self = this;
return await this.needsolutionSve.db.transaction(async function (t) {
await self.needsolutionSve.dao.update(needsolutioninfo, t);
needsolutioninfo = await self.needsolutionSve.dao.model.findOne({
return await this.needsolutionDao.db.transaction(async function (t) {
await self.needsolutionDao.update(needsolutioninfo, t);
needsolutioninfo = await self.needsolutionDao.model.findOne({
where: { channelSolutionNo: ab.BizId }, raw: true
});
statusObj["BizId"] = ab.BizId;
......@@ -451,13 +450,13 @@ class AliyunQcService{
return system.getResultFail(-102, "方案状态不能为空");
}
//获取方案信息
var ns = await this.needsolutionSve.dao.model.findOne({
var ns = await this.needsolutionDao.model.findOne({
where: { channelSolutionNo: ab.BizId }, raw: true
});
if (!ns || !ns.id) {
return system.getResultFail(-102, "未知方案");
}
var needinfo = await this.needsolutionSve.needinfoDao.model.findOne({
var needinfo = await this.needinfoDao.model.findOne({
where: { needNo: ns.needNo }, raw: true
});
if (!needinfo) {
......@@ -534,8 +533,8 @@ class AliyunQcService{
// else if(ab.status == "2" || ab.status == "4"){ //2, "⽤户已上传" 4, "⽤户已确认"
// updateObj["status"]="dqr";
// }
await this.needsolutionSve.dao.update(updateObj);//方案状态修改
ns = await this.needsolutionSve.dao.model.findOne({
await this.needsolutionDao.update(updateObj);//方案状态修改
ns = await this.needsolutionDao.model.findOne({
where: { channelSolutionNo: ab.BizId }, raw: true
});
return system.getResultSuccess(ns);
......@@ -553,7 +552,7 @@ class AliyunQcService{
return system.getResultFail(-103, "需求当前状态不能为空");
}
//获取需求信息
var needinfo = await this.needsolutionSve.needinfoDao.model.findOne({
var needinfo = await this.needinfoDao.model.findOne({
where: { channelNeedNo: ab.intentionBizId }, raw: true
});
if (!needinfo) {
......@@ -563,7 +562,7 @@ class AliyunQcService{
return system.getResultFail(-105, "该方案需求状态为" + needinfo.statusName + ",不能执行此操作");
}
//获取方案信息
var ns = await this.needsolutionSve.dao.model.findOne({
var ns = await this.needsolutionDao.model.findOne({
where: { channelNeedNo: ab.intentionBizId, status: "dqr" }, raw: true
});
if (!ns) {
......@@ -588,7 +587,7 @@ class AliyunQcService{
solutionContent.needStatusName = intentionStatusList[ab.intentionStatus];
solutionContent = JSON.stringify(solutionContent);
updateObj["solutionContent"] = solutionContent;
await this.needsolutionSve.dao.update(updateObj);//方案状态修改
await this.needsolutionDao.update(updateObj);//方案状态修改
return system.getResultSuccess();
}
//接收方案编号(方案推送至阿里后,接收保存方案信息)
......@@ -600,13 +599,13 @@ class AliyunQcService{
if (!ab.solutionNo) {
return system.getResultFail(-102, "方案业务编号不能为空");
}
var ns = await this.needsolutionSve.dao.model.findOne({
var ns = await this.needsolutionDao.model.findOne({
where: { solutionNo: ab.solutionNo }, raw: true
});
if (!ns || !ns.id) {
return system.getResultFail(-103, "未知方案");
}
var needinfo = await this.needsolutionSve.needinfoDao.model.findOne({
var needinfo = await this.needinfoDao.model.findOne({
where: { needNo: ns.needNo }, raw: true
});
if (!needinfo) {
......@@ -615,9 +614,51 @@ class AliyunQcService{
if (needinfo.status == "ycd" || needinfo.status == "ygb") {
return system.getResultFail(-105, "该方案需求状态为" + needinfo.statusName + ",不能执行此操作");
}
await this.needsolutionSve.dao.model.update({ channelSolutionNo: ab.solutionBizId }, { where: { id: ns.id } });//修改方案信息
await this.needsolutionDao.model.update({ channelSolutionNo: ab.solutionBizId }, { where: { id: ns.id } });//修改方案信息
return system.getResultSuccess();
}
/*
返回20位业务订单号
prefix:业务前缀
*/
async getBusUid(prefix) {
prefix = (prefix || "");
if (prefix) {
prefix = prefix.toUpperCase();
}
var prefixlength = prefix.length;
var subLen = 8 - prefixlength;
var uidStr = "";
if (subLen > 0) {
uidStr = await this.getUidInfo(subLen, 60);
}
var timStr = moment().format("YYYYMMDDHHmm");
return prefix + timStr + uidStr;
}
/*
len:返回长度
radix:参与计算的长度,最大为62
*/
async getUidInfo(len, radix) {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');//长度62,到yz长度为长36
var uuid = [], i;
radix = radix || chars.length;
if (len) {
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else {
var r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
}
}
return uuid.join('');
}
}
module.exports = AliyunQcService;
......
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