package com.hzy.project.business.income.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hzy.framework.aspectj.lang.annotation.Log;
import com.hzy.framework.aspectj.lang.enums.BusinessType;
import com.hzy.project.business.income.domain.Income;
import com.hzy.project.business.income.service.IIncomeService;
import com.hzy.framework.web.controller.BaseController;
import com.hzy.framework.web.domain.AjaxResult;
import com.hzy.common.utils.poi.ExcelUtil;
import com.hzy.framework.web.page.TableDataInfo;

/**
 * 收入Controller
 * 
 * @author ruoyi
 * @date 2026-01-02
 */
@Controller
@RequestMapping("/business/income")
public class IncomeController extends BaseController
{
    private String prefix = "business/income";

    @Autowired
    private IIncomeService incomeService;

    @RequiresPermissions("business:income:view")
    @GetMapping()
    public String income()
    {
        return prefix + "/income";
    }

    /**
     * 查询收入列表
     */
    @RequiresPermissions("business:income:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Income income)
    {
        startPage();
        List<Income> list = incomeService.selectIncomeList(income);
        return getDataTable(list);
    }

    /**
     * 导出收入列表
     */
    @RequiresPermissions("business:income:export")
    @Log(title = "收入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Income income)
    {
        List<Income> list = incomeService.selectIncomeList(income);
        ExcelUtil<Income> util = new ExcelUtil<Income>(Income.class);
        return util.exportExcel(list, "收入数据");
    }

    /**
     * 新增收入
     */
    @RequiresPermissions("business:income:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存收入
     */
    @RequiresPermissions("business:income:add")
    @Log(title = "收入", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Income income)
    {
        return toAjax(incomeService.insertIncome(income));
    }

    /**
     * 修改收入
     */
    @RequiresPermissions("business:income:edit")
    @GetMapping("/edit/{incomeId}")
    public String edit(@PathVariable("incomeId") Long incomeId, ModelMap mmap)
    {
        Income income = incomeService.selectIncomeByIncomeId(incomeId);
        mmap.put("income", income);
        return prefix + "/edit";
    }

    /**
     * 修改保存收入
     */
    @RequiresPermissions("business:income:edit")
    @Log(title = "收入", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Income income)
    {
        return toAjax(incomeService.updateIncome(income));
    }

    /**
     * 删除收入
     */
    @RequiresPermissions("business:income:remove")
    @Log(title = "收入", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(incomeService.deleteIncomeByIncomeIds(ids));
    }
}
