feat:优化项目信息,增加用户器材信息管理
This commit is contained in:
@ -20,6 +20,14 @@ type (
|
||||
Papers []string `json:"papers" form:"papers"`
|
||||
Patents []string `json:"patents" form:"patents"`
|
||||
}
|
||||
// equipmentForm 设备信息
|
||||
equipmentForm struct {
|
||||
Kind int `json:"kind" form:"kind" binding:"required"`
|
||||
Code string `json:"code" form:"code" binding:"required"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
Params string `json:"params" form:"params"`
|
||||
Description string `json:"description" form:"description"`
|
||||
}
|
||||
)
|
||||
|
||||
func (a *enterpriseForm) paperInfo() []uint64 {
|
||||
@ -100,3 +108,59 @@ func (*Manage) EnterpriseDelete(c *gin.Context) {
|
||||
Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) Equipment(c *gin.Context) {
|
||||
form := &struct {
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
Code string `json:"code" form:"code"`
|
||||
Title string `json:"title" form:"title"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
List(form.Kind, form.Code, form.Title, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) EquipmentAdd(c *gin.Context) {
|
||||
form := new(equipmentForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&manage.EquipmentParams{Kind: form.Kind, Code: form.Code, Title: form.Title, Params: form.Params, Description: form.Description})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) EquipmentEdit(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
equipmentForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&manage.EquipmentParams{ID: form.Convert(), Kind: form.Kind, Code: form.Code, Title: form.Title,
|
||||
Params: form.Params, Description: form.Description})
|
||||
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) EquipmentDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -88,12 +88,6 @@ type (
|
||||
Kind int `json:"kind" form:"kind" binding:"required"`
|
||||
Keywords []string `json:"keywords" form:"keywords"`
|
||||
}
|
||||
// equipmentForm 设备参数
|
||||
equipmentForm struct {
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
Research string `json:"research" form:"research" binding:"required"`
|
||||
Describe string `json:"describe" form:"describe"`
|
||||
}
|
||||
// productForm 产品参数
|
||||
productForm struct {
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
@ -494,58 +488,6 @@ func (a *Technology) TopicDelete(c *gin.Context) {
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Technology) Equipment(c *gin.Context) {
|
||||
form := &struct {
|
||||
Title string `json:"title" form:"title"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology2.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
List(form.Title, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Technology) EquipmentAdd(c *gin.Context) {
|
||||
form := new(equipmentForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.EquipmentParams{Title: form.Title, Research: form.Research, Describe: form.Describe})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Technology) EquipmentEdit(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
equipmentForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Form(&technology2.EquipmentParams{ID: form.Convert(), Title: form.Title, Research: form.Research, Describe: form.Describe})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Technology) EquipmentDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewEquipment()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
|
||||
Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) Product(c *gin.Context) {
|
||||
form := &struct {
|
||||
Title string `json:"title" form:"title"`
|
||||
|
@ -98,6 +98,8 @@ func (c *Enterprise) Form(params *EnterpriseParams) error {
|
||||
if mUserCooperateEnterprise.ID > 0 {
|
||||
return model2.Updates(mUserCooperateEnterprise.UserCooperateEnterprise, mUserCooperateEnterprise.UserCooperateEnterprise)
|
||||
}
|
||||
mUserCooperateEnterprise.Local.Local = c.local
|
||||
mUserCooperateEnterprise.UID = c.UID
|
||||
return model2.Create(mUserCooperateEnterprise.UserCooperateEnterprise)
|
||||
}
|
||||
|
||||
|
126
app/api/enterprise/controller/manage/equipment.go
Normal file
126
app/api/enterprise/controller/manage/equipment.go
Normal file
@ -0,0 +1,126 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Equipment 设备信息
|
||||
type Equipment struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type EquipmentHandle func(session *session.Enterprise, local string) *Equipment
|
||||
|
||||
type (
|
||||
EquipmentInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.ManageEquipment
|
||||
}
|
||||
EquipmentParams struct {
|
||||
ID uint64
|
||||
Kind int
|
||||
Code, Title, Params, Description string
|
||||
PurchaseAt string
|
||||
}
|
||||
)
|
||||
|
||||
// List 列表信息
|
||||
func (c *Equipment) List(kind int, code, title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mManageEquipment := model.NewManageEquipment()
|
||||
|
||||
where := []*model2.ModelWhereOrder{
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("local", c.local),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
},
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("uid", c.UID),
|
||||
},
|
||||
}
|
||||
if kind > 0 {
|
||||
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhere("kind", kind)})
|
||||
}
|
||||
if code != "" {
|
||||
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhereLike("code", code)})
|
||||
}
|
||||
if title != "" {
|
||||
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhereLike("title", title)})
|
||||
}
|
||||
out := make([]*model2.ManageEquipment, 0)
|
||||
|
||||
var count int64
|
||||
|
||||
if err := model2.Pages(mManageEquipment.ManageEquipment, &out, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*EquipmentInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &EquipmentInfo{
|
||||
ID: v.GetEncodeID(), ManageEquipment: v,
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Form 数据操作
|
||||
func (c *Equipment) Form(params *EquipmentParams) error {
|
||||
mManageEquipment := model.NewManageEquipment()
|
||||
|
||||
if params.ID > 0 {
|
||||
mManageEquipment.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mManageEquipment.ManageEquipment, []string{"id", "uid", "created_at"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,器材信息不存在或已被删除")
|
||||
} else if mManageEquipment.UID != c.UID {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
}
|
||||
mManageEquipment.Kind = model2.ManageEquipmentKind(params.Kind)
|
||||
mManageEquipment.Code = params.Code
|
||||
mManageEquipment.Title = params.Title
|
||||
mManageEquipment.Params = params.Params
|
||||
mManageEquipment.Description = params.Description
|
||||
|
||||
if mManageEquipment.ID > 0 {
|
||||
return model2.Updates(mManageEquipment.ManageEquipment, mManageEquipment.ManageEquipment)
|
||||
}
|
||||
mManageEquipment.Local.Local = c.local
|
||||
mManageEquipment.UID = c.UID
|
||||
return model2.Create(mManageEquipment.ManageEquipment)
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Equipment) Delete(id uint64) error {
|
||||
mManageEquipment := model.NewManageEquipment()
|
||||
mManageEquipment.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mManageEquipment.ManageEquipment, []string{"id", "uid", "created_at"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,器材信息不存在或已被删除")
|
||||
} else if mManageEquipment.UID != c.UID {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
return model2.Delete(mManageEquipment.ManageEquipment)
|
||||
}
|
||||
|
||||
func NewEquipment() EquipmentHandle {
|
||||
return func(session *session.Enterprise, local string) *Equipment {
|
||||
return &Equipment{
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
package technology
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/api/manage/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Equipment 技术设备
|
||||
type Equipment struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type EquipmentHandle func(session *session.Enterprise, local string) *Equipment
|
||||
|
||||
type EquipmentParams struct {
|
||||
ID uint64
|
||||
Title, Research, Describe string
|
||||
}
|
||||
|
||||
type EquipmentInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.TechnologyEquipment
|
||||
}
|
||||
|
||||
// List 列表信息
|
||||
func (c *Equipment) List(title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mTechnologyEquipment := model.NewTechnologyEquipment()
|
||||
|
||||
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("local", c.local),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("uid", c.UID),
|
||||
}}
|
||||
|
||||
if title != "" {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("title", title),
|
||||
})
|
||||
}
|
||||
out := make([]*model2.TechnologyEquipment, 0)
|
||||
|
||||
var count int64
|
||||
|
||||
if err := model2.Pages(mTechnologyEquipment.TechnologyEquipment, &out, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*EquipmentInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &EquipmentInfo{
|
||||
ID: v.GetEncodeID(), TechnologyEquipment: v,
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
func (c *Equipment) Form(params *EquipmentParams) error {
|
||||
mTechnologyEquipment := model.NewTechnologyEquipment()
|
||||
|
||||
if params.ID > 0 {
|
||||
mTechnologyEquipment.ID = params.ID
|
||||
|
||||
isExist, err := model2.First(mTechnologyEquipment.TechnologyEquipment)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,设备信息不存在")
|
||||
} else if mTechnologyEquipment.Local.Local != c.local {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
}
|
||||
mTechnologyEquipment.Title = params.Title
|
||||
mTechnologyEquipment.Research = params.Research
|
||||
mTechnologyEquipment.Describe = params.Describe
|
||||
|
||||
if mTechnologyEquipment.ID > 0 {
|
||||
return model2.Updates(mTechnologyEquipment.TechnologyEquipment, mTechnologyEquipment.TechnologyEquipment)
|
||||
}
|
||||
mTechnologyEquipment.UID = c.UID
|
||||
return model2.Create(mTechnologyEquipment.TechnologyEquipment)
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Equipment) Delete(id uint64) error {
|
||||
mTechnologyEquipment := model.NewTechnologyEquipment()
|
||||
mTechnologyEquipment.ID = id
|
||||
|
||||
isExist, err := model2.First(mTechnologyEquipment.TechnologyEquipment)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,设备信息不存在或已被删除")
|
||||
} else if mTechnologyEquipment.UID != c.UID {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
return model2.Delete(mTechnologyEquipment.TechnologyEquipment)
|
||||
}
|
||||
|
||||
func NewEquipment() EquipmentHandle {
|
||||
return func(session *session.Enterprise, local string) *Equipment {
|
||||
return &Equipment{
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
@ -44,7 +44,7 @@ func (c *Bank) List() ([]*BankInfo, error) {
|
||||
out := make([]*model2.UserManageBank, 0)
|
||||
|
||||
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("uid", c.ManageUID),
|
||||
Where: model2.NewWhere("uid", c.UID),
|
||||
Order: model2.NewOrder("is_default", model2.OrderModeToDesc),
|
||||
}}
|
||||
if err := model2.Find(mUserManageBank.UserManageBank, &out, where...); err != nil {
|
||||
@ -84,13 +84,13 @@ func (c *Bank) Bind(params *BankParams, captcha string) error {
|
||||
} else if count > 0 {
|
||||
return errors.New("当前银行卡已被注册")
|
||||
}
|
||||
mUserManageBank.MUid = c.ManageUID
|
||||
mUserManageBank.UID = c.UID
|
||||
mUserManageBank.Name = params.Name
|
||||
mUserManageBank.IDCard = params.IDCard
|
||||
mUserManageBank.BankCard = params.BankCard
|
||||
mUserManageBank.BankName = params.BankName
|
||||
|
||||
if err = model2.Count(mUserManageBank.UserManageBank, &count, model2.NewWhere("uid", c.ManageUID)); err != nil {
|
||||
if err = model2.Count(mUserManageBank.UserManageBank, &count, model2.NewWhere("uid", c.UID)); err != nil {
|
||||
return err
|
||||
} else if count <= 0 {
|
||||
mUserManageBank.IsDefault = model2.UserManageBankDefaultForYes
|
||||
@ -109,7 +109,7 @@ func (c *Bank) Unbind(id uint64) error {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,绑定信息不存在")
|
||||
} else if mUserManageBank.MUid != c.ManageUID {
|
||||
} else if mUserManageBank.UID != c.UID {
|
||||
return errors.New("无权限操作")
|
||||
}
|
||||
return model2.Delete(mUserManageBank)
|
||||
|
11
app/api/enterprise/model/manage_equipment.go
Normal file
11
app/api/enterprise/model/manage_equipment.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type ManageEquipment struct {
|
||||
*model.ManageEquipment
|
||||
}
|
||||
|
||||
func NewManageEquipment() *ManageEquipment {
|
||||
return &ManageEquipment{model.NewManageEquipment()}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type TechnologyEquipment struct {
|
||||
*model.TechnologyEquipment
|
||||
}
|
||||
|
||||
func NewTechnologyEquipment() *TechnologyEquipment {
|
||||
return &TechnologyEquipment{model.NewTechnologyEquipment()}
|
||||
}
|
Reference in New Issue
Block a user