From 46476267aa9bad741d3e43fc26adf66e844b59eb Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 8 Feb 2022 11:05:47 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E4=BC=98=E5=8C=96=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .default_setting.yaml | 8 --- README.md | 58 +++++++++++++++++-- app/api/admin/controller/manage/expert.go | 2 - .../controller/technology/achievement.go | 29 +++++++++- app/api/admin/controller/technology/basic.go | 13 ++++- app/api/admin/controller/technology/demand.go | 2 +- .../admin/controller/technology/product.go | 2 +- .../website/model/technology_achievement.go | 2 +- app/service/es_achievement.go | 3 - app/service/es_test.go | 14 +++++ cmd/serve/init.go | 2 - config/config.go | 9 --- serve/es/es_test.go | 18 +++++- 13 files changed, 125 insertions(+), 37 deletions(-) create mode 100644 app/service/es_test.go diff --git a/.default_setting.yaml b/.default_setting.yaml index 7832504..1e1ee22 100644 --- a/.default_setting.yaml +++ b/.default_setting.yaml @@ -26,14 +26,6 @@ cache: max_idle: 1000 idle_timeout: 240 -# UPLOAD 上传文件配置 -upload: - path: upload/ - ext: png,jpg,csv,xls,xlsx,pcm,wav,amr,mp3,mp4,json - # size 4<<20,不支持位运算,文件最大限制 - size: 4194304 - rename: true - #LOG 日志管理 log: file: log/logs.log diff --git a/README.md b/README.md index 5a48d51..228955d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,57 @@ -# SciencesServer +简体中文 -中科元系统管理 +

Sciences Server

