rai_serve_week_bill.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package rai_serve
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxRaiServeWeekBill struct {
  7. ServeWeekBillId int `orm:"column(serve_week_bill_id);pk" description:"服务周账单ID"`
  8. CompanyId int `comment:"公司ID"`
  9. CompanyName string `comment:"公司名称"`
  10. UserTotal int `comment:"用户数量"`
  11. WeekServeCount float64 `comment:"周度服务量总计"`
  12. CoverageRate float64 `comment:"覆盖率"`
  13. WeekStartDate string `comment:"周一开始日期"`
  14. WeekEndDate string `comment:"周日结束日期"`
  15. CreateTime time.Time `comment:"创建时间"`
  16. ModifyTime time.Time `comment:"修改时间"`
  17. }
  18. // AddCygxRaiServeWeekBillMulti 批量添加
  19. func AddCygxRaiServeWeekBillMulti(items []*CygxRaiServeWeekBill) (err error) {
  20. if len(items) == 0 {
  21. return
  22. }
  23. o, err := orm.NewOrm().Begin()
  24. if err != nil {
  25. return
  26. }
  27. defer func() {
  28. if err == nil {
  29. o.Commit()
  30. } else {
  31. o.Rollback()
  32. }
  33. }()
  34. if len(items) > 0 {
  35. //批量添加流水信息
  36. _, err = o.InsertMulti(len(items), items)
  37. }
  38. return
  39. }
  40. // UpdateCygxRaiServeWeekBillMulti 批量修改客户周度信息
  41. func UpdateCygxRaiServeWeekBillMulti(items []*CygxRaiServeWeekBill) (err error) {
  42. o := orm.NewOrm()
  43. p, err := o.Raw("UPDATE cygx_rai_serve_week_bill SET user_total = ? , week_serve_count =? , coverage_rate =? ,modify_time = ? WHERE company_id = ? AND week_start_date = ? ").Prepare()
  44. if err != nil {
  45. return
  46. }
  47. defer func() {
  48. _ = p.Close() // 别忘记关闭 statement
  49. }()
  50. for _, v := range items {
  51. _, err = p.Exec(v.UserTotal, v.WeekServeCount, v.CoverageRate, v.ModifyTime, v.CompanyId, v.WeekStartDate)
  52. if err != nil {
  53. return
  54. }
  55. }
  56. return
  57. }
  58. // 列表
  59. func GetCygxRaiServeWeekBillListAll(condition string, pars []interface{}) (items []*CygxRaiServeWeekBill, err error) {
  60. if condition == "" {
  61. return
  62. }
  63. o := orm.NewOrm()
  64. sql := `SELECT * FROM cygx_rai_serve_week_bill WHERE 1= 1 `
  65. if condition != "" {
  66. sql += condition
  67. }
  68. _, err = o.Raw(sql, pars).QueryRows(&items)
  69. return
  70. }