package biapprove import ( "eta_gn/eta_api/global" "eta_gn/eta_api/utils" "fmt" "strings" "time" ) type BiApproveMessage struct { Id int `gorm:"primaryKey;column:id"` SendUserId int `gorm:"column:send_user_id"` // 发送人Id ReceiveUserId int `gorm:"column:receive_user_id"` // 接收者Id Content string `gorm:"column:content"` // 消息内容 Remark string `gorm:"column:remark"` // 备注信息 BiApproveId int `gorm:"column:bi_approve_id"` // 审批Id ApproveState int `gorm:"column:approve_state"` // 审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回 IsRead int `gorm:"column:is_read"` // 是否已读:0-未读;1-已读 CreateTime time.Time `gorm:"column:create_time"` // 创建时间 ModifyTime time.Time `gorm:"column:modify_time"` // 修改时间 } var BiApproveMessageCols = struct { Id string SendUserId string ReceiveUserId string Content string Remark string BiApproveId string ApproveState string IsRead string CreateTime string ModifyTime string }{ Id: "id", SendUserId: "send_user_id", ReceiveUserId: "receive_user_id", Content: "content", Remark: "remark", BiApproveId: "bi_approve_id", ApproveState: "approve_state", IsRead: "is_read", CreateTime: "create_time", ModifyTime: "modify_time", } func (r *BiApproveMessage) TableName() string { return "bi_approve_message" } func (r *BiApproveMessage) Create() (err error) { o := global.DmSQL["rddp"] err = o.Create(r).Error return err } func (m *BiApproveMessage) PrimaryId() string { return BiApproveMessageCols.Id } func (r *BiApproveMessage) CreateMulti(items []*BiApproveMessage) (err error) { if len(items) == 0 { return } o := global.DmSQL["rddp"] err = o.CreateInBatches(items, utils.MultiAddNum).Error return } func (m *BiApproveMessage) GetCountByCondition(condition string, pars []interface{}) (count int, err error) { sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition) err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error return } func (m *BiApproveMessage) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BiApproveMessage, err error) { fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY create_time DESC` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order) err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error return } func (m *BiApproveMessage) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*BiApproveMessage, err error) { fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY create_time DESC` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order) pars = append(pars, startSize, pageSize) err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error return } func (m *BiApproveMessage) GetItemById(id int) (item *BiApproveMessage, err error) { sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? `, m.TableName(), m.PrimaryId()) err = global.DmSQL["rddp"].Raw(sql, id).First(&item).Error return } func (m *BiApproveMessage) Update(cols []string) (err error) { err = global.DmSQL["rddp"].Model(m).Select(cols).Updates(m).Error return }