feat:完善项目

This commit is contained in:
henry
2021-11-02 16:22:07 +08:00
parent 690cd96bed
commit 20d81825e1
81 changed files with 5394 additions and 3700 deletions

View File

@ -1,9 +1,7 @@
package api
import (
"ArmedPolice/app/controller"
"ArmedPolice/app/service"
"ArmedPolice/app/controller/account"
"github.com/gin-gonic/gin"
)
@ -52,8 +50,8 @@ func (a *Account) Login(c *gin.Context) {
APIFailure(err.(error))(c)
return
}
data, err := controller.NewAccount()(nil).Login(form.Account, form.Password, form.Captcha.Key, form.Captcha.Value,
c.GetHeader("x-equipment"), c.ClientIP())
//c.GetHeader("x-equipment")
data, err := account.NewInstance()(nil).Login()
APIResponse(err, data)(c)
}
@ -77,6 +75,6 @@ func (a *Account) Login(c *gin.Context) {
* }
*/
func (a *Account) Logout(c *gin.Context) {
err := controller.NewAccount()(getSession()(c).(*service.Session)).Logout()
APIResponse(err)(c)
//err := controller.NewAccount()(getSession()(c).(*service.Session)).Logout()
//APIResponse(err)(c)
}

View File

@ -1,101 +0,0 @@
package api
import (
"ArmedPolice/app/controller/auth"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
type Auth struct{}
/**
* @apiDefine Auth 权限管理
*/
func (a *Auth) List(c *gin.Context) {
data, err := auth.NewInstance()(getSession()(c).(*service.Session)).List()
APIResponse(err, data)(c)
}
/**
* @api {post} /api/auth/tenant/bind 租户权限绑定
* @apiVersion 1.0.0
* @apiName AuthTenantBind
* @apiGroup Auth
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} tenant_id 租户ID
* @apiParam {Array.Number} auth_ids 权限ID
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Auth) TenantBind(c *gin.Context) {
form := &struct {
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
AuthIDs []uint64 `json:"auth_ids" form:"auth_ids" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := auth.NewTenant()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.AuthIDs)
APIResponse(err)(c)
}
func (a *Auth) Role(c *gin.Context) {
form := &struct {
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := auth.NewRole()(getSession()(c).(*service.Session)).List(form.RoleID)
APIResponse(err, data)(c)
}
/**
* @api {post} /api/auth/role/bind 角色权限绑定
* @apiVersion 1.0.0
* @apiName AuthRoleBind
* @apiGroup Auth
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} role_id 角色ID
* @apiParam {Array.Number} auth_ids 权限ID
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Auth) RoleBind(c *gin.Context) {
form := &struct {
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
AuthIDs []uint64 `json:"auth_ids" form:"auth_ids" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := auth.NewRole()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.AuthIDs)
APIResponse(err)(c)
}

View File

@ -1,34 +0,0 @@
package api
import (
"ArmedPolice/app/controller"
"github.com/gin-gonic/gin"
)
type Config struct{}
func (a *Config) List(c *gin.Context) {
form := &struct {
Kind int `json:"kind" form:"kind"`
pageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := controller.NewConfig()().Config(form.Kind, form.Page, form.PageSize)
APIResponse(err, data)
}
func (a *Config) Edit(c *gin.Context) {
form := &struct {
Params map[string]interface{} `json:"params" form:"params" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := controller.NewConfig()().Form(form.Params)
APIResponse(err)
}

View File

@ -1,23 +0,0 @@
package api
import (
"ArmedPolice/app/controller"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
type Log struct{}
func (a *Log) Login(c *gin.Context) {
form := &struct {
Name string `json:"name" form:"name"`
pageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := controller.NewLog()(getSession()(c).(*service.Session)).Login(form.Name, form.Page, form.PageSize)
APIResponse(err, data)(c)
}

View File

@ -1,425 +0,0 @@
package api
import (
"ArmedPolice/app/controller/menu"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
type Menu struct{}
type (
// menuForm 菜单信息
menuForm struct {
ParentID uint64 `json:"parent_id" form:"parent_id"`
Name string `json:"name" form:"name" binding:"required"`
Kind int `json:"kind" form:"kind" binding:"required"`
Link string `json:"link" form:"link"`
Component string `json:"component" form:"component"`
Icon string `json:"icon" form:"icon"`
Auth int `json:"auth" form:"auth"`
Sort int `json:"sort" form:"sort"`
Status int `json:"status" form:"status"`
Remark string `json:"remark" form:"remark"`
}
)
/**
* @apiDefine Menu 菜单管理
*/
/**
* @api {get} /api/menu/list 菜单列表
* @apiVersion 1.0.0
* @apiName MenuList
* @apiGroup Menu
*
* @apiHeader {string} x-token token
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Array} data 具体信息
* @apiSuccess (200) {Number} data.id 菜单ID
* @apiSuccess (200) {Number} data.parent_id 父级ID
* @apiSuccess (200) {String} data.name 菜单名称
* @apiSuccess (200) {Number} data.kind 类型1目录2菜单
* @apiSuccess (200) {String} data.link 访问地址
* @apiSuccess (200) {String} data.component 组件
* @apiSuccess (200) {Array} data.children="[]" 子集
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": [
* "id": 1,
* "parent_id": 0,
* "name": "系统管理",
* "kind": 1,
* "link": "1"
* "component": ""
* "children": [
* {
* "id": 2,
* "parent_id": 1,
* "name": "用户管理",
* "kind": 1,
* "link": "1"
* "component": ""
* "children": [],
* }
* ]
* ]
* }
*/
func (a *Menu) List(c *gin.Context) {
data, err := menu.NewInstance()(getSession()(c).(*service.Session)).List()
APIResponse(err, data)(c)
}
/**
* @api {post} /api/menu/add 菜单添加
* @apiVersion 1.0.0
* @apiName MenuAdd
* @apiGroup Menu
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} parent_id 父级ID
* @apiParam {String} name 菜单名
* @apiParam {Number} kind 菜单类型1目录2菜单
* @apiParam {String} link 访问地址
* @apiParam {String} component 页面组件
* @apiParam {String} icon 页面icon
* @apiParam {Number} auth 菜单权限0普通权限1超管权限
* @apiParam {Number} sort 排序,从大到小
* @apiParam {Number} status 忘了干嘛,没用
* @apiParam {String} remark 备注信息
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* }
*/
func (a *Menu) Add(c *gin.Context) {
form := new(menuForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := menu.NewInstance()(getSession()(c).(*service.Session)).Data(&menu.InstanceParams{
ParentID: form.ParentID, Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component,
Icon: form.Icon, Auth: form.Auth, Sort: form.Sort, Status: form.Status, Remark: form.Remark,
})
APIResponse(err)(c)
}
/**
* @api {post} /api/menu/edit 菜单修改
* @apiVersion 1.0.0
* @apiName MenuEdit
* @apiGroup Menu
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} id ID
* @apiParam {Number} parent_id 父级ID
* @apiParam {String} name 菜单名
* @apiParam {Number} kind 菜单类型1目录2菜单
* @apiParam {String} link 访问地址
* @apiParam {String} component 页面组件
* @apiParam {String} icon 页面icon
* @apiParam {Number} auth 菜单权限0普通权限1超管权限
* @apiParam {Number} sort 排序,从大到小
* @apiParam {Number} status 禁用状态1启用2禁用
* @apiParam {String} remark 备注信息
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* }
*/
func (a *Menu) Edit(c *gin.Context) {
form := &struct {
idForm
menuForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := menu.NewInstance()(getSession()(c).(*service.Session)).Data(&menu.InstanceParams{
ID: form.ID, ParentID: form.ParentID, Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component,
Icon: form.Icon, Auth: form.Auth, Sort: form.Sort, Status: form.Status, Remark: form.Remark,
})
APIResponse(err)(c)
}
/**
* @api {post} /api/menu/status 菜单状态
* @apiVersion 1.0.0
* @apiName MenuStatus
* @apiGroup Menu
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} id ID
* @apiParam {Number} status 状态1启动2禁用
*
* @apiSuccess (200) {Number} code=200 成功响应状态码!
* @apiSuccess (200) {String} msg="ok" 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Menu) Status(c *gin.Context) {
form := &struct {
idForm
Status int `json:"status" form:"status" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := menu.NewInstance()(getSession()(c).(*service.Session)).Status(form.ID, form.Status)
APIResponse(err)(c)
}
/**
* @api {post} /api/menu/delete 删除菜单
* @apiVersion 1.0.0
* @apiName MenuDelete
* @apiGroup Menu
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} id ID
*
* @apiSuccess (200) {Number} code=200 成功响应状态码!
* @apiSuccess (200) {String} msg="ok" 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Menu) Delete(c *gin.Context) {
form := new(idForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := menu.NewInstance()(getSession()(c).(*service.Session)).Delete(form.ID)
APIResponse(err)(c)
}
/**
* @api {get} /api/menu/user 用户菜单列表
* @apiVersion 1.0.0
* @apiName MenuUser
* @apiGroup Menu
*
* @apiHeader {string} x-token token
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Array} data 具体信息
* @apiSuccess (200) {Number} data.id 菜单ID
* @apiSuccess (200) {Number} data.parent_id 父级ID
* @apiSuccess (200) {String} data.name 菜单名称
* @apiSuccess (200) {Number} data.kind 类型1目录2菜单
* @apiSuccess (200) {String} data.link 访问地址
* @apiSuccess (200) {String} data.component 组件
* @apiSuccess (200) {Array} data.children="[]" 子集
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": [
* "id": 1,
* "parent_id": 0,
* "name": "系统管理",
* "kind": 1,
* "link": "1"
* "component": ""
* "children": [
* {
* "id": 2,
* "parent_id": 1,
* "name": "用户管理",
* "kind": 1,
* "link": "1"
* "component": ""
* "children": [],
* }
* ]
* ]
* }
*/
func (a *Menu) User(c *gin.Context) {
data, err := menu.NewUser()(getSession()(c).(*service.Session)).List()
APIResponse(err, data)(c)
}
func (a *Menu) Tenant(c *gin.Context) {
form := &struct {
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := menu.NewTenant()(getSession()(c).(*service.Session)).List(form.TenantID)
APIResponse(err, data)(c)
}
/**
* @api {post} /api/tenant/bind 租户菜单绑定
* @apiVersion 1.0.0
* @apiName MenuTenantBind
* @apiGroup Menu
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} tenant_id 租户ID
* @apiParam {Array.Number} menu_ids 菜单ID
*
* @apiSuccess (200) {Number} code=200 成功响应状态码!
* @apiSuccess (200) {String} msg="ok" 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Menu) TenantBind(c *gin.Context) {
form := &struct {
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
MenuIDs []uint64 `json:"menu_ids" form:"menu_ids" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := menu.NewTenant()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.MenuIDs)
APIResponse(err)(c)
}
/**
* @api {post} /api/menu/role 角色菜单列表
* @apiVersion 1.0.0
* @apiName MenuRole
* @apiGroup Menu
*
* @apiHeader {string} x-token token
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Array} data 具体信息
* @apiSuccess (200) {Number} data.id 菜单ID
* @apiSuccess (200) {Number} data.parent_id 父级ID
* @apiSuccess (200) {String} data.name 菜单名称
* @apiSuccess (200) {Number} data.kind 类型1目录2菜单
* @apiSuccess (200) {String} data.link 访问地址
* @apiSuccess (200) {String} data.component 组件
* @apiSuccess (200) {Array} data.children="[]" 子集
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": [
* "id": 1,
* "parent_id": 0,
* "name": "系统管理",
* "kind": 1,
* "link": "1"
* "component": ""
* "children": [
* {
* "id": 2,
* "parent_id": 1,
* "name": "用户管理",
* "kind": 1,
* "link": "1"
* "component": ""
* "children": [],
* }
* ]
* ]
* }
*/
func (a *Menu) Role(c *gin.Context) {
form := &struct {
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := menu.NewRole()(getSession()(c).(*service.Session)).List(form.RoleID)
APIResponse(err, data)(c)
}
/**
* @api {post} /api/role/bind 角色菜单绑定
* @apiVersion 1.0.0
* @apiName MenuRoleBind
* @apiGroup Menu
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} role_id 角色ID
* @apiParam {Array.Number} menu_ids 菜单ID
*
* @apiSuccess (200) {Number} code=200 成功响应状态码!
* @apiSuccess (200) {String} msg="ok" 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Menu) RoleBind(c *gin.Context) {
form := &struct {
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
MenuIDs []uint64 `json:"menu_ids" form:"menu_ids" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := menu.NewRole()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.MenuIDs)
APIResponse(err)(c)
}

View File

@ -1,107 +0,0 @@
package api
import (
"ArmedPolice/app/controller/role"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
type Role struct{}
func (a *Role) List(c *gin.Context) {
form := &struct {
Name string `json:"name" form:"name"`
Status int `json:"status" form:"status"`
pageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := role.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Status, form.Page, form.PageSize)
APIResponse(err, data)(c)
}
func (a *Role) Select(c *gin.Context) {
data, err := role.NewInstance()(getSession()(c).(*service.Session)).Select()
APIResponse(err, data)(c)
}
func (a *Role) Add(c *gin.Context) {
form := &struct {
Name string `json:"name" form:"name" binding:"required"`
Remark string `json:"remark" form:"remark" binding:"required"`
Sort int `json:"sort" form:"sort"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := role.NewInstance()(getSession()(c).(*service.Session)).Data(0, form.Name, form.Remark, form.Sort)
APIResponse(err)(c)
}
func (a *Role) Edit(c *gin.Context) {
form := &struct {
idForm
Name string `json:"name" form:"name" binding:"required"`
Remark string `json:"remark" form:"remark" binding:"required"`
Sort int `json:"sort" form:"sort"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := role.NewInstance()(getSession()(c).(*service.Session)).Data(form.ID, form.Name, form.Remark, form.Sort)
APIResponse(err)(c)
}
func (a *Role) Status(c *gin.Context) {
form := &struct {
idForm
Status int `json:"status" form:"status" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := role.NewInstance()(getSession()(c).(*service.Session)).Status(form.ID, form.Status)
APIResponse(err)(c)
}
func (a *Role) Delete(c *gin.Context) {
form := new(idForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := role.NewInstance()(getSession()(c).(*service.Session)).Delete(form.ID)
APIResponse(err)(c)
}
func (a *Role) User(c *gin.Context) {
form := &struct {
uidForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := role.NewUser()(getSession()(c).(*service.Session)).List(form.Convert())
APIResponse(err, data)(c)
}
func (a *Role) UserBind(c *gin.Context) {
form := &struct {
uidForm
RoleIDs []uint64 `json:"role_ids" form:"role_ids" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := role.NewUser()(getSession()(c).(*service.Session)).Bind(form.Convert(), form.RoleIDs)
APIResponse(err)(c)
}

View File

@ -6,32 +6,43 @@ import (
"strings"
)
type idForm struct {
type IDForm struct {
ID uint64 `json:"id" form:"id" binding:"required"`
}
type uidForm struct {
type IDStringForm struct {
ID string `json:"id" form:"id"`
}
func (this *IDStringForm) Convert() uint64 {
if this.ID == "" {
return 0
}
return uint64(utils.HASHIDDecode(this.ID))
}
type UIDForm struct {
UID string `json:"uid" form:"uid" binding:"required"`
}
func (this *uidForm) Convert() uint64 {
func (this *UIDForm) Convert() uint64 {
return utils.StringToUnit64(this.UID)
}
type imageForm struct {
type ImageForm struct {
Image string `json:"image" form:"image"`
}
func (this *imageForm) FilterImageURL() string {
func (this *ImageForm) FilterImageURL() string {
return strings.Replace(this.Image, config.SettingInfo.Domain, "", -1)
}
type positionForm struct {
type PositionForm struct {
Longitude float64 `json:"longitude" form:"longitude" binding:"required"`
Latitude float64 `json:"latitude" form:"latitude" binding:"required"`
}
type pageForm struct {
type PageForm struct {
Page int `json:"current" form:"current" binding:"required"`
PageSize int `json:"pageSize" form:"pageSize" binding:"required"`
PageSize int `json:"page_size" form:"page_size" binding:"required"`
}

132
app/api/supplier.go Normal file
View File

@ -0,0 +1,132 @@
package api
import (
"ArmedPolice/app/common/model"
"ArmedPolice/app/controller/supplier"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
type Supplier struct{}
type (
// supplierForm 参数信息
supplierForm struct {
Name string `json:"name" form:"name" binding:"required"`
Mobile string `json:"mobile" form:"mobile" binding:"required"`
Address string `json:"address" form:"address"`
Remark string `json:"remark" form:"remark"`
}
)
func (*Supplier) Material(c *gin.Context) {
form := &struct {
Name string `json:"name" form:"name"`
Mobile string `json:"mobile" form:"mobile"`
PageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := supplier.NewInstance()(getSession()(c).(*service.Session)).
List(form.Name, form.Mobile, model.ManageSupplierKindForMaterial, form.Page, form.PageSize)
APIResponse(err, data)
}
func (*Supplier) MaterialAdd(c *gin.Context) {
form := new(supplierForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := supplier.NewInstance()(getSession()(c).(*service.Session)).Form(&supplier.InstanceParams{
Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
Kind: model.ManageSupplierKindForMaterial,
})
APIResponse(err)
}
func (*Supplier) MaterialEdit(c *gin.Context) {
form := &struct {
IDStringForm
supplierForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := supplier.NewInstance()(getSession()(c).(*service.Session)).Form(&supplier.InstanceParams{
ID: form.Convert(), Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
Kind: model.ManageSupplierKindForMaterial,
})
APIResponse(err)
}
func (*Supplier) MaterialDelete(c *gin.Context) {
form := new(IDStringForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := supplier.NewInstance()(getSession()(c).(*service.Session)).Delete(form.Convert())
APIResponse(err)
}
func (*Supplier) Repair(c *gin.Context) {
form := &struct {
Name string `json:"name" form:"name"`
Mobile string `json:"mobile" form:"mobile"`
PageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := supplier.NewInstance()(getSession()(c).(*service.Session)).
List(form.Name, form.Mobile, model.ManageSupplierKindForRepair, form.Page, form.PageSize)
APIResponse(err, data)
}
func (*Supplier) RepairAdd(c *gin.Context) {
form := new(supplierForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := supplier.NewInstance()(getSession()(c).(*service.Session)).Form(&supplier.InstanceParams{
Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
Kind: model.ManageSupplierKindForRepair,
})
APIResponse(err)
}
func (*Supplier) RepairEdit(c *gin.Context) {
form := &struct {
IDStringForm
supplierForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := supplier.NewInstance()(getSession()(c).(*service.Session)).Form(&supplier.InstanceParams{
ID: form.Convert(), Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
Kind: model.ManageSupplierKindForRepair,
})
APIResponse(err)
}
func (*Supplier) RepairDelete(c *gin.Context) {
form := new(IDStringForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := supplier.NewInstance()(getSession()(c).(*service.Session)).Delete(form.Convert())
APIResponse(err)
}

View File

@ -1,403 +0,0 @@
package api
import (
"ArmedPolice/app/controller/tenant"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
type Tenant struct{}
type (
// tenantForm 基本信息
tenantForm struct {
Name string `json:"name" form:"name" binding:"required"` // 名称
imageForm // 图片
Account string `json:"account" form:"account" binding:"required"` // 登录帐号
Password string `json:"password" form:"password" binding:"required"` // 登录密码
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"` // 重复登录密码
Deadline string `json:"deadline" form:"deadline" binding:"required"` // 协约终止时间
Remark string `json:"remark" form:"remark"` // 备注
}
// tenantSettingForm 配置信息
tenantSettingForm struct {
Protocol []uint `json:"protocol" form:"protocol" binding:"required"` // 消息协议
MaxDevices int `json:"max_devices" form:"max_devices" binding:"required"` // 允许最多的设备数
MaxCustomer int `json:"max_customer" form:"max_customer"` // 允许最多的客户数
}
)
/**
* @apiDefine Tenant 租户管理
*/
/**
* @api {post} /api/tenant/list 租户列表
* @apiVersion 1.0.0
* @apiName TenantList
* @apiGroup Tenant
*
* @apiHeader {string} x-token token
*
* @apiParam {String} [name='""'] 租户名称
* @apiParam {Number} [status=0] 租户状态
* @apiParam {Number} current 当前页
* @apiParam {Number} page_size 页展示数
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Array} data 具体信息
* @apiSuccess (200) {Number} data.id ID
* @apiSuccess (200) {String} data.key 标识key
* @apiSuccess (200) {String} data.name 公司名称
* @apiSuccess (200) {Time} data.deadline 协议到期时间
* @apiSuccess (200) {Number} data.device_count 设备数量
* @apiSuccess (200) {Json} data.config 配置信息
* @apiSuccess (200) {Number} data.config.max_devices 最大设备数
* @apiSuccess (200) {Number} data.config.max_customer 最大客户数
* @apiSuccess (200) {Number} data.config.protocol 支持协议(&
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": [
* {
* "id": 1,
* "key": "3xPdWH",
* "image": "",
* "name": "商挈智能",
* "deadline": "2021-12-31T23:59:59+08:00",
* "remark": "测试",
* "created_at": "2021-07-27T10:45:18+08:00",
* "updated_at": "2021-07-27T10:45:18+08:00",
* "device_count": 0,
* "config": {
* "max_devices": 1,
* "max_customer": 1,
* "protocol": 3
* }
* }
* ]
* }
*/
func (a *Tenant) List(c *gin.Context) {
form := &struct {
Name string `json:"name" form:"name"`
Status int `json:"status" form:"status"`
pageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := tenant.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Status, form.Page, form.PageSize)
APIResponse(err, data)(c)
}
/**
* @api {post} /api/tenant/add 租户添加
* @apiVersion 1.0.0
* @apiName TenantAdd
* @apiGroup Tenant
*
* @apiHeader {string} x-token token
*
* @apiParam {String} name 租户名称
* @apiParam {String} image 租户图片
* @apiParam {String} account 租户管理员登录帐号
* @apiParam {String} password 租户管理员登录密码
* @apiParam {String} repeat_pwd 重复密码
* @apiParam {Number} max_devices 最大设备数
* @apiParam {Number} [max_customer=0] 租户可拥有的最大客户数
* @apiParam {Array.Number} protocol 消息协议
* @apiParam {Time} deadline 协议有效期2021-12-31
* @apiParam {String} [remark="''"] 备注信息
* @apiParam {Number} current 当前页
* @apiParam {Number} page_size 页展示数
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Tenant) Add(c *gin.Context) {
form := new(tenantForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := tenant.NewInstance()(getSession()(c).(*service.Session)).Add(&tenant.InstanceParams{Name: form.Name,
Image: form.FilterImageURL(), Account: form.Account, Password: form.Password, RepeatPwd: form.RepeatPwd,
Deadline: form.Deadline, Remark: form.Remark,
})
APIResponse(err)(c)
}
/**
* @api {post} /api/tenant/edit 租户修改
* @apiVersion 1.0.0
* @apiName TenantEdit
* @apiGroup Tenant
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} id ID
* @apiParam {String} name 租户名称
* @apiParam {String} image 租户图片
* @apiParam {String} [remark="''"] 备注信息
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Tenant) Edit(c *gin.Context) {
form := &struct {
idForm
Name string `json:"name" form:"name" binding:"required"`
imageForm
Remark string `json:"remark" form:"remark"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := tenant.NewInstance()(getSession()(c).(*service.Session)).Edit(&tenant.InstanceParams{ID: form.ID, Name: form.Name,
Image: form.FilterImageURL(), Remark: form.Remark,
})
APIResponse(err)(c)
}
/**
* @api {post} /api/tenant/edit/password 租户修改密码
* @apiVersion 1.0.0
* @apiName TenantEditPassword
* @apiGroup Tenant
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} id ID
* @apiParam {String} name 租户名称
* @apiParam {String} image 租户图片
* @apiParam {String} [remark="''"] 备注信息
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Tenant) EditPassword(c *gin.Context) {
form := &struct {
idForm
Password string `json:"password" form:"password" binding:"required"` // 登录密码
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"` // 重复登录密码
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := tenant.NewInstance()(getSession()(c).(*service.Session)).Edit(&tenant.InstanceParams{ID: form.ID, Password: form.Password,
RepeatPwd: form.RepeatPwd,
})
APIResponse(err)(c)
}
/**
* @api {post} /api/tenant/detail 租户详细信息
* @apiVersion 1.0.0
* @apiName TenantDetail
* @apiGroup Tenant
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} id ID
* @apiParam {Number} type 详细信息1基本信息2资产设备信息3成员信息4权限信息
* @apiParam {Number} [current=0] 当前页
* @apiParam {Number} [page_size=0] 页展示数
* @apiParam {String} [name="''"] 成员名称
* @apiParam {Number} [status=0] 成员状态
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": Any
* }
*/
func (a *Tenant) Detail(c *gin.Context) {
form := &struct {
idForm
Type tenant.InstanceDetailType `json:"type" form:"type" binding:"required"`
Page int `json:"current" form:"current"`
PageSize int `json:"pageSize" form:"pageSize"`
Name string `json:"name" form:"name"`
Status int `json:"status" form:"status"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := tenant.NewInstance()(getSession()(c).(*service.Session)).Detail(form.ID, form.Type, form.Page,
form.PageSize, form.Name, form.Status)
APIResponse(err, data)(c)
}
/**
* @api {post} /api/tenant/renewal 租户续期
* @apiVersion 1.0.0
* @apiName TenantRenewal
* @apiGroup Tenant
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} id ID
* @apiParam {Time} deadline 协议有效期2021-12-31
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Tenant) Renewal(c *gin.Context) {
form := &struct {
idForm
Deadline string `json:"deadline" form:"deadline" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := tenant.NewInstance()(getSession()(c).(*service.Session)).Renewal(form.ID, form.Deadline)
APIResponse(err)(c)
}
/**
* @api {post} /api/tenant/start_up 租户启用
* @apiVersion 1.0.0
* @apiName TenantStartUp
* @apiGroup Tenant
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} id ID
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Tenant) StartUp(c *gin.Context) {
form := new(idForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := tenant.NewInstance()(getSession()(c).(*service.Session)).StartUp(form.ID)
APIResponse(err)(c)
}
/**
* @api {post} /api/tenant/disable 租户禁用
* @apiVersion 1.0.0
* @apiName TenantDisable
* @apiGroup Tenant
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} id ID
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Tenant) Disable(c *gin.Context) {
form := new(idForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := tenant.NewInstance()(getSession()(c).(*service.Session)).Disable(form.ID)
APIResponse(err)(c)
}
/**
* @api {post} /api/tenant/member/bind 租户用户绑定状态
* @apiVersion 1.0.0
* @apiName TenantMemberBind
* @apiGroup Tenant
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} id ID
* @apiParam {Number} status 状态1启用2禁用
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (a *Tenant) MemberBind(c *gin.Context) {
form := &struct {
uidForm
Status int `json:"status" form:"status" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := tenant.NewInstance()(getSession()(c).(*service.Session)).MemberBind(form.Convert(), form.Status)
APIResponse(err)(c)
}

View File

@ -1,115 +1 @@
package api
import (
"ArmedPolice/app/controller/user"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
type User struct{}
type userForm struct {
Account string `json:"account" form:"account" binding:"required"`
Name string `json:"name" form:"name" binding:"required"`
Mobile string `json:"mobile" form:"mobile" binding:"required"`
Gender int `json:"gender" form:"gender" binding:"required"`
Departments []uint64 `json:"departments" form:"departments"`
Roles []uint64 `json:"roles" form:"roles"`
Remark string `json:"remark" form:"remark"`
}
/**
* @apiDefine User 用户管理
*/
func (a *User) Info(c *gin.Context) {
data, err := user.NewInstance()(getSession()(c).(*service.Session)).Info()
APIResponse(err, data)(c)
}
func (a *User) List(c *gin.Context) {
form := &struct {
Name string `json:"name" form:"name"`
Mobile string `json:"mobile" form:"mobile"`
Status int `json:"status" form:"status"`
pageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := user.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Mobile, form.Status, form.Page, form.PageSize)
APIResponse(err, data)(c)
}
func (a *User) Add(c *gin.Context) {
form := &struct {
userForm
Password string `json:"password" form:"password" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := user.NewInstance()(getSession()(c).(*service.Session)).Add(&user.InstanceForm{
Account: form.Account, Name: form.Name, Mobile: form.Mobile, Password: form.Password,
Remark: form.Remark, Gender: form.Gender, Departments: form.Departments, Roles: form.Roles,
})
APIResponse(err)(c)
}
func (a *User) Edit(c *gin.Context) {
form := &struct {
idForm
userForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := user.NewInstance()(getSession()(c).(*service.Session)).Edit(&user.InstanceForm{
ID: form.ID, Account: form.Account, Name: form.Name, Mobile: form.Mobile,
Remark: form.Remark, Gender: form.Gender, Departments: form.Departments, Roles: form.Roles,
})
APIResponse(err)(c)
}
func (a *User) Password(c *gin.Context) {
form := &struct {
idForm
Password string `json:"password" form:"password" binding:"required"`
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := user.NewInstance()(getSession()(c).(*service.Session)).Password(form.ID, form.Password, form.RepeatPwd)
APIResponse(err)(c)
}
func (a *User) EditPassword(c *gin.Context) {
form := &struct {
OldPwd string `json:"old_pwd" form:"old_pwd" binding:"required"`
Password string `json:"password" form:"password" binding:"required"`
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := user.NewPerson()(getSession()(c).(*service.Session)).EditPassword(form.OldPwd, form.Password, form.RepeatPwd)
APIResponse(err)(c)
}
func (a *User) Delete(c *gin.Context) {
form := new(idForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := user.NewInstance()(getSession()(c).(*service.Session)).Delete(form.ID)
APIResponse(err)(c)
}