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.FsStorePayment;
import com.fs.his.param.FsStorePaymentParam;
import com.fs.his.service.IFsStorePaymentService;
import com.fs.his.vo.FsStorePaymentExcelVO;
import com.fs.his.vo.FsStorePaymentVO;
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 2023-08-21
 */
@RestController
@RequestMapping("/store/storePayment")
public class FsStorePaymentController extends BaseController
{
    @Autowired
    private IFsStorePaymentService fsStorePaymentService;

    /**
     * 查询支付明细列表
     */
    @PreAuthorize("@ss.hasPermi('store:storePayment:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsStorePaymentParam fsStorePayment)
    {
        startPage();
        LoginUser loginUser = SecurityUtils.getLoginUser();
        fsStorePayment.setCompanyId(loginUser.getCompany().getCompanyId());
        fsStorePayment.setCompanyUserId(loginUser.getUser().getUserId());
        List<FsStorePaymentVO> list = fsStorePaymentService.selectFsStorePaymentListVO(fsStorePayment);
        return getDataTable(list);
    }

    /**
     * 导出支付明细列表
     */
    @PreAuthorize("@ss.hasPermi('store:storePayment:export')")
    @Log(title = "支付明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsStorePaymentParam fsStorePayment)
    {    LoginUser loginUser = SecurityUtils.getLoginUser();
        logger.info("tc>\n【导出支付明细】："+ loginUser.getUser().getUserId());
        Long count =fsStorePaymentService.selectFsStorePaymentExcelVOCount(fsStorePayment);
        if (count>30000){
            return AjaxResult.error("导出数据不可超过3w条");
        }
        List<FsStorePaymentExcelVO> list = fsStorePaymentService.selectFsStorePaymentExcelVO(fsStorePayment);
        ExcelUtil<FsStorePaymentExcelVO> util = new ExcelUtil<FsStorePaymentExcelVO>(FsStorePaymentExcelVO.class);
        return util.exportExcel(list, "支付明细数据");
    }

    /**
     * 获取支付明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:storePayment:query')")
    @GetMapping(value = "/{paymentId}")
    public AjaxResult getInfo(@PathVariable("paymentId") Long paymentId)
    {
        return AjaxResult.success(fsStorePaymentService.selectFsStorePaymentByPaymentIdVO(paymentId));
    }

    /**
     * 新增支付明细
     */
    @PreAuthorize("@ss.hasPermi('store:storePayment:add')")
    @Log(title = "支付明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsStorePayment fsStorePayment)
    {
        return toAjax(fsStorePaymentService.insertFsStorePayment(fsStorePayment));
    }

    /**
     * 修改支付明细
     */
    @PreAuthorize("@ss.hasPermi('his:storePayment:edit')")
    @Log(title = "支付明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStorePayment fsStorePayment)
    {
        return toAjax(fsStorePaymentService.updateFsStorePayment(fsStorePayment));
    }

    /**
     * 删除支付明细
     */
    @PreAuthorize("@ss.hasPermi('his:storePayment:remove')")
    @Log(title = "支付明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paymentIds}")
    public AjaxResult remove(@PathVariable Long[] paymentIds)
    {
        return toAjax(fsStorePaymentService.deleteFsStorePaymentByPaymentIds(paymentIds));
    }
}
