package org.springblade.system.controller;

import com.github.pagehelper.PageHelper;
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.core.page.TableDataInfo;
import org.springblade.common.enums.OperaType;
import org.springblade.common.utils.sql.SqlUtil;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.system.domain.ArchivalCatalogueDto;
import org.springblade.system.domain.ProjectDto;
import org.springblade.system.domain.SelectDto;
import org.springblade.system.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Author：liang.chao
 * @Date：2025/9/11 - 9:50
 * 档案管理->项目管理
 */
@RestController
@RequestMapping("/project")
@Slf4j
@NonDS
public class ProjectController extends BaseController {

    @Autowired
    private ProjectService service;
    @PostMapping("getProjectList")
    @SysLog(title = "项目管理列表", module = "档案管理->项目管理", businessType = OperaType.QUERY, details = "项目管理列表", logType = 1)
    @RequiresPermissions("project:manage:list")
    public TableDataInfo getProjectList(@RequestBody ProjectDto dto) {
        try {
			// 直接使用 dto 中的分页参数
			PageHelper.startPage(dto.getPageNum() != null ? dto.getPageNum() : 1,
					dto.getPageSize() != null ? dto.getPageSize() : 10,
					SqlUtil.escapeOrderBySql(dto.getOrderBy()))
				.setReasonable(dto.getReasonable() != null ? dto.getReasonable() : true);
            List<ProjectDto> list = service.list(dto);
            return getDataTable(list);
        } catch (Exception e) {
            log.error(e.toString(), e);
            return getDataTable(new ArrayList<>());
        }
    }
    @PostMapping("getFileCatalogSelect")
    @SysLog(title = "档案目录下拉", module = "档案管理->档案目录下拉", businessType = OperaType.QUERY, details = "档案目录下拉", logType = 1)
    public AjaxResult getFileCatalogSelect() {
        try {
            List<SelectDto> list = service.getFileCatalogSelect();
            return AjaxResult.success(list);
        } catch (Exception e) {
            log.error(e.toString(), e);
            return AjaxResult.error("请求出错了");
        }
    }

    @PostMapping("updateContentsName")
    @SysLog(title = "配置档案类型", module = "档案管理->配置档案类型", businessType = OperaType.UPDATE, details = "配置档案类型", logType = 1)
    @RequiresPermissions("contents:name:edit")
    public AjaxResult updateContentsName(@RequestBody ProjectDto projectDto) {
        return service.updateContentsName(projectDto);
    }


}
