1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- // 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:ProjectId"`
- Name string `gorm:"column:Name"`
- ExpectStartTime time.Time `gorm:"column:ExpectStartTime"`
- ExpectEndTime time.Time `gorm:"column:ExpectEndTime"`
- RealityEndTime time.Time `gorm:"column:RealityEndTime"`
- RealityStartTime time.Time `gorm:"column:RealityStartTime"`
- Image string `gorm:"column:Image"`
- Status int64 `gorm:"column:Status"`
- CreatedAt time.Time `gorm:"column:CreatedAt"`
- UpdatedAt time.Time `gorm:"column:UpdatedAt"`
- }
- func (TProjectSchedule) TableName() string {
- return "ProjectSchedule"
- }
- 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 ProjectSchedule"),
- 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
- }
|