company_approval_message.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. package company_approval_message
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_mobile_admin/models/tables/business_trip"
  5. "hongze/hongze_mobile_admin/utils"
  6. "time"
  7. )
  8. type CompanyApprovalMessage struct {
  9. Id int `orm:"column(id);pk"`
  10. CreateUserId int `description:"申请者id"`
  11. ReceiveUserId int `description:"审批者id"`
  12. MessageStatus int `description:"消息状态:0未读,1:已读,2:作废"`
  13. SourceType int `description:"消息来源类型,1:客户,2:合同,3:用印"`
  14. Remark string `description:"备注信息"`
  15. Content string `description:"消息内容"`
  16. CompanyId int `description:"客户id"`
  17. CompanyName string `description:"客户名称"`
  18. CreateTime time.Time `description:"创建时间"`
  19. ModifyTime time.Time `description:"修改时间"`
  20. CompanyApprovalId int `description:"审批单id"`
  21. ApprovalStatus int `description:"审批结果:1:待审批,2:已审批,3:已驳回"`
  22. OperationStatus int `description:"消息状态:1:待审批,2:已审批"`
  23. MessageType int `description:"1:申请消息,2:审批结果"`
  24. MessageInfo string `description:"消息主要内容,json数据"`
  25. }
  26. // 添加审批消息
  27. func AddCompanyApprovalMessage(item *CompanyApprovalMessage) (err error) {
  28. o := orm.NewOrm()
  29. _, err = o.Insert(item)
  30. return
  31. }
  32. // 修改审批消息
  33. func ModifyCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) {
  34. o := orm.NewOrm()
  35. sql := `UPDATE company_approval_message SET operation_status=2,modify_time=NOW()
  36. WHERE company_approval_id=? AND source_type=? AND message_type=1 AND operation_status=1 `
  37. _, err = o.Raw(sql, companyApprovalId, sourceType).Exec()
  38. return
  39. }
  40. // 消息列表结果
  41. type CompanyApprovalMessageList struct {
  42. Id int `orm:"column(id);pk"`
  43. CreateUserId int `description:"申请者id"`
  44. MessageStatus int `description:"消息状态:0未读,1:已读,2:作废"`
  45. MessageType int `description:"1:申请消息,2:审批结果,3:文字消息"`
  46. ApprovalStatus int `description:"审批结果:1:待审批,2:已审批,3:已驳回"`
  47. SourceType int `description:"消息来源类型,1:客户,2:合同,3:用印"`
  48. Remark string `description:"备注信息"`
  49. Content string `description:"消息内容"`
  50. CompanyName string `description:"客户名称"`
  51. CreateTime time.Time `description:"创建时间"`
  52. RealName string `description:"销售名称"`
  53. CompanyApprovalId int `description:"审批单id"`
  54. MessageInfo string `description:"消息主要内容,json数据" json:"-"`
  55. ApprovalInfo ApprovalInfo `description:"审批单信息"`
  56. BusinessTripInfo *business_trip.BusinessApplyView `description:"出差申请信息"`
  57. }
  58. // 消息审批单信息
  59. type ApprovalInfo struct {
  60. ApplyName string `description:"申请人姓名"`
  61. Type string `description:"类型"`
  62. Title string `description:"主题内容"`
  63. Content string `description:"主体内容"`
  64. CompanyName string `description:"客户信息"`
  65. ApplyTime time.Time `description:"提交时间"`
  66. ApprovalTime time.Time `description:"审批时间"`
  67. Extra string `description:"附加字段: 比如视频评论的标签"`
  68. MessageSource string `description:"消息来源:问答社区/视频社区/线上路演"`
  69. }
  70. type CompanyApprovalMessageListResp struct {
  71. List []*CompanyApprovalMessageList
  72. Total int `description:"总数据条数"`
  73. }
  74. // 待办消息列表
  75. type CompanyApprovalMessageListV2Resp struct {
  76. Company CompanyApprovalMessageListResp `description:"客户"`
  77. Contract CompanyApprovalMessageListResp `description:"合同"`
  78. }
  79. // 获取消息列表总数据
  80. func GetCompanyApprovalMessageCount(sysUserId, sourceType int) (count int, err error) {
  81. sql := `SELECT COUNT(1) AS count FROM company_approval_message AS a
  82. INNER JOIN admin AS b ON a.create_user_id=b.admin_id
  83. WHERE receive_user_id=? AND a.operation_status=1 AND message_status !=2 AND a.source_type=? `
  84. o := orm.NewOrm()
  85. err = o.Raw(sql, sysUserId, sourceType).QueryRow(&count)
  86. return
  87. }
  88. // 消息列表页
  89. func GetCompanyApprovalMessageList(sysUserId, startSize, pageSize int, sourceTypes []int) (items []*CompanyApprovalMessageList, err error) {
  90. sql := `SELECT
  91. a.*, b.real_name
  92. FROM
  93. company_approval_message AS a
  94. INNER JOIN admin AS b ON a.create_user_id = b.admin_id
  95. WHERE
  96. receive_user_id =? AND message_status != 2 AND a.source_type IN (` + utils.GetOrmInReplace(len(sourceTypes)) + `)`
  97. sql += ` ORDER BY create_time DESC LIMIT ?,? `
  98. o := orm.NewOrm()
  99. _, err = o.Raw(sql, sysUserId, sourceTypes, startSize, pageSize).QueryRows(&items)
  100. return
  101. }
  102. // 获取最近一条消息
  103. func GetLastMessage(sysUserId, sourceType int) (item *CompanyApprovalMessageList, err error) {
  104. sql := `SELECT a.*,b.real_name FROM company_approval_message AS a
  105. INNER JOIN admin AS b ON a.create_user_id=b.admin_id
  106. WHERE receive_user_id=? AND message_status !=2 AND source_type=?`
  107. sql += ` ORDER BY create_time DESC `
  108. o := orm.NewOrm()
  109. err = o.Raw(sql, sysUserId, sourceType).QueryRow(&item)
  110. return
  111. }
  112. // 获取最近一条消息
  113. func GetLastMessageBySourceTypes(sysUserId int, sourceType []int) (item *CompanyApprovalMessageList, err error) {
  114. sql := `SELECT
  115. a.*, b.real_name
  116. FROM
  117. company_approval_message AS a
  118. INNER JOIN admin AS b ON a.create_user_id = b.admin_id
  119. WHERE
  120. receive_user_id = ? AND message_status != 2 AND source_type IN (` + utils.GetOrmInReplace(len(sourceType)) + `)
  121. ORDER BY
  122. create_time DESC`
  123. o := orm.NewOrm()
  124. err = o.Raw(sql, sysUserId, sourceType).QueryRow(&item)
  125. return
  126. }
  127. // 获取未读消息数
  128. func GetNotReadMessageTotal(sysUserId, sourceType int) (total int64, err error) {
  129. sql := `SELECT count(*) total FROM company_approval_message AS a
  130. INNER JOIN admin AS b ON a.create_user_id=b.admin_id
  131. WHERE receive_user_id=? AND a.operation_status=1 AND a.message_status =0 AND source_type=?`
  132. o := orm.NewOrm()
  133. err = o.Raw(sql, sysUserId, sourceType).QueryRow(&total)
  134. return
  135. }
  136. // 获取评论未读消息数
  137. func GetCommentNotReadMessageTotal(sysUserId int, types []int) (total int64, err error) {
  138. sql := `SELECT count(*) total FROM company_approval_message AS a
  139. INNER JOIN admin AS b ON a.create_user_id=b.admin_id
  140. WHERE receive_user_id=? AND a.operation_status=1 AND a.message_status =0 AND source_type IN (` + utils.GetOrmInReplace(len(types)) + `)`
  141. o := orm.NewOrm()
  142. err = o.Raw(sql, sysUserId, types).QueryRow(&total)
  143. return
  144. }
  145. // 申请服务更新请求参数
  146. type CompanyApprovalMessageReadReq struct {
  147. Id int `description:"消息id"`
  148. }
  149. // 变更为消息已读状态
  150. func ModifyCompanyApprovalMessageStatus(companyApprovalMessageId int) (err error) {
  151. o := orm.NewOrm()
  152. sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW() WHERE id=?`
  153. _, err = o.Raw(sql, companyApprovalMessageId).Exec()
  154. return
  155. }
  156. // 变更当前类型下所有未读消息为消息已读状态
  157. func ModifyAllCompanyApprovalMessageStatus(receiveUserId int, sourceTypes []int) (err error) {
  158. o := orm.NewOrm()
  159. 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`
  160. _, err = o.Raw(sql, receiveUserId, sourceTypes).Exec()
  161. return
  162. }
  163. // CancelCompanyApprovalMessage 消息作废
  164. func CancelCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) {
  165. o := orm.NewOrm()
  166. sql := `UPDATE company_approval_message SET message_status=2,modify_time=NOW()
  167. WHERE company_approval_id=? AND source_type=? AND message_type=1 AND operation_status=1 `
  168. //sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW() WHERE id=?`
  169. _, err = o.Raw(sql, companyApprovalId, sourceType).Exec()
  170. return
  171. }
  172. // 消息删除
  173. func DeleteCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) {
  174. o := orm.NewOrm()
  175. sql := `DELETE FROM company_approval_message WHERE company_approval_id=? AND source_type=? `
  176. _, err = o.Raw(sql, companyApprovalId, sourceType).Exec()
  177. return
  178. }
  179. // CancelCompanyApprovalMessage 消息作废
  180. func IsReadCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) {
  181. o := orm.NewOrm()
  182. sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW()
  183. WHERE company_approval_id=? AND source_type=? AND message_type=1 AND operation_status=1 `
  184. _, err = o.Raw(sql, companyApprovalId, sourceType).Exec()
  185. return
  186. }