feat:完善信息

This commit is contained in:
henry
2021-10-09 11:55:54 +08:00
parent 2191f0ea3f
commit af44287b4a
19 changed files with 368 additions and 12 deletions

View File

@ -16,9 +16,8 @@ func (c *Platform) Format() string {
// ReturnPages 分页数据
type ReturnPages struct {
Page int `json:"page"`
Data interface{} `json:"data"`
TotalCount int64 `json:"total_count"`
Data interface{} `json:"data"`
Count int64 `json:"count"`
}
type Key struct{}

View File

@ -31,7 +31,7 @@ func (c *Config) Config(kind, page, pageSize int) (*ReturnPages, error) {
if err := model2.Pages(mSysConfig.SysConfig, &out, page, pageSize, &count, where...); err != nil {
return nil, err
}
return &ReturnPages{Data: out, Page: page, TotalCount: count}, nil
return &ReturnPages{Data: out, Count: count}, nil
}
func (c *Config) Form(params map[string]interface{}) error {

45
app/basic/api/struct.go Normal file
View File

@ -0,0 +1,45 @@
package api
import (
"SciencesServer/config"
"SciencesServer/utils"
"strings"
)
type IDForm struct {
ID uint64 `json:"id" form:"id" binding:"required"`
}
type IDStringForm struct {
ID string `json:"id" form:"id" binding:"required"`
}
func (this *IDStringForm) Convert() uint64 {
return uint64(utils.HASHIDDecode(this.ID))
}
type UIDForm struct {
UID string `json:"uid" form:"uid" binding:"required"`
}
func (this *UIDForm) Convert() uint64 {
return utils.StringToUnit64(this.UID)
}
type ImageForm struct {
Image string `json:"image" form:"image"`
}
func (this *ImageForm) FilterImageURL() string {
return strings.Replace(this.Image, config.SettingInfo.Domain, "", -1)
}
type PositionForm struct {
Longitude float64 `json:"longitude" form:"longitude" binding:"required"`
Latitude float64 `json:"latitude" form:"latitude" binding:"required"`
}
type PageForm struct {
Page int `json:"current" form:"current" binding:"required"`
PageSize int `json:"page_size" form:"page_size" binding:"required"`
}

View File

@ -2,6 +2,7 @@ package model
import (
"SciencesServer/serve/orm"
"SciencesServer/utils"
"fmt"
"strings"
"time"
@ -12,6 +13,7 @@ import (
// IModel
type IModel interface {
GetID() uint64
GetEncodeID() string
TableName() string
SetDatabase(database string, key ...string)
}
@ -66,6 +68,10 @@ func (m *Model) GetID() uint64 {
return m.ID
}
func (m *Model) GetEncodeID() string {
return utils.HASHIDEncode(int(m.ID))
}
func (m *Model) SetDatabase(database string, key ...string) {
m.Database = database + "_" + strings.Join(key, "_")
}

View File

@ -0,0 +1,4 @@
package model
type TechnologyInstance struct {
}

View File

@ -0,0 +1,40 @@
package model
import (
"SciencesServer/utils"
"time"
)
// TechnologyPaper 科技论文数据模型
type TechnologyPaper struct {
Model
ModelTenant
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
Title string `gorm:"column:title;type:varchar(100);default:null;comment:题目" json:"title"`
Ext string `gorm:"column:ext;type:varchar(30);default:null;comment:引用格式" json:"ext"`
Author string `gorm:"column:author;type:varchar(100);default:null;comment:作者" json:"author"`
PublishAt time.Time `gorm:"column:publish_at;type:datetime;not null;comment:出版日期" json:"publish_at"`
Keyword string `gorm:"column:keyword;type:varchar(100);default:null;comment:关键词" json:"keyword"`
Tag string `gorm:"column:tags;type:varchar(255);default:null;comment:标签" json:"-"`
Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:备注" json:"remark"`
ModelDeleted
ModelAt
}
func (m *TechnologyPaper) TableName() string {
return m.NewTableName("technology_paper")
}
func (m *TechnologyPaper) GetTagAttribute() []string {
tags := make([]string, 0)
_ = utils.FromJSON(m.Tag, &tags)
return tags
}
func (m *TechnologyPaper) SetTagAttribute(tags []string) {
m.Tag = utils.AnyToJSON(tags)
}
func NewTechnologyPaper() *TechnologyPaper {
return &TechnologyPaper{}
}

View File

@ -0,0 +1,78 @@
package api
import (
"SciencesServer/app/basic/api"
"SciencesServer/app/enterprise/controller/technology"
"SciencesServer/app/service"
"github.com/gin-gonic/gin"
)
type Technology struct{}
type (
// paperForm 论文参数
paperForm struct {
Title string `json:"title" form:"title" binding:"required"` // 题目
Ext string `json:"ext" form:"ext" binding:"required"` // 格式
Author string `json:"author" form:"author" binding:"required"` // 作者
PublishAt string `json:"publish_at" form:"publish_at" binding:"required"` // 出版日期
Keyword string `json:"keyword" form:"keyword"` // 关键词
Tags []string `json:"tags" form:"tags"` // 标签
Remark string `json:"remark" form:"remark"` // 备注
}
)
func (a *Technology) Paper(c *gin.Context) {
form := &struct {
Title string `json:"title"`
api.PageForm
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
data, err := technology.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise)).List(form.Title, form.Page, form.PageSize)
api.APIResponse(err, data)
}
func (a *Technology) PaperAdd(c *gin.Context) {
form := new(paperForm)
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
err := technology.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise)).Form(&technology.PaperParams{
Title: form.Title, Ext: form.Ext, Author: form.Author, PublishAt: form.PublishAt,
Keyword: form.Keyword, Tags: form.Tags, Remark: form.Remark,
})
api.APIResponse(err)
}
func (a *Technology) PaperEdit(c *gin.Context) {
form := &struct {
api.IDStringForm
paperForm
}{}
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
err := technology.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise)).Form(&technology.PaperParams{
ID: form.Convert(), Title: form.Title, Ext: form.Ext, Author: form.Author, PublishAt: form.PublishAt,
Keyword: form.Keyword, Tags: form.Tags, Remark: form.Remark,
})
api.APIResponse(err)
}
func (a *Technology) PaperDelete(c *gin.Context) {
form := new(api.IDStringForm)
if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c)
return
}
err := technology.NewPaper()(api.GetSession()(c).(*service.SessionEnterprise)).Delete(form.Convert())
api.APIResponse(err)
}

