feat:修改技术文档需求数据模块

This commit is contained in:
henry
2021-11-30 10:10:25 +08:00
parent a441d1f2f1
commit c6f0129e4b
3 changed files with 56 additions and 58 deletions

View File

@ -3,7 +3,6 @@ package api
import ( import (
technology2 "SciencesServer/app/api/enterprise/controller/technology" technology2 "SciencesServer/app/api/enterprise/controller/technology"
"SciencesServer/app/basic/api" "SciencesServer/app/basic/api"
"SciencesServer/app/basic/config"
"SciencesServer/app/session" "SciencesServer/app/session"
config2 "SciencesServer/config" config2 "SciencesServer/config"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -61,21 +60,20 @@ type (
} }
// demandForm 需求参数 // demandForm 需求参数
demandForm struct { demandForm struct {
Title string `json:"title" form:"title" binding:"required"` Title string `json:"title" form:"title" binding:"required"`
Introduce string `json:"introduce" form:"introduce" binding:"required"` Introduce string `json:"introduce" form:"introduce" binding:"required"`
Name string `json:"name" form:"name" binding:"required"` Name string `json:"name" form:"name" binding:"required"`
Mobile string `json:"mobile" form:"mobile" binding:"required"` Mobile string `json:"mobile" form:"mobile" binding:"required"`
Deadline string `json:"deadline" form:"deadline" binding:"required"` Deadline string `json:"deadline" form:"deadline" binding:"required"`
Industry []string `json:"industry" form:"industry" binding:"required"` Industry []string `json:"industry" form:"industry" binding:"required"`
Kinds []string `json:"kinds" form:"kinds" binding:"required"` Kinds []string `json:"kinds" form:"kinds" binding:"required"`
config.Area
Budget float64 `json:"budget" form:"budget"` Budget float64 `json:"budget" form:"budget"`
BudgetMode int `json:"budget_mode" form:"budget_mode"` BudgetMode int `json:"budget_mode" form:"budget_mode"`
Expect []string `json:"expect" form:"expect"` // 期望合作的企业及模式 Expects []string `json:"expects" form:"expects"` // 期望合作的企业及模式
DemandBasic string `json:"demand_basic" form:"demand_basic"` // 基础 DemandBasic string `json:"demand_basic" form:"demand_basic"` // 基础
DemandExpect string `json:"demand_expect" form:"demand_expect"` // 预期 DemandExpect string `json:"demand_expect" form:"demand_expect"` // 预期
DemandBenefit string `json:"demand_benefit" form:"demand_benefit"` // 效益 DemandBenefit string `json:"demand_benefit" form:"demand_benefit"` // 效益
Status int `json:"status" form:"status"` IsSubmit int `json:"is_submit" form:"is_submit"`
} }
// topicForm 课题参数 // topicForm 课题参数
topicForm struct { topicForm struct {
@ -384,12 +382,12 @@ func (a *Technology) DemandAdd(c *gin.Context) {
err := technology2.NewDemand()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)). err := technology2.NewDemand()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
Form(&technology2.DemandParams{ Form(&technology2.DemandParams{
Title: form.Title, Introduce: form.Introduce, Name: form.Name, Mobile: form.Mobile, Deadline: form.Deadline, Title: form.Title, Introduce: form.Introduce, Name: form.Name, Mobile: form.Mobile, Deadline: form.Deadline,
Industry: form.Industry, Kinds: form.Kinds, Area: form.Area, Budget: form.Budget, BudgetMode: form.BudgetMode, Industry: form.Industry, Kinds: form.Kinds, Budget: form.Budget, BudgetMode: form.BudgetMode,
Expect: form.Expect, Demand: struct { Expects: form.Expects, Demand: struct {
Basic string `json:"basic"` Basic string
Expect string `json:"expect"` Expect string
Benefit string `json:"benefit"` Benefit string
}{Basic: form.DemandBasic, Expect: form.DemandExpect, Benefit: form.DemandBenefit}, Status: form.Status, }{Basic: form.DemandBasic, Expect: form.DemandExpect, Benefit: form.DemandBenefit}, IsSubmit: form.IsSubmit,
}) })
api.APIResponse(err)(c) api.APIResponse(err)(c)
} }
@ -406,12 +404,12 @@ func (a *Technology) DemandEdit(c *gin.Context) {
err := technology2.NewDemand()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)). err := technology2.NewDemand()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)).
Form(&technology2.DemandParams{ Form(&technology2.DemandParams{
ID: form.Convert(), Title: form.Title, Introduce: form.Introduce, Name: form.Name, Mobile: form.Mobile, Deadline: form.Deadline, ID: form.Convert(), Title: form.Title, Introduce: form.Introduce, Name: form.Name, Mobile: form.Mobile, Deadline: form.Deadline,
Industry: form.Industry, Kinds: form.Kinds, Area: form.Area, Budget: form.Budget, BudgetMode: form.BudgetMode, Industry: form.Industry, Kinds: form.Kinds, Budget: form.Budget, BudgetMode: form.BudgetMode,
Expect: form.Expect, Demand: struct { Expects: form.Expects, Demand: struct {
Basic string `json:"basic"` Basic string
Expect string `json:"expect"` Expect string
Benefit string `json:"benefit"` Benefit string
}{Basic: form.DemandBasic, Expect: form.DemandExpect, Benefit: form.DemandBenefit}, Status: form.Status, }{Basic: form.DemandBasic, Expect: form.DemandExpect, Benefit: form.DemandBenefit}, IsSubmit: form.IsSubmit,
}) })
api.APIResponse(err)(c) api.APIResponse(err)(c)
} }

