company_no_renewed_ascribe.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package company
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CompanyNoRenewedAscribe struct {
  7. NoRenewedAscribeId int `orm:"column(no_renewed_ascribe_id);pk" description:"主键ID"`
  8. CompanyAscribeId int `description:"归因ID"`
  9. AscribeContent string `description:"归因说明"`
  10. Content string `description:"内容说明"`
  11. AdminId int `description:"管理员ID"`
  12. CompanyId int `description:"公司ID"`
  13. ProductId int `description:"产品id"`
  14. CreateTime time.Time `description:"创建时间"`
  15. ModifyTime time.Time `description:"更新时间"`
  16. }
  17. type CompanyNoRenewedAscribeLog struct {
  18. NoRenewedAscribeId int `orm:"column(no_renewed_ascribe_id);pk" description:"主键ID"`
  19. CompanyAscribeId int `description:"归因ID"`
  20. AscribeContent string `description:"归因说明"`
  21. Content string `description:"内容说明"`
  22. AdminId int `description:"管理员ID"`
  23. CompanyId int `description:"公司ID"`
  24. ProductId int `description:"产品id"`
  25. CreateTime time.Time `description:"创建时间"`
  26. ModifyTime time.Time `description:"更新时间"`
  27. }
  28. type CompanyNoRenewedAscribeResp struct {
  29. NoRenewedAscribeId int `description:"主键ID"`
  30. CompanyAscribeId int `description:"归因ID"`
  31. AscribeContent string `description:"归因说明"`
  32. ProductId int `description:"产品id"`
  33. Content string `description:"内容说明"`
  34. AdminId int `description:"管理员ID"`
  35. CompanyId int `description:"公司ID"`
  36. CreateTime string `description:"创建时间"`
  37. ModifyTime string `description:"更新时间"`
  38. }
  39. type CompanyNoRenewedAscribeListResp struct {
  40. List []*CompanyNoRenewedAscribeResp
  41. }
  42. type CompanyNoRenewedAscribeDetailResp struct {
  43. Detail *CompanyNoRenewedAscribeResp
  44. }
  45. type CompanyNoRenewedAscribeReq struct {
  46. CompanyAscribeId int `description:"归因ID"`
  47. ProductId int `description:"产品id"`
  48. Content string `description:"内容说明"`
  49. CompanyId int `description:"公司ID"`
  50. }
  51. // 添加
  52. func AddCompanyNoRenewedAscribe(item *CompanyNoRenewedAscribe, itemLog *CompanyNoRenewedAscribeLog) (err error) {
  53. o := orm.NewOrm()
  54. to, err := o.Begin()
  55. if err != nil {
  56. return
  57. }
  58. defer func() {
  59. if err != nil {
  60. _ = to.Rollback()
  61. } else {
  62. _ = to.Commit()
  63. }
  64. }()
  65. _, err = to.Insert(item)
  66. if err != nil {
  67. return
  68. }
  69. _, err = to.Insert(itemLog)
  70. return
  71. }
  72. // 修改
  73. func UpdateCompanyNoRenewedAscribe(item *CompanyNoRenewedAscribe, itemLog *CompanyNoRenewedAscribeLog) (err error) {
  74. o := orm.NewOrm()
  75. to, err := o.Begin()
  76. if err != nil {
  77. return
  78. }
  79. defer func() {
  80. if err != nil {
  81. _ = to.Rollback()
  82. } else {
  83. _ = to.Commit()
  84. }
  85. }()
  86. updateParams := make(map[string]interface{})
  87. updateParams["CompanyAscribeId"] = item.CompanyAscribeId
  88. updateParams["ModifyTime"] = item.ModifyTime
  89. updateParams["Content"] = item.Content
  90. updateParams["AscribeContent"] = item.AscribeContent
  91. ptrStructOrTableName := "company_no_renewed_ascribe"
  92. whereParam := map[string]interface{}{"company_id": item.CompanyId, "product_id": item.ProductId}
  93. qs := to.QueryTable(ptrStructOrTableName)
  94. for expr, exprV := range whereParam {
  95. qs = qs.Filter(expr, exprV)
  96. }
  97. _, err = qs.Update(updateParams)
  98. if err != nil {
  99. return
  100. }
  101. _, err = to.Insert(itemLog)
  102. return
  103. }
  104. // 获取数量
  105. func GetCompanyNoRenewedAscribeCount(condition string, pars []interface{}) (count int, err error) {
  106. sqlCount := ` SELECT COUNT(1) AS count FROM company_no_renewed_ascribe as a WHERE 1= 1 `
  107. if condition != "" {
  108. sqlCount += condition
  109. }
  110. o := orm.NewOrm()
  111. err = o.Raw(sqlCount, pars).QueryRow(&count)
  112. return
  113. }
  114. // 通过ID获取详情
  115. func GetCompanyNoRenewedAscribeDetail(companyId, productId int) (item *CompanyNoRenewedAscribeResp, err error) {
  116. o := orm.NewOrm()
  117. sql := `SELECT * FROM company_no_renewed_ascribe WHERE company_id=? AND product_id = ? `
  118. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  119. return
  120. }
  121. // 列表
  122. func GetCompanyNoRenewedAscribeList(condition string, pars []interface{}, startSize, pageSize int) (items []*CompanyNoRenewedAscribeResp, err error) {
  123. o := orm.NewOrm()
  124. sql := `SELECT * FROM company_no_renewed_ascribe as a WHERE 1= 1 `
  125. if condition != "" {
  126. sql += condition
  127. }
  128. if startSize+pageSize > 0 {
  129. sql += ` LIMIT ?,? `
  130. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  131. }
  132. _, err = o.Raw(sql, pars).QueryRows(&items)
  133. return
  134. }