敏捷工具
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

package com.whn.hellospring.service;
import com.whn.hellospring.model.OilDO;
import com.whn.hellospring.repository.OilRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
public class OilService {
@Autowired
private OilRepository oilRepository;
/**
* 油耗列表
*/
public List<Double> getWearList(Long customer_id){
return oilRepository.findWearList(customer_id);
}
/**
* 获取有效数量num之和
* @return
*/
public double getNumTotal(Long customer_id){
return oilRepository.countNum(customer_id);
}
/**
* 获取有效区间里程和
* @return
*/
public double getIntervalMileageTotal(Long customer_id){
return oilRepository.countIntervalMileage(customer_id);
}
/**
* 获取最新的一条有效记录
*/
public OilDO getRecentlyRecord(Long customer_id) {
List<OilDO> recordList = oilRepository.finAllSortByTime(customer_id);
if (recordList == null || recordList.size() == 0) return null;
int index = -1;
for (int i = 0; i < recordList.size(); i++) {
OilDO oilDO = recordList.get(i);
if (oilDO.getStatus() == 1) {
index = i;
break;
}
}
if(index==-1){
return null;
}else{
return recordList.get(index);
}
}
/**
* 获取有效记录列表
*/
public List<OilDO> getRecordList(Long customer_id) {
List<OilDO> recordList = oilRepository.finAllSortByTime(customer_id);
// Collections.reverse(recordList);
List<OilDO> list = new ArrayList<>();
for (int i = 0; i < recordList.size(); i++) {
if (recordList.get(i).getStatus() == 1) {
list.add(recordList.get(i));
}
}
log.info("list:{}", list);
return list;
}
/**
* 获取全部记录列表
* 包括被删除的status = 0
*/
public List<OilDO> getRecordAllList(Long customer_id) {
List<OilDO> recordList = oilRepository.finAllSortByTime(customer_id);
// Collections.reverse(recordList);
log.info("recordList:{}", recordList);
return recordList;
}
/**
* 新增更新
*/
public OilDO addUpdateRecord(OilDO oilDO) {
OilDO save = oilRepository.save(oilDO);
return save;
}
/**
* 删除
*
* @return
*/
public OilDO deleteRecord(Long id) {
OilDO oilDO = oilRepository.getOne(id);
oilDO.setStatus(0);
return oilRepository.save(oilDO);
}
}