package digital.laboratory.platform.inspection.controller;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import digital.laboratory.platform.common.core.util.R;
import digital.laboratory.platform.inspection.dto.TestRecordArgumentDto;
import digital.laboratory.platform.inspection.entity.TaskInfo;
import digital.laboratory.platform.inspection.entity.TestRecordInstrument;
import digital.laboratory.platform.inspection.service.TestRecordInstrumentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author xy
 * @version 1.0
 * @title TestRecordInstrumentController
 * @description 实验中使用到的仪器设备
 * @create 2023/12/19 11:48
 */
@RestController
@RequestMapping("/testRecord_instrument")
@Api(tags = "07-检验记录-使用仪器管理", description = "检验记录-使用仪器管理")
public class TestRecordInstrumentController {
    @Resource
    private TestRecordInstrumentService testRecordInstrumentService;

    //添加
    @PostMapping("/addInstrument")
    @ApiOperation(value = "添加设备仪器", notes = "添加设备仪器")
    public R addInstrument(@RequestBody TestRecordInstrument testRecordInstrument) {
        TestRecordInstrument ret = testRecordInstrumentService.addTestRecordInstrument(testRecordInstrument);
        if (ret != null) {
            return R.ok(ret, "添加实验仪器设备成功");
        } else {
            return R.failed("false", "添加实验仪器设备失败");
        }
    }

    //修改接口
    @PostMapping("/updateInstrument")
    @ApiOperation(value = "修改实验设备仪器", notes = "")
    public R updateInstrument(@RequestBody TestRecordInstrument testRecordInstrument) {
        TestRecordInstrument ret = testRecordInstrumentService.updateTestRecordInstrument(testRecordInstrument);
        if (ret != null) {
            return R.ok(ret, "添加成功");
        } else {
            return R.failed("false", "添加失败");
        }
    }

    //删除数据
    @DeleteMapping("/deleteInstrument")
    @ApiOperation(value = "删除实验设备仪器信息", notes = "")
    public R deleteInstrument(String id) {
        Assert.notBlank(id, "参数id不能为空");
        boolean ret = testRecordInstrumentService.deleteTestRecordInstrument(id);
        if (ret) {
            return R.ok("true", "删除成功");
        } else {
            return R.failed("false", "删除成功");
        }
    }

    //显示列表分页
    @GetMapping("/getInstrumentPageList")
    @ApiOperation(value = "获取实验中仪器设备分页数据", notes = "")
    public R getInstrumentPageList(Page page, String testId, String keywords, Integer opCode) {
        return R.ok(testRecordInstrumentService.getTestRecordInstrumentPageList(page, testId,keywords,opCode), "获取数据成功");
    }

    @GetMapping("/getInstrumentToTemplatePage")
    @ApiOperation(value = "获取模板中仪器设备分页数据", notes = "")
    public R getTemplateInstrumentPageList(Page page, String templateId, String keywords, Integer opCode) {
        return R.ok(testRecordInstrumentService.getTemplateInstrumentPageList(page, templateId,keywords,opCode), "获取数据成功");
    }

    //显示列表
    @GetMapping("/getInstrumentList")
    @ApiOperation(value = "获取列表", notes = "")
    public R getInstrumentList(TestRecordInstrument testRecordInstrument) {
        return R.ok(testRecordInstrumentService.getTestRecordInstrumentList(testRecordInstrument), "获取数据成功");
    }

    @PutMapping("/useInstrument")
    @ApiOperation(value = "添加或移除实验过程中使用的仪器设备", notes = "添加或移除实验过程中使用的仪器设备")
    public R useTestRecordInstrument(@RequestBody TestRecordArgumentDto testRecordArgumentDto) {
        return testRecordInstrumentService.useTestRecordInstrument(testRecordArgumentDto) ? R.ok("添加成功!") : R.failed("添加失败!");
    }

    @PutMapping("/useInstrumentToTemplate")
    @ApiOperation(value = "添加或移除模板中使用的仪器设备", notes = "添加或移除模板中使用的仪器设备")
    public R useTemplateInstrument(@RequestBody TestRecordArgumentDto testRecordArgumentDto) {
        return testRecordInstrumentService.useTemplateInstrument(testRecordArgumentDto) ? R.ok("添加成功!") : R.failed("添加失败!");
    }
}
