package com.huimv.beeboxs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.huimv.beeboxs.common.utils.Result;
import com.huimv.beeboxs.common.utils.ResultCode;
import com.huimv.beeboxs.entity.HiveBeehive;
import com.huimv.beeboxs.entity.HiveWeight;
import com.huimv.beeboxs.mapper.HiveWeightMapper;
import com.huimv.beeboxs.service.IHiveWeightService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2022-04-28
 */
@Service
public class HiveWeightServiceImpl extends ServiceImpl<HiveWeightMapper, HiveWeight> implements IHiveWeightService {

    @Override
    public Result searchList(Map map) {
        String startDate = (String)map.get("startDate");
        String endDate = (String)map.get("endDate");
        String hiveId = (String)map.get("hiveId");

        QueryWrapper<HiveWeight> wrapper = new QueryWrapper<>();
        if (StringUtils.isBlank(hiveId)){
            return new Result(10001,"请选择蜂箱",false);
        }
        wrapper.eq("uid_hex",hiveId);
//        wrapper.orderByDesc("create_date");

        if (StringUtils.isNotBlank(startDate)){
            startDate = startDate+" 00:00:00";
            wrapper.ge("update_time",startDate);
        }

        if (StringUtils.isNotBlank(endDate)){
            endDate = endDate+" 23:59:59";
            wrapper.le("update_time",endDate);
        }

        wrapper.orderByAsc("update_time");

        return new Result(ResultCode.SUCCESS,this.list(wrapper));
    }
}
