package org.jeecg.modules.database.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.*;
import org.jeecg.modules.database.constant.ExperimentStatus;
import org.jeecg.modules.database.dto.*;
import org.jeecg.modules.database.entity.*;
import org.jeecg.modules.database.service.*;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description: 试验管理
 * @Author: jeecg-boot
 * @Date: 2024-08-30
 * @Version: V1.0
 */
@Tag(name = "试验管理")
@RestController
@RequestMapping("/database/experiment")
@Slf4j
public class ExperimentController extends JeecgController<Experiment, IExperimentService> {
    @Autowired
    private IExperimentService                 experimentService;
    @Autowired
    private IExperimentLogService              experimentLogService;
    @Autowired
    private IExperimentAnnealProcessService    experimentAnnealProcessService;
    @Autowired
    private IExperimentRadiationProcessService experimentRadiationProcessService;
    @Autowired
    private IExperimentTestProcessService      experimentTestProcessService;
    @Autowired
    private ISysUserService                    userService;
    @Autowired
    private IExperimentUserService             experimentUserService;
    @Autowired
    private IExperimentSequenceService         experimentSequenceService;

    @Autowired
    private IExperimentSampleInfoService         experimentSampleInfoService;
    @Autowired
    private IExperimentDeviationConditionService experimentDeviationConditionService;
    @Autowired
    private IExperimentDeviationEquipmentService experimentDeviationEquipmentService;
    @Autowired
    private IExperimentIrradiationBoardService   experimentIrradiationBoardService;
    @Autowired
    private IExperimentFileService               experimentFileService;
    @Autowired
    private INasaDataRecordService               nasaDataRecordService;
    @Autowired
    private ILocalDatabaseService                localDatabaseService;

    /**
     * 分页列表查询
     *
     * @param experiment
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "试验管理-分页列表查询")
    @Operation(summary = "试验管理-分页列表查询")
    @GetMapping(value = "/list")
    //    @PermissionData(pageComponent="experiment/manage/ExperimentList")
    public Result<IPage<Experiment>> queryPageList(Experiment experiment, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                   HttpServletRequest req) {
        //Map<String, QueryRuleEnum> customeRuleMap = new HashMap<>();
        // 自定义duoXuan字段的查询规则为：LIKE_WITH_OR
        //customeRuleMap.put("startDate", QueryRuleEnum.RIGHT_LIKE);
        //
        Map<String, String[]> parameterMap = req.getParameterMap();
        //QueryWrapper<Experiment> queryWrapper = QueryGenerator.initQueryWrapper(experiment, parameterMap, customeRuleMap);
        Page<Experiment> page = new Page<>(pageNo, pageSize);

        experiment.setName(StringUtils.remove(experiment.getName(), "*"));
        experiment.setClientName(StringUtils.remove(experiment.getClientName(), "*"));
        experiment.setSampleType(StringUtils.remove(experiment.getSampleType(), "*"));
        experiment.setSampleModel(StringUtils.remove(experiment.getSampleModel(), "*"));
        experiment.setEquipmentModel(StringUtils.remove(experiment.getEquipmentModel(), "*"));

        String username = JwtUtil.getUserNameByToken(req);
        SysUser currentUser = userService.getUserByName(username);
        currentUser.setPostText("e.index_no asc");
        if (parameterMap.containsKey("column") && StringUtils.isNotBlank(parameterMap.get("column")[0])) {
            String columnObj = parameterMap.get("column")[0];
            if (!StringUtils.equals(columnObj, "createTime")) {
                String column = ReflectHelper.getTableFieldName(experiment.getClass(), columnObj);
                String order = parameterMap.get("order")[0];
                String orderSql = "e." + column + " " + order;
                currentUser.setPostText(orderSql);
            }
        }

        IPage<Experiment> pageList = experimentService.join(page, experiment, currentUser);
        pageList.getRecords().forEach(v -> experimentService.fetchExperimentDetail(v));
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param experiment
     * @return
     */
    @AutoLog(value = "试验管理-添加")
    @Operation(summary = "试验管理-添加",
            description = "添加试验,传sampleInfoList,deviationConditionList,deviationEquipmentList,irradiationBoardList,不用传fileList. </br> "
                    + "experimentUser 用,隔开")
    @RequiresPermissions("database:experiment:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody Experiment experiment, HttpServletRequest request) {
        String experimentNo = experiment.getExperimentNo();
        if (!StringUtils.startsWith(experimentNo, "KC")) {
            return Result.error("实验编号格式不正确！");
        }
        List<ExperimentSampleInfo> sampleInfoList = experiment.getSampleInfoList();
        List<ExperimentIrradiationBoard> irradiationBoardList = experiment.getIrradiationBoardList();
        List<ExperimentDeviationCondition> deviationConditionList = experiment.getDeviationConditionList();
        List<ExperimentDeviationEquipment> deviationEquipmentList = experiment.getDeviationEquipmentList();
        Set<String> sampleList = sampleInfoList.stream().map(v -> v.getSampleModel()).collect(Collectors.toUnmodifiableSet());
        Set<String> boardList = irradiationBoardList.stream().map(v -> v.getSampleModel()).collect(Collectors.toUnmodifiableSet());
        Set<String> conditionList = deviationConditionList.stream().map(v -> v.getSampleModel()).collect(Collectors.toUnmodifiableSet());
        Set<String> equipmentList = deviationEquipmentList.stream().map(v -> v.getSampleModel()).collect(Collectors.toUnmodifiableSet());
        if (!sampleList.equals(boardList)) {
            return Result.error("辐照板信息不匹配！");
        }
        if (!sampleList.equals(conditionList)) {
            return Result.error("偏置条件信息不匹配！");
        }
        if (!sampleList.equals(equipmentList)) {
            return Result.error("加偏设备信息不匹配！");
        }
        experiment.setStatus(ExperimentStatus.PRE_TEST);
        experimentService.saveWithDetail(experiment);

        ExperimentLog experimentLog = new ExperimentLog();
        experimentLog.setExperimentId(experiment.getId());
        experimentLog.setLogContent("新建实验");
        String username = JwtUtil.getUserNameByToken(request);
        SysUser userByName = userService.getUserByName(username);
        experimentLog.setCreateBy(userByName.getRealname());
        experimentLogService.save(experimentLog);

        return Result.OK("添加成功！");
    }

