Skip to content

Instantly share code, notes, and snippets.

@bluemoon2014
Last active April 26, 2018 01:57
Show Gist options
  • Save bluemoon2014/8d8bf7bc2af0e2b5b0097330ccc365b7 to your computer and use it in GitHub Desktop.
Save bluemoon2014/8d8bf7bc2af0e2b5b0097330ccc365b7 to your computer and use it in GitHub Desktop.
重构后的路由
/**
* Created by myc on 2018/4/16.
*/
var express = require('express');
var managerBidBackAndIssue = express.Router();
var bidBackAndIssueSQLServer = require('../server/BidBackAndIssueSQLServer.js');
var bidQKLServer = require('../server/BidQKLServer.js');
var bidIssueDetailSQLServer = require("../server/BidIssueDetailSQLServer.js");
var bidAttachSQLServer = require("../server/AttachSQLServer.js");
var bidSegSQLServer = require("../server/BidSegSQLServer.js");
var bidParterSQLServer = require("../server/BidPartnerSQLServer.js");
var logSQLServer = require('../server/LogSQLServer.js');
var logQKLServer = require('../server/LogQKLServer.js');
var logUtil = require("../utils/logUtil.js");
var commonUtil = require("../utils/commonUtil.js");
var responseUtil = require("../utils/responseUtil");
//区块链用的 拼接参数
const BID_BACK_CONTENT_ARRAY = [
"code",
"bidCode",
"backDate",
"backAmount",
"description",
"created"
];
const BID_ATTACH_CONTENT_ARRAY = [
"code",
"refType",
"refCode",
"name",
"path",
"size",
"mimeType",
"description",
"accCode",
"created"
];
const BID_ISSUE_CONTENT_ARRAY = ["code", "bidCode", "issueDate", "openDate", "description", "created"];
const BID_WIN_SEG_CONTENT_ARRAY = [
"code",
"refCode",
"name",
"contractPlan",
"expectFee",
"description",
"created"
];
const BID_ISSUE_FEE_CONTENT_ARRAY = [
"code",
"refCode",
"contractPlan",
"fee",
"expectFee",
"description",
"created"
];
const BID_ISSUE_DETAIL_CONTENT_ARRAY = [
"code",
"refCode",
"orgCode",
"segName",
"date",
"expectAmount",
"amount",
"description",
"created"
];
var filter = require("../domain/filter");
managerBidBackAndIssue.use(filter.checkToken);
//处理Post请求需要的
var bodyParser = require("body-parser");
managerBidBackAndIssue.use(bodyParser.urlencoded({extended : false}));
/* GET users listing. *///?
managerBidBackAndIssue.get('/', function (req, res) {
res.send('respond with a resource');
});
//useful
//返回查询到的attach 对象数组(有记录在案)
//传入code 数组
function queryBidAttachByCodesAndReturnRecordedAttachs(_codes) {
return new Promise(function (resolve, reject) {
Promise.all(_codes.map(function (code) {
return bidAttachSQLServer.queryAttachByCode(code);
})).then(function (results) {
var attachs_ = results.map(function (attachs) {
if (attachs.length > 0) return attachs[0];
});
resolve(attachs_);
}).catch(reject);
});
}
//useful
//修改所关联的附件 results 是查出来的附件
//如果要修改的附件不存在 则添加
//如果要修改的附件存在 则不做什么
//如果已经存在的附件不在修改的附件中,则删除
//如果么有传attach字段 则不改什么
function dealAttachCodesWithRefcodeReturnModifiedAttachs(attachCodes, refCode, attachReftype) {
return new Promise(function(resolve, reject) {
var attachObjcResults;
var existCodes;
var updated = []; // 存入修改记录
bidAttachSQLServer.queryBindAttach(refCode).then(function (recordAttachs) {
attachObjcResults = recordAttachs;
existCodes = attachObjcResults.map(function (AttachObjcResult) {
return AttachObjcResult.code;
});
//没有这个参数 则什么都不做
if (!attachCodes) {
resolve(updated);
return;//不进行一下操作 因为无值
}
//修改为空数组 无记录
if (Array.isArray(attachCodes) && attachCodes.length == 0 && commonUtil.isEmpty(attachObjcResults)){
resolve(updated);
return;
}
//修改是空数组 有记录附件
if (Array.isArray(attachCodes) && attachCodes.length == 0 && commonUtil.isNotEmpty(attachObjcResults)){
attachObjcResults.forEach(function (attachobjcResult) {
attachobjcResult.refCode = "null";
attachobjcResult.refType = 0;
attachobjcResult.status = 0;//0表示删除 1 修改
updated.push(attachobjcResult);
});
resolve(updated);
return;
}
return queryBidAttachByCodesAndReturnRecordedAttachs(attachCodes);
}).then(function (newRecordedAttachs) {
if (newRecordedAttachs.length == 0) {
resolve(updated);
return;
}
//修改时非空数组 无记录 则增加
if (commonUtil.isNotEmpty(newRecordedAttachs) && commonUtil.isEmpty(attachObjcResults)) {
newRecordedAttachs.forEach(function (recordedAttach) {
recordedAttach.refCode = refCode;
recordedAttach.refType = attachReftype;
updated.push(recordedAttach);
})
resolve(updated);
return;
}
var newRecordAttachCodes = newRecordedAttachs.map(function (currentAttach) {
return currentAttach.code;
});
var equalCodes = newRecordAttachCodes.filter(function (currentCode) {
return existCodes.indexOf(currentCode) !== -1;
});
//修改时非空数组 有记录
if (commonUtil.isNotEmpty(newRecordedAttachs) && commonUtil.isNotEmpty(attachObjcResults)) {
newRecordedAttachs.forEach(function (currentNewAttach) {
//不匹配
if (equalCodes.indexOf(currentNewAttach.code) == -1) {
currentNewAttach.refCode = refCode;
currentNewAttach.refType = attachReftype;
updated.push(currentNewAttach);
}
});
//不匹配 删除
attachObjcResults.forEach(function (currentResultAttach) {
if (equalCodes.indexOf(currentResultAttach.code) == -1) {
currentResultAttach.refType = 0;
currentResultAttach.refCode = "null";
updated.push(currentResultAttach);
}
});
resolve(updated);
}
return;
}).catch(reject);
});
}
//-------------------------mycBegin---------------------
//检查修改表的 参数 包含了附件信息
//确保附件是有内容的数组 或者是空数组 或者是null
function checkBackModInputParams(params) {
return new Promise(function (resolve, reject) {
// check params
if (commonUtil.isEmpty(params.code)) {
reject("[回标编号]必须输入");
return;
}
var attachs = params.attachs;
if (commonUtil.isNotEmpty(attachs)) {
if(!Array.isArray(attachs)) {
reject("附件参数错误");
return;
}
attachs = attachs.filter(function (attach) {
return commonUtil.isNotEmpty(attach)
});
}
params.attachs = attachs;
resolve(attachs);
});
}
//已经上传的附件(attachCode) 查询SQL是否有记录 并把有的记录返回 + 绑定到的主表的信息
function queryAttachFromSQLAndBindInfo(attachs, bidBackCode, attachRefType, user, txOption){
return new Promise(function(resolve, reject) {
var updated = [];
if (commonUtil.isEmpty(attachs)) {
resolve(updated);//为空则
} else {
// 处理附件的code
var promiseArray = attachs.map(function (attachCode) {
return bidAttachSQLServer.queryAttachByCode(attachCode);
});
Promise.all(promiseArray).then(function(results){
console.log("查找到的附件格式");
console.log(results);
results.forEach(function (attachObjcs) {
if (commonUtil.isNotEmpty(attachObjcs)) {
updated.push({
refCode : bidBackCode,
refType:attachRefType,
code : attachObjcs[0].code,
name : attachObjcs[0].name,
path : attachObjcs[0].path,
status : 1 // 0 表示己经删除, 1 表示修改
});
} else {
reject("找不到相关附件");
}
});
//区块链 TODO
}).then(function () {
resolve(updated);
}).catch(function (error) {
reject(error);
});
}
});
}
//增加回标信息
//"bidCode","backDate","backAmount","description",
managerBidBackAndIssue.post("/addBidBack",function(req, res){
var txOption, bidBackCode, user, bidBackLogInfo;
var params = req.body;
checkBidBackParamsAttachs(params).then(function(attachs){
txOption = accountUtil.transactionOptionForEx(req.session);
bidBackCode = commonUtil.getUUID("bidBack"); //自动随机拼接编号生成
params.code = bidBackCode;
user = req.session.user;
bidBackLogInfo = {
dataName : "",
module : "招标回标",
func : "addBidBack",
businessID : bidBackCode,
operator : user.userName,
operateTime : logUtil.getFormatByTime(),
operateDesc : "加入回标信息"
}
params.created = new Date();
timeLog("开始查询oracle 附件");
return queryAttachFromSQLAndBindInfo(attachs, bidBackCode, 5, user, txOption);
}).then(function(updatedAttachsWithBindInfo) {
timeLog("开始绑定附件到回标");
bidBackLogInfo.other = JSON.stringify(updatedAttachsWithBindInfo);
return bindWithAttachSQL(updatedAttachsWithBindInfo);
}).then(function() {
timeLog("开始增加区块链回标");
return bidQKLServer.addBidBackInfo(commonUtil.join(params, BID_BACK_CONTENT_ARRAY), txOption);
}).then(function (receipt) {
timeLog("开始写日志");
bidBackLogInfo.blockNumber = receipt.blockNumber.toString();
bidBackLogInfo.blockHash = receipt.blockHash;
bidBackLogInfo.transactionHash = receipt.transactionHash;
return logQKLServer.writeLog(bidBackLogInfo, receipt, txOption);
}).then(function () {
timeLog("开始写入oracle 回标");
params.blockNumber = bidBackLogInfo.blockNumber;
params.blockHash = bidBackLogInfo.blockHash;
params.transactionHash = bidBackLogInfo.transactionHash;
return bidBackAndIssueSQLServer.addBidBackInfo(params);
}).then(function () {
timeLog("开始写入日志");
return logSQLServer.writeLog(bidBackLogInfo);
}).then(function () {
timeLog("响应给客户端");
responseUtil.sendSuccess(res, {});
console.log("成功-----------加入回标 ------------数据库");
}).catch(function (error) {
console.error(error);
responseUtil.sendError(res, error);
});
});
/* 修改回标 */
managerBidBackAndIssue.post('/modBidBackInfo', function (req, res) {
var txOption, bidBackCode, user, bidBackLogInfo, attachs;
var params = req.body;
checkBackModInputParams(params).then(function (ats) {
attachs = ats;
return bidBackAndIssueSQLServer.queryBidBackInfoByCode(params);//oracle数据
}).then(function (results) {
//检查的逻辑在这 确保回标存在
if (commonUtil.isEmpty(results)) {
throw new Error("未找到相关合同数据");
} else {
txOption = accountUtil.transactionOptionForEx(req.session);
bidBackCode = params.code;
user = req.session.user;
bidBackLogInfo = {
dataName : params.name || results[0].name,
module : "回标模块",
func : "modBidBackInfo",
businessID : bidBackCode,
operator : user.userName,
operateTime : logUtil.getFormatByTime(),
operateDesc : "修改回标",
other : params.other
};
}
return bidAttachSQLServer.queryBindAttach(bidBackCode);
}).then(function (results) { // 修改附件的操作指南
return dealAttachCodesWithRefcodeReturnModifiedAttachs(attachs, results, bidBackCode, 5, user, txOption);
}).then(function (updated) {
//修改附件
bidBackLogInfo.other = JSON.stringify(updated);
return bindWithAttachSQL(updated);//未加区块链
}).then(function () {
// 将修改后的合同写入区块链
var txContent = commonUtil.join(params, BID_BACK_CONTENT_ARRAY);
console.debug("txContent : " + txContent);
return bidQKLServer.modBidBackInfo(txContent, txOption);
}).then(function (receipt) {
//写入日志 (区块链)
bidBackLogInfo.blockNumber = receipt.blockNumber.toString();
bidBackLogInfo.blockHash = receipt.blockHash;
bidBackLogInfo.transactionHash = receipt.transactionHash;
return logQKLServer.writeLog(bidBackLogInfo, receipt, txOption);
}).then(function () {
//oracle 写入表
params.blockNumber = bidBackLogInfo.blockNumber;
params.blockHash = bidBackLogInfo.blockHash;
params.transactionHash = bidBackLogInfo.transactionHash;
return bidBackAndIssueSQLServer.modBidBackInfo(params);
}).then(function () {
return logSQLServer.writeLog(bidBackLogInfo);
}).then(function () {
responseUtil.sendSuccess(res, {});
console.log("成功-----------修改回标 ------------数据库");
}).catch(function (error) {
console.error(error);
responseUtil.sendError(res, error);
});
});
/* 查询回标 by code */
managerBidBackAndIssue.post('/getBidBackByCode', function (req, res) {
var user = req.session.user;
bidBackAndIssueSQLServer.queryBidBackInfoByCode(req.body).then(function (results) {
if(commonUtil.isEmpty(results)) {
responseUtil.sendSuccess(res, results);
} else {
bidAttachSQLServer.queryBindAttach(results[0].code).then(function (attachs) {
results[0].attachs = attachs;
console.log("成功-----------查询回标 ------------数据库");
responseUtil.sendSuccess(res, results);
logUtil.writeLogSingleDB(results[0].name, results[0].blockNumber, results[0].blockHash, results[0].transactionHash,
user.accCode, "招标计划模块", "getBid", results[0].code, user.userName, logUtil.getFormatByTime(), user.depName);
});
}
}).catch(function (error) {
console.error(error);
responseUtil.sendError(res, error);
});
});
/* 查询回标列表 */
managerBidBackAndIssue.post('/getBidBackList', function (req, res) {
var user = req.session.user;
bidBackAndIssueSQLServer.getBidBackList(req.body).then(function (results) {
console.log("成功-----------查询回标列表 ------------数据库");
responseUtil.sendSuccess(res, results);
if (commonUtil.isNotEmpty(results)) {
logUtil.writeLogSingleDB(results[0].name, results[0].blockNumber, results[0].blockHash, results[0].transactionHash,
user.accCode, "回标", "getBidBackList", results[0].code, user.userName, logUtil.getFormatByTime(), "查询回标列表");
}
}).catch(function (error) {
console.error(error);
responseUtil.sendError(res, error);
});
});
/* 区块链 查询合同 TEST */
managerBidBackAndIssue.post('/getContractQKL', function (req, res) {
var txOption = accountUtil.transactionOptionForEx(req.session);
var contractCode = req.body.code;
contractQKLServer.queryContractInfo(contractCode, txOption).then(function (result) {
console.log("成功-----------查询合同 ------------区块链");
responseUtil.sendSuccess(res, result);
}).catch(function (error) {
console.error(error);
responseUtil.sendError(res, error);
});
});
/* 区块链 查询合同 TEST */
managerBidBackAndIssue.post('/getAttachQKL', function (req, res) {
var txOption = accountUtil.transactionOptionForEx(req.session);
var contractCode = req.body.code;
contractQKLServer.queryContractAttachment(contractCode, txOption).then(function (result) {
console.log("成功-----------查询合同 ------------区块链");
responseUtil.sendSuccess(res, result);
}).catch(function (error) {
console.error(error);
responseUtil.sendError(res, error);
});
});
/* 合同修改记录
* @param contractCode
*
* */
managerBidBackAndIssue.post('/queryModLogs', function (req, res) {
var params = req.body;
params.func = "modContract";
params.businessID = params.code;
logSQLServer.queryLogByFunc(params).then(function (result) {
responseUtil.sendSuccess(res, result);
}).catch(function (error) {
console.error(error);
responseUtil.sendError(res, error);
});
});
/* 合同查询记录
*
* @param contractCode
*
* */
managerBidBackAndIssue.post('/queryGetLogs', function (req, res) {
var params = req.body;
params.func = "getContract";
params.businessID = params.code;
logSQLServer.queryLogByFunc(params).then(function (result) {
responseUtil.sendSuccess(res, result);
}).catch(function (error) {
console.error(error);
responseUtil.sendError(res, error);
});
});
//-------------------------发标开始---------------------
//检查发标增加时的参数
function checkBidIssueAddInputParams(params) {
return new Promise(function (resolve, reject){
if (commonUtil.isEmpty(params.bidCode)) {
reject("[招标编号] 必须输入");
return;
}
if (commonUtil.isEmpty(params.issueDate)) {
reject("[发标时间] 必须输入");
return;
}
if (commonUtil.isEmpty(params.openDate)) {
reject("[开标时间] 必须输入");
return;
}
if (commonUtil.isEmpty(params.description)) {
reject("[发标描述] 必须输入");
return;
}
var attachs = params.attachs;
if (commonUtil.isNotEmpty(attachs)) {
if(!Array.isArray(attachs)) {
reject("附件参数错误");
return;
}
attachs = attachs.filter(function (attach) {
return commonUtil.isNotEmpty(attach)
});
}
resolve(attachs);
});
}
//检查修改表的 参数 包含了附件信息
//确保附件是有内容的数组 或者是空数组 或者是null
function checkIssueModInputParams(params) {
return new Promise(function (resolve, reject) {
// check params
if (commonUtil.isEmpty(params.code)) {
reject("[发标编号]必须输入");
return;
}
var attachs = params.attachs;
if (commonUtil.isNotEmpty(attachs)) {
if(!Array.isArray(attachs)) {
reject("附件参数错误");
return;
}
attachs = attachs.filter(function (attach) {
return commonUtil.isNotEmpty(attach)
});
}
params.attachs = attachs;
resolve(attachs);
});
}
//增加发标信息
// code","bidCode","issueDate","openDate", "description", "created
managerBidBackAndIssue.post("/addBidIssue",function(req, res){
var txOption, bidIssueCode, user, bidIssueLogInfo;
var params = req.body;
checkBidIssueAddInputParams(params).then(function(attachs){
txOption = accountUtil.transactionOptionForEx(req.session);
bidIssueCode = commonUtil.getUUID("bidIssue"); //自动随机拼接编号生成
params.code = bidIssueCode;
user = req.session.user;
bidIssueLogInfo = {
dataName : "",
module : "招标发标",
func : "addBidIssue",
businessID : bidIssueCode,
operator : user.userName,
operateTime : logUtil.getFormatByTime(),
operateDesc : "加入发标信息"
}
params.created = new Date();
timeLog("开始查询oracle 附件");
return queryAttachFromSQLAndBindInfo(attachs, bidIssueCode, 6, user, txOption);
}).then(function(updatedAttachsWithBindInfo) {
timeLog("开始绑定附件到发标");
bidIssueLogInfo.other = JSON.stringify(updatedAttachsWithBindInfo);
return bindWithAttachSQL(updatedAttachsWithBindInfo);
}).then(function() {
timeLog("开始增加区块链发标");
return bidQKLServer.addBidIssueInfo(commonUtil.join(params, BID_ISSUE_CONTENT_ARRAY), txOption);
}).then(function (receipt) {
timeLog("开始写日志");
bidIssueLogInfo.blockNumber = receipt.blockNumber.toString();
bidIssueLogInfo.blockHash = receipt.blockHash;
bidIssueLogInfo.transactionHash = receipt.transactionHash;
return logQKLServer.writeLog(bidIssueLogInfo, receipt, txOption);
}).then(function () {
timeLog("开始写入oracle 发标");
params.blockNumber = bidIssueLogInfo.blockNumber;
params.blockHash = bidIssueLogInfo.blockHash;
params.transactionHash = bidIssueLogInfo.transactionHash;
return bidBackAndIssueSQLServer.addBidIssueInfo(params);
}).then(function () {
timeLog("开始写入日志");
return logSQLServer.writeLog(bidIssueLogInfo);
}).then(function () {
timeLog("响应给客户端");
responseUtil.sendSuccess(res, {});
console.log("成功-----------加入中标 ------------数据库");
}).catch(function (error) {
console.error(error);
responseUtil.sendError(res, error);
});
});
/* 修改发标 */
managerBidBackAndIssue.post('/modBidIssueInfo', function (req, res) {
var txOption, bidIssueCode, user, bidIssueLogInfo, attachs;
var params = req.body;
checkIssueModInputParams(params).then(function (ats) {
attachs = ats;
return bidBackAndIssueSQLServer.queryBidIssueInfoByCode(params);//oracle数据 实际传参数objc
}).then(function (results) {
//检查的逻辑在这 确保回标存在
if (commonUtil.isEmpty(results)) {
throw new Error("未找到相关合同数据");
} else {
txOption = accountUtil.transactionOptionForEx(req.session);
bidIssueCode = params.code;
user = req.session.user;
bidIssueLogInfo = {
dataName : params.name || results[0].name,
module : "中标模块",
func : "modBidIssueInfo",
businessID : bidIssueCode,
operator : user.userName,
operateTime : logUtil.getFormatByTime(),
operateDesc : "修改中标",
other : params.other
};
}
return bidAttachSQLServer.queryBindAttach(bidIssueCode);
}).then(function (results) { // 修改附件的操作指南
return dealAttachCodesWithRefcodeReturnModifiedAttachs(attachs, results, bidIssueCode, 6, user, txOption);
}).then(function (updated) {
//修改附件
bidIssueLogInfo.other = JSON.stringify(updated);
return bindWithAttachSQL(updated);//未加区块链
}).then(function () {
// 将修改后的合同写入区块链
var txContent = commonUtil.join(params, BID_ISSUE_CONTENT_ARRAY);
console.debug("txContent : " + txContent);
return bidQKLServer.modBidIssueInfo(txContent, txOption);
}).then(function (receipt) {
//写入日志 (区块链)
bidIssueLogInfo.blockNumber = receipt.blockNumber.toString();
bidIssueLogInfo.blockHash = receipt.blockHash;
bidIssueLogInfo.transactionHash = receipt.transactionHash;
return logQKLServer.writeLog(bidIssueLogInfo, receipt, txOption);
}).then(function () {
//oracle 写入表
params.blockNumber = bidIssueLogInfo.blockNumber;
params.blockHash = bidIssueLogInfo.blockHash;
params.transactionHash = bidIssueLogInfo.transactionHash;
return bidBackAndIssueSQLServer.modBidIssueInfo(params);
}).then(function () {
return logSQLServer.writeLog(bidIssueLogInfo);
}).then(function () {
responseUtil.sendSuccess(res, {});
console.log("成功-----------修改发标 ------------数据库");
}).catch(function (error) {
console.error(error);
responseUtil.sendError(res, error);
});
});
/* 查询发标 by code */
managerBidBackAndIssue.post('/getBidIssueByCode', function (req, res) {
var user = req.session.user;
bidBackAndIssueSQLServer.queryBidIssueInfoByCode(req.body).then(function (results) {
if(commonUtil.isEmpty(results)) {
responseUtil.sendSuccess(res, results);
} else {
bidAttachSQLServer.queryBindAttach(results[0].code).then(function (attachs) {
results[0].attachs = attachs;
console.log("成功-----------查询发标 ------------数据库");
responseUtil.sendSuccess(res, results);
logUtil.writeLogSingleDB(results[0].name, results[0].blockNumber, results[0].blockHash, results[0].transactionHash,
user.accCode, "发标模块", "getBidIssueByCode", results[0].code, user.userName, logUtil.getFormatByTime(), user.depName);
});
}
}).catch(function (error) {
console.error(error);
responseUtil.sendError(res, error);
});
});
/* 查询发标列表 */
// managerBidBackAndIssue.post('/getBidIssueList', function (req, res) {
// var user = req.session.user;
// bidBackAndIssueSQLServer.getBidIssueList(req.body).then(function (results) {
// console.log("成功-----------查询发标列表 ------------数据库");
// responseUtil.sendSuccess(res, results);
// if (commonUtil.isNotEmpty(results)) {
// logUtil.writeLogSingleDB("获取发标列表", results[0].blockNumber, results[0].blockHash, results[0].transactionHash,
// user.accCode, "发标", "getBidIssueList", results[0].code, user.userName, logUtil.getFormatByTime(), "查询发标列表");
// }
// }).catch(function (error) {
// console.error(error);
// responseUtil.sendError(res, error);
// });
// });
//-------------------------发标结束---------------------
managerBidBackAndIssue.post("/test", function (req, res ) {
var pp = {
code:"attach-1522749040153-c953e1b1",
name:"我是测试用的附件!www"
}
for (var i = 0; i < 1; i++) {
pp.description = "" +i;
pp.refCode = "bidIssueDetail-1524469715760-5c3e628a";
bidAttachSQLServer.addAttachMycWrapper(deepCopyObjt(pp)).then(function (some) {
console.log("what is some " + some);
}).catch(function (error) {
// responseUtil.sendError(res, error);
console.log("w error " + error);
});
}
//
// bidAttachSQLServer.modAttach(pp).then(function (something) {
// console.log(something);
// res.send("ok");
// }).catch(function (error) {
// res.send(error);
// })
});
//-------------------------myc新接口Begin---------------------
//挑选出有code 和无code 的参数数组 对应需要更改和需要删除的 和新增的
//inserts deletes updates
//顺便把其他表增加refCode字段
function parseObjcCodeToDeletesAndUpdatesAndInsert(arguments, refCode, isDelete) {
var insertArray = [];
var deleteArray = [];
var updateArray = [];
if (commonUtil.isEmpty(arguments)) return{inserts:[], deletes:[], updates:[]};
arguments.forEach(function(currentObjt) {
if (isDelete){
deletes.push(currentObjt);
return;
}
if (commonUtil.isNotEmpty(refCode))
currentObjt.refCode = refCode;
if (currentObjt.delete) {
deleteArray.push(currentObjt);
}else if(commonUtil.isNotEmpty(currentObjt.code)){
updateArray.push(currentObjt);
}else{
insertArray.push(currentObjt);
}
});
return {inserts:insertArray, deletes:deleteArray, updates:updateArray};
}
//bidIssue bidIssueSegs bidIssueFees bidIssueDetails
managerBidBackAndIssue.post("/addAndModIssuesAndSegsAndFeesAndDetails", function(req, res) {
//发标只能有一个
var params = req.body;
var user = req.session.user;
var txOption = accountUtil.transactionOptionForEx(req.session);
var bidIssue = params.bidIssue;
var bidWinSegs = commonUtil.toArray(params.bidIssueSegs);
var bidFees = commonUtil.toArray(params.bidIssueFees);
var bidIssueDetails = commonUtil.toArray(params.bidIssueDetails);//有可能为空
//发标明细的更改附件临时变量
var attachsTempArray;
var bidIssueCodeRouter;
if (!bidIssue) {
responseUtil.sendError(res, "发标参数不能为空!");
return;
}
var bidIssueObjcToDeal = parseObjcCodeToDeletesAndUpdatesAndInsert([bidIssue]);
var bidWindSegsObjcToDeal;
var bidFeesObjcToDeal;
var bidIssueDetailsObjcToDeal;
function parseAndAddRalatedInfo(_isDelete) {
bidWindSegsObjcToDeal = parseObjcCodeToDeletesAndUpdatesAndInsert(bidWinSegs, bidIssue.code, _isDelete);
bidFeesObjcToDeal = parseObjcCodeToDeletesAndUpdatesAndInsert(bidFees, bidIssue.code, _isDelete);
bidIssueDetailsObjcToDeal = parseObjcCodeToDeletesAndUpdatesAndInsert(bidIssueDetails, bidIssue.code, _isDelete);
}
if (bidIssueObjcToDeal.deletes.length ==1) {
bidBackAndIssueSQLServer.deleteBidIssueByCode(bidIssueObjcToDeal.deletes[0].code).then(function () {
parseAndAddRalatedInfo(true);
sameProcedure(bidIssueObjcToDeal.deletes[0].code);
// responseUtil.sendSuccess(res, "delete success");
}).catch(function(error) {
responseUtil.sendError(res, error);
});
}else if(bidIssueObjcToDeal.inserts.length == 1){
var txContentTemp = commonUtil.join(bidIssueObjcToDeal.inserts[0], BID_ISSUE_CONTENT_ARRAY);
bidQKLServer.addBidIssueInfoMycWrapper(txContentTemp, txOption).catch(function (error) {
return Promise.reject(error);
}).then(function () {
bidBackAndIssueSQLServer.addBidIssueInfo(bidIssueObjcToDeal.inserts[0]).then(function (code) {
parseAndAddRalatedInfo(false);
sameProcedure(code);
}).catch(function (error) {
responseUtil.sendError(res, error);
})
}).catch(function (error) {
responseUtil.sendError(res, error);
return;
});
}else if (bidIssueObjcToDeal.updates.length == 1) {
var txContentTemp = commonUtil.join(bidIssueObjcToDeal.updates[0], BID_ISSUE_CONTENT_ARRAY);
bidQKLServer.modBidIssueInfoMycWrapper(txContentTemp, txOption).catch(function (error) {
return Promise.reject(error);
}).then(function () {
bidBackAndIssueSQLServer.modBidIssueInfo(bidIssueObjcToDeal.updates[0]).then(function (code) {
parseAndAddRalatedInfo(false);
sameProcedure(code);
}).catch(function (error) {
responseUtil.sendError(res, error);
});
});
}
function sameProcedure(bidIssueCode) {
var bidIssueLogInfo = {
dataName : params.name ,
module : "发标模块",
func : "addAndModIssuesAndSegsAndFeesAndDetails",
businessID : bidIssueCode,
operator : user.userName,
operateTime : logUtil.getFormatByTime(),
operateDesc : "修改发标",
other : params.other
};
logQKLServer.writeLogMycWrapper(bidIssueLogInfo,txOption).then(function() {
return logSQLServer.writeLogMycWrapper(bidIssueLogInfo);
}).then(function () {
//增加分标段
return Promise.all(bidWindSegsObjcToDeal.inserts.map(function (currentBidWinSeg) {
var txContentTemp = commonUtil.join(currentBidWinSeg,BID_WIN_SEG_CONTENT_ARRAY);
return bidQKLServer.addBidSegmentMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidWindSegsObjcToDeal.inserts.map(function (currentBidWinSeg) {
return bidSegSQLServer.addBidWinSegMycWrapper(currentBidWinSeg);
}));
}).then(function (bidWinSegCodes) {
//增加分标段成功
//TODO
// responseUtil.sendSuccess(res, bidWinSegCodes);
return Promise.all(bidWinSegCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "增加分标段";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo),txOption);
}));
}).then(function (bidWinSegCodes) {
return Promise.all(bidWinSegCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "增加分标段";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo));
}));
}).then(function () {
//更改
return Promise.all(bidWindSegsObjcToDeal.updates.map(function (currentBidWinSeg) {
var txContentTemp = commonUtil.join(currentBidWinSeg,BID_WIN_SEG_CONTENT_ARRAY);
return bidQKLServer.modBidSegmentMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidWindSegsObjcToDeal.updates.map(function (currentBidWinSeg) {
return bidSegSQLServer.modBidWinSegMycWrapper(currentBidWinSeg);
}));
}).then(function (bidWinSegCodes) {
return Promise.all(bidWinSegCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "修改分标段";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo),txOption);
}));
}).then(function (bidWinSegCodes) {
return Promise.all(bidWinSegCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "修改分标段";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo));
}));
}).then(function () {
//删除分标段
return Promise.all(bidWindSegsObjcToDeal.deletes.map(function (currentBidWinSeg) {
currentBidWinSeg.refCode = "null";
return bidSegSQLServer.modBidWinSegMycWrapper(currentBidWinSeg);
}));
}).then(function (bidWinSegCodes) {
return Promise.all(bidWinSegCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "删除分标段";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo),txOption);
}));
}).then(function (bidWinSegCodes) {
return Promise.all(bidWinSegCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "删除分标段";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo));
}));
}).then(function () {
//增加发标费用相关项
//-------------------------------------------//
return Promise.all(bidFeesObjcToDeal.inserts.map(function (currentBidFee) {
var txContentTemp = commonUtil.join(currentBidFee,BID_ISSUE_FEE_CONTENT_ARRAY);
return bidQKLServer.addBidIssueFeeMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidFeesObjcToDeal.inserts.map(function (currentBidFee) {
return bidBackAndIssueSQLServer.addBidIssueFeeInfo(currentBidFee);
}));
}).then(function (bidFeeCodes) {
//增加发标相关项成功
//TODO
// responseUtil.sendSuccess(res, bidFeeCodes);
return Promise.all(bidFeeCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "增加发标相关费用项";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo),txOption);
}));
}).then(function (bidFeeCodes) {
return Promise.all(bidFeeCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "增加发标相关费用项";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo));
}));
}).then(function () {
//更改发标相关费用项
return Promise.all(bidFeesObjcToDeal.updates.map(function (currentBidFee) {
var txContentTemp = commonUtil.join(currentBidFee,BID_ISSUE_FEE_CONTENT_ARRAY);
return bidQKLServer.modBidIssueFeeMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidFeesObjcToDeal.updates.map(function (currentBidFee) {
return bidBackAndIssueSQLServer.modBidIssueFeeInfo(currentBidFee);
}));
}).then(function (bidFeeCodes) {
return Promise.all(bidFeeCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "修改发标相关费用项";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo),txOption);
}));
}).then(function (bidFeeCodes) {
return Promise.all(bidFeeCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "修改发标相关费用项";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo));
}));
}).then(function () {
//删除发标相关费用项
return Promise.all(bidFeesObjcToDeal.deletes.map(function (currentBidFee) {
currentBidFee.refCode = "null";
var txContentTemp = commonUtil.join(currentBidFee,BID_ISSUE_FEE_CONTENT_ARRAY);
return bidQKLServer.modBidIssueFeeMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidFeesObjcToDeal.deletes.map(function (currentBidFee) {
currentBidFee.refCode = "null";
return bidBackAndIssueSQLServer.deleteBidIssueFeeByCode(currentBidFee.code);
}));
}).then(function (bidFeeCodes) {
return Promise.all(bidFeeCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "删除发标相关费用项";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo),txOption);
}));
}).then(function (bidFeeCodes) {
return Promise.all(bidFeeCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "删除发标相关费用项";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo));
}));
}).then(function () {
//增加发标明细
//-------------------------------------------//
return Promise.all(bidIssueDetailsObjcToDeal.inserts.map(function (currentBidIssueDetail) {
var txContentTemp = commonUtil.join(currentBidIssueDetail,BID_ISSUE_DETAIL_CONTENT_ARRAY);
return bidQKLServer.addBidIssueDetailInfoMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidIssueDetailsObjcToDeal.inserts.map(function (currentBidIssueDetail) {
return bidIssueDetailSQLServer.addBidIssueDetailInfo(currentBidIssueDetail);
}));
}).then(function (bidIssueDetailCodes) {
//增加发标明细成功
//TODO
// responseUtil.sendSuccess(res, bidIssueDetailCodes);
return Promise.all(bidIssueDetailCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "增加发标明细";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo),txOption);
}));
}).then(function (bidIssueDetailCodes) {
return Promise.all(bidIssueDetailCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "增加发标明细";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo));
}));
}).then(function () {
//----------------------------------//
//增加发标明细附件
return Promise.all(bidIssueDetailsObjcToDeal.inserts.map(function (currentBidIssueDetail) {
return dealAttachCodesWithRefcodeReturnModifiedAttachs(currentBidIssueDetail.attachs,currentBidIssueDetail.code,7);
}));
}).then(function (twoDArray) {
var oneArray = twoDToOneDArray(twoDArray);
attachsTempArray = oneArray;
return Promise.all(oneArray.map(function (currentAttach) {
var txContentTemp = commonUtil.join(currentAttach,BID_ATTACH_CONTENT_ARRAY);
bidQKLServer.updateBidAttachmentMycWrapper(txContentTemp, txOption);
}));
}).then(function () {
return Promise.all(attachsTempArray.map(function (currentAttach) {
return bidAttachSQLServer.modAttachMycWrapper(currentAttach);
}));
}).then(function (attachCodes) {
//增加发标明细附件成功
//TODO
// responseUtil.sendSuccess(res, bidIssueDetailCodes);
return Promise.all(attachCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "更改发标明细附件";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo),txOption);
}));
}).then(function (attachCodes) {
return Promise.all(attachCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "更改发标明细附件";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo));
}));
}).then(function () {
//修改发标明细
//-------------------------------------------//
return Promise.all(bidIssueDetailsObjcToDeal.updates.map(function (currentBidIssueDetail) {
var txContentTemp = commonUtil.join(currentBidIssueDetail,BID_ISSUE_DETAIL_CONTENT_ARRAY);
return bidQKLServer.modBidIssueDetailInfoMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidIssueDetailsObjcToDeal.updates.map(function (currentBidIssueDetail) {
return bidIssueDetailSQLServer.modBidIssueDetailInfo(currentBidIssueDetail);
}));
}).then(function (bidIssueDetailCodes) {
//修改发标明细成功
//TODO
// responseUtil.sendSuccess(res, bidIssueDetailCodes);
return Promise.all(bidIssueDetailCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "修改发标明细";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo),txOption);
}));
}).then(function (bidIssueDetailCodes) {
return Promise.all(bidIssueDetailCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "修改发标明细";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo));
}));
}).then(function () {
//----------------------------------//
//修改发标明细附件
return Promise.all(bidIssueDetailsObjcToDeal.updates.map(function (currentBidIssueDetail) {
return dealAttachCodesWithRefcodeReturnModifiedAttachs(currentBidIssueDetail.attachs,currentBidIssueDetail.code,7);
}));
}).then(function (twoDArray) {
var oneArray = twoDToOneDArray(twoDArray);
attachsTempArray = oneArray;
return Promise.all(oneArray.map(function (currentAttach) {
var txContentTemp = commonUtil.join(currentAttach,BID_ATTACH_CONTENT_ARRAY);
bidQKLServer.updateBidAttachmentMycWrapper(txContentTemp, txOption);
}));
}).then(function () {
return Promise.all(attachsTempArray.map(function (currentAttach) {
return bidAttachSQLServer.modAttachMycWrapper(currentAttach);
}));
}).then(function (attachCodes) {
//修改发标明细附件成功
//TODO
// responseUtil.sendSuccess(res, bidIssueDetailCodes);
return Promise.all(attachCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "更改发标明细附件";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo),txOption);
}));
}).then(function (attachCodes) {
return Promise.all(attachCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "更改发标明细附件";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo));
}));
}).then(function () {
//删除发标明细
//--------------------------------------------//
return Promise.all(bidIssueDetailsObjcToDeal.deletes.map(function (currentBidIssueDetail) {
currentBidIssueDetail.redCode = "null";
var txContentTemp = commonUtil.join(currentBidIssueDetail,BID_ISSUE_DETAIL_CONTENT_ARRAY);
return bidQKLServer.modBidIssueDetailInfoMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidIssueDetailsObjcToDeal.deletes.map(function (currentBidIssueDetail) {
currentBidIssueDetail.refCode = "null";
return bidIssueDetailSQLServer.modBidIssueDetailInfo(currentBidIssueDetail);
}));
}).then(function (bidIssueDetailCodes) {
return Promise.all(bidIssueDetailCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "删除发标明细";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo),txOption);
}));
}).then(function (bidIssueDetailCodes) {
return Promise.all(bidIssueDetailCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "删除发标明细";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo));
}));
}).then(function () {
//----------------------------------//
//删除发标明细的附件
return Promise.all(bidIssueDetailsObjcToDeal.deletes.map(function (currentBidIssueDetail) {
return dealAttachCodesWithRefcodeReturnModifiedAttachs([],currentBidIssueDetail.code,0);
}));
}).then(function (twoDArray) {
var oneArray = twoDToOneDArray(twoDArray);
attachsTempArray = oneArray;
return Promise.all(oneArray.map(function (currentAttach) {
var txContentTemp = commonUtil.join(currentAttach,BID_ATTACH_CONTENT_ARRAY);
bidQKLServer.updateBidAttachmentMycWrapper(txContentTemp, txOption);
}));
}).then(function () {
return Promise.all(attachsTempArray.map(function (currentAttach) {
return bidAttachSQLServer.modAttachMycWrapper(currentAttach);
}));
}).then(function (attachCodes) {
//删除发标明细附件成功
//TODO
// responseUtil.sendSuccess(res, bidIssueDetailCodes);
return Promise.all(attachCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "删除发标明细附件";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo),txOption);
}));
}).then(function (attachCodes) {
return Promise.all(attachCodes.map(function (currentCode) {
bidIssueLogInfo.businessID = currentCode;
bidIssueLogInfo.operateDesc = "删除发标明细附件";
bidIssueLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidIssueLogInfo));
}));
}).then(function () {
//good job
responseUtil.sendSuccess(res, "all good!");
}).catch(function (error) {
responseUtil.sendError(res, error);
});
}//sameProcedure
});
//根据发标code 获取很多
managerBidBackAndIssue.post("/getBidIssueSegsAndFeesAndDetails",function (req, res) {
var final = {};
var p1 = bidSegSQLServer.getBidWinSegListByBidIssueCodeMycWrapper(req.body.bidIssueCode).then(function (results) {
final.bidSegs = results;
return Promise.resolve();
});
var p2 = bidBackAndIssueSQLServer.queryBidIssueFeeListInfoByIssueCode(req.body.bidIssueCode).then(function (results) {
final.bidIssueFees = results;
return Promise.resolve();
});
var p3 = bidIssueDetailSQLServer.getBidIssueDetailListByBidIssueCode(req.body.bidIssueCode).then(function (results) {
final.bidIssueDetails = results;
return Promise.resolve();
}).then(function () {
return Promise.all(final.bidIssueDetails.map(function (currentBidIssueDetail) {
return bidAttachSQLServer.queryBindAttach(currentBidIssueDetail.code).then(function (results) {
currentBidIssueDetail.attachs = results;
return Promise.resolve();
});
}));
});
Promise.all([p1, p2, p3]).then(function () {
responseUtil.sendSuccess(res, final);
}).catch(function (error) {
responseUtil.sendError(res, error);
});
});
//code 根据code 获取发标
managerBidBackAndIssue.post("/getBidIssue",function (req, res) {
bidBackAndIssueSQLServer.queryBidIssueInfoByCode(req.body.code).then(function (results) {
responseUtil.sendSuccess(res, results);
}).catch(function (error) {
responseUtil.sendError(res, error);
});
});
// 根据招标计划的code 获取发标的信息列表
managerBidBackAndIssue.post("/getBidIssueList", function (req, res) {
var bidCode = req.body.bidCode;
bidBackAndIssueSQLServer.getBidIssueListByBidCode(bidCode).then(function (results) {
responseUtil.sendSuccess(res, results);
}).catch(function (error) {
responseUtil.sendError(res, error);
});
});
// bidCode
managerBidBackAndIssue.post("/getBidIssueListAndAttachInfos",function (req, res) {
var rr = [];
var bidCode = req.body.bidCode;
bidBackAndIssueSQLServer.getBidIssueListByBidCode(bidCode).then(function (results) {
return Promise.all(results.map(function (currentBidIssue, index) {
var final = {};
final.bidIssue = currentBidIssue;
var p1 = bidSegSQLServer.getBidWinSegListByBidIssueCodeMycWrapper(currentBidIssue.code).then(function (results) {
final.bidIssueSegs = results;
return Promise.resolve();
});
var p2 = bidBackAndIssueSQLServer.queryBidIssueFeeListInfoByIssueCode(currentBidIssue.code).then(function (results) {
final.bidIssueFees = results;
return Promise.resolve();
});
var p3 = bidIssueDetailSQLServer.getBidIssueDetailListByBidIssueCode(currentBidIssue.code).then(function (results) {
final.bidIssueDetails = results;
return Promise.resolve();
}).then(function () {
return Promise.all(final.bidIssueDetails.map(function (currentBidIssueDetail) {
return bidAttachSQLServer.queryBindAttach(currentBidIssueDetail.code).then(function (results) {
currentBidIssueDetail.attachs = results;
return Promise.resolve();
});
}));
}).then(function () {
return Promise.all(final.bidIssueDetails.map(function (currentBidIssueDetail) {
return bidParterSQLServer.queryBidPartnerByCode(currentBidIssueDetail.orgCode).then(function (bidPartnerInfos) {
if (commonUtil.isNotEmpty(bidPartnerInfos)){
currentBidIssueDetail.partnerName = bidPartnerInfos[0].name;
} else {
currentBidIssueDetail.partnerName = "";
}
return Promise.resolve();
});
}));
});
return Promise.all([p1, p2, p3]).then(function () {
rr[index] = final;
return Promise.resolve();
});
}));
}).then(function () {
responseUtil.sendSuccess(res, rr);
}).catch(function (error) {
responseUtil.sendError(res, error);
});
});
//-----------------------------回标接口Begin----------------------
//bidBack bidBackSegs bidBackFees bidBackDetails
managerBidBackAndIssue.post("/addAndModBidBackAndSegsAndFeesAndDetails", function(req, res) {
//回标只能有一个
var params = req.body;
var user = req.session.user;
var txOption = accountUtil.transactionOptionForEx(req.session);
var bidBack = params.bidBack;
var bidWinSegs = commonUtil.toArray(params.bidBackSegs);
var bidFees = commonUtil.toArray(params.bidBackFees);
var bidBackDetails = commonUtil.toArray(params.bidBackDetails);//有可能为空
//回标明细的更改附件临时变量
var attachsTempArray;
var bidBackCodeRouter;
if (!bidBack) {
responseUtil.sendError(res, "回标参数不能为空!");
return;
}
var bidBackObjcToDeal = parseObjcCodeToDeletesAndUpdatesAndInsert([bidBack]);
var bidWindSegsObjcToDeal ;
var bidFeesObjcToDeal;
var bidBackDetailsObjcToDeal;
function parseAndAddRalatedInfo(_isDelete) {
bidWindSegsObjcToDeal = parseObjcCodeToDeletesAndUpdatesAndInsert(bidWinSegs, bidBack.code, _isDelete);
bidFeesObjcToDeal = parseObjcCodeToDeletesAndUpdatesAndInsert(bidFees, bidBack.code, _isDelete);
bidBackDetailsObjcToDeal = parseObjcCodeToDeletesAndUpdatesAndInsert(bidBackDetails, bidBack.code, _isDelete);
}
if (bidBackObjcToDeal.deletes.length ==1) {
bidBackAndIssueSQLServer.deleteBidBackByCode(bidBackObjcToDeal.deletes[0].code).then(function () {
parseAndAddRalatedInfo(true);
sameProcedure(bidBackObjcToDeal.deletes[0].code);
}).catch(function(error) {
responseUtil.sendError(res, error);
});
}else if(bidBackObjcToDeal.inserts.length == 1){
var txContentTemp = commonUtil.join(bidBackObjcToDeal.inserts[0], BID_ISSUE_CONTENT_ARRAY);
bidQKLServer.addBidBackInfoMycWrapper(txContentTemp, txOption).catch(function (error) {
return Promise.reject(error);
}).then(function () {
bidBackAndIssueSQLServer.addBidBackInfo(bidBackObjcToDeal.inserts[0]).then(function (code) {
parseAndAddRalatedInfo(false);
sameProcedure(code);
}).catch(function (error) {
responseUtil.sendError(res, error);
});
}).catch(function (error) {
responseUtil.sendError(res, error);
return;
});
}else if (bidBackObjcToDeal.updates.length == 1) {
var txContentTemp = commonUtil.join(bidBackObjcToDeal.updates[0], BID_ISSUE_CONTENT_ARRAY);
bidQKLServer.modBidBackInfoMycWrapper(txContentTemp, txOption).catch(function (error) {
return Promise.reject(error);
}).then(function () {
bidBackAndIssueSQLServer.modBidBackInfo(bidBackObjcToDeal.updates[0]).then(function (code) {
parseAndAddRalatedInfo(false);
sameProcedure(code);
}).catch(function (error) {
responseUtil.sendError(res, error);
});
}).catch(function (error) {
responseUtil.sendError(res, error);
});
}
function sameProcedure(bidBackCode) {
var bidBackLogInfo = {
dataName : params.name ,
module : "回标模块",
func : "addAndModBidBackAndSegsAndFeesAndDetails",
businessID : bidBackCode,
operator : user.userName,
operateTime : logUtil.getFormatByTime(),
operateDesc : "修改回标",
other : params.other
};
logSomething(bidBackLogInfo,txOption);
//增加分标段
//--------------------//
Promise.all(bidWindSegsObjcToDeal.inserts.map(function (currentBidWinSeg) {
var txContentTemp = commonUtil.join(currentBidWinSeg,BID_WIN_SEG_CONTENT_ARRAY);
return bidQKLServer.addBidSegmentMycWrapper(txContentTemp,txOption);
})).then(function () {
return Promise.all(bidWindSegsObjcToDeal.inserts.map(function (currentBidWinSeg) {
return bidSegSQLServer.addBidWinSegMycWrapper(currentBidWinSeg);
}));
}).then(function (bidWinSegCodes) {
//增加分标段成功
//TODO
// responseUtil.sendSuccess(res, bidWinSegCodes);
bidWinSegCodes.forEach(function (currentSegCode) {
bidBackLogInfo.businessID = currentSegCode;
bidBackLogInfo.operateDesc = "增加分标段";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
logSomething(bidBackLogInfo, txOption);
});
//更改
return Promise.all(bidWindSegsObjcToDeal.updates.map(function (currentBidWinSeg) {
var txContentTemp = commonUtil.join(currentBidWinSeg,BID_WIN_SEG_CONTENT_ARRAY);
return bidQKLServer.modBidSegmentMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidWindSegsObjcToDeal.updates.map(function (currentBidWinSeg) {
return bidSegSQLServer.modBidWinSegMycWrapper(currentBidWinSeg);
}));
}).then(function (bidWinSegCodes) {
bidWinSegCodes.forEach(function (currentSegCode) {
bidBackLogInfo.businessID = currentSegCode;
bidBackLogInfo.operateDesc = "修改分标段";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
logSomething(bidBackLogInfo, txOption);
});
//删除分标段
return Promise.all(bidWindSegsObjcToDeal.deletes.map(function (currentBidWinSeg) {
currentBidWinSeg.refCode = "null";
var txContentTemp = commonUtil.join(currentBidWinSeg,BID_WIN_SEG_CONTENT_ARRAY);
return bidQKLServer.modBidSegmentMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidWindSegsObjcToDeal.deletes.map(function (currentBidWinSeg) {
currentBidWinSeg.refCode = "null";
return bidSegSQLServer.modBidWinSegMycWrapper(currentBidWinSeg);
}));
}).then(function (bidWinSegCodes) {
bidWinSegCodes.forEach(function (currentSegCode) {
bidBackLogInfo.businessID = currentSegCode;
bidBackLogInfo.operateDesc = "删除分标段";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
logSomething(bidBackLogInfo, txOption);
});
//增加回标费用相关项
//-------------------------------------------//
return Promise.all(bidFeesObjcToDeal.inserts.map(function (currentBidFee) {
var txContentTemp = commonUtil.join(currentBidFee,BID_ISSUE_FEE_CONTENT_ARRAY);
return bidQKLServer.addBidIssueFeeMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidFeesObjcToDeal.inserts.map(function (currentBidFee) {
return bidBackAndIssueSQLServer.addBidIssueFeeInfo(currentBidFee);
}));
}).then(function (bidFeeCodes) {
//增加回标相关项成功
//TODO
// responseUtil.sendSuccess(res, bidFeeCodes);
bidFeeCodes.forEach(function (currentBidFeeCode) {
bidBackLogInfo.businessID = currentBidFeeCode;
bidBackLogInfo.operateDesc = "增加回标相关费用项";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
logSomething(bidBackLogInfo, txOption);
});
//更改回标相关费用项
return Promise.all(bidFeesObjcToDeal.updates.map(function (currentBidFee) {
var txContentTemp = commonUtil.join(currentBidFee,BID_ISSUE_FEE_CONTENT_ARRAY);
return bidQKLServer.modBidIssueFeeMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidFeesObjcToDeal.updates.map(function (currentBidFee) {
return bidBackAndIssueSQLServer.modBidIssueFeeInfo(currentBidFee);
}));
}).then(function (bidFeeCodes) {
return Promise.all(bidFeeCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "修改回标相关费用项";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo),txOption);
}));
}).then(function (bidFeeCodes) {
return Promise.all(bidFeeCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "修改回标相关费用项";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo));
}));
}).then(function () {
//删除回标相关费用项
return Promise.all(bidFeesObjcToDeal.deletes.map(function (currentBidFee) {
currentBidFee.refCode = "null";
var txContentTemp = commonUtil.join(currentBidFee,BID_ISSUE_FEE_CONTENT_ARRAY);
return bidQKLServer.modBidIssueFeeMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidFeesObjcToDeal.deletes.map(function (currentBidFee) {
currentBidFee.refCode = "null";
return bidBackAndIssueSQLServer.deleteBidIssueFeeByCode(currentBidFee.code);
}));
}).then(function (bidFeeCodes) {
return Promise.all(bidFeeCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "删除回标相关费用项";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo),txOption);
}));
}).then(function (bidFeeCodes) {
return Promise.all(bidFeeCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "删除回标相关费用项";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo));
}));
}).then(function () {
//增加回标明细
//-------------------------------------------//
return Promise.all(bidBackDetailsObjcToDeal.inserts.map(function (currentBidBackDetail) {
var txContentTemp = commonUtil.join(currentBidBackDetail,BID_ISSUE_DETAIL_CONTENT_ARRAY);
return bidQKLServer.addBidIssueDetailInfoMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidBackDetailsObjcToDeal.inserts.map(function (currentBidBackDetail) {
return bidIssueDetailSQLServer.addBidIssueDetailInfo(currentBidBackDetail);
}));
}).then(function (bidBackDetailCodes) {
//增加回标明细成功
//TODO
// responseUtil.sendSuccess(res, bidBackDetailCodes);
return Promise.all(bidBackDetailCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "增加回标明细";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo),txOption);
}));
}).then(function (bidBackDetailCodes) {
return Promise.all(bidBackDetailCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "增加回标明细";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo));
}));
}).then(function () {
//----------------------------------//
//增加回标明细附件
return Promise.all(bidBackDetailsObjcToDeal.inserts.map(function (currentBidBackDetail) {
return dealAttachCodesWithRefcodeReturnModifiedAttachs(currentBidBackDetail.attachs,currentBidBackDetail.code,5);
}));
}).then(function (twoDArray) {
var oneArray = twoDToOneDArray(twoDArray);
attachsTempArray = oneArray;
return Promise.all(oneArray.map(function (currentAttach) {
var txContentTemp = commonUtil.join(currentAttach,BID_ATTACH_CONTENT_ARRAY);
bidQKLServer.updateBidAttachmentMycWrapper(txContentTemp, txOption);
}));
}).then(function () {
return Promise.all(attachsTempArray.map(function (currentAttach) {
return bidAttachSQLServer.modAttachMycWrapper(currentAttach);
}));
}).then(function (attachCodes) {
//增加回标明细附件成功
//TODO
// responseUtil.sendSuccess(res, bidBackDetailCodes);
return Promise.all(attachCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "增加回标明细附件";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo),txOption);
}));
}).then(function (attachCodes) {
return Promise.all(attachCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "增加回标明细附件";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo));
}));
}).then(function () {
//修改回标明细
//-------------------------------------------//
return Promise.all(bidBackDetailsObjcToDeal.updates.map(function (currentBidBackDetail) {
var txContentTemp = commonUtil.join(currentBidBackDetail,BID_ISSUE_DETAIL_CONTENT_ARRAY);
return bidQKLServer.modBidIssueDetailInfoMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidBackDetailsObjcToDeal.updates.map(function (currentBidBackDetail) {
return bidIssueDetailSQLServer.modBidIssueDetailInfo(currentBidBackDetail);
}));
}).then(function (bidBackDetailCodes) {
//修改回标明细成功
//TODO
// responseUtil.sendSuccess(res, bidBackDetailCodes);
return Promise.all(bidBackDetailCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "修改回标明细";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo),txOption);
}));
}).then(function (bidBackDetailCodes) {
return Promise.all(bidBackDetailCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "修改回标明细";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo));
}));
}).then(function () {
//----------------------------------//
//修改回标明细附件
return Promise.all(bidBackDetailsObjcToDeal.updates.map(function (currentBidBackDetail) {
return dealAttachCodesWithRefcodeReturnModifiedAttachs(currentBidBackDetail.attachs,currentBidBackDetail.code,5);
}));
}).then(function (twoDArray) {
var oneArray = twoDToOneDArray(twoDArray);
attachsTempArray = oneArray;
return Promise.all(oneArray.map(function (currentAttach) {
var txContentTemp = commonUtil.join(currentAttach,BID_ATTACH_CONTENT_ARRAY);
bidQKLServer.updateBidAttachmentMycWrapper(txContentTemp, txOption);
}));
}).then(function () {
return Promise.all(attachsTempArray.map(function (currentAttach) {
return bidAttachSQLServer.modAttachMycWrapper(currentAttach);
}));
}).then(function (attachCodes) {
//修改回标明细附件成功
//TODO
// responseUtil.sendSuccess(res, bidBackDetailCodes);
return Promise.all(attachCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "更改回标明细附件";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo),txOption);
}));
}).then(function (attachCodes) {
return Promise.all(attachCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "更改回标明细附件";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo));
}));
}).then(function () {
//删除回标明细
//--------------------------------------------//
return Promise.all(bidBackDetailsObjcToDeal.deletes.map(function (currentBidBackDetail) {
currentBidBackDetail.refCode = "null";
var txContentTemp = commonUtil.join(currentBidBackDetail,BID_ISSUE_DETAIL_CONTENT_ARRAY);
return bidQKLServer.modBidIssueDetailInfoMycWrapper(txContentTemp,txOption);
}));
}).then(function () {
return Promise.all(bidBackDetailsObjcToDeal.deletes.map(function (currentBidBackDetail) {
currentBidBackDetail.refCode = "null";
return bidIssueDetailSQLServer.modBidIssueDetailInfo(currentBidBackDetail);
}));
}).then(function (bidBackDetailCodes) {
return Promise.all(bidBackDetailCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "删除回标明细";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo),txOption);
}));
}).then(function (bidBackDetailCodes) {
return Promise.all(bidBackDetailCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "删除回标明细";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo));
}));
}).then(function () {
//----------------------------------//
//删除回标明细的附件
return Promise.all(bidBackDetailsObjcToDeal.deletes.map(function (currentBidBackDetail) {
return dealAttachCodesWithRefcodeReturnModifiedAttachs([],currentBidBackDetail.code,0);
}));
}).then(function (twoDArray) {
var oneArray = twoDToOneDArray(twoDArray);
attachsTempArray = oneArray;
return Promise.all(oneArray.map(function (currentAttach) {
var txContentTemp = commonUtil.join(currentAttach,BID_ATTACH_CONTENT_ARRAY);
bidQKLServer.updateBidAttachmentMycWrapper(txContentTemp, txOption);
}));
}).then(function () {
return Promise.all(attachsTempArray.map(function (currentAttach) {
return bidAttachSQLServer.modAttachMycWrapper(currentAttach);
}));
}).then(function (attachCodes) {
//删除回标明细附件成功
//TODO
// responseUtil.sendSuccess(res, bidBackDetailCodes);
return Promise.all(attachCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "删除回标明细附件";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logQKLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo),txOption);
}));
}).then(function (attachCodes) {
return Promise.all(attachCodes.map(function (currentCode) {
bidBackLogInfo.businessID = currentCode;
bidBackLogInfo.operateDesc = "删除回标明细附件";
bidBackLogInfo.operateTime = logUtil.getFormatByTime();
return logSQLServer.writeLogMycWrapper(deepCopyObjt(bidBackLogInfo));
}));
}).then(function () {
//good job
responseUtil.sendSuccess(res, "all good!");
}).catch(function (error) {
responseUtil.sendError(res, error);
});
}//sameProcedure
});
//根据回标code 获取回标的详情
managerBidBackAndIssue.post("/getBidBackByCode", function (req, res) {
bidBackAndIssueSQLServer.queryBidBackInfoByCode(req.body.code).then(function (results) {
responseUtil.sendSuccess(res, results);
}).catch(function (error) {
responseUtil.sendError(res, error);
});
});
//根据回标code 获取分标段 相关费用和回标明细
//bidBackCode
managerBidBackAndIssue.post("/getBidBackSegsAndFeesAndDetails", function (req, res) {
var final = {};
var p1 = bidSegSQLServer.getBidWinSegListByBidIssueCodeMycWrapper(req.body.bidBackCode).then(function (results) {
final.bidSegs = results;
return Promise.resolve();
});
var p2 = bidBackAndIssueSQLServer.queryBidIssueFeeListInfoByIssueCode(req.body.bidBackCode).then(function (results) {
final.bidBackFees = results;
return Promise.resolve();
});
var p3 = bidIssueDetailSQLServer.getBidIssueDetailListByBidIssueCode(req.body.bidBackCode).then(function (results) {
final.bidBackDetails = results;
return Promise.resolve();
}).then(function () {
return Promise.all(final.bidBackDetails.map(function (currentBidIssueDetail) {
return bidAttachSQLServer.queryBindAttach(currentBidIssueDetail.code).then(function (results) {
currentBidIssueDetail.attachs = results;
return Promise.resolve();
});
}));
});
Promise.all([p1, p2, p3]).then(function () {
responseUtil.sendSuccess(res, final);
}).catch(function (error) {
responseUtil.sendError(res, error);
});
});
// 获取回标列表 根据招标计划的code
// bidCode
managerBidBackAndIssue.post("/getBidBackListByBidCode", function (req, res) {
bidBackAndIssueSQLServer.getBidBackListByBidCode(req.body.bidCode).then(function (results) {
responseUtil.sendSuccess(res, results);
}).catch(function (error) {
responseUtil.sendError(res, error);
});
});
// 根据招标计划的code 获取发标的信息列表
managerBidBackAndIssue.post("/getBidIssueList", function (req, res) {
var bidCode = req.body.bidCode;
bidBackAndIssueSQLServer.getBidIssueListByBidCode(bidCode).then(function (results) {
responseUtil.sendSuccess(res, results);
}).catch(function (error) {
responseUtil.sendError(res, error);
});
});
// bidCode
managerBidBackAndIssue.post("/getBidBackListAndAttachInfos",function (req, res) {
var rr = [];
var bidCode = req.body.bidCode;
bidBackAndIssueSQLServer.getBidBackListByBidCode(bidCode).then(function (results) {
return Promise.all(results.map(function (currentBidBack, index) {
var final = {};
final.bidBack = currentBidBack;
var p1 = bidSegSQLServer.getBidWinSegListByBidIssueCodeMycWrapper(currentBidBack.code).then(function (results) {
final.bidBackSegs = results;
return Promise.resolve();
});
var p2 = bidBackAndIssueSQLServer.queryBidIssueFeeListInfoByIssueCode(currentBidBack.code).then(function (results) {
final.bidBackFees = results;
return Promise.resolve();
});
var p3 = bidIssueDetailSQLServer.getBidIssueDetailListByBidIssueCode(currentBidBack.code).then(function (results) {
final.bidBackDetails = results;
return Promise.resolve();
}).then(function () {
return Promise.all(final.bidBackDetails.map(function (currentBidBackDetail) {
return bidAttachSQLServer.queryBindAttach(currentBidBackDetail.code).then(function (results) {
currentBidBackDetail.attachs = results;
return Promise.resolve();
});
}));
}).then(function () {
return Promise.all(final.bidBackDetails.map(function (currentBidBackDetail) {
return bidParterSQLServer.queryBidPartnerByCode(currentBidBackDetail.orgCode).then(function (bidPartnerInfos) {
if (commonUtil.isNotEmpty(bidPartnerInfos)){
currentBidBackDetail.partnerName = bidPartnerInfos[0].name;
} else {
currentBidBackDetail.partnerName = "";
}
return Promise.resolve();
});
}));
});
return Promise.all([p1, p2, p3]).then(function () {
rr[index] = final;
return Promise.resolve();
});
}));
}).then(function () {
responseUtil.sendSuccess(res, rr);
}).catch(function (error) {
responseUtil.sendError(res, error);
});
});
//-----------------------------回标接口End----------------------
//-------------------------myc新接口End-----------------------
//-----------------------privateBegin--------------------------
function timeLog(_description){
console.log(_description +" time " + Date());
}
function deepCopyObjt(argument) {
if (typeof argument != "object") return argument;
var newObjt = {};
for (attr in argument){
newObjt[attr] = deepCopyObjt(argument[attr]);
}
return newObjt;
}
//log anyway
function logSomething(_logInfo,_txOption) {
logQKLServer.writeLogMycWrapper(deepCopyObjt(_logInfo),_txOption);
logSQLServer.writeLogMycWrapper(deepCopyObjt(_logInfo));
}
//转换成一维数组
function twoDToOneDArray(_twoArray) {
var oneArray_ = [];
for (var i = 0; i < _twoArray.length; i++) {
oneArray_ = oneArray_.concat(_twoArray[i]);
}
return oneArray_;
}
//-----------------------privateEND--------------------------
module.exports = managerBidBackAndIssue;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment