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.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.v2.v1.model.JsRestInspection;
import com.ruoyi.web.v2.v1.service.IJsRestInspectionService;
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.io.IOException;
import java.util.Map;

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

/**
 * <p>
 * v2.0静养巡查登记 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-05-22
 */
@RestController
@RequestMapping("/js-rest-inspection")
@Api("2.0静养巡查登记")
public class JsRestInspectionController {

    @Autowired
    private IJsRestInspectionService inspectionService;
/*
    @ApiOperation("静养巡查添加")
    @PostMapping("/add")
    public AjaxResult add(@RequestParam(value = "restInspectionTime") String restInspectionTime
            , @RequestParam(value = "pigpenName") String pigpenName, @RequestParam(value = "files") MultipartFile files
            , @RequestParam(value = "restInspectionContent") String restInspectionContent
            , @RequestParam(value = "handle") String handle
            , @RequestParam(value = "dealAmount") Integer dealAmount, @RequestParam(value = "userName") String userName
            , @RequestParam(value = "divideCircleId") Integer divideCircleId) throws IOException {
        return inspectionService.add(restInspectionTime, pigpenName, files, restInspectionContent, handle, dealAmount, userName, divideCircleId);
    }

    @ApiOperation("静养巡查修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestParam(value = "restInspectionTime") String restInspectionTime
            , @RequestParam(value = "files") MultipartFile files
            , @RequestParam(value = "restInspectionContent") String restInspectionContent
            , @RequestParam(value = "handle") String handle
            , @RequestParam(value = "dealAmount") Integer dealAmount, @RequestParam(value = "userName") String userName
            , @RequestParam(value = "id") Integer id) throws IOException {
        return inspectionService.edit(id, restInspectionTime, files, restInspectionContent, handle, dealAmount, userName);
    }*/

    @ApiOperation("静养巡查添加")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JsRestInspection restInspection) throws IOException {
        return inspectionService.add(restInspection);
    }

    @ApiOperation("静养巡查修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody JsRestInspection restInspection) throws IOException {
        return inspectionService.edit(restInspection);
    }

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

    @ApiOperation("静养巡查列表")
    @PostMapping("/list")
    public AjaxResult listAll() {
        return inspectionService.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 = "pigpenName", required = false) String pigpenName) {

        return inspectionService.page(pageNum, pageSize, startTime, endTime, pigpenName);
    }

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

    @ApiOperation("静养巡查详情通过传分圈id")
    @PostMapping("/listByDivideCircleId")
    public AjaxResult listByDivideCircleId(@RequestBody Map<String, String> paramsMap) {
        String pageNum = paramsMap.get("pageNum");
        String pageSize = paramsMap.get("pageSize");
        String id = paramsMap.get("id");
        String[] split = id.split(",");
        Page<JsRestInspection> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
        QueryWrapper<JsRestInspection> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id",split);
        return success(inspectionService.page(page, queryWrapper));
    }


    @ApiOperation("选择待宰圈号得到最新待宰圈的批次")
    @PostMapping("/listByPigpen")
    public AjaxResult listByPigpen(@RequestBody Map<String, String> paramsMap) {
        String id = paramsMap.get("id");
        return success(inspectionService.listByPigpen(Integer.parseInt(id)));
    }
}
