package com.huimv.admin.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.huimv.admin.common.utils.Result;
import com.huimv.admin.common.utils.ResultCode;
import com.huimv.admin.entity.EartagData2;
import com.huimv.admin.entity.SysAccountMultilevel;
import com.huimv.admin.mapper.EartagData2Mapper;
import com.huimv.admin.service.IEartagData2Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2023-09-19
 */
@Service
public class EartagData2ServiceImpl extends ServiceImpl<EartagData2Mapper, EartagData2> implements IEartagData2Service {

    @Override
    public Result getEnvByTime(Map<String, String> map) {
        String earmark = map.get("earmark");
        String startDate = map.get("startDate");
        String endDate = map.get("endDate");
//        String userId = map.get("userId");
        Date now = new Date();
//        SysAccountMultilevel user = sysAccountMultilevelMapper.selectById(userId);
        if (StringUtils.isBlank(earmark)) {
            return new Result(10001, "请选择耳标", false);
        }
        QueryWrapper<EartagData2> wrapper = new QueryWrapper<>();
        wrapper.eq("earmark", earmark);
        if (StringUtils.isBlank(startDate)) {
            wrapper.ge("add_time", DateUtil.beginOfDay(now));
        } else {
            wrapper.between("add_time", startDate, endDate);
        }
        wrapper.orderByAsc("add_time");
        List<EartagData2> list = this.list(wrapper);
        //用户数据
//        if (user.getIsUser() == 0) {
//            for (EartagData2 eartagData2 : list) {
//                Float earTemp1 = eartagData2.getEarTemp1();
//                if (earTemp1 > 40) {
//                    eartagData2.setEarTemp1(40F);
//                }
//                if (earTemp1 < 30) {
//                    eartagData2.setEarTemp1(30F);
//                }
//            }
//        }
        return new Result(ResultCode.SUCCESS, list);
    }
}
