|
|
@ -3,72 +3,72 @@ |
|
|
|
async function bindAnxin2pep (ctx) { |
|
|
|
const transaction = await ctx.fs.dc.orm.transaction(); |
|
|
|
try { |
|
|
|
const models = ctx.fs.dc.models; |
|
|
|
const { clickHouse } = ctx.app.fs |
|
|
|
const { bindId, name, pepProjectId, anxinProjectId = [], app = [] } = ctx.request.body |
|
|
|
// const models = ctx.fs.dc.models;
|
|
|
|
// const { clickHouse } = ctx.app.fs
|
|
|
|
// const { bindId, name, pepProjectId, anxinProjectId = [], app = [] } = ctx.request.body
|
|
|
|
|
|
|
|
let bindId_ = bindId |
|
|
|
const existRes = await models.ProjectCorrelation.findOne({ |
|
|
|
where: { |
|
|
|
pepProjectId: pepProjectId |
|
|
|
} |
|
|
|
}) |
|
|
|
// let bindId_ = bindId
|
|
|
|
// const existRes = await models.ProjectCorrelation.findOne({
|
|
|
|
// where: {
|
|
|
|
// pepProjectId: pepProjectId
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
|
|
|
|
let storageData = { |
|
|
|
name, pepProjectId, anxinProjectId, |
|
|
|
} |
|
|
|
if (bindId_) { |
|
|
|
if (!existRes) { |
|
|
|
throw '尚无已绑定的项企项目' |
|
|
|
} |
|
|
|
// 修改
|
|
|
|
await models.ProjectCorrelation.update(storageData, { |
|
|
|
where: { |
|
|
|
pepProjectId: pepProjectId |
|
|
|
}, |
|
|
|
transaction |
|
|
|
}) |
|
|
|
} else { |
|
|
|
// 新增
|
|
|
|
if (existRes) { |
|
|
|
// 但是有之前的数据
|
|
|
|
if (existRes.del) { |
|
|
|
// 不过之前的删除了
|
|
|
|
// let storageData = {
|
|
|
|
// name, pepProjectId, anxinProjectId,
|
|
|
|
// }
|
|
|
|
// if (bindId_) {
|
|
|
|
// if (!existRes) {
|
|
|
|
// throw '尚无已绑定的项企项目'
|
|
|
|
// }
|
|
|
|
// // 修改
|
|
|
|
// await models.ProjectCorrelation.update(storageData, {
|
|
|
|
// where: {
|
|
|
|
// pepProjectId: pepProjectId
|
|
|
|
// },
|
|
|
|
// transaction
|
|
|
|
// })
|
|
|
|
// } else {
|
|
|
|
// // 新增
|
|
|
|
// if (existRes) {
|
|
|
|
// // 但是有之前的数据
|
|
|
|
// if (existRes.del) {
|
|
|
|
// // 不过之前的删除了
|
|
|
|
|
|
|
|
} else { |
|
|
|
// 没有删除 重复添加
|
|
|
|
throw '当前项企项目已绑定' |
|
|
|
} |
|
|
|
} else { |
|
|
|
const createRes = await models.ProjectCorrelation.create(storageData, { |
|
|
|
transaction |
|
|
|
}) |
|
|
|
bindId_ = createRes.id |
|
|
|
// } else {
|
|
|
|
// // 没有删除 重复添加
|
|
|
|
// throw '当前项企项目已绑定'
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// const createRes = await models.ProjectCorrelation.create(storageData, {
|
|
|
|
// transaction
|
|
|
|
// })
|
|
|
|
// bindId_ = createRes.id
|
|
|
|
|
|
|
|
await models.ProjectApp.bulkCreate(app.map((a, i, arr) => { |
|
|
|
if (!a.name || !a.url) { |
|
|
|
throw `${a.name} ${a.url} 缺少必要参数` |
|
|
|
} |
|
|
|
let curUrlArr = a.url.split('://') |
|
|
|
if(curUrlArr.length < 2){ |
|
|
|
throw `${a.name} ${a.url} url 地址错误` |
|
|
|
} |
|
|
|
for (let ii = i; ii < arr.length; ii++) { |
|
|
|
let |
|
|
|
} |
|
|
|
// await models.ProjectApp.bulkCreate(app.map((a, i, arr) => {
|
|
|
|
// if (!a.name || !a.url) {
|
|
|
|
// throw `${a.name} ${a.url} 缺少必要参数`
|
|
|
|
// }
|
|
|
|
// let curUrlArr = a.url.split('://')
|
|
|
|
// if(curUrlArr.length < 2){
|
|
|
|
// throw `${a.name} ${a.url} url 地址错误`
|
|
|
|
// }
|
|
|
|
// for (let ii = i; ii < arr.length; ii++) {
|
|
|
|
// let
|
|
|
|
// }
|
|
|
|
|
|
|
|
return { |
|
|
|
name: a.name, |
|
|
|
url: a.url, |
|
|
|
projectId: bindId_, |
|
|
|
lock: false, |
|
|
|
} |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
// return {
|
|
|
|
// name: a.name,
|
|
|
|
// url: a.url,
|
|
|
|
// projectId: bindId_,
|
|
|
|
// lock: false,
|
|
|
|
// }
|
|
|
|
// }))
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
await transaction.commit(); |
|
|
|
ctx.status = 204; |
|
|
|
// await transaction.commit();
|
|
|
|
// ctx.status = 204;
|
|
|
|
} catch (error) { |
|
|
|
await transaction.rollback(); |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|