package com.fs.store.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.his.domain.FsStoreBill;
import com.fs.his.param.FsStoreBillParam;
import com.fs.his.service.IFsStoreBillService;
import com.fs.his.vo.FsStoreBillVO;
import com.fs.store.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店铺帐单记录Controller
 *
 * @author fs
 * @date 2023-06-25
 */
@RestController
@RequestMapping("/store/storeBill")
public class FsStoreBillController extends BaseController
{
    @Autowired
    private IFsStoreBillService fsStoreBillService;

    /**
     * 查询店铺帐单记录列表
     */

    @GetMapping("/list")
    public TableDataInfo list(FsStoreBillParam fsStoreBill)
    {
        fsStoreBill.setStoreId(UserUtil.getLoginUserStoreID());
        startPage();
        List<FsStoreBillVO> list = fsStoreBillService.selectFsStoreBillListVO(fsStoreBill);
        return getDataTable(list);
    }

    /**
     * 导出店铺帐单记录列表
     */

    @Log(title = "店铺帐单记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsStoreBill fsStoreBill)
    {
        fsStoreBill.setStoreId(UserUtil.getLoginUserStoreID());
        List<FsStoreBill> list = fsStoreBillService.selectFsStoreBillList(fsStoreBill);
        ExcelUtil<FsStoreBill> util = new ExcelUtil<FsStoreBill>(FsStoreBill.class);
        return util.exportExcel(list, "店铺帐单记录数据");
    }

    /**
     * 获取店铺帐单记录详细信息
     */

    @GetMapping(value = "/{billId}")
    public AjaxResult getInfo(@PathVariable("billId") Long billId)
    {
        return AjaxResult.success(fsStoreBillService.selectFsStoreBillByBillId(billId));
    }

    /**
     * 新增店铺帐单记录
     */

    @Log(title = "店铺帐单记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsStoreBill fsStoreBill)
    {
        fsStoreBill.setStoreId(UserUtil.getLoginUserStoreID());
        return toAjax(fsStoreBillService.insertFsStoreBill(fsStoreBill));
    }

    /**
     * 修改店铺帐单记录
     */

    @Log(title = "店铺帐单记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStoreBill fsStoreBill)
    {
        fsStoreBill.setStoreId(UserUtil.getLoginUserStoreID());
        return toAjax(fsStoreBillService.updateFsStoreBill(fsStoreBill));
    }

    /**
     * 删除店铺帐单记录
     */

    @Log(title = "店铺帐单记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{billIds}")
    public AjaxResult remove(@PathVariable Long[] billIds)
    {
        return toAjax(fsStoreBillService.deleteFsStoreBillByBillIds(billIds));
    }
}
