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.BaseFloor;
import com.huimv.environ.eco.service.IBaseFloorService;
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("/floor")
public class  BaseFloorController {

    @Autowired
    private IBaseFloorService baseFloorService;

    @GetMapping("list")
    public Result list(@RequestParam(name = "farmId") Integer farmId) {
        return new Result(ResultCode.SUCCESS, baseFloorService.list(new QueryWrapper<BaseFloor>().eq("farm_id", farmId)));
    }

    @GetMapping("listDemo")
    public Result listDemo(@RequestParam(name = "farmId") Integer farmId) {
        List<BaseFloor> baseFloors = baseFloorService.list(new QueryWrapper<BaseFloor>().eq("farm_id", farmId));
        if (ObjectUtil.isNotEmpty(baseFloors)) {
            for (BaseFloor baseFloor : baseFloors) {
                baseFloor.setFloorName(baseFloor.getFloorName().substring(2));

            }
        }

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

}
