package rentComputer

import (
	"log-server/global"
	"log-server/model/rentComputer"
)

type ServiceRentComputerLog struct {
}

func (s *ServiceRentComputerLog) AddRentComputerLog(log rentComputer.RentComputerLog) (err error) {
	//if !errors.Is(global.GVA_DB.Where("pc_num = ? and shop_id = ?", log.PcNum, log.ShopId).First(&rentComputer.RentComputer{}).Error, gorm.ErrRecordNotFound) {
	//	return errors.New("租机编号已存在")
	//}
	global.GVA_LOG.Info("log>>>" + log.Log)
	return global.GVA_DB.Create(&log).Error
}

// QueryRentComputerLogByPcNum 查询日志
func (s *ServiceRentComputerLog) QueryRentComputerLogByPcNum(log rentComputer.RentComputerLog) (list interface{}, err error) {
	//global.GVA_LOG.Info(log.PcNum)
	//global.GVA_LOG.Info(strconv.Itoa(int(log.ShopId)))
	var logList []rentComputer.RentComputerLog
	db := global.GVA_DB.Model(&rentComputer.RentComputerLog{})
	db.Where("pc_num = ? and shop_id = ?", log.PcNum, log.ShopId)
	err = db.Order("create_time desc").Find(&logList).Error
	return logList, err
}
