company_approval_message.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. AffiliatedCompany string `description:"归属公司-用印审批用"`
  58. }
  59. // 消息审批单信息
  60. type ApprovalInfo struct {
  61. ApplyName string `description:"申请人姓名"`
  62. Type string `description:"类型"`
  63. Title string `description:"主题内容"`
  64. Content string `description:"主体内容"`
  65. CompanyName string `description:"客户信息"`
  66. ApplyTime time.Time `description:"提交时间"`
  67. ApprovalTime time.Time `description:"审批时间"`
  68. Extra string `description:"附加字段: 比如视频评论的标签"`
  69. MessageSource string `description:"消息来源:问答社区/视频社区/线上路演"`
  70. }
  71. type CompanyApprovalMessageListResp struct {
  72. List []*CompanyApprovalMessageList
  73. Total int `description:"总数据条数"`
  74. }
  75. // 待办消息列表
  76. type CompanyApprovalMessageListV2Resp struct {
  77. Company CompanyApprovalMessageListResp `description:"客户"`
  78. Contract CompanyApprovalMessageListResp `description:"合同"`
  79. }
  80. // 获取消息列表总数据
  81. func GetCompanyApprovalMessageCount(sysUserId, sourceType int) (count int, err error) {
  82. sql := `SELECT COUNT(1) AS count FROM company_approval_message AS a
  83. INNER JOIN admin AS b ON a.create_user_id=b.admin_id
  84. WHERE receive_user_id=? AND a.operation_status=1 AND message_status !=2 AND a.source_type=? `
  85. o := orm.NewOrm()
  86. err = o.Raw(sql, sysUserId, sourceType).QueryRow(&count)
  87. return
  88. }
  89. // 消息列表页
  90. func GetCompanyApprovalMessageList(sysUserId, startSize, pageSize int, sourceTypes []int) (items []*CompanyApprovalMessageList, err error) {
  91. sql := `SELECT
  92. a.*, b.real_name
  93. FROM
  94. company_approval_message AS a
  95. INNER JOIN admin AS b ON a.create_user_id = b.admin_id
  96. WHERE
  97. receive_user_id =? AND message_status != 2 AND a.source_type IN (` + utils.GetOrmInReplace(len(sourceTypes)) + `)`
  98. sql += ` ORDER BY create_time DESC LIMIT ?,? `
  99. o := orm.NewOrm()
  100. _, err = o.Raw(sql, sysUserId, sourceTypes, startSize, pageSize).QueryRows(&items)
  101. return
  102. }
  103. // 获取最近一条消息
  104. func GetLastMessage(sysUserId, sourceType int) (item *CompanyApprovalMessageList, err error) {
  105. sql := `SELECT a.*,b.real_name FROM company_approval_message AS a
  106. INNER JOIN admin AS b ON a.create_user_id=b.admin_id
  107. WHERE receive_user_id=? AND message_status !=2 AND source_type=?`
  108. sql += ` ORDER BY create_time DESC `
  109. o := orm.NewOrm()
  110. err = o.Raw(sql, sysUserId, sourceType).QueryRow(&item)
  111. return
  112. }
  113. // 获取最近一条消息
  114. func GetLastMessageBySourceTypes(sysUserId int, sourceType []int) (item *CompanyApprovalMessageList, err error) {
  115. sql := `SELECT
  116. a.*, b.real_name
  117. FROM
  118. company_approval_message AS a
  119. INNER JOIN admin AS b ON a.create_user_id = b.admin_id
  120. WHERE
  121. receive_user_id = ? AND message_status != 2 AND source_type IN (` + utils.GetOrmInReplace(len(sourceType)) + `)
  122. ORDER BY
  123. create_time DESC`
  124. o := orm.NewOrm()
  125. err = o.Raw(sql, sysUserId, sourceType).QueryRow(&item)
  126. return
  127. }
  128. // 获取未读消息数
  129. func GetNotReadMessageTotal(sysUserId, sourceType int) (total int64, err error) {
  130. sql := `SELECT count(*) total FROM company_approval_message AS a
  131. INNER JOIN admin AS b ON a.create_user_id=b.admin_id
  132. WHERE receive_user_id=? AND a.operation_status=1 AND a.message_status =0 AND source_type=?`
  133. o := orm.NewOrm()
  134. err = o.Raw(sql, sysUserId, sourceType).QueryRow(&total)
  135. return
  136. }
  137. // 获取评论未读消息数
  138. func GetCommentNotReadMessageTotal(sysUserId int, types []int) (total int64, err error) {
  139. sql := `SELECT count(*) total FROM company_approval_message AS a
  140. INNER JOIN admin AS b ON a.create_user_id=b.admin_id
  141. WHERE receive_user_id=? AND a.operation_status=1 AND a.message_status =0 AND source_type IN (` + utils.GetOrmInReplace(len(types)) + `)`
  142. o := orm.NewOrm()
  143. err = o.Raw(sql, sysUserId, types).QueryRow(&total)
  144. return
  145. }
  146. // 申请服务更新请求参数
  147. type CompanyApprovalMessageReadReq struct {
  148. Id int `description:"消息id"`
  149. }
  150. // 变更为消息已读状态
  151. func ModifyCompanyApprovalMessageStatus(companyApprovalMessageId int) (err error) {
  152. o := orm.NewOrm()
  153. sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW() WHERE id=?`
  154. _, err = o.Raw(sql, companyApprovalMessageId).Exec()
  155. return
  156. }
  157. // 变更当前类型下所有未读消息为消息已读状态
  158. func ModifyAllCompanyApprovalMessageStatus(receiveUserId int, sourceTypes []int) (err error) {
  159. o := orm.NewOrm()
  160. 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`
  161. _, err = o.Raw(sql, receiveUserId, sourceTypes).Exec()
  162. return
  163. }
  164. // CancelCompanyApprovalMessage 消息作废
  165. func CancelCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) {
  166. o := orm.NewOrm()
  167. sql := `UPDATE company_approval_message SET message_status=2,modify_time=NOW()
  168. WHERE company_approval_id=? AND source_type=? AND message_type=1 AND operation_status=1 `
  169. //sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW() WHERE id=?`
  170. _, err = o.Raw(sql, companyApprovalId, sourceType).Exec()
  171. return
  172. }
  173. // 消息删除
  174. func DeleteCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) {
  175. o := orm.NewOrm()
  176. sql := `DELETE FROM company_approval_message WHERE company_approval_id=? AND source_type=? `
  177. _, err = o.Raw(sql, companyApprovalId, sourceType).Exec()
  178. return
  179. }
  180. // CancelCompanyApprovalMessage 消息作废
  181. func IsReadCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) {
  182. o := orm.NewOrm()
  183. sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW()
  184. WHERE company_approval_id=? AND source_type=? AND message_type=1 AND operation_status=1 `
  185. _, err = o.Raw(sql, companyApprovalId, sourceType).Exec()
  186. return
  187. }