company_permission.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CompanyReportPermission struct {
  7. CompanyReportPermissionId int64 `orm:"column(company_report_permission_id);pk"`
  8. CompanyId int
  9. ReportPermissionId int
  10. CreatedTime time.Time
  11. LastUpdatedTime time.Time
  12. ChartPermissionId int
  13. StartDate string `description:"权限开始日期"`
  14. EndDate string `description:"权限结束日期"`
  15. ProductId int `description:"产品id"`
  16. ProductName string `description:"产品名称"`
  17. CompanyContractId int `description:"合同id"`
  18. Status string `description:"'正式','试用','关闭'"`
  19. ModifyTime time.Time `description:"修改时间"`
  20. IsUpgrade int `description:"是否升级,1是,0否"`
  21. ExpensiveYx int `description:"权益研选: 0-3w; 1-5w"`
  22. }
  23. func GetCompanyPermission(companyId int) (permission string, err error) {
  24. sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission
  25. FROM company_report_permission AS a
  26. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  27. INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
  28. WHERE a.company_id=?
  29. AND c.is_suspend=0
  30. AND b.cygx_auth=1
  31. AND c.status IN('正式','试用','永续')
  32. AND a.status IN('正式','试用','永续') `
  33. o := orm.NewOrm()
  34. err = o.Raw(sql, companyId).QueryRow(&permission)
  35. return
  36. }
  37. // GetCompanyReportPermissionByCompanyIdAndProductId 获取权限类型
  38. func GetCompanyReportPermissionByCompanyIdAndProductId(companyId, productId int) (items []*CompanyReportPermission, err error) {
  39. o := orm.NewOrm()
  40. sql := `SELECT
  41. re.*
  42. FROM
  43. company_report_permission as re
  44. INNER JOIN chart_permission as c ON c.chart_permission_id = re.chart_permission_id
  45. WHERE
  46. re.company_id = ?
  47. AND re.product_id = ?
  48. AND STATUS = '正式' `
  49. _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
  50. return
  51. }