/**
 * 20241029 ©WANGKANG 1686617586@qq.com
 */

package com.taais.biz.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.taais.common.core.core.domain.CommonResult;
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 com.taais.biz.domain.vo.DataSeqVo;
import com.taais.biz.domain.bo.DataSeqBo;
import com.taais.biz.service.IDataSeqService;

import com.taais.common.core.core.page.PageResult;

/**
 * 数据管理Controller
 *
 * @author wangkang
 * 2024-10-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/DataSeq")
public class DataSeqController extends BaseController {
    @Resource
    private IDataSeqService dataSeqService;

    /**
     * 查询数据管理列表
     */
    @SaCheckPermission("demo:DataSeq:list")
    @GetMapping("/list")
    public CommonResult<PageResult<DataSeqVo>> list(DataSeqBo dataSeqBo) {
        return CommonResult.success(dataSeqService.selectPage(dataSeqBo));
    }

    /**
     * 导出数据管理列表
     */
    @SaCheckPermission("demo:DataSeq:export")
    @Log(title = "数据管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataSeqBo dataSeqBo) {
        List<DataSeqVo> list = dataSeqService.selectList(dataSeqBo);
        ExcelUtil.exportExcel(list, "数据管理", DataSeqVo.class, response);
    }

    /**
     * 获取数据管理详细信息
     */
    @SaCheckPermission("demo:DataSeq:query")
    @GetMapping(value = "/{id}")
    public CommonResult<DataSeqVo> getInfo(@PathVariable Long id) {
        return CommonResult.success(dataSeqService.selectById(id));
    }

    /**
     * 新增数据管理
     */
    @SaCheckPermission("demo:DataSeq:add")
    @Log(title = "数据管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public CommonResult<Void> add(@Validated @RequestBody DataSeqBo dataSeqBo) {
        boolean inserted = dataSeqService.insert(dataSeqBo);
        if (!inserted) {
            return CommonResult.fail("新增数据管理记录失败！");
        }
        return CommonResult.success();
    }

    /**
     * 修改数据管理
     */
    @SaCheckPermission("demo:DataSeq:edit")
    @Log(title = "数据管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public CommonResult<Void> edit(@Validated @RequestBody DataSeqBo dataSeqBo) {
        Boolean updated = dataSeqService.update(dataSeqBo);
        if (!updated) {
            return CommonResult.fail("修改数据管理记录失败!");
        }
        return CommonResult.success();
    }

    /**
     * 删除数据管理
     */
    @SaCheckPermission("demo:DataSeq:remove")
    @Log(title = "数据管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult<Void> remove(@PathVariable Long[] ids) {
        boolean deleted = dataSeqService.deleteByIds(ids);
        if (!deleted) {
            return CommonResult.fail("删除数据管理记录失败!");
        }
        return CommonResult.success();
    }

    @GetMapping("/getAllImages/{inputOdssId}")
    public CommonResult<List<String>> getAllImages(@PathVariable Long inputOdssId) {
        return CommonResult.success(dataSeqService.getAllImages(inputOdssId));
    }

    @GetMapping("/getImages/{inputOdssId}/{subsystem}/{ifInput}/{dir}")
    public CommonResult<List<String>> getImages(@PathVariable Long inputOdssId, @PathVariable String subsystem, @PathVariable Boolean ifInput, @PathVariable String dir) {
        return CommonResult.success(dataSeqService.getImages(inputOdssId, subsystem, ifInput, dir));
    }
}
