company_history_remark.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // DelCompanyHistoryRemark 删除客户历史备注
  52. func DelCompanyHistoryRemark(tableName string, tableId int) (err error) {
  53. o := orm.NewOrm()
  54. sql := `DELETE FROM company_history_remark WHERE table_name = ? AND table_id = ? `
  55. _, err = o.Raw(sql, tableName, tableId).Exec()
  56. return
  57. }
  58. // GetCompanyHistoryRemarkList 获取备注列表
  59. func GetCompanyHistoryRemarkListinit() (items []*CompanyHistoryRemark, err error) {
  60. o := orm.NewOrm()
  61. sql := "SELECT * FROM company_history_remark WHERE table_id > 0 "
  62. _, err = o.Raw(sql).QueryRows(&items)
  63. return
  64. }
  65. // AddCompanyHistoryRemarkMultiinit 批量添加
  66. func AddCompanyHistoryRemarkMultiinit(items []*CompanyHistoryRemark) (err error) {
  67. if len(items) == 0 {
  68. return
  69. }
  70. o, err := orm.NewOrm().Begin()
  71. if err != nil {
  72. return
  73. }
  74. defer func() {
  75. if err == nil {
  76. o.Commit()
  77. } else {
  78. o.Rollback()
  79. }
  80. }()
  81. if len(items) > 0 {
  82. //批量添加流水信息
  83. _, err = o.InsertMulti(len(items), items)
  84. }
  85. return
  86. }