AlarmcountsService.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.gyee.healthmodel.service;
  2. import com.gyee.healthmodel.model.auto.Alarmcount;
  3. import com.gyee.healthmodel.service.auto.IAlarmcountService;
  4. import com.gyee.healthmodel.util.DateUtils;
  5. import org.springframework.stereotype.Service;
  6. import javax.annotation.Resource;
  7. import java.util.Date;
  8. import java.util.List;
  9. /**
  10. * @ClassName : AlarmcountsService
  11. * @Description : 自定义报警统计service
  12. */
  13. @Service
  14. public class AlarmcountsService {
  15. private final int DIGIT=2;
  16. @Resource
  17. private IAlarmcountService alarmcountService;
  18. public String findAlarmcount(Long snapid, Date beginDate,Date endDate) {
  19. List<Alarmcount> alarmlist = alarmcountService.findAlarmcount(snapid, DateUtils.truncate(beginDate),DateUtils.truncate(endDate));
  20. if (!alarmlist.isEmpty()) {
  21. for (int i = 0; i < alarmlist.size() - 1; i++) {
  22. for (int j = alarmlist.size() - 1; j > i; j--) {
  23. if (alarmlist.get(i).getAlarmdate()
  24. .equals(alarmlist.get(j).getAlarmdate())
  25. && alarmlist.get(i).getSnapid()
  26. .equals(alarmlist.get(j).getSnapid())) {
  27. alarmlist.remove(j);
  28. }
  29. }
  30. }
  31. double sumCount = 0;
  32. double count = 0;
  33. for (Alarmcount ac : alarmlist) {
  34. sumCount += ac.getCount();
  35. count++;
  36. }
  37. return sumCount + "," + count;
  38. }
  39. return "0.0,0.0";
  40. }
  41. public Double findyearstodayAlarmcount(Long snapid, Date beginDate,Date endDate) {
  42. List<Alarmcount> alarmlist = alarmcountService.findAlarmcount(snapid, DateUtils.truncate(beginDate),DateUtils.truncate(endDate));
  43. if (!alarmlist.isEmpty()) {
  44. for (int i = 0; i < alarmlist.size() - 1; i++) {
  45. for (int j = alarmlist.size() - 1; j > i; j--) {
  46. if (alarmlist.get(i).getAlarmdate()
  47. .equals(alarmlist.get(j).getAlarmdate())
  48. && alarmlist.get(i).getSnapid()
  49. .equals(alarmlist.get(j).getSnapid())) {
  50. alarmlist.remove(j);
  51. }
  52. }
  53. }
  54. double sumCount = 0;
  55. for (Alarmcount ac : alarmlist) {
  56. sumCount += ac.getCount();
  57. }
  58. return sumCount;
  59. }
  60. return 0.0;
  61. }
  62. }