package com.huimv.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.admin.common.utils.NumberUtils;
import com.huimv.admin.common.utils.Result;
import com.huimv.admin.common.utils.ResultCode;
import com.huimv.admin.entity.EartagData;
import com.huimv.admin.service.IEartagDataService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 健康监测的耳标信息 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-01-22
 */
@RestController
@RequestMapping("/eartag-data")
@CrossOrigin
public class EartagDataController {
    @Autowired
    private IEartagDataService dataService;

    @PostMapping("/add")
    public void add(@RequestBody Map<String, String> paramsMap) {
        Double min = 37.5;
        Double max = 39.0;
        String farmId = paramsMap.get("farmId");
        for (int i = 0; i < 100; i++) {
            EartagData eartagData = new EartagData();
            eartagData.setFarmId(Integer.parseInt(farmId));
            eartagData.setTemp(NumberUtils.getNumFloat(min, max));
            eartagData.setDayNum("273");
            eartagData.setAct(NumberUtils.getNum(0, 500, 0));
            eartagData.setBat(NumberUtils.getNum(90, 93, 0));
            eartagData.setEartag(String.valueOf(15484250 + i));
            dataService.save(eartagData);
        }
    }

    @PostMapping("/list")
    public Result list(@RequestBody Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        return new Result(ResultCode.SUCCESS,dataService.list(new QueryWrapper<EartagData>().eq("farm_id", farmId)));
    }
}
