package com.huimv.beeboxs.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.beeboxs.common.utils.Result;
import com.huimv.beeboxs.entity.HiveBaseBeehive;
import com.huimv.beeboxs.entity.HiveBaseStation;
import com.huimv.beeboxs.service.IHiveBaseBeehiveService;
import com.huimv.beeboxs.service.IHiveBaseStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2022-04-21
 */
@RestController
@CrossOrigin
@RequestMapping("/hiveBaseBeehive")
public class HiveBaseBeehiveController {
    @Autowired
    private IHiveBaseBeehiveService baseBeehiveService;
    @Autowired
    private IHiveBaseStationService baseStationService;

    @PostMapping("/list")
    public Result page(@RequestBody Map map){

        return baseBeehiveService.searchList(map);
    }


    @PostMapping("/update")
    public Result update(@RequestBody HiveBaseBeehive hiveBaseBeehive){
        hiveBaseBeehive.setBindingDate(new Date());


        HiveBaseStation hex = baseStationService.getOne(new QueryWrapper<HiveBaseStation>().eq("ap_uid_hex", hiveBaseBeehive.getApUidHex()));

        hiveBaseBeehive.setFarmId(hex.getFarmId());
        hiveBaseBeehive.setApName(hex.getApName());
        baseBeehiveService.updateById(hiveBaseBeehive);
        return new Result(10000,"绑定成功",true);
    }

    @PostMapping("/listAll")
    public Result listAll(@RequestBody Map map){

        return baseBeehiveService.listAll(map);
    }

    @PostMapping("/listCount")
    public Result listCount(@RequestBody Map map){

        return baseBeehiveService.listCount(map);
    }


}
