package com.huimv.beeboxs.controller;


import com.huimv.beeboxs.common.utils.Result;
import com.huimv.beeboxs.entity.HiveBaseStation;
import com.huimv.beeboxs.entity.vo.HiveBaseStationVo;
import com.huimv.beeboxs.service.IBaseHiveFarmService;
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
 */
@CrossOrigin
@RestController
@RequestMapping("/hiveBaseStation")
public class HiveBaseStationController {

    @Autowired
    private IHiveBaseStationService baseStationService;

    @Autowired
    private IBaseHiveFarmService baseHiveFarmService;

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

        return baseStationService.searchList(map);
    }

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

        return baseStationService.listCount(map);
    }


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

        return baseStationService.listAll(map);
    }

    @PostMapping("/update")
    public Result update(@RequestBody HiveBaseStationVo hiveBaseStationVo){


        HiveBaseStation hiveBaseStation = new HiveBaseStation();
        hiveBaseStation.setId(hiveBaseStationVo.getId());
        Integer farmIds = hiveBaseStationVo.getFarmIds();
        String farmName = baseHiveFarmService.getById(farmIds).getFarmName();
        hiveBaseStation.setFarmId(farmIds);
        hiveBaseStation.setFarmName(farmName);
        hiveBaseStation.setBindingDate(new Date());
        baseStationService.updateById(hiveBaseStation);
        return new Result(10000,"绑定成功",true);
    }






}
