github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/gen_method/examples/physics_delete_by_uniquustomer_g7__generated.go (about)

     1  package examples
     2  
     3  import (
     4  	"fmt"
     5  	"reflect"
     6  	"strings"
     7  	"time"
     8  
     9  	"github.com/artisanhe/gorm"
    10  	"github.com/artisanhe/tools/courier/enumeration"
    11  	"github.com/artisanhe/tools/duration"
    12  	"github.com/artisanhe/tools/mysql/dberr"
    13  	"github.com/artisanhe/tools/timelib"
    14  	"github.com/go-sql-driver/mysql"
    15  	"github.com/sirupsen/logrus"
    16  )
    17  
    18  type PhysicsDeleteByUniquustomerG7List []PhysicsDeleteByUniquustomerG7
    19  
    20  func init() {
    21  	DBTable.Register(&PhysicsDeleteByUniquustomerG7{})
    22  }
    23  
    24  func (pdbug PhysicsDeleteByUniquustomerG7) TableName() string {
    25  	table_name := "t_physics_delete_by_uniquustomer_g7"
    26  	if DBTable.Name == "" {
    27  		return table_name
    28  	}
    29  	return DBTable.Name + "." + table_name
    30  }
    31  
    32  func (pdbugl *PhysicsDeleteByUniquustomerG7List) BatchFetchByCreateTimeList(db *gorm.DB, createTimeList []timelib.MySQLTimestamp) error {
    33  	defer duration.PrintDuration(map[string]interface{}{
    34  		"request": "[DB]PhysicsDeleteByUniquustomerG7.BatchFetchByCreateTimeList",
    35  	})()
    36  
    37  	if len(createTimeList) == 0 {
    38  		return nil
    39  	}
    40  
    41  	err := db.Table(PhysicsDeleteByUniquustomerG7{}.TableName()).Where("F_create_time in (?) and F_enabled = ?", createTimeList, enumeration.BOOL__TRUE).Find(pdbugl).Error
    42  	if err != nil {
    43  		logrus.Errorf("%s", err.Error())
    44  		return dberr.RecordFetchFailedError
    45  	} else {
    46  		return nil
    47  	}
    48  }
    49  
    50  func (pdbugl *PhysicsDeleteByUniquustomerG7List) BatchFetchByCustomerIDList(db *gorm.DB, customerIDList []uint64) error {
    51  	defer duration.PrintDuration(map[string]interface{}{
    52  		"request": "[DB]PhysicsDeleteByUniquustomerG7.BatchFetchByCustomerIDList",
    53  	})()
    54  
    55  	if len(customerIDList) == 0 {
    56  		return nil
    57  	}
    58  
    59  	err := db.Table(PhysicsDeleteByUniquustomerG7{}.TableName()).Where("F_customer_id in (?) and F_enabled = ?", customerIDList, enumeration.BOOL__TRUE).Find(pdbugl).Error
    60  	if err != nil {
    61  		logrus.Errorf("%s", err.Error())
    62  		return dberr.RecordFetchFailedError
    63  	} else {
    64  		return nil
    65  	}
    66  }
    67  
    68  func (pdbugl *PhysicsDeleteByUniquustomerG7List) BatchFetchByG7sOrgCodeList(db *gorm.DB, g7sOrgCodeList []string) error {
    69  	defer duration.PrintDuration(map[string]interface{}{
    70  		"request": "[DB]PhysicsDeleteByUniquustomerG7.BatchFetchByG7sOrgCodeList",
    71  	})()
    72  
    73  	if len(g7sOrgCodeList) == 0 {
    74  		return nil
    75  	}
    76  
    77  	err := db.Table(PhysicsDeleteByUniquustomerG7{}.TableName()).Where("F_g7s_org_code in (?) and F_enabled = ?", g7sOrgCodeList, enumeration.BOOL__TRUE).Find(pdbugl).Error
    78  	if err != nil {
    79  		logrus.Errorf("%s", err.Error())
    80  		return dberr.RecordFetchFailedError
    81  	} else {
    82  		return nil
    83  	}
    84  }
    85  
    86  func (pdbugl *PhysicsDeleteByUniquustomerG7List) BatchFetchByG7sUserIDList(db *gorm.DB, g7sUserIDList []string) error {
    87  	defer duration.PrintDuration(map[string]interface{}{
    88  		"request": "[DB]PhysicsDeleteByUniquustomerG7.BatchFetchByG7sUserIDList",
    89  	})()
    90  
    91  	if len(g7sUserIDList) == 0 {
    92  		return nil
    93  	}
    94  
    95  	err := db.Table(PhysicsDeleteByUniquustomerG7{}.TableName()).Where("F_g7s_user_id in (?) and F_enabled = ?", g7sUserIDList, enumeration.BOOL__TRUE).Find(pdbugl).Error
    96  	if err != nil {
    97  		logrus.Errorf("%s", err.Error())
    98  		return dberr.RecordFetchFailedError
    99  	} else {
   100  		return nil
   101  	}
   102  }
   103  
   104  func (pdbugl *PhysicsDeleteByUniquustomerG7List) BatchFetchByUpdateTimeList(db *gorm.DB, updateTimeList []timelib.MySQLTimestamp) error {
   105  	defer duration.PrintDuration(map[string]interface{}{
   106  		"request": "[DB]PhysicsDeleteByUniquustomerG7.BatchFetchByUpdateTimeList",
   107  	})()
   108  
   109  	if len(updateTimeList) == 0 {
   110  		return nil
   111  	}
   112  
   113  	err := db.Table(PhysicsDeleteByUniquustomerG7{}.TableName()).Where("F_update_time in (?) and F_enabled = ?", updateTimeList, enumeration.BOOL__TRUE).Find(pdbugl).Error
   114  	if err != nil {
   115  		logrus.Errorf("%s", err.Error())
   116  		return dberr.RecordFetchFailedError
   117  	} else {
   118  		return nil
   119  	}
   120  }
   121  
   122  func (pdbug *PhysicsDeleteByUniquustomerG7) Create(db *gorm.DB) error {
   123  	defer duration.PrintDuration(map[string]interface{}{
   124  		"request": "[DB]PhysicsDeleteByUniquustomerG7.Create",
   125  	})()
   126  
   127  	if time.Time(pdbug.CreateTime).IsZero() {
   128  		pdbug.CreateTime = timelib.MySQLTimestamp(time.Now())
   129  	}
   130  
   131  	if time.Time(pdbug.UpdateTime).IsZero() {
   132  		pdbug.UpdateTime = timelib.MySQLTimestamp(time.Now())
   133  	}
   134  
   135  	pdbug.Enabled = enumeration.Bool(enumeration.BOOL__TRUE)
   136  	err := db.Table(pdbug.TableName()).Create(pdbug).Error
   137  	if err != nil {
   138  		if mysql_err, ok := err.(*mysql.MySQLError); !ok {
   139  			logrus.Errorf("%s", err.Error())
   140  			return dberr.RecordCreateFailedError
   141  		} else if mysql_err.Number != dberr.DuplicateEntryErrNumber {
   142  			logrus.Errorf("%s", err.Error())
   143  			return dberr.RecordCreateFailedError
   144  		} else {
   145  			return dberr.RecordConflictError
   146  		}
   147  	} else {
   148  		return nil
   149  	}
   150  }
   151  
   152  type PhysicsDeleteByUniquustomerG7DBFieldData struct {
   153  	G7sUserID  string
   154  	CustomerID string
   155  	G7sOrgCode string
   156  	CreateTime string
   157  	UpdateTime string
   158  	Enabled    string
   159  }
   160  
   161  // FetchNoneUniqueIndexFields without Enabled and CreateTime field.
   162  func (pdbugdbfd *PhysicsDeleteByUniquustomerG7DBFieldData) FetchNoneUniqueIndexFields() []string {
   163  	return []string{
   164  		"F_g7s_org_code", "F_update_time",
   165  	}
   166  }
   167  
   168  func (pdbug PhysicsDeleteByUniquustomerG7) DBField() *PhysicsDeleteByUniquustomerG7DBFieldData {
   169  	return &PhysicsDeleteByUniquustomerG7DBFieldData{
   170  		G7sUserID:  "F_g7s_user_id",
   171  		CustomerID: "F_customer_id",
   172  		G7sOrgCode: "F_g7s_org_code",
   173  		CreateTime: "F_create_time",
   174  		UpdateTime: "F_update_time",
   175  		Enabled:    "F_enabled",
   176  	}
   177  }
   178  
   179  var PhysicsDeleteByUniquustomerG7StructFieldAndDBFieldRelate = map[string]string{
   180  	"G7sUserID":  "F_g7s_user_id",
   181  	"CustomerID": "F_customer_id",
   182  	"G7sOrgCode": "F_g7s_org_code",
   183  	"CreateTime": "F_create_time",
   184  	"UpdateTime": "F_update_time",
   185  	"Enabled":    "F_enabled",
   186  }
   187  
   188  var PhysicsDeleteByUniquustomerG7DBFieldAndStructFieldRelate = map[string]string{
   189  	"F_g7s_user_id":  "G7sUserID",
   190  	"F_customer_id":  "CustomerID",
   191  	"F_g7s_org_code": "G7sOrgCode",
   192  	"F_create_time":  "CreateTime",
   193  	"F_update_time":  "UpdateTime",
   194  	"F_enabled":      "Enabled",
   195  }
   196  
   197  // CreateOnDuplicateWithUpdateFields only update the no unique index field, it return error if updateFields contain unique index field.
   198  // It doesn't update the Enabled and CreateTime field.
   199  func (pdbug *PhysicsDeleteByUniquustomerG7) CreateOnDuplicateWithUpdateFields(db *gorm.DB, updateFields []string) error {
   200  	defer duration.PrintDuration(map[string]interface{}{
   201  		"request": "[DB]PhysicsDeleteByUniquustomerG7.CreateOnDuplicateWithUpdateFields",
   202  	})()
   203  	if len(updateFields) == 0 {
   204  		return fmt.Errorf("Must have update fields.")
   205  	}
   206  
   207  	noUniqueIndexFields := (&PhysicsDeleteByUniquustomerG7DBFieldData{}).FetchNoneUniqueIndexFields()
   208  	if len(noUniqueIndexFields) == 0 {
   209  		return fmt.Errorf("There are no unique fields.")
   210  	}
   211  
   212  	var noUniqueIndexFieldsMap = make(map[string]string)
   213  	for _, field := range noUniqueIndexFields {
   214  		noUniqueIndexFieldsMap[field] = ""
   215  	}
   216  
   217  	var updateFieldsMap = make(map[string]string)
   218  	for _, field := range updateFields {
   219  		// have unique field in updateFields
   220  		if _, ok := noUniqueIndexFieldsMap[field]; !ok {
   221  			return fmt.Errorf("Field[%s] is unique index or wrong field or Enable field", PhysicsDeleteByUniquustomerG7DBFieldAndStructFieldRelate[field])
   222  		}
   223  		updateFieldsMap[field] = ""
   224  	}
   225  
   226  	if time.Time(pdbug.CreateTime).IsZero() {
   227  		pdbug.CreateTime = timelib.MySQLTimestamp(time.Now())
   228  	}
   229  
   230  	if time.Time(pdbug.UpdateTime).IsZero() {
   231  		pdbug.UpdateTime = timelib.MySQLTimestamp(time.Now())
   232  	}
   233  
   234  	pdbug.Enabled = enumeration.Bool(enumeration.BOOL__TRUE)
   235  
   236  	structType := reflect.TypeOf(pdbug).Elem()
   237  	if structType.Kind() != reflect.Struct {
   238  		return fmt.Errorf("Instance not struct type.")
   239  	}
   240  	structVal := reflect.ValueOf(pdbug).Elem()
   241  
   242  	var param_list []interface{}
   243  	var str_list = []string{"insert into"}
   244  	var insertFieldsStr = pdbug.TableName() + "("
   245  	var placeHolder = "values("
   246  	for i := 0; i < structType.NumField(); i++ {
   247  		if i == 0 {
   248  			insertFieldsStr += PhysicsDeleteByUniquustomerG7StructFieldAndDBFieldRelate[structType.Field(i).Name]
   249  			placeHolder += fmt.Sprintf("%s", "?")
   250  		} else {
   251  			insertFieldsStr += fmt.Sprintf(",%s", PhysicsDeleteByUniquustomerG7StructFieldAndDBFieldRelate[structType.Field(i).Name])
   252  			placeHolder += fmt.Sprintf("%s", ", ?")
   253  		}
   254  		param_list = append(param_list, structVal.Field(i).Interface())
   255  	}
   256  	insertFieldsStr += ")"
   257  	placeHolder += ")"
   258  	str_list = append(str_list, []string{insertFieldsStr, placeHolder, "on duplicate key update"}...)
   259  
   260  	var updateStr []string
   261  	for i := 0; i < structType.NumField(); i++ {
   262  		if dbField, ok := PhysicsDeleteByUniquustomerG7StructFieldAndDBFieldRelate[structType.Field(i).Name]; !ok {
   263  			return fmt.Errorf("Wrong field of struct, may be changed field but not regenerate code.")
   264  		} else {
   265  			if _, ok := updateFieldsMap[dbField]; ok {
   266  				updateStr = append(updateStr, fmt.Sprintf("%s = ?", dbField))
   267  				param_list = append(param_list, structVal.Field(i).Interface())
   268  			}
   269  		}
   270  	}
   271  	str_list = append(str_list, strings.Join(updateStr, ","))
   272  	sql := strings.Join(str_list, " ")
   273  	err := db.Exec(sql, param_list...).Error
   274  	if err != nil {
   275  		logrus.Errorf("%s", err.Error())
   276  		return dberr.RecordCreateFailedError
   277  	}
   278  
   279  	return nil
   280  }
   281  
   282  func (pdbug *PhysicsDeleteByUniquustomerG7) DeleteByG7sUserIDAndCustomerID(db *gorm.DB) error {
   283  	defer duration.PrintDuration(map[string]interface{}{
   284  		"request": "[DB]PhysicsDeleteByUniquustomerG7.DeleteByG7sUserIDAndCustomerID",
   285  	})()
   286  
   287  	err := db.Table(pdbug.TableName()).Where("F_g7s_user_id = ? and F_customer_id = ? and F_enabled = ?", pdbug.G7sUserID, pdbug.CustomerID, enumeration.BOOL__TRUE).Delete(pdbug).Error
   288  	if err != nil {
   289  		logrus.Errorf("%s", err.Error())
   290  		return dberr.RecordDeleteFailedError
   291  	} else {
   292  		return nil
   293  	}
   294  }
   295  
   296  func (pdbugl *PhysicsDeleteByUniquustomerG7List) FetchByCreateTime(db *gorm.DB, createTime timelib.MySQLTimestamp) error {
   297  	defer duration.PrintDuration(map[string]interface{}{
   298  		"request": "[DB]PhysicsDeleteByUniquustomerG7.FetchByCreateTime",
   299  	})()
   300  
   301  	err := db.Table(PhysicsDeleteByUniquustomerG7{}.TableName()).Where("F_create_time = ? and F_enabled = ?", createTime, enumeration.BOOL__TRUE).Find(pdbugl).Error
   302  	if err == nil {
   303  		return nil
   304  	} else {
   305  		logrus.Errorf("%s", err.Error())
   306  		return dberr.RecordFetchFailedError
   307  	}
   308  }
   309  
   310  func (pdbugl *PhysicsDeleteByUniquustomerG7List) FetchByCustomerID(db *gorm.DB, customerID uint64) error {
   311  	defer duration.PrintDuration(map[string]interface{}{
   312  		"request": "[DB]PhysicsDeleteByUniquustomerG7.FetchByCustomerID",
   313  	})()
   314  
   315  	err := db.Table(PhysicsDeleteByUniquustomerG7{}.TableName()).Where("F_customer_id = ? and F_enabled = ?", customerID, enumeration.BOOL__TRUE).Find(pdbugl).Error
   316  	if err == nil {
   317  		return nil
   318  	} else {
   319  		logrus.Errorf("%s", err.Error())
   320  		return dberr.RecordFetchFailedError
   321  	}
   322  }
   323  
   324  func (pdbugl *PhysicsDeleteByUniquustomerG7List) FetchByG7sOrgCode(db *gorm.DB, g7sOrgCode string) error {
   325  	defer duration.PrintDuration(map[string]interface{}{
   326  		"request": "[DB]PhysicsDeleteByUniquustomerG7.FetchByG7sOrgCode",
   327  	})()
   328  
   329  	err := db.Table(PhysicsDeleteByUniquustomerG7{}.TableName()).Where("F_g7s_org_code = ? and F_enabled = ?", g7sOrgCode, enumeration.BOOL__TRUE).Find(pdbugl).Error
   330  	if err == nil {
   331  		return nil
   332  	} else {
   333  		logrus.Errorf("%s", err.Error())
   334  		return dberr.RecordFetchFailedError
   335  	}
   336  }
   337  
   338  func (pdbugl *PhysicsDeleteByUniquustomerG7List) FetchByG7sUserID(db *gorm.DB, g7sUserID string) error {
   339  	defer duration.PrintDuration(map[string]interface{}{
   340  		"request": "[DB]PhysicsDeleteByUniquustomerG7.FetchByG7sUserID",
   341  	})()
   342  
   343  	err := db.Table(PhysicsDeleteByUniquustomerG7{}.TableName()).Where("F_g7s_user_id = ? and F_enabled = ?", g7sUserID, enumeration.BOOL__TRUE).Find(pdbugl).Error
   344  	if err == nil {
   345  		return nil
   346  	} else {
   347  		logrus.Errorf("%s", err.Error())
   348  		return dberr.RecordFetchFailedError
   349  	}
   350  }
   351  
   352  func (pdbug *PhysicsDeleteByUniquustomerG7) FetchByG7sUserIDAndCustomerID(db *gorm.DB) error {
   353  	defer duration.PrintDuration(map[string]interface{}{
   354  		"request": "[DB]PhysicsDeleteByUniquustomerG7.FetchByG7sUserIDAndCustomerID",
   355  	})()
   356  
   357  	err := db.Table(pdbug.TableName()).Where("F_g7s_user_id = ? and F_customer_id = ? and F_enabled = ?", pdbug.G7sUserID, pdbug.CustomerID, enumeration.BOOL__TRUE).Find(pdbug).Error
   358  	if err == nil {
   359  		return nil
   360  	} else {
   361  		if err == gorm.RecordNotFound {
   362  			return dberr.RecordNotFoundError
   363  		} else {
   364  			logrus.Errorf("%s", err.Error())
   365  			return dberr.RecordFetchFailedError
   366  		}
   367  	}
   368  }
   369  
   370  func (pdbug *PhysicsDeleteByUniquustomerG7) FetchByG7sUserIDAndCustomerIDForUpdate(db *gorm.DB) error {
   371  	defer duration.PrintDuration(map[string]interface{}{
   372  		"request": "[DB]PhysicsDeleteByUniquustomerG7.FetchByG7sUserIDAndCustomerIDForUpdate",
   373  	})()
   374  
   375  	err := db.Table(pdbug.TableName()).Where("F_g7s_user_id = ? and F_customer_id = ? and F_enabled = ?", pdbug.G7sUserID, pdbug.CustomerID, enumeration.BOOL__TRUE).Set("gorm:query_option", "FOR UPDATE").Find(pdbug).Error
   376  	if err == nil {
   377  		return nil
   378  	} else {
   379  		if err == gorm.RecordNotFound {
   380  			return dberr.RecordNotFoundError
   381  		} else {
   382  			logrus.Errorf("%s", err.Error())
   383  			return dberr.RecordFetchFailedError
   384  		}
   385  	}
   386  }
   387  
   388  func (pdbugl *PhysicsDeleteByUniquustomerG7List) FetchByUpdateTime(db *gorm.DB, updateTime timelib.MySQLTimestamp) error {
   389  	defer duration.PrintDuration(map[string]interface{}{
   390  		"request": "[DB]PhysicsDeleteByUniquustomerG7.FetchByUpdateTime",
   391  	})()
   392  
   393  	err := db.Table(PhysicsDeleteByUniquustomerG7{}.TableName()).Where("F_update_time = ? and F_enabled = ?", updateTime, enumeration.BOOL__TRUE).Find(pdbugl).Error
   394  	if err == nil {
   395  		return nil
   396  	} else {
   397  		logrus.Errorf("%s", err.Error())
   398  		return dberr.RecordFetchFailedError
   399  	}
   400  }
   401  
   402  func (pdbugl *PhysicsDeleteByUniquustomerG7List) FetchList(db *gorm.DB, size, offset int32, query ...map[string]interface{}) (int32, error) {
   403  	defer duration.PrintDuration(map[string]interface{}{
   404  		"request": "[DB]PhysicsDeleteByUniquustomerG7.FetchList",
   405  	})()
   406  
   407  	var count int32
   408  	if len(query) == 0 {
   409  		query = append(query, map[string]interface{}{"F_enabled": enumeration.BOOL__TRUE})
   410  	} else {
   411  		if _, ok := query[0]["F_enabled"]; !ok {
   412  			query[0]["F_enabled"] = enumeration.BOOL__TRUE
   413  		}
   414  	}
   415  
   416  	if size <= 0 {
   417  		size = -1
   418  		offset = -1
   419  	}
   420  	var err error
   421  
   422  	err = db.Table(PhysicsDeleteByUniquustomerG7{}.TableName()).Where(query[0]).Count(&count).Limit(size).Offset(offset).Order("F_create_time desc").Find(pdbugl).Error
   423  
   424  	if err != nil {
   425  		logrus.Errorf("%s", err.Error())
   426  		return 0, dberr.RecordFetchFailedError
   427  	} else {
   428  		return int32(count), nil
   429  	}
   430  }
   431  
   432  func (pdbug *PhysicsDeleteByUniquustomerG7) SoftDeleteByG7sUserIDAndCustomerID(db *gorm.DB) error {
   433  	defer duration.PrintDuration(map[string]interface{}{
   434  		"request": "[DB]PhysicsDeleteByUniquustomerG7.SoftDeleteByG7sUserIDAndCustomerID",
   435  	})()
   436  
   437  	var updateMap = map[string]interface{}{}
   438  	updateMap["F_enabled"] = enumeration.BOOL__FALSE
   439  
   440  	if time.Time(pdbug.UpdateTime).IsZero() {
   441  		pdbug.UpdateTime = timelib.MySQLTimestamp(time.Now())
   442  	}
   443  
   444  	err := db.Table(pdbug.TableName()).Where("F_g7s_user_id = ? and F_customer_id = ? and F_enabled = ?", pdbug.G7sUserID, pdbug.CustomerID, enumeration.BOOL__TRUE).Updates(updateMap).Error
   445  	if err != nil {
   446  		if mysql_err, ok := err.(*mysql.MySQLError); !ok {
   447  			logrus.Errorf("%s", err.Error())
   448  			return dberr.RecordDeleteFailedError
   449  		} else if mysql_err.Number != dberr.DuplicateEntryErrNumber {
   450  			logrus.Errorf("%s", err.Error())
   451  			return dberr.RecordDeleteFailedError
   452  		} else {
   453  			logrus.Warningf("%s", err.Error())
   454  			// 物理删除被软删除的数据
   455  			delErr := db.Where("F_g7s_user_id = ? and F_customer_id = ? and F_enabled = ?", pdbug.G7sUserID, pdbug.CustomerID, enumeration.BOOL__TRUE).Delete(&PhysicsDeleteByUniquustomerG7{}).Error
   456  			if delErr != nil {
   457  				logrus.Errorf("%s", delErr.Error())
   458  				return dberr.RecordDeleteFailedError
   459  			}
   460  
   461  			return nil
   462  		}
   463  	} else {
   464  		return nil
   465  	}
   466  }
   467  
   468  func (pdbug *PhysicsDeleteByUniquustomerG7) UpdateByG7sUserIDAndCustomerIDWithMap(db *gorm.DB, updateMap map[string]interface{}) error {
   469  	defer duration.PrintDuration(map[string]interface{}{
   470  		"request": "[DB]PhysicsDeleteByUniquustomerG7.UpdateByG7sUserIDAndCustomerIDWithMap",
   471  	})()
   472  
   473  	if _, ok := updateMap["F_update_time"]; !ok {
   474  		updateMap["F_update_time"] = timelib.MySQLTimestamp(time.Now())
   475  
   476  	}
   477  	dbRet := db.Table(pdbug.TableName()).Where("F_g7s_user_id = ? and F_customer_id = ? and F_enabled = ?", pdbug.G7sUserID, pdbug.CustomerID, enumeration.BOOL__TRUE).Updates(updateMap)
   478  	err := dbRet.Error
   479  	if err != nil {
   480  		if mysql_err, ok := err.(*mysql.MySQLError); !ok {
   481  			logrus.Errorf("%s", err.Error())
   482  			return dberr.RecordUpdateFailedError
   483  		} else if mysql_err.Number != dberr.DuplicateEntryErrNumber {
   484  			logrus.Errorf("%s", err.Error())
   485  			return dberr.RecordUpdateFailedError
   486  		} else {
   487  			return dberr.RecordConflictError
   488  		}
   489  	} else {
   490  		if dbRet.RowsAffected == 0 {
   491  			findErr := db.Table(pdbug.TableName()).Where("F_g7s_user_id = ? and F_customer_id = ? and F_enabled = ?", pdbug.G7sUserID, pdbug.CustomerID, enumeration.BOOL__TRUE).Find(&PhysicsDeleteByUniquustomerG7{}).Error
   492  			if findErr == gorm.RecordNotFound {
   493  				return dberr.RecordNotFoundError
   494  			} else if findErr != nil {
   495  				return dberr.RecordUpdateFailedError
   496  			}
   497  			//存在有效数据记录,返回成功
   498  			return nil
   499  		} else {
   500  			return nil
   501  		}
   502  	}
   503  }
   504  
   505  func (pdbug *PhysicsDeleteByUniquustomerG7) UpdateByG7sUserIDAndCustomerIDWithStruct(db *gorm.DB) error {
   506  	defer duration.PrintDuration(map[string]interface{}{
   507  		"request": "[DB]PhysicsDeleteByUniquustomerG7.UpdateByG7sUserIDAndCustomerIDWithStruct",
   508  	})()
   509  
   510  	if time.Time(pdbug.UpdateTime).IsZero() {
   511  		pdbug.UpdateTime = timelib.MySQLTimestamp(time.Now())
   512  	}
   513  
   514  	dbRet := db.Table(pdbug.TableName()).Where("F_g7s_user_id = ? and F_customer_id = ? and F_enabled = ?", pdbug.G7sUserID, pdbug.CustomerID, enumeration.BOOL__TRUE).Updates(pdbug)
   515  	err := dbRet.Error
   516  	if err != nil {
   517  		if mysql_err, ok := err.(*mysql.MySQLError); !ok {
   518  			logrus.Errorf("%s", err.Error())
   519  			return dberr.RecordUpdateFailedError
   520  		} else if mysql_err.Number != dberr.DuplicateEntryErrNumber {
   521  			logrus.Errorf("%s", err.Error())
   522  			return dberr.RecordUpdateFailedError
   523  		} else {
   524  			return dberr.RecordConflictError
   525  		}
   526  	} else {
   527  		if dbRet.RowsAffected == 0 {
   528  			findErr := db.Table(pdbug.TableName()).Where("F_g7s_user_id = ? and F_customer_id = ? and F_enabled = ?", pdbug.G7sUserID, pdbug.CustomerID, enumeration.BOOL__TRUE).Find(&PhysicsDeleteByUniquustomerG7{}).Error
   529  			if findErr == gorm.RecordNotFound {
   530  				return dberr.RecordNotFoundError
   531  			} else if findErr != nil {
   532  				return dberr.RecordUpdateFailedError
   533  			}
   534  			//存在有效数据记录,返回成功
   535  			return nil
   536  		} else {
   537  			return nil
   538  		}
   539  	}
   540  }