[ADD]系统厂商和业务系统

This commit is contained in:
hehui 2019-08-11 15:41:32 +08:00
parent 05eea252ef
commit e7468ab608
21 changed files with 1381 additions and 85 deletions

3
.gitignore vendored
View File

@ -12,4 +12,5 @@
*.out
conf/app.ini
.idea/*
.idea/*
runtime/logs/*

View File

@ -0,0 +1,149 @@
package basic
import (
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"github.com/viletyy/potato/models/basic"
"github.com/viletyy/potato/pkg/e"
"github.com/viletyy/potato/pkg/setting"
"github.com/viletyy/potato/pkg/util"
"net/http"
)
// @Summary 业务系统列表
// @Tags businesses
// @Description
// @Accept json
// @Produce json
// @Success 200 {string} json "{"code" : 200, "data" : {}, "msg" : "ok"}"
// @Router /v1/businesses [get]
func GetBusinesses(c *gin.Context) {
maps := make(map[string]interface{})
data := make(map[string]interface{})
data["lists"] = basic.GetBusinesses(util.GetPage(c), setting.PageSize, maps)
data["total"] = basic.GetBusinessTotal(maps)
code := e.SUCCESS
c.JSON(http.StatusOK, gin.H{
"code" : code,
"msg" : e.GetMsg(code),
"data" : data,
})
}
// @Summary 新增业务系统
// @Tags businesses
// @Description
// @Accept mpfd
// @Produce json
// @Param name formData string true "业务系统 名称"
// @Param desc formData string false "业务系统 描述"
// @Param c_id formData int false "业务系统 云端id"
// @Success 200 {string} json "{"code" : 200, "msg" : "ok"}"
// @Router /v1/businesses [post]
func AddBusiness(c *gin.Context) {
name := c.PostForm("name")
desc := c.PostForm("desc")
cId := com.StrTo(c.PostForm("c_id")).MustInt()
valid := validation.Validation{}
valid.Required(name, "name").Message("名称不能为空")
code := e.INVALID_PARAMS
if ! valid.HasErrors() {
if ! basic.ExistVendorByName(name) {
code = e.SUCCESS
basic.AddBusiness(name, desc, cId)
} else {
code = e.ERROR_EXIST_BUSINESS
}
}
c.JSON(http.StatusOK, gin.H{
"code" : code,
"msg" : e.GetMsg(code),
"data" : make(map[string]string),
})
}
// @Summary 修改业务系统
// @Tags businesses
// @Description
// @Accept mpfd
// @Produce json
// @Param id path int true "业务系统 ID"
// @Param name formData string false "业务系统 名称"
// @Param desc formData string false "业务系统 描述"
// @Param c_id formData string false "业务系统 云端id"
// @Success 200 {string} json "{"code" : 200, "msg" : "ok"}"
// @Router /v1/businesses/{id} [patch]
func EditBusiness(c *gin.Context) {
id := com.StrTo(c.Param("id")).MustInt()
name := c.PostForm("name")
desc := c.PostForm("desc")
cId := com.StrTo(c.PostForm("c_id")).MustInt()
valid := validation.Validation{}
valid.Min(id, 1, "id").Message("ID必须大于0")
data := make(map[string]interface{})
code := e.INVALID_PARAMS
if ! valid.HasErrors() {
code = e.SUCCESS
if basic.ExistVendorById(id) {
if name != "" {
data["name"] = name
}
if desc != "" {
data["desc"] = desc
}
if cId != 0 {
data["c_id"] = cId
}
basic.EditBusiness(id, data)
} else {
code = e.ERROR_NOT_EXIST_BUSINESS
}
}
c.JSON(http.StatusOK, gin.H{
"code" : code,
"msg" : e.GetMsg(code),
"data" : data,
})
}
// @Summary 删除业务系统
// @Tags businesses
// @Description
// @Accept json
// @Produce json
// @Param id path int true "业务系统 ID"
// @Success 200 {string} json "{"code" : 200, "msg" : "ok"}"
// @Router /v1/businesses/{id} [delete]
func DeleteBusiness(c *gin.Context) {
id := com.StrTo(c.Param("id")).MustInt()
valid := validation.Validation{}
valid.Min(id, 1, "id").Message("ID必须大于0")
code := e.INVALID_PARAMS
if ! valid.HasErrors() {
code = e.SUCCESS
if basic.ExistBusinessById(id) {
basic.DeleteBusiness(id)
} else {
code = e.ERROR_NOT_EXIST_BUSINESS
}
}
c.JSON(http.StatusOK, gin.H{
"code" : code,
"msg" : e.GetMsg(code),
"data" : make(map[string]string),
})
}

View File

@ -1,9 +1,9 @@
package data
package basic
import (
"github.com/gin-gonic/gin"
_ "github.com/viletyy/potato/models/data"
data2 "github.com/viletyy/potato/models/data"
"github.com/viletyy/potato/models/basic"
_ "github.com/viletyy/potato/models/basic"
"github.com/viletyy/potato/pkg/e"
"github.com/viletyy/potato/pkg/setting"
"github.com/viletyy/potato/pkg/util"
@ -15,7 +15,7 @@ import (
// @Description
// @Accept json
// @Produce json
// @Success 200 {string} json "{"code" : 200, "data" : {}, "msg": "ok" }"
// @Success 200 {string} json "{"code" : 200, "basic" : {}, "msg": "ok" }"
// @Router /v1/meta_databases [get]
func GetMetaDatabases(c *gin.Context) {
name := c.Query("name")
@ -27,13 +27,13 @@ func GetMetaDatabases(c *gin.Context) {
maps["name"] = name
}
data["lists"] = data2.GetMetaDatabases(util.GetPage(c), setting.PageSize, maps)
data["total"] = data2.GetMetaDatabaseTotal(maps)
data["lists"] = basic.GetMetaDatabases(util.GetPage(c), setting.PageSize, maps)
data["total"] = basic.GetMetaDatabaseTotal(maps)
code := e.SUCCESS
c.JSON(http.StatusOK, gin.H{
"code": code,
"msg": e.GetMsg(code),
"data": data,
"basic": data,
})
}

View File

@ -1,4 +1,4 @@
package data
package basic
import (
"github.com/gin-gonic/gin"
@ -12,8 +12,8 @@ import (
// @Accept json
// @Produce json
// @Param id path int true "数据源 ID"
// @Success 200 {string} json "{"code" : 200, "data" : {}, "msg": "ok" }"
// @Router /v1/meta_databases/:id/meta_tables [get]
// @Success 200 {string} json "{"code" : 200, "basic" : {}, "msg": "ok" }"
// @Router /v1/meta_databases/{id}/meta_tables [get]
func GetMetaTables(c *gin.Context) {
name := c.Query("name")
@ -29,6 +29,6 @@ func GetMetaTables(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": code,
"msg": e.GetMsg(code),
"data": data,
"basic": data,
})
}

View File

@ -0,0 +1,144 @@
package basic
import (
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"github.com/viletyy/potato/models/basic"
"github.com/viletyy/potato/pkg/e"
"github.com/viletyy/potato/pkg/setting"
"github.com/viletyy/potato/pkg/util"
"net/http"
)
// @Summary 系统厂商列表
// @Tags vendors
// @Description
// @Accept json
// @Produce json
// @Success 200 {string} json "{"code" : 200, "data" : {}, "msg" : "ok"}"
// @Router /v1/vendors [get]
func GetVendors(c *gin.Context) {
maps := make(map[string]interface{})
data := make(map[string]interface{})
data["lists"] = basic.GetVendors(util.GetPage(c), setting.PageSize, maps)
data["total"] = basic.GetVendorsTotal(maps)
code := e.SUCCESS
c.JSON(http.StatusOK, gin.H{
"code": code,
"msg": e.GetMsg(code),
"data": data,
})
}
// @Summary 新增系统厂商
// @Tags vendors
// @Description
// @Accept mpfd
// @Produce json
// @Param name formData string true "系统厂商 名称"
// @Param c_id formData int false "系统厂商 云端id"
// @Success 200 {string} json "{"code" : 200, "msg" : "ok"}"
// @Router /v1/vendors [post]
func AddVendor(c *gin.Context) {
name := c.PostForm("name")
cId := com.StrTo(c.PostForm("c_id")).MustInt()
valid := validation.Validation{}
valid.Required(name, "name").Message("名称不能为空")
code := e.INVALID_PARAMS
if ! valid.HasErrors() {
if ! basic.ExistVendorByName(name) {
code = e.SUCCESS
basic.AddVendor(name, cId)
} else {
code = e.ERROR_EXIST_VENDOR
}
}
c.JSON(http.StatusOK, gin.H{
"code" : code,
"msg" : e.GetMsg(code),
"data" : make(map[string]string),
})
}
// @Summary 修改系统厂商
// @Tags vendors
// @Description
// @Accept mpfd
// @Produce json
// @Param id path int true "系统厂商 ID"
// @Param name formData string false "系统厂商 名称"
// @Param c_id formData int false "系统厂商 云端id"
// @Success 200 {string} json "{"code" : 200, "msg" : "ok"}"
// @Router /v1/vendors/{id} [patch]
func EditVendor(c *gin.Context) {
id := com.StrTo(c.Param("id")).MustInt()
name := c.PostForm("name")
cId := com.StrTo(c.PostForm("c_id")).MustInt()
valid := validation.Validation{}
valid.Min(id, 1, "id").Message("ID必须大于0")
data := make(map[string]interface{})
code := e.INVALID_PARAMS
if ! valid.HasErrors() {
code = e.SUCCESS
if basic.ExistVendorById(id) {
if name != "" {
data["name"] = name
}
if cId > 0 {
data["c_id"] = cId
}
basic.EditVendor(id, data)
} else {
code = e.ERROR_NOT_EXIST_VENDOR
}
}
c.JSON(http.StatusOK, gin.H{
"code" : code,
"msg" : e.GetMsg(code),
"data" : data,
})
}
// @Summary 删除系统厂商
// @Tags vendors
// @Description
// @Accept json
// @Produce json
// @Param id path int true "系统厂商 ID"
// @Success 200 {string} json "{"code" : 200, "msg" : "ok"}"
// @Router /v1/vendors/{id} [delete]
func DeleteVendor(c *gin.Context) {
id := com.StrTo(c.Param("id")).MustInt()
valid := validation.Validation{}
valid.Min(id, 1, "id").Message("ID必须大于0")
code := e.INVALID_PARAMS
if ! valid.HasErrors() {
code = e.SUCCESS
if basic.ExistVendorById(id) {
basic.DeleteVendor(id)
} else {
code = e.ERROR_NOT_EXIST_VENDOR
}
}
c.JSON(http.StatusOK, gin.H{
"code" : code,
"msg" : e.GetMsg(code),
"data" : make(map[string]string),
})
}

View File

@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2019-08-07 19:40:27.3805 +0800 CST m=+0.046403409
// 2019-08-11 15:32:17.412899 +0800 CST m=+0.054203802
package docs
@ -25,7 +25,331 @@ var doc = `{
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {}
"paths": {
"/v1/businesses": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "业务系统列表",
"responses": {
"200": {
"description": "{\"code\" : 200, \"data\" : {}, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"post": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "新增业务系统",
"parameters": [
{
"type": "string",
"description": "业务系统 名称",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "业务系统 描述",
"name": "desc",
"in": "formData"
},
{
"type": "integer",
"description": "业务系统 云端id",
"name": "c_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/businesses/{id}": {
"delete": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "删除业务系统",
"parameters": [
{
"type": "integer",
"description": "业务系统 ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"patch": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "修改业务系统",
"parameters": [
{
"type": "integer",
"description": "业务系统 ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "业务系统 名称",
"name": "name",
"in": "formData"
},
{
"type": "string",
"description": "业务系统 描述",
"name": "desc",
"in": "formData"
},
{
"type": "string",
"description": "业务系统 云端id",
"name": "c_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/meta_databases": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"meta_databases"
],
"summary": "数据源列表",
"responses": {
"200": {
"description": "{\"code\" : 200, \"basic\" : {}, \"msg\": \"ok\" }",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/meta_databases/{id}/meta_tables": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"meta_tables"
],
"summary": "元数据列表",
"parameters": [
{
"type": "integer",
"description": "数据源 ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"basic\" : {}, \"msg\": \"ok\" }",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/vendors": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"vendors"
],
"summary": "系统厂商列表",
"responses": {
"200": {
"description": "{\"code\" : 200, \"data\" : {}, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"post": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"vendors"
],
"summary": "新增系统厂商",
"parameters": [
{
"type": "string",
"description": "系统厂商 名称",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "integer",
"description": "系统厂商 云端id",
"name": "c_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/vendors/{id}": {
"delete": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"vendors"
],
"summary": "删除系统厂商",
"parameters": [
{
"type": "integer",
"description": "系统厂商 ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"patch": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"vendors"
],
"summary": "修改系统厂商",
"parameters": [
{
"type": "integer",
"description": "系统厂商 ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "系统厂商 名称",
"name": "name",
"in": "formData"
},
{
"type": "integer",
"description": "系统厂商 云端id",
"name": "c_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
}
}
}`
type swaggerInfo struct {
@ -41,7 +365,7 @@ type swaggerInfo struct {
var SwaggerInfo = swaggerInfo{
Version: "1.0",
Host: "",
BasePath: "/",
BasePath: "/api",
Schemes: []string{},
Title: "Potato Api",
Description: "This is a data_govern use golang",

View File

@ -7,6 +7,330 @@
"license": {},
"version": "1.0"
},
"basePath": "/",
"paths": {}
"basePath": "/api",
"paths": {
"/v1/businesses": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "业务系统列表",
"responses": {
"200": {
"description": "{\"code\" : 200, \"data\" : {}, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"post": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "新增业务系统",
"parameters": [
{
"type": "string",
"description": "业务系统 名称",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "业务系统 描述",
"name": "desc",
"in": "formData"
},
{
"type": "integer",
"description": "业务系统 云端id",
"name": "c_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/businesses/{id}": {
"delete": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "删除业务系统",
"parameters": [
{
"type": "integer",
"description": "业务系统 ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"patch": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"businesses"
],
"summary": "修改业务系统",
"parameters": [
{
"type": "integer",
"description": "业务系统 ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "业务系统 名称",
"name": "name",
"in": "formData"
},
{
"type": "string",
"description": "业务系统 描述",
"name": "desc",
"in": "formData"
},
{
"type": "string",
"description": "业务系统 云端id",
"name": "c_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/meta_databases": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"meta_databases"
],
"summary": "数据源列表",
"responses": {
"200": {
"description": "{\"code\" : 200, \"basic\" : {}, \"msg\": \"ok\" }",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/meta_databases/{id}/meta_tables": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"meta_tables"
],
"summary": "元数据列表",
"parameters": [
{
"type": "integer",
"description": "数据源 ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"basic\" : {}, \"msg\": \"ok\" }",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/vendors": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"vendors"
],
"summary": "系统厂商列表",
"responses": {
"200": {
"description": "{\"code\" : 200, \"data\" : {}, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"post": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"vendors"
],
"summary": "新增系统厂商",
"parameters": [
{
"type": "string",
"description": "系统厂商 名称",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "integer",
"description": "系统厂商 云端id",
"name": "c_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/vendors/{id}": {
"delete": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"vendors"
],
"summary": "删除系统厂商",
"parameters": [
{
"type": "integer",
"description": "系统厂商 ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
},
"patch": {
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"vendors"
],
"summary": "修改系统厂商",
"parameters": [
{
"type": "integer",
"description": "系统厂商 ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "系统厂商 名称",
"name": "name",
"in": "formData"
},
{
"type": "integer",
"description": "系统厂商 云端id",
"name": "c_id",
"in": "formData"
}
],
"responses": {
"200": {
"description": "{\"code\" : 200, \"msg\" : \"ok\"}",
"schema": {
"type": "string"
}
}
}
}
}
}
}

View File

@ -1,9 +1,219 @@
basePath: /
basePath: /api
info:
contact: {}
description: This is a data_govern use golang
license: {}
title: Potato Api
version: "1.0"
paths: {}
paths:
/v1/businesses:
get:
consumes:
- application/json
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "data" : {}, "msg" : "ok"}'
schema:
type: string
summary: 业务系统列表
tags:
- businesses
post:
consumes:
- multipart/form-data
parameters:
- description: 业务系统 名称
in: formData
name: name
required: true
type: string
- description: 业务系统 描述
in: formData
name: desc
type: string
- description: 业务系统 云端id
in: formData
name: c_id
type: integer
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "msg" : "ok"}'
schema:
type: string
summary: 新增业务系统
tags:
- businesses
/v1/businesses/{id}:
delete:
consumes:
- application/json
parameters:
- description: 业务系统 ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "msg" : "ok"}'
schema:
type: string
summary: 删除业务系统
tags:
- businesses
patch:
consumes:
- multipart/form-data
parameters:
- description: 业务系统 ID
in: path
name: id
required: true
type: integer
- description: 业务系统 名称
in: formData
name: name
type: string
- description: 业务系统 描述
in: formData
name: desc
type: string
- description: 业务系统 云端id
in: formData
name: c_id
type: string
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "msg" : "ok"}'
schema:
type: string
summary: 修改业务系统
tags:
- businesses
/v1/meta_databases:
get:
consumes:
- application/json
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "basic" : {}, "msg": "ok" }'
schema:
type: string
summary: 数据源列表
tags:
- meta_databases
/v1/meta_databases/{id}/meta_tables:
get:
consumes:
- application/json
parameters:
- description: 数据源 ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "basic" : {}, "msg": "ok" }'
schema:
type: string
summary: 元数据列表
tags:
- meta_tables
/v1/vendors:
get:
consumes:
- application/json
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "data" : {}, "msg" : "ok"}'
schema:
type: string
summary: 系统厂商列表
tags:
- vendors
post:
consumes:
- multipart/form-data
parameters:
- description: 系统厂商 名称
in: formData
name: name
required: true
type: string
- description: 系统厂商 云端id
in: formData
name: c_id
type: integer
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "msg" : "ok"}'
schema:
type: string
summary: 新增系统厂商
tags:
- vendors
/v1/vendors/{id}:
delete:
consumes:
- application/json
parameters:
- description: 系统厂商 ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "msg" : "ok"}'
schema:
type: string
summary: 删除系统厂商
tags:
- vendors
patch:
consumes:
- multipart/form-data
parameters:
- description: 系统厂商 ID
in: path
name: id
required: true
type: integer
- description: 系统厂商 名称
in: formData
name: name
type: string
- description: 系统厂商 云端id
in: formData
name: c_id
type: integer
produces:
- application/json
responses:
"200":
description: '{"code" : 200, "msg" : "ok"}'
schema:
type: string
summary: 修改系统厂商
tags:
- vendors
swagger: "2.0"

View File

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"github.com/viletyy/potato/pkg/setting"
"github.com/viletyy/potato/pkg/util"
"github.com/viletyy/potato/routers"
"log"
"net/http"
@ -21,12 +20,6 @@ import (
func main() {
router := routers.InitRouter()
// 数据库配置
_ = util.InitDB()
defer util.CloseDB()
util.InitRedis()
defer util.CloseRedis()
server := &http.Server{
Addr: fmt.Sprintf(":%d", setting.HTTPPort),
Handler: router,

View File

@ -30,7 +30,7 @@ func JWT() gin.HandlerFunc {
c.JSON(http.StatusUnauthorized, gin.H{
"code" : code,
"msg" : e.GetMsg(code),
"data" : data,
"basic" : data,
})
c.Abort()

61
models/basic/business.go Normal file
View File

@ -0,0 +1,61 @@
package basic
import "github.com/viletyy/potato/pkg/util"
type Business struct {
util.Model
Name string `json:"name"`
Desc string `json:"desc"`
CId int `json:"c_id"`
}
func GetBusinesses(pageNum int, pageSize int, maps interface{}) (businesses []Business) {
util.DB.Where(maps).Offset(pageNum).Limit(pageSize).Find(&businesses)
return
}
func GetBusinessTotal(maps interface{}) (count int) {
util.DB.Model(&Business{}).Where(maps).Count(&count)
return
}
func ExistBusinessByName(name string) bool {
var business Business
util.DB.Select("id").Where("name = ?", name).First(&business)
if business.ID > 0 {
return true
}
return false
}
func ExistBusinessById(id int) bool {
var business Business
util.DB.Select("id").Where("id = ?", id).First(&business)
if business.ID > 0 {
return true
}
return false
}
func AddBusiness(name string, desc string, cId int) bool {
util.DB.Create(&Business {
Name: name,
Desc: desc,
CId: cId,
})
return true
}
func EditBusiness(id int, data interface{}) bool {
util.DB.Model(&Business{}).Where("id = ?", id).Update(data)
return true
}
func DeleteBusiness(id int) bool {
util.DB.Where("id = ?", id).Delete(&Business{})
return true
}

View File

@ -0,0 +1,34 @@
package basic
import (
"github.com/viletyy/potato/pkg/util"
"time"
)
type MetaDatabase struct {
util.Model
Name string `json:"name"`
Host string `json:"host"`
Port string `json:"port"`
DbName string `json:"db_name"`
Username string `json:"username"`
Password string `json:"password"`
LastConnectTime time.Time `json:"last_connect_time"`
Usable bool `json:"usable"`
Comment string `json:"comment"`
Vendor Vendor
VendorId int `json:"vendor_id"`
Business Business
BusinessId int `json:"business_id"`
}
func GetMetaDatabases(pageNum int, pageSize int, maps interface{}) (metaDatabases []MetaDatabase) {
util.DB.Where(maps).Offset(pageNum).Limit(pageSize).Find(&metaDatabases)
return
}
func GetMetaDatabaseTotal(maps interface{}) (count int) {
util.DB.Model(&MetaDatabase{}).Where(maps).Count(&count)
return
}

7
models/basic/migrate.go Normal file
View File

@ -0,0 +1,7 @@
package basic
import "github.com/viletyy/potato/pkg/util"
func init() {
util.DB.AutoMigrate(&MetaDatabase{}, &Vendor{}, &Business{})
}

59
models/basic/vendor.go Normal file
View File

@ -0,0 +1,59 @@
package basic
import "github.com/viletyy/potato/pkg/util"
type Vendor struct {
util.Model
Name string `json:"name"`
CId int `json:"c_id"`
}
func GetVendors(pageNum int, pageSize int, maps interface{}) (vendors []Vendor) {
util.DB.Where(maps).Offset(pageNum).Limit(pageSize).Find(&vendors)
return
}
func GetVendorsTotal(maps interface{}) (count int) {
util.DB.Model(&Vendor{}).Where(maps).Count(&count)
return
}
func ExistVendorByName(name string) bool {
var vendor Vendor
util.DB.Select("id").Where("name = ?", name).First(&vendor)
if vendor.ID > 0 {
return true
}
return false
}
func ExistVendorById(id int) bool {
var vendor Vendor
util.DB.Select("id").Where("id = ?", id).First(&vendor)
if vendor.ID > 0 {
return true
}
return false
}
func AddVendor(name string, cId int) bool {
util.DB.Create(&Vendor {
Name: name,
CId: cId,
})
return true
}
func EditVendor(id int, data interface{}) bool {
util.DB.Model(&Vendor{}).Where("id = ?", id).Update(data)
return true
}
func DeleteVendor(id int) bool {
util.DB.Where("id = ?", id).Delete(&Vendor{})
return true
}

View File

@ -1,23 +0,0 @@
package data
import "github.com/viletyy/potato/pkg/util"
type MetaDatabase struct {
util.Model
Name string `json:"name"`
CnName string `json:"cn_name"`
Logo string `json:"logo"`
}
func GetMetaDatabases(pageNum int, pageSize int, maps interface{}) (metaDatabases []MetaDatabase) {
util.DB.Where(maps).Offset(pageNum).Limit(pageSize).Find(&metaDatabases)
return
}
func GetMetaDatabaseTotal(maps interface{}) (count int) {
util.DB.Model(&MetaDatabase{}).Where(maps).Count(&count)
return
}

View File

@ -5,12 +5,10 @@ const (
ERROR = 500
INVALID_PARAMS = 400
ERROR_EXIST_GAME = 10001
ERROR_EXIST_TEAM = 10002
ERROR_NOT_EXIST_GAME = 10003
ERROR_NOT_EXIST_TEAM = 10004
ERROR_NOT_EXIST_LEAGUE = 10005
ERROR_NOT_EXIST_SERIES = 10006
ERROR_EXIST_VENDOR = 10011
ERROR_NOT_EXIST_VENDOR = 10012
ERROR_EXIST_BUSINESS = 10021
ERROR_NOT_EXIST_BUSINESS = 10022
ERROR_AUTH_CHECK_TOKEN_FAIL = 20001
ERROR_AUTH_CHECK_TOKEN_TIMEOUT = 20002

View File

@ -4,12 +4,10 @@ var MsgFlags = map[int]string {
SUCCESS : "ok",
ERROR : "fail",
INVALID_PARAMS : "请求参数错误",
ERROR_EXIST_GAME : "已存在该游戏",
ERROR_EXIST_TEAM : "已存在该队伍",
ERROR_NOT_EXIST_GAME : "该游戏不存在",
ERROR_NOT_EXIST_TEAM : "该队伍不存在",
ERROR_NOT_EXIST_LEAGUE : "该联赛不存在",
ERROR_NOT_EXIST_SERIES : "该系列赛不存在",
ERROR_EXIST_VENDOR : "已存在该系统厂商",
ERROR_NOT_EXIST_VENDOR : "该系统厂商不存在",
ERROR_EXIST_BUSINESS : "已存在该业务系统",
ERROR_NOT_EXIST_BUSINESS : "该业务系统不存在",
ERROR_AUTH_CHECK_TOKEN_FAIL : "Token鉴权失败",
ERROR_AUTH_CHECK_TOKEN_TIMEOUT : "Token已超时",

View File

@ -19,10 +19,19 @@ type Model struct {
var(
DB *gorm.DB
DB = InitDB()
Redis *redis.Client
)
func init() {
// 数据库配置
InitDB()
//defer DB.Close()
InitRedis()
defer Redis.Close()
}
func InitDB() *gorm.DB {
var (
err error
@ -58,6 +67,8 @@ func InitDB() *gorm.DB {
DB.DB().SetMaxIdleConns(10)
DB.DB().SetMaxOpenConns(100)
logging.Info(DB)
return DB
}
@ -79,11 +90,3 @@ func InitRedis() {
logging.Fatal("redis连接失败!", err)
}
}
func CloseDB() {
DB.Close()
}
func CloseRedis() {
Redis.Close()
}

27
routers/basic.go Normal file
View File

@ -0,0 +1,27 @@
package routers
import (
"github.com/viletyy/potato/controller/api/v1/basic"
)
func V1InitBasicRouter() {
metaDatabases := V1RouterGroup.Group("/meta_databases")
{
metaDatabases.GET("", basic.GetMetaDatabases)
metaDatabases.GET("/:id/meta_tables", basic.GetMetaTables)
}
vendors := V1RouterGroup.Group("/vendors")
{
vendors.GET("", basic.GetVendors)
vendors.POST("", basic.AddVendor)
vendors.PATCH("/:id", basic.EditVendor)
vendors.DELETE("/:id", basic.DeleteVendor)
}
businesses := V1RouterGroup.Group("/businesses")
{
businesses.GET("", basic.GetBusinesses)
businesses.POST("", basic.AddBusiness)
businesses.PATCH("/:id", basic.EditBusiness)
businesses.DELETE("/:id", basic.DeleteBusiness)
}
}

View File

@ -1,13 +0,0 @@
package routers
import (
"github.com/viletyy/potato/controller/api/v1/data"
)
func V1InitDataRouter() {
metaDatabases := V1RouterGroup.Group("/meta_databases")
{
metaDatabases.GET("", data.GetMetaDatabases)
metaDatabases.GET(":id/meta_tables", data.GetMetaTables)
}
}

View File

@ -35,5 +35,5 @@ func InitRouter() *gin.Engine {
}
func V1InitModule() {
V1InitDataRouter()
V1InitBasicRouter()
}