feat:优化项目信息
This commit is contained in:
@ -150,6 +150,46 @@ func (*Manage) ExpertExamine(c *gin.Context) {
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Manage) ExpertPatent(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
Title string `json:"title" form:"title"`
|
||||
ApplyName string `json:"apply_name" form:"apply_name"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := manage.NewExpert()(api.GetSession()(c).(*session.Admin)).Patent(form.Convert(), form.Title, form.ApplyName)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Manage) ExpertPatentBind(bind bool) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.IDStringForm
|
||||
PatentIDs []string `json:"patent_ids" form:"patent_ids" binding:"required"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
patentIDs := make([]uint64, 0)
|
||||
|
||||
for _, v := range form.PatentIDs {
|
||||
patentIDs = append(patentIDs, (&api.IDStringForm{ID: v}).Convert())
|
||||
}
|
||||
var err error
|
||||
|
||||
if bind {
|
||||
err = manage.NewExpert()(api.GetSession()(c).(*session.Admin)).PatentBind(form.Convert(), patentIDs)
|
||||
} else {
|
||||
err = manage.NewExpert()(api.GetSession()(c).(*session.Admin)).PatentUnbind(form.Convert(), patentIDs)
|
||||
}
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
}
|
||||
|
||||
func (*Manage) Research(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
|
@ -12,7 +12,6 @@ type Technology struct{}
|
||||
|
||||
func (*Technology) Patent(c *gin.Context) {
|
||||
form := &struct {
|
||||
api.TenantIDStringForm
|
||||
Title string `json:"title" form:"title"`
|
||||
IPCCode string `json:"ipc_code" form:"ipc_code"`
|
||||
api.PageForm
|
||||
@ -21,7 +20,7 @@ func (*Technology) Patent(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).Instance(form.Convert(), form.Title, form.IPCCode,
|
||||
data, err := technology.NewPatent()(api.GetSession()(c).(*session.Admin)).Instance(form.Title, form.IPCCode,
|
||||
form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
@ -45,6 +45,12 @@ type (
|
||||
Researchs []string `json:"researchs"`
|
||||
Area string `json:"area"`
|
||||
}
|
||||
// ExpertPatent 专家专利信息
|
||||
ExpertPatent struct {
|
||||
ID string `json:"id"`
|
||||
*model.ManageExpertPatent
|
||||
IsBind bool `json:"is_bind"`
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 首页信息
|
||||
@ -191,6 +197,97 @@ func (c *Expert) Form(params *BasicParams, other *config.IdentityForExpert) erro
|
||||
return model2.Create(mManageExpert.ManageExpert)
|
||||
}
|
||||
|
||||
// Patent 专利信息
|
||||
func (c *Expert) Patent(id uint64, title, applyName string) ([]*ExpertPatent, error) {
|
||||
mManageExpert := model.NewManageExpert()
|
||||
|
||||
out, err := mManageExpert.Basic(id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if out == nil || out.ID <= 0 {
|
||||
return nil, errors.New("操作错误,未找到对应的专家信息")
|
||||
}
|
||||
// 查看专利信息
|
||||
patents := make([]*model.ManageExpertPatent, 0)
|
||||
|
||||
where := []*model2.ModelWhere{
|
||||
//model2.NewWhereFindInSet("p.apply_name", out.ResearchName),
|
||||
model2.NewWhereFindInSet("p.inventor", out.Name),
|
||||
}
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("p.title", title))
|
||||
}
|
||||
if applyName != "" {
|
||||
where = append(where, model2.NewWhereFindInSet("p.apply_name", applyName))
|
||||
}
|
||||
if patents, err = mManageExpert.Patents(where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*ExpertPatent, 0)
|
||||
|
||||
for _, v := range patents {
|
||||
list = append(list, &ExpertPatent{
|
||||
ID: v.GetEncodeID(),
|
||||
ManageExpertPatent: v,
|
||||
IsBind: v.UserPatentCount > 0,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// PatentBind 专利认领绑定
|
||||
func (c *Expert) PatentBind(id uint64, patentID []uint64) error {
|
||||
mUserExpert := model.NewUserExpert()
|
||||
|
||||
uids := make([]uint64, 0)
|
||||
|
||||
err := model2.Pluck(mUserExpert.UserExpert, "uid", &uids, model2.NewWhere("expert_id", id),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(uids) <= 0 {
|
||||
return nil
|
||||
}
|
||||
data := make([]*model2.UserPatent, 0)
|
||||
|
||||
for _, uid := range uids {
|
||||
for _, v := range patentID {
|
||||
data = append(data, &model2.UserPatent{
|
||||
UID: uid,
|
||||
PatentID: v,
|
||||
})
|
||||
}
|
||||
}
|
||||
if len(data) > 0 {
|
||||
return model2.Creates(model.NewUserPatent().UserPatent, data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PatentUnbind 专利认领解绑
|
||||
func (c *Expert) PatentUnbind(id uint64, patentID []uint64) error {
|
||||
mUserExpert := model.NewUserExpert()
|
||||
|
||||
uids := make([]uint64, 0)
|
||||
|
||||
err := model2.Pluck(mUserExpert.UserExpert, "uid", &uids, model2.NewWhere("expert_id", id),
|
||||
model2.NewWhere("invalid_status", model2.InvalidStatusForNot))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(uids) <= 0 {
|
||||
return nil
|
||||
}
|
||||
return model2.DeleteWhere(model.NewUserPatent().UserPatent, []*model2.ModelWhere{
|
||||
model2.NewWhereIn("uid", uids),
|
||||
model2.NewWhereIn("patent_id", patentID),
|
||||
})
|
||||
}
|
||||
|
||||
func NewExpert() ExpertHandle {
|
||||
return func(session *session.Admin) *Expert {
|
||||
return &Expert{session}
|
||||
|
@ -33,6 +33,11 @@ type (
|
||||
ID string `json:"id"`
|
||||
*model2.TechnologyPatent
|
||||
}
|
||||
// PatentFilterInfo 专利筛选信息
|
||||
PatentFilterInfo struct {
|
||||
Experts []*string
|
||||
Patents []*PatentInfo `json:"patents"`
|
||||
}
|
||||
// PatentParams 专利参数信息
|
||||
PatentParams struct {
|
||||
ID, TenantID uint64
|
||||
@ -92,17 +97,11 @@ func (c *PatentParams) checkParams(iModel *model.TechnologyPatent, condition map
|
||||
}
|
||||
|
||||
// Instance 首页信息
|
||||
func (c *Patent) Instance(tenantID uint64, title, ipc string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
func (c *Patent) Instance(title, ipc string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mSysPatent := model.NewTechnologyPatent()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if c.TenantID > 0 {
|
||||
where = append(where, model2.NewWhere("p.tenant_id", c.TenantID))
|
||||
}
|
||||
if tenantID > 0 {
|
||||
where = append(where, model2.NewWhere("p.tenant_id", tenantID))
|
||||
}
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("p.title", title))
|
||||
}
|
||||
@ -158,14 +157,12 @@ func (c *Patent) Form(params *PatentParams) error {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mTechnologyPatent.TenantID > 0 && c.TenantID != mTechnologyPatent.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
if mTechnologyPatent.ApplyCode != params.ApplyCode {
|
||||
_condition["apply_code"] = params.ApplyCode
|
||||
}
|
||||
if mTechnologyPatent.IPCCode != params.IPCCode {
|
||||
_condition["ipc_code"] = params.IPCCode
|
||||
_condition["open_code"] = params.OpenCode
|
||||
}
|
||||
if len(_condition) > 0 {
|
||||
if isExist, err = mTechnologyPatent.IsExistParams(_condition); err != nil {
|
||||
@ -217,14 +214,13 @@ func (c *Patent) Form(params *PatentParams) error {
|
||||
return nil
|
||||
}
|
||||
_condition["apply_code"] = params.ApplyCode
|
||||
_condition["ipc_code"] = params.IPCCode
|
||||
_condition["open_code"] = params.OpenCode
|
||||
|
||||
if isExist, err := mTechnologyPatent.IsExistParams(_condition); err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,申请号或公开(公告)号已存在")
|
||||
}
|
||||
mTechnologyPatent.TenantID = c.TenantID
|
||||
|
||||
if err := model2.Create(mTechnologyPatent.TechnologyPatent); err != nil {
|
||||
return err
|
||||
@ -234,6 +230,39 @@ func (c *Patent) Form(params *PatentParams) error {
|
||||
return manage.Create()
|
||||
}
|
||||
|
||||
// Filter 筛选信息
|
||||
func (c *Patent) Filter(applyName, inventor string) (*PatentFilterInfo, error) {
|
||||
// 查询用户专家信息
|
||||
mManageResearch := model.NewManageResearch()
|
||||
researchIDs := make([]uint64, 0)
|
||||
|
||||
err := model2.Pluck(mManageResearch.ManageResearch, "id", &researchIDs, model2.NewWhere("name", applyName),
|
||||
model2.NewWhere("examine_status", model2.ExamineStatusForAgree))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(researchIDs) > 0 {
|
||||
// 查询科研机构下专家信息
|
||||
mManageExpert := model.NewManageExpert()
|
||||
|
||||
experts := make([]*model2.ManageExpert, 0)
|
||||
|
||||
if err = model2.ScanFields(mManageExpert.ManageExpert, &experts, []string{"id", "uid", "name", "mobile"},
|
||||
&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("name", inventor),
|
||||
}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("examine_status", model2.ExamineStatusForAgree),
|
||||
}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereIn("research_id", researchIDs),
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
}
|
||||
return &PatentFilterInfo{}, nil
|
||||
}
|
||||
|
||||
// Bind 绑定信息
|
||||
func (c *Patent) Bind(id, uid uint64) error {
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
@ -245,8 +274,6 @@ func (c *Patent) Bind(id, uid uint64) error {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mTechnologyPatent.TenantID > 0 && c.TenantID != mTechnologyPatent.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
if err = model2.Updates(mTechnologyPatent.TechnologyPatent, map[string]interface{}{
|
||||
"uid": uid, "updated_at": time.Now(),
|
||||
@ -267,8 +294,6 @@ func (c *Patent) Delete(id uint64) error {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,专利信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mTechnologyPatent.TenantID > 0 && c.TenantID != mTechnologyPatent.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Delete(mTechnologyPatent.TechnologyPatent, tx); err != nil {
|
||||
|
@ -28,8 +28,54 @@ type (
|
||||
TenantProvince string `json:"-"`
|
||||
TenantCity string `json:"-"`
|
||||
}
|
||||
// ManageExpertUser 专家用户信息
|
||||
ManageExpertUser struct {
|
||||
model.Model
|
||||
Name string `json:"name"`
|
||||
ResearchName string `json:"research_name"`
|
||||
}
|
||||
// ManageExpertPatent 专家专利信息
|
||||
ManageExpertPatent struct {
|
||||
model.Model
|
||||
Title string `json:"title"`
|
||||
ApplyName string `json:"apply_name"`
|
||||
ApplyCode string `json:"apply_code"`
|
||||
ApplyAt string `json:"apply_at"`
|
||||
Inventor string `json:"inventor"`
|
||||
UserPatentCount int64 `json:"-"`
|
||||
}
|
||||
)
|
||||
|
||||
// User 用户专家信息
|
||||
func (m *ManageExpert) User(uid uint64) (*ManageExpertUser, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS e").
|
||||
Select("e.id", "e.name", "r.name AS research_name").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON e.research_id = r.id", model.NewManageResearch().TableName())).
|
||||
Where("e.uid = ?", uid).
|
||||
Where("e.examine_status = ?", model.ExamineStatusForAgree).
|
||||
Where("e.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
out := new(ManageExpertUser)
|
||||
|
||||
err := db.Scan(out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
// User 用户专家信息
|
||||
func (m *ManageExpert) Basic(id uint64) (*ManageExpertUser, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS e").
|
||||
Select("e.id", "e.name", "r.name AS research_name").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON e.research_id = r.id", model.NewManageResearch().TableName())).
|
||||
Where("e.id = ?", id)
|
||||
|
||||
out := new(ManageExpertUser)
|
||||
|
||||
err := db.Scan(out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
// Expert 专家信息
|
||||
func (m *ManageExpert) Expert(id uint64) (*ManageExpertDetail, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS e").
|
||||
@ -59,7 +105,7 @@ func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model
|
||||
"WHERE u.is_deleted = %d AND u.invalid_status = %d GROUP BY u.expert_id) AS u ON e.id = u.expert_id",
|
||||
model.NewUserExpert().TableName(),
|
||||
model.NewTechnologyAchievement().TableName(), model.DeleteStatusForNot, model.TechnologyStatusKindForAgree,
|
||||
model.NewTechnologyPatent().TableName(), model.DeleteStatusForNot,
|
||||
model.NewUserPatent().TableName(), model.DeleteStatusForNot,
|
||||
model.DeleteStatusForNot, model.InvalidStatusForNot)).
|
||||
Where("e.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
@ -80,6 +126,27 @@ func (m *ManageExpert) Experts(page, pageSize int, count *int64, where ...*model
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Patents 专利信息
|
||||
func (m *ManageExpert) Patents(where ...*model.ModelWhere) ([]*ManageExpertPatent, error) {
|
||||
db := orm.GetDB().Table(model.NewTechnologyPatent().TableName()+" AS p").
|
||||
Select("p.id", "p.title", "p.apply_name", "p.apply_code", "p.apply_at", "p.inventor", "u.count AS user_patent_count").
|
||||
Joins(fmt.Sprintf("LEFT JOIN (SELECT patent_id, COUNT(patent_id) AS count FROM %s WHERE is_deleted = %d GROUP BY patent_id) AS u ON p.id = u.patent_id",
|
||||
model.NewUserPatent().TableName(), model.DeleteStatusForNot)).
|
||||
Where("p.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*ManageExpertPatent, 0)
|
||||
|
||||
if err := db.Order("p.id " + model.OrderModeToDesc).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewManageExpert() *ManageExpert {
|
||||
return &ManageExpert{model.NewManageExpert()}
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ func (c *PatentParams) add(tenantID, uid uint64) error {
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mTechnologyPatent.Kind = model2.TechnologyPatentKind(c.Kind)
|
||||
mTechnologyPatent.TenantID = tenantID
|
||||
mTechnologyPatent.Title = c.Title
|
||||
mTechnologyPatent.FileUrl = c.FileUrl
|
||||
mTechnologyPatent.ApplyCode = c.ApplyCode
|
||||
|
@ -31,7 +31,6 @@ func (m *TechnologyPatent) Instance(where ...*model.ModelWhere) ([]*TechnologyPa
|
||||
Select("p.id", "p.title", "LEFT(p.description, 80) AS description", "p.apply_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON p.ipc_code = c.ipc AND c.is_deleted = %d",
|
||||
model.NewTechnologyPatentClassify().TableName(), model.DeleteStatusForNot)).
|
||||
Where("p.shelf_status = ?", model.ShelfStatusForUp).
|
||||
Where("p.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
|
@ -33,7 +33,7 @@ type (
|
||||
// PatentInfo 专利信息
|
||||
PatentInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model.TechnologyPatentBasicInfo
|
||||
*model.UserPatentInfo
|
||||
}
|
||||
// PaperInfo 论文信息
|
||||
PaperInfo struct {
|
||||
@ -122,25 +122,20 @@ func project(uids []uint64, page, pageSize int) (*controller.ReturnPages, error)
|
||||
|
||||
// patent 专利信息
|
||||
func patent(uids []uint64, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mTechnologyPatent := model.NewTechnologyPatent()
|
||||
var count int64
|
||||
out := make([]*model.TechnologyPatentBasicInfo, 0)
|
||||
mUserPatent := model.NewUserPatent()
|
||||
|
||||
if err := model2.PagesFields(mTechnologyPatent.TechnologyPatent, &out, []string{
|
||||
"id", "title", "apply_at", "description",
|
||||
}, page, pageSize, &count, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("uid", uids),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("shelf_status", model2.ShelfStatusForUp),
|
||||
}); err != nil {
|
||||
var count int64
|
||||
|
||||
out, err := mUserPatent.Patents(uids, page, pageSize, &count)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*PatentInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &PatentInfo{
|
||||
ID: v.GetEncodeID(), TechnologyPatentBasicInfo: v,
|
||||
ID: v.GetEncodeID(), UserPatentInfo: v,
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
|
@ -58,9 +58,9 @@ func (m *ManageExpert) Detail(limit int, id uint64) (*ManageExpertInfo, error) {
|
||||
"e.introduce", "p.title AS patent_title", "r.name AS research_name").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS e_u ON e.id = e_u.expert_id AND e_u.invalid_status = %d AND e_u.is_deleted = %d",
|
||||
model.NewUserExpert().TableName(), model.InvalidStatusForNot, model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf(`LEFT JOIN (SELECT uid, SUBSTRING_INDEX(GROUP_CONCAT(kind, '$$', title ORDER BY id DESC SEPARATOR '&&'), '&&', %d) AS title
|
||||
FROM %s WHERE is_deleted = %d AND shelf_status = %d GROUP BY uid) AS p ON e_u.uid = p.uid`,
|
||||
limit, mTechnologyPatent.TableName(), model.DeleteStatusForNot, model.ShelfStatusForUp)).
|
||||
Joins(fmt.Sprintf(`LEFT JOIN (SELECT u.uid, SUBSTRING_INDEX(GROUP_CONCAT(p.kind, '$$', p.title ORDER BY p.id DESC SEPARATOR '&&'), '&&', %d) AS title
|
||||
FROM %s AS u LEFT JOIN %s AS p ON u.patent_id = p.id WHERE u.is_deleted = %d GROUP BY u.uid) AS p ON e_u.uid = p.uid`,
|
||||
limit, model.NewUserPatent().TableName(), mTechnologyPatent.TableName(), model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON e.research_id = r.id", model.NewManageResearch().TableName())).
|
||||
Where("e.id = ?", id)
|
||||
|
||||
|
@ -18,23 +18,12 @@ type TechnologyPatentInfo struct {
|
||||
ApplyAt string `json:"apply_at"`
|
||||
}
|
||||
|
||||
type (
|
||||
// TechnologyPatentBasicInfo 专利信息
|
||||
TechnologyPatentBasicInfo struct {
|
||||
model.Model
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
ApplyAt string `json:"apply_at"`
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 专利信息
|
||||
func (m *TechnologyPatent) Instance(where ...*model.ModelWhere) ([]*TechnologyPatentInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS p").
|
||||
Select("p.id", "p.title", "LEFT(p.description, 80) AS description", "p.apply_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON p.ipc_code = c.ipc AND c.is_deleted = %d",
|
||||
model.NewTechnologyPatentClassify().TableName(), model.DeleteStatusForNot)).
|
||||
Where("p.shelf_status = ?", model.ShelfStatusForUp).
|
||||
Where("p.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
@ -56,7 +45,6 @@ func (m *TechnologyPatent) Patents(page, pageSize int, count *int64, where ...*m
|
||||
Select("p.id", "p.title", "LEFT(p.description, 80) AS description", "p.apply_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON p.ipc_code = c.ipc AND c.is_deleted = %d",
|
||||
model.NewTechnologyPatentClassify().TableName(), model.DeleteStatusForNot)).
|
||||
Where("p.shelf_status = ?", model.ShelfStatusForUp).
|
||||
Where("p.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
@ -87,7 +75,6 @@ func (m *TechnologyPatent) Distribution() ([]*DataAreaDistributionInfo, error) {
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u_e ON p.uid = u_e.uid", model.NewUserExpert().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON u_e.expert_id = e.id", model.NewManageExpert().TableName())).
|
||||
Where("p.is_deleted = ?", model.DeleteStatusForNot).
|
||||
Where("p.shelf_status = ?", model.ShelfStatusForUp).
|
||||
Group("e.province").Group("e.city").Group("e.district").
|
||||
Order("e.province " + model.OrderModeToAsc).Order("e.city " + model.OrderModeToAsc).Order("e.district " + model.OrderModeToAsc).
|
||||
Scan(&out).Error
|
||||
|
52
app/api/website/model/user_patent.go
Normal file
52
app/api/website/model/user_patent.go
Normal file
@ -0,0 +1,52 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type UserPatent struct {
|
||||
*model.UserPatent
|
||||
}
|
||||
|
||||
type UserPatentInfo struct {
|
||||
model.Model
|
||||
Title string `json:"title"`
|
||||
ApplyAt string `json:"apply_at"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// Patents 专利信息
|
||||
func (m *UserPatent) Patents(uid []uint64, page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*UserPatentInfo, error) {
|
||||
_uids := make([]string, 0)
|
||||
|
||||
for _, u := range uid {
|
||||
_uids = append(_uids, fmt.Sprintf("%d", u))
|
||||
}
|
||||
db := orm.GetDB().Table(model.NewTechnologyPatent().TableName()+" AS p").
|
||||
Select("p.id", "p.title", "p.apply_at", "p.description").
|
||||
Joins(fmt.Sprintf("RIGHT JOIN (SELECT patent_id FROM %s WHERE uid IN (%v) is_deleted = %d patent_id) AS u ON p.id = u.patent_id",
|
||||
model.NewTechnologyPatent().TableName(), strings.Join(_uids, ","), model.DeleteStatusForNot)).
|
||||
Where("u.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*UserPatentInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewUserPatent() *UserPatent {
|
||||
return &UserPatent{model.NewUserPatent()}
|
||||
}
|
@ -48,7 +48,7 @@ func mysql() *gorm.DB {
|
||||
orm.WithMaxOpenConns(2000),
|
||||
orm.WithMaxLifetime(1000),
|
||||
orm.WithMysqlOption(&logic.Mysql{
|
||||
Username: "appuser", Password: "ABCabc01!", Host: "192.168.0.188", Port: 3306,
|
||||
Username: "appuser", Password: "ABCabc01", Host: "192.168.0.188", Port: 3306,
|
||||
Database: "sciences", Parameters: "charset=utf8mb4,utf8&parseTime=True&loc=Local",
|
||||
}),
|
||||
).Init()
|
||||
@ -129,7 +129,6 @@ func TestRecoveryPatent(t *testing.T) {
|
||||
Description: filter(v.Description),
|
||||
PrincipalClaim: filter(v.PrincipalClaim),
|
||||
IPCCode: v.IPCCode,
|
||||
Shelf: Shelf{ShelfStatus: 1},
|
||||
ModelAt: ModelAt{
|
||||
CreatedAt: now, UpdatedAt: now,
|
||||
},
|
||||
@ -146,6 +145,48 @@ func TestRecoveryPatent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestB(t *testing.T) {
|
||||
page := 1
|
||||
|
||||
mysql := mysql()
|
||||
|
||||
mTechnologyPatent := new(TechnologyPatent)
|
||||
|
||||
limit := 100
|
||||
|
||||
out := make([]*TechnologyPatent, 0)
|
||||
|
||||
for {
|
||||
err := mysql.Table(mTechnologyPatent.TableName()).Select("id", "apply_code", "apply_at", "open_code",
|
||||
"apply_name", "inventor").
|
||||
Offset((page - 1) * limit).Limit(limit).
|
||||
Scan(&out).Error
|
||||
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
if len(out) <= 0 {
|
||||
t.Log("执行结束")
|
||||
return
|
||||
}
|
||||
for _, v := range out {
|
||||
if err = mysql.Table(mTechnologyPatent.TableName()).Where("id = ?", v.ID).Updates(map[string]interface{}{
|
||||
"apply_code": strings.TrimLeft(v.ApplyCode, " "),
|
||||
"apply_at": strings.TrimLeft(v.ApplyAt, " "),
|
||||
"open_code": strings.TrimLeft(v.OpenCode, " "),
|
||||
"apply_name": strings.Join(strings.Split(v.ApplyName, ";"), ","),
|
||||
"inventor": strings.Join(strings.Split(v.Inventor, ";"), ","),
|
||||
}).Error; err != nil {
|
||||
t.Error("Mysql:" + err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
page++
|
||||
out = make([]*TechnologyPatent, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func TestA(t *testing.T) {
|
||||
return
|
||||
mysql := mysql()
|
||||
|
@ -3,7 +3,6 @@ package model
|
||||
// TechnologyPatent 专利信息数据模型
|
||||
type TechnologyPatent struct {
|
||||
Model
|
||||
ModelTenant
|
||||
Kind TechnologyPatentKind `gorm:"column:kind;index:idx_sys_patent_kind;type:tinyint(1);default:0;comment:专利类型" json:"kind"`
|
||||
Title string `gorm:"column:title;type:varchar(100);default:'';comment:名称标题" json:"title"`
|
||||
FileUrl string `gorm:"column:file_url;type:varchar(255);default:'';comment:文件地址" json:"file_url"`
|
||||
|
@ -302,6 +302,9 @@ func registerAdminAPI(app *gin.Engine) {
|
||||
manage.POST("/expert/edit", _api.ExpertForm)
|
||||
manage.POST("/expert/detail", _api.ExpertDetail)
|
||||
manage.POST("/expert/examine", _api.ExpertExamine)
|
||||
manage.POST("/expert/patent", _api.ExpertPatent)
|
||||
manage.POST("/expert/patent/bind", _api.ExpertPatentBind(true))
|
||||
manage.POST("/expert/patent/unbind", _api.ExpertPatentBind(false))
|
||||
manage.POST("/research", _api.Research)
|
||||
manage.POST("/research/select", _api.ResearchSelect)
|
||||
manage.POST("/research/add", _api.ResearchForm)
|
||||
|
@ -74,7 +74,7 @@ func TestNewInstanceSearch(t *testing.T) {
|
||||
query := elastic.NewBoolQuery()
|
||||
//query.Must(elastic.NewMatchQuery("age", "27"))
|
||||
|
||||
service := client.Search().Index("student")
|
||||
service := client.Search().Index("es_achievement_index")
|
||||
|
||||
result, err := service.Pretty(true).Query(query).Do(context.Background())
|
||||
|
||||
|
Reference in New Issue
Block a user