package com.unis.statisticalReport.info.modular.grainTempCheck.service;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unis.statisticalReport.info.modular.grainTempCheck.entity.GrainTemp;
import com.unis.statisticalReport.info.modular.grainTempCheck.entity.GrainTempExcel;
import com.unis.statisticalReport.info.modular.grainTempCheck.mapper.GrainTempMapper;
import com.unis.statisticalReport.info.modular.grainTempCheck.param.GrainTempPageParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author qingsong.han
 * @description:
 * @create 2024-06-04 15:29
 */
public interface GrainTempService extends IService<GrainTemp> {

    Page<GrainTemp> getPage(GrainTempPageParam param);

    List<GrainTempExcel> exportExcel();

    @Slf4j
    @Service
    class GrainTempServiceImpl extends ServiceImpl<GrainTempMapper, GrainTemp> implements GrainTempService {
        @Resource
        private GrainTempMapper grainTempMapper;

        @Override
        public Page<GrainTemp> getPage(GrainTempPageParam param) {
            return grainTempMapper.getPage(new Page<>(param.getCurrent(), param.getSize()), param.getStorehouseName());
        }

        @Override
        public List<GrainTempExcel> exportExcel() {
            // 查询进30天的数据
            Calendar now1 = Calendar.getInstance();
            String endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now1.getTime());
            now1.add(Calendar.DAY_OF_MONTH, -30);
            String startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now1.getTime());
            return grainTempMapper.exportExcel(startDate, endDate);
        }
    }

}
