作者 王健

新增【公司-领域模型】

@@ -2,22 +2,13 @@ package domain @@ -2,22 +2,13 @@ package domain
2 2
3 // 公司信息 3 // 公司信息
4 type CompanyInfo struct { 4 type CompanyInfo struct {
5 - // 公司Id  
6 - CompanyId int64 `json:"companyId"`  
7 - // 公司名称  
8 - Name string `json:"name"`  
9 - // 公司简称  
10 - Abbreviation string `json:"abbreviation"`  
11 - // 公司logo  
12 - Logo string `json:"logo"`  
13 - // 公司联系电话  
14 - Phone string `json:"phone"`  
15 - // 状态 1正常 2禁用  
16 - Status int64 `json:"status"`  
17 - // 备注  
18 - Remarks string `json:"remarks"`  
19 - // 是否有效【1:有效】【2:无效】  
20 - Enable int64 `json:"enable"`  
21 - // 公司主管理员  
22 - Admin *UserInfo `json:"admin"` 5 + CompanyId int64 `json:"companyId"` // 公司Id
  6 + Name string `json:"name"` // 公司名称
  7 + Abbreviation string `json:"abbreviation"` // 公司简称
  8 + Logo string `json:"logo"` // 公司logo
  9 + Phone string `json:"phone"` // 公司联系电话
  10 + Status int64 `json:"status"` // 状态 1正常 2禁用
  11 + Remarks string `json:"remarks"` // 备注
  12 + Enable int64 `json:"enable"` // 是否有效【1:有效】【2:无效】
  13 + Admin UserInfo `json:"admin"` // 公司主管理员
23 } 14 }
@@ -6,7 +6,7 @@ import ( @@ -6,7 +6,7 @@ import (
6 ) 6 )
7 7
8 type Company struct { 8 type Company struct {
9 - tableName string `pg:"companys,alias:company"` 9 + tableName string `pg:"companies,alias:company"`
10 // 公司Id 10 // 公司Id
11 CompanyId int64 `pg:",pk"` 11 CompanyId int64 `pg:",pk"`
12 // 公司信息 12 // 公司信息
@@ -53,7 +53,9 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp @@ -53,7 +53,9 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp
53 &company.UpdateAt, 53 &company.UpdateAt,
54 &company.DeleteAt, 54 &company.DeleteAt,
55 ), 55 ),
56 - fmt.Sprintf("INSERT INTO companys (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), 56 +
  57 + fmt.Sprintf("INSERT INTO companies (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
  58 +
57 company.CompanyId, 59 company.CompanyId,
58 company.CompanyInfo, 60 company.CompanyInfo,
59 company.CreateAt, 61 company.CreateAt,
@@ -71,7 +73,9 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp @@ -71,7 +73,9 @@ func (repository *CompanyRepository) Save(company *domain.Company) (*domain.Comp
71 &company.UpdateAt, 73 &company.UpdateAt,
72 &company.DeleteAt, 74 &company.DeleteAt,
73 ), 75 ),
74 - fmt.Sprintf("UPDATE companys SET %s WHERE company_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), 76 +
  77 + fmt.Sprintf("UPDATE companies SET %s WHERE company_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
  78 +
75 company.CompanyId, 79 company.CompanyId,
76 company.CompanyInfo, 80 company.CompanyInfo,
77 company.CreateAt, 81 company.CreateAt,
@@ -115,21 +119,23 @@ func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{} @@ -115,21 +119,23 @@ func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{}
115 func (repository *CompanyRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Company, error) { 119 func (repository *CompanyRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Company, error) {
116 tx := repository.transactionContext.PgTx 120 tx := repository.transactionContext.PgTx
117 var companyModels []*models.Company 121 var companyModels []*models.Company
118 - companys := make([]*domain.Company, 0) 122 +
  123 + companies := make([]*domain.Company, 0)
  124 +
119 query := sqlbuilder.BuildQuery(tx.Model(&companyModels), queryOptions) 125 query := sqlbuilder.BuildQuery(tx.Model(&companyModels), queryOptions)
120 query.SetOffsetAndLimit(20) 126 query.SetOffsetAndLimit(20)
121 query.SetOrderDirect("company_id", "DESC") 127 query.SetOrderDirect("company_id", "DESC")
122 if count, err := query.SelectAndCount(); err != nil { 128 if count, err := query.SelectAndCount(); err != nil {
123 - return 0, companys, err 129 + return 0, companies, err
124 } else { 130 } else {
125 for _, companyModel := range companyModels { 131 for _, companyModel := range companyModels {
126 if company, err := transform.TransformToCompanyDomainModelFromPgModels(companyModel); err != nil { 132 if company, err := transform.TransformToCompanyDomainModelFromPgModels(companyModel); err != nil {
127 - return 0, companys, err 133 + return 0, companies, err
128 } else { 134 } else {
129 - companys = append(companys, company) 135 + companies = append(companies, company)
130 } 136 }
131 } 137 }
132 - return int64(count), companys, nil 138 + return int64(count), companies, nil
133 } 139 }
134 } 140 }
135 func NewCompanyRepository(transactionContext *pgTransaction.TransactionContext) (*CompanyRepository, error) { 141 func NewCompanyRepository(transactionContext *pgTransaction.TransactionContext) (*CompanyRepository, error) {