197 lines
5.0 KiB
Go
197 lines
5.0 KiB
Go
package api
|
|
|
|
import (
|
|
"ArmedPolice/app/controller/basic"
|
|
"ArmedPolice/app/controller/tenant"
|
|
"ArmedPolice/app/service"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Tenant struct{}
|
|
|
|
type tenantForm struct {
|
|
ParentID string `json:"parent_id" form:"parent_id"`
|
|
Name string `json:"name" form:"name" binding:"required"`
|
|
Remark string `json:"remark" form:"remark"`
|
|
Province string `json:"province" form:"province"`
|
|
City string `json:"city" form:"city"`
|
|
District string `json:"district" form:"district"`
|
|
Address string `json:"address" form:"address"`
|
|
}
|
|
|
|
/**
|
|
* @apiDefine Tenant 租户(单位)管理
|
|
*/
|
|
|
|
/**
|
|
* @api {post} /api/v1/tenant/list 单位列表
|
|
* @apiVersion 1.0.0
|
|
* @apiName TenantList
|
|
* @apiGroup Tenant
|
|
*
|
|
* @apiHeader {string} x-token token
|
|
*
|
|
* @apiSuccess (200) {Object} data 数据信息
|
|
* @apiSuccess (200) {Object} data.data 具体信息
|
|
* @apiSuccess (200) {String} data.id ID
|
|
* @apiSuccess (200) {String} data.name 名称
|
|
* @apiSuccess (200) {String} data.province 省
|
|
* @apiSuccess (200) {String} data.city 市
|
|
* @apiSuccess (200) {String} data.district 区
|
|
* @apiSuccess (200) {String} data.address 地址
|
|
* @apiSuccess (200) {String} data.remark 备注
|
|
* @apiSuccess (200) {Object} data.children 子集
|
|
* @apiSuccess (200) {Number} code 成功响应状态码!
|
|
* @apiSuccess (200) {String} msg 成功提示
|
|
*
|
|
* @apiSuccessExample {json} Success response:
|
|
* HTTPS 200 OK
|
|
* {
|
|
* "code": 200
|
|
* "msg": "ok"
|
|
* "data": {
|
|
* [
|
|
* {
|
|
* "id": "EgmJ4Ga7LQ",
|
|
* "name": "合肥市武警支队",
|
|
* "province": "安徽省",
|
|
* "city": "合肥市",
|
|
* "district": "蜀山区",
|
|
* "address": "大蜀山。 ",
|
|
* "remark": "",
|
|
* "children": []
|
|
* }
|
|
* ],
|
|
* }
|
|
*/
|
|
func (*Tenant) List(c *gin.Context) {
|
|
data, err := tenant.NewInstance()(getSession()(c).(*service.Session)).List()
|
|
APIResponse(err, data)(c)
|
|
}
|
|
|
|
/**
|
|
* @api {post} /api/v1/tenant/add 单位信息添加
|
|
* @apiVersion 1.0.0
|
|
* @apiName TenantAdd
|
|
* @apiGroup Tenant
|
|
*
|
|
* @apiHeader {string} x-token token
|
|
*
|
|
* @apiParam {String} [parent_id="''"] 父集
|
|
* @apiParam {String} name 名称
|
|
* @apiParam {String} [remark="''"] 名称
|
|
* @apiParam {String} [province="''"] 省
|
|
* @apiParam {String} [city="''"] 市
|
|
* @apiParam {String} [district="''"] 区
|
|
* @apiParam {String} [address="''"] 地址
|
|
*
|
|
* @apiSuccess (200) {Object} data 数据信息
|
|
* @apiSuccess (200) {Number} code 成功响应状态码!
|
|
* @apiSuccess (200) {String} msg 成功提示
|
|
*
|
|
* @apiSuccessExample {json} Success response:
|
|
* HTTPS 200 OK
|
|
* {
|
|
* "code": 200
|
|
* "msg": "ok"
|
|
* "data": null
|
|
* }
|
|
*/
|
|
func (*Tenant) Add(c *gin.Context) {
|
|
form := new(tenantForm)
|
|
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
obj := &IDStringForm{ID: form.ParentID}
|
|
err := tenant.NewInstance()(getSession()(c).(*service.Session)).Form(&tenant.InstanceParams{
|
|
ParentID: obj.Convert(), Name: form.Name, Remark: form.Remark,
|
|
CommonArea: basic.CommonArea{
|
|
Province: form.Province, City: form.City, District: form.District, Address: form.Address,
|
|
},
|
|
})
|
|
APIResponse(err)(c)
|
|
}
|
|
|
|
/**
|
|
* @api {post} /api/v1/tenant/edit 单位信息修改
|
|
* @apiVersion 1.0.0
|
|
* @apiName TenantEdit
|
|
* @apiGroup Tenant
|
|
*
|
|
* @apiHeader {string} x-token token
|
|
*
|
|
* @apiParam {String} id ID
|
|
* @apiParam {String} [parent_id="''"] 父集
|
|
* @apiParam {String} name 名称
|
|
* @apiParam {String} [remark="''"] 名称
|
|
* @apiParam {String} [province="''"] 省
|
|
* @apiParam {String} [city="''"] 市
|
|
* @apiParam {String} [district="''"] 区
|
|
* @apiParam {String} [address="''"] 地址
|
|
*
|
|
* @apiSuccess (200) {Object} data 数据信息
|
|
* @apiSuccess (200) {Number} code 成功响应状态码!
|
|
* @apiSuccess (200) {String} msg 成功提示
|
|
*
|
|
* @apiSuccessExample {json} Success response:
|
|
* HTTPS 200 OK
|
|
* {
|
|
* "code": 200
|
|
* "msg": "ok"
|
|
* "data": null
|
|
* }
|
|
*/
|
|
func (*Tenant) Edit(c *gin.Context) {
|
|
form := &struct {
|
|
IDStringForm
|
|
tenantForm
|
|
}{}
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
obj := &IDStringForm{ID: form.ParentID}
|
|
err := tenant.NewInstance()(getSession()(c).(*service.Session)).Form(&tenant.InstanceParams{
|
|
ID: form.Convert(), ParentID: obj.Convert(), Name: form.Name, Remark: form.Remark,
|
|
CommonArea: basic.CommonArea{
|
|
Province: form.Province, City: form.City, District: form.District, Address: form.Address,
|
|
},
|
|
})
|
|
APIResponse(err)(c)
|
|
}
|
|
|
|
/**
|
|
* @api {post} /api/v1/tenant/delete 单位信息删除
|
|
* @apiVersion 1.0.0
|
|
* @apiName TenantDelete
|
|
* @apiGroup Tenant
|
|
*
|
|
* @apiHeader {string} x-token token
|
|
*
|
|
* @apiParam {String} id ID
|
|
*
|
|
* @apiSuccess (200) {Object} data 数据信息
|
|
* @apiSuccess (200) {Number} code 成功响应状态码!
|
|
* @apiSuccess (200) {String} msg 成功提示
|
|
*
|
|
* @apiSuccessExample {json} Success response:
|
|
* HTTPS 200 OK
|
|
* {
|
|
* "code": 200
|
|
* "msg": "ok"
|
|
* "data": null
|
|
* }
|
|
*/
|
|
func (*Tenant) Delete(c *gin.Context) {
|
|
form := new(IDStringForm)
|
|
|
|
if err := bind(form)(c); err != nil {
|
|
APIFailure(err.(error))(c)
|
|
return
|
|
}
|
|
err := tenant.NewInstance()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
|
APIResponse(err)(c)
|
|
}
|