report_mapping_category_group.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxReportMappingCategoryGroup struct {
  7. Id int `orm:"column(id);pk" description:"id"`
  8. ChartPermissionId int `description:"行业ID"`
  9. IdCygx int `description:"表cygx_report_mapping_cygx 主键ID"`
  10. ArticleId int `description:"报告Id"`
  11. CreateTime time.Time `description:"创建时间"`
  12. ModifyTime time.Time `description:"更新时间"`
  13. PermissionType int `description:"1主观,2客观 ,0不限制"`
  14. }
  15. type CygxReportMappingCategoryGroupResp struct {
  16. Id int `orm:"column(id);pk" description:"id"`
  17. ChartPermissionId int `description:"行业ID"`
  18. IdCygx int `description:"表cygx_report_mapping_cygx 主键ID"`
  19. ArticleId int `description:"报告Id"`
  20. CreateTime time.Time `description:"创建时间"`
  21. ModifyTime time.Time `description:"更新时间"`
  22. PermissionType int `description:"1主观,2客观 ,0不限制"`
  23. }
  24. // AddCygxReportMappingCategoryGroupMulti 批量添加
  25. func AddCygxReportMappingCategoryGroupMulti(items []*CygxReportMappingCategoryGroup, articleId int) (err error) {
  26. o, err := orm.NewOrm().Begin()
  27. if err != nil {
  28. return
  29. }
  30. defer func() {
  31. if err == nil {
  32. o.Commit()
  33. } else {
  34. o.Rollback()
  35. }
  36. }()
  37. //删除原有数据
  38. sql := ` DELETE FROM cygx_report_mapping_category_group WHERE article_id = ? AND is_by_hand = 0 `
  39. _, err = o.Raw(sql, articleId).Exec()
  40. if err != nil {
  41. return
  42. }
  43. //批量插入新的关联数据
  44. if len(items) > 0 {
  45. //批量添加流水信息
  46. _, err = o.InsertMulti(len(items), items)
  47. }
  48. return
  49. }
  50. // 列表
  51. func GetCygxReportMappingCategoryGroupList(condition string, pars []interface{}) (items []*CygxReportMappingCategoryGroupResp, err error) {
  52. o := orm.NewOrm()
  53. sql := `SELECT * FROM cygx_report_mapping_category_group as art WHERE 1= 1 `
  54. if condition != "" {
  55. sql += condition
  56. }
  57. _, err = o.Raw(sql, pars).QueryRows(&items)
  58. return
  59. }