Files
2022-01-07 16:12:43 +08:00

207 lines
5.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"SciencesServer/app/basic/config"
"SciencesServer/serve/orm"
"SciencesServer/serve/orm/logic"
"SciencesServer/utils"
"fmt"
"gorm.io/gorm"
"strings"
"testing"
"time"
)
// PPatent 专利信息数据模型
type PPatent struct {
Model
Kind string `gorm:"column:kind;type:tinyint(1);default:0;comment:专利类型" json:"kind"`
Title string `gorm:"column:title;type:varchar(255);default:'';comment:名称标题" json:"title"`
FileUrl string `gorm:"column:file_url;type:varchar(255);default:'';comment:文件地址" json:"file_url"`
ApplyCode string `gorm:"column:apply_code;type:varchar(50);default:'';comment:申请号" json:"apply_code"`
ApplyAt string `gorm:"column:apply_at;type:varchar(30);default:'';comment:申请日" json:"apply_at"`
OpenCode string `gorm:"column:open_code;type:varchar(50);default:'';comment:公开(公告)号" json:"open_code"`
OpenAt string `gorm:"column:open_at;type:varchar(30);default:'';comment:公开(公告)日" json:"open_at"`
ApplyName string `gorm:"column:apply_name;type:varchar(100);default:'';comment:申请(专利权)人" json:"apply_name"`
ApplyAddress string `gorm:"column:apply_address;type:varchar(255);default:'';comment:申请人地址" json:"apply_address"`
Inventor string `gorm:"column:inventor;type:varchar(100);default:'';comment:发明人" json:"inventor"`
Description string `gorm:"column:description;type:text;comment:摘要" json:"description"`
PrincipalClaim string `gorm:"column:principal_claim;type:text;comment:主权项" json:"principal_claim"`
IPCCode string `gorm:"column:ipc_code;type:varchar(50);default:'';comment:IPC主分类号" json:"ipc_code"`
Shelf
Status SysParentStatus `gorm:"column:status;type:tinyint(1);default:1;comment:专利状态(1授权2实审3公开)" json:"-"`
ModelDeleted
ModelAt
}
func (m *PPatent) TableName() string {
return "manage_patent"
}
func mysql() *gorm.DB {
instance := orm.NewInstance(
orm.WithDebug(true),
orm.WithDBMode("mysql"),
orm.WithTablePrefix(""),
orm.WithSingularTable(false),
orm.WithMaxIdleConns(3600),
orm.WithMaxOpenConns(2000),
orm.WithMaxLifetime(1000),
orm.WithMysqlOption(&logic.Mysql{
Username: "appuser", Password: "ABCabc01!", Host: "192.168.0.188", Port: 3306,
Database: "sciences", Parameters: "charset=utf8mb4,utf8&parseTime=True&loc=Local",
}),
).Init()
return instance.Engine
}
func sqlite() *gorm.DB {
instance := orm.NewInstance(
orm.WithDebug(true),
orm.WithDBMode("sqlite"),
orm.WithTablePrefix(""),
orm.WithSingularTable(false),
orm.WithMaxIdleConns(3600),
orm.WithMaxOpenConns(2000),
orm.WithMaxLifetime(1000),
orm.WithSqliteOption(&logic.Sqlite{Path: "../../../lib",
Name: "data.db"}),
).Init()
return instance.Engine
}
func filter(src string) string {
src = utils.ReplaceAllCompile(src, "\t", "")
src = utils.ReplaceAllCompile(src, "\n", "")
src = strings.TrimLeft(src, " ")
src = strings.TrimRight(src, " ")
return src
}
func TestRecoveryPatent(t *testing.T) {
return
src := make([]*PPatent, 0)
sqlite := sqlite()
var err error
page := 1
mysql := mysql()
mSysPatent := new(SysPatent)
now := time.Now()
limit := 100
for {
if err = sqlite.Offset((page - 1) * limit).Limit(limit).Find(&src).Error; err != nil {
t.Error("Sqlite" + err.Error())
return
}
if len(src) <= 0 {
t.Log("执行结束")
return
}
t.Log(len(src))
out := make([]*SysPatent, 0)
for _, v := range src {
kind := SysParentKindForInvent
if v.Kind == "实用新型" {
kind = SysParentKindForNewPractical
} else if v.Kind == "外观设计" {
kind = SysParentKindForDesign
}
data := &SysPatent{
Kind: kind,
Title: v.Title,
FileUrl: v.FileUrl,
ApplyCode: v.ApplyCode,
ApplyAt: v.ApplyAt,
OpenCode: v.OpenCode,
OpenAt: v.OpenAt,
ApplyName: filter(v.ApplyName),
ApplyAddress: filter(v.ApplyAddress),
Inventor: filter(v.Inventor),
Description: filter(v.Description),
PrincipalClaim: filter(v.PrincipalClaim),
IPCCode: v.IPCCode,
Shelf: Shelf{ShelfStatus: 1},
ModelAt: ModelAt{
CreatedAt: now, UpdatedAt: now,
},
}
out = append(out, data)
}
src = make([]*PPatent, 0)
page++
if err = mysql.Table(mSysPatent.TableName()).Create(out).Error; err != nil {
t.Error("Mysql" + err.Error())
return
}
}
}
func TestA(t *testing.T) {
return
mysql := mysql()
file := "../../../file/sys_industry.json"
src := make([]*config.MemoryForIndustry, 0)
utils.LoadConfig(file, &src)
out := make([]*SysIndustry, 0)
var id uint64 = 1
for _, v := range src {
var parentID uint64 = 0
data := &SysIndustry{
Model: Model{
ID: id,
},
ParentID: parentID,
Name: v.Name,
}
out = append(out, data)
if v.Children != nil && len(v.Children) > 0 {
parentID = id
for _, val := range v.Children {
id++
data = &SysIndustry{
Model: Model{
ID: id,
},
ParentID: parentID,
Name: val.Name,
}
out = append(out, data)
}
}
id++
}
fmt.Println(utils.AnyToJSON(out))
err := mysql.Table(NewSysIndustry().TableName()).Create(out).Error
t.Log(err)
}
func TestNewUserInstance(t *testing.T) {
mysql := mysql()
out := make([]string, 0)
mysql.Table(NewUserInstance().TableName()).
Where("is_deleted = ?", DeleteStatusForNot).
Where(fmt.Sprintf("id IN (%v) OR id IN (%v)", strings.Join([]string{"1"}, ","), strings.Join([]string{"2"}, ","))).
Pluck("id", &out)
t.Log(out)
t.Log(len(out))
}