View File

@ -15,7 +15,7 @@ type InstanceLoginCallback func(params *InstanceLoginParams) *InstanceLoginRetur
type (
InstanceLoginParams struct {
UID uint64
UID, TenantID uint64
Name, Mobile, Avatar string
Identity, SelectIdentity int
Status model.AccountStatusKind
@ -34,6 +34,7 @@ func (c *Instance) Login() InstanceLoginCallback {
session := service.NewSessionEnterprise()
session.Token = token
session.UID = params.UID
session.TenantID = params.TenantID
session.Avatar = params.Avatar
session.Name = params.Name
session.Mobile = params.Mobile

View File

@ -79,8 +79,9 @@ func loginForSmsCaptcha(params *LoginParams) (*InstanceLoginParams, error) {
}
RETURNS:
return &InstanceLoginParams{
UID: mUserInstance.UUID, Name: mUserInstance.Name, Mobile: mUserInstance.Mobile, Avatar: mUserTenant.Avatar,
Identity: mUserInstance.Identity, SelectIdentity: mUserTenant.Identity, Status: mUserInstance.Status,
UID: mUserInstance.UUID, TenantID: mUserTenant.TenantID, Name: mUserInstance.Name, Mobile: mUserInstance.Mobile,
Avatar: mUserTenant.Avatar, Identity: mUserInstance.Identity, SelectIdentity: mUserTenant.Identity,
Status: mUserInstance.Status,
}, nil
}
@ -109,8 +110,9 @@ func loginForPassword(params *LoginParams) (*InstanceLoginParams, error) {
return nil, err
}
return &InstanceLoginParams{
UID: mUserInstance.UUID, Name: mUserInstance.Name, Mobile: mUserInstance.Mobile, Avatar: mUserTenant.Avatar,
Identity: mUserInstance.Identity, SelectIdentity: mUserTenant.Identity, Status: mUserInstance.Status,
UID: mUserInstance.UUID, TenantID: mUserTenant.TenantID, Name: mUserInstance.Name, Mobile: mUserInstance.Mobile,
Avatar: mUserTenant.Avatar, Identity: mUserInstance.Identity, SelectIdentity: mUserTenant.Identity,
Status: mUserInstance.Status,
}, nil
}

View File

@ -0,0 +1,25 @@
package technology
import "SciencesServer/app/service"
// Instance 技术管理
type Instance struct{ *service.SessionEnterprise }
type InstanceHandle func(enterprise *service.SessionEnterprise) *Instance
func (c *Instance) List(status, page, pageSize int) {
}
func (c *Instance) Form() {
}
func (c *Instance) Delete() {
}
func NewInstance() InstanceHandle {
return func(enterprise *service.SessionEnterprise) *Instance {
return &Instance{enterprise}
}
}

View File

@ -0,0 +1,111 @@
package technology
import (
"SciencesServer/app/api/controller"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/enterprise/model"
"SciencesServer/app/service"
"SciencesServer/utils"
"errors"
"time"
)
// Paper 论文管理
type Paper struct{ *service.SessionEnterprise }
type PaperHandle func(enterprise *service.SessionEnterprise) *Paper
type (
PaperInfo struct {
ID string `json:"id"`
*model2.TechnologyPaper
Tags []string `json:"tags"`
}
PaperParams struct {
ID uint64
Title, Ext, Author, PublishAt, Keyword, Remark string
Tags []string
}
)
// List 列表信息
func (c *Paper) List(title string, page, pageSize int) (*controller.ReturnPages, error) {
mTechnologyPaper := model.NewTechnologyPaper()
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
Where: model2.NewWhere("tenant_id", c.TenantID),
Order: model2.NewOrder("id", model2.OrderModeToDesc),
}}
if title != "" {
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhereLike("title", title)})
}
out := make([]*model2.TechnologyPaper, 0)
var count int64
if err := model2.Pages(mTechnologyPaper.TechnologyPaper, &out, page, pageSize, &count, where...); err != nil {
return nil, err
}
list := make([]*PaperInfo, 0)
for _, v := range out {
list = append(list, &PaperInfo{ID: v.GetEncodeID(), TechnologyPaper: v, Tags: v.GetTagAttribute()})
}
return &controller.ReturnPages{Data: list, Count: count}, nil
}
// Form 参数信息
func (c *Paper) Form(params *PaperParams) error {
mTechnologyPaper := model.NewTechnologyPaper()
if params.ID > 0 {
mTechnologyPaper.ID = params.ID
if isExist, err := model2.First(mTechnologyPaper.TechnologyPaper); err != nil {
return err
} else if !isExist {
return errors.New("当前论文信息不存在")
} else if mTechnologyPaper.UID != c.UID {
return errors.New("无权限操作")
}
}
mTechnologyPaper.Title = params.Title
mTechnologyPaper.Ext = params.Ext
mTechnologyPaper.Author = params.Author
mTechnologyPaper.PublishAt = utils.DateTimeToTime(params.PublishAt)
mTechnologyPaper.Keyword = params.Keyword
mTechnologyPaper.SetTagAttribute(params.Tags)
mTechnologyPaper.Remark = params.Remark
if params.ID <= 0 {
return model2.Create(mTechnologyPaper.TechnologyPaper)
}
mTechnologyPaper.UpdatedAt = time.Now()
return model2.Updates(mTechnologyPaper.TechnologyPaper, mTechnologyPaper.TechnologyPaper)
}
// Delete 删除操作
func (c *Paper) Delete(id uint64) error {
mTechnologyPaper := model.NewTechnologyPaper()
mTechnologyPaper.ID = id
var count int64
err := model2.Count(mTechnologyPaper.TechnologyPaper, &count, model2.NewWhere("id", id), model2.NewWhere("uid", c.UID))
if err != nil {
return err
} else if count <= 0 {
return errors.New("当前论文信息不存在")
}
if err = model2.Delete(mTechnologyPaper.TechnologyPaper); err != nil {
return err
}
return nil
}
func NewPaper() PaperHandle {
return func(enterprise *service.SessionEnterprise) *Paper {
return &Paper{enterprise}
}
}