    @AutoLog(value = "试验管理-暂存")
    @Operation(summary = "试验管理-暂存")
    @RequiresPermissions("database:experiment:add")
    @PostMapping(value = "/staging")
    public Result<String> staging(@RequestBody Experiment experiment, HttpServletRequest request) {
        String experimentNo = experiment.getExperimentNo();
        if (!StringUtils.startsWith(experimentNo, "KC")) {
            return Result.error("实验编号格式不正确！");
        }
        //0503: 暂存 去掉状态的判断
        /*if (StringUtils.isNotBlank(experiment.getId())) {
            Experiment dbExp = experimentService.getById(experiment.getId());
            if (!(StringUtils.equals(dbExp.getStatus(), ExperimentStatus.STAGING) || StringUtils.equals(dbExp.getStatus(),
                    ExperimentStatus.PRE_TEST))) {
                return Result.error("实验状态不正确！");
            }
        }*/
        experiment.setStatus(ExperimentStatus.STAGING);
        experimentService.saveWithDetail(experiment);

        return Result.OK("暂存成功！");
    }

    /**
     * 编辑
     *
     * @param experiment
     * @return
     */
    @AutoLog(value = "试验管理-编辑")
    @Operation(summary = "试验管理-编辑",
            description = "编辑试验,传sampleInfoList,deviationConditionList,deviationEquipmentList,irradiationBoardList,不用传fileList \n "
                    + "experimentUser 用逗号隔开,无修改的字段可不传")
    @RequiresPermissions("database:experiment:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody Experiment experiment, HttpServletRequest request) {
        Experiment dbExp = experimentService.getById(experiment.getId());
        if (StringUtils.equals(dbExp.getStatus(), ExperimentStatus.COMPLETED) || StringUtils.equals(dbExp.getStatus(),
                ExperimentStatus.REVIEWED)) {
            return Result.error("试验状态:[" + dbExp.getStatus() + "]不能进行修改！");
        }
        if (StringUtils.equals(dbExp.getStatus(), ExperimentStatus.STAGING)) {
            experiment.setStatus(ExperimentStatus.PRE_TEST);
        } else {
            experiment.setStatus(dbExp.getStatus());
        }
        experiment.setIndexNo(dbExp.getIndexNo());
        List<ExperimentSampleInfo> sampleInfoList = experiment.getSampleInfoList();
        List<ExperimentIrradiationBoard> irradiationBoardList = experiment.getIrradiationBoardList();
        List<ExperimentDeviationCondition> deviationConditionList = experiment.getDeviationConditionList();
        List<ExperimentDeviationEquipment> deviationEquipmentList = experiment.getDeviationEquipmentList();
        Set<String> sampleList = sampleInfoList.stream().map(v -> v.getSampleModel()).collect(Collectors.toUnmodifiableSet());
        Set<String> boardList = irradiationBoardList.stream().map(v -> v.getSampleModel()).collect(Collectors.toUnmodifiableSet());
        Set<String> conditionList = deviationConditionList.stream().map(v -> v.getSampleModel()).collect(Collectors.toUnmodifiableSet());
        Set<String> equipmentList = deviationEquipmentList.stream().map(v -> v.getSampleModel()).collect(Collectors.toUnmodifiableSet());
        if (!sampleList.equals(boardList)) {
            return Result.error("辐照板信息不匹配！");
        }
        if (!sampleList.equals(conditionList)) {
            return Result.error("偏置条件信息不匹配！");
        }

        if (!sampleList.equals(equipmentList)) {
            return Result.error("加偏设备信息不匹配！");
        }

        experimentService.saveWithDetail(experiment);
        ExperimentLog experimentLog = new ExperimentLog();
        experimentLog.setExperimentId(experiment.getId());
        experimentLog.setLogContent("修改实验信息");
        String username = JwtUtil.getUserNameByToken(request);
        SysUser userByName = userService.getUserByName(username);
        experimentLog.setCreateBy(userByName.getRealname());
        experimentLogService.save(experimentLog);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "试验管理-通过id删除")
    @Operation(summary = "试验管理-通过id删除")
    @RequiresPermissions("database:experiment:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        experimentService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "试验管理-试验复制")
    @Operation(summary = "试验管理-试验复制")
    //@RequiresPermissions("database:experiment:delete")
    @PostMapping(value = "/copy")
    public Result<String> copy(@RequestParam(name = "id", required = true) String id) {
        Experiment old = experimentService.getById(id);
        experimentService.fetchExperimentDetail(old);
        Experiment copied = experimentService.copy(old);

        List<ExperimentAnnealProcess> experimentAnnealProcess = experimentAnnealProcessService.getByExperimentId(old.getId());
        if (CollUtil.isNotEmpty(experimentAnnealProcess)) {
            experimentAnnealProcess.forEach(v -> experimentAnnealProcessService.copy(v.getId(), copied.getId()));
        }
        List<ExperimentRadiationProcess> experimentRadiationProcess = experimentRadiationProcessService.getByExperimentId(old.getId());
        if (CollUtil.isNotEmpty(experimentRadiationProcess)) {
            experimentRadiationProcess.forEach(v -> experimentRadiationProcessService.copy(v.getId(), copied.getId()));
        }
        List<ExperimentTestProcess> experimentTestProcess = experimentTestProcessService.getByExperimentId(old.getId());
        if (CollUtil.isNotEmpty(experimentTestProcess)) {
            experimentTestProcess.forEach(v -> experimentTestProcessService.copy(v.getId(), copied.getId()));
        }
        return Result.OK("复制成功!");
    }

    @AutoLog(value = "试验管理-完成试验")
    @Operation(summary = "试验管理-完成试验")
    @PostMapping(value = "/complete")
    public Result<String> complete(@RequestBody Experiment experiment) {
        if (StringUtils.isBlank(experiment.getId())) {
            return Result.error("试验数据不存在！");
        }
        Experiment dbData = experimentService.getById(experiment.getId());
        if (StringUtils.equals(dbData.getStatus(), ExperimentStatus.COMPLETED) || StringUtils.equals(dbData.getStatus(),
                ExperimentStatus.REVIEWED)) {
            return Result.error("试验状态:[" + dbData.getStatus() + "]不能进行修改！");
        }
        experimentService.changeStatus(experiment.getId(), ExperimentStatus.COMPLETED);
        LocalDatabase localData = new LocalDatabase();
        localData.setClientName(dbData.getClientName());
        localData.setName(dbData.getName());
        localData.setType(dbData.getType());
        localData.setStartDate(dbData.getStartDate());
        localData.setEndDate(dbData.getEndDate());
        localData.setStatus(ExperimentStatus.COMPLETED);
        localData.setExperimentNo(dbData.getExperimentNo());
        localData.setExperimentId(dbData.getId());
        localData.setTotalCountXhy(dbData.getTotalCountXhy());
        localData.setTotalCountLhs(dbData.getTotalCountLhs());
        List<ExperimentSampleInfo> sampleInfoList = experimentSampleInfoService.getByExperimentId(dbData.getId());
        if (CollUtil.isNotEmpty(sampleInfoList)) {
            String joinStr = String.join(",", sampleInfoList.stream().map(v -> v.getSampleModel()).collect(Collectors.toSet()));
            localData.setSampleModel(joinStr);
        }
        localDatabaseService.save(localData);
        return Result.OK("试验已完成!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "试验管理-批量删除")
    @Operation(summary = "试验管理-批量删除")
    @RequiresPermissions("database:experiment:delete")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.experimentService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "试验管理-通过id查询")
    @Operation(summary = "试验管理-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<Experiment> queryById(@RequestParam(name = "id", required = true) String id) {
        Experiment experiment = experimentService.getById(id);
        if (experiment == null) {
            return Result.error("未找到对应数据");
        }
        experimentService.fetchExperimentDetail(experiment);
        return Result.OK(experiment);
    }

    @Operation(summary = "试验管理-检查能否生成报告")
    @GetMapping(value = "/checkCanReport")
    public Result<Experiment> checkCanReport(@RequestParam(name = "id", required = true) String id) {
        Experiment experiment = experimentService.getById(id);
        if (experiment == null) {
            return Result.error("未找到试验数据!");
        }
        List<ExperimentTestProcess> experimentTestProcesses = experimentTestProcessService.getByExperimentId(experiment.getId());
        List<ExperimentRadiationProcess> radiationProcessList = experimentRadiationProcessService.getByExperimentId(experiment.getId());
        List<ExperimentAnnealProcess> experimentAnnealProcessList = experimentAnnealProcessService.getByExperimentId(experiment.getId());
        if (CollUtil.isEmpty(experimentTestProcesses)) {
            return Result.error("未填写测试过程!");
        }
        if (CollUtil.isEmpty(radiationProcessList)) {
            return Result.error("未填写辐照过程!");
        }
        if (CollUtil.isEmpty(experimentAnnealProcessList)) {
            return Result.error("未填写退火过程!");
        }
        return Result.OK();
    }

    /**
     * 导出excel
     *
     * @param request
     * @param experiment
     */

    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, Experiment experiment) {
        //return super.exportXls(request, experiment, Experiment.class, "试验管理");
        String title = "试验管理";
        QueryWrapper<Experiment> queryWrapper = QueryGenerator.initQueryWrapper(experiment, request.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        // 过滤选中数据
        String selections = request.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            queryWrapper.in("id", selectionList);
        }
        // Step.2 获取导出数据
        queryWrapper.orderBy(true, true, "index_no");
        List<Experiment> exportList = experimentService.list(queryWrapper);
        for (Experiment ex : exportList) {
            experimentService.fetchExperimentDetail(ex);
        }
        List<ExperimentExportDTO> resultList = new ArrayList<>();
        for (Experiment ex : exportList) {
            ExperimentExportDTO dto = new ExperimentExportDTO();
            dto.setId(ex.getId());
            dto.setIndexNo(ex.getIndexNo());
            dto.setExperimentNo(ex.getExperimentNo());
            dto.setName(ex.getName());
            dto.setClientName(ex.getClientName());
            dto.setType(ex.getType());
            dto.setStartDate(ex.getStartDate());
            dto.setEndDate(ex.getEndDate());
            String equipmentStr = ex.getDeviationEquipmentList().stream().map(v -> v.getEquipmentNo()).filter(
                            v -> StringUtils.isNotBlank(v))
                    .collect(Collectors.joining("\n"));
            dto.setEquipment(equipmentStr);
            dto.setSupervisorName(ex.getSupervisorName());
            dto.setReportCount(ex.getExperimentReportList().size() + "");
            List<ExperimentRating> experimentRatingList = ex.getExperimentRatingList();
            String rateStr = experimentRatingList.stream().map(v -> v.getRateUserName() + "：" + v.getTotalScore()).collect(
                    Collectors.joining("\n"));
            dto.setRateUserAndScore(rateStr);
            List<ExperimentRadiationProcess> experimentRadiationProcess = experimentRadiationProcessService.getByExperimentId(ex.getId());
            //辐照过程
            List<RadiationProcessExportDTO> detailList = new ArrayList<>();
            //List<ExperimentIrradiationBoard> irradiationBoardList = ex.getIrradiationBoardList();
            if (CollUtil.isNotEmpty(experimentRadiationProcess)) {
                experimentRadiationProcess.forEach(v -> {
                    List<ExperimentSampleInfo> sampleInfoList = v.getSampleInfoList();
                    if (CollUtil.isNotEmpty(sampleInfoList)) {
                        sampleInfoList.forEach(sample -> {
                            RadiationProcessExportDTO detail = new RadiationProcessExportDTO();
                            detail.setRadiateType(v.getRadiationSource());
                            detail.setSampleModel(sample.getSampleModel());
                            detail.setSampleType(sample.getSampleType());
                            detail.setMeasurementRate("");
                            detail.setTotalMeasurementRate("");
                            detail.setSourceArea("");
                            detailList.add(detail);
                        });
                    }
                });
            }

            //退火过程
            List<AnnealProcessExportDTO> annealProcessList = new ArrayList<>();
            List<ExperimentAnnealProcess> experimentAnnealProcessList = experimentAnnealProcessService.getByExperimentId(ex.getId());
            if (CollUtil.isNotEmpty(experimentAnnealProcessList)) {
                experimentAnnealProcessList.forEach(v -> {

                    List<ExperimentSampleInfo> sampleInfoList = v.getSampleInfoList();
                    if (CollUtil.isNotEmpty(sampleInfoList)) {
                        sampleInfoList.forEach(sample -> {
                            AnnealProcessExportDTO annealProcessExportDTO = new AnnealProcessExportDTO();
                            annealProcessExportDTO.setSampleName(sample.getSampleName());
                            annealProcessExportDTO.setSampleModel(sample.getSampleModel());
                            annealProcessExportDTO.setSampleType(sample.getSampleType());
                            annealProcessExportDTO.setAnnealTemperature(v.getAnnealTemperature());
                            annealProcessExportDTO.setAnnealStartTime(DateUtils.formatDate(v.getAnnealStartTime(), "yyyy-MM-dd HH:mm"));
                            annealProcessExportDTO.setAnnealEndTime(DateUtils.formatDate(v.getAnnealEndTime(), "yyyy-MM-dd HH:mm"));
                            annealProcessList.add(annealProcessExportDTO);
                        });
                    }

                });
            }

            dto.setAnnealProcessList(annealProcessList);

            //测试过程
            List<ExperimentTestProcess> experimentTestProcessList = experimentTestProcessService.getByExperimentId(ex.getId());
            List<TestProcessExportDTO> testProcessList = new ArrayList<>();
            if (CollUtil.isNotEmpty(experimentTestProcessList)) {
                experimentTestProcessList.forEach(v -> {
                    List<ExperimentSampleInfo> sampleInfoList = v.getSampleInfoList();
                    if (CollUtil.isNotEmpty(sampleInfoList)) {
                        TestProcessExportDTO testProcessExportDTO = new TestProcessExportDTO();
                        testProcessExportDTO.setEnvironmentalTemperature(v.getEnvironmentalTemperature());
                        testProcessExportDTO.setEnvironmentalHumidity(v.getEnvironmentalHumidity());

                        testProcessList.add(testProcessExportDTO);
                    }
                });
            }
            dto.setTestProcessList(testProcessList);

            dto.setRadiationProcessList(detailList);
            resultList.add(dto);
        }
        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //此处设置的filename无效 ,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.FILE_NAME, title);
        mv.addObject(NormalExcelConstants.CLASS, ExperimentExportDTO.class);
        //update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
        ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + Optional.ofNullable(sysUser).map(v -> v.getRealname())
                .orElse("") + ",导出日期:" + DateUtils.formatDate(new Date()), title);
        //exportParams.setImageBasePath(jeecgBaseConfig.getPath().getUpload());
        //update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
        mv.addObject(NormalExcelConstants.PARAMS, exportParams);
        mv.addObject(NormalExcelConstants.DATA_LIST, resultList);
        return mv;

    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequiresPermissions("database:experiment:add")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, Experiment.class);
    }

    /**
     * 审核
     *
     * @param experiment
     * @return
     */
    @PostMapping(value = "/audit")
    public Result<String> queryPageList(@RequestBody Experiment experiment) {
        if (Objects.isNull(experiment) || StringUtils.isBlank(experiment.getId())) {
            return Result.OK("请选择试验");
        }
        experiment.setStatus(ExperimentStatus.REVIEWED);
        experimentService.updateById(experiment);
        return Result.OK("审核完成");
    }

}
