You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
2.7 KiB
118 lines
2.7 KiB
'use strict';
|
|
const moment = require('moment')
|
|
|
|
|
|
|
|
async function getNetworks (ctx) {
|
|
try{
|
|
const models = ctx.fs.dc.models
|
|
const { limit, page, name } = ctx.query
|
|
let options = {
|
|
where: {},
|
|
order: [['id', 'asc']],
|
|
include:[{
|
|
model: models.Project,
|
|
attributes: ['id', 'name','type'],
|
|
}]
|
|
}
|
|
|
|
if (name) {
|
|
options.where.name = { $like: `%${name}%` };
|
|
}
|
|
if (limit) {
|
|
options.limit = Number(limit);
|
|
}
|
|
if (page && limit) {
|
|
options.offset = Number(page) * Number(limit);
|
|
}
|
|
const Networks = await models.Network.findAndCountAll(options)
|
|
ctx.status = 200;
|
|
ctx.body = Networks
|
|
}catch(error){
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
"message": "获取宽带专网失败"
|
|
}
|
|
}
|
|
}
|
|
|
|
async function addOrUpdateNetwork(ctx){
|
|
const { id,name,type,account,indate,projectId } = ctx.request.body
|
|
try{
|
|
if(id){
|
|
// 更新
|
|
await ctx.fs.dc.models.Network.update({
|
|
name,
|
|
type,
|
|
account,
|
|
indate,
|
|
projectId
|
|
}, {
|
|
where: {
|
|
id
|
|
}
|
|
})
|
|
ctx.status = 200;
|
|
ctx.body = {
|
|
message: '更新宽带专网成功'
|
|
}
|
|
}else{
|
|
//新增
|
|
await ctx.fs.dc.models.Network.create({
|
|
name,
|
|
type,
|
|
account,
|
|
indate,
|
|
projectId
|
|
})
|
|
ctx.status = 200;
|
|
ctx.body = {
|
|
message: '新增宽带专网成功'
|
|
}
|
|
|
|
}
|
|
|
|
}catch(error){
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
"message": id?'编辑宽带专网失败':'新增宽带专网失败'
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
async function delNetwork(ctx){
|
|
try{
|
|
const { id } = ctx.params
|
|
await ctx.fs.dc.models.Network.destroy({
|
|
where: {
|
|
id
|
|
}
|
|
})
|
|
ctx.status = 200;
|
|
ctx.body = {
|
|
message: '删除宽带专网成功'
|
|
}
|
|
|
|
}catch(error){
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
"message": "删除宽带专网失败"
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
getNetworks,
|
|
addOrUpdateNetwork,
|
|
delNetwork,
|
|
|
|
}
|
|
|