StatisticsDriveService.java
2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.stdinterface.dto.StatisticsDriveDto;
import cn.com.glsx.stdinterface.modules.mapper.StatisticsDriveMapper;
import cn.com.glsx.stdinterface.modules.model.StatisticsDrive;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* 项目名:ne-shield-standard-interfaces
* 包名: cn.com.glsx.stdinterface.modules.service
* 作者: Yanglinlong
* 日期: 2021/8/25 14:27
*/
@Slf4j
@Service
public class StatisticsDriveService {
@Autowired
private StatisticsDriveMapper statisticsDriveMapper;
public List<StatisticsDriveDto> statisticsDriveDataEveryDay() {
// 获取昨天的日期
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
String yesterDayFormat = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
log.info("数据统计的天数===" + yesterDayFormat);
return statisticsDriveMapper.statisticsDriveDataEveryDay(yesterDayFormat);
}
public void insertStatisticsDriveList(List<StatisticsDriveDto> statisticsDriveDtoList) {
List<StatisticsDrive> statisticsDriveList = new ArrayList<>();
for (StatisticsDriveDto statisticsDriveDto : statisticsDriveDtoList) {
StatisticsDrive statisticsDrive = new StatisticsDrive();
statisticsDrive.setSn(statisticsDriveDto.getSn());
statisticsDrive.setDriveNum(statisticsDriveDto.getDriveNum());
statisticsDrive.setDriveTotal(statisticsDriveDto.getDriveTotal());
statisticsDrive.setDriveTime(statisticsDriveDto.getDriveTime());
statisticsDrive.setCreatedTime(new Date());
statisticsDriveList.add(statisticsDrive);
}
statisticsDriveMapper.insertList(statisticsDriveList);
}
/**
* 统计每天的数据并插入
*
* @return 成功插入的行数
*/
public Integer statisticsAndInsertDriveDataEveryDay() {
// 获取昨天的日期
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
String yesterDayFormat = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
log.info("[试驾统计]数据统计的天数===" + yesterDayFormat);
Integer num = statisticsDriveMapper.statisticsAndInsertDriveDataEveryDay(yesterDayFormat);
log.info("[试驾统计]插入到统计表的数据行数===" + num);
return num;
}
}