feat:完善信息
This commit is contained in:
@ -91,7 +91,7 @@ func (c *Agent) Instance(tenantID uint64, name string, status int, page, pageSiz
|
||||
|
||||
count := utils.StringToInt(objs[1])
|
||||
|
||||
if model2.TechnologyDemandServiceStatus(utils.StringToInt(objs[0])) == model2.TechnologyDemandServiceStatusForComplete {
|
||||
if model2.TechnologyDemandServiceStatus(utils.StringToInt(objs[0])) == model2.TechnologyDemandServiceStatusForClosedQuestions {
|
||||
demand.Complete = count
|
||||
}
|
||||
demand.Total += count
|
||||
|
@ -439,6 +439,44 @@ func (a *Technology) DemandDelete(c *gin.Context) {
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) DemandService(c *gin.Context) {
|
||||
form := &struct {
|
||||
Title string `json:"title" form:"status"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology2.NewDemandService()(api.GetSession()(c).(*session.Enterprise)).Instance(form.Title, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Technology) DemandServiceDetail(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology2.NewDemandService()(api.GetSession()(c).(*session.Enterprise)).Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Technology) DemandServiceHandle(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
Config string `json:"config" form:"config"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology2.NewDemandService()(api.GetSession()(c).(*session.Enterprise)).Handle(form.Convert(), form.Status, form.Config)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Technology) Topic(c *gin.Context) {
|
||||
form := &struct {
|
||||
Status int `json:"status" form:"status"`
|
||||
|
@ -5,8 +5,10 @@ import (
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -177,6 +179,65 @@ func (c *Demand) Delete(id uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Progress 进度信息
|
||||
func (c *Demand) Progress(demandID uint64) {
|
||||
mTechnologyDemandService := model.NewTechnologyDemandService()
|
||||
|
||||
model2.FirstWhere(mTechnologyDemandService.TechnologyDemandService,
|
||||
model2.NewWhere("demand_id", demandID))
|
||||
}
|
||||
|
||||
// ProgressLaunch 进度发起
|
||||
func (c *Demand) ProgressLaunch(demandID uint64, status int, config string) error {
|
||||
// TODO:缺少发起判断
|
||||
// 查询当前进度
|
||||
mTechnologyDemandService := model.NewTechnologyDemandService()
|
||||
|
||||
isExist, err := model2.FirstWhere(mTechnologyDemandService.TechnologyDemandService,
|
||||
model2.NewWhere("demand_id", demandID))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mTechnologyDemandService.UID = c.UID
|
||||
mTechnologyDemandService.DemandID = demandID
|
||||
mTechnologyDemandService.Progress = model2.TechnologyDemandServiceProgressKindForMemorandum
|
||||
|
||||
if err = model2.Create(mTechnologyDemandService.TechnologyDemandService, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mTechnologyDemandServiceProgress := model.NewTechnologyDemandServiceProgress()
|
||||
mTechnologyDemandServiceProgress.ServiceID = mTechnologyDemandService.ID
|
||||
mTechnologyDemandServiceProgress.Progress = model2.TechnologyDemandServiceProgressKindForMemorandum
|
||||
mTechnologyDemandServiceProgress.Config = config
|
||||
return model2.Create(mTechnologyDemandServiceProgress.TechnologyDemandServiceProgress, tx)
|
||||
})
|
||||
}
|
||||
if mTechnologyDemandService.Status != model2.TechnologyDemandServiceStatusForOngoing {
|
||||
return errors.New("操作错误,当前状态不可处理")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
// 下一流程
|
||||
mTechnologyDemandService.Progress = mTechnologyDemandService.NextProgress()
|
||||
|
||||
if mTechnologyDemandService.Progress == model2.TechnologyDemandServiceProgressKindForComplete {
|
||||
if status <= 0 {
|
||||
return errors.New("操作错误,请确认结题状态")
|
||||
}
|
||||
mTechnologyDemandService.Status = model2.TechnologyDemandServiceStatus(status)
|
||||
}
|
||||
if err = model2.Updates(mTechnologyDemandService.TechnologyDemandService, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mTechnologyDemandServiceProgress := model.NewTechnologyDemandServiceProgress()
|
||||
mTechnologyDemandServiceProgress.ServiceID = mTechnologyDemandService.ID
|
||||
mTechnologyDemandServiceProgress.Progress = mTechnologyDemandService.Progress
|
||||
mTechnologyDemandServiceProgress.Config = config
|
||||
return model2.Create(mTechnologyDemandServiceProgress.TechnologyDemandServiceProgress, tx)
|
||||
})
|
||||
}
|
||||
|
||||
func NewDemand() DemandHandle {
|
||||
return func(session *session.Enterprise, tenantID uint64) *Demand {
|
||||
return &Demand{Enterprise: session, tenantID: tenantID}
|
||||
|
152
app/api/enterprise/controller/technology/demand_service.go
Normal file
152
app/api/enterprise/controller/technology/demand_service.go
Normal file
@ -0,0 +1,152 @@
|
||||
package technology
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DemandService struct {
|
||||
*session.Enterprise
|
||||
}
|
||||
|
||||
type DemandServiceHandle func(session *session.Enterprise) *DemandService
|
||||
|
||||
type (
|
||||
// DemandServiceInstance 需求服务信息
|
||||
DemandServiceInstance struct {
|
||||
ID string `json:"id"`
|
||||
*model.TechnologyDemandServiceInfo
|
||||
}
|
||||
// DemandServiceDetail 需求服务详细信息
|
||||
DemandServiceDetail struct {
|
||||
ID string `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Progress []*DemandServiceProgress `json:"progress"`
|
||||
}
|
||||
// DemandServiceProgress 需求服务进度信息
|
||||
DemandServiceProgress struct {
|
||||
ID string `json:"id"`
|
||||
Progress model2.TechnologyDemandServiceProgressKind `json:"progress"`
|
||||
Config interface{} `json:"config"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *DemandService) Instance(title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mTechnologyDemandService := model.NewTechnologyDemandService()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("d.title", title))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mTechnologyDemandService.Services(page, pageSize, &count)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*DemandServiceInstance, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &DemandServiceInstance{
|
||||
ID: v.GetEncodeID(),
|
||||
TechnologyDemandServiceInfo: v,
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *DemandService) Detail(id uint64) (*DemandServiceDetail, error) {
|
||||
mTechnologyDemandService := model.NewTechnologyDemandService()
|
||||
mTechnologyDemandService.ID = id
|
||||
|
||||
isExist, err := model2.First(mTechnologyDemandService.TechnologyDemandService)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,需求服务信息不存在")
|
||||
}
|
||||
mTechnologyDemandServiceProgress := model.NewTechnologyDemandServiceProgress()
|
||||
|
||||
out := make([]*model2.TechnologyDemandServiceProgress, 0)
|
||||
|
||||
if err = model2.ScanFields(mTechnologyDemandServiceProgress.TechnologyDemandServiceProgress, &out, []string{"id", "progress", "config", "created_at"},
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("service_id", id),
|
||||
Order: model2.NewOrder("progress", model2.OrderModeToAsc),
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
progress := make([]*DemandServiceProgress, 0)
|
||||
|
||||
for _, v := range out {
|
||||
progress = append(progress, &DemandServiceProgress{
|
||||
ID: v.GetEncodeID(),
|
||||
Progress: v.Progress,
|
||||
Config: v.Config,
|
||||
CreatedAt: v.CreatedAt,
|
||||
})
|
||||
}
|
||||
return &DemandServiceDetail{
|
||||
ID: mTechnologyDemandService.GetEncodeID(),
|
||||
CreatedAt: mTechnologyDemandService.CreatedAt,
|
||||
Progress: progress,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Handle 处理操作
|
||||
func (c *DemandService) Handle(id uint64, status int, config string) error {
|
||||
// 查询当前进度
|
||||
mTechnologyDemandService := model.NewTechnologyDemandService()
|
||||
mTechnologyDemandService.ID = id
|
||||
|
||||
isExist, err := model2.First(mTechnologyDemandService.TechnologyDemandService)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,需求服务信息不存在")
|
||||
}
|
||||
if mTechnologyDemandService.UID != c.UID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
if mTechnologyDemandService.Status != model2.TechnologyDemandServiceStatusForOngoing {
|
||||
return errors.New("操作错误,当前状态不可处理")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
// 下一流程
|
||||
mTechnologyDemandService.Progress = mTechnologyDemandService.NextProgress()
|
||||
|
||||
if mTechnologyDemandService.Progress == model2.TechnologyDemandServiceProgressKindForComplete {
|
||||
if status <= 0 {
|
||||
return errors.New("操作错误,请确认结题状态")
|
||||
}
|
||||
mTechnologyDemandService.Status = model2.TechnologyDemandServiceStatus(status)
|
||||
}
|
||||
if err = model2.Updates(mTechnologyDemandService.TechnologyDemandService, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mTechnologyDemandServiceProgress := model.NewTechnologyDemandServiceProgress()
|
||||
mTechnologyDemandServiceProgress.ServiceID = mTechnologyDemandService.ID
|
||||
mTechnologyDemandServiceProgress.Progress = mTechnologyDemandService.Progress
|
||||
mTechnologyDemandServiceProgress.Config = config
|
||||
return model2.Create(mTechnologyDemandServiceProgress.TechnologyDemandServiceProgress, tx)
|
||||
})
|
||||
}
|
||||
|
||||
func NewDemandService() DemandServiceHandle {
|
||||
return func(session *session.Enterprise) *DemandService {
|
||||
return &DemandService{session}
|
||||
}
|
||||
}
|
45
app/api/enterprise/model/technology_demand_service.go
Normal file
45
app/api/enterprise/model/technology_demand_service.go
Normal file
@ -0,0 +1,45 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// TechnologyDemandService 技术需求进度模型
|
||||
type TechnologyDemandService struct {
|
||||
*model.TechnologyDemandService
|
||||
}
|
||||
|
||||
// TechnologyDemandServiceInfo 技术需求进度信息
|
||||
type TechnologyDemandServiceInfo struct {
|
||||
*model.TechnologyDemandService
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
// Services 服务信息
|
||||
func (m *TechnologyDemandService) Services(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyDemandServiceInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS s").
|
||||
Select("s.*", "d.title").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS d ON s.demand_id = d.id", model.NewTechnologyDemand().TableName()))
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*TechnologyDemandServiceInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := db.Order("s.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewTechnologyDemandService() *TechnologyDemandService {
|
||||
return &TechnologyDemandService{model.NewTechnologyDemandService()}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
// TechnologyDemandServiceProgress 技术需求进度数据模型
|
||||
type TechnologyDemandServiceProgress struct {
|
||||
*model.TechnologyDemandServiceProgress
|
||||
}
|
||||
|
||||
func NewTechnologyDemandServiceProgress() *TechnologyDemandServiceProgress {
|
||||
return &TechnologyDemandServiceProgress{model.NewTechnologyDemandServiceProgress()}
|
||||
}
|
@ -6,7 +6,7 @@ type TechnologyDemandService struct {
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
DemandID uint64 `gorm:"column:demand_id;type:int(11);default:0;comment:需求ID" json:"-"`
|
||||
Progress TechnologyDemandServiceProgressKind `gorm:"column:progress;type:tinyint(1);default:0;comment:进度类型" json:"progress"`
|
||||
Status int `gorm:"column:status;type:tinyint(1);default:0;comment:进度状态(0:进行中,1:已完成)" json:"status"`
|
||||
Status TechnologyDemandServiceStatus `gorm:"column:status;type:tinyint(1);default:0;comment:进度状态(0:进行中,1:已结题,2:未结题)" json:"status"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
@ -14,19 +14,41 @@ type TechnologyDemandService struct {
|
||||
// TechnologyDemandServiceProgressKind 技术需求服务进度类型
|
||||
type TechnologyDemandServiceProgressKind int
|
||||
|
||||
const (
|
||||
// TechnologyDemandServiceProgressKindForMemorandum 合作备忘录
|
||||
TechnologyDemandServiceProgressKindForMemorandum TechnologyDemandServiceProgressKind = iota + 101
|
||||
// TechnologyDemandServiceProgressKindForConfirmation 确认解决方案
|
||||
TechnologyDemandServiceProgressKindForConfirmation
|
||||
// TechnologyDemandServiceProgressKindForSign 签署合同
|
||||
TechnologyDemandServiceProgressKindForSign
|
||||
// TechnologyDemandServiceProgressKindForComplete 流程结束
|
||||
TechnologyDemandServiceProgressKindForComplete
|
||||
)
|
||||
|
||||
type TechnologyDemandServiceStatus int
|
||||
|
||||
const (
|
||||
// TechnologyDemandServiceStatusForOngoing 进行中
|
||||
TechnologyDemandServiceStatusForOngoing TechnologyDemandServiceStatus = iota
|
||||
// TechnologyDemandServiceStatusForComplete 已完成
|
||||
TechnologyDemandServiceStatusForComplete
|
||||
// TechnologyDemandServiceStatusForClosedQuestions 已结题
|
||||
TechnologyDemandServiceStatusForClosedQuestions
|
||||
// TechnologyDemandServiceStatusForOpenQuestions 未结题
|
||||
TechnologyDemandServiceStatusForOpenQuestions
|
||||
)
|
||||
|
||||
func (m *TechnologyDemandService) TableName() string {
|
||||
return "technology_demand_service"
|
||||
}
|
||||
|
||||
func (m *TechnologyDemandService) NextProgress() TechnologyDemandServiceProgressKind {
|
||||
if m.Progress == TechnologyDemandServiceProgressKindForMemorandum {
|
||||
return TechnologyDemandServiceProgressKindForConfirmation
|
||||
} else if m.Progress == TechnologyDemandServiceProgressKindForConfirmation {
|
||||
return TechnologyDemandServiceProgressKindForSign
|
||||
}
|
||||
return TechnologyDemandServiceProgressKindForComplete
|
||||
}
|
||||
|
||||
func NewTechnologyDemandService() *TechnologyDemandService {
|
||||
return &TechnologyDemandService{}
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ package model
|
||||
// TechnologyDemandServiceProgress 技术需求服务进度信息
|
||||
type TechnologyDemandServiceProgress struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
Progress TechnologyDemandServiceProgressKind `gorm:"column:progress;type:tinyint(1);default:0;comment:进度类型" json:"progress"`
|
||||
Config string `gorm:"column:config;type:text;comment:详细信息" json:"config"`
|
||||
ServiceID uint64 `gorm:"column:service_id;type:int(11);default:服务ID;comment:用户uuid" json:"-"`
|
||||
Progress TechnologyDemandServiceProgressKind `gorm:"column:progress;type:tinyint(1);default:0;comment:进度类型" json:"progress"`
|
||||
Config string `gorm:"column:config;type:text;comment:详细信息" json:"config"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
Reference in New Issue
Block a user