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


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.v2.v1.entity.InspectionRecord;
import com.ruoyi.web.v2.v1.service.IInspectionRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

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

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2025-11-20
 */
@RestController
@RequestMapping("/inspection-record")
public class InspectionRecordController {

    @Autowired
    private IInspectionRecordService inspectionRecordService;

    @ApiOperation("检验项目管理添加")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody InspectionRecord checkProject) throws JsonProcessingException {
        return success(inspectionRecordService.save(checkProject));
    }

    @ApiOperation("检验项目管理修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody InspectionRecord checkProject) throws JsonProcessingException {
        return success(inspectionRecordService.updateById(checkProject));
    }

    @ApiOperation("检验项目管理删除")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        for (String s : ids.split(",")) {
            inspectionRecordService.removeById(s);
        }
        return success();
    }

    @ApiOperation("检验项目管理列表")
    @PostMapping("/list")
    public AjaxResult listAll(){
        return success(inspectionRecordService.list());
    }

    @ApiOperation("检验项目管理分页")
    @GetMapping("/page")
    public AjaxResult page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize
            , @RequestParam(value = "projectName", required = false) String projectName) {
        return success(inspectionRecordService.page(new Page<InspectionRecord>(pageNum,pageSize)));
    }

    @ApiOperation("检验项目管理详情")
    @PostMapping("/listById")
    public AjaxResult listById(@RequestBody Map<String, String> paramsMap){
        String id = paramsMap.get("id");
        return success(inspectionRecordService.getById(id));
    }
}
