package org.springblade.system.controller;

import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
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.R;
import org.springblade.common.core.domain.entity.SysEncryType;
import org.springblade.common.core.page.TableDataInfo;
import org.springblade.common.enums.OperaType;
import org.springblade.common.utils.sql.SqlUtil;
import org.springblade.system.service.ISysEncryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：liang.chao
 * @Date：2025/9/10 - 10:14
 * 档案加密类型管理
 */

@RestController
@RequestMapping("/system/encry/type")
public class SysEncryTypeController extends BaseController {

    @Resource
    private ISysEncryTypeService encryTypeService;

    @PostMapping("/list")
    @SysLog(title = "数据加密类型列表", module = "数据档案移交->数据加密类型管理", businessType = OperaType.QUERY, details = "数据加密类型列表", logType = 1)
    @RequiresPermissions("encry:type:list")
    public TableDataInfo list(@RequestBody SysEncryType dto) {
		// 直接使用 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<SysEncryType> list = encryTypeService.selectSysEncryTypeList(dto);
        return getDataTable(list);
    }
    @PostMapping("addEncryType")
    @SysLog(title = "新增数据加密类型", module = "数据档案移交->数据加密类型管理", businessType = OperaType.INSERT, details = "新增数据加密类型", logType = 1)
    @RequiresPermissions("encry:type:add")
    public R add(@RequestBody @Validated SysEncryType sysEncryType) {
        return encryTypeService.add(sysEncryType);
    }


    @PostMapping("editEncryType")
    @SysLog(title = "修改数据加密类型", module = "数据档案移交->数据加密类型管理", businessType = OperaType.UPDATE, details = "修改数据加密类型", logType = 1)
    @RequiresPermissions("encry:type:edit")
    public R edit(@RequestBody @Validated SysEncryType sysEncryType) {
        return encryTypeService.edit(sysEncryType);
    }

    @PostMapping("delEncryType")
    @SysLog(title = "删除数据加密类型", module = "数据档案移交->数据加密类型管理", businessType = OperaType.DELETE, details = "删除数据加密类型", logType = 1)
    @RequiresPermissions("encry:type:del")
    public R del(@RequestBody SysEncryType sysEncryType) {
        Integer delNum = encryTypeService.del(sysEncryType);
        if (delNum > 0) {
            return R.ok();
        } else {
            return R.fail("删除失败");
        }
    }





    // 新增文件加密类型
    @PostMapping("/listFile")
    @SysLog(title = "档案文件加密类型列表", module = "数据档案移交->档案加密类型管理", businessType = OperaType.QUERY, details = "档案加密类型列表", logType = 1)
    @RequiresPermissions("encry:type:list")
    public TableDataInfo listFile(@RequestBody SysEncryType dto) {
		// 直接使用 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<SysEncryType> list = encryTypeService.selectSysEncryTypeListFile(dto);
        return getDataTable(list);
    }
    @PostMapping("addEncryTypeFile")
    @SysLog(title = "新增档案文件加密类型", module = "数据档案移交->档案加密类型管理", businessType = OperaType.INSERT, details = "新增档案加密类型", logType = 1)
    @RequiresPermissions("encry:type:add")
    public R addEncryTypeFile(@RequestBody @Validated SysEncryType sysEncryType) {
        return encryTypeService.addFile(sysEncryType);
    }


    @PostMapping("editEncryTypeFile")
    @SysLog(title = "修改档案文件加密类型", module = "数据档案移交->档案加密类型管理", businessType = OperaType.UPDATE, details = "修改档案加密类型", logType = 1)
    @RequiresPermissions("encry:type:edit")
    public R editEncryTypeFile(@RequestBody @Validated SysEncryType sysEncryType) {
        return encryTypeService.editFile(sysEncryType);
    }

    @PostMapping("delEncryTypeFile")
    @SysLog(title = "删除档案文件加密类型", module = "数据档案移交->档案加密类型管理", businessType = OperaType.DELETE, details = "删除档案加密类型", logType = 1)
    @RequiresPermissions("encry:type:del")
    public R delEncryTypeFile(@RequestBody SysEncryType sysEncryType) {
        Integer delNum = encryTypeService.delFile(sysEncryType);
        if (delNum > 0) {
            return R.ok();
        } else {
            return R.fail("删除失败");
        }
    }

}
