feat:完善项目信息
This commit is contained in:
@ -149,22 +149,6 @@ func (*Manage) ExpertExamine(c *gin.Context) {
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) Laboratory(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (*Manage) LaboratoryExamine(c *gin.Context) {
|
||||
form := new(manageExamineForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForLaboratory
|
||||
err := form.handle(api.GetSession()(c).(*session.Admin), nil)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) Research(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
@ -191,6 +175,19 @@ func (*Manage) ResearchSelect(c *gin.Context) {
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) ResearchForm(c *gin.Context) {
|
||||
form := &struct {
|
||||
manageForm
|
||||
config.IdentityForResearch
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewResearch()(api.GetSession()(c).(*session.Admin)).Form(form.bind(), &form.IdentityForResearch)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) ResearchExamine(c *gin.Context) {
|
||||
form := new(manageExamineForm)
|
||||
|
||||
@ -214,6 +211,70 @@ func (*Manage) ResearchDetail(c *gin.Context) {
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) Laboratory(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
Name string `json:"name" form:"name"`
|
||||
ExamineStatus int `json:"examine_status" form:"examine_status"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewLaboratory()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert(), form.Name, form.ExamineStatus, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) LaboratoryForm(c *gin.Context) {
|
||||
form := &struct {
|
||||
manageForm
|
||||
config.IdentityForLaboratory
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := manage.NewLaboratory()(api.GetSession()(c).(*session.Admin)).Form(form.bind(), &form.IdentityForLaboratory)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) LaboratorySelect(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
ResearchID uint64 `json:"research_id" form:"research_id"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewLaboratory()(api.GetSession()(c).(*session.Admin)).Select(form.Convert(), form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) LaboratoryDetail(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewLaboratory()(api.GetSession()(c).(*session.Admin)).Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) LaboratoryExamine(c *gin.Context) {
|
||||
form := new(manageExamineForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
form.Identity = config.TenantUserIdentityForLaboratory
|
||||
err := form.handle(api.GetSession()(c).(*session.Admin), nil)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) Agent(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
@ -121,7 +121,6 @@ func (c *Company) Form(params *BasicParams, other *config.IdentityForCompany) er
|
||||
}
|
||||
mManageCompany.Product = other.Product
|
||||
mManageCompany.Url = other.Url
|
||||
mManageCompany.License = other.FilterLicense()
|
||||
mManageCompany.SetIndustryAttribute(params.Industrys)
|
||||
mManageCompany.SetKeywordAttribute(params.Keywords)
|
||||
mManageCompany.SetDirectionAttribute(other.Directions)
|
||||
@ -136,6 +135,7 @@ func (c *Company) Form(params *BasicParams, other *config.IdentityForCompany) er
|
||||
// 查询手机号码是否在当前租户下是否已经注册了
|
||||
mManageCompany.Name = params.Name
|
||||
mManageCompany.Code = params.Code
|
||||
mManageCompany.License = other.FilterLicense()
|
||||
|
||||
if isExist, err := params.isExist(mManageCompany.ManageCompany, model2.NewWhere("tenant_id", params.TenantID),
|
||||
model2.NewWhere("code", params.Code)); err != nil {
|
||||
|
204
app/api/admin/controller/manage/laboratory.go
Normal file
204
app/api/admin/controller/manage/laboratory.go
Normal file
@ -0,0 +1,204 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Laboratory 实验室信息
|
||||
type Laboratory struct {
|
||||
*session.Admin
|
||||
}
|
||||
|
||||
type LaboratoryHandle func(session *session.Admin) *Laboratory
|
||||
|
||||
type (
|
||||
// LaboratoryInstance 实验室信息
|
||||
LaboratoryInstance struct {
|
||||
ID string `json:"id"`
|
||||
*model.ManageLaboratoryInfo
|
||||
Area string `json:"area"`
|
||||
}
|
||||
// LaboratorySelect 实验室筛选信息
|
||||
LaboratorySelect struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
// LaboratoryDetail 实验室详细信息
|
||||
LaboratoryDetail struct {
|
||||
ID string `json:"id"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
*model2.ManageLaboratory
|
||||
Industrys []string `json:"industrys"`
|
||||
Keywords []string `json:"keywords"`
|
||||
Researchs []string `json:"researchs"`
|
||||
Area string `json:"area"`
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *Laboratory) Instance(tenantID uint64, name string, examineStatus, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mManageLaboratory := model.NewManageLaboratory()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, model2.NewWhere("l.tenant_id", c.TenantID))
|
||||
}
|
||||
if tenantID > 0 {
|
||||
where = append(where, model2.NewWhere("l.tenant_id", tenantID))
|
||||
}
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("l.name", name))
|
||||
}
|
||||
if examineStatus > 0 {
|
||||
where = append(where, model2.NewWhere("l.examine_status", examineStatus))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mManageLaboratory.Laboratorys(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*LaboratoryInstance, 0)
|
||||
|
||||
for _, v := range out {
|
||||
v.Address = v.FormatBasic()
|
||||
|
||||
list = append(list, &LaboratoryInstance{
|
||||
ID: v.GetEncodeID(), ManageLaboratoryInfo: v, Area: (&model2.Area{
|
||||
Province: v.TenantProvince,
|
||||
City: v.TenantCity,
|
||||
}).FormatBasic(),
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Select 筛选信息
|
||||
func (c *Laboratory) Select(tenantID, researchID uint64) ([]*LaboratorySelect, error) {
|
||||
if tenantID <= 0 {
|
||||
tenantID = c.TenantID
|
||||
}
|
||||
mManageResearch := model.NewManageResearch()
|
||||
|
||||
out := make([]*model2.ManageResearch, 0)
|
||||
|
||||
where := []*model2.ModelWhereOrder{
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", tenantID)},
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("examine_status", model2.ExamineStatusForAgree)},
|
||||
}
|
||||
|
||||
if researchID > 0 {
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("research_id", tenantID)})
|
||||
}
|
||||
if err := model2.ScanFields(mManageResearch.ManageResearch, &out, []string{"id", "name"}, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*LaboratorySelect, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &LaboratorySelect{
|
||||
ID: v.GetEncodeID(),
|
||||
Name: v.Name,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Form 数据操作
|
||||
func (c *Laboratory) Form(params *BasicParams, other *config.IdentityForLaboratory) error {
|
||||
mManageLaboratory := model.NewManageLaboratory()
|
||||
|
||||
if params.ID > 0 {
|
||||
mManageLaboratory.ID = params.ID
|
||||
isExist, err := model2.FirstField(mManageLaboratory.ManageLaboratory, []string{"id", "name", "code", "tenant_id", "created_at"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,实验室信息不存在或已被删除")
|
||||
}
|
||||
if c.TenantID > 0 {
|
||||
if mManageLaboratory.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
} else {
|
||||
if mManageLaboratory.TenantID != params.TenantID {
|
||||
if isExist, err = params.isExist(mManageLaboratory.ManageLaboratory, model2.NewWhere("tenant_id", params.TenantID),
|
||||
model2.NewWhere("code", params.Code)); err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,当前站点下已存在同一实验室机构代码")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mManageLaboratory.TenantID = c.TenantID
|
||||
mManageLaboratory.ResearchID = other.ConvertResearch()
|
||||
mManageLaboratory.Image.Image = params.Image
|
||||
mManageLaboratory.Name = params.Name
|
||||
mManageLaboratory.Code = params.Code
|
||||
mManageLaboratory.Area = model2.Area{
|
||||
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
|
||||
}
|
||||
mManageLaboratory.Url = other.Url
|
||||
mManageLaboratory.SetIndustryAttribute(params.Industrys)
|
||||
mManageLaboratory.SetKeywordAttribute(params.Keywords)
|
||||
mManageLaboratory.SetResearchAttribute(other.Researchs)
|
||||
mManageLaboratory.Introduce = params.Introduce
|
||||
|
||||
if c.TenantID <= 0 {
|
||||
mManageLaboratory.TenantID = params.TenantID
|
||||
}
|
||||
if mManageLaboratory.ID > 0 {
|
||||
return model2.Updates(mManageLaboratory.ManageLaboratory, mManageLaboratory.ManageLaboratory)
|
||||
}
|
||||
mManageLaboratory.Name = params.Name
|
||||
mManageLaboratory.Code = params.Code
|
||||
|
||||
if isExist, err := params.isExist(mManageLaboratory.ManageLaboratory, model2.NewWhere("tenant_id", params.TenantID),
|
||||
model2.NewWhere("code", params.Code)); err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,当前站点下已存在同一实验室机构代码")
|
||||
}
|
||||
return model2.Create(mManageLaboratory.ManageLaboratory)
|
||||
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Laboratory) Detail(id uint64) (*LaboratoryDetail, error) {
|
||||
mManageLaboratory := model.NewManageLaboratory()
|
||||
|
||||
out, err := mManageLaboratory.Laboratory(id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if out.ManageLaboratory == nil {
|
||||
return nil, errors.New("操作错误,实验室信息不存在或已被删除")
|
||||
}
|
||||
return &LaboratoryDetail{
|
||||
ID: out.GetEncodeID(),
|
||||
TenantID: out.GetEncodeTenantID(),
|
||||
ManageLaboratory: out.ManageLaboratory,
|
||||
Industrys: out.GetIndustryAttribute(),
|
||||
Keywords: out.GetKeywordAttribute(),
|
||||
Researchs: out.GetResearchAttribute(),
|
||||
Area: out.FormatBasic(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewLaboratory() LaboratoryHandle {
|
||||
return func(session *session.Admin) *Laboratory {
|
||||
return &Laboratory{session}
|
||||
}
|
||||
}
|
@ -2,12 +2,14 @@ package manage
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Research 研究机构
|
||||
type Research struct {
|
||||
*session.Admin
|
||||
}
|
||||
@ -100,8 +102,63 @@ func (c *Research) Select(tenantID uint64) ([]*ResearchSelect, error) {
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (c *Research) Form() {
|
||||
// Form 数据操作
|
||||
func (c *Research) Form(params *BasicParams, other *config.IdentityForResearch) error {
|
||||
mManageResearch := model.NewManageResearch()
|
||||
|
||||
if params.ID > 0 {
|
||||
mManageResearch.ID = params.ID
|
||||
isExist, err := model2.FirstField(mManageResearch.ManageResearch, []string{"id", "name", "code", "tenant_id", "created_at"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,研究机构信息不存在或已被删除")
|
||||
}
|
||||
if c.TenantID > 0 {
|
||||
if mManageResearch.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
} else {
|
||||
if mManageResearch.TenantID != params.TenantID {
|
||||
if isExist, err = params.isExist(mManageResearch.ManageResearch, model2.NewWhere("tenant_id", params.TenantID),
|
||||
model2.NewWhere("code", params.Code)); err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,当前站点下已存在同一研究机构代码")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mManageResearch.TenantID = c.TenantID
|
||||
mManageResearch.Image.Image = params.Image
|
||||
mManageResearch.Name = params.Name
|
||||
mManageResearch.Code = params.Code
|
||||
mManageResearch.Area = model2.Area{
|
||||
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
|
||||
}
|
||||
mManageResearch.SetIndustryAttribute(params.Industrys)
|
||||
mManageResearch.SetKeywordAttribute(params.Keywords)
|
||||
mManageResearch.SetResearchAttribute(other.Researchs)
|
||||
mManageResearch.Introduce = params.Introduce
|
||||
|
||||
if c.TenantID <= 0 {
|
||||
mManageResearch.TenantID = params.TenantID
|
||||
}
|
||||
if mManageResearch.ID > 0 {
|
||||
return model2.Updates(mManageResearch.ManageResearch, mManageResearch.ManageResearch)
|
||||
}
|
||||
mManageResearch.Name = params.Name
|
||||
mManageResearch.Code = params.Code
|
||||
mManageResearch.License = other.FilterLicense()
|
||||
|
||||
if isExist, err := params.isExist(mManageResearch.ManageResearch, model2.NewWhere("tenant_id", params.TenantID),
|
||||
model2.NewWhere("code", params.Code)); err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,当前站点下已存在同一研究机构代码")
|
||||
}
|
||||
return model2.Create(mManageResearch.ManageResearch)
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
|
@ -46,7 +46,7 @@ func (m *ManageExpert) Expert(id uint64) (*ManageExpertDetail, error) {
|
||||
func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageExpertInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS e").
|
||||
Select("e.id", "e.name", "e.industry", "r.name AS research_name", "l.name AS laboratory_name",
|
||||
"e.province", "e.city", "e.address", "e.created_at",
|
||||
"e.province", "e.city", "e.created_at",
|
||||
"t.province AS tenant_province", "t.city AS tenant_city").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON e.research_id = r.id", model.NewManageResearch().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS l ON e.laboratory_id = l.id", model.NewManageLaboratory().TableName())).
|
||||
|
@ -1,11 +1,77 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ManageLaboratory struct {
|
||||
*model.ManageLaboratory
|
||||
}
|
||||
|
||||
type (
|
||||
// ManageLaboratoryInfo 实验室信息
|
||||
ManageLaboratoryInfo struct {
|
||||
model.Model
|
||||
Name string `json:"name"`
|
||||
Industry string `json:"industry"`
|
||||
ResearchName string `json:"research_name"`
|
||||
model.Image
|
||||
model.Area
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
TenantProvince string `json:"-"`
|
||||
TenantCity string `json:"-"`
|
||||
}
|
||||
// ManageLaboratoryDetail 实验室详细信息
|
||||
ManageLaboratoryDetail struct {
|
||||
*model.ManageLaboratory
|
||||
model.Area
|
||||
}
|
||||
)
|
||||
|
||||
// Laboratory 实验室信息
|
||||
func (m *ManageLaboratory) Laboratory(id uint64) (*ManageLaboratoryDetail, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS l").
|
||||
Select("l.*", "t.province", "t.city").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON l.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Where("l.id = ?", id)
|
||||
|
||||
out := new(ManageLaboratoryDetail)
|
||||
|
||||
err := db.Scan(out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
// Laboratorys 实验室信息
|
||||
func (m *ManageLaboratory) Laboratorys(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageLaboratoryInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS l").
|
||||
Select("l.id", "l.name", "l.industry", "l.name AS research_name", "l.image",
|
||||
"l.province", "l.city", "l.created_at",
|
||||
"t.province AS tenant_province", "t.city AS tenant_city").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON l.research_id = r.id", model.NewManageResearch().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t ON l.tenant_id = t.id", model.NewSysTenant().TableName())).
|
||||
Where("e.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*ManageLaboratoryInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := db.Order("l.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewManageLaboratory() *ManageLaboratory {
|
||||
return &ManageLaboratory{model.NewManageLaboratory()}
|
||||
}
|
||||
|
@ -297,10 +297,16 @@ func registerAdminAPI(app *gin.Engine) {
|
||||
manage.POST("/expert/examine", _api.ExpertExamine)
|
||||
manage.POST("/research", _api.Research)
|
||||
manage.POST("/research/select", _api.ResearchSelect)
|
||||
//manage.POST("/research/add", _api.ResearchForm)
|
||||
//manage.POST("/research/edit", _api.ResearchForm)
|
||||
manage.POST("/research/add", _api.ResearchForm)
|
||||
manage.POST("/research/edit", _api.ResearchForm)
|
||||
manage.POST("/research/detail", _api.ResearchDetail)
|
||||
manage.POST("/research/examine", _api.ResearchExamine)
|
||||
manage.POST("/laboratory", _api.Laboratory)
|
||||
manage.POST("/laboratory/select", _api.LaboratorySelect)
|
||||
manage.POST("/laboratory/add", _api.LaboratoryForm)
|
||||
manage.POST("/laboratory/edit", _api.LaboratoryForm)
|
||||
manage.POST("/laboratory/detail", _api.LaboratoryDetail)
|
||||
manage.POST("/laboratory/examine", _api.LaboratoryExamine)
|
||||
}
|
||||
// Service 服务管理
|
||||
service := v1.Group("/service")
|
||||
|
Reference in New Issue
Block a user