作者 唐旭辉

修改 同步的公司数据

@@ -16,6 +16,12 @@ type SyncCompanyService struct{} @@ -16,6 +16,12 @@ type SyncCompanyService struct{}
16 16
17 var _ SyncAction = (*SyncCompanyService)(nil) 17 var _ SyncAction = (*SyncCompanyService)(nil)
18 18
  19 +type CompanyBaseApplet struct {
  20 + Name string `json:"name"`
  21 + URL string `json:"url"`
  22 + Id string `json:"id"`
  23 +}
  24 +
19 //企业平台的公司基础数据 25 //企业平台的公司基础数据
20 type CompanyBase struct { 26 type CompanyBase struct {
21 Id int64 `json:"id"` //id 27 Id int64 `json:"id"` //id
@@ -23,7 +29,8 @@ type CompanyBase struct { @@ -23,7 +29,8 @@ type CompanyBase struct {
23 AdminCompanyId int `json:"admin_company_id"` //总后台的公司id 29 AdminCompanyId int `json:"admin_company_id"` //总后台的公司id
24 Logo string `json:"logo"` //公司图标 30 Logo string `json:"logo"` //公司图标
25 Remarks string `json:"remarks"` //备注 31 Remarks string `json:"remarks"` //备注
26 - Abbreviation string `json:"abbreviation"` 32 + Abbreviation string `json:"abbreviation"` //公司简称
  33 + Applets []CompanyBaseApplet `json:"applets"` //公司对接的小程序
27 } 34 }
28 35
29 // CompanytData 企业平台发送过来的公司数据数据 36 // CompanytData 企业平台发送过来的公司数据数据
@@ -115,6 +122,16 @@ func (service SyncCompanyService) addCompany(data CompanytData) error { @@ -115,6 +122,16 @@ func (service SyncCompanyService) addCompany(data CompanytData) error {
115 Enable: domain.CompanyEnableYes, //默认初始化值 122 Enable: domain.CompanyEnableYes, //默认初始化值
116 Abbreviation: data.Company.Abbreviation, 123 Abbreviation: data.Company.Abbreviation,
117 } 124 }
  125 + applets := []domain.CompanyApplets{}
  126 + for _, v := range data.Company.Applets {
  127 + app := domain.CompanyApplets{
  128 + Name: v.Name,
  129 + URL: v.URL,
  130 + Id: v.Id,
  131 + }
  132 + applets = append(applets, app)
  133 + }
  134 + comany.Applets = applets
118 err = companyRespository.Add(&comany) 135 err = companyRespository.Add(&comany)
119 if err != nil { 136 if err != nil {
120 return fmt.Errorf("添加公司数据失败,%s", err) 137 return fmt.Errorf("添加公司数据失败,%s", err)
@@ -192,6 +209,7 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error { @@ -192,6 +209,7 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error {
192 "Remarks": data.Company.Remarks, 209 "Remarks": data.Company.Remarks,
193 "AdminCompanyId": data.Company.AdminCompanyId, 210 "AdminCompanyId": data.Company.AdminCompanyId,
194 "Abbreviation": data.Company.Abbreviation, 211 "Abbreviation": data.Company.Abbreviation,
  212 + "Applets": data.Company.Applets,
195 }) 213 })
196 for i := range oldCompanyAdmins { 214 for i := range oldCompanyAdmins {
197 oldCompanyAdmins[i].Update(map[string]interface{}{ 215 oldCompanyAdmins[i].Update(map[string]interface{}{
@@ -17,6 +17,12 @@ const ( @@ -17,6 +17,12 @@ const (
17 CompanyEnableNo int8 = 2 17 CompanyEnableNo int8 = 2
18 ) 18 )
19 19
  20 +type CompanyApplets struct {
  21 + Name string `json:"name"`
  22 + URL string `json:"url"`
  23 + Id string `json:"id"`
  24 +}
  25 +
20 // 公司信息 26 // 公司信息
21 type Company struct { 27 type Company struct {
22 // 唯一标识 28 // 唯一标识
@@ -41,6 +47,7 @@ type Company struct { @@ -41,6 +47,7 @@ type Company struct {
41 UpdateAt time.Time `json:"updateAt"` 47 UpdateAt time.Time `json:"updateAt"`
42 // 删除时间 48 // 删除时间
43 DeleteAt time.Time `json:"deleteAt"` 49 DeleteAt time.Time `json:"deleteAt"`
  50 + Applets []CompanyApplets `json:"applets"`
44 } 51 }
45 52
46 func (c Company) EnableIsOk() bool { 53 func (c Company) EnableIsOk() bool {
@@ -72,6 +79,9 @@ func (c *Company) Update(m map[string]interface{}) error { @@ -72,6 +79,9 @@ func (c *Company) Update(m map[string]interface{}) error {
72 if v, ok := m["Abbreviation"]; ok { 79 if v, ok := m["Abbreviation"]; ok {
73 c.Abbreviation = v.(string) 80 c.Abbreviation = v.(string)
74 } 81 }
  82 + if v, ok := m["Applets"]; ok {
  83 + c.Applets = v.([]CompanyApplets)
  84 + }
75 return nil 85 return nil
76 } 86 }
77 87
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "time" 5 "time"
6 6
7 "github.com/go-pg/pg/v10" 7 "github.com/go-pg/pg/v10"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
8 ) 9 )
9 10
10 // 公司信息 11 // 公司信息
@@ -34,6 +35,8 @@ type Company struct { @@ -34,6 +35,8 @@ type Company struct {
34 UpdateAt time.Time 35 UpdateAt time.Time
35 // 删除时间 36 // 删除时间
36 DeleteAt time.Time 37 DeleteAt time.Time
  38 +
  39 + Applets []domain.CompanyApplets
37 } 40 }
38 41
39 var _ pg.BeforeUpdateHook = (*Company)(nil) 42 var _ pg.BeforeUpdateHook = (*Company)(nil)
@@ -36,6 +36,7 @@ func (repository CompanyRepository) transformPgModelToDomainModel(m *models.Comp @@ -36,6 +36,7 @@ func (repository CompanyRepository) transformPgModelToDomainModel(m *models.Comp
36 CreateAt: m.CreateAt, 36 CreateAt: m.CreateAt,
37 UpdateAt: m.UpdateAt, 37 UpdateAt: m.UpdateAt,
38 Abbreviation: m.Abbreviation, 38 Abbreviation: m.Abbreviation,
  39 + Applets: m.Applets,
39 }, nil 40 }, nil
40 } 41 }
41 42
@@ -55,6 +56,7 @@ func (reponsitory CompanyRepository) Add(m *domain.Company) error { @@ -55,6 +56,7 @@ func (reponsitory CompanyRepository) Add(m *domain.Company) error {
55 CreateAt: m.CreateAt, 56 CreateAt: m.CreateAt,
56 UpdateAt: m.UpdateAt, 57 UpdateAt: m.UpdateAt,
57 Abbreviation: m.Abbreviation, 58 Abbreviation: m.Abbreviation,
  59 + Applets: m.Applets,
58 } 60 }
59 _, err = tx.Model(&companyModel).Insert() 61 _, err = tx.Model(&companyModel).Insert()
60 return err 62 return err
@@ -77,6 +79,7 @@ func (reponsitory CompanyRepository) Edit(m *domain.Company) error { @@ -77,6 +79,7 @@ func (reponsitory CompanyRepository) Edit(m *domain.Company) error {
77 DeleteAt: m.DeleteAt, 79 DeleteAt: m.DeleteAt,
78 UpdateAt: m.UpdateAt, 80 UpdateAt: m.UpdateAt,
79 Abbreviation: m.Abbreviation, 81 Abbreviation: m.Abbreviation,
  82 + Applets: m.Applets,
80 } 83 }
81 _, err = tx.Model(&companyModel).WherePK().Update() 84 _, err = tx.Model(&companyModel).WherePK().Update()
82 return err 85 return err