maycur.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package controllers
  2. import (
  3. "hongze/hz_crm_api/models"
  4. "hongze/hz_crm_api/services/maycur"
  5. "hongze/hz_crm_api/utils"
  6. "time"
  7. )
  8. // MaycurController 每刻报销
  9. type MaycurController struct {
  10. BaseAuthController
  11. }
  12. // MaycurOpenController 每刻报销-无鉴权
  13. type MaycurOpenController struct {
  14. BaseCommonController
  15. }
  16. // SyncCompanyProfile
  17. // @Title 主动触发-同步客户档案及权限
  18. // @Description 同步客户档案及权限
  19. // @Success 200 Ret=200 操作成功
  20. // @router /company_profile/sync [post]
  21. func (this *MaycurController) SyncCompanyProfile() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. if br.ErrMsg == "" {
  25. br.IsSendEmail = false
  26. }
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. sysUser := this.SysUser
  31. if sysUser == nil {
  32. br.Msg = "请登录"
  33. br.ErrMsg = "请登录,SysUser Is Empty"
  34. br.Ret = 408
  35. return
  36. }
  37. // 每刻没提供debug环境,所以测试环境不同步
  38. if utils.RunMode != "release" {
  39. br.Msg = "测试环境暂不允许同步"
  40. return
  41. }
  42. // 加锁
  43. cacheKey := "maycur:company:sync"
  44. ok := utils.Rc.SetNX(cacheKey, 1, time.Second*600)
  45. if !ok {
  46. br.Msg = "请勿频繁同步, 请稍后再试"
  47. return
  48. }
  49. go func() {
  50. _ = maycur.SyncCompanyProfile()
  51. }()
  52. br.Ret = 200
  53. br.Success = true
  54. br.Msg = "操作成功"
  55. }
  56. // DailySyncCompanyProfile
  57. // @Title 每日同步-同步客户档案及权限
  58. // @Description 同步客户档案及权限
  59. // @Success 200 Ret=200 操作成功
  60. // @router /company_profile/daily_sync [post]
  61. func (this *MaycurOpenController) DailySyncCompanyProfile() {
  62. br := new(models.BaseResponse).Init()
  63. defer func() {
  64. if br.ErrMsg == "" {
  65. br.IsSendEmail = false
  66. }
  67. this.Data["json"] = br
  68. this.ServeJSON()
  69. }()
  70. // 每刻没提供debug环境,所以测试环境不同步
  71. if utils.RunMode != "release" {
  72. br.Msg = "测试环境暂不允许同步"
  73. return
  74. }
  75. // 简单校验一下
  76. ip := this.Ctx.Input.IP()
  77. if ip != "127.0.0.1" {
  78. br.Msg = "未经授权, 不可操作"
  79. br.ErrMsg = "未经授权, 不可操作, IP: " + ip
  80. return
  81. }
  82. // 加锁
  83. cacheKey := "maycur:company:sync"
  84. ok := utils.Rc.SetNX(cacheKey, 1, time.Second*600)
  85. if !ok {
  86. br.Msg = "请勿频繁同步, 请稍后再试"
  87. return
  88. }
  89. go func() {
  90. _ = maycur.SyncCompanyProfile()
  91. }()
  92. br.Ret = 200
  93. br.Success = true
  94. br.Msg = "操作成功"
  95. }