敏捷工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
2.8 KiB

2 years ago
  1. package com.whn.hellospring.service;
  2. import com.whn.hellospring.model.OilDO;
  3. import com.whn.hellospring.repository.OilRepository;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. @Slf4j
  10. @Service
  11. public class OilService {
  12. @Autowired
  13. private OilRepository oilRepository;
  14. /**
  15. * 油耗列表
  16. */
  17. public List<Double> getWearList(Long customer_id){
  18. return oilRepository.findWearList(customer_id);
  19. }
  20. /**
  21. * 获取有效数量num之和
  22. * @return
  23. */
  24. public double getNumTotal(Long customer_id){
  25. return oilRepository.countNum(customer_id);
  26. }
  27. /**
  28. * 获取有效区间里程和
  29. * @return
  30. */
  31. public double getIntervalMileageTotal(Long customer_id){
  32. return oilRepository.countIntervalMileage(customer_id);
  33. }
  34. /**
  35. * 获取最新的一条有效记录
  36. */
  37. public OilDO getRecentlyRecord(Long customer_id) {
  38. List<OilDO> recordList = oilRepository.finAllSortByTime(customer_id);
  39. if (recordList == null || recordList.size() == 0) return null;
  40. int index = -1;
  41. for (int i = 0; i < recordList.size(); i++) {
  42. OilDO oilDO = recordList.get(i);
  43. if (oilDO.getStatus() == 1) {
  44. index = i;
  45. break;
  46. }
  47. }
  48. if(index==-1){
  49. return null;
  50. }else{
  51. return recordList.get(index);
  52. }
  53. }
  54. /**
  55. * 获取有效记录列表
  56. */
  57. public List<OilDO> getRecordList(Long customer_id) {
  58. List<OilDO> recordList = oilRepository.finAllSortByTime(customer_id);
  59. // Collections.reverse(recordList);
  60. List<OilDO> list = new ArrayList<>();
  61. for (int i = 0; i < recordList.size(); i++) {
  62. if (recordList.get(i).getStatus() == 1) {
  63. list.add(recordList.get(i));
  64. }
  65. }
  66. log.info("list:{}", list);
  67. return list;
  68. }
  69. /**
  70. * 获取全部记录列表
  71. * 包括被删除的status = 0
  72. */
  73. public List<OilDO> getRecordAllList(Long customer_id) {
  74. List<OilDO> recordList = oilRepository.finAllSortByTime(customer_id);
  75. // Collections.reverse(recordList);
  76. log.info("recordList:{}", recordList);
  77. return recordList;
  78. }
  79. /**
  80. * 新增更新
  81. */
  82. public OilDO addUpdateRecord(OilDO oilDO) {
  83. OilDO save = oilRepository.save(oilDO);
  84. return save;
  85. }
  86. /**
  87. * 删除
  88. *
  89. * @return
  90. */
  91. public OilDO deleteRecord(Long id) {
  92. OilDO oilDO = oilRepository.getOne(id);
  93. oilDO.setStatus(0);
  94. return oilRepository.save(oilDO);
  95. }
  96. }