作者 唐旭辉

修改 同步的公司数据

... ... @@ -16,6 +16,12 @@ type SyncCompanyService struct{}
var _ SyncAction = (*SyncCompanyService)(nil)
type CompanyBaseApplet struct {
Name string `json:"name"`
URL string `json:"url"`
Id string `json:"id"`
}
//企业平台的公司基础数据
type CompanyBase struct {
Id int64 `json:"id"` //id
... ... @@ -23,7 +29,8 @@ type CompanyBase struct {
AdminCompanyId int `json:"admin_company_id"` //总后台的公司id
Logo string `json:"logo"` //公司图标
Remarks string `json:"remarks"` //备注
Abbreviation string `json:"abbreviation"`
Abbreviation string `json:"abbreviation"` //公司简称
Applets []CompanyBaseApplet `json:"applets"` //公司对接的小程序
}
// CompanytData 企业平台发送过来的公司数据数据
... ... @@ -115,6 +122,16 @@ func (service SyncCompanyService) addCompany(data CompanytData) error {
Enable: domain.CompanyEnableYes, //默认初始化值
Abbreviation: data.Company.Abbreviation,
}
applets := []domain.CompanyApplets{}
for _, v := range data.Company.Applets {
app := domain.CompanyApplets{
Name: v.Name,
URL: v.URL,
Id: v.Id,
}
applets = append(applets, app)
}
comany.Applets = applets
err = companyRespository.Add(&comany)
if err != nil {
return fmt.Errorf("添加公司数据失败,%s", err)
... ... @@ -192,6 +209,7 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error {
"Remarks": data.Company.Remarks,
"AdminCompanyId": data.Company.AdminCompanyId,
"Abbreviation": data.Company.Abbreviation,
"Applets": data.Company.Applets,
})
for i := range oldCompanyAdmins {
oldCompanyAdmins[i].Update(map[string]interface{}{
... ...
... ... @@ -17,6 +17,12 @@ const (
CompanyEnableNo int8 = 2
)
type CompanyApplets struct {
Name string `json:"name"`
URL string `json:"url"`
Id string `json:"id"`
}
// 公司信息
type Company struct {
// 唯一标识
... ... @@ -41,6 +47,7 @@ type Company struct {
UpdateAt time.Time `json:"updateAt"`
// 删除时间
DeleteAt time.Time `json:"deleteAt"`
Applets []CompanyApplets `json:"applets"`
}
func (c Company) EnableIsOk() bool {
... ... @@ -72,6 +79,9 @@ func (c *Company) Update(m map[string]interface{}) error {
if v, ok := m["Abbreviation"]; ok {
c.Abbreviation = v.(string)
}
if v, ok := m["Applets"]; ok {
c.Applets = v.([]CompanyApplets)
}
return nil
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"time"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
// 公司信息
... ... @@ -34,6 +35,8 @@ type Company struct {
UpdateAt time.Time
// 删除时间
DeleteAt time.Time
Applets []domain.CompanyApplets
}
var _ pg.BeforeUpdateHook = (*Company)(nil)
... ...
... ... @@ -36,6 +36,7 @@ func (repository CompanyRepository) transformPgModelToDomainModel(m *models.Comp
CreateAt: m.CreateAt,
UpdateAt: m.UpdateAt,
Abbreviation: m.Abbreviation,
Applets: m.Applets,
}, nil
}
... ... @@ -55,6 +56,7 @@ func (reponsitory CompanyRepository) Add(m *domain.Company) error {
CreateAt: m.CreateAt,
UpdateAt: m.UpdateAt,
Abbreviation: m.Abbreviation,
Applets: m.Applets,
}
_, err = tx.Model(&companyModel).Insert()
return err
... ... @@ -77,6 +79,7 @@ func (reponsitory CompanyRepository) Edit(m *domain.Company) error {
DeleteAt: m.DeleteAt,
UpdateAt: m.UpdateAt,
Abbreviation: m.Abbreviation,
Applets: m.Applets,
}
_, err = tx.Model(&companyModel).WherePK().Update()
return err
... ...