From e753e99fd825b71e83dcd723d5b4a7434d7cc6d5 Mon Sep 17 00:00:00 2001 From: henry Date: Fri, 22 Oct 2021 17:10:43 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=AE=8C=E5=96=84=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/enterprise/api/technology.go | 102 ++++++++++++++++++ .../enterprise/controller/technology/topic.go | 3 + app/common/model/technology_topic.go | 15 +++ config/system.go | 8 ++ lib/email.go | 20 ++-- lib/email_test.go | 23 ++-- 6 files changed, 150 insertions(+), 21 deletions(-) diff --git a/app/api/enterprise/api/technology.go b/app/api/enterprise/api/technology.go index 01c66fa..e02d67b 100644 --- a/app/api/enterprise/api/technology.go +++ b/app/api/enterprise/api/technology.go @@ -5,12 +5,33 @@ import ( "SciencesServer/app/basic/api" "SciencesServer/app/basic/config" "SciencesServer/app/service" + config2 "SciencesServer/config" "github.com/gin-gonic/gin" + "strings" ) type Technology struct{} type ( + // instanceForm 技术参数 + instanceForm struct { + PatentID uint64 `json:"patent_id" form:"patent_id" binding:"required"` + Territory uint64 `json:"territory" form:"territory"` + Title string `json:"title" form:"title" binding:"required"` + Company string `json:"company" form:"company" binding:"required"` + api.ImageForm + ProveImages string `json:"prove_images" form:"prove_images" binding:"required"` + Introduce string `json:"introduce" form:"introduce" binding:"required"` + Purpose string `json:"purpose" form:"purpose" binding:"required"` + Remark string `json:"remark" form:"remark"` + Maturity int `json:"maturity" form:"maturity"` + Prototype int `json:"prototype" form:"prototype"` + Source int `json:"source" form:"source"` + Transaction int `json:"transaction" form:"transaction"` + Status int `json:"status" form:"status"` + Products []string `json:"products" form:"products"` + Keywords []string `json:"keywords" form:"keywords"` + } // paperForm 论文参数 paperForm struct { Title string `json:"title" form:"title" binding:"required"` // 题目 @@ -70,6 +91,87 @@ type ( } ) +func (a *instanceForm) FilterProveImages() string { + return strings.Replace(a.ProveImages, config2.SettingInfo.Domain, "", -1) +} + +func (a *Technology) Instance(c *gin.Context) { + form := &struct { + Status int `json:"status" form:"status"` + api.PageForm + }{} + if err := api.Bind(form)(c); err != nil { + api.APIFailure(err.(error))(c) + return + } + data, err := technology2.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)). + List(form.Status, form.Page, form.PageSize) + api.APIResponse(err, data)(c) +} + +func (a *Technology) InstanceAdd(c *gin.Context) { + form := new(instanceForm) + + if err := api.Bind(form)(c); err != nil { + api.APIFailure(err.(error))(c) + return + } + err := technology2.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)). + Form(&technology2.InstanceParams{ + PatentID: form.PatentID, Territory: form.Territory, Title: form.Title, Company: form.Company, + Images: form.FilterImageURL(), ProveImages: form.FilterProveImages(), Introduce: form.Introduce, Purpose: form.Purpose, + Remark: form.Remark, Maturity: form.Maturity, Prototype: form.Prototype, Source: form.Source, + Transaction: form.Transaction, Status: form.Status, Products: form.Products, Keywords: form.Keywords, + }) + api.APIResponse(err)(c) +} + +func (a *Technology) InstanceEdit(c *gin.Context) { + form := &struct { + api.IDStringForm + instanceForm + }{} + if err := api.Bind(form)(c); err != nil { + api.APIFailure(err.(error))(c) + return + } + err := technology2.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)). + Form(&technology2.InstanceParams{ + ID: form.Convert(), + PatentID: form.PatentID, Territory: form.Territory, Title: form.Title, Company: form.Company, + Images: form.FilterImageURL(), ProveImages: form.FilterProveImages(), Introduce: form.Introduce, Purpose: form.Purpose, + Remark: form.Remark, Maturity: form.Maturity, Prototype: form.Prototype, Source: form.Source, + Transaction: form.Transaction, Status: form.Status, Products: form.Products, Keywords: form.Keywords, + }) + api.APIResponse(err)(c) +} + +func (a *Technology) InstanceShelf(c *gin.Context) { + form := &struct { + api.IDStringForm + Status int `json:"status" form:"status"` + }{} + if err := api.Bind(form)(c); err != nil { + api.APIFailure(err.(error))(c) + return + } + err := technology2.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)). + Shelf(form.Convert(), form.Status) + api.APIResponse(err)(c) +} + +func (a *Technology) InstanceDelete(c *gin.Context) { + form := new(api.IDStringForm) + + if err := api.Bind(form)(c); err != nil { + api.APIFailure(err.(error))(c) + return + } + err := technology2.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise), api.GetLocal()(c).(string)). + Delete(form.Convert()) + api.APIResponse(err)(c) +} + func (a *Technology) Paper(c *gin.Context) { form := &struct { Title string `json:"title" form:"title"` diff --git a/app/api/enterprise/controller/technology/topic.go b/app/api/enterprise/controller/technology/topic.go index 8fa2713..2b5a8bb 100644 --- a/app/api/enterprise/controller/technology/topic.go +++ b/app/api/enterprise/controller/technology/topic.go @@ -102,6 +102,9 @@ func (c *Topic) Form(params *TopicParams) error { return errors.New("操作错误,课题信息不存在") } else if mTechnologyTopic.UID != c.ManageUID { return errors.New("无权限操作") + } else if mTechnologyTopic.Status != model2.TechnologyTopicStatusForDraft && + mTechnologyTopic.Status != model2.TechnologyTopicStatusForRefuse { + return errors.New("操作错误,当前状态不允许修改") } } mTechnologyTopic.Title = params.Title diff --git a/app/common/model/technology_topic.go b/app/common/model/technology_topic.go index b1fedad..1683a1d 100644 --- a/app/common/model/technology_topic.go +++ b/app/common/model/technology_topic.go @@ -21,6 +21,7 @@ type TechnologyTopic struct { Kind TechnologyTopicKind `gorm:"column:kind;type:tinyint(1);default:0comment:类型" json:"kind"` BeginAt time.Time `gorm:"column:begin_at;type:datetime;not null;comment:开始时间" json:"begin_at"` FinishAt time.Time `gorm:"column:finish_at;type:datetime;not null;comment:结束时间" json:"finish_at"` + Status TechnologyTopicStatus `gorm:"column:status;type:tinyint(1);default:0;comment:状态" json:"status"` ModelDeleted ModelAt } @@ -44,6 +45,20 @@ const ( //TechnologyTopicKindFor ) +// TechnologyTopicStatus 技术课题状态 +type TechnologyTopicStatus int + +const ( + // TechnologyTopicStatusForDraft 草稿箱 + TechnologyTopicStatusForDraft TechnologyTopicStatus = iota + // TechnologyTopicStatusForExamining 审核中 + TechnologyTopicStatusForExamining + // TechnologyTopicStatusForAgree 审核通过 + TechnologyTopicStatusForAgree + // TechnologyTopicStatusForRefuse 审核拒绝 + TechnologyTopicStatusForRefuse +) + func (m *TechnologyTopic) TableName() string { return m.NewTableName("technology_topic") } diff --git a/config/system.go b/config/system.go index b66fd99..50e345c 100644 --- a/config/system.go +++ b/config/system.go @@ -20,6 +20,14 @@ const ( WechatForAppID string = "appid" ) +const ( + EmailForAlias string = "email_alias" // 邮件别名 + EmailForHost string = "email_host" // 邮件Host + EmailForPort string = "email_port" // 邮件端口地址 + EmailForUser string = "email_user" // 邮件用户 + EmailForPass string = "email_pass" // 邮件密码;定义邮箱服务器连接信息,如果是阿里邮箱 email_pass填密码,qq邮箱填授权码 +) + const ( UploadPath string = "upload_path" // 上传路径 UploadExt string = "upload_ext" // 上传文件限制 diff --git a/lib/email.go b/lib/email.go index 75189bd..f554a10 100644 --- a/lib/email.go +++ b/lib/email.go @@ -9,11 +9,15 @@ type Email struct { } type EmailOption struct { - User, Auth string // Auth:定义邮箱服务器连接信息,如果是阿里邮箱 Auth填密码,qq邮箱填授权码 - Host string - Port int + Alias, User, Pass string // Auth:定义邮箱服务器连接信息,如果是阿里邮箱 Pass填密码,qq邮箱填授权码 + Host string + Port int } +// EmailSendHandle 邮件发送处理 +// @objects:发送对象,多个邮件地址 +// @subject:邮件主题 +// @body:邮件正文 type EmailSendHandle func(objects []string, subject, body string) error func (this *Email) Init() { @@ -23,11 +27,11 @@ func (this *Email) Init() { func (this *Email) Send() EmailSendHandle { return func(objects []string, subject, body string) error { m := gomail.NewMessage() - m.SetHeader("From", "XD Game"+"<"+this.User+">") //这种方式可以添加别名,即“XD Game”, 也可以直接用m.SetHeader("From",mailConn["user"]) 读者可以自行实验下效果 - m.SetHeader("To", objects...) //发送给多个用户 - m.SetHeader("Subject", subject) //设置邮件主题 - m.SetBody("text/html", body) //设置邮件正文 - return gomail.NewDialer(this.Host, this.Port, this.User, this.Auth).DialAndSend(m) + m.SetHeader("From", m.FormatAddress(this.User, this.Alias)) + m.SetHeader("To", objects...) + m.SetHeader("Subject", subject) + m.SetBody("text/html", body) + return gomail.NewDialer(this.Host, this.Port, this.User, this.Pass).DialAndSend(m) } } diff --git a/lib/email_test.go b/lib/email_test.go index 54f5711..d9f475e 100644 --- a/lib/email_test.go +++ b/lib/email_test.go @@ -10,24 +10,21 @@ import ( func SendMail(mailTo []string, subject string, body string) error { //定义邮箱服务器连接信息,如果是阿里邮箱 pass填密码,qq邮箱填授权码 mailConn := map[string]string{ - "user": "postmaster@ipeace.org.cn", - "pass": "Email@henry!", - "host": "smtp.qiye.aliyun.com", - "port": "465", + "alias": "postmaster", + "user": "postmaster@ipeace.org.cn", + "pass": "Email@henry!", + "host": "smtp.qiye.aliyun.com", + "port": "465", } port, _ := strconv.Atoi(mailConn["port"]) //转换端口类型为int m := gomail.NewMessage() - m.SetHeader("From", "XD Game"+"<"+mailConn["user"]+">") //这种方式可以添加别名,即“XD Game”, 也可以直接用m.SetHeader("From",mailConn["user"]) 读者可以自行实验下效果 - m.SetHeader("To", mailTo...) //发送给多个用户 - m.SetHeader("Subject", subject) //设置邮件主题 - m.SetBody("text/html", body) //设置邮件正文 - - d := gomail.NewDialer(mailConn["host"], port, mailConn["user"], mailConn["pass"]) - - err := d.DialAndSend(m) - return err + m.SetHeader("From", m.FormatAddress(mailConn["user"], mailConn["alias"])) + m.SetHeader("To", mailTo...) + m.SetHeader("Subject", subject) + m.SetBody("text/html", body) + return gomail.NewDialer(mailConn["host"], port, mailConn["user"], mailConn["pass"]).DialAndSend(m) } func TestNewEmail(t *testing.T) {