package com.fs.store.controller;

import java.util.List;

import com.fs.common.utils.ParseUtils;
import com.fs.store.param.FsUserBillParam;
import com.fs.store.vo.FsUserBillVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.store.service.IFsUserBillService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 用户账单Controller
 *
 * @author fs
 * @date 2022-04-30
 */
@RestController
@RequestMapping("/store/userBill")
public class FsUserBillController extends BaseController
{
    @Autowired
    private IFsUserBillService fsUserBillService;

    /**
     * 查询用户账单列表
     */
    @PreAuthorize("@ss.hasPermi('store:userBill:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserBillParam fsUserBill)
    {
        startPage();
        List<FsUserBillVO> list = fsUserBillService.selectFsUserBillListVO(fsUserBill);
        for (FsUserBillVO vo : list){
            vo.setPhone(ParseUtils.parsePhone(vo.getPhone()));
        }
        return getDataTable(list);
    }

    /**
     * 导出用户账单列表
     */
    @PreAuthorize("@ss.hasPermi('store:userBill:export')")
    @Log(title = "用户账单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserBillParam fsUserBill)
    {
        List<FsUserBillVO> list = fsUserBillService.selectFsUserBillListVO(fsUserBill);
        for (FsUserBillVO vo : list){
            vo.setPhone(ParseUtils.parsePhone(vo.getPhone()));
        }
        ExcelUtil<FsUserBillVO> util = new ExcelUtil<FsUserBillVO>(FsUserBillVO.class);
        return util.exportExcel(list, "用户帐单");
    }

    /**
     * 获取用户账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:userBill:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsUserBillService.selectFsUserBillById(id));
    }


}