+
+中科云管理系统 +
-### 迁移数据 +[comment]: <> (- 预览: https://preview.pro.antdv.com) -./SciencesServer init -H 192.168.0.188 -P 3306 -d sciences -u appuser -p ABCabc01 \ No newline at end of file +环境和依赖 +---- + +- Go>=1.15 +- [Gin](https://github.com/gin-gonic/gin) - Web Router +- [Gorm.v2](https://github.com/go-gorm/gorm) - Data Engine +- [Cacbin](https://github.com/casbin/casbin) - Auth(RBAC) +- [Redis](https://github.com/redis/redis) + +项目编译和运行 +---- + +- 编译项目 +```bash +go bulid [-x|-o] +``` + +- 运行项目 +```bash +./项目文件 start -m ['debug'|'release'] -s ['./default_setting.yaml'] -a ['./default_engine.yaml'] +``` +> 请注意: +> +> 复制[.default_setting.yaml](./.default_setting.yaml)文件,去除前面的`.`,参考基本配置信息 +> +> 在运行项目开始,请先执行初始化命令 `init` (./项目文件 init -H 地址 -P 端口 -d 数据库 -u 用户名 -p 密码 ) +> +> 参考案例:./SciencesServer init -H 192.168.0.188 -P 3306 -d sciences -u appuser -p ABCabc01 +> +> 支持mysql,sqlite,建议使用mysql作为数据引擎,详细请参考 [default_engine.yaml](./default_engine.yaml) ,初始化会生成此文件 + +- 打包项目 +```bash +pack +``` +> 请注意,需要node.js支持,安装 `pack` (npm install -g @penggy/pack)命令 + +- 发布项目 +```bash +linux:一:./server.sh(请注意修改文件提示的地方);二:nohup ./项目 &;三:DockerFile +``` + +- 其他说明 + - 项目目录 + - file 配置文件,不可删除 + - key 密钥管理,不可删除 + - cmd 项目执行入口 + - log 日志管理,自动生成 diff --git a/app/api/admin/controller/manage/expert.go b/app/api/admin/controller/manage/expert.go index b014179..be7fe11 100644 --- a/app/api/admin/controller/manage/expert.go +++ b/app/api/admin/controller/manage/expert.go @@ -9,7 +9,6 @@ import ( config2 "SciencesServer/config" "SciencesServer/utils" "errors" - "fmt" "time" ) @@ -152,7 +151,6 @@ func (c *Expert) Form(params *BasicParams, other *config.IdentityForExpert) erro } } } - fmt.Println(utils.AnyToJSON(other)) mManageExpert.TenantID = c.TenantID mManageExpert.ResearchID = other.ConvertResearch() mManageExpert.LaboratoryID = other.ConvertLaboratory() diff --git a/app/api/admin/controller/technology/achievement.go b/app/api/admin/controller/technology/achievement.go index f2a7311..4811fb4 100644 --- a/app/api/admin/controller/technology/achievement.go +++ b/app/api/admin/controller/technology/achievement.go @@ -2,10 +2,13 @@ package technology import ( "SciencesServer/app/api/admin/model" + "SciencesServer/app/basic/config" "SciencesServer/app/basic/controller" model2 "SciencesServer/app/common/model" + "SciencesServer/app/service" "SciencesServer/app/session" "errors" + "strings" ) type Achievement struct { @@ -87,7 +90,8 @@ func (c *Achievement) Examine(id uint64, status int, remark string) error { mTechnologyAchievement := model.NewTechnologyAchievement() mTechnologyAchievement.ID = id - isExist, err := model2.FirstField(mTechnologyAchievement.TechnologyAchievement, []string{"id", "tenant_id", "status"}) + isExist, err := model2.FirstField(mTechnologyAchievement.TechnologyAchievement, []string{"id", "tenant_id", "title", + "industry", "keyword", "status"}) if err != nil { return err @@ -100,7 +104,28 @@ func (c *Achievement) Examine(id uint64, status int, remark string) error { if mTechnologyAchievement.Status != model2.TechnologyStatusKindForExamining { return errors.New("操作错误,当前成果状态不允许审核") } - return handleExamine(mTechnologyAchievement.TechnologyAchievement, c.UID, model2.SysUserExamineLogKindForAchievement, status, remark) + if err = handleExamine(mTechnologyAchievement.TechnologyAchievement, c.UID, model2.SysUserExamineLogKindForAchievement, status, remark, func() error { + if model2.ExamineStatusKind(status) == model2.ExamineStatusForAgree { + _industrys := make([]string, 0) + + for _, v := range mTechnologyAchievement.GetIndustryAttribute() { + _industrys = append(_industrys, config.GetIndustryInfo(v, "-", "-").Value) + } + // 存放ES中 + manage := service.NewESAchievement( + service.WithAchievementID(mTechnologyAchievement.ID), + service.WithAchievementTitle(mTechnologyAchievement.Title), + service.WithAchievementIndustry(strings.Join(_industrys, ";")), + service.WithAchievementKeyword(strings.Join(mTechnologyAchievement.GetKeywordAttribute(), ";")), + ) + return manage.Create() + } + return nil + }); err != nil { + return err + } + + return nil } // Shelf 上下架 diff --git a/app/api/admin/controller/technology/basic.go b/app/api/admin/controller/technology/basic.go index b6161a8..4fa87fa 100644 --- a/app/api/admin/controller/technology/basic.go +++ b/app/api/admin/controller/technology/basic.go @@ -8,7 +8,9 @@ import ( "time" ) -func handleExamine(iModel model2.IModel, uid uint64, kind model2.SysUserExamineLogKind, status int, remark string) error { +type callback func() error + +func handleExamine(iModel model2.IModel, uid uint64, kind model2.SysUserExamineLogKind, status int, remark string, callback2 callback) error { return orm.GetDB().Transaction(func(tx *gorm.DB) error { err := model2.Updates(iModel, map[string]interface{}{ "status": status, "updated_at": time.Now(), @@ -23,6 +25,13 @@ func handleExamine(iModel model2.IModel, uid uint64, kind model2.SysUserExamineL mSysUserExamineLog.ObjectID = iModel.GetID() mSysUserExamineLog.Status = status mSysUserExamineLog.Remark = remark - return model2.Create(mSysUserExamineLog.SysUserExamineLog, tx) + + if err = model2.Create(mSysUserExamineLog.SysUserExamineLog, tx); err != nil { + return err + } + if callback2 != nil { + return callback2() + } + return err }) } diff --git a/app/api/admin/controller/technology/demand.go b/app/api/admin/controller/technology/demand.go index 296d070..9ecee52 100644 --- a/app/api/admin/controller/technology/demand.go +++ b/app/api/admin/controller/technology/demand.go @@ -103,7 +103,7 @@ func (c *Demand) Examine(id uint64, status int, remark string) error { if mTechnologyDemand.Status != model2.TechnologyStatusKindForExamining { return errors.New("操作错误,当前需求状态不允许审核") } - return handleExamine(mTechnologyDemand.TechnologyDemand, c.UID, model2.SysUserExamineLogKindForDemandTechnology, status, remark) + return handleExamine(mTechnologyDemand.TechnologyDemand, c.UID, model2.SysUserExamineLogKindForDemandTechnology, status, remark, nil) } // Delete 删除操作 diff --git a/app/api/admin/controller/technology/product.go b/app/api/admin/controller/technology/product.go index 0f5086b..1a615c6 100644 --- a/app/api/admin/controller/technology/product.go +++ b/app/api/admin/controller/technology/product.go @@ -100,7 +100,7 @@ func (c *Product) Examine(id uint64, status int, remark string) error { if mTechnologyProduct.Status != model2.TechnologyStatusKindForExamining { return errors.New("操作错误,当前产品状态不允许审核") } - return handleExamine(mTechnologyProduct.TechnologyProduct, c.UID, model2.SysUserExamineLogKindForProduct, status, remark) + return handleExamine(mTechnologyProduct.TechnologyProduct, c.UID, model2.SysUserExamineLogKindForProduct, status, remark, nil) } // Shelf 上下架操作 diff --git a/app/api/website/model/technology_achievement.go b/app/api/website/model/technology_achievement.go index d3fc19d..b3024f5 100644 --- a/app/api/website/model/technology_achievement.go +++ b/app/api/website/model/technology_achievement.go @@ -53,7 +53,7 @@ func (m *TechnologyAchievement) Achievements(page, pageSize int, count *int64, w // Achievement 成果信息 func (m *TechnologyAchievement) Achievement(where ...*model.ModelWhere) ([]*TechnologyAchievementInfo, error) { db := orm.GetDB().Table(m.TableName()+" AS a"). - Select("a.id", "a.title", "a.mode", "a.image", "a.charge_info", "a.industry", "a.customer", "a.maturity", + Select("a.id", "a.title", "a.mode", "a.image", "a.config", "a.industry", "a.customer", "a.maturity", "a.cooperation_mode", "a.keyword", "v.count AS visit_count", "c.count AS collect_count"). Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, SUM(count) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS v ON a.id = v.object_id", model.NewUserVisit().TableName(), model.UserCollectKindForTechnologyAchievement, model.DeleteStatusForNot)). diff --git a/app/service/es_achievement.go b/app/service/es_achievement.go index aa68ad4..3af913e 100644 --- a/app/service/es_achievement.go +++ b/app/service/es_achievement.go @@ -20,9 +20,6 @@ func (this *ESAchievement) Index() string { } func (this *ESAchievement) Create() error { - if this.Industry != "" { - this.Title = this.Industry + " - " + this.Title - } _bytes, _ := json.Marshal(this) return es.Create(this.Index(), fmt.Sprintf("%d", this.ID), _bytes) } diff --git a/app/service/es_test.go b/app/service/es_test.go new file mode 100644 index 0000000..a7de2c5 --- /dev/null +++ b/app/service/es_test.go @@ -0,0 +1,14 @@ +package service + +import "testing" + +func TestESAchievement_Create(t *testing.T) { + manage := NewESAchievement( + WithAchievementID(1), + WithAchievementTitle("测试一"), + WithAchievementIndustry("测试测试"), + WithAchievementKeyword("关键词1;关键词2"), + ) + err := manage.Create() + t.Log(err) +} diff --git a/cmd/serve/init.go b/cmd/serve/init.go index e600e84..d7c92b3 100644 --- a/cmd/serve/init.go +++ b/cmd/serve/init.go @@ -17,7 +17,6 @@ import ( "fmt" "github.com/spf13/cobra" "net/http" - "strings" ) var ( @@ -43,7 +42,6 @@ func run() { // 载入配置信息 utils.LoadConfig(configFile, config.SettingInfo, func(i interface{}) { obj := i.(*config.Setting) - obj.Upload.Exts = strings.Split(obj.Upload.Ext, ",") logger.NewLogger().Init(&logger.Option{File: obj.Log.File, LeastDay: obj.Log.LeastDay, Level: obj.Log.Level, IsStdout: false}).Load() }) // 载入数据引擎配置 diff --git a/config/config.go b/config/config.go index 2c4d5cb..02fba66 100644 --- a/config/config.go +++ b/config/config.go @@ -69,15 +69,6 @@ type Setting struct { Redis *Redis `yaml:"redis"` } - // Upload 配置 - Upload struct { - Path string `yaml:"path"` - Ext string `yaml:"ext"` - Exts []string `yaml:"-"` - Size int64 `yaml:"size"` - Rename bool `yaml:"rename"` - } - // Log 配置 Log struct { File string `yaml:"file"` diff --git a/serve/es/es_test.go b/serve/es/es_test.go index b8c3e3a..97848e1 100644 --- a/serve/es/es_test.go +++ b/serve/es/es_test.go @@ -33,13 +33,27 @@ func _new() *elastic.Client { return client } +type ESAchievement struct { + ID uint64 `json:"id"` // 成果ID + Title string `json:"title"` // 成果名称 + Industry string `json:"industry"` // 行业领域 + Keyword string `json:"keyword"` // 关键词 +} + func TestNewInstanceCreate(t *testing.T) { client := _new() //client.Delete() - src := Student{ID: 2, Name: "henry", Age: 28} - client.Index().Index("student").Id(fmt.Sprintf("%d", src.ID)).BodyJson(utils.AnyToJSON(src)). + //src := Student{ID: 2, Name: "henry", Age: 28} + src := &ESAchievement{ + ID: 6, + Title: "测试6", + Industry: "测试测试", + Keyword: "关键词1;关键词2", + } + _, err := client.Index().Index("es_achievement_index").Id(fmt.Sprintf("%d", src.ID)).BodyJson(utils.AnyToJSON(src)). Do(context.Background()) + t.Log(err) } func TestNewInstanceUpdate(t *testing.T) {