/reports/ru/apertum/qsystem/reports/generators/RepCurrentUsers.java

https://code.google.com/p/apertum-qsystem/ · Java · 86 lines · 57 code · 9 blank · 20 comment · 5 complexity · df9f2c1e8326d4d9db3550d174aed1a4 MD5 · raw file

  1. /*
  2. * Copyright (C) 2010 {Apertum}Projects. web: www.apertum.ru email: info@apertum.ru
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package ru.apertum.qsystem.reports.generators;
  18. import java.sql.Connection;
  19. import java.util.HashMap;
  20. import java.util.LinkedList;
  21. import net.sf.jasperreports.engine.JRDataSource;
  22. import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
  23. import org.apache.http.HttpRequest;
  24. import ru.apertum.qsystem.reports.common.Response;
  25. import ru.apertum.qsystem.reports.model.AGenerator;
  26. import ru.apertum.qsystem.reports.model.CurRepRecord;
  27. import ru.apertum.qsystem.server.model.QPlanService;
  28. import ru.apertum.qsystem.server.model.QUser;
  29. import ru.apertum.qsystem.server.model.QUserList;
  30. /**
  31. *
  32. * @author Evgeniy Egorov
  33. */
  34. public class RepCurrentUsers extends AGenerator {
  35. public RepCurrentUsers(String href, String resourceNameTemplate) {
  36. super(href, resourceNameTemplate);
  37. }
  38. @Override
  39. protected JRDataSource getDataSource(HttpRequest request) {
  40. final LinkedList<CurRepRecord> dataSource = new LinkedList<CurRepRecord>();
  41. for (QUser user : QUserList.getInstance().getItems()) {
  42. int user_worked = 0;
  43. int user_killed = 0;
  44. long user_avg_time_work = 0;
  45. for (QPlanService plan : user.getPlanServices()) {
  46. user_worked += plan.getWorked();
  47. user_killed += plan.getKilled();
  48. user_avg_time_work += (plan.getAvg_work() * plan.getWorked());
  49. }
  50. user_avg_time_work = user.getPlanServices().isEmpty() || user_worked == 0 ? 0 : user_avg_time_work / user_worked;
  51. for (QPlanService plan : user.getPlanServices()) {
  52. dataSource.add(new CurRepRecord(user.getName(), plan.getService().getName(), user_worked, user_killed, user_avg_time_work, plan.getWorked(), plan.getKilled(), plan.getAvg_work()));
  53. }
  54. }
  55. return new JRBeanCollectionDataSource(dataSource);
  56. }
  57. @Override
  58. protected HashMap getParameters(HttpRequest request) {
  59. return new HashMap();
  60. }
  61. @Override
  62. protected Connection getConnection(HttpRequest request) {
  63. return null;
  64. }
  65. @Override
  66. protected Response preparationReport(HttpRequest request) {
  67. return null;
  68. }
  69. @Override
  70. protected Response getDialog(HttpRequest request, String errorMessage) {
  71. return null;
  72. }
  73. @Override
  74. protected String validate(HttpRequest request, HashMap<String, String> params) {
  75. return null;
  76. }
  77. }