package data

import (
	"eta/eta_mobile/models/data_manage"
	"time"
)

func AddEditEdbInfoRcord(oldEdbInfo *data_manage.EdbInfo, newEdbInfo *data_manage.EdbInfoEditRecord) (err error) {
	if oldEdbInfo.EdbName != newEdbInfo.EdbName || oldEdbInfo.Frequency != newEdbInfo.Frequency || oldEdbInfo.Unit != newEdbInfo.Unit {
		ctime := time.Now()
		edbRecord := new(data_manage.EdbInfoRecord)
		edbRecord.EdbInfoId = oldEdbInfo.EdbInfoId
		edbRecord.OldEdbName = oldEdbInfo.EdbName
		edbRecord.OldFrequency = oldEdbInfo.Frequency
		edbRecord.OldUnit = oldEdbInfo.Unit
		edbRecord.NewEdbName = newEdbInfo.EdbName
		edbRecord.NewFrequency = newEdbInfo.Frequency
		edbRecord.NewUnit = newEdbInfo.Unit
		edbRecord.OperateUserId = newEdbInfo.OperateUserId
		edbRecord.OperateUserRealName = newEdbInfo.OperateUserRealName
		edbRecord.CreateTime = ctime
		edbRecord.Timestamp = ctime.Unix()
		err = data_manage.AddEditEdbInfoRcord(edbRecord)
		if err != nil {
			return
		}
		err = data_manage.ModifyEdbInfoBaseTimeById(edbRecord.EdbInfoId, ctime)
	}
	return
}
