feat:完善项目
This commit is contained in:
@ -152,7 +152,15 @@ func (*Manage) Equipment(c *gin.Context) {
|
||||
* }
|
||||
*/
|
||||
func (*Manage) EquipmentSelect(c *gin.Context) {
|
||||
data, err := manage.NewEquipment()(getSession()(c).(*service.Session)).Select()
|
||||
form := &struct {
|
||||
ParentID string `json:"parent_id" form:"parent_id"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
obj := &IDStringForm{ID: form.ParentID}
|
||||
data, err := manage.NewEquipment()(getSession()(c).(*service.Session)).Select(obj.Convert())
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -335,6 +343,52 @@ func (*Manage) EquipmentDelete(c *gin.Context) {
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) EquipmentMaterial(c *gin.Context) {
|
||||
form := &struct {
|
||||
EquipmentID string `json:"equipment_id" form:"equipment_id" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewEquipmentMaterial()(getSession()(c).(*service.Session)).
|
||||
List((&IDStringForm{ID: form.EquipmentID}).Convert())
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) EquipmentMaterialBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
EquipmentID string `json:"equipment_id" form:"equipment_id" binding:"required"`
|
||||
MaterialIDs []string `json:"material_ids" form:"material_ids"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
materialIDs := make([]uint64, 0)
|
||||
obj := new(IDStringForm)
|
||||
|
||||
for _, v := range form.MaterialIDs {
|
||||
obj.ID = v
|
||||
materialIDs = append(materialIDs, obj.Convert())
|
||||
}
|
||||
err := manage.NewEquipmentMaterial()(getSession()(c).(*service.Session)).Bind(&manage.EquipmentMaterialBindParams{
|
||||
EquipmentID: (&IDStringForm{ID: form.EquipmentID}).Convert(), MaterialIDs: materialIDs,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) EquipmentMaterialDelete(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewEquipmentMaterial()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/v1/manage/material 器材信息
|
||||
* @apiVersion 1.0.0
|
||||
@ -716,13 +770,14 @@ func (*Manage) MaterialSupplierDelete(c *gin.Context) {
|
||||
*/
|
||||
func (*Manage) Notice(c *gin.Context) {
|
||||
form := &struct {
|
||||
Title string `json:"title" form:"title"`
|
||||
PageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewNotice()(getSession()(c).(*service.Session)).List(form.Page, form.PageSize)
|
||||
data, err := manage.NewNotice()(getSession()(c).(*service.Session)).List(form.Title, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ type (
|
||||
// EquipmentInfo 装备信息
|
||||
EquipmentInfo struct {
|
||||
basic.CommonIDString
|
||||
ParentID string `json:"parent_id"`
|
||||
Code string `json:"code"`
|
||||
Title string `json:"title"`
|
||||
Image string `json:"image"`
|
||||
@ -39,7 +40,7 @@ type (
|
||||
}
|
||||
// EquipmentMaterialDetail 装备器材信息
|
||||
EquipmentMaterialDetail struct {
|
||||
*model.ManageEquipmentMaterialInfo
|
||||
*model.ManageMaterialBasic
|
||||
ID string `json:"id"`
|
||||
}
|
||||
// EquipmentParams 装备参数信息
|
||||
@ -63,8 +64,15 @@ func (c *Equipment) tree(iModel model2.IModel, src []*model2.ManageEquipment, pa
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
parentID := ""
|
||||
|
||||
if v.ParentID > 0 {
|
||||
iModel.SetID(v.ParentID)
|
||||
parentID = iModel.GetEncodeID()
|
||||
}
|
||||
out = append(out, &EquipmentInfo{
|
||||
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
||||
ParentID: parentID,
|
||||
Code: v.Code,
|
||||
Title: v.Title,
|
||||
Image: v.Analysis(config.SettingInfo.Domain),
|
||||
@ -95,23 +103,26 @@ func (c *Equipment) List(parentID uint64, title string, page, pageSize int) (*ba
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := model2.PagesFields(mManageEquipment.ManageEquipment, &out, []string{"id", "code", "title", "image", "created_at"},
|
||||
if err := model2.PagesFields(mManageEquipment.ManageEquipment, &out, []string{"id", "parent_id", "code", "title", "image", "created_at"},
|
||||
page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &basic.PageDataResponse{
|
||||
Data: c.tree(mManageEquipment.ManageEquipment, out, 0),
|
||||
Data: c.tree(mManageEquipment.ManageEquipment, out, parentID),
|
||||
Count: count,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Select 筛选信息
|
||||
func (c *Equipment) Select() ([]*EquipmentBasic, error) {
|
||||
func (c *Equipment) Select(parentID uint64) ([]*EquipmentBasic, error) {
|
||||
mManageEquipment := model.NewManageEquipment()
|
||||
|
||||
out := make([]*model2.ManageEquipment, 0)
|
||||
|
||||
if err := model2.ScanFields(mManageEquipment.ManageEquipment, &out, []string{"id", "code", "title"}); err != nil {
|
||||
where := []*model2.ModelWhereOrder{
|
||||
&model2.ModelWhereOrder{Where: model2.NewWhere("parent_id", parentID)},
|
||||
}
|
||||
if err := model2.ScanFields(mManageEquipment.ManageEquipment, &out, []string{"id", "code", "title"}, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*EquipmentBasic, 0)
|
||||
@ -119,8 +130,7 @@ func (c *Equipment) Select() ([]*EquipmentBasic, error) {
|
||||
for _, v := range out {
|
||||
list = append(list, &EquipmentBasic{
|
||||
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
||||
Code: v.Code,
|
||||
Title: v.Title,
|
||||
Code: v.Code, Title: v.Title,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
@ -146,7 +156,7 @@ func (c *Equipment) Detail(id uint64) (*EquipmentDetail, error) {
|
||||
}
|
||||
mManageEquipmentMaterial := model.NewManageEquipmentMaterial()
|
||||
|
||||
materials := make([]*model.ManageEquipmentMaterialInfo, 0)
|
||||
materials := make([]*model.ManageMaterialBasic, 0)
|
||||
|
||||
if materials, err = mManageEquipmentMaterial.Materials(id); err != nil {
|
||||
return nil, err
|
||||
@ -156,8 +166,8 @@ func (c *Equipment) Detail(id uint64) (*EquipmentDetail, error) {
|
||||
mManageEquipmentMaterial.ID = v.ID
|
||||
|
||||
out.Materials = append(out.Materials, &EquipmentMaterialDetail{
|
||||
ManageEquipmentMaterialInfo: v,
|
||||
ID: mManageEquipmentMaterial.GetEncodeID(),
|
||||
ManageMaterialBasic: v,
|
||||
ID: mManageEquipmentMaterial.GetEncodeID(),
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
|
86
app/controller/manage/equipment_material.go
Normal file
86
app/controller/manage/equipment_material.go
Normal file
@ -0,0 +1,86 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/controller/basic"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"ArmedPolice/serve/orm"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type EquipmentMaterial struct{ *service.Session }
|
||||
|
||||
type EquipmentMaterialHandle func(session *service.Session) *EquipmentMaterial
|
||||
|
||||
type (
|
||||
// EquipmentMaterialInfo 装备器材信息
|
||||
EquipmentMaterialInfo struct {
|
||||
*model.ManageMaterialBasic
|
||||
basic.CommonIDString
|
||||
}
|
||||
EquipmentMaterialBindParams struct {
|
||||
EquipmentID uint64
|
||||
MaterialIDs []uint64
|
||||
}
|
||||
)
|
||||
|
||||
// List 列表信息
|
||||
func (c *EquipmentMaterial) List(equipmentID uint64) ([]*EquipmentMaterialInfo, error) {
|
||||
mManageEquipmentMaterial := model.NewManageEquipmentMaterial()
|
||||
|
||||
out, err := mManageEquipmentMaterial.Materials(equipmentID)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*EquipmentMaterialInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
mManageEquipmentMaterial.ID = v.ID
|
||||
|
||||
list = append(list, &EquipmentMaterialInfo{
|
||||
CommonIDString: basic.CommonIDString{ID: mManageEquipmentMaterial.GetEncodeID()},
|
||||
ManageMaterialBasic: v,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Bind 绑定操作
|
||||
func (c *EquipmentMaterial) Bind(params *EquipmentMaterialBindParams) error {
|
||||
mManageEquipmentMaterial := model.NewManageEquipmentMaterial()
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
err := model2.DeleteWhere(mManageEquipmentMaterial.ManageEquipmentMaterial, []*model2.ModelWhere{
|
||||
model2.NewWhere("equipment_id", params.EquipmentID),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
list := make([]*model2.ManageEquipmentMaterial, 0)
|
||||
|
||||
for _, v := range params.MaterialIDs {
|
||||
list = append(list, &model2.ManageEquipmentMaterial{
|
||||
EquipmentID: params.EquipmentID,
|
||||
MaterialID: v,
|
||||
})
|
||||
}
|
||||
if len(list) > 0 {
|
||||
return model2.Creates(mManageEquipmentMaterial.ManageEquipmentMaterial, list)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (c *EquipmentMaterial) Delete(id uint64) error {
|
||||
mManageEquipmentMaterial := model.NewManageEquipmentMaterial()
|
||||
mManageEquipmentMaterial.ID = id
|
||||
return model2.Delete(mManageEquipmentMaterial.ManageEquipmentMaterial)
|
||||
}
|
||||
|
||||
func NewEquipmentMaterial() EquipmentMaterialHandle {
|
||||
return func(session *service.Session) *EquipmentMaterial {
|
||||
return &EquipmentMaterial{session}
|
||||
}
|
||||
}
|
@ -19,17 +19,26 @@ type NoticeInfo struct {
|
||||
}
|
||||
|
||||
// List 列表信息
|
||||
func (c *Notice) List(page, pageSize int) (*basic.PageDataResponse, error) {
|
||||
func (c *Notice) List(title string, page, pageSize int) (*basic.PageDataResponse, error) {
|
||||
mManageNotice := model.NewManageNotice()
|
||||
|
||||
out := make([]*model2.ManageNotice, 0)
|
||||
|
||||
var count int64
|
||||
|
||||
if err := model2.Pages(mManageNotice.ManageNotice, &out, page, pageSize, &count, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}); err != nil {
|
||||
where := []*model2.ModelWhereOrder{
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
},
|
||||
}
|
||||
|
||||
if title != "" {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("title", title),
|
||||
})
|
||||
}
|
||||
if err := model2.Pages(mManageNotice.ManageNotice, &out, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*NoticeInfo, 0)
|
||||
@ -69,6 +78,7 @@ func (c *Notice) Form(id uint64, title, content string) error {
|
||||
"title": title, "content": content, "updated_at": time.Now(),
|
||||
})
|
||||
}
|
||||
mManageNotice.TenantID = c.TenantID
|
||||
mManageNotice.Title = title
|
||||
mManageNotice.Content = content
|
||||
return model2.Create(mManageNotice)
|
||||
|
@ -254,6 +254,15 @@ func (c *Instance) Form(params *InstanceParams) error {
|
||||
func (c *Instance) Delete(id uint64) error {
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUser.ID = id
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "is_admin"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户信息不存在或已被删除")
|
||||
} else if mSysUser.IsAdminUser() {
|
||||
return errors.New("操作错误,超管不可删除")
|
||||
}
|
||||
return model2.Delete(mSysUser.SysUser)
|
||||
}
|
||||
|
||||
|
@ -9,20 +9,16 @@ import (
|
||||
type ManageEquipmentMaterial struct {
|
||||
*model.ManageEquipmentMaterial
|
||||
}
|
||||
type ManageEquipmentMaterialInfo struct {
|
||||
ID uint64 `json:"id"`
|
||||
ManageMaterialBasic
|
||||
}
|
||||
|
||||
// Materials 器材信息
|
||||
func (m *ManageEquipmentMaterial) Materials(equipmentID uint64) ([]*ManageEquipmentMaterialInfo, error) {
|
||||
func (m *ManageEquipmentMaterial) Materials(equipmentID uint64) ([]*ManageMaterialBasic, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS e").
|
||||
Select("e.id", "m.code", "m.title", "m.unit", "s.name AS manufacturer_name").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS m ON e.material_id = m.id", model.NewManageMaterial().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m.manufacturer_id = s.id", model.NewManageSupplier().TableName())).
|
||||
Where("e.equipment_id = ? AND e.is_deleted = ?", equipmentID, model.DeleteStatusForNot)
|
||||
|
||||
out := make([]*ManageEquipmentMaterialInfo, 0)
|
||||
out := make([]*ManageMaterialBasic, 0)
|
||||
|
||||
err := db.Scan(&out).Error
|
||||
|
||||
|
@ -13,7 +13,7 @@ type ManageMaterial struct {
|
||||
type (
|
||||
// ManageMaterialBasic 基本信息
|
||||
ManageMaterialBasic struct {
|
||||
ID uint64 `json:"id"`
|
||||
ID uint64 `json:"-"`
|
||||
Code string `json:"code"`
|
||||
Title string `json:"title"`
|
||||
Price float64 `json:"price"`
|
||||
|
@ -49,7 +49,7 @@ func (m *SysUser) Users(page, pageSize int, count *int64, where ...*model.ModelW
|
||||
mSysTenant := model.NewSysTenant()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" As u").Select("u.id", "u.uuid", "account", "u.name", "u.avatar",
|
||||
"u.mobile", "u.email", "u.status", "t.name AS tenant_name", "u.created_at").
|
||||
"u.mobile", "u.email", "u.gender", "u.status", "t.name AS tenant_name", "u.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON u.tenant_id = t.id", mSysTenant.TableName())).
|
||||
Where("u.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
|
@ -165,6 +165,9 @@ func (this *Router) registerAPI() {
|
||||
manageV1.POST("/equipment/add", _api.EquipmentAdd)
|
||||
manageV1.POST("/equipment/edit", _api.EquipmentEdit)
|
||||
manageV1.POST("/equipment/delete", _api.EquipmentDelete)
|
||||
manageV1.POST("/equipment/material", _api.EquipmentMaterial)
|
||||
manageV1.POST("/equipment/material/bind", _api.EquipmentMaterialBind)
|
||||
manageV1.POST("/equipment/material/delete", _api.EquipmentMaterialDelete)
|
||||
manageV1.POST("/material", _api.Material)
|
||||
manageV1.GET("/material/select", _api.MaterialSelect)
|
||||
manageV1.POST("/material/add", _api.MaterialAdd)
|
||||
@ -177,7 +180,7 @@ func (this *Router) registerAPI() {
|
||||
manageV1.POST("/notice/detail", _api.NoticeDetail)
|
||||
manageV1.POST("/notice/add", _api.NoticeAdd)
|
||||
manageV1.POST("/notice/edit", _api.NoticeEdit)
|
||||
manageV1.POST("/notice/delete", _api.NoticeEdit)
|
||||
manageV1.POST("/notice/delete", _api.NoticeDelete)
|
||||
}
|
||||
// Work 工单管理
|
||||
workV1 := v1.Group("/work")
|
||||
|
@ -5,5 +5,5 @@ import "testing"
|
||||
func TestSha256String(t *testing.T) {
|
||||
//t.Log(Md5String("9f735e0df9a1ddc702bf0a1a7b83033f9f7153a00c29de82cedadc9957289b05"))
|
||||
t.Log(HASHIDEncode(1))
|
||||
t.Log(HASHIDDecode("A9GVg5JZdr"))
|
||||
t.Log(HASHIDDecode("d3rJnGwE9o"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user