Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func (t *FnsTransport) CheckAll(ctx *fasthttp.RequestCtx) {
- users, err := t.srvc.EmployeeRepo.GetAllSelfEmployeed()
- if err != nil {
- t.NewResponse(ctx, http.StatusInternalServerError, err)
- t.log.Err(err).Msg(err.Error())
- return
- }
- csvFinal, err := os.Create("/Users/ilchel/go/src/WB_NEW/fnsservice/ret.csv")
- defer csvFinal.Close()
- if err != nil {
- t.NewResponse(ctx, http.StatusInternalServerError, err)
- t.log.Err(err).Msg(err.Error())
- return
- }
- type Record struct {
- EmpId int64
- Status bool
- }
- wi := 0
- finalFile := [][]string{}
- i := 0
- active := 0
- for _, v := range users {
- inn := utils.AtoI(v.Inn, 0)
- if inn == 0 {
- t.log.Error().Msg("Wrong INN")
- wi += 1
- continue
- }
- status, err := t.srvc.Client.CheckUпser(ctx, inn)
- if err != nil {
- t.NewResponse(ctx, http.StatusInternalServerError, err)
- t.log.Err(err).Msg(fmt.Sprintf("Error checking %d: %s", v.EmployeeID, err.Error()))
- return
- }
- if !status.IsSelfEmployed {
- finalFile = append(finalFile, []string{strconv.Itoa(int(v.EmployeeID))})
- active += 1
- }
- if i%100 == 0 {
- fmt.Println(i)
- }
- i += 1
- }
- w := csv.NewWriter(csvFinal)
- err = w.WriteAll(finalFile) // calls Flush internally
- if err != nil {
- log.Fatal(err)
- }
- fmt.Println(finalFile)
- type Ret struct {
- Count int `json:"count"`
- Active int `json:"active"`
- WrongInn int `json:wrong_inn`
- }
- res := &Ret{Count: i, Active: active, WrongInn: wi}
- t.NewResponse(ctx, http.StatusOK, res)
- }
- func (r *Service) GetMany(context.Context) (data []Data, err error) {
- res := r.store.Find().Many(bson.M{"contracttypeid": 5}).ExtractAllTo(&data).Error
- return data, res
- }
Advertisement
Add Comment
Please, Sign In to add comment