package com.huimv.receive.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.receive.common.utils.PdfUtil;
import com.huimv.receive.common.utils.Result;
import com.huimv.receive.common.utils.ResultCode;
import com.huimv.receive.entity.BaseDevice;
import com.huimv.receive.entity.BaseLocation;
import com.huimv.receive.service.IBaseDeviceService;
import com.huimv.receive.service.IBaseLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2023-09-04
 */
@RestController
@RequestMapping("/base-device")
@CrossOrigin
public class BaseDeviceController {
    @Autowired
    private IBaseDeviceService baseDeviceService;


    @PostMapping("/addDevice")
    public Result addDevice(@RequestBody BaseDevice baseDevice){
        return  baseDeviceService.addDevice(baseDevice);
    }

    @PostMapping("/updateDevice")
    public Result updateDevice(@RequestBody BaseDevice baseDevice){
        return  baseDeviceService.updateDevice(baseDevice);
    }


    @Autowired
    private IBaseDeviceService deviceService;
    @GetMapping("/printDevice")
    public void printDevice(HttpServletResponse response, @RequestParam(name = "ids") String ids) throws Exception {
        Map<String, String> map = new HashMap<>();
        map.put("ids", ids);
        deviceService.printDevice(response, map);
        String path = "/opt/huatong/device.xls";
        PdfUtil.returnPdfStream3(response, path, "设备列表");
    }

    @PostMapping("/listSelect")
    public Result listSelect(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
        return deviceService.listSelect(httpServletRequest, paramsMap);
    }

    @PostMapping("/listCount")
    public Result listCount(HttpServletRequest httpServletRequest, @RequestBody Map<String, String> paramsMap) {
        return deviceService.listCount(httpServletRequest, paramsMap);
    }

    @PostMapping("/delete")
    public Result delete(HttpServletRequest httpServletRequest,@RequestBody Map<String, String> paramsMap){
        String ids = paramsMap.get("ids");
        String[] split = ids.split(",");
        for (String s : split) {
            deviceService.removeById(s);
        }
        return new Result(10000,"删除成功！",true);
    }

}
