package company_approval_message import ( "github.com/beego/beego/v2/client/orm" "hongze/hongze_mobile_admin/models/tables/business_trip" "hongze/hongze_mobile_admin/utils" "time" ) type CompanyApprovalMessage struct { Id int `orm:"column(id);pk"` CreateUserId int `description:"申请者id"` ReceiveUserId int `description:"审批者id"` MessageStatus int `description:"消息状态:0未读,1:已读,2:作废"` SourceType int `description:"消息来源类型,1:客户,2:合同,3:用印"` Remark string `description:"备注信息"` Content string `description:"消息内容"` CompanyId int `description:"客户id"` CompanyName string `description:"客户名称"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` CompanyApprovalId int `description:"审批单id"` ApprovalStatus int `description:"审批结果:1:待审批,2:已审批,3:已驳回"` OperationStatus int `description:"消息状态:1:待审批,2:已审批"` MessageType int `description:"1:申请消息,2:审批结果"` MessageInfo string `description:"消息主要内容,json数据"` } // 添加审批消息 func AddCompanyApprovalMessage(item *CompanyApprovalMessage) (err error) { o := orm.NewOrm() _, err = o.Insert(item) return } // 修改审批消息 func ModifyCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) { o := orm.NewOrm() sql := `UPDATE company_approval_message SET operation_status=2,modify_time=NOW() WHERE company_approval_id=? AND source_type=? AND message_type=1 AND operation_status=1 ` _, err = o.Raw(sql, companyApprovalId, sourceType).Exec() return } // 消息列表结果 type CompanyApprovalMessageList struct { Id int `orm:"column(id);pk"` CreateUserId int `description:"申请者id"` MessageStatus int `description:"消息状态:0未读,1:已读,2:作废"` MessageType int `description:"1:申请消息,2:审批结果,3:文字消息"` ApprovalStatus int `description:"审批结果:1:待审批,2:已审批,3:已驳回"` SourceType int `description:"消息来源类型,1:客户,2:合同,3:用印"` Remark string `description:"备注信息"` Content string `description:"消息内容"` CompanyName string `description:"客户名称"` CreateTime time.Time `description:"创建时间"` RealName string `description:"销售名称"` CompanyApprovalId int `description:"审批单id"` MessageInfo string `description:"消息主要内容,json数据" json:"-"` ApprovalInfo ApprovalInfo `description:"审批单信息"` BusinessTripInfo *business_trip.BusinessApplyView `description:"出差申请信息"` } // 消息审批单信息 type ApprovalInfo struct { ApplyName string `description:"申请人姓名"` Type string `description:"类型"` Title string `description:"主题内容"` Content string `description:"主体内容"` CompanyName string `description:"客户信息"` ApplyTime time.Time `description:"提交时间"` ApprovalTime time.Time `description:"审批时间"` Extra string `description:"附加字段: 比如视频评论的标签"` MessageSource string `description:"消息来源:问答社区/视频社区/线上路演"` } type CompanyApprovalMessageListResp struct { List []*CompanyApprovalMessageList Total int `description:"总数据条数"` } // 待办消息列表 type CompanyApprovalMessageListV2Resp struct { Company CompanyApprovalMessageListResp `description:"客户"` Contract CompanyApprovalMessageListResp `description:"合同"` } // 获取消息列表总数据 func GetCompanyApprovalMessageCount(sysUserId, sourceType int) (count int, err error) { sql := `SELECT COUNT(1) AS count FROM company_approval_message AS a INNER JOIN admin AS b ON a.create_user_id=b.admin_id WHERE receive_user_id=? AND a.operation_status=1 AND message_status !=2 AND a.source_type=? ` o := orm.NewOrm() err = o.Raw(sql, sysUserId, sourceType).QueryRow(&count) return } // 消息列表页 func GetCompanyApprovalMessageList(sysUserId, startSize, pageSize int, sourceTypes []int) (items []*CompanyApprovalMessageList, err error) { sql := `SELECT a.*, b.real_name FROM company_approval_message AS a INNER JOIN admin AS b ON a.create_user_id = b.admin_id WHERE receive_user_id =? AND message_status != 2 AND a.source_type IN (` + utils.GetOrmInReplace(len(sourceTypes)) + `)` sql += ` ORDER BY create_time DESC LIMIT ?,? ` o := orm.NewOrm() _, err = o.Raw(sql, sysUserId, sourceTypes, startSize, pageSize).QueryRows(&items) return } // 获取最近一条消息 func GetLastMessage(sysUserId, sourceType int) (item *CompanyApprovalMessageList, err error) { sql := `SELECT a.*,b.real_name FROM company_approval_message AS a INNER JOIN admin AS b ON a.create_user_id=b.admin_id WHERE receive_user_id=? AND message_status !=2 AND source_type=?` sql += ` ORDER BY create_time DESC ` o := orm.NewOrm() err = o.Raw(sql, sysUserId, sourceType).QueryRow(&item) return } // 获取最近一条消息 func GetLastMessageBySourceTypes(sysUserId int, sourceType []int) (item *CompanyApprovalMessageList, err error) { sql := `SELECT a.*, b.real_name FROM company_approval_message AS a INNER JOIN admin AS b ON a.create_user_id = b.admin_id WHERE receive_user_id = ? AND message_status != 2 AND source_type IN (` + utils.GetOrmInReplace(len(sourceType)) + `) ORDER BY create_time DESC` o := orm.NewOrm() err = o.Raw(sql, sysUserId, sourceType).QueryRow(&item) return } // 获取未读消息数 func GetNotReadMessageTotal(sysUserId, sourceType int) (total int64, err error) { sql := `SELECT count(*) total FROM company_approval_message AS a INNER JOIN admin AS b ON a.create_user_id=b.admin_id WHERE receive_user_id=? AND a.operation_status=1 AND a.message_status =0 AND source_type=?` o := orm.NewOrm() err = o.Raw(sql, sysUserId, sourceType).QueryRow(&total) return } // 获取评论未读消息数 func GetCommentNotReadMessageTotal(sysUserId int, types []int) (total int64, err error) { sql := `SELECT count(*) total FROM company_approval_message AS a INNER JOIN admin AS b ON a.create_user_id=b.admin_id WHERE receive_user_id=? AND a.operation_status=1 AND a.message_status =0 AND source_type IN (` + utils.GetOrmInReplace(len(types)) + `)` o := orm.NewOrm() err = o.Raw(sql, sysUserId, types).QueryRow(&total) return } // 申请服务更新请求参数 type CompanyApprovalMessageReadReq struct { Id int `description:"消息id"` } // 变更为消息已读状态 func ModifyCompanyApprovalMessageStatus(companyApprovalMessageId int) (err error) { o := orm.NewOrm() sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW() WHERE id=?` _, err = o.Raw(sql, companyApprovalMessageId).Exec() return } // 变更当前类型下所有未读消息为消息已读状态 func ModifyAllCompanyApprovalMessageStatus(receiveUserId int, sourceTypes []int) (err error) { o := orm.NewOrm() sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW() WHERE receive_user_id = ? and source_type IN (` + utils.GetOrmInReplace(len(sourceTypes)) + `) and message_status=0` _, err = o.Raw(sql, receiveUserId, sourceTypes).Exec() return } // CancelCompanyApprovalMessage 消息作废 func CancelCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) { o := orm.NewOrm() sql := `UPDATE company_approval_message SET message_status=2,modify_time=NOW() WHERE company_approval_id=? AND source_type=? AND message_type=1 AND operation_status=1 ` //sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW() WHERE id=?` _, err = o.Raw(sql, companyApprovalId, sourceType).Exec() return } // 消息删除 func DeleteCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) { o := orm.NewOrm() sql := `DELETE FROM company_approval_message WHERE company_approval_id=? AND source_type=? ` _, err = o.Raw(sql, companyApprovalId, sourceType).Exec() return } // CancelCompanyApprovalMessage 消息作废 func IsReadCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) { o := orm.NewOrm() sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW() WHERE company_approval_id=? AND source_type=? AND message_type=1 AND operation_status=1 ` _, err = o.Raw(sql, companyApprovalId, sourceType).Exec() return }