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


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.v2.v1.model.JsSample;
import com.ruoyi.web.v2.v1.service.IJsSampleService;
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-23
 */
@RestController
@RequestMapping("/js-sample")
@Api("2.0样品留存登记")
public class JsSampleController {

    @Autowired
    private IJsSampleService sampleService;

    @ApiOperation("样品留存登记添加")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JsSample sample){
        return sampleService.add(sample);
    }

    @ApiOperation("样品留存登记修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody JsSample sample){
        return sampleService.edit(sample);
    }

    @ApiOperation("样品留存登记删除")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        return sampleService.delete(ids);
    }

    @ApiOperation("样品留存登记列表")
    @PostMapping("/list")
    public AjaxResult listAll(){
        return sampleService.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 = "sampleNum", required = false) String sampleNum
            ,@RequestParam(value = "animalType", required = false) String animalType) {
        return sampleService.page(pageNum, pageSize, startTime,endTime,sampleNum,animalType);
    }

    @ApiOperation("样品留存登记详情")
    @GetMapping("/listById")
    public AjaxResult listById( JsSample jsSample){
        return success(sampleService.getDetail(jsSample));
    }

    @ApiOperation("样品留存登记列表")
    @PostMapping("/listByProduceName")
    public AjaxResult listByProduceName(@RequestBody Map<String, String> paramsMap){
        String produceName = paramsMap.get("produceName");
        String entranceBatchId = paramsMap.get("entranceBatchId");

        return success(  sampleService.list(new QueryWrapper<JsSample>().eq("produce_name",produceName).eq("entrance_batch_id",entranceBatchId)));
    }
}
