package com.ruoyi.web.v2.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.v2.model.JsPatrol;
import com.ruoyi.web.v2.service.IJsPatrolService;
import io.swagger.annotations.Api;
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>
 * v2.0质量巡查 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-05-26
 */
@RestController
@RequestMapping("/js-patrol")
@Api("2.0质量巡查")
public class JsPatrolController {

    @Autowired
    private IJsPatrolService jsPatrolService;

    @ApiOperation("质量巡查添加")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JsPatrol jsPatrol) {
        return jsPatrolService.add(jsPatrol);
    }

    @ApiOperation("质量巡查修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody JsPatrol jsPatrol) {
        return jsPatrolService.edit(jsPatrol);
    }

    @ApiOperation("质量巡查删除")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        return jsPatrolService.delete(ids);
    }

    @ApiOperation("质量巡查列表")
    @PostMapping("/list")
    public AjaxResult listAll() {
        return jsPatrolService.listAll();
    }

    @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 = "patrolLocation", required = false) String patrolLocation) {
        return jsPatrolService.page(pageNum, pageSize, startTime, endTime,patrolLocation);
    }

    @ApiOperation("质量巡查详情")
    @PostMapping("/listById")
    public AjaxResult listById(@RequestBody Map<String, String> paramsMap) {
        String id = paramsMap.get("id");
        return success(jsPatrolService.getById(id));
    }
}
