package data_stat

import (
	"eta/eta_api/models/data_manage"
	"eta/eta_api/models/data_stat"
	"eta/eta_api/models/system"
	"eta/eta_api/utils"
	"fmt"
	"time"
)

func AddEdbDeleteLog(edbInfo *data_manage.EdbInfo, sysUser *system.Admin) (err error) {
	if edbInfo != nil {
		log := new(data_stat.EdbInfoDeleteLog)
		log.EdbInfoId = edbInfo.EdbInfoId
		log.EdbInfoType = edbInfo.EdbInfoType
		log.SourceName = edbInfo.SourceName
		log.Source = edbInfo.Source
		log.EdbCode = edbInfo.EdbCode
		log.EdbName = edbInfo.EdbName
		log.EdbNameEn = edbInfo.EdbNameEn
		log.EdbNameSource = edbInfo.SourceIndexName
		log.Frequency = edbInfo.Frequency
		log.Unit = edbInfo.Unit
		log.UnitEn = edbInfo.UnitEn
		log.StartDate = edbInfo.StartDate
		log.EndDate = edbInfo.EndDate
		log.SysUserId = edbInfo.SysUserId
		log.SysUserRealName = edbInfo.SysUserRealName
		log.UniqueCode = edbInfo.UniqueCode
		log.EdbCreateTime = edbInfo.CreateTime.Format(utils.FormatDateTime)
		log.EdbModifyTime = edbInfo.ModifyTime.Format(utils.FormatDateTime)
		log.CreateTime = time.Now().Format(utils.FormatDateTime)
		log.MinValue = edbInfo.MinValue
		log.MaxValue = edbInfo.MaxValue
		log.CalculateFormula = edbInfo.CalculateFormula
		log.EdbType = edbInfo.EdbType
		log.LatestDate = edbInfo.LatestDate
		log.LatestValue = edbInfo.LatestValue
		log.MoveType = edbInfo.MoveType
		log.MoveFrequency = edbInfo.MoveFrequency
		log.NoUpdate = edbInfo.NoUpdate
		log.ChartImage = edbInfo.ChartImage
		log.Calendar = edbInfo.Calendar
		log.DataDateType = edbInfo.DataDateType
		log.ManualSave = edbInfo.ManualSave
		log.TerminalCode = edbInfo.TerminalCode

		log.DelSysUserId = sysUser.AdminId
		log.DelSysUserRealName = sysUser.RealName
		log.DataUpdateTime = edbInfo.DataUpdateTime
		log.ErDataUpdateDate = edbInfo.ErDataUpdateDate

		_, err = data_stat.AddEdbDeleteLog(log)
		if err != nil {
			err = fmt.Errorf("新增指标删除日志失败,Err: %s", err)
			return
		}
	}
	return
}