View File

@ -3,7 +3,6 @@ package technology
import ( import (
"SciencesServer/app/api/enterprise/model" "SciencesServer/app/api/enterprise/model"
"SciencesServer/app/api/manage/controller" "SciencesServer/app/api/manage/controller"
"SciencesServer/app/basic/config"
model2 "SciencesServer/app/common/model" model2 "SciencesServer/app/common/model"
"SciencesServer/app/session" "SciencesServer/app/session"
"SciencesServer/utils" "SciencesServer/utils"
@ -45,16 +44,15 @@ type (
ID uint64 ID uint64
Title, Introduce, Name, Mobile, Deadline string Title, Introduce, Name, Mobile, Deadline string
Industry, Kinds []string Industry, Kinds []string
config.Area Budget float64
Budget float64 BudgetMode int
BudgetMode int Expects []string // 期望合作的企业及模式
Expect []string `json:"expect"` // 期望合作的企业及模式 Demand struct {
Demand struct { Basic string // 基础
Basic string `json:"basic"` // 基础 Expect string // 预期
Expect string `json:"expect"` // 预期 Benefit string // 效益
Benefit string `json:"benefit"` // 效益 } // 需求详细信息
} `json:"demand"` // 需求详细信息 IsSubmit int
Status int `json:"status"`
} }
) )
@ -113,7 +111,7 @@ func (c *Demand) Form(params *DemandParams) error {
if params.ID > 0 { if params.ID > 0 {
mTechnologyDemand.ID = params.ID mTechnologyDemand.ID = params.ID
isExist, err := model2.FirstField(mTechnologyDemand.TechnologyDemand, []string{"id", "uid", "status"}) isExist, err := model2.FirstField(mTechnologyDemand.TechnologyDemand, []string{"id", "uid", "status", "created_at"})
if err != nil { if err != nil {
return err return err
@ -129,20 +127,15 @@ func (c *Demand) Form(params *DemandParams) error {
mTechnologyDemand.Title = params.Title mTechnologyDemand.Title = params.Title
mTechnologyDemand.Name = params.Name mTechnologyDemand.Name = params.Name
mTechnologyDemand.Mobile = params.Mobile 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.Introduce = params.Introduce
mTechnologyDemand.SetKindAttribute(params.Kinds) mTechnologyDemand.SetKindAttribute(params.Kinds)
mTechnologyDemand.SetIndustryAttribute(params.Industry) mTechnologyDemand.SetIndustryAttribute(params.Industry)
mTechnologyDemand.Budget = params.Budget mTechnologyDemand.Budget = params.Budget
mTechnologyDemand.BudgetMode = model2.TechnologyDemandBudgetMode(params.BudgetMode) mTechnologyDemand.BudgetMode = model2.TechnologyDemandBudgetMode(params.BudgetMode)
mTechnologyDemand.Deadline = utils.DataTimeToDate(params.Deadline) mTechnologyDemand.Deadline = utils.DataTimeToDate(params.Deadline)
mTechnologyDemand.Status = model2.TechnologyDemandStatus(params.Status)
mTechnologyDemand.SetOtherAttribute(&model2.TechnologyDemandOther{ mTechnologyDemand.SetOtherAttribute(&model2.TechnologyDemandOther{
Expect: params.Expect, Expect: params.Expects,
Demand: struct { Demand: struct {
Basic string `json:"basic"` Basic string `json:"basic"`
Expect string `json:"expect"` Expect string `json:"expect"`
@ -152,11 +145,15 @@ func (c *Demand) Form(params *DemandParams) error {
}, },
}) })
if mTechnologyDemand.ID > 0 { if mTechnologyDemand.ID > 0 {
mTechnologyDemand.UpdatedAt = time.Now() mTechnologyDemand.Status = model2.TechnologyDemandStatusForExamining
return model2.Updates(mTechnologyDemand.TechnologyDemand, mTechnologyDemand.TechnologyDemand) return model2.Updates(mTechnologyDemand.TechnologyDemand, mTechnologyDemand.TechnologyDemand)
} }
mTechnologyDemand.UID = c.UID mTechnologyDemand.UID = c.UID
mTechnologyDemand.Local.Local = c.local mTechnologyDemand.Local.Local = c.local
if params.IsSubmit > 0 {
mTechnologyDemand.Status = model2.TechnologyDemandStatusForExamining
}
return model2.Create(mTechnologyDemand.TechnologyDemand) return model2.Create(mTechnologyDemand.TechnologyDemand)
} }

View File

@ -2,6 +2,7 @@ package model
import ( import (
"SciencesServer/utils" "SciencesServer/utils"
"encoding/json"
"time" "time"
) )
@ -9,10 +10,9 @@ import (
type TechnologyDemand struct { type TechnologyDemand struct {
Model Model
Local Local
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
Title string `gorm:"column:title;type:varchar(50);default:null;comment:需求名称" json:"title"` Title string `gorm:"column:title;type:varchar(50);default:null;comment:需求名称" json:"title"`
Kind string `gorm:"column:kind;type:varchar(50);default:null;comment:需求类别" json:"-"` Kind string `gorm:"column:kind;type:varchar(50);default:null;comment:需求类别" json:"-"`
Area
Name string `gorm:"column:name;type:varchar(30);default:null;comment:联系人" json:"name"` Name string `gorm:"column:name;type:varchar(30);default:null;comment:联系人" json:"name"`
Mobile string `gorm:"column:mobile;type:varchar(15);default:null;comment:联系方式" json:"mobile"` Mobile string `gorm:"column:mobile;type:varchar(15);default:null;comment:联系方式" json:"mobile"`
Industry string `gorm:"column:industry;type:varchar(255);comment:行业信息" json:"industry"` Industry string `gorm:"column:industry;type:varchar(255);comment:行业信息" json:"industry"`
@ -64,28 +64,31 @@ func (m *TechnologyDemand) TableName() string {
return m.NewTableName("technology_demand") return m.NewTableName("technology_demand")
} }
func (m *TechnologyDemand) SetKindAttribute(kinds []string) { func (m *TechnologyDemand) SetKindAttribute(value []string) {
m.Kind = utils.AnyToJSON(kinds) _bytes, _ := json.Marshal(value)
m.Kind = string(_bytes)
} }
func (m *TechnologyDemand) GetKindAttribute() []string { func (m *TechnologyDemand) GetKindAttribute() []string {
kinds := make([]string, 0) out := make([]string, 0)
_ = utils.FromJSON(m.Kind, &kinds) _ = json.Unmarshal([]byte(m.Kind), &out)
return kinds return out
} }
func (m *TechnologyDemand) SetIndustryAttribute(industrys []string) { func (m *TechnologyDemand) SetIndustryAttribute(value []string) {
m.Industry = utils.AnyToJSON(industrys) _bytes, _ := json.Marshal(value)
m.Industry = string(_bytes)
} }
func (m *TechnologyDemand) GetIndustryAttribute() []string { func (m *TechnologyDemand) GetIndustryAttribute() []string {
industrys := make([]string, 0) out := make([]string, 0)
_ = utils.FromJSON(m.Industry, &industrys) _ = json.Unmarshal([]byte(m.Industry), &out)
return industrys return out
} }
func (m *TechnologyDemand) SetOtherAttribute(other *TechnologyDemandOther) { func (m *TechnologyDemand) SetOtherAttribute(value *TechnologyDemandOther) {
m.Other = utils.AnyToJSON(other) _bytes, _ := json.Marshal(value)
m.Other = string(_bytes)
} }
func (m *TechnologyDemand) GetOtherAttribute() *TechnologyDemandOther { func (m *TechnologyDemand) GetOtherAttribute() *TechnologyDemandOther {