package org.eco.als.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.eco.als.domain.bo.DataImportBo;
import org.eco.als.domain.vo.DataImportVo;
import org.eco.als.service.IDataImportService;
import org.eco.common.core.core.domain.CommonResult;
import org.eco.common.core.core.page.PageResult;
import org.eco.common.log.annotation.Log;
import org.eco.common.log.enums.BusinessType;
import org.eco.common.web.annotation.RepeatSubmit;
import org.eco.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 数据导入信息Controller
 *
 * @author wgk
 * @date 2024-07-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/als/dataImport")
public class DataImportController extends BaseController {
    @Resource
    private IDataImportService dataImportService;

    /**
     * 查询数据导入信息列表
     */
    @SaCheckPermission("als:dataImport:list")
    @GetMapping("/list")
    public CommonResult<PageResult<DataImportVo>> list(DataImportBo dataImportBo) {
        return CommonResult.success(dataImportService.selectPage(dataImportBo));
    }

    /**
     * 获取数据导入信息详细信息
     */
    @SaCheckPermission("als:dataImport:query")
    @GetMapping(value = "/{id}")
    public CommonResult<DataImportVo> getInfo(@PathVariable Long id) {
        return CommonResult.success(dataImportService.selectById(id));
    }

    /**
     * 新增数据导入信息
     */
    @SaCheckPermission("als:dataImport:add")
    @Log(title = "数据导入信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public CommonResult<Void> add(@Validated @RequestBody DataImportBo dataImportBo) {
        boolean inserted = dataImportService.insert(dataImportBo);
        if (!inserted) {
            return CommonResult.fail("新增数据导入信息记录失败！");
        }
        return CommonResult.success();
    }

    /**
     * 修改数据导入信息
     */
    @SaCheckPermission("als:dataImport:edit")
    @Log(title = "数据导入信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public CommonResult<Void> edit(@Validated @RequestBody DataImportBo dataImportBo) {
        boolean updated = dataImportService.update(dataImportBo);
        if (!updated) {
            return CommonResult.fail("修改数据导入信息记录失败!");
        }
        return CommonResult.success();
    }

    /**
     * 删除数据导入信息
     */
    @SaCheckPermission("als:dataImport:remove")
    @Log(title = "数据导入信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult<Void> remove(@PathVariable Long[] ids) {
        boolean deleted = dataImportService.deleteByIds(ids);
        if (!deleted) {
            return CommonResult.fail("删除数据导入信息记录失败!");
        }
        return CommonResult.success();
    }
}
