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 (
technology2 "SciencesServer/app/api/enterprise/controller/technology"
"SciencesServer/app/basic/api"
"SciencesServer/app/basic/config"
"SciencesServer/app/session"
config2 "SciencesServer/config"
"github.com/gin-gonic/gin"
@ -61,21 +60,20 @@ type (
}
// demandForm 需求参数
demandForm struct {
Title string `json:"title" form:"title" binding:"required"`
Introduce string `json:"introduce" form:"introduce" binding:"required"`
Name string `json:"name" form:"name" binding:"required"`
Mobile string `json:"mobile" form:"mobile" binding:"required"`
Deadline string `json:"deadline" form:"deadline" binding:"required"`
Industry []string `json:"industry" form:"industry" binding:"required"`
Kinds []string `json:"kinds" form:"kinds" binding:"required"`
config.Area
Title string `json:"title" form:"title" binding:"required"`
Introduce string `json:"introduce" form:"introduce" binding:"required"`
Name string `json:"name" form:"name" binding:"required"`
Mobile string `json:"mobile" form:"mobile" binding:"required"`
Deadline string `json:"deadline" form:"deadline" binding:"required"`
Industry []string `json:"industry" form:"industry" binding:"required"`
Kinds []string `json:"kinds" form:"kinds" binding:"required"`
Budget float64 `json:"budget" form:"budget"`
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"` // 基础
DemandExpect string `json:"demand_expect" form:"demand_expect"` // 预期
DemandBenefit string `json:"demand_benefit" form:"demand_benefit"` // 效益
Status int `json:"status" form:"status"`
IsSubmit int `json:"is_submit" form:"is_submit"`
}
// topicForm 课题参数
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)).
Form(&technology2.DemandParams{
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,
Expect: form.Expect, Demand: struct {
Basic string `json:"basic"`
Expect string `json:"expect"`
Benefit string `json:"benefit"`
}{Basic: form.DemandBasic, Expect: form.DemandExpect, Benefit: form.DemandBenefit}, Status: form.Status,
Industry: form.Industry, Kinds: form.Kinds, Budget: form.Budget, BudgetMode: form.BudgetMode,
Expects: form.Expects, Demand: struct {
Basic string
Expect string
Benefit string
}{Basic: form.DemandBasic, Expect: form.DemandExpect, Benefit: form.DemandBenefit}, IsSubmit: form.IsSubmit,
})
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)).
Form(&technology2.DemandParams{
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,
Expect: form.Expect, Demand: struct {
Basic string `json:"basic"`
Expect string `json:"expect"`
Benefit string `json:"benefit"`
}{Basic: form.DemandBasic, Expect: form.DemandExpect, Benefit: form.DemandBenefit}, Status: form.Status,
Industry: form.Industry, Kinds: form.Kinds, Budget: form.Budget, BudgetMode: form.BudgetMode,
Expects: form.Expects, Demand: struct {
Basic string
Expect string
Benefit string
}{Basic: form.DemandBasic, Expect: form.DemandExpect, Benefit: form.DemandBenefit}, IsSubmit: form.IsSubmit,
})
api.APIResponse(err)(c)
}

View File

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

View File

@ -2,6 +2,7 @@ package model
import (
"SciencesServer/utils"
"encoding/json"
"time"
)
@ -9,10 +10,9 @@ import (
type TechnologyDemand struct {
Model
Local
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"`
Kind string `gorm:"column:kind;type:varchar(50);default:null;comment:需求类别" json:"-"`
Area
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"`
Kind string `gorm:"column:kind;type:varchar(50);default:null;comment:需求类别" json:"-"`
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"`
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")
}
func (m *TechnologyDemand) SetKindAttribute(kinds []string) {
m.Kind = utils.AnyToJSON(kinds)
func (m *TechnologyDemand) SetKindAttribute(value []string) {
_bytes, _ := json.Marshal(value)
m.Kind = string(_bytes)
}
func (m *TechnologyDemand) GetKindAttribute() []string {
kinds := make([]string, 0)
_ = utils.FromJSON(m.Kind, &kinds)
return kinds
out := make([]string, 0)
_ = json.Unmarshal([]byte(m.Kind), &out)
return out
}
func (m *TechnologyDemand) SetIndustryAttribute(industrys []string) {
m.Industry = utils.AnyToJSON(industrys)
func (m *TechnologyDemand) SetIndustryAttribute(value []string) {
_bytes, _ := json.Marshal(value)
m.Industry = string(_bytes)
}
func (m *TechnologyDemand) GetIndustryAttribute() []string {
industrys := make([]string, 0)
_ = utils.FromJSON(m.Industry, &industrys)
return industrys
out := make([]string, 0)
_ = json.Unmarshal([]byte(m.Industry), &out)
return out
}
func (m *TechnologyDemand) SetOtherAttribute(other *TechnologyDemandOther) {
m.Other = utils.AnyToJSON(other)
func (m *TechnologyDemand) SetOtherAttribute(value *TechnologyDemandOther) {
_bytes, _ := json.Marshal(value)
m.Other = string(_bytes)
}
func (m *TechnologyDemand) GetOtherAttribute() *TechnologyDemandOther {