package digital.laboratory.platform.inspection.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import digital.laboratory.platform.common.core.util.R;
import digital.laboratory.platform.inspection.dto.TestRecordStandardSolutionDto;
import digital.laboratory.platform.inspection.entity.TestRecordStandardSolution;
import digital.laboratory.platform.inspection.service.TestRecordStandardSolutionService;
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_standardSolution")
@Api(tags = "11-检验记录-使用的标准溶液，标准溶液", description = "检验记录-使用的标准溶液，标准溶液")

public class TestRecordStandardSolutionController {
    @Resource
    private TestRecordStandardSolutionService testRecordStandardSolutionService;

    @PostMapping("/addSolution")
    @ApiOperation(value = "添加实验标准溶液", notes = "添加实验过程中使用的标准溶液")
    public R addTestRecordStandardSolution(@RequestBody TestRecordStandardSolutionDto testRecordStandardSolution) {
        return testRecordStandardSolutionService.addTestRecordStandardSolution(testRecordStandardSolution) != null ? R.ok(testRecordStandardSolution, "添加成功!") : R.failed("添加失败!");
    }

    @PostMapping("/addBlankSolution")
    @ApiOperation(value = "添加空白溶剂、空白样品 type 1：空白溶剂 -1：空白样品", notes = "添加空白溶剂、空白样品 type 1：空白溶剂 -1：空白样品")
    public R addBlankSolution(String testId,Integer type) {
        TestRecordStandardSolution testRecordStandardSolution = testRecordStandardSolutionService.addBlankSolution(testId,type);
        return testRecordStandardSolution != null ? R.ok(testRecordStandardSolution, "添加成功!") : R.failed("添加失败!");
    }

    @PostMapping("/addQCSolution")
    @ApiOperation(value = "添加质控溶液", notes = "添加质控溶液")
    public R createQualityControlSol(String testId) {
        List<TestRecordStandardSolution> qualityControlSol = testRecordStandardSolutionService.createQualityControlSol(testId);
        return qualityControlSol.size()>0 ? R.ok(qualityControlSol, "添加成功!") : R.failed("添加失败!");
    }

    @DeleteMapping("/delSolution")
    @ApiOperation(value = "删除实验标准溶液", notes = "删除实验过程中使用的标准溶液")
    public R delTestRecordStandardSolution(String id) {
        return testRecordStandardSolutionService.delTestRecordStandardSolution(id) ? R.ok("删除成功!") : R.failed("删除失败!");
    }

    @PutMapping("/updateSolution")
    @ApiOperation(value = "修改实验标准溶液", notes = "修改实验过程中使用的标准溶液")
    public R updateTestRecordStandardSolution(@RequestBody TestRecordStandardSolutionDto testRecordStandardSolutionDto) {
        return testRecordStandardSolutionService.updateTestRecordStandardSolution(testRecordStandardSolutionDto) != null ? R.ok(testRecordStandardSolutionDto, "修改成功") : R.failed("修改失败!");
    }

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

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

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

    @GetMapping("/detection")
    @ApiOperation(value = "判断实验中是否存在至少一瓶标准溶液", notes = "判断实验中是否存在至少一瓶标准溶液")
    public R detection(String testId) {
        return R.ok(testRecordStandardSolutionService.detection(testId));
    }


}
