Files
ArmedPolice/app/api/supplier.go
2021-11-10 15:09:31 +08:00

618 lines
17 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package api
import (
"ArmedPolice/app/common/model"
"ArmedPolice/app/controller/manage"
"ArmedPolice/app/service"
"github.com/gin-gonic/gin"
)
/**
* @apiDefine Supplier 供应商管理
*/
type Supplier struct{}
type (
// supplierForm 参数信息
supplierForm struct {
Name string `json:"name" form:"name" binding:"required"`
Contacts string `json:"contacts" form:"contacts" binding:"required"`
Mobile string `json:"mobile" form:"mobile" binding:"required"`
Address string `json:"address" form:"address"`
Remark string `json:"remark" form:"remark"`
}
)
/**
* @api {post} /api/v1/supplier/select 供应商Select
* @apiVersion 1.0.0
* @apiName SupplierSelect
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {Number} kind 类型101制造商102材料合作商103维修合作商
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {String} data.id ID
* @apiSuccess (200) {String} data.name 名称
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": [
* {
* "id": "EgmJ4Ga7LQ",
* "name": "测试的",
* }
* ]
* }
*/
func (*Supplier) Select(c *gin.Context) {
form := &struct {
Kind int `json:"kind" form:"kind" binding:"required"`
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
data, err := manage.NewSupplier()(getSession()(c).(*service.Session)).Select(form.Kind)
APIResponse(err, data)(c)
}
/**
* @api {post} /api/v1/supplier/material 器材信息
* @apiVersion 1.0.0
* @apiName SupplierMaterial
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} [name="''"] 名称
* @apiParam {String} [mobile="''"] 联系方式
* @apiParam {Number} current 当前页
* @apiParam {Number} page_size 页展示数
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Object} data.data 具体信息
* @apiSuccess (200) {String} data.data.id ID
* @apiSuccess (200) {String} data.data.kind 类型101制造商102材料合作商103维修合作商
* @apiSuccess (200) {String} data.data.name 名称
* @apiSuccess (200) {String} data.data.mobile 联系方式
* @apiSuccess (200) {String} data.data.contacts 联系人
* @apiSuccess (200) {String} data.data.address 联系地址
* @apiSuccess (200) {String} data.data.remark 备注信息
* @apiSuccess (200) {Time} data.data.created_at 创建时间
* @apiSuccess (200) {Time} data.data.updated_at 更新时间
* @apiSuccess (200) {Number} data.count 总数
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": {
* "data": [
* {
* "id": "EgmJ4Ga7LQ",
* "kind": 102,
* "name": "测试的",
* "mobile": "",
* "contacts": "",
* "address": "",
* "remark": "",
* "created_at": "2021-11-09T13:39:19+08:00",
* "updated_at": "2021-11-09T13:52:39+08:00"
* }
* ],
* "count": 1
* }
* }
*/
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 := manage.NewSupplier()(getSession()(c).(*service.Session)).
List(form.Name, form.Mobile, model.ManageSupplierKindForMaterial, form.Page, form.PageSize)
APIResponse(err, data)(c)
}
/**
* @api {post} /api/v1/supplier/material/add 器材信息添加
* @apiVersion 1.0.0
* @apiName SupplierMaterialAdd
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @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 (*Supplier) MaterialAdd(c *gin.Context) {
form := new(supplierForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
Name: form.Name, Mobile: form.Mobile, Contacts: form.Contacts, Address: form.Address, Remark: form.Remark,
Kind: model.ManageSupplierKindForMaterial,
})
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/supplier/material/edit 器材信息修改
* @apiVersion 1.0.0
* @apiName SupplierMaterialEdit
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @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 (*Supplier) MaterialEdit(c *gin.Context) {
form := &struct {
IDStringForm
supplierForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
ID: form.Convert(), Name: form.Name, Contacts: form.Contacts, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
Kind: model.ManageSupplierKindForMaterial,
})
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/supplier/material/delete 器材信息删除
* @apiVersion 1.0.0
* @apiName SupplierMaterialDelete
* @apiGroup Supplier
*
* @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 (*Supplier) MaterialDelete(c *gin.Context) {
form := new(IDStringForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Delete(form.Convert())
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/supplier/repair 修理厂信息
* @apiVersion 1.0.0
* @apiName SupplierRepair
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} [name="''"] 名称
* @apiParam {String} [mobile="''"] 联系方式
* @apiParam {Number} current 当前页
* @apiParam {Number} page_size 页展示数
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Object} data.data 具体信息
* @apiSuccess (200) {String} data.data.id ID
* @apiSuccess (200) {String} data.data.kind 类型101制造商102材料合作商103维修合作商
* @apiSuccess (200) {String} data.data.name 名称
* @apiSuccess (200) {String} data.data.mobile 联系方式
* @apiSuccess (200) {String} data.data.contacts 联系人
* @apiSuccess (200) {String} data.data.address 联系地址
* @apiSuccess (200) {String} data.data.remark 备注信息
* @apiSuccess (200) {Time} data.data.created_at 创建时间
* @apiSuccess (200) {Time} data.data.updated_at 更新时间
* @apiSuccess (200) {Number} data.count 总数
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": {
* "data": [
* {
* "id": "EgmJ4Ga7LQ",
* "kind": 102,
* "name": "测试的",
* "mobile": "",
* "contacts": "",
* "address": "",
* "remark": "",
* "created_at": "2021-11-09T13:39:19+08:00",
* "updated_at": "2021-11-09T13:52:39+08:00"
* }
* ],
* "count": 1
* }
* }
*/
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 := manage.NewSupplier()(getSession()(c).(*service.Session)).
List(form.Name, form.Mobile, model.ManageSupplierKindForRepair, form.Page, form.PageSize)
APIResponse(err, data)(c)
}
/**
* @api {post} /api/v1/supplier/repair/add 修理厂信息添加
* @apiVersion 1.0.0
* @apiName SupplierRepairAdd
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @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 (*Supplier) RepairAdd(c *gin.Context) {
form := new(supplierForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
Name: form.Name, Mobile: form.Mobile, Contacts: form.Contacts, Address: form.Address, Remark: form.Remark,
Kind: model.ManageSupplierKindForRepair,
})
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/supplier/repair/edit 修理厂信息修改
* @apiVersion 1.0.0
* @apiName SupplierRepairEdit
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @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 (*Supplier) RepairEdit(c *gin.Context) {
form := &struct {
IDStringForm
supplierForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
ID: form.Convert(), Name: form.Name, Contacts: form.Contacts, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
Kind: model.ManageSupplierKindForRepair,
})
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/supplier/repair/delete 修理厂信息删除
* @apiVersion 1.0.0
* @apiName SupplierRepairDelete
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @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 (*Supplier) RepairDelete(c *gin.Context) {
form := new(IDStringForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Delete(form.Convert())
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/supplier/manufacturer 制造商信息
* @apiVersion 1.0.0
* @apiName SupplierManufacturer
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} [name="''"] 名称
* @apiParam {String} [mobile="''"] 联系方式
* @apiParam {Number} current 当前页
* @apiParam {Number} page_size 页展示数
*
* @apiSuccess (200) {Object} data 数据信息
* @apiSuccess (200) {Object} data.data 具体信息
* @apiSuccess (200) {String} data.data.id ID
* @apiSuccess (200) {String} data.data.kind 类型101制造商102材料合作商103维修合作商
* @apiSuccess (200) {String} data.data.name 名称
* @apiSuccess (200) {String} data.data.mobile 联系方式
* @apiSuccess (200) {String} data.data.contacts 联系人
* @apiSuccess (200) {String} data.data.address 联系地址
* @apiSuccess (200) {String} data.data.remark 备注信息
* @apiSuccess (200) {Time} data.data.created_at 创建时间
* @apiSuccess (200) {Time} data.data.updated_at 更新时间
* @apiSuccess (200) {Number} data.count 总数
* @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示
*
* @apiSuccessExample {json} Success response:
* HTTPS 200 OK
* {
* "code": 200
* "msg": "ok"
* "data": {
* "data": [
* {
* "id": "EgmJ4Ga7LQ",
* "kind": 102,
* "name": "测试的",
* "mobile": "",
* "contacts": "",
* "address": "",
* "remark": "",
* "created_at": "2021-11-09T13:39:19+08:00",
* "updated_at": "2021-11-09T13:52:39+08:00"
* }
* ],
* "count": 1
* }
* }
*/
func (*Supplier) Manufacturer(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 := manage.NewSupplier()(getSession()(c).(*service.Session)).
List(form.Name, form.Mobile, model.ManageSupplierKindForManufacturer, form.Page, form.PageSize)
APIResponse(err, data)(c)
}
/**
* @api {post} /api/v1/supplier/manufacturer/add 制造商信息添加
* @apiVersion 1.0.0
* @apiName SupplierManufacturerAdd
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @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 (*Supplier) ManufacturerAdd(c *gin.Context) {
form := new(supplierForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
Name: form.Name, Mobile: form.Mobile, Contacts: form.Contacts, Address: form.Address, Remark: form.Remark,
Kind: model.ManageSupplierKindForManufacturer,
})
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/supplier/manufacturer/edit 制造商信息修改
* @apiVersion 1.0.0
* @apiName SupplierManufacturerEdit
* @apiGroup Supplier
*
* @apiHeader {string} x-token token
*
* @apiParam {String} id ID
* @apiParam {String} name 名称
* @apiParam {String} contacts 联系人
* @apiParam {String} mobile 联系方式
* @apiParam {String} [address="''"] 联系地址
* @apiParam {String} [remark="''"] 联系备注
*
* @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 (*Supplier) ManufacturerEdit(c *gin.Context) {
form := &struct {
IDStringForm
supplierForm
}{}
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
ID: form.Convert(), Name: form.Name, Contacts: form.Contacts, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
Kind: model.ManageSupplierKindForManufacturer,
})
APIResponse(err)(c)
}
/**
* @api {post} /api/v1/supplier/manufacturer/delete 制造商信息删除
* @apiVersion 1.0.0
* @apiName SupplierManufacturerDelete
* @apiGroup Supplier
*
* @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 (*Supplier) ManufacturerDelete(c *gin.Context) {
form := new(IDStringForm)
if err := bind(form)(c); err != nil {
APIFailure(err.(error))(c)
return
}
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Delete(form.Convert())
APIResponse(err)(c)
}