package com.huimv.admin.controller;


import com.huimv.admin.common.utils.Result;
import com.huimv.admin.entity.WriteEnvData;
import com.huimv.admin.entity.vo.WriteEnvDataAddVo;
import com.huimv.admin.service.IWriteEnvDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

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

/**
 * <p>
 * 环境监测温湿度填报 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-11-17
 */
@RestController
@RequestMapping("/write-env-data")
@CrossOrigin
public class WriteEnvDataController {
    @Autowired
    private IWriteEnvDataService writeEnvDataService;

    @RequestMapping("/envList")
    public Result addWriteData(HttpServletRequest httpServletRequest, @RequestBody WriteEnvDataAddVo writeEnvDataAddVo) {
        return writeEnvDataService.add(httpServletRequest,writeEnvDataAddVo);
    }

    @RequestMapping("/addWriteData")
    public Result envList(HttpServletRequest httpServletRequest, @RequestBody  WriteEnvData writeEnvData) {
        writeEnvDataService.save(writeEnvData);
        return new Result(10000, "添加成功!", true);
    }
    @RequestMapping("/editData")
    public Result editData(@RequestBody WriteEnvData writeEnvData) {
        writeEnvDataService.updateById(writeEnvData);
        return new Result(10000, "修改成功！", true);
    }
    @RequestMapping("/listData")
    public Result listData(HttpServletRequest httpServletRequest,@RequestBody  Map<String, String> paramsMap) {
        return writeEnvDataService.listData(httpServletRequest, paramsMap);
    }
    @RequestMapping("/removeWriteData")
    public Result removeWriteData(@RequestBody  Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        String[] split = ids.split(",");
        for (String s : split) {
            writeEnvDataService.removeById(s);
        }
        return new Result(10000, "删除成功！", true);
    }
}
