/*
Copyright [2020] [https://www.xiaonuo.vip]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：

1.请不要删除和修改根目录下的LICENSE文件。
2.请不要删除和修改Snowy源码头部的版权声明。
3.请保留源码和相关描述文件的项目出处，作者声明等。
4.分发源码时候，请注明软件出处 https://gitee.com/xiaonuobase/snowy
5.在修改包名，模块名称，项目代码等时，请注明软件出处 https://gitee.com/xiaonuobase/snowy
6.若您的项目无法满足以上几点，可申请商业授权，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package com.huimv.modular.eartagdata.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huimv.core.pojo.page.PageResult;
import com.huimv.modular.collectorregister.EartagDataCountVo;
import com.huimv.modular.eartagdata.entity.EartagData;
import com.huimv.modular.eartagdata.entity.EartagParamVo;
import com.huimv.modular.eartagdata.entity.vo.EartagDataVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 耳标数据详情
 *
 * @author Yangdi
 * @date 2021-08-19 13:18:22
 */
@Repository
public interface EartagDataMapper extends BaseMapper<EartagData> {
    List<EartagDataCountVo> countByTime(@Param(Constants.WRAPPER) QueryWrapper<EartagData> wrapper);

    List<EartagDataCountVo> countByDay(@Param(Constants.WRAPPER) QueryWrapper<EartagData> wrapper);

    Page<EartagData> findByCondition(@Param("page")IPage<EartagData> page, @Param(Constants.WRAPPER) LambdaQueryWrapper<EartagData> wrapper);


    //传参page    还有查询参数
    Page<EartagDataVo> pageIndex(@Param("page") IPage<EartagDataVo> page, @Param("eartagParamVo") EartagParamVo eartagParamVo);


    @Select("SELECT    p.id , p.eartag_no ,  p.device_code ,    p.ear_temp  , p.exercise  ,p.bat   ,p.time    , IF (   p.device_code  =  (SELECT  g.device_code    FROM  (  SELECT  a.device_code  ,  COUNT(*)  AS  counts   FROM  (  SELECT device_code  , eartag_no  FROM  eartag_data  WHERE eartag_no =#{eartag_no}  ORDER BY id    DESC LIMIT  1000   ) a         GROUP  BY   a.eartag_no    ,  a.device_code    ORDER  BY  counts   DESC   LIMIT 1   ) g      )      ,  p.env_temp  ,NULL )  AS   env_temp  FROM   eartag_data     p       WHERE  p.eartag_no =#{eartag_no}     ORDER BY   p.id   DESC       \n    ")
    List<EartagData> eartagDetails(@Param("eartag_no") String eartag_no);




     //删除所有耳标号为传入耳标号的耳标
     @Delete(" DELETE   FROM    `eartag_data` WHERE    eartag_no =#{eartag_no}    ")
     void    deleteOneEartagDataAll(@Param("eartag_no") String eartag_no);



    /**
     * 和Mybatis使用方法一致  这样也可以的
     * @param
     * @return
     */
    @Select("SELECT * FROM eartag_data where eartag_no = #{eartag_no}")
    List<EartagData> selectByName(@Param("eartag_no") String eartag_no);

    /**
     * 和Mybatis使用方法一致  这样也可以的
     * @param
     * @return
     */







}