package com.huimv.produce.warning.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huimv.common.utils.Result;
import com.huimv.common.utils.ResultCode;
import com.huimv.produce.warning.entity.SysThreshold;
import com.huimv.produce.warning.mapper.SysThresholdMapper;
import com.huimv.produce.warning.service.ISysThresholdService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author astupidcoder
 * @since 2021-11-30
 */
@Service
public class SysThresholdServiceImpl extends ServiceImpl<SysThresholdMapper, SysThreshold> implements ISysThresholdService {

    @Override
    public Result listWarningInfoWeater(Map<String, String> map) {
        String farmId = map.get("farmId");
        String maxTem = map.get("maxTem");
        String minTem = map.get("minTem");
        SysThreshold threshold = this.getById(farmId);
        if(ObjectUtil.isEmpty(threshold)){
             return new Result(10001,"该牧场未设置天气阈值",false);
        }
        String weatherMaxTem = threshold.getWeatherMaxTem();
        String weatherMixTem = threshold.getWeatherMinTem();
        Map endMap =new HashMap();
        if (Double.parseDouble(maxTem) > Double.parseDouble(weatherMaxTem)){
            endMap.put("maxTem",true);
            endMap.put("maxTemStr","今日最高温度为"+maxTem+"℃,高于阈值"+weatherMaxTem+"℃");
        }else {
            endMap.put("maxTem",false);
            endMap.put("maxTemStr",null);
        }
        if (Double.parseDouble(minTem) < Double.parseDouble(weatherMixTem)){
            endMap.put("minTem",true);
            endMap.put("minTemStr","今日最低温度为"+minTem+"℃,低于阈值"+weatherMixTem+"℃");
        }else {
            endMap.put("minTem",false);
            endMap.put("minTemStr",null);
        }


        return new Result(ResultCode.SUCCESS,endMap);
    }
}
