package com.ruoyi.export.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.export.domain.vo.ExportLanguageVo;
import com.ruoyi.export.domain.bo.ExportLanguageBo;
import com.ruoyi.export.service.IExportLanguageService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 语言管理
 *
 * @author ruoyi
 * @date 2025-07-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/export/language")
public class ExportLanguageController extends BaseController {

    private final IExportLanguageService iExportLanguageService;

    /**
     * 查询语言管理列表
     */
    @GetMapping("/list")
    public TableDataInfo<ExportLanguageVo> list(ExportLanguageBo bo, PageQuery pageQuery) {
        return iExportLanguageService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出语言管理列表
     */
    @Log(title = "语言管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ExportLanguageBo bo, HttpServletResponse response) {
        List<ExportLanguageVo> list = iExportLanguageService.queryList(bo);
        ExcelUtil.exportExcel(list, "语言管理", ExportLanguageVo.class, response);
    }

    /**
     * 获取语言管理详细信息
     *
     * @param languageId 主键
     */
    @GetMapping("/{languageId}")
    public R<ExportLanguageVo> getInfo(@NotNull(message = "主键不能为空")
                                       @PathVariable Long languageId) {
        return R.ok(iExportLanguageService.queryById(languageId));
    }

    /**
     * 新增语言管理
     */
    @Log(title = "语言管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ExportLanguageBo bo) {
        return toAjax(iExportLanguageService.insertByBo(bo));
    }

    /**
     * 修改语言管理
     */
    @Log(title = "语言管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ExportLanguageBo bo) {
        return toAjax(iExportLanguageService.updateByBo(bo));
    }

    /**
     * 删除语言管理
     *
     * @param languageIds 主键串
     */
    @Log(title = "语言管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{languageIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] languageIds) {
        return toAjax(iExportLanguageService.deleteWithValidByIds(Arrays.asList(languageIds), true));
    }
}
