package com.huimv.environ.eco.controller;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.common.utils.Result;
import com.huimv.common.utils.ResultCode;
import com.huimv.environ.eco.entity.BaseBox;
import com.huimv.environ.eco.entity.SysHumidity;
import com.huimv.environ.eco.entity.SysTelecom;
import com.huimv.environ.eco.entity.SysTemperature;
import com.huimv.environ.eco.service.IBaseBoxService;
import com.huimv.environ.eco.service.ISysHumidityService;
import com.huimv.environ.eco.service.ISysTemperatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2021-11-11
 */
@RestController
@RequestMapping("/box")
public class BaseBoxController {

    @Autowired
    private IBaseBoxService baseBoxService;

    @GetMapping("list")
    public Result list(@RequestParam(name = "farmId") Integer farmId){


        return new Result(ResultCode.SUCCESS,baseBoxService.list(new QueryWrapper<BaseBox>().eq("farm_id",farmId)));

    }

    @GetMapping("listByFloor")
    public Result listByFloor(@RequestParam(name = "floorId") Integer floorId){

        return new Result(ResultCode.SUCCESS, baseBoxService.list(new QueryWrapper<BaseBox>().eq("floor_id",floorId)));
    }
    @GetMapping("listByFloorDemo")
    public Result listByFloorDemo(@RequestParam(name = "floorId") Integer floorId){
        List<BaseBox> floor_id = baseBoxService.list(new QueryWrapper<BaseBox>().eq("floor_id", floorId));
        if (ObjectUtil.isNotEmpty(floor_id)){
            for (BaseBox baseBox : floor_id) {
                baseBox.setAlias(baseBox.getAlias().substring(4));
            }
        }
        return new Result(ResultCode.SUCCESS, floor_id);
    }



}