View File

@ -0,0 +1,4 @@
package technology
// Patent 专利管理
type Patent struct{}

View File

@ -47,6 +47,7 @@ type (
var tenantHandlePerfect = map[int]func(params *TenantPerfectParams) (string, error){
config.TenantUserIdentityForCompany: perfectForCompany,
config.TenantUserIdentityForExpert: perfectForExpert,
}
func perfectForCompany(params *TenantPerfectParams) (string, error) {
@ -56,8 +57,8 @@ func perfectForCompany(params *TenantPerfectParams) (string, error) {
return utils.AnyToJSON(params.TenantParamsForCompany), nil
}
func perfectForExpert() error {
return nil
func perfectForExpert(params *TenantPerfectParams) (string, error) {
return "", nil
}
func perfectForResearch() error {

View File

@ -0,0 +1,13 @@
package model
import (
"SciencesServer/app/common/model"
)
type TechnologyPaper struct {
*model.TechnologyPaper
}
func NewTechnologyPaper() *TechnologyPaper {
return &TechnologyPaper{model.NewTechnologyPaper()}
}

View File

@ -9,7 +9,7 @@ type UserTenant struct {
}
func (m *UserTenant) LastChooseInfo(uid uint64) error {
_, err := model.FirstField(m.UserTenant, []string{"id", "uid", "avatar", "identity"},
_, err := model.FirstField(m.UserTenant, []string{"id", "tenant_id", "uid", "avatar", "identity"},
model.NewWhere("uid", uid),
model.NewWhere("selected", model.UserTenantSelectedForYes))
return err

View File

@ -30,6 +30,7 @@ func NewSession() *Session {
// SessionEnterprise 企业用户
type SessionEnterprise struct {
UID uint64 `json:"uid"` // 唯一标识ID
TenantID uint64 `json:"tenant_id"` // 租户ID
Token string `json:"token"` // token
Name string `json:"name"` // 名称
Avatar string `json:"avatar"` // 头像

1
go.mod
View File

@ -22,6 +22,7 @@ require (
github.com/robfig/cron v1.2.0
github.com/satori/go.uuid v1.2.0
github.com/sirupsen/logrus v1.8.1
github.com/speps/go-hashids v1.0.0 // indirect
github.com/spf13/cobra v1.2.1
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac

2
go.sum
View File

@ -383,6 +383,8 @@ github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/speps/go-hashids v1.0.0 h1:jdFC07PrExRM4Og5Ev4411Tox75aFpkC77NlmutadNI=
github.com/speps/go-hashids v1.0.0/go.mod h1:P7hqPzMdnZOfyIk+xrlG1QaSMw+gCBdHKsBDnhpaZvc=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw=

View File

@ -6,11 +6,15 @@ import (
"crypto/sha256"
"crypto/sha512"
"encoding/hex"
"github.com/speps/go-hashids"
"strings"
"golang.org/x/crypto/bcrypt"
)
// salt 盐值
const salt = "CHeF6AC392"
// Md5String
func Md5String(s string, salt ...string) string {
h := md5.New()
@ -50,3 +54,22 @@ func HashString(s []byte) string {
func HashCompare(src, compare []byte) bool {
return bcrypt.CompareHashAndPassword(src, compare) == nil
}
// HASHIDEncode 混淆
func HASHIDEncode(src int) string {
hd := hashids.NewData()
hd.Salt = salt
hd.MinLength = 6
h := hashids.NewWithData(hd)
e, _ := h.Encode([]int{src})
return e
}
// HASHIDDecode 还原混淆
func HASHIDDecode(src string) int {
hd := hashids.NewData()
hd.Salt = salt
h := hashids.NewWithData(hd)
e, _ := h.DecodeWithError(src)
return e[0]
}