123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package crontab
- import (
- "kpt-pasture/model"
- "kpt-pasture/module/backend"
- "time"
- "gitee.com/xuyiping_admin/pkg/logger/zaplog"
- "go.uber.org/zap"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- // IsExistCrontabLog 定时任务今日是否已经执行过
- func (e *Entry) IsExistCrontabLog(name string) bool {
- currDateTime := time.Now().Format(model.LayoutDate2)
- var count int64 = 0
- if err := e.DB.Model(&model.CronLog{}).Where("name = ?", name).
- Where("date = ?", currDateTime).Count(&count).Error; err != nil {
- zaplog.Error("CreateCrontabLog", zap.Any("err", err), zap.String("name", name))
- return false
- }
- if count > 0 {
- return true
- }
- return false
- }
- func (e *Entry) CreateCrontabLog(name string) {
- crontabLog := model.NewCronLog(name)
- if err := e.DB.Model(&model.CronLog{}).Create(crontabLog).Error; err != nil {
- zaplog.Error("CreateCrontabLog", zap.Any("err", err), zap.String("name", name))
- }
- }
- // CreatedCalendar 创建当天工单日历记录
- func (e *Entry) CreatedCalendar(calendarType pasturePb.CalendarType_Kind, count int32) {
- calendarTypeName := backend.CalendarTypeMap()[calendarType]
- newCalendar := model.NewCalendar(calendarTypeName, calendarType, count)
- historyCalendar := &model.Calendar{}
- if err := e.DB.Model(&model.Calendar{}).Where("calendar_type = ?", calendarType).
- Where("show_day = ?", time.Now().Format(model.LayoutDate2)).First(historyCalendar).Error; err != nil {
- zaplog.Error("CreatedCalendar", zap.Any("err", err), zap.Any("historyCalendar", historyCalendar))
- }
- if historyCalendar.Id <= 0 {
- if err := e.DB.Model(&model.Calendar{}).Create(newCalendar).Error; err != nil {
- zaplog.Error("CreatedCalendar", zap.Any("err", err), zap.Any("workOrderCalendar", newCalendar))
- }
- return
- }
- if err := e.DB.Model(&model.Calendar{}).Where("id = ?", historyCalendar.Id).
- Update("count", count).Error; err != nil {
- zaplog.Error("CreatedCalendar", zap.Any("err", err), zap.Any("historyCalendar", historyCalendar))
- }
- }
- func (e *Entry) IsExistSameTimeCow(cow *model.Cow, sameTime *model.SameTime) bool {
- var count int64 = 0
- if err := e.DB.Model(&model.CowSameTime{}).
- Where("cow_id = ?", cow.Id).
- Where("lact = ?", cow.Lact).
- Where("same_time_id = ?", sameTime.Id).
- Where("same_time_status != ?", pasturePb.SameTimeStatus_End).
- Count(&count).Error; err != nil {
- zaplog.Error("IsExistSameTimeCow", zap.Any("err", err), zap.Any("cow", cow), zap.Any("sameTime", sameTime))
- return false
- }
- if count > 0 {
- return true
- }
- return false
- }
|