Cheeel666

CheckUsersFns

Apr 26th, 2022
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. func (t *FnsTransport) CheckAll(ctx *fasthttp.RequestCtx) {
  2. users, err := t.srvc.EmployeeRepo.GetAllSelfEmployeed()
  3. if err != nil {
  4. t.NewResponse(ctx, http.StatusInternalServerError, err)
  5. t.log.Err(err).Msg(err.Error())
  6. return
  7. }
  8.  
  9. csvFinal, err := os.Create("/Users/ilchel/go/src/WB_NEW/fnsservice/ret.csv")
  10. defer csvFinal.Close()
  11. if err != nil {
  12. t.NewResponse(ctx, http.StatusInternalServerError, err)
  13. t.log.Err(err).Msg(err.Error())
  14. return
  15. }
  16.  
  17. type Record struct {
  18. EmpId int64
  19. Status bool
  20. }
  21.  
  22. wi := 0
  23. finalFile := [][]string{}
  24. i := 0
  25. active := 0
  26. for _, v := range users {
  27. inn := utils.AtoI(v.Inn, 0)
  28. if inn == 0 {
  29. t.log.Error().Msg("Wrong INN")
  30. wi += 1
  31. continue
  32. }
  33. status, err := t.srvc.Client.CheckUпser(ctx, inn)
  34. if err != nil {
  35. t.NewResponse(ctx, http.StatusInternalServerError, err)
  36. t.log.Err(err).Msg(fmt.Sprintf("Error checking %d: %s", v.EmployeeID, err.Error()))
  37. return
  38. }
  39. if !status.IsSelfEmployed {
  40. finalFile = append(finalFile, []string{strconv.Itoa(int(v.EmployeeID))})
  41. active += 1
  42. }
  43. if i%100 == 0 {
  44. fmt.Println(i)
  45. }
  46. i += 1
  47. }
  48.  
  49. w := csv.NewWriter(csvFinal)
  50. err = w.WriteAll(finalFile) // calls Flush internally
  51.  
  52. if err != nil {
  53. log.Fatal(err)
  54. }
  55. fmt.Println(finalFile)
  56. type Ret struct {
  57. Count int `json:"count"`
  58. Active int `json:"active"`
  59. WrongInn int `json:wrong_inn`
  60. }
  61. res := &Ret{Count: i, Active: active, WrongInn: wi}
  62.  
  63. t.NewResponse(ctx, http.StatusOK, res)
  64. }
  65.  
  66.  
  67. func (r *Service) GetMany(context.Context) (data []Data, err error) {
  68. res := r.store.Find().Many(bson.M{"contracttypeid": 5}).ExtractAllTo(&data).Error
  69. return data, res
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment