company_history_remark.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. // GetCompanyHistoryRemarkList 获取备注列表
  52. func GetCompanyHistoryRemarkListInit() (items []*CompanyHistoryRemark, err error) {
  53. o := orm.NewOrm()
  54. sql := "SELECT * FROM company_history_remark WHERE sys_admin_name LIKE '%6%' AND product_id = 2 ORDER BY show_time DESC "
  55. _, err = o.Raw(sql).QueryRows(&items)
  56. return
  57. }
  58. func GetCompanyHistoryRemarkListInitExport() (items []*CompanyHistoryRemark, err error) {
  59. o := orm.NewOrm()
  60. 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 "
  61. _, err = o.Raw(sql).QueryRows(&items)
  62. return
  63. }
  64. func GetCompanyHistoryRemarkListInitExportinit() (items []*CompanyHistoryRemark, err error) {
  65. o := orm.NewOrm()
  66. 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 "
  67. _, err = o.Raw(sql).QueryRows(&items)
  68. return
  69. }
  70. // DelCompanyHistoryRemark 删除客户历史备注
  71. func DelCompanyHistoryRemark(tableName string, tableId int) (err error) {
  72. o := orm.NewOrm()
  73. sql := `DELETE FROM company_history_remark WHERE table_name = ? AND table_id = ? `
  74. _, err = o.Raw(sql, tableName, tableId).Exec()
  75. return
  76. }
  77. // GetCompanyHistoryRemarkList 获取备注列表
  78. func GetCompanyHistoryRemarkListinit() (items []*CompanyHistoryRemark, err error) {
  79. o := orm.NewOrm()
  80. sql := "SELECT * FROM company_history_remark WHERE table_id > 0 "
  81. _, err = o.Raw(sql).QueryRows(&items)
  82. return
  83. }
  84. // AddCompanyHistoryRemarkMultiinit 批量添加
  85. func AddCompanyHistoryRemarkMultiinit(items []*CompanyHistoryRemark) (err error) {
  86. if len(items) == 0 {
  87. return
  88. }
  89. o, err := orm.NewOrm().Begin()
  90. if err != nil {
  91. return
  92. }
  93. defer func() {
  94. if err == nil {
  95. o.Commit()
  96. } else {
  97. o.Rollback()
  98. }
  99. }()
  100. if len(items) > 0 {
  101. //批量添加流水信息
  102. _, err = o.InsertMulti(len(items), items)
  103. }
  104. return
  105. }