staff_company_statistics.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package staff
  4. import (
  5. "context"
  6. "github.com/jaryhe/gopkgs/database"
  7. "github.com/jaryhe/gopkgs/logger"
  8. "go.uber.org/zap"
  9. "smart-site-management/errors"
  10. "smart-site-management/model"
  11. "smart-site-management/pb/v1"
  12. )
  13. func LaborCompanyStatistics(ctx context.Context, req *v1.LaborCompanyStatisticsRequest) (reply *v1.LaborCompanyStatisticsReply, err error) {
  14. reply = &v1.LaborCompanyStatisticsReply{}
  15. if req.ProjectId == 0 {
  16. return nil,errors.ParamsError
  17. }
  18. list, err := model.StaffCompanyStaticList(database.DB(), req.ProjectId)
  19. if err != nil {
  20. logger.Error("StaffCompanyStaticList",
  21. zap.String("err", err.Error()))
  22. return nil, errors.DataBaseError
  23. }
  24. reply.List = make([]*v1.LaborCompanyStatistics, len(list))
  25. for i, v := range list{
  26. item := &v1.LaborCompanyStatistics{
  27. LaborCompany:v.CompanyName,
  28. Total:int64(v.StaffCount),
  29. Attendance:int64(v.StaffAttendanceCount),
  30. LaborAttendance: int64(v.StaffAttendanceLabor),
  31. ManagerAttendance:int64(v.StaffAttendanceCount - v.StaffAttendanceLabor),
  32. }
  33. reply.List[i] = item
  34. }
  35. return reply, nil
  36. }