作者 陈志颖

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

... ... @@ -88,7 +88,7 @@ var _ SyncAction = (*SyncEmployeeService)(nil)
/**
* @Author SteveChan
* @Description //TODO 新增、导入用户初始化栏目设置
* @Description //新增、导入用户初始化栏目设置
* @Date 23:54 2021/1/26
* @Param
* @return
... ... @@ -263,6 +263,12 @@ func (service SyncEmployeeService) updateEmployeeData(datas []EmployeeData) erro
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var columnSettingRepository domain.ColumnSettingRepository
if columnSettingRepository, err = factory.CreateColumnSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range datas {
data := datas[i]
var (
... ... @@ -302,6 +308,21 @@ func (service SyncEmployeeService) updateEmployeeData(datas []EmployeeData) erro
if err = usersRepository.Add(&newUser); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
// 添加用户数据时初始化栏目设置
newColumnSetting := &domain.ColumnSetting{
Description: "订单管理栏目设置",
UserName: data.Name,
CompanyId: int(data.CompanyId),
Uid: data.Id,
Key: constant.ORDER_BASE, // 订单栏目模块名称
Value: domain.DefaultColumns, // 栏目值数组,创建用户时使用默认栏目设置
InvalidValue: domain.DefaultInvalidColumns, // 初始化无效栏目数组
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
if _, err = columnSettingRepository.Save(newColumnSetting); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
continue
} else {
entryTime, _ := time.Parse("2006-01-02", data.EntryTime)
... ...
... ... @@ -38,23 +38,7 @@ func (repository *ColumnSettingRepository) Save(columnSetting *domain.ColumnSett
if err != nil {
return nil, err
}
//_, err := repository.nextIdentify()
//if err != nil {
// return columnSetting, err
//}
//if _, errInsert := tx.QueryOne(
// 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)),
// "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",
// columnSetting.CompanyId, columnSetting.CreatedAt, columnSetting.Description, columnSetting.Key, columnSetting.Uid, columnSetting.UpdatedAt, columnSetting.UserName, pg.Array(columnSetting.Value), pg.Array(columnSetting.InvalidValue)); errInsert != nil {
// return columnSetting, errInsert
//}
} else {
//if _, errUpdate := tx.QueryOne(
// 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)),
// "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",
// 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 {
// return columnSetting, errUpdate
//}
_, err := tx.Model(columnSettingModel).WherePK().
Column("company_id", "created_at", "description", "key", "uid", "updated_at", "user_name", "value", "invalid_value").Update()
if err != nil {
... ... @@ -78,13 +62,9 @@ func (repository *ColumnSettingRepository) Remove(columnSetting *domain.ColumnSe
// 批量删除
if len(columnSettings) > 0 {
//var columnSettingModels []models.ColumnSetting
var ids []int64
for _, setting := range columnSettings {
ids = append(ids, setting.Identify().(int64))
//columnSettingModels = append(columnSettingModels, models.ColumnSetting{
// Id: setting.Identify().(int64),
//})
}
if _, err := tx.Model((*models.ColumnSetting)(nil)).Where("id IN (?)", pg.In(ids)).Delete(); err != nil {
return nil, columnSettings, err
... ...