feat:完善信息,增加需求指派功能
This commit is contained in:
@ -291,6 +291,19 @@ func (*Manage) Agent(c *gin.Context) {
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) AgentSelect(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
Keyword string `json:"keyword" form:"keyword"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewAgent()(api.GetSession()(c).(*session.Admin)).Select(form.Convert(), form.Keyword)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) AgentDetail(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
|
@ -355,6 +355,19 @@ func (*Technology) DemandDelete(c *gin.Context) {
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) DemandAssign(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
AgentID string `json:"agent_id" form:"agent_id" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := technology.NewDemand()(api.GetSession()(c).(*session.Admin)).Assign(form.Convert(), (&api.IDStringForm{ID: form.AgentID}).Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Technology) Project(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
|
@ -42,6 +42,12 @@ type (
|
||||
*model2.ManageAgent
|
||||
IDImage *model2.ManageAgentIDImage `json:"id_image"`
|
||||
}
|
||||
// AgentSelect 经纪人筛选信息
|
||||
AgentSelect struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Mobile string `json:"mobile"`
|
||||
}
|
||||
// AgentParams 经纪人参数信息
|
||||
AgentParams struct {
|
||||
ID, TenantID uint64
|
||||
@ -105,6 +111,35 @@ func (c *Agent) Instance(tenantID uint64, name string, status int, page, pageSiz
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Select 筛选信息
|
||||
func (c *Agent) Select(tenantID uint64, keyword string) ([]*AgentSelect, error) {
|
||||
mManageAgent := model.NewManageAgent()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if tenantID > 0 {
|
||||
where = append(where, model2.NewWhere("tenant_id", tenantID))
|
||||
}
|
||||
if keyword != "" {
|
||||
where = append(where, model2.NewWhereValue("(name LIKE '%"+keyword+"%') OR (mobile LIKE '%"+keyword+"%')"))
|
||||
}
|
||||
out, err := mManageAgent.Agent(where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*AgentSelect, len(out))
|
||||
|
||||
for k, v := range out {
|
||||
list[k] = &AgentSelect{
|
||||
ID: v.GetEncodeID(),
|
||||
Name: v.Name,
|
||||
Mobile: v.Mobile,
|
||||
}
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Agent) Detail(id uint64) (*AgentDetail, error) {
|
||||
mManageAgent := model.NewManageAgent()
|
||||
|
@ -123,6 +123,36 @@ func (c *Demand) Delete(id uint64) error {
|
||||
return model2.Delete(mTechnologyDemand.TechnologyDemand)
|
||||
}
|
||||
|
||||
// Assign 指派经纪人
|
||||
func (c *Demand) Assign(id, agentID uint64) error {
|
||||
mTechnologyDemand := model.NewTechnologyDemand()
|
||||
mTechnologyDemand.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mTechnologyDemand.TechnologyDemand, []string{"id", "tenant_id"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,需求信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mTechnologyDemand.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
// 查询该需求是否已经指派
|
||||
mTechnologyDemandService := model.NewTechnologyDemandService()
|
||||
|
||||
var count int64
|
||||
|
||||
if err = model2.Count(mTechnologyDemandService.TechnologyDemandService, &count, model2.NewWhere("demand_id", id)); err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("操作错误,该需求信息已指派,请勿重复指派")
|
||||
}
|
||||
mTechnologyDemandService.DemandID = id
|
||||
mTechnologyDemandService.AgentID = agentID
|
||||
|
||||
return model2.Create(mTechnologyDemandService.TechnologyDemandService)
|
||||
}
|
||||
|
||||
func NewDemand() DemandHandle {
|
||||
return func(session *session.Admin) *Demand {
|
||||
return &Demand{session}
|
||||
|
@ -16,6 +16,27 @@ type ManageAgentInfo struct {
|
||||
model.Area
|
||||
}
|
||||
|
||||
func (m *ManageAgent) Agent(where ...*model.ModelWhere) ([]*model.ManageAgent, error) {
|
||||
db := orm.GetDB().Table(m.TableName()).
|
||||
Select("id", "name", "mobile")
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
if v.Condition == "" {
|
||||
db.Where(v.Value)
|
||||
continue
|
||||
}
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*model.ManageAgent, 0)
|
||||
|
||||
if err := db.Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Agents 经纪人信息
|
||||
func (m *ManageAgent) Agents(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*ManageAgentInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS a").
|
||||
|
11
app/api/admin/model/technology_demand_service.go
Normal file
11
app/api/admin/model/technology_demand_service.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type TechnologyDemandService struct {
|
||||
*model.TechnologyDemandService
|
||||
}
|
||||
|
||||
func NewTechnologyDemandService() *TechnologyDemandService {
|
||||
return &TechnologyDemandService{model.NewTechnologyDemandService()}
|
||||
}
|
@ -5,10 +5,8 @@ import (
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -179,65 +177,6 @@ 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}
|
||||
|
@ -41,18 +41,28 @@ type (
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *DemandService) Instance(title string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mUserAgent := model.NewUserAgent()
|
||||
|
||||
isExist, err := model2.FirstField(mUserAgent.UserAgent, []string{"id", "agent_id"}, model2.NewWhere("uid", c.UID))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,未知的身份信息")
|
||||
}
|
||||
// 查询用户经纪人身份信息
|
||||
mTechnologyDemandService := model.NewTechnologyDemandService()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
where := []*model2.ModelWhere{model2.NewWhere("d.agent_id", mUserAgent.AgentID)}
|
||||
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("d.title", title))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mTechnologyDemandService.Services(page, pageSize, &count)
|
||||
out := make([]*model.TechnologyDemandServiceInfo, 0)
|
||||
|
||||
if err != nil {
|
||||
if out, err = mTechnologyDemandService.Services(page, pageSize, &count); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*DemandServiceInstance, 0)
|
||||
@ -76,7 +86,7 @@ func (c *DemandService) Detail(id uint64) (*DemandServiceDetail, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,需求服务信息不存在")
|
||||
return nil, errors.New("操作错误,需求服务信息不存在或已被删除")
|
||||
}
|
||||
mTechnologyDemandServiceProgress := model.NewTechnologyDemandServiceProgress()
|
||||
|
||||
@ -118,9 +128,15 @@ func (c *DemandService) Handle(id uint64, status int, config string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,需求服务信息不存在")
|
||||
return errors.New("操作错误,需求服务信息不存在或已被删除")
|
||||
}
|
||||
if mTechnologyDemandService.UID != c.UID {
|
||||
mUserAgent := model.NewUserAgent()
|
||||
|
||||
if isExist, err = model2.FirstField(mUserAgent.UserAgent, []string{"id", "agent_id"}, model2.NewWhere("uid", c.UID)); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,未知的身份信息")
|
||||
} else if mUserAgent.AgentID != mTechnologyDemandService.AgentID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
if mTechnologyDemandService.Status != model2.TechnologyDemandServiceStatusForOngoing {
|
||||
@ -140,6 +156,7 @@ func (c *DemandService) Handle(id uint64, status int, config string) error {
|
||||
return err
|
||||
}
|
||||
mTechnologyDemandServiceProgress := model.NewTechnologyDemandServiceProgress()
|
||||
mTechnologyDemandServiceProgress.UID = c.UID
|
||||
mTechnologyDemandServiceProgress.ServiceID = mTechnologyDemandService.ID
|
||||
mTechnologyDemandServiceProgress.Progress = mTechnologyDemandService.Progress
|
||||
mTechnologyDemandServiceProgress.Config = config
|
||||
@ -147,6 +164,21 @@ func (c *DemandService) Handle(id uint64, status int, config string) error {
|
||||
})
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *DemandService) Delete(id uint64) error {
|
||||
mTechnologyDemandService := model.NewTechnologyDemandService()
|
||||
mTechnologyDemandService.ID = id
|
||||
|
||||
isExist, err := model2.First(mTechnologyDemandService.TechnologyDemandService)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,需求服务信息不存在或已被删除")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewDemandService() DemandServiceHandle {
|
||||
return func(session *session.Enterprise) *DemandService {
|
||||
return &DemandService{session}
|
||||
|
18
app/common/model/manage_company_service.go
Normal file
18
app/common/model/manage_company_service.go
Normal file
@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
// ManageCompanyService 公司企业服务数据模型
|
||||
type ManageCompanyService struct {
|
||||
Model
|
||||
CompanyID uint64
|
||||
AgentID uint64
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *ManageCompanyService) TableName() string {
|
||||
return "manage_company_service"
|
||||
}
|
||||
|
||||
func NewManageCompanyService() *ManageCompanyService {
|
||||
return &ManageCompanyService{}
|
||||
}
|
@ -3,7 +3,7 @@ package model
|
||||
// TechnologyDemandService 技术需求服务信息
|
||||
type TechnologyDemandService struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
AgentID uint64 `gorm:"column:agent_id;type:int(11);default:0;comment:经纪人模型ID" 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 TechnologyDemandServiceStatus `gorm:"column:status;type:tinyint(1);default:0;comment:进度状态(0:进行中,1:已结题,2:未结题)" json:"status"`
|
||||
|
@ -3,6 +3,8 @@ package model
|
||||
// TechnologyDemandServiceProgress 技术需求服务进度信息
|
||||
type TechnologyDemandServiceProgress struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
|
||||
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"`
|
||||
|
Reference in New Issue
Block a user