412 lines
13 KiB
Go
412 lines
13 KiB
Go
package api
|
||
|
||
import (
|
||
"ArmedPolice/app/controller/work"
|
||
"ArmedPolice/app/service"
|
||
"github.com/gin-gonic/gin"
|
||
)
|
||
|
||
/**
|
||
* @apiDefine Work 工单管理
|
||
*/
|
||
|
||
type Work struct{}
|
||
|
||
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"` // 联系地址
|
||
}
|
||
// scheduleForm 流程信息
|
||
scheduleForm struct {
|
||
Title string `json:"title" form:"title" binding:"required"`
|
||
Stage int `json:"stage" form:"stage"`
|
||
Step int `json:"step" form:"step"`
|
||
Target int `json:"target" form:"target" binding:"required"`
|
||
TargetValue []string `json:"target_value" form:"target_value" binding:"required"`
|
||
IsCountersign int `json:"is_countersign" form:"is_countersign"`
|
||
}
|
||
)
|
||
|
||
/**
|
||
* @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) {Object} 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) {String} data.schedule_title 流程名称
|
||
* @apiSuccess (200) {Number} data.priority 紧急状态(1:普通,2:紧急,3:非常紧急)
|
||
* @apiSuccess (200) {Number} data.status 状态(0:进行中,1:已完成)
|
||
* @apiSuccess (200) {Time} data.created_at 创建时间
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": [
|
||
* {
|
||
* "id": "m9Qa2ZaOvE",
|
||
* "title": "刹车盘",
|
||
* "material_code": "装备编码",
|
||
* "material_title": "装备名称",
|
||
* "breakdown_title": "发动机,刹车盘",
|
||
* "schedule_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)
|
||
}
|
||
|
||
/**
|
||
* @api {post} /api/v1/work/person 个人申请信息
|
||
* @apiVersion 1.0.0
|
||
* @apiName WorkPerson
|
||
* @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) {Object} 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) {String} data.schedule_title 流程名称
|
||
* @apiSuccess (200) {Number} data.priority 紧急状态(1:普通,2:紧急,3:非常紧急)
|
||
* @apiSuccess (200) {Number} data.status 状态(0:进行中,1:已完成)
|
||
* @apiSuccess (200) {Time} data.created_at 创建时间
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": [
|
||
* {
|
||
* "id": "m9Qa2ZaOvE",
|
||
* "title": "刹车盘",
|
||
* "material_code": "装备编码",
|
||
* "material_title": "装备名称",
|
||
* "breakdown_title": "发动机,刹车盘",
|
||
* "schedule_title": "分管领导审批",
|
||
* "priority": 1,
|
||
* "status": 0,
|
||
* "created_at": "2021-11-05T14:24:07+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)
|
||
}
|
||
|
||
/**
|
||
* @api {post} /api/v1/work/workbench 个人待办事项
|
||
* @apiVersion 1.0.0
|
||
* @apiName WorkWorkbench
|
||
* @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) {Object} 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) {String} data.schedule_title 流程名称
|
||
* @apiSuccess (200) {Number} data.priority 紧急状态(1:普通,2:紧急,3:非常紧急)
|
||
* @apiSuccess (200) {Number} data.status 状态(0:进行中,1:已完成)
|
||
* @apiSuccess (200) {Time} data.created_at 创建时间
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": [
|
||
* {
|
||
* "id": "m9Qa2ZaOvE",
|
||
* "title": "刹车盘",
|
||
* "material_code": "装备编码",
|
||
* "material_title": "装备名称",
|
||
* "breakdown_title": "发动机,刹车盘",
|
||
* "schedule_title": "分管领导审批",
|
||
* "priority": 1,
|
||
* "status": 0,
|
||
* "created_at": "2021-11-05T14:24:07+08:00",
|
||
* }
|
||
* ]
|
||
* }
|
||
*/
|
||
func (*Work) Workbench(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)).Workbench(form.MaterialID, form.Kind, form.Page, form.PageSize)
|
||
APIResponse(err, data)(c)
|
||
}
|
||
|
||
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)
|
||
}
|
||
|
||
func (*Work) Launch(c *gin.Context) {
|
||
form := &struct {
|
||
workLaunchForm
|
||
Material []*workLaunchMaterialForm `json:"material" form:"material"`
|
||
Address workLaunchDistributionForm `json:"distribution" form:"distribution"`
|
||
}{}
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
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,
|
||
})
|
||
APIResponse(err)
|
||
}
|
||
|
||
func (*Work) Examine(c *gin.Context) {
|
||
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
|
||
}
|
||
err := work.NewInstance()(getSession()(c).(*service.Session)).Examine(form.Convert(), form.Status, form.Remark, form.IsAssist)
|
||
APIResponse(err)
|
||
}
|
||
|
||
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)
|
||
}
|
||
|
||
/**
|
||
* @api {get} /api/v1/work/schedule 工单流程信息
|
||
* @apiVersion 1.0.0
|
||
* @apiName WorkSchedule
|
||
* @apiGroup Work
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiSuccess (200) {Object} data 数据信息
|
||
* @apiSuccess (200) {Number} data.kind 流程类型(1;维修工单)
|
||
* @apiSuccess (200) {String} data.title 流程名称
|
||
* @apiSuccess (200) {Object} data.schedules 流程信息
|
||
* @apiSuccess (200) {String} data.schedules.id 流程详细ID
|
||
* @apiSuccess (200) {String} data.schedules.title 流程详细名称
|
||
* @apiSuccess (200) {Number} data.schedules.stage 阶段
|
||
* @apiSuccess (200) {Number} data.schedules.step 步骤
|
||
* @apiSuccess (200) {Number} data.schedules.target 触发对象(1:个人,2:角色)
|
||
* @apiSuccess (200) {String} data.schedules.target_value 触发对象信息
|
||
* @apiSuccess (200) {String} data.schedules.target_value_title 触发对象具体信息
|
||
* @apiSuccess (200) {Number} data.schedules.is_countersign 是否会签(0:否,1:是)暂不需要此字段
|
||
* @apiSuccess (200) {Time} data.schedules.created_at 创建时间
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": [
|
||
* {
|
||
* "kind": "m9Qa2ZaOvE",
|
||
* "title": "刹车盘",
|
||
* "schedules": [
|
||
* {
|
||
* "id": "A9GVg5JZdr",
|
||
* "title": "发起工单",
|
||
* "stage": 1,
|
||
* "step": 2,
|
||
* "target": 2,
|
||
* "target_value": "9",
|
||
* "target_value_title": "区域修理队",
|
||
* "is_countersign": 0,
|
||
* "created_at": "2021-11-05T14:24:07+08:00",
|
||
* ]
|
||
* }
|
||
* }
|
||
* ]
|
||
* }
|
||
*/
|
||
func (*Work) Schedule(c *gin.Context) {
|
||
data, err := work.NewSchedule()(getSession()(c).(*service.Session)).List()
|
||
APIResponse(err, data)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {get} /api/v1/work/schedule/edit 工单流程信息修改
|
||
* @apiVersion 1.0.0
|
||
* @apiName WorkSchedulEdit
|
||
* @apiGroup Work
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiParam {String} id Id
|
||
* @apiParam {String} title 名称
|
||
* @apiParam {Number} target 触发对象
|
||
* @apiParam {Array.String} target_value 触发对象具体信息
|
||
*
|
||
* @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 (*Work) ScheduleEdit(c *gin.Context) {
|
||
form := &struct {
|
||
IDStringForm
|
||
scheduleForm
|
||
}{}
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
err := work.NewSchedule()(getSession()(c).(*service.Session)).Form(&work.ScheduleParams{
|
||
ID: form.Convert(), Title: form.Title, Stage: form.Stage, Step: form.Step,
|
||
Target: form.Target, IsCountersign: form.IsCountersign, TargetValue: form.TargetValue,
|
||
})
|
||
APIResponse(err)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {get} /api/v1/work/schedule/delete 工单流程信息删除
|
||
* @apiVersion 1.0.0
|
||
* @apiName WorkSchedulDelete
|
||
* @apiGroup Work
|
||
*
|
||
* @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 (*Work) ScheduleDelete(c *gin.Context) {
|
||
form := new(IDStringForm)
|
||
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
err := work.NewSchedule()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
||
APIResponse(err)(c)
|
||
}
|