package com.huimv.admin.controller;


import com.huimv.admin.common.utils.Result;
import com.huimv.admin.entity.EnergyEnvDevice;
import com.huimv.admin.entity.EnvDevice;
import com.huimv.admin.service.IEnergyEnvDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2023-02-21
 */
@CrossOrigin
@RestController
@RequestMapping("/admin/energyEnvDevice")
public class EnergyEnvDeviceController {
    @Autowired
    private IEnergyEnvDeviceService energyEnvDeviceService;

    @RequestMapping("/DeviceList")
    public Result getDeviceList(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
        return energyEnvDeviceService.list(httpServletRequest,paramsMap);
    }

    @RequestMapping("/DeviceAdd")
    public Result getDeviceAdd(HttpServletRequest httpServletRequest, @RequestBody EnergyEnvDevice energyEnvDevice) {
        return energyEnvDeviceService.add(httpServletRequest,energyEnvDevice);
    }

    @RequestMapping("/DeviceEdit")
    public Result getDeviceEdit(HttpServletRequest httpServletRequest, @RequestBody EnergyEnvDevice energyEnvDevice) {
        return energyEnvDeviceService.edit(httpServletRequest,energyEnvDevice);
    }

    @RequestMapping("/DeviceDelete")
    public Result getDeviceDelete(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
        return energyEnvDeviceService.delete(httpServletRequest,paramsMap);
    }
    @RequestMapping("/deviceCount")
    public Result  deviceCount(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
        return energyEnvDeviceService.deviceCount(httpServletRequest,paramsMap);
    }


    @RequestMapping("/bandingUnitId")
    public Result bandingUnitId(HttpServletRequest httpServletRequest, @RequestBody EnergyEnvDevice envDevice) {
        return energyEnvDeviceService.bandingUnitId(httpServletRequest,envDevice);
    }
    @RequestMapping("/unBandingUnitId")
    public Result unBandingUnitId(HttpServletRequest httpServletRequest, @RequestBody EnergyEnvDevice envDevice) {
        envDevice.setUnitId(0);
        envDevice.setUnitName("");
        energyEnvDeviceService.updateById(envDevice);
        return new Result(10000,"解绑成功",true);
    }

    @RequestMapping("/listDevice")
    public Result listDevice(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
        return energyEnvDeviceService.listDevice(httpServletRequest,paramsMap);
    }
    @PostMapping("/updateName")
    public Result updateName(HttpServletRequest httpServletRequest, @RequestParam(name = "file") MultipartFile file) throws Exception {
        return energyEnvDeviceService.updateName(httpServletRequest, file);
    }
}
