package com.xinelu.manage.controller.billinfo;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.billinfo.BillInfo;
import com.xinelu.manage.dto.billinfo.BillInfoDto;
import com.xinelu.manage.service.billinfo.IBillInfoService;
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 zh
 * @date 2026-04-16
 */
@RestController
@RequestMapping("/system/billInfo")
public class BillInfoController extends BaseController {
    @Resource
    private IBillInfoService billInfoService;

    /**
     * 查询账单信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:billInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(BillInfo billInfo) {
        startPage();
        List<BillInfo> list = billInfoService.selectBillInfoList(billInfo);
        return getDataTable(list);
    }

    /**
     * 导出账单信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:billInfo:export')")
    @Log(title = "账单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BillInfo billInfo) {
        List<BillInfo> list = billInfoService.selectBillInfoList(billInfo);
        ExcelUtil<BillInfo> util = new ExcelUtil<>(BillInfo.class);
        util.exportExcel(response, list, "账单信息数据");
    }

    /**
     * 获取账单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:billInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(billInfoService.selectBillInfoById(id));
    }

    /**
     * 获取账单信息详细信息
     */
    @GetMapping(value = "/view")
    public AjaxResult view(String billCode) {
        return AjaxResult.success(billInfoService.selectBillDetails(billCode));
    }

    /**
     * 新增账单信息
     */
    @PreAuthorize("@ss.hasPermi('system:billInfo:add')")
    @Log(title = "账单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BillInfo billInfo) {
        return toAjax(billInfoService.insertBillInfo(billInfo));
    }

    /**
     * 修改账单信息
     */
    @PreAuthorize("@ss.hasPermi('system:billInfo:edit')")
    @Log(title = "账单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BillInfo billInfo) {
        return toAjax(billInfoService.updateBillInfo(billInfo));
    }

    /**
     * 删除账单信息
     */
    @PreAuthorize("@ss.hasPermi('system:billInfo:remove')")
    @Log(title = "账单信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(billInfoService.deleteBillInfoByIds(ids));
    }

    /**
     * 导出账单明细信息列表
     */
    @PostMapping("/exportDetails")
    public void exportDetails(HttpServletResponse response, BillInfo billInfo) {
        List<BillInfoDto> list = billInfoService.selectBillDetails(billInfo.getBillCode());
        ExcelUtil<BillInfoDto> util = new ExcelUtil<>(BillInfoDto.class);
        util.exportExcel(response, list, "账单信息数据");
    }
}