company_approval_message.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package company
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type CompanyApprovalMessage struct {
  8. Id int `orm:"column(id);pk"`
  9. CreateUserId int `description:"申请者id"`
  10. ReceiveUserId int `description:"审批者id"`
  11. MessageStatus int `description:"消息状态:0未读,1:已读"`
  12. SourceType int `description:"消息来源类型,1:客户,2:合同,3:用印"`
  13. Remark string `description:"备注信息"`
  14. Content string `description:"消息内容"`
  15. CompanyId int `description:"客户id"`
  16. CompanyName string `description:"客户名称"`
  17. CreateTime time.Time `description:"创建时间"`
  18. ModifyTime time.Time `description:"修改时间"`
  19. CompanyApprovalId int `description:"审批单id"`
  20. ApprovalStatus int `description:"审批状态:1:待审批,2:已审批,3:已驳回"`
  21. OperationStatus int `description:"消息状态:1:待审批,2:已审批"`
  22. MessageType int `description:"1:申请消息,2:审批结果,3:文字消息"`
  23. MessageInfo string `description:"消息主要内容,json数据"`
  24. }
  25. // 添加审批消息
  26. func AddCompanyApprovalMessage(item *CompanyApprovalMessage) (err error) {
  27. o := orm.NewOrm()
  28. _, err = o.Insert(item)
  29. return
  30. }
  31. // GetCompanyApprovalMessageById 主键获取消息
  32. func GetCompanyApprovalMessageById(id int) (item *CompanyApprovalMessage, err error) {
  33. o := orm.NewOrm()
  34. sql := `SELECT * FROM company_approval_message WHERE id = ? LIMIT 1`
  35. err = o.Raw(sql, id).QueryRow(&item)
  36. return
  37. }
  38. type CompanyApprovalMessageList struct {
  39. Id int `orm:"column(id);pk"`
  40. MessageStatus int `description:"消息状态:0未读,1:已读,2:作废"`
  41. SourceType int `description:"消息来源类型,1:客户,2:合同 3:用印"`
  42. Remark string `description:"备注信息"`
  43. Content string `description:"消息内容"`
  44. CompanyName string `description:"客户名称"`
  45. CreateTime string `description:"创建时间"`
  46. RealName string `description:"销售名称"`
  47. CompanyApprovalId int `description:"审批单id"`
  48. ApprovalStatus int `description:"审批状态:1:待审批,2:已审批,3:已驳回"`
  49. }
  50. type CompanyApprovalMessageListResp struct {
  51. List []*CompanyApprovalMessageList
  52. Total int `description:"总数据条数"`
  53. }
  54. // 待办消息列表
  55. type CompanyApprovalMessageListV2Resp struct {
  56. Company CompanyApprovalMessageListResp `description:"客户"`
  57. Contract CompanyApprovalMessageListResp `description:"合同"`
  58. Seal CompanyApprovalMessageListResp `description:"用印"`
  59. EdbReplace CompanyApprovalMessageListResp `description:"指标替换"`
  60. ETATrial ETATrialApprovalMessageListResp `description:"ETA试用"`
  61. BusinessTrip CompanyApprovalMessageListResp `description:"出差"`
  62. }
  63. type ETATrialApprovalMessageListResp struct {
  64. List []*ETATrialApprovalMessageList
  65. Total int `description:"总数据条数"`
  66. }
  67. type ETATrialApprovalMessageList struct {
  68. Id int `orm:"column(id);pk"`
  69. MessageStatus int `description:"消息状态:0未读,1:已读,2:作废"`
  70. SourceType int `description:"消息来源类型,1:客户,2:合同 3:用印 4:指标替换 5:ETA试用"`
  71. Remark string `description:"备注信息"`
  72. Content string `description:"消息内容"`
  73. CompanyName string `description:"客户名称"`
  74. CreateTime string `description:"创建时间"`
  75. RealName string `description:"销售名称"`
  76. Redirect int `description:"跳转路径 1用户列表 2审批列表"`
  77. }
  78. func GetCompanyApprovalMessageList(sysUserId int, startTime string) (items []*CompanyApprovalMessageList, err error) {
  79. sql := `SELECT a.*,b.real_name FROM company_approval_message AS a
  80. INNER JOIN admin AS b ON a.create_user_id=b.admin_id
  81. WHERE receive_user_id=? AND a.operation_status=1 AND message_status !=2 `
  82. if startTime != "" {
  83. sql += ` AND create_time>='` + startTime + `'`
  84. }
  85. sql += ` ORDER BY create_time DESC `
  86. o := orm.NewOrm()
  87. _, err = o.Raw(sql, sysUserId).QueryRows(&items)
  88. return
  89. }
  90. func GetCompanyApprovalMessageCount(sysUserId int, startTime string) (count int, err error) {
  91. sql := `SELECT COUNT(1) AS count FROM company_approval_message AS a
  92. INNER JOIN admin AS b ON a.create_user_id=b.admin_id
  93. WHERE receive_user_id=? AND a.operation_status=1 AND message_status !=2 `
  94. if startTime != "" {
  95. sql += ` AND create_time>='` + startTime + `'`
  96. }
  97. o := orm.NewOrm()
  98. err = o.Raw(sql, sysUserId).QueryRow(&count)
  99. return
  100. }
  101. // 修改消息信息
  102. func ModifyCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) {
  103. o := orm.NewOrm()
  104. sql := `UPDATE company_approval_message SET operation_status=2,modify_time=NOW()
  105. WHERE company_approval_id=? AND source_type=? AND message_type=1 AND operation_status=1 `
  106. _, err = o.Raw(sql, companyApprovalId, sourceType).Exec()
  107. return
  108. }
  109. // 申请服务更新请求参数
  110. type CompanyApprovalMessageReadReq struct {
  111. Id int `description:"消息id"`
  112. }
  113. func ModifyCompanyApprovalMessageStatus(companyApprovalMessageId int) (err error) {
  114. o := orm.NewOrm()
  115. sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW() WHERE id=?`
  116. _, err = o.Raw(sql, companyApprovalMessageId).Exec()
  117. return
  118. }
  119. // 消息作废
  120. func CancelCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) {
  121. o := orm.NewOrm()
  122. sql := `UPDATE company_approval_message SET message_status=2,modify_time=NOW()
  123. WHERE company_approval_id=? AND source_type=? AND message_type=1 AND operation_status=1 `
  124. //sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW() WHERE id=?`
  125. _, err = o.Raw(sql, companyApprovalId, sourceType).Exec()
  126. return
  127. }
  128. func GetAdminCompanyApprovalMessageList(startTime string) (items []*CompanyApprovalMessageList, err error) {
  129. sql := `SELECT a.*,b.real_name 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 = -1 AND a.operation_status=1 AND message_status !=2 `
  132. if startTime != "" {
  133. sql += ` AND create_time>='` + startTime + `'`
  134. }
  135. sql += ` ORDER BY create_time DESC `
  136. o := orm.NewOrm()
  137. _, err = o.Raw(sql).QueryRows(&items)
  138. return
  139. }
  140. // 消息删除
  141. func DeleteCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) {
  142. o := orm.NewOrm()
  143. sql := `DELETE FROM company_approval_message WHERE company_approval_id=? AND source_type=? `
  144. _, err = o.Raw(sql, companyApprovalId, sourceType).Exec()
  145. return
  146. }
  147. // CancelCompanyApprovalMessage 消息作废
  148. func IsReadCompanyApprovalMessage(companyApprovalId, sourceType int) (err error) {
  149. o := orm.NewOrm()
  150. sql := `UPDATE company_approval_message SET message_status=1,modify_time=NOW()
  151. WHERE company_approval_id=? AND source_type=? AND message_type=1 AND operation_status=1 `
  152. _, err = o.Raw(sql, companyApprovalId, sourceType).Exec()
  153. return
  154. }
  155. // ModifyCompanyApprovalMessageStatusByCond 条件修改已读状态
  156. func ModifyCompanyApprovalMessageStatusByCond(cond string, pars []interface{}) (err error) {
  157. o := orm.NewOrm()
  158. sql := `UPDATE company_approval_message SET message_status = 1, modify_time = NOW() WHERE 1 = 1 %s`
  159. sql = fmt.Sprintf(sql, cond)
  160. _, err = o.Raw(sql, pars).Exec()
  161. return
  162. }