package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ss.dividendDetail.domain.DividendDetail;
import com.ruoyi.ss.dividendDetail.domain.DividendDetailQuery;
import com.ruoyi.ss.dividendDetail.domain.DividendDetailVO;
import com.ruoyi.ss.dividendDetail.service.IDividendDetailService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 分账明细Controller
 *
 * @author qzz
 * @date 2024-10-10
 */
@RestController
@RequestMapping("/system/detail")
public class DividendDetailController extends BaseController
{
    @Resource
    private IDividendDetailService rlDividendDetailService;

    /**
     * 查询分账明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(DividendDetailQuery rlDividendDetail)
    {
        startPage();
        List<DividendDetailVO> list = rlDividendDetailService.selectRlDividendDetailList(rlDividendDetail);
        return getDataTable(list);
    }

    /**
     * 导出分账明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:detail:export')")
    @Log(title = "分账明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DividendDetailQuery rlDividendDetail)
    {
        List<DividendDetailVO> list = rlDividendDetailService.selectRlDividendDetailList(rlDividendDetail);
        ExcelUtil<DividendDetailVO> util = new ExcelUtil<>(DividendDetailVO.class);
        util.exportExcel(response, list, "分账明细数据");
    }

    /**
     * 获取分账明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rlDividendDetailService.selectRlDividendDetailById(id));
    }

    /**
     * 新增分账明细
     */
    @PreAuthorize("@ss.hasPermi('system:detail:add')")
    @Log(title = "分账明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DividendDetail rlDividendDetail)
    {
        return toAjax(rlDividendDetailService.insertRlDividendDetail(rlDividendDetail));
    }

    /**
     * 修改分账明细
     */
    @PreAuthorize("@ss.hasPermi('system:detail:edit')")
    @Log(title = "分账明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DividendDetail rlDividendDetail)
    {
        return toAjax(rlDividendDetailService.updateRlDividendDetail(rlDividendDetail));
    }

    /**
     * 删除分账明细
     */
    @PreAuthorize("@ss.hasPermi('system:detail:remove')")
    @Log(title = "分账明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rlDividendDetailService.deleteRlDividendDetailByIds(ids));
    }
}
