package digital.laboratory.platform.inspection.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import digital.laboratory.platform.common.core.util.R;
import digital.laboratory.platform.inspection.dto.TestSampleDataExpandDTO;
import digital.laboratory.platform.inspection.entity.TestRecordSampleDataExpand;
import digital.laboratory.platform.inspection.service.TestRecordSampledataExpandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author xy
 * @version 1.0
 * @title TestRecordSampleDataController   实验数据控制器
 * @description
 * @create 2024/1/19 15:57
 */
@RestController
@RequestMapping("/testDataExpand")
@Api(tags = "18-检验鉴定-实验扩展数据管理服务", description = "检验鉴定-实验扩展数据管理服务")
public class TestRecordSampleDataExpandController {

    @Resource
    private TestRecordSampledataExpandService testRecordSampledataExpandService;

    @ApiOperation("样本实验扩展数据 - 列表查询")
    @PostMapping("/list")
    public R<List<TestRecordSampleDataExpand>> list(String dataId) {
        return R.ok(testRecordSampledataExpandService.list(Wrappers.<TestRecordSampleDataExpand>lambdaQuery()
                .eq(StrUtil.isNotBlank(dataId), TestRecordSampleDataExpand::getTestDataId, dataId))
        );
    }

    @ApiOperation("更新扩展数据")
    @PutMapping("/update")
    public R<Boolean> update(@RequestBody TestSampleDataExpandDTO updateDTO) {
        if (StrUtil.isBlank(updateDTO.getId())) {
            return R.failed("扩展数据id不能为空！");
        }
        return R.ok(testRecordSampledataExpandService.updateBatchByDTO(Collections.singletonList(updateDTO), null));
    }

}
