StatisticsDriveService.java 1.84 KB
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.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) {
        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());
            statisticsDriveMapper.insertSelective(statisticsDrive);
        }
    }
}