// Copyright 2019 github.com. All rights reserved. // Use of this source code is governed by github.com. package model import ( "github.com/jinzhu/gorm" "go.uber.org/zap" "smart-enterprise-management/errors" "time" "github.com/jaryhe/gopkgs/logger" "encoding/json" ) const ( // 未完工 ProjectProgressUnfinish = iota // 已完工 ProjectProgressFinish // 延期 ProjectProgressDelay ) type TProjectSchedule struct { ID int64 `gorm:"column:id"` ProjectId int64 `gorm:"column:project_id"` Name string `gorm:"column:name"` ExpectStartTime time.Time `gorm:"column:expect_start_time"` ExpectEndTime time.Time `gorm:"column:expect_end_time"` RealityEndTime time.Time `gorm:"column:reality_end_time"` Image string `gorm:"column:image"` Status int64 `gorm:"column:status"` CreatedAt time.Time `gorm:"column:created_at"` UpdatedAt time.Time `gorm:"column:updated_at"` } func (TProjectSchedule) TableName() string { return "t_project_schedule" } func (p *TProjectSchedule) Del(db *gorm.DB, where map[string]interface{}) error { cond, val, err := whereBuild(where) if err != nil { return err } err = db.Table(p.TableName()).Where(cond, val...).Delete(p).Error if err != nil { fields, _ := json.Marshal(where) logger.Error("mysql", zap.String("sql", "delete from t_project_schedule"), zap.String("fields",string(fields)), zap.String("error", err.Error())) return errors.DataBaseError } return err } func (p *TProjectSchedule) Count(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) (int64, error) { if len(where) > 0 || len(or) > 0{ cond, val, err := whereBuildAndOr(where, or) if err != nil { return 0, err } ret := int64(0) err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error return ret, err } ret := int64(0) err := db.Table(p.TableName()).Count(&ret).Error return ret, err }