company_history_remark.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package company
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CompanyHistoryRemark struct {
  7. HistoryId int `orm:"column(history_id);pk" comment:"备注id"`
  8. CompanyId int `comment:"客户ID"`
  9. ProductId int `comment:"产品id"`
  10. Content string `comment:"备注内容"`
  11. SysAdminId int `comment:"创建人ID"`
  12. SysAdminName string `comment:"创建人姓名"`
  13. CreateTime time.Time `comment:"创建时间"`
  14. ModifyTime time.Time `comment:"更新时间"`
  15. TableName string `comment:"表名"`
  16. TableId int `comment:"表ID"`
  17. UserId int `comment:"用户ID"`
  18. Mobile string `comment:"手机号"`
  19. Email string `comment:"邮箱"`
  20. RealName string `comment:"用户实际名称"`
  21. ShowTime time.Time `comment:"对外展示的创建时间"`
  22. }
  23. // CompanyHistoryRemarkReq 新增历史备注请求
  24. type CompanyHistoryRemarkReq struct {
  25. CompanyId int `description:"客户id"`
  26. Content string `description:"备注内容"`
  27. }
  28. // 新增
  29. func AddCompanyHistoryRemark(remark *CompanyHistoryRemark) (err error) {
  30. o := orm.NewOrm()
  31. _, err = o.Insert(remark)
  32. return
  33. }
  34. type CompanyHistoryRemarkResp struct {
  35. CompanyId int `comment:"客户ID"`
  36. Content string `comment:"备注内容"`
  37. SysAdminName string `comment:"创建人姓名"`
  38. RemarkType string `comment:"备注类型"`
  39. CreateTime string `comment:"对外展示的创建时间"`
  40. }
  41. type CompanyHistoryRemarkListResp struct {
  42. List []*CompanyHistoryRemarkResp
  43. }
  44. // GetCompanyHistoryRemarkList 获取备注列表
  45. func GetCompanyHistoryRemarkList(CompanyId, ProductId string) (items []*CompanyHistoryRemark, err error) {
  46. o := orm.NewOrm()
  47. sql := "SELECT * FROM company_history_remark WHERE company_id=? AND product_id=? ORDER BY show_time DESC "
  48. _, err = o.Raw(sql, CompanyId, ProductId).QueryRows(&items)
  49. return
  50. }
  51. func GetCompanyHistoryRemarkListInitExport() (items []*CompanyHistoryRemark, err error) {
  52. o := orm.NewOrm()
  53. sql := "SELECT * FROM company_history_remark WHERE product_id=2 AND show_time >= '2024-07-24' AND show_time < '2024-09-23' AND table_name IN ('company_service_record','company_history_remark') ORDER BY show_time DESC "
  54. _, err = o.Raw(sql).QueryRows(&items)
  55. return
  56. }
  57. func GetCompanyHistoryRemarkListInitExportinit() (items []*CompanyHistoryRemark, err error) {
  58. o := orm.NewOrm()
  59. sql := "SELECT\n\t* \nFROM\n\tcompany_history_remark \nWHERE\n\tproduct_id = 2 \n\tAND show_time >= '2024-07-01' \n\tAND show_time < '2024-10-01' \n\tAND table_name IN ( 'company_service_record', 'company_history_remark' ) \n\tAND \tsys_admin_id IN ( SELECT admin_id FROM admin WHERE group_id IN ( 68, 72 ) ) \nORDER BY\n\tshow_time DESC "
  60. _, err = o.Raw(sql).QueryRows(&items)
  61. return
  62. }
  63. // DelCompanyHistoryRemark 删除客户历史备注
  64. func DelCompanyHistoryRemark(tableName string, tableId int) (err error) {
  65. o := orm.NewOrm()
  66. sql := `DELETE FROM company_history_remark WHERE table_name = ? AND table_id = ? `
  67. _, err = o.Raw(sql, tableName, tableId).Exec()
  68. return
  69. }
  70. // GetCompanyHistoryRemarkList 获取备注列表
  71. func GetCompanyHistoryRemarkListinit() (items []*CompanyHistoryRemark, err error) {
  72. o := orm.NewOrm()
  73. sql := "SELECT * FROM company_history_remark WHERE table_id > 0 "
  74. _, err = o.Raw(sql).QueryRows(&items)
  75. return
  76. }
  77. // AddCompanyHistoryRemarkMultiinit 批量添加
  78. func AddCompanyHistoryRemarkMultiinit(items []*CompanyHistoryRemark) (err error) {
  79. if len(items) == 0 {
  80. return
  81. }
  82. o, err := orm.NewOrm().Begin()
  83. if err != nil {
  84. return
  85. }
  86. defer func() {
  87. if err == nil {
  88. o.Commit()
  89. } else {
  90. o.Rollback()
  91. }
  92. }()
  93. if len(items) > 0 {
  94. //批量添加流水信息
  95. _, err = o.InsertMulti(len(items), items)
  96. }
  97. return
  98. }