package com.zbf.web.controller.system;

import cn.hutool.json.JSONArray;
import com.zbf.common.annotation.Log;
import com.zbf.common.core.controller.BaseController;
import com.zbf.common.core.domain.AjaxResult;
import com.zbf.common.enums.BusinessType;
import com.zbf.common.utils.poi.ExcelUtil;
import com.zbf.generator.util.ColumnUtils;
import com.zbf.system.domain.TBaseFinancialClass;
import com.zbf.system.domain.TBasePallet;
import com.zbf.system.service.ITBaseFinancialClassService;
import liquibase.pro.packaged.S;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 财务分类Controller
 *
 * @author sunits
 * @date 2024-06-28
 */
@RestController
@RequestMapping("/system/financialClass")
public class TBaseFinancialClassController extends BaseController {
    @Autowired
    private ITBaseFinancialClassService tBaseFinancialClassService;

    /**
     * 查询财务分类列表
     */
    //@PreAuthorize("@ss.hasPermi('system:financialClass:list')")
    @GetMapping("/list")
    public AjaxResult list(TBaseFinancialClass tBaseFinancialClass) {
        Map<String, Object> map = new HashMap();
        JSONArray columns = ColumnUtils.getColumnsJson(TBaseFinancialClass.class);
        List<TBaseFinancialClass> list = tBaseFinancialClassService.selectTBaseFinancialClassList(tBaseFinancialClass);
        map.put("list",list);
        map.put("columns",columns);
        return success(map);
    }

    /**
     * 导出财务分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:financialClass:export')")
    @Log(title = "财务分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBaseFinancialClass tBaseFinancialClass) {
        List<TBaseFinancialClass> list = tBaseFinancialClassService.selectTBaseFinancialClassList(tBaseFinancialClass);
        ExcelUtil<TBaseFinancialClass> util = new ExcelUtil<TBaseFinancialClass>(TBaseFinancialClass.class);
        util.exportExcel(response, list, "财务分类数据");
    }

    /**
     * 获取财务分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:financialClass:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tBaseFinancialClassService.selectTBaseFinancialClassById(id));
    }

    /**
     * 新增财务分类
     */
    @PreAuthorize("@ss.hasPermi('system:financialClass:add')")
    @Log(title = "财务分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBaseFinancialClass tBaseFinancialClass) {
        return toAjax(tBaseFinancialClassService.insertTBaseFinancialClass(tBaseFinancialClass));
    }

    /**
     * 修改财务分类
     */
    @PreAuthorize("@ss.hasPermi('system:financialClass:edit')")
    @Log(title = "财务分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBaseFinancialClass tBaseFinancialClass) {
        return toAjax(tBaseFinancialClassService.updateTBaseFinancialClass(tBaseFinancialClass));
    }

    /**
     * 删除财务分类
     */
    @PreAuthorize("@ss.hasPermi('system:financialClass:remove')")
    @Log(title = "财务分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tBaseFinancialClassService.deleteTBaseFinancialClassByIds(ids));
    }

    /**
     * 启用
     */
    @PreAuthorize("@ss.hasPermi('system:financialClass:remove')")
    @Log(title = "财务分类", businessType = BusinessType.UPDATE)
    @DeleteMapping("/disable/{ids}")
    public AjaxResult disable(@PathVariable Long[] ids) {
        return toAjax(tBaseFinancialClassService.disabledTBaseFinancialClassByIds(ids));
    }

    /**
     * 禁用
     */
    @PreAuthorize("@ss.hasPermi('system:financialClass:edit')")
    @Log(title = "财务分类", businessType = BusinessType.UPDATE)
    @DeleteMapping("/enable/{ids}")
    public AjaxResult enable(@PathVariable Long[] ids) {
        return toAjax(tBaseFinancialClassService.enableTBaseFinancialClassByIds(ids));
    }

    /**
     * 修改状态
     */
    @PreAuthorize("@ss.hasPermi('system:financialClass:edit')")
    @Log(title = "财务分类", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody TBaseFinancialClass tBaseFinancialClass) {
        return toAjax(tBaseFinancialClassService.updateStatus(tBaseFinancialClass));
    }

}

