feat:完善项目
This commit is contained in:
@ -1,7 +1,158 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ArmedPolice/app/controller/manage"
|
||||||
|
"ArmedPolice/app/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
type Manage struct{}
|
type Manage struct{}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// manageEquipmentForm 装备参数信息
|
||||||
|
manageEquipmentForm struct {
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
// manageMaterialForm 装备参数信息
|
||||||
|
manageMaterialForm struct {
|
||||||
|
ManufacturerID uint64 `json:"manufacturer_id" form:"manufacturer_id"`
|
||||||
|
Code string `json:"code" form:"code" binding:"required"`
|
||||||
|
Title string `json:"title" form:"title" binding:"required"`
|
||||||
|
ImageForm
|
||||||
|
Position string `json:"position" form:"position"`
|
||||||
|
Remark string `json:"remark" form:"remark"`
|
||||||
|
Unit int `json:"unit" form:"Unit" binding:"required"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @apiDefine Manage 数据管理
|
* @apiDefine Manage 数据管理
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
func (*Manage) Equipment(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
ParentID uint64 `json:"parent_id" form:"parent_id"`
|
||||||
|
Title string `json:"title" form:"title"`
|
||||||
|
PageForm
|
||||||
|
}{}
|
||||||
|
if err := bind(form)(c); err != nil {
|
||||||
|
APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := manage.NewEquipment()(getSession()(c).(*service.Session)).List(form.ParentID, form.Title, form.Page, form.PageSize)
|
||||||
|
APIResponse(err, data)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Manage) EquipmentDetail(c *gin.Context) {
|
||||||
|
form := new(IDStringForm)
|
||||||
|
|
||||||
|
if err := bind(form)(c); err != nil {
|
||||||
|
APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := manage.NewEquipment()(getSession()(c).(*service.Session)).Detail(form.Convert())
|
||||||
|
APIResponse(err, data)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Manage) EquipmentAdd(c *gin.Context) {
|
||||||
|
form := new(manageEquipmentForm)
|
||||||
|
|
||||||
|
if err := bind(form)(c); err != nil {
|
||||||
|
APIFailure(err.(error))(c)
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
APIResponse(err)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Manage) EquipmentEdit(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
IDStringForm
|
||||||
|
manageEquipmentForm
|
||||||
|
}{}
|
||||||
|
if err := bind(form)(c); err != nil {
|
||||||
|
APIFailure(err.(error))(c)
|
||||||
|
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,
|
||||||
|
Remark: form.Remark,
|
||||||
|
})
|
||||||
|
APIResponse(err)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Manage) EquipmentDelete(c *gin.Context) {
|
||||||
|
form := new(IDStringForm)
|
||||||
|
|
||||||
|
if err := bind(form)(c); err != nil {
|
||||||
|
APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := manage.NewEquipment()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
||||||
|
APIResponse(err)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Manage) Material(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
ManufacturerID uint64 `json:"manufacturer_id" form:"manufacturer_id"`
|
||||||
|
SupplierID uint64 `json:"supplier_id" form:"supplier_id"`
|
||||||
|
Code string `json:"code" form:"code"`
|
||||||
|
Title string `json:"title" form:"title"`
|
||||||
|
PageForm
|
||||||
|
}{}
|
||||||
|
if err := bind(form)(c); err != nil {
|
||||||
|
APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := manage.NewMaterial()(getSession()(c).(*service.Session)).
|
||||||
|
List(form.ManufacturerID, form.SupplierID, form.Code, form.Title, form.Page, form.PageSize)
|
||||||
|
APIResponse(err, data)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Manage) MaterialAdd(c *gin.Context) {
|
||||||
|
form := new(manageMaterialForm)
|
||||||
|
|
||||||
|
if err := bind(form)(c); err != nil {
|
||||||
|
APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Form(&manage.MaterialParams{
|
||||||
|
ManufacturerID: form.ManufacturerID, Code: form.Code, Title: form.Title, Image: form.FilterImageURL(),
|
||||||
|
Position: form.Position, Remark: form.Remark, Unit: form.Unit,
|
||||||
|
})
|
||||||
|
APIResponse(err)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Manage) MaterialEdit(c *gin.Context) {
|
||||||
|
form := &struct {
|
||||||
|
IDStringForm
|
||||||
|
manageMaterialForm
|
||||||
|
}{}
|
||||||
|
if err := bind(form)(c); err != nil {
|
||||||
|
APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Form(&manage.MaterialParams{
|
||||||
|
ID: form.Convert(), ManufacturerID: form.ManufacturerID, Code: form.Code, Title: form.Title,
|
||||||
|
Image: form.FilterImageURL(), Position: form.Position, Remark: form.Remark, Unit: form.Unit,
|
||||||
|
})
|
||||||
|
APIResponse(err)(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Manage) MaterialDelete(c *gin.Context) {
|
||||||
|
form := new(IDStringForm)
|
||||||
|
|
||||||
|
if err := bind(form)(c); err != nil {
|
||||||
|
APIFailure(err.(error))(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := manage.NewMaterial()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
||||||
|
APIResponse(err)(c)
|
||||||
|
}
|
||||||
|
7
app/api/work.go
Normal file
7
app/api/work.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
type Work struct{}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @apiDefine Work 工单管理
|
||||||
|
*/
|
@ -38,15 +38,15 @@ type (
|
|||||||
}
|
}
|
||||||
// EquipmentParams 装备参数信息
|
// EquipmentParams 装备参数信息
|
||||||
EquipmentParams struct {
|
EquipmentParams struct {
|
||||||
ID uint64
|
ID uint64
|
||||||
Title, Image, Config, Remark string
|
Code, Title, Image, Config, Remark string
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *EquipmentParams) isExist(iModel model2.IModel) (bool, error) {
|
func (c *EquipmentParams) isExist(iModel model2.IModel, tenantID uint64) (bool, error) {
|
||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
if err := model2.Count(iModel, &count, model2.NewWhere("title", c.Title)); err != nil {
|
if err := model2.Count(iModel, &count, model2.NewWhere("tenant_id", tenantID), model2.NewWhere("code", c.Code)); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
return count > 0, nil
|
return count > 0, nil
|
||||||
@ -71,7 +71,7 @@ func (c *Equipment) tree(src []*model2.ManageEquipment, parentID uint64) []*Equi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List 列表信息
|
// List 列表信息
|
||||||
func (c *Equipment) List(title string, page, pageSize int) ([]*EquipmentInfo, error) {
|
func (c *Equipment) List(parentID uint64, title string, page, pageSize int) ([]*EquipmentInfo, error) {
|
||||||
mManageEquipment := model.NewManageEquipment()
|
mManageEquipment := model.NewManageEquipment()
|
||||||
|
|
||||||
out := make([]*model2.ManageEquipment, 0)
|
out := make([]*model2.ManageEquipment, 0)
|
||||||
@ -81,6 +81,11 @@ func (c *Equipment) List(title string, page, pageSize int) ([]*EquipmentInfo, er
|
|||||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
if parentID > 0 {
|
||||||
|
where = append(where, &model2.ModelWhereOrder{
|
||||||
|
Where: model2.NewWhere("parentID", parentID),
|
||||||
|
})
|
||||||
|
}
|
||||||
if title != "" {
|
if title != "" {
|
||||||
where = append(where, &model2.ModelWhereOrder{
|
where = append(where, &model2.ModelWhereOrder{
|
||||||
Where: model2.NewWhereLike("title", title),
|
Where: model2.NewWhereLike("title", title),
|
||||||
@ -106,7 +111,6 @@ func (c *Equipment) Detail(id uint64) (*EquipmentDetail, error) {
|
|||||||
} else if !isExist {
|
} else if !isExist {
|
||||||
return nil, errors.New("操作错误,数据不存在")
|
return nil, errors.New("操作错误,数据不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
out := &EquipmentDetail{
|
out := &EquipmentDetail{
|
||||||
CommonIDString: basic.CommonIDString{ID: mManageEquipment.GetEncodeID()},
|
CommonIDString: basic.CommonIDString{ID: mManageEquipment.GetEncodeID()},
|
||||||
ManageEquipment: mManageEquipment.ManageEquipment,
|
ManageEquipment: mManageEquipment.ManageEquipment,
|
||||||
@ -147,14 +151,15 @@ func (c *Equipment) Form(params *EquipmentParams) error {
|
|||||||
return errors.New("操作错误,装备信息不存在")
|
return errors.New("操作错误,装备信息不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.Title != mManageEquipment.Title {
|
if params.Code != mManageEquipment.Code {
|
||||||
if isExist, err = params.isExist(mManageEquipment.ManageEquipment); err != nil {
|
if isExist, err = params.isExist(mManageEquipment.ManageEquipment, c.TenantID); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if isExist {
|
} else if isExist {
|
||||||
return errors.New("操作错误,已存在相应的装备信息")
|
return errors.New("操作错误,已存在相应的装备信息")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mManageEquipment.Code = params.Code
|
||||||
mManageEquipment.Title = params.Title
|
mManageEquipment.Title = params.Title
|
||||||
mManageEquipment.Image.Image = params.Image
|
mManageEquipment.Image.Image = params.Image
|
||||||
mManageEquipment.Config = params.Config
|
mManageEquipment.Config = params.Config
|
||||||
@ -165,7 +170,7 @@ func (c *Equipment) Form(params *EquipmentParams) error {
|
|||||||
return model2.Updates(mManageEquipment.ManageEquipment, mManageEquipment.ManageEquipment)
|
return model2.Updates(mManageEquipment.ManageEquipment, mManageEquipment.ManageEquipment)
|
||||||
}
|
}
|
||||||
// 查询装备信息是否存在
|
// 查询装备信息是否存在
|
||||||
if isExist, err := params.isExist(mManageEquipment.ManageEquipment); err != nil {
|
if isExist, err := params.isExist(mManageEquipment.ManageEquipment, c.TenantID); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if isExist {
|
} else if isExist {
|
||||||
return errors.New("操作错误,已存在相应的装备信息")
|
return errors.New("操作错误,已存在相应的装备信息")
|
||||||
|
@ -38,11 +38,14 @@ func (c *MaterialParams) isExistForCode(iModel model2.IModel, tenantID uint64) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List 列表信息
|
// List 列表信息
|
||||||
func (c *Material) List(supplierID uint64, code, title string, page, pageSize int) (*basic.PageDataResponse, error) {
|
func (c *Material) List(manufacturerID, supplierID uint64, code, title string, page, pageSize int) (*basic.PageDataResponse, error) {
|
||||||
mManageMaterial := model.NewManageMaterial()
|
mManageMaterial := model.NewManageMaterial()
|
||||||
|
|
||||||
where := make([]*model2.ModelWhere, 0)
|
where := make([]*model2.ModelWhere, 0)
|
||||||
|
|
||||||
|
if manufacturerID > 0 {
|
||||||
|
where = append(where, model2.NewWhere("m.manufacturer_id", manufacturerID))
|
||||||
|
}
|
||||||
if supplierID > 0 {
|
if supplierID > 0 {
|
||||||
where = append(where, model2.NewWhere("m.supplier_id", supplierID))
|
where = append(where, model2.NewWhere("m.supplier_id", supplierID))
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"apidoc": {
|
"apidoc": {
|
||||||
"name": "ArmedPolice",
|
"name": "ArmedPolice",
|
||||||
"title": "ArmedPoliceAPI",
|
"title": "ArmedPoliceAPI",
|
||||||
"description": "话不多说",
|
"description": "话不多说,请看接口,看不懂,自己想办法",
|
||||||
"url": "http://127.0.0.1:8010",
|
"url": "http://127.0.0.1:8010",
|
||||||
"sampleUrl": "http://127.0.0.1:8010",
|
"sampleUrl": "http://127.0.0.1:8010",
|
||||||
"order": [
|
"order": [
|
||||||
|
@ -96,6 +96,20 @@ func (this *Router) registerAPI() {
|
|||||||
roleV1.POST("/menus", _api.Menu)
|
roleV1.POST("/menus", _api.Menu)
|
||||||
roleV1.POST("/menu/bind", _api.MenuBind)
|
roleV1.POST("/menu/bind", _api.MenuBind)
|
||||||
}
|
}
|
||||||
|
// Manage 数据管理
|
||||||
|
manageV1 := v1.Group("/manage")
|
||||||
|
{
|
||||||
|
_api := new(api.Manage)
|
||||||
|
manageV1.POST("/equipment", _api.Equipment)
|
||||||
|
manageV1.POST("/equipment/detail", _api.EquipmentDetail)
|
||||||
|
manageV1.POST("/equipment/add", _api.EquipmentAdd)
|
||||||
|
manageV1.POST("/equipment/edit", _api.EquipmentEdit)
|
||||||
|
manageV1.POST("/equipment/delete", _api.EquipmentDelete)
|
||||||
|
manageV1.POST("/material", _api.Material)
|
||||||
|
manageV1.POST("/material/add", _api.MaterialAdd)
|
||||||
|
manageV1.POST("/material/edit", _api.MaterialEdit)
|
||||||
|
manageV1.POST("/material/delete", _api.MaterialDelete)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Router) Init() *gin.Engine {
|
func (this *Router) Init() *gin.Engine {
|
||||||
|
Reference in New Issue
Block a user