feat:完善信息

This commit is contained in:
henry
2021-10-22 17:10:43 +08:00
parent fdda4b0209
commit e753e99fd8
6 changed files with 150 additions and 21 deletions

View File

@ -5,12 +5,33 @@ import (
"SciencesServer/app/basic/api" "SciencesServer/app/basic/api"
"SciencesServer/app/basic/config" "SciencesServer/app/basic/config"
"SciencesServer/app/service" "SciencesServer/app/service"
config2 "SciencesServer/config"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"strings"
) )
type Technology struct{} type Technology struct{}
type ( 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 论文参数
paperForm struct { paperForm struct {
Title string `json:"title" form:"title" binding:"required"` // 题目 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) { func (a *Technology) Paper(c *gin.Context) {
form := &struct { form := &struct {
Title string `json:"title" form:"title"` Title string `json:"title" form:"title"`

View File

@ -102,6 +102,9 @@ func (c *Topic) Form(params *TopicParams) error {
return errors.New("操作错误,课题信息不存在") return errors.New("操作错误,课题信息不存在")
} else if mTechnologyTopic.UID != c.ManageUID { } else if mTechnologyTopic.UID != c.ManageUID {
return errors.New("无权限操作") return errors.New("无权限操作")
} else if mTechnologyTopic.Status != model2.TechnologyTopicStatusForDraft &&
mTechnologyTopic.Status != model2.TechnologyTopicStatusForRefuse {
return errors.New("操作错误,当前状态不允许修改")
} }
} }
mTechnologyTopic.Title = params.Title mTechnologyTopic.Title = params.Title

View File

@ -21,6 +21,7 @@ type TechnologyTopic struct {
Kind TechnologyTopicKind `gorm:"column:kind;type:tinyint(1);default:0comment:类型" json:"kind"` 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"` 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"` 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 ModelDeleted
ModelAt ModelAt
} }
@ -44,6 +45,20 @@ const (
//TechnologyTopicKindFor //TechnologyTopicKindFor
) )
// TechnologyTopicStatus 技术课题状态
type TechnologyTopicStatus int
const (
// TechnologyTopicStatusForDraft 草稿箱
TechnologyTopicStatusForDraft TechnologyTopicStatus = iota
// TechnologyTopicStatusForExamining 审核中
TechnologyTopicStatusForExamining
// TechnologyTopicStatusForAgree 审核通过
TechnologyTopicStatusForAgree
// TechnologyTopicStatusForRefuse 审核拒绝
TechnologyTopicStatusForRefuse
)
func (m *TechnologyTopic) TableName() string { func (m *TechnologyTopic) TableName() string {
return m.NewTableName("technology_topic") return m.NewTableName("technology_topic")
} }

View File

@ -20,6 +20,14 @@ const (
WechatForAppID string = "appid" 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 ( const (
UploadPath string = "upload_path" // 上传路径 UploadPath string = "upload_path" // 上传路径
UploadExt string = "upload_ext" // 上传文件限制 UploadExt string = "upload_ext" // 上传文件限制

View File

@ -9,11 +9,15 @@ type Email struct {
} }
type EmailOption struct { type EmailOption struct {
User, Auth string // Auth定义邮箱服务器连接信息如果是阿里邮箱 Auth填密码qq邮箱填授权码 Alias, User, Pass string // Auth定义邮箱服务器连接信息如果是阿里邮箱 Pass填密码qq邮箱填授权码
Host string Host string
Port int Port int
} }
// EmailSendHandle 邮件发送处理
// @objects发送对象多个邮件地址
// @subject邮件主题
// @body邮件正文
type EmailSendHandle func(objects []string, subject, body string) error type EmailSendHandle func(objects []string, subject, body string) error
func (this *Email) Init() { func (this *Email) Init() {
@ -23,11 +27,11 @@ func (this *Email) Init() {
func (this *Email) Send() EmailSendHandle { func (this *Email) Send() EmailSendHandle {
return func(objects []string, subject, body string) error { return func(objects []string, subject, body string) error {
m := gomail.NewMessage() m := gomail.NewMessage()
m.SetHeader("From", "XD Game"+"<"+this.User+">") //这种方式可以添加别名即“XD Game” 也可以直接用<code>m.SetHeader("From",mailConn["user"])</code> 读者可以自行实验下效果 m.SetHeader("From", m.FormatAddress(this.User, this.Alias))
m.SetHeader("To", objects...) //发送给多个用户 m.SetHeader("To", objects...)
m.SetHeader("Subject", subject) //设置邮件主题 m.SetHeader("Subject", subject)
m.SetBody("text/html", body) //设置邮件正文 m.SetBody("text/html", body)
return gomail.NewDialer(this.Host, this.Port, this.User, this.Auth).DialAndSend(m) return gomail.NewDialer(this.Host, this.Port, this.User, this.Pass).DialAndSend(m)
} }
} }

View File

@ -10,24 +10,21 @@ import (
func SendMail(mailTo []string, subject string, body string) error { func SendMail(mailTo []string, subject string, body string) error {
//定义邮箱服务器连接信息,如果是阿里邮箱 pass填密码qq邮箱填授权码 //定义邮箱服务器连接信息,如果是阿里邮箱 pass填密码qq邮箱填授权码
mailConn := map[string]string{ mailConn := map[string]string{
"user": "postmaster@ipeace.org.cn", "alias": "postmaster",
"pass": "Email@henry!", "user": "postmaster@ipeace.org.cn",
"host": "smtp.qiye.aliyun.com", "pass": "Email@henry!",
"port": "465", "host": "smtp.qiye.aliyun.com",
"port": "465",
} }
port, _ := strconv.Atoi(mailConn["port"]) //转换端口类型为int port, _ := strconv.Atoi(mailConn["port"]) //转换端口类型为int
m := gomail.NewMessage() m := gomail.NewMessage()
m.SetHeader("From", "XD Game"+"<"+mailConn["user"]+">") //这种方式可以添加别名即“XD Game” 也可以直接用<code>m.SetHeader("From",mailConn["user"])</code> 读者可以自行实验下效果 m.SetHeader("From", m.FormatAddress(mailConn["user"], mailConn["alias"]))
m.SetHeader("To", mailTo...) //发送给多个用户 m.SetHeader("To", mailTo...)
m.SetHeader("Subject", subject) //设置邮件主题 m.SetHeader("Subject", subject)
m.SetBody("text/html", body) //设置邮件正文 m.SetBody("text/html", body)
d := gomail.NewDialer(mailConn["host"], port, mailConn["user"], mailConn["pass"])
err := d.DialAndSend(m)
return err
return gomail.NewDialer(mailConn["host"], port, mailConn["user"], mailConn["pass"]).DialAndSend(m)
} }
func TestNewEmail(t *testing.T) { func TestNewEmail(t *testing.T) {