company_permission.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. package services
  2. import (
  3. "fmt"
  4. "hongze/hongze_task/models"
  5. "strconv"
  6. "strings"
  7. "time"
  8. )
  9. //客户权限设置
  10. func SetCompanyPermission() {
  11. var err error
  12. defer func() {
  13. if err != nil {
  14. fmt.Println("SetCompanyPermission Err:", err.Error())
  15. }
  16. }()
  17. companyList, err := models.GetCompany()
  18. fmt.Println("len:", len(companyList))
  19. time.Sleep(10 * time.Second)
  20. if err != nil {
  21. return
  22. }
  23. for k, v := range companyList {
  24. fmt.Println("line 24:", k, v.CompanyName)
  25. permissionList, err := models.GetCompanyReportPermission(v.CompanyId)
  26. if err != nil {
  27. return
  28. }
  29. if len(permissionList) == 14 {
  30. fmt.Println(k, v.CompanyName, "大套餐客户")
  31. } else {
  32. fmt.Println(k, v.CompanyName, "小套餐客户")
  33. flag := 0
  34. for m, n := range permissionList {
  35. fmt.Println(m, n.ChartPermissionId)
  36. if n.ChartPermissionId == 17 {
  37. flag = 1
  38. }
  39. if n.ChartPermissionId == 8 {
  40. flag = 2
  41. }
  42. }
  43. if flag == 0 || flag == 1 {
  44. //新增炉料权限
  45. item := new(models.CompanyReportPermission)
  46. item.CompanyId = v.CompanyId
  47. item.ChartPermissionId = 8
  48. item.CreatedTime = time.Now()
  49. item.LastUpdatedTime = time.Now()
  50. item.ReportPermissionId = 8
  51. err = models.AddCompanyReportPermission(item)
  52. if err != nil {
  53. fmt.Println("AddCompanyReportPermission Err:", err.Error())
  54. //return
  55. }
  56. }
  57. }
  58. }
  59. }
  60. func addCompany12() {
  61. str := `25,
  62. 28,
  63. 51,
  64. 61,
  65. 65,
  66. 74,
  67. 79,
  68. 91,
  69. 96,
  70. 135,
  71. 153,
  72. 158,
  73. 170,
  74. 173,
  75. 175,
  76. 199,
  77. 235,
  78. 241,
  79. 248,
  80. 275,
  81. 280,
  82. 339,
  83. 367,
  84. 368,
  85. 395,
  86. 400,
  87. 424,
  88. 473,
  89. 488,
  90. 493,
  91. 561,
  92. 562,
  93. 565,
  94. 568,
  95. 569,
  96. 588,
  97. 617,
  98. 650,
  99. 728,
  100. 738,
  101. 740,
  102. 742,
  103. 753,
  104. 763,
  105. 780,
  106. 796,
  107. 829,
  108. 840,
  109. 862,
  110. 896,
  111. 940,
  112. 951,
  113. 964,
  114. 980,
  115. 993,
  116. 1049,
  117. 1064,
  118. 1075,
  119. 1101,
  120. 1103,
  121. 1113,
  122. 1116,
  123. 1118,
  124. 1156,
  125. 1201,
  126. 1256,
  127. 1298,
  128. 1428,
  129. 1443,
  130. 1505,
  131. 1620,
  132. 1720,
  133. 1730,
  134. 1780,
  135. 1782,
  136. 1861,
  137. 1906,
  138. 1917,
  139. 2005,
  140. 2011,
  141. 2172,
  142. 2232,
  143. 2302,
  144. 2399,
  145. 2428,
  146. 2488,
  147. 2507,
  148. 2539,
  149. 2577,
  150. 2581,
  151. 2594,
  152. 2660,
  153. 2825,
  154. 2890,
  155. 2950,
  156. 3014,
  157. 3088,
  158. 3201,
  159. 3235,
  160. 3417,
  161. 3445,
  162. 3451,
  163. 3510,
  164. 3543,
  165. 3592,
  166. 3687,
  167. 3763,
  168. 3798,
  169. 3890,
  170. 3962,
  171. 3987,
  172. 4002,
  173. 4085,
  174. 4399,
  175. 4413,
  176. 4489`
  177. strArr := strings.Split(str, ",")
  178. for k, v := range strArr {
  179. fmt.Println(k)
  180. //新增炉料权限
  181. v=strings.Replace(v,"\n","",-1)
  182. companyId,err:=strconv.Atoi(v)
  183. if err!=nil {
  184. fmt.Println("strconv",err.Error())
  185. }
  186. item := new(models.CompanyReportPermission)
  187. item.CompanyId = companyId
  188. item.ChartPermissionId = 12
  189. item.CreatedTime = time.Now()
  190. item.LastUpdatedTime = time.Now()
  191. item.ReportPermissionId = 12
  192. err = models.AddCompanyReportPermission(item)
  193. if err != nil {
  194. fmt.Println("AddCompanyReportPermission Err:", err.Error(), "CompanyId:", v)
  195. //return
  196. }
  197. }
  198. }