作者 陈志颖

fix:修改新增公司增加栏目设置

@@ -100,8 +100,9 @@ func (service SyncCompanyService) addCompany(data CompanytData) error { @@ -100,8 +100,9 @@ func (service SyncCompanyService) addCompany(data CompanytData) error {
100 transactionContext.RollbackTransaction() 100 transactionContext.RollbackTransaction()
101 }() 101 }()
102 var ( 102 var (
103 - companyRespository domain.CompanyRepository  
104 - userRespository domain.UsersRepository 103 + companyRespository domain.CompanyRepository
  104 + userRespository domain.UsersRepository
  105 + columnSettingRepository domain.ColumnSettingRepository
105 ) 106 )
106 if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{ 107 if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{
107 "transactionContext": transactionContext, 108 "transactionContext": transactionContext,
@@ -113,6 +114,11 @@ func (service SyncCompanyService) addCompany(data CompanytData) error { @@ -113,6 +114,11 @@ func (service SyncCompanyService) addCompany(data CompanytData) error {
113 }); err != nil { 114 }); err != nil {
114 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 115 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
115 } 116 }
  117 + if columnSettingRepository, err = factory.CreateColumnSettingRepository(map[string]interface{}{
  118 + "transactionContext": transactionContext,
  119 + }); err != nil {
  120 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  121 + }
116 applets := []domain.CompanyApplets{} 122 applets := []domain.CompanyApplets{}
117 for _, v := range data.Company.Applets { 123 for _, v := range data.Company.Applets {
118 app := domain.CompanyApplets{ 124 app := domain.CompanyApplets{
@@ -164,6 +170,21 @@ func (service SyncCompanyService) addCompany(data CompanytData) error { @@ -164,6 +170,21 @@ func (service SyncCompanyService) addCompany(data CompanytData) error {
164 if err != nil { 170 if err != nil {
165 return fmt.Errorf("添加用户数据失败,%s", err) 171 return fmt.Errorf("添加用户数据失败,%s", err)
166 } 172 }
  173 + // 初始化栏目设置
  174 + newColumnSetting := &domain.ColumnSetting{
  175 + Description: "订单管理栏目设置",
  176 + UserName: data.User.Name,
  177 + CompanyId: int(data.User.CompanyId),
  178 + Uid: data.User.Id,
  179 + Key: constant.ORDER_BASE, // 订单栏目模块名称
  180 + Value: domain.DefaultColumns, // 栏目值数组,创建用户时使用默认栏目设置
  181 + InvalidValue: domain.DefaultInvalidColumns, // 初始化无效栏目数组
  182 + CreatedAt: time.Now(),
  183 + UpdatedAt: time.Now(),
  184 + }
  185 + if _, err = columnSettingRepository.Save(newColumnSetting); err != nil {
  186 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  187 + }
167 err = transactionContext.CommitTransaction() 188 err = transactionContext.CommitTransaction()
168 return nil 189 return nil
169 } 190 }
@@ -197,12 +218,6 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error { @@ -197,12 +218,6 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error {
197 }); err != nil { 218 }); err != nil {
198 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 219 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
199 } 220 }
200 - var columnSettingRepository domain.ColumnSettingRepository  
201 - if columnSettingRepository, err = factory.CreateColumnSettingRepository(map[string]interface{}{  
202 - "transactionContext": transactionContext,  
203 - }); err != nil {  
204 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
205 - }  
206 oldCompany, err = companyRespository.FindOne(domain.CompanyFindOneOptions{ 221 oldCompany, err = companyRespository.FindOne(domain.CompanyFindOneOptions{
207 Id: data.Company.Id, 222 Id: data.Company.Id,
208 }) 223 })
@@ -284,21 +299,6 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error { @@ -284,21 +299,6 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error {
284 if err != nil { 299 if err != nil {
285 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 300 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
286 } 301 }
287 - // 初始化栏目设置  
288 - newColumnSetting := &domain.ColumnSetting{  
289 - Description: "订单管理栏目设置",  
290 - UserName: data.User.Name,  
291 - CompanyId: int(data.User.CompanyId),  
292 - Uid: data.User.Id,  
293 - Key: constant.ORDER_BASE, // 订单栏目模块名称  
294 - Value: domain.DefaultColumns, // 栏目值数组,创建用户时使用默认栏目设置  
295 - InvalidValue: domain.DefaultInvalidColumns, // 初始化无效栏目数组  
296 - CreatedAt: time.Now(),  
297 - UpdatedAt: time.Now(),  
298 - }  
299 - if _, err = columnSettingRepository.Save(newColumnSetting); err != nil {  
300 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
301 - }  
302 err = transactionContext.CommitTransaction() 302 err = transactionContext.CommitTransaction()
303 return nil 303 return nil
304 } 304 }