package com.ruoyi.web.v2.v1.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.jsonUtil;
import com.ruoyi.web.v2.v1.model.JsEnvCheck;
import com.ruoyi.web.v2.v1.model.JsEnvCheck;
import com.ruoyi.web.v2.v1.service.IJsDrugService;
import com.ruoyi.web.v2.v1.service.IJsEnvCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * <p>
 * v2.0环境拭子检测 前端控制器
 * </p>
 *
 * @author coede
 * @since 2025-09-28
 */
@RestController
@RequestMapping("/js-envCheck")
@Api("2.0环境拭子检测")
public class JsEnvCheckController {

    @Autowired
    private IJsEnvCheckService envCheckService;

    @ApiOperation("环境拭子检测管理添加")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JsEnvCheck jsEnvCheck) throws JsonProcessingException {
       if(envCheckService.save(jsEnvCheck)){
           return success();
       }else {
           return error();
       }
    }

    @ApiOperation("环境拭子检测管理修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody JsEnvCheck jsEnvCheck) throws JsonProcessingException {
        if(envCheckService.updateById(jsEnvCheck)){
            return success();
        }else {
            return error();
        }
    }

    @ApiOperation("环境拭子检测管理删除")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        String[] split = ids.split(",");
        for (String s : split) {
            envCheckService.removeById(s);
        }
        return success();
    }

    @ApiOperation("环境拭子检测管理列表")
    @PostMapping("/list")
    public AjaxResult listAll(@RequestBody Map<String, String> param){
        return success(envCheckService.list());
    }

    @ApiOperation("环境拭子检测管理分页")
    @GetMapping("/page")
    public AjaxResult page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize
            , @RequestParam(value = "startTime", required = false) String startTime
            , @RequestParam(value = "endTime", required = false) String endTime
            , @RequestParam(value = "checkProject", required = false) String checkProject) {
        return envCheckService.page(pageNum, pageSize, startTime, endTime, checkProject);
    }

    @ApiOperation("环境拭子检测管理详情")
    @PostMapping("/listById")
    public AjaxResult listById(@RequestBody Map<String, String> paramsMap){
        String id = paramsMap.get("id");
        return success(envCheckService.getById(id));
    }
}
