Files
ArmedPolice/app/api/work.go

173 lines
5.4 KiB
Go
Raw Normal View History

2021-11-04 17:48:12 +08:00
package api
2021-11-05 15:27:04 +08:00
import (
"ArmedPolice/app/controller/work"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
2021-11-04 17:48:12 +08:00
/**
* @apiDefine Work 工单管理
*/
2021-11-05 15:27:04 +08:00
type Work struct{}
2021-11-08 17:42:23 +08:00
type (
// workLaunchForm 工单发起基本信息
workLaunchForm struct {
Kind int `json:"kind" form:"kind" binding:"required"` // 类型
Title string `json:"title" form:"title"`
EquipmentID uint64 `json:"equipment_id" form:"equipment_id" binding:"required"` // 装备ID
Breakdowns []uint64 `json:"breakdowns" form:"breakdowns"` // 故障类型
PlateNumber string `json:"plate_number" form:"plate_number"` // 车牌号
Priority int `json:"priority" form:"priority" binding:"required"` // 优先级
IsAssist int `json:"is_assist" form:"is_assist"` // 是否需要上级审批
Remark string `json:"remark" form:"remark"` // 备注信息
}
// workLaunchMaterialForm 工单发起配件信息
workLaunchMaterialForm struct {
}
// workLaunchDistributionForm 工单发起地址信息
workLaunchDistributionForm struct {
Name string `json:"name" form:"name" binding:"required"` // 联系人
Mobile string `json:"mobile" form:"mobile" binding:"required"` // 联系方式
Address string `json:"address" form:"address" binding:"required"` // 联系地址
}
)
2021-11-08 15:52:46 +08:00
2021-11-05 15:27:04 +08:00
/**
* @api {post} /api/v1/work/list 工单信息
* @apiVersion 1.0.0
* @apiName WorkList
* @apiGroup Work
*
* @apiHeader {string} x-token token
* @apiHeader {string} Content-Type=application/json 传输方式
*
* @apiParam {String} [material_id=0] 装备ID
* @apiParam {String} [kind=0] 工单类型
* @apiParam {Number} current 当前页
* @apiParam {Number} page_size 页展示数
*
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
* @apiSuccess (200) {Array} data 数据信息
* @apiSuccess (200) {String} data.id ID
* @apiSuccess (200) {String} data.title 标题名称
* @apiSuccess (200) {String} data.material_code 装备编码
* @apiSuccess (200) {String} data.material_title 装备名称
* @apiSuccess (200) {String} data.breakdown_title 故障信息
* @apiSuccess (200) {Number} data.priority 紧急状态1普通2紧急3非常紧急
* @apiSuccess (200) {Number} data.status 状态0进行中1已完成
* @apiSuccess (200) {Time} data.created_at 创建时间
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": [
* {
* "id": "m9Qa2ZaOvE",
* "title": "刹车盘",
* "material_code": "装备编码",
* "material_title": "装备名称",
* "breakdown_title": "发动机,刹车盘",
* "priority": 1,
* "status": 0,
* "created_at": "2021-11-05T14:24:07+08:00",
* }
* ]
* }
*/
func (*Work) Instance(c *gin.Context) {
form := &struct {
MaterialID uint64 `json:"material_id" form:"material_id"`
Kind int `json:"kind" form:"kind"`
PageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := work.NewInstance()(getSession()(c).(*service.Session)).List(form.MaterialID, form.Kind, form.Page, form.PageSize)
APIResponse(err, data)(c)
}
2021-11-09 14:08:02 +08:00
func (*Work) Person(c *gin.Context) {
form := &struct {
MaterialID uint64 `json:"material_id" form:"material_id"`
Kind int `json:"kind" form:"kind"`
PageForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := work.NewInstance()(getSession()(c).(*service.Session)).Person(form.MaterialID, form.Kind, form.Page, form.PageSize)
APIResponse(err, data)(c)
}
2021-11-05 18:07:32 +08:00
func (*Work) ToDo(c *gin.Context) {
}
2021-11-09 14:08:02 +08:00
func (*Work) Detail(c *gin.Context) {
form := new(IDStringForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := work.NewInstance()(getSession()(c).(*service.Session)).Detail(form.Convert())
APIResponse(err, data)(c)
}
2021-11-05 15:27:04 +08:00
func (*Work) Launch(c *gin.Context) {
2021-11-08 15:52:46 +08:00
form := &struct {
2021-11-08 17:42:23 +08:00
workLaunchForm
Material []*workLaunchMaterialForm `json:"material" form:"material"`
Address workLaunchDistributionForm `json:"distribution" form:"distribution"`
2021-11-08 15:52:46 +08:00
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
2021-11-08 17:42:23 +08:00
err := work.NewInstance()(getSession()(c).(*service.Session)).Launch(&work.InstanceLaunchParams{
Kind: form.Kind, Title: form.Title, EquipmentID: form.EquipmentID, Breakdowns: form.Breakdowns,
PlateNumber: form.PlateNumber, Priority: form.Priority, IsAssist: form.IsAssist, Remark: form.Remark,
})
2021-11-08 15:52:46 +08:00
APIResponse(err)
2021-11-05 15:27:04 +08:00
}
func (*Work) Examine(c *gin.Context) {
2021-11-05 18:07:32 +08:00
form := &struct {
IDStringForm
Status int `json:"status" form:"status" binding:"required"`
Remark string `json:"remark" form:"remark"`
IsAssist int `json:"is_assist" form:"is_assist"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
2021-11-08 17:42:23 +08:00
err := work.NewInstance()(getSession()(c).(*service.Session)).Examine(form.Convert(), form.Status, form.Remark, form.IsAssist)
2021-11-05 18:07:32 +08:00
APIResponse(err)
2021-11-05 15:27:04 +08:00
}
2021-11-09 14:08:02 +08:00
func (*Work) Delete(c *gin.Context) {
form := new(IDStringForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := work.NewInstance()(getSession()(c).(*service.Session)).Delete(form.Convert())
APIResponse(err)(c)
}
func (*Work) Schedule(c *gin.Context) {
data, err := work.NewSchedule()(getSession()(c).(*service.Session)).List()
APIResponse(err, data)(c)
}