作者 陈志颖

fix:更新无可更新数据时添加栏目设置

@@ -88,7 +88,7 @@ var _ SyncAction = (*SyncEmployeeService)(nil) @@ -88,7 +88,7 @@ var _ SyncAction = (*SyncEmployeeService)(nil)
88 88
89 /** 89 /**
90 * @Author SteveChan 90 * @Author SteveChan
91 - * @Description //TODO 新增、导入用户初始化栏目设置 91 + * @Description //新增、导入用户初始化栏目设置
92 * @Date 23:54 2021/1/26 92 * @Date 23:54 2021/1/26
93 * @Param 93 * @Param
94 * @return 94 * @return
@@ -263,6 +263,12 @@ func (service SyncEmployeeService) updateEmployeeData(datas []EmployeeData) erro @@ -263,6 +263,12 @@ func (service SyncEmployeeService) updateEmployeeData(datas []EmployeeData) erro
263 }); err != nil { 263 }); err != nil {
264 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 264 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
265 } 265 }
  266 + var columnSettingRepository domain.ColumnSettingRepository
  267 + if columnSettingRepository, err = factory.CreateColumnSettingRepository(map[string]interface{}{
  268 + "transactionContext": transactionContext,
  269 + }); err != nil {
  270 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  271 + }
266 for i := range datas { 272 for i := range datas {
267 data := datas[i] 273 data := datas[i]
268 var ( 274 var (
@@ -302,6 +308,21 @@ func (service SyncEmployeeService) updateEmployeeData(datas []EmployeeData) erro @@ -302,6 +308,21 @@ func (service SyncEmployeeService) updateEmployeeData(datas []EmployeeData) erro
302 if err = usersRepository.Add(&newUser); err != nil { 308 if err = usersRepository.Add(&newUser); err != nil {
303 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 309 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
304 } 310 }
  311 + // 添加用户数据时初始化栏目设置
  312 + newColumnSetting := &domain.ColumnSetting{
  313 + Description: "订单管理栏目设置",
  314 + UserName: data.Name,
  315 + CompanyId: int(data.CompanyId),
  316 + Uid: data.Id,
  317 + Key: constant.ORDER_BASE, // 订单栏目模块名称
  318 + Value: domain.DefaultColumns, // 栏目值数组,创建用户时使用默认栏目设置
  319 + InvalidValue: domain.DefaultInvalidColumns, // 初始化无效栏目数组
  320 + CreatedAt: time.Now(),
  321 + UpdatedAt: time.Now(),
  322 + }
  323 + if _, err = columnSettingRepository.Save(newColumnSetting); err != nil {
  324 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  325 + }
305 continue 326 continue
306 } else { 327 } else {
307 entryTime, _ := time.Parse("2006-01-02", data.EntryTime) 328 entryTime, _ := time.Parse("2006-01-02", data.EntryTime)
@@ -38,23 +38,7 @@ func (repository *ColumnSettingRepository) Save(columnSetting *domain.ColumnSett @@ -38,23 +38,7 @@ func (repository *ColumnSettingRepository) Save(columnSetting *domain.ColumnSett
38 if err != nil { 38 if err != nil {
39 return nil, err 39 return nil, err
40 } 40 }
41 - //_, err := repository.nextIdentify()  
42 - //if err != nil {  
43 - // return columnSetting, err  
44 - //}  
45 - //if _, errInsert := tx.QueryOne(  
46 - // pg.Scan(&columnSetting.Id, &columnSetting.CompanyId, &columnSetting.CreatedAt, &columnSetting.Description, &columnSetting.Key, &columnSetting.Uid, &columnSetting.UpdatedAt, &columnSetting.UserName, pg.Array(&columnSetting.Value), pg.Array(&columnSetting.InvalidValue)),  
47 - // "INSERT INTO column_settings (company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value",  
48 - // columnSetting.CompanyId, columnSetting.CreatedAt, columnSetting.Description, columnSetting.Key, columnSetting.Uid, columnSetting.UpdatedAt, columnSetting.UserName, pg.Array(columnSetting.Value), pg.Array(columnSetting.InvalidValue)); errInsert != nil {  
49 - // return columnSetting, errInsert  
50 - //}  
51 } else { 41 } else {
52 - //if _, errUpdate := tx.QueryOne(  
53 - // pg.Scan(&columnSetting.Id, &columnSetting.CompanyId, &columnSetting.CreatedAt, &columnSetting.Description, &columnSetting.Key, &columnSetting.Uid, &columnSetting.UpdatedAt, &columnSetting.UserName, pg.Array(&columnSetting.Value), pg.Array(&columnSetting.InvalidValue)),  
54 - // "UPDATE column_settings SET company_id=?, created_at=?, description=?, key=?, uid=?, updated_at=?, user_name=?, value=?, invalid_value=? WHERE id=? RETURNING id, company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value",  
55 - // columnSetting.CompanyId, columnSetting.CreatedAt, columnSetting.Description, columnSetting.Key, columnSetting.Uid, columnSetting.UpdatedAt, columnSetting.UserName, pg.Array(columnSetting.Value), pg.Array(columnSetting.InvalidValue), columnSetting.Identify()); errUpdate != nil {  
56 - // return columnSetting, errUpdate  
57 - //}  
58 _, err := tx.Model(columnSettingModel).WherePK(). 42 _, err := tx.Model(columnSettingModel).WherePK().
59 Column("company_id", "created_at", "description", "key", "uid", "updated_at", "user_name", "value", "invalid_value").Update() 43 Column("company_id", "created_at", "description", "key", "uid", "updated_at", "user_name", "value", "invalid_value").Update()
60 if err != nil { 44 if err != nil {
@@ -78,13 +62,9 @@ func (repository *ColumnSettingRepository) Remove(columnSetting *domain.ColumnSe @@ -78,13 +62,9 @@ func (repository *ColumnSettingRepository) Remove(columnSetting *domain.ColumnSe
78 62
79 // 批量删除 63 // 批量删除
80 if len(columnSettings) > 0 { 64 if len(columnSettings) > 0 {
81 - //var columnSettingModels []models.ColumnSetting  
82 var ids []int64 65 var ids []int64
83 for _, setting := range columnSettings { 66 for _, setting := range columnSettings {
84 ids = append(ids, setting.Identify().(int64)) 67 ids = append(ids, setting.Identify().(int64))
85 - //columnSettingModels = append(columnSettingModels, models.ColumnSetting{  
86 - // Id: setting.Identify().(int64),  
87 - //})  
88 } 68 }
89 if _, err := tx.Model((*models.ColumnSetting)(nil)).Where("id IN (?)", pg.In(ids)).Delete(); err != nil { 69 if _, err := tx.Model((*models.ColumnSetting)(nil)).Where("id IN (?)", pg.In(ids)).Delete(); err != nil {
90 return nil, columnSettings, err 70 return nil, columnSettings, err