pg_cooperation_application_dao.go
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
type CooperationApplicationDao struct {
transactionContext *pgTransaction.TransactionContext
}
// CheckApplicationExist 判断该申请人是否提交过申请
func (dao *CooperationApplicationDao) CheckApplicationExist(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var cooperationApplicationModels []*models.CooperationApplication
query := tx.Model(&cooperationApplicationModels)
if cooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && cooperationProjectNumber != "" {
query = query.Where("cooperation_project_number = ?", cooperationProjectNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`cooperation_application.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`cooperation_application.org @> '{"orgId":"?"}'`, orgId)
}
if applicantId, ok := queryOptions["applicantId"]; ok && applicantId.(int64) != 0 {
query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userId":"?"}'`, applicantId)
}
if visitorUserBaseId, ok := queryOptions["visitorUserBaseId"]; ok && visitorUserBaseId.(int64) != 0 {
query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userBaseId":"?"}'`, visitorUserBaseId)
}
if applicantBaseId, ok := queryOptions["applicantBaseId"]; ok && applicantBaseId.(int64) != 0 {
query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userBaseId":"?"}'`, applicantBaseId)
}
ok, err := query.Exists()
return ok, err
}
func NewCooperationApplicationDao(transactionContext *pgTransaction.TransactionContext) (*CooperationApplicationDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CooperationApplicationDao{
transactionContext: transactionContext,
}, nil
}
}