feat:完善项目

This commit is contained in:
henry
2021-11-15 17:32:23 +08:00
parent f5e2063685
commit 78128277ff
27 changed files with 717 additions and 105 deletions

View File

@ -3,6 +3,7 @@ package api
import (
"ArmedPolice/app/controller/account"
"ArmedPolice/app/service"
"ArmedPolice/config"
"github.com/gin-gonic/gin"
)
@ -82,13 +83,11 @@ func (a *Account) Login(c *gin.Context) {
* }
*/
func (a *Account) Logout(c *gin.Context) {
handle := getSession()(c)
// 因跳过中间键故只能自己去获取token用户信息
token := c.GetHeader(config.APIRequestToken)
session := new(service.Session)
session, _ := service.NewAuthToken(token).Auth()
if handle != nil {
session = handle.(*service.Session)
}
err := account.NewInstance()(session).Logout()
APIResponse(err)(c)
}

View File

@ -89,13 +89,13 @@ func (*Config) Area(c *gin.Context) {
* @apiParam {Number} current 当前页
* @apiParam {Number} page_size 页展示数
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Array} data 数据信息
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {String} data.id ID
* @apiSuccess (200) {String} data.title 标题名称
* @apiSuccess (200) {String} data.remark 备注信息
* @apiSuccess (200) {Time} data.created_at 创建时间
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
@ -125,6 +125,30 @@ func (*Config) Breakdown(c *gin.Context) {
APIResponse(err, data)(c)
}
/**
* @api {post} /api/v1/config/breakdown/add 故障信息添加
* @apiVersion 1.0.0
* @apiName ConfigBreakdownAdd
* @apiGroup Config
*
* @apiHeader {string} x-token token
* @apiHeader {string} Content-Type=application/json 传输方式
*
* @apiParam {String} title 名称
* @apiParam {String} [remark="''"] 备注名称
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Object} data 数据信息
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*Config) BreakdownAdd(c *gin.Context) {
form := &struct {
Title string `json:"title" form:"title" binding:"required"`
@ -138,6 +162,31 @@ func (*Config) BreakdownAdd(c *gin.Context) {
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/config/breakdown/edit 故障信息修改
* @apiVersion 1.0.0
* @apiName ConfigBreakdownEdit
* @apiGroup Config
*
* @apiHeader {string} x-token token
* @apiHeader {string} Content-Type=application/json 传输方式
*
* @apiParam {String} id ID
* @apiParam {String} title 名称
* @apiParam {String} [remark="''"] 备注名称
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Object} data 数据信息
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*Config) BreakdownEdit(c *gin.Context) {
form := &struct {
IDStringForm
@ -152,6 +201,29 @@ func (*Config) BreakdownEdit(c *gin.Context) {
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/config/breakdown/delete 故障信息删除
* @apiVersion 1.0.0
* @apiName ConfigBreakdownDelete
* @apiGroup Config
*
* @apiHeader {string} x-token token
* @apiHeader {string} Content-Type=application/json 传输方式
*
* @apiParam {String} id ID
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Object} data 数据信息
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": null
* }
*/
func (*Config) BreakdownDelete(c *gin.Context) {
form := new(IDStringForm)

110
app/api/dashboard.go Normal file
View File

@ -0,0 +1,110 @@
package api
import (
"ArmedPolice/app/controller/dashboard"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
/**
* @apiDefine Dashboard 仪表盘
*/
type Dashboard struct{}
/**
* @api {get} /api/v1/dashboard 工作台
* @apiVersion 1.0.0
* @apiName DashboardIndex
* @apiGroup Dashboard
*
* @apiHeader {string} x-token token
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Object} data.workbench 待办事项
* @apiSuccess (200) {String} data.workbench.id ID
* @apiSuccess (200) {String} data.workbench.equipment_code 设备标识
* @apiSuccess (200) {String} data.workbench.equipment_title 设备名称
* @apiSuccess (200) {String} data.workbench.breakdown_title 故障信息
* @apiSuccess (200) {String} data.workbench.username 用户名
* @apiSuccess (200) {Time} data.workbench.created_at 创建时间
* @apiSuccess (200) {Object} data.notice 公告信息
* @apiSuccess (200) {String} data.notice.id ID
* @apiSuccess (200) {String} data.notice.title 公告标题
* @apiSuccess (200) {Time} data.notice.created_at 公告创建时间
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": {
* "workbench": [
* "id": "",
* "equipment_code": "",
* "equipment_title": ""
* "breakdown_title": ""
* "username": ""
* "created_at": ""
* ]
* "notice": [
* "id": "",
* "title": "",
* "created_at": "2021-11-01"
* ]
* }
* }
*/
func (*Dashboard) Index(c *gin.Context) {
data, err := dashboard.NewInstance()(getSession()(c).(*service.Session)).Index()
APIResponse(err, data)(c)
}
/**
* @api {post} /api/v1/dashboard/repair 工单维修信息
* @apiVersion 1.0.0
* @apiName DashboardRepair
* @apiGroup Dashboard
*
* @apiHeader {string} x-token token
*
* @apiParam {String} date 具体月份 - 2021-10-01
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Number} data.count 数量
* @apiSuccess (200) {Number} data.amount 金额
* @apiSuccess (200) {String} data.date 时间
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": [
* {
* "count": 0,
* "amount": 0,
* "date": "2021-11-01"
* }...
* ]
* }
*/
func (*Dashboard) Repair(c *gin.Context) {
form := &struct {
Date string `json:"date" form:"date" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := dashboard.NewRepair()(getSession()(c).(*service.Session)).Static(form.Date)
APIResponse(err, data)(c)
}
func (*Dashboard) Score(c *gin.Context) {
}

View File

@ -11,8 +11,9 @@ type Manage struct{}
type (
// manageEquipmentForm 装备参数信息
manageEquipmentForm struct {
Code string `json:"code" form:"code" binding:"required"`
Title string `json:"title" form:"title" binding:"required"`
ParentID string `json:"parent_id" form:"parent_id"`
Code string `json:"code" form:"code" binding:"required"`
Title string `json:"title" form:"title" binding:"required"`
ImageForm
Config string `json:"config" form:"config"`
Remark string `json:"remark" form:"remark"`
@ -23,8 +24,12 @@ type (
Code string `json:"code" form:"code" binding:"required"`
Title string `json:"title" form:"title" binding:"required"`
ImageForm
Remark string `json:"remark" form:"remark"`
Unit int `json:"unit" form:"Unit" binding:"required"`
Price float64 `json:"price" form:"price" binding:"required"`
Remark string `json:"remark" form:"remark"`
Unit int `json:"unit" form:"unit" binding:"required"`
MaterialID string `json:"material_id" form:"material_id"`
SupplierID string `json:"supplier_id" form:"supplier_id"`
Stock float64 `json:"stock" form:"stock"`
}
// manageNoticeForm 公告参数信息
manageNoticeForm struct {
@ -33,11 +38,26 @@ type (
}
)
func (this *manageEquipmentForm) ParentInfo() uint64 {
obj := &IDStringForm{ID: this.ParentID}
return obj.Convert()
}
func (this *manageMaterialForm) ManufacturerInfo() uint64 {
obj := &IDStringForm{ID: this.ManufacturerID}
return obj.Convert()
}
func (this *manageMaterialForm) MaterialInfo() uint64 {
obj := &IDStringForm{ID: this.MaterialID}
return obj.Convert()
}
func (this *manageMaterialForm) SupplierInfo() uint64 {
obj := &IDStringForm{ID: this.SupplierID}
return obj.Convert()
}
/**
* @apiDefine Manage 数据管理
*/
@ -207,6 +227,7 @@ func (*Manage) EquipmentDetail(c *gin.Context) {
*
* @apiHeader {string} x-token token
*
* @apiParam {String} parent_id 装备父集ID
* @apiParam {String} code 器材编码
* @apiParam {String} title 器材名称
* @apiParam {String} image 器材图片
@ -232,8 +253,8 @@ func (*Manage) EquipmentAdd(c *gin.Context) {
return
}
err := manage.NewEquipment()(getSession()(c).(*service.Session)).Form(&manage.EquipmentParams{
Code: form.Code, Title: form.Title, Image: form.FilterImageURL(), Config: form.Config,
Remark: form.Remark,
ParentID: form.ParentInfo(), Code: form.Code, Title: form.Title, Image: form.FilterImageURL(),
Config: form.Config, Remark: form.Remark,
})
APIResponse(err)(c)
}
@ -247,6 +268,7 @@ func (*Manage) EquipmentAdd(c *gin.Context) {
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
* @apiParam {String} parent_id 装备父集ID
* @apiParam {String} code 器材编码
* @apiParam {String} title 器材名称
* @apiParam {String} image 器材图片
@ -274,7 +296,7 @@ func (*Manage) EquipmentEdit(c *gin.Context) {
return
}
err := manage.NewEquipment()(getSession()(c).(*service.Session)).Form(&manage.EquipmentParams{
ID: form.Convert(), Code: form.Code, Title: form.Title, Image: form.FilterImageURL(), Config: form.Config,
ID: form.Convert(), ParentID: form.ParentInfo(), Code: form.Code, Title: form.Title, Image: form.FilterImageURL(), Config: form.Config,
Remark: form.Remark,
})
APIResponse(err)(c)
@ -432,10 +454,14 @@ func (*Manage) MaterialSelect(c *gin.Context) {
*
* @apiParam {String} manufacturer_id 制造商ID
* @apiParam {String} code 器材编码
* @apiParam {float} price 价格
* @apiParam {String} title 器材名称
* @apiParam {String} image 器材图片
* @apiParam {Number} unit 单位
* @apiParam {String} remark 备注
* @apiParam {String} material_id 器材ID
* @apiParam {String} supplier_id 供应商ID
* @apiParam {String} [stock=0] 库存
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Number} code 成功响应状态码!
@ -458,7 +484,8 @@ func (*Manage) MaterialAdd(c *gin.Context) {
}
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Form(&manage.MaterialParams{
ManufacturerID: form.ManufacturerInfo(), Code: form.Code, Title: form.Title, Image: form.FilterImageURL(),
Remark: form.Remark, Unit: form.Unit,
Price: form.Price, Remark: form.Remark, Unit: form.Unit, MaterialID: form.MaterialInfo(),
SupplierID: form.SupplierInfo(), Stock: form.Stock,
})
APIResponse(err)(c)
}
@ -474,6 +501,7 @@ func (*Manage) MaterialAdd(c *gin.Context) {
* @apiParam {String} id ID
* @apiParam {String} manufacturer_id 制造商ID
* @apiParam {String} code 器材编码
* @apiParam {float} price 价格
* @apiParam {String} title 器材名称
* @apiParam {String} image 器材图片
* @apiParam {Number} unit 单位
@ -502,7 +530,7 @@ func (*Manage) MaterialEdit(c *gin.Context) {
}
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Form(&manage.MaterialParams{
ID: form.Convert(), ManufacturerID: form.ManufacturerInfo(), Code: form.Code, Title: form.Title,
Image: form.FilterImageURL(), Remark: form.Remark, Unit: form.Unit,
Price: form.Price, Image: form.FilterImageURL(), Remark: form.Remark, Unit: form.Unit,
})
APIResponse(err)(c)
}