company_delay_permission.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package company_delay_permission
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CompanyDelayPermission struct {
  7. Id int `orm:"column(id);pk"`
  8. CompanyId int `description:"客户id"`
  9. CompanyApplyId int `description:"申请id"`
  10. ChartPermissionId int `description:"权限id"`
  11. StartDate string `description:"开始日期"`
  12. EndDate string `description:"结束日期"`
  13. CreateTime time.Time `description:"创建时间"`
  14. ModifyTime time.Time `description:"修改时间"`
  15. }
  16. //新增客户合同
  17. func AddCompanyDelayPermission(item *CompanyDelayPermission) (err error) {
  18. o := orm.NewOrm()
  19. _, err = o.Insert(item)
  20. return
  21. }
  22. func ModifyCompanyDelayPermission(companyId, companyApplyId, chartPermissionId int) (err error) {
  23. o := orm.NewOrm()
  24. sql := `UPDATE company_delay_permission SET end_date=DATE_FORMAT(DATE_ADD(end_date, INTERVAL 2 MONTH),'%Y-%m-%d') WHERE company_id=? AND company_apply_id=? AND chart_permission_id=? `
  25. _, err = o.Raw(sql, companyId, companyApplyId, chartPermissionId).Exec()
  26. return
  27. }
  28. func GetDelayPermissionCount(companyId, companyApplyId, chartPermissionId int) (count int, err error) {
  29. o := orm.NewOrm()
  30. sql := `SELECT COUNT(1) AS count FROM company_delay_permission WHERE company_id=? AND company_apply_id=? AND chart_permission_id=? `
  31. err = o.Raw(sql, companyId, companyApplyId, chartPermissionId).QueryRow(&count)
  32. return
  33. }
  34. func GetApplyDelayPermission(companyApplyId int) (delay_permission string, err error) {
  35. o := orm.NewOrm()
  36. sql := ` SELECT GROUP_CONCAT(DISTINCT b.permission_name SEPARATOR ' ') AS delay_permission FROM company_delay_permission AS a
  37. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  38. WHERE company_apply_id=? `
  39. err = o.Raw(sql, companyApplyId).QueryRow(&delay_permission)
  40. return
  41. }
  42. func GetDelayPermissionItems(companyId, companyApplyId int) (items []*CompanyDelayPermission, err error) {
  43. o := orm.NewOrm()
  44. sql := `SELECT * FROM company_delay_permission WHERE company_id=? AND company_apply_id=? `
  45. _, err = o.Raw(sql, companyId, companyApplyId).QueryRows(&items)
  46. return
  47. }
  48. //根据合同id删除对应的权限
  49. func DeleteCompanyDelayPermission(companyApplyId int) (err error) {
  50. o := orm.NewOrm()
  51. sql := `DELETE FROM company_delay_permission WHERE company_apply_id=? `
  52. _, err = o.Raw(sql, companyApplyId).Exec()
  53. return
  54. }