package digital.laboratory.platform.inspection.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import digital.laboratory.platform.common.core.util.R;
import digital.laboratory.platform.inspection.dto.TestRecordSampleSolutionDto;
import digital.laboratory.platform.inspection.entity.TestRecordSampleSolution;
import digital.laboratory.platform.inspection.entity.TestRecordStandardSolution;
import digital.laboratory.platform.inspection.service.TestRecordSampleSolutionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/testRecord_sampleSolution")
@Api(tags = "10-检验记录-使用的样本溶液，样本溶液管理", description = "检验记录-使用的样本溶液，样本溶液管理")
public class TestRecordSampleSolutionController {

    @Resource
    private TestRecordSampleSolutionService testRecordSampleSolutionService;

    @PostMapping("/addSolution")
    @ApiOperation(value = "添加实验样本溶液", notes = "添加实验过程中使用的样本溶液")
    public R<TestRecordSampleSolution> addTestRecordSampleSolution(@RequestBody TestRecordSampleSolutionDto testRecordSampleSolutionDto) {
        TestRecordSampleSolution testRecordSampleSolution = testRecordSampleSolutionService.addTestRecordSampleSolution(testRecordSampleSolutionDto);
        return testRecordSampleSolution != null ? R.ok(testRecordSampleSolution, "添加成功!") : R.failed("添加失败!");
    }

    @DeleteMapping("/delSolution")
    @ApiOperation(value = "删除实验样本溶液", notes = "删除实验过程中使用的样本溶液")

    public R delTestRecordSampleSolution(String id) {
        return testRecordSampleSolutionService.delTestRecordSampleSolution(id) ? R.ok("删除成功!") : R.failed("删除失败!");
    }

    @PutMapping("/updateSolution")
    @ApiOperation(value = "修改实验样本溶液", notes = "修改实验过程中使用的样本溶液")
    public R<TestRecordSampleSolution> updateTestRecordSampleSolution(@RequestBody TestRecordSampleSolutionDto testRecordSampleSolutionDto) {
        TestRecordSampleSolution testRecordSampleSolution = testRecordSampleSolutionService.updateTestRecordSampleSolution(testRecordSampleSolutionDto);
        return testRecordSampleSolution != null ? R.ok(testRecordSampleSolution, "修改成功!") : R.failed("修改失败!");
    }

    @GetMapping("/getSolutionList")
    @ApiOperation(value = "通过实验（检验）ID查询样本溶液集合", notes = "通过实验（检验）ID查询样本溶液集合")
    public R<List<TestRecordSampleSolution>> getSolutionList(String testId, String keywords) {
        return R.ok(testRecordSampleSolutionService.getSolutionList(testId, keywords), "查询成功");
    }

    @GetMapping("/getSolutionPage")
    @ApiOperation(value = "通过实验（检验）ID查询样本溶液分页集合", notes = "通过实验（检验）ID查询样本溶液分页集合")
    public R<IPage<TestRecordSampleSolution>> getSolutionPage(Page page, String testId, String keywords) {
        return R.ok(testRecordSampleSolutionService.getSolutionPage(page, testId, keywords), "查询成功");
    }

    @PutMapping("/matchingWeighing")
    @ApiOperation(value = "通过实验ID匹配样本溶液质量与计算浓度", notes = "通过实验ID匹配样本溶液质量与计算浓度")
    public R<List<TestRecordSampleSolution>> matchingWeighing(String id) {
        List<TestRecordSampleSolution> testRecordSampleSolutionList = testRecordSampleSolutionService.matchingWeighing(id);
        return testRecordSampleSolutionList != null ? R.ok(testRecordSampleSolutionList, "匹配成功!") : R.failed("匹配失败!");
    }


    @PostMapping("/createTaskSamSol")
    @ApiOperation(value = "根据任务类型实验中选择的检材创建对应的样本溶液", notes = "根据任务类型实验中选择的检材创建对应的样本溶液")
    public R createTaskSamSol(String testId) {
        return testRecordSampleSolutionService.createTaskSamSol(testId) ? R.ok("创建成功!") : R.failed("创建失败!");
    }

    @PostMapping("/copy")
    @ApiOperation(value = "根据已有样本溶液创建多个样本溶液",notes = "参数 testRecordSampleSolutionDto：已有样本溶液对象；testRecordSampleSolutionDto中的materialIdList：需要创建的对应检材ID集合")
    public R copySolution(@RequestBody TestRecordSampleSolutionDto testRecordSampleSolutionDto) {
        List<TestRecordSampleSolution> recordSampleSolutions = testRecordSampleSolutionService.copySolution(testRecordSampleSolutionDto);
        return recordSampleSolutions != null ? R.ok(recordSampleSolutions, "创建成功!") : R.failed("创建失败!");
    }
}