189 lines
6.3 KiB
Go
189 lines
6.3 KiB
Go
package technology
|
|
|
|
import (
|
|
"SciencesServer/app/api/enterprise/model"
|
|
"SciencesServer/app/api/manage/controller"
|
|
"SciencesServer/app/basic/config"
|
|
model2 "SciencesServer/app/common/model"
|
|
"SciencesServer/app/service"
|
|
"SciencesServer/utils"
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
// Demand 技术需求管理
|
|
type Demand struct {
|
|
*service.SessionEnterprise
|
|
local string
|
|
}
|
|
|
|
type DemandHandle func(enterprise *service.SessionEnterprise, local string) *Demand
|
|
|
|
type (
|
|
// DemandInfo 需求信息
|
|
DemandInfo struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Name string `json:"name"`
|
|
Mobile string `json:"mobile"`
|
|
Kinds []string `json:"kinds"`
|
|
Budget float64 `json:"budget"`
|
|
BudgetMode model2.TechnologyDemandBudgetMode `json:"budget_mode"`
|
|
Deadline time.Time `json:"deadline"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
// DemandDetailInfo 需求详细信息
|
|
DemandDetailInfo struct {
|
|
ID string `json:"id"`
|
|
*model2.TechnologyDemand
|
|
Kinds []string `json:"kinds"`
|
|
Industry []string `json:"industry"`
|
|
*model2.TechnologyDemandOther
|
|
}
|
|
// DemandParams 需求参数信息
|
|
DemandParams struct {
|
|
ID uint64
|
|
Title, Introduce, Name, Mobile, Deadline string
|
|
Industry, Kinds []string
|
|
config.Area
|
|
Budget float64
|
|
BudgetMode int
|
|
Expect []string `json:"expect"` // 期望合作的企业及模式
|
|
Demand struct {
|
|
Basic string `json:"basic"` // 基础
|
|
Expect string `json:"expect"` // 预期
|
|
Benefit string `json:"benefit"` // 效益
|
|
} `json:"demand"` // 需求详细信息
|
|
Status int `json:"status"`
|
|
}
|
|
)
|
|
|
|
// List 列表信息
|
|
func (c *Demand) List(status, page, pageSize int) (*controller.ReturnPages, error) {
|
|
mTechnologyDemand := model.NewTechnologyDemand()
|
|
|
|
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
|
|
Where: model2.NewWhere("uid", c.ManageUID),
|
|
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
|
}, &model2.ModelWhereOrder{
|
|
Where: model2.NewWhere("status", status),
|
|
}}
|
|
var count int64
|
|
|
|
out := make([]*model2.TechnologyDemand, 0)
|
|
|
|
if err := model2.PagesFields(mTechnologyDemand.TechnologyDemand, &out, []string{"id", "title", "kind", "name",
|
|
"mobile", "budget", "budget_mode", "deadline", "created_at"}, page, pageSize, &count, where...); err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]*DemandInfo, 0)
|
|
|
|
for _, v := range out {
|
|
list = append(list, &DemandInfo{
|
|
ID: v.GetEncodeID(), Title: v.Title, Name: v.Name, Mobile: v.Mobile, Budget: v.Budget, BudgetMode: v.BudgetMode,
|
|
Kinds: v.GetKindAttribute(), Deadline: v.Deadline, CreatedAt: v.CreatedAt,
|
|
})
|
|
}
|
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
|
}
|
|
|
|
// Detail 详细信息
|
|
func (c *Demand) Detail(id uint64) (*DemandDetailInfo, error) {
|
|
mTechnologyDemand := model.NewTechnologyDemand()
|
|
mTechnologyDemand.ID = id
|
|
|
|
isExist, err := model2.First(mTechnologyDemand.TechnologyDemand)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
} else if !isExist {
|
|
return nil, errors.New("操作错误,数据不存在")
|
|
}
|
|
return &DemandDetailInfo{
|
|
ID: mTechnologyDemand.GetEncodeID(), TechnologyDemand: mTechnologyDemand.TechnologyDemand,
|
|
Kinds: mTechnologyDemand.GetKindAttribute(), Industry: mTechnologyDemand.GetIndustryAttribute(),
|
|
TechnologyDemandOther: mTechnologyDemand.GetOtherAttribute(),
|
|
}, nil
|
|
}
|
|
|
|
// Form 数据操作
|
|
func (c *Demand) Form(params *DemandParams) error {
|
|
mTechnologyDemand := model.NewTechnologyDemand()
|
|
|
|
if params.ID > 0 {
|
|
mTechnologyDemand.ID = params.ID
|
|
|
|
isExist, err := model2.FirstField(mTechnologyDemand.TechnologyDemand, []string{"id", "uid", "status"})
|
|
|
|
if err != nil {
|
|
return err
|
|
} else if !isExist {
|
|
return errors.New("操作错误,数据不存在")
|
|
} else if mTechnologyDemand.UID != c.ManageUID {
|
|
return errors.New("无权限操作")
|
|
} else if mTechnologyDemand.Status != model2.TechnologyDemandStatusForRefuse &&
|
|
mTechnologyDemand.Status != model2.TechnologyDemandStatusForDraft {
|
|
return errors.New("操作错误,当前状态不允许修改")
|
|
}
|
|
}
|
|
mTechnologyDemand.Title = params.Title
|
|
mTechnologyDemand.Name = params.Name
|
|
mTechnologyDemand.Mobile = params.Mobile
|
|
mTechnologyDemand.Area = model2.Area{
|
|
Province: params.Area.Province, City: params.Area.City, District: params.Area.District,
|
|
Address: params.Area.Address,
|
|
}
|
|
mTechnologyDemand.Introduce = params.Introduce
|
|
mTechnologyDemand.SetKindAttribute(params.Kinds)
|
|
mTechnologyDemand.SetIndustryAttribute(params.Industry)
|
|
mTechnologyDemand.Budget = params.Budget
|
|
mTechnologyDemand.BudgetMode = model2.TechnologyDemandBudgetMode(params.BudgetMode)
|
|
mTechnologyDemand.Deadline = utils.DataTimeToDate(params.Deadline)
|
|
mTechnologyDemand.Status = model2.TechnologyDemandStatus(params.Status)
|
|
|
|
mTechnologyDemand.SetOtherAttribute(&model2.TechnologyDemandOther{
|
|
Expect: params.Expect,
|
|
Demand: struct {
|
|
Basic string `json:"basic"`
|
|
Expect string `json:"expect"`
|
|
Benefit string `json:"benefit"`
|
|
}{
|
|
Basic: params.Demand.Basic, Expect: params.Demand.Expect, Benefit: params.Demand.Benefit,
|
|
},
|
|
})
|
|
if mTechnologyDemand.ID > 0 {
|
|
mTechnologyDemand.UpdatedAt = time.Now()
|
|
return model2.Updates(mTechnologyDemand.TechnologyDemand, mTechnologyDemand.TechnologyDemand)
|
|
}
|
|
mTechnologyDemand.TenantID = c.TenantID
|
|
mTechnologyDemand.UID = c.ManageUID
|
|
mTechnologyDemand.Local.Local = c.local
|
|
return model2.Create(mTechnologyDemand.TechnologyDemand)
|
|
}
|
|
|
|
// Delete 删除操作
|
|
func (c *Demand) Delete(id uint64) error {
|
|
mTechnologyDemand := model.NewTechnologyDemand()
|
|
mTechnologyDemand.ID = id
|
|
|
|
isExist, err := model2.FirstField(mTechnologyDemand.TechnologyDemand, []string{"id", "uid", "status"})
|
|
|
|
if err != nil {
|
|
return err
|
|
} else if !isExist {
|
|
return errors.New("操作错误,数据不存在")
|
|
} else if mTechnologyDemand.UID != c.ManageUID {
|
|
return errors.New("无权限操作")
|
|
}
|
|
if err = model2.Delete(mTechnologyDemand.TechnologyDemand); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func NewDemand() DemandHandle {
|
|
return func(enterprise *service.SessionEnterprise, local string) *Demand {
|
|
return &Demand{SessionEnterprise: enterprise, local: local}
|
|
}
|
|
}
|