company_service_record.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package company
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "strings"
  7. "time"
  8. )
  9. // CompanyServiceRecord 客户-服务记录表
  10. type CompanyServiceRecord struct {
  11. CompanyServiceRecordId int `orm:"column(company_service_record_id);pk" description:"服务记录ID"`
  12. CompanyType int `description:"客户类型,1:英文客户,2:中文客户"`
  13. CompanyId int `description:"客户ID"`
  14. Content string `description:"内容"`
  15. SysAdminId int `description:"创建人ID"`
  16. SysAdminName string `description:"创建人姓名"`
  17. CreateTime time.Time `description:"创建时间"`
  18. ModifyTime time.Time `description:"修改时间"`
  19. Mark int `description:"是否标记 0不是 1是"`
  20. }
  21. var CompanyServiceRecordColumns = struct {
  22. CompanyServiceRecordId string
  23. CompanyType string
  24. CompanyId string
  25. Content string
  26. SysAdminId string
  27. SysAdminName string
  28. CreateTime string
  29. ModifyTime string
  30. }{
  31. CompanyServiceRecordId: "company_service_record_id",
  32. CompanyType: "company_type",
  33. CompanyId: "company_id",
  34. Content: "content",
  35. SysAdminId: "sys_admin_id",
  36. SysAdminName: "sys_admin_name",
  37. CreateTime: "create_time",
  38. ModifyTime: "modify_time",
  39. }
  40. func (m *CompanyServiceRecord) TableName() string {
  41. return "company_service_record"
  42. }
  43. func (m *CompanyServiceRecord) Create() (newId int, err error) {
  44. o := orm.NewOrm()
  45. id, err := o.Insert(m)
  46. if err != nil {
  47. return
  48. }
  49. newId = int(id)
  50. return
  51. }
  52. func (m *CompanyServiceRecord) Update(cols []string) (err error) {
  53. o := orm.NewOrm()
  54. _, err = o.Update(m, cols...)
  55. return
  56. }
  57. func (m *CompanyServiceRecord) Del() (err error) {
  58. o := orm.NewOrm()
  59. sql := `DELETE FROM company_service_record WHERE company_service_record_id = ? LIMIT 1`
  60. _, err = o.Raw(sql, m.CompanyServiceRecordId).Exec()
  61. return
  62. }
  63. func (m *CompanyServiceRecord) GetItemById(id int) (err error) {
  64. o := orm.NewOrm()
  65. sql := `SELECT * FROM company_service_record WHERE company_service_record_id = ? LIMIT 1`
  66. err = o.Raw(sql, id).QueryRow(&m)
  67. return
  68. }
  69. func (m *CompanyServiceRecord) GetItemByCondition(condition string, pars []interface{}) (err error) {
  70. o := orm.NewOrm()
  71. sql := `SELECT * FROM company_service_record WHERE 1=1 `
  72. sql += condition
  73. sql += ` LIMIT 1`
  74. err = o.Raw(sql, pars).QueryRow(&m)
  75. return
  76. }
  77. func (m *CompanyServiceRecord) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  78. o := orm.NewOrm()
  79. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  80. err = o.Raw(sql, pars).QueryRow(&count)
  81. return
  82. }
  83. func (m *CompanyServiceRecord) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*CompanyServiceRecord, err error) {
  84. o := orm.NewOrm()
  85. fields := strings.Join(fieldArr, ",")
  86. if len(fieldArr) == 0 {
  87. fields = `*`
  88. }
  89. order := `ORDER BY create_time DESC`
  90. if orderRule != "" {
  91. order = ` ORDER BY ` + orderRule
  92. }
  93. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  94. _, err = o.Raw(sql, pars).QueryRows(&items)
  95. return
  96. }
  97. func (m *CompanyServiceRecord) GetPageItemsByCondition(startSize, pageSize int, condition string, pars []interface{}, fieldArr []string, orderRule string) (total int, items []*CompanyServiceRecord, err error) {
  98. o := orm.NewOrm()
  99. fields := strings.Join(fieldArr, ",")
  100. if len(fieldArr) == 0 {
  101. fields = `*`
  102. }
  103. order := `ORDER BY create_time DESC`
  104. if orderRule != "" {
  105. order = ` ORDER BY ` + orderRule
  106. }
  107. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  108. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  109. if err = o.Raw(totalSql, pars).QueryRow(&total); err != nil {
  110. return
  111. }
  112. sql += ` LIMIT ?,?`
  113. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  114. return
  115. }
  116. type CompanyServiceRecordAddReq struct {
  117. CompanyType int `description:"客户类型,0:中文客户,1:英文客户"`
  118. CompanyId int `description:"客户ID"`
  119. Content string `description:"内容"`
  120. }
  121. type CompanyServiceRecordDelReq struct {
  122. CompanyServiceRecordId int `description:"服务记录ID"`
  123. }
  124. type CompanyServiceRecordPageListResp struct {
  125. List []*CompanyServiceRecordItem
  126. Paging *paging.PagingItem `description:"分页数据"`
  127. }
  128. type CompanyServiceRecordItem struct {
  129. CompanyServiceRecordId int `description:"文档ID"`
  130. Content string `description:"服务描述"`
  131. SysAdminId int `description:"创建人ID"`
  132. SysAdminName string `description:"创建人姓名"`
  133. CreateTime string `description:"创建时间"`
  134. Mark int `description:"是否标记 0不是 1是"`
  135. }
  136. // 更新备注标记
  137. func UpdateCompanyServiceRecordMark(remarkId, mark int) (err error) {
  138. o := orm.NewOrm()
  139. sql := `UPDATE company_service_record SET mark=? WHERE company_service_record_id=? `
  140. _, err = o.Raw(sql, mark, remarkId).Exec()
  141. return
  142. }