package com.fs.company.controller.store;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.framework.security.LoginUser;
import com.fs.framework.security.SecurityUtils;
import com.fs.his.domain.FsStoreOrderBillLog;
import com.fs.his.service.IFsStoreOrderBillLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单开票记录Controller
 *
 * @author fs
 * @date 2025-01-07
 */
@RestController
@RequestMapping("/bill/billLog")
public class FsStoreOrderBillLogController extends BaseController
{
    @Autowired
    private IFsStoreOrderBillLogService fsStoreOrderBillLogService;

    /**
     * 查询订单开票记录列表
     */
    @PreAuthorize("@ss.hasPermi('bill:billLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsStoreOrderBillLog fsStoreOrderBillLog)
    {
        startPage();
        LoginUser loginUser = SecurityUtils.getLoginUser();
        fsStoreOrderBillLog.setCompanyId(loginUser.getCompany().getCompanyId());
        List<FsStoreOrderBillLog> list = fsStoreOrderBillLogService.selectFsStoreOrderBillLogList(fsStoreOrderBillLog);
        return getDataTable(list);
    }

    /**
     * 导出订单开票记录列表
     */
    @PreAuthorize("@ss.hasPermi('bill:billLog:export')")
    @Log(title = "订单开票记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsStoreOrderBillLog fsStoreOrderBillLog)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        fsStoreOrderBillLog.setCompanyId(loginUser.getCompany().getCompanyId());
        List<FsStoreOrderBillLog> list = fsStoreOrderBillLogService.selectFsStoreOrderBillLogList(fsStoreOrderBillLog);
        ExcelUtil<FsStoreOrderBillLog> util = new ExcelUtil<>(FsStoreOrderBillLog.class);
        return util.exportExcel(list, "订单开票记录数据");
    }

    /**
     * 获取订单开票记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('bill:billLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsStoreOrderBillLogService.selectFsStoreOrderBillLogById(id));
    }

    /**
     * 新增订单开票记录
     */
    @PreAuthorize("@ss.hasPermi('bill:billLog:add')")
    @Log(title = "订单开票记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsStoreOrderBillLog fsStoreOrderBillLog)
    {
        return toAjax(fsStoreOrderBillLogService.insertFsStoreOrderBillLog(fsStoreOrderBillLog));
    }

    /**
     * 修改订单开票记录
     */
    @PreAuthorize("@ss.hasPermi('bill:billLog:edit')")
    @Log(title = "订单开票记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStoreOrderBillLog fsStoreOrderBillLog)
    {
        return toAjax(fsStoreOrderBillLogService.updateFsStoreOrderBillLog(fsStoreOrderBillLog));
    }

    /**
     * 删除订单开票记录
     */
    @PreAuthorize("@ss.hasPermi('bill:billLog:remove')")
    @Log(title = "订单开票记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsStoreOrderBillLogService.deleteFsStoreOrderBillLogByIds(ids));
    }
}
