package com.huimv.eartag.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.common.utils.Result;
import com.huimv.common.utils.ResultCode;
import com.huimv.eartag.dao.entity.EartagDataEntity;
import com.huimv.eartag.entity.EartagData;
import com.huimv.eartag.entity.dto.EartagDataDto;
import com.huimv.eartag.mapper.EartagDataMapper;
import com.huimv.eartag.service.IEartagDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2022-06-01
 */
@Service
public class EartagDataServiceImpl extends ServiceImpl<EartagDataMapper, EartagData> implements IEartagDataService {
    @Autowired
    EartagDataMapper eartagDataMapper;

    @Override
    public Result getTemp(String earmark) {

        return new Result(ResultCode.SUCCESS,this.list(new QueryWrapper<EartagData>().ge("ask_time", DateUtil.beginOfDay(new Date()))));
    }

    @Override
    public Result getAct(String earmark) {
        Date date = new Date();
        QueryWrapper<EartagData> wrapper = new QueryWrapper<>();
        wrapper.eq("earmark",earmark);
        wrapper.between("ask_time",DateUtil.beginOfDay(DateUtil.offsetDay(date,-7)),date);
        wrapper.groupBy("`time`");
        List<EartagDataDto> list =   eartagDataMapper.getAct(wrapper);
        return new Result(ResultCode.SUCCESS,list);
    }
}
