package com.taais.biz.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.taais.biz.domain.bo.DataAmplificationTaskBo;
import com.taais.biz.domain.bo.DataAmplificationTaskBo;
import com.taais.biz.domain.dto.task.TestResultDto;
import com.taais.biz.domain.dto.task.TranResultDto;
import com.taais.biz.domain.vo.AlgorithmBizProcessVo;
import com.taais.biz.domain.vo.DataAmplificationTaskVo;
import com.taais.biz.service.IAlgorithmBizProcessService;
import com.taais.biz.service.IDataAmplificationTaskService;
import com.taais.common.core.core.domain.CommonResult;
import com.taais.common.core.core.page.PageResult;
import com.taais.common.excel.utils.ExcelUtil;
import com.taais.common.log.annotation.Log;
import com.taais.common.log.enums.BusinessType;
import com.taais.common.web.annotation.RepeatSubmit;
import com.taais.common.web.core.BaseController;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * 数据扩增业务处理Controller
 *
 * @author 0
 * 2024-06-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/task/dataAmplificationTask")
public class DataAmplificationTaskController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(DataAmplificationTaskController.class);
    @Resource
    private IDataAmplificationTaskService dataAmplificationTaskService;

    /**
     * 查询数据扩增业务处理列表
     */
    @GetMapping("/list")
    public CommonResult<PageResult<DataAmplificationTaskVo>> list(DataAmplificationTaskBo dataAmplificationTaskBo) {
        return CommonResult.success(dataAmplificationTaskService.selectPage(dataAmplificationTaskBo));
    }

    /**
     * 导出数据扩增业务处理列表
     */
    @Log(title = "数据扩增业务处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataAmplificationTaskBo dataAmplificationTaskBo) {
        List<DataAmplificationTaskVo> list = dataAmplificationTaskService.selectList(dataAmplificationTaskBo);
        ExcelUtil.exportExcel(list, "数据扩增业务处理", DataAmplificationTaskVo.class, response);
    }

    /**
     * 获取数据扩增业务处理详细信息
     */
    @GetMapping(value = "/{id}")
    public CommonResult<DataAmplificationTaskVo> getInfo(@PathVariable Long id) {
        return CommonResult.success(dataAmplificationTaskService.selectById(id));
    }

    /**
     * 新增数据扩增业务处理
     */
    @Log(title = "数据扩增业务处理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public CommonResult<Void> add(@Validated @RequestBody DataAmplificationTaskBo algorithmBizProcessBo) {
        boolean inserted = dataAmplificationTaskService.insert(algorithmBizProcessBo);
        if (!inserted) {
            return CommonResult.fail("新增数据扩增业务处理记录失败！");
        }
        return CommonResult.success();
    }

    /**
     * 修改数据扩增业务处理
     */
    @Log(title = "数据扩增业务处理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public CommonResult<Void> edit(@Validated @RequestBody DataAmplificationTaskBo dataAmplificationTaskBo) {
        Boolean updated = dataAmplificationTaskService.update(dataAmplificationTaskBo);
        if (!updated) {
            return CommonResult.fail("修改数据扩增业务处理记录失败!");
        }
        return CommonResult.success();
    }

    /**
     * 删除数据扩增业务处理
     */
    @Log(title = "数据扩增业务处理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult<Void> remove(@PathVariable Long[] ids) {
        boolean deleted = dataAmplificationTaskService.deleteByIds(ids);
        if (!deleted) {
            return CommonResult.fail("删除数据扩增业务处理记录失败!");
        }
        return CommonResult.success();
    }
}
