package org.springblade.system.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.annotation.RequiresPermissions;
import org.springblade.common.annotation.SysLog;
import org.springblade.common.core.controller.BaseController;
import org.springblade.common.core.domain.AjaxResult;
import org.springblade.common.enums.OperaType;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.system.domain.ArchivedSettingDto;
import org.springblade.system.service.ArchivedSettingService;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author：liang.chao
 * @Date：2025/9/15 - 9:54
 */
@RestController
@RequestMapping("/archivedSetting")
@Slf4j
@NonDS
public class ArchivedSettingController extends BaseController {

    @Resource
    private ArchivedSettingService service;
    @PostMapping("query")
    public AjaxResult getArchivedSetting(@RequestBody ArchivedSettingDto dto) {
        try {
            List<ArchivedSettingDto> list = service.getArchivedSetting(dto);
            return AjaxResult.success(list);
        } catch (Exception e) {
            log.error(e.toString(), e);
            return AjaxResult.error("请求出错了");
        }
    }

    @PostMapping("add")
    @SysLog(title = "新增归档配置", module = "数据/档案移交->归档配置", businessType = OperaType.INSERT, details = "新增归档配置", logType = 1)
    @RequiresPermissions("archived:setting:add")
    public AjaxResult addArchivedSetting(@RequestBody ArchivedSettingDto dto) {
        try {
            return service.addArchivedSetting(dto);
        } catch (Exception e) {
            log.error(e.toString(), e);
            return AjaxResult.error("请求出错了");
        }
    }
    @PostMapping("edit")
    @SysLog(title = "修改归档配置", module = "数据/档案移交->归档配置", businessType = OperaType.UPDATE, details = "修改归档配置", logType = 1)
    @RequiresPermissions("archived:setting:edit")
    public AjaxResult updateArchivedSetting(@RequestBody List<ArchivedSettingDto> dto) {
        try {
            return service.updateArchivedSetting(dto);
        } catch (Exception e) {
            log.error(e.toString(), e);
            return AjaxResult.error("请求出错了");
        }
    }
}
