package com.fs.store.controller;

import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.common.utils.ParseUtils;
import com.fs.common.utils.ServletUtils;
import com.fs.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import com.fs.store.param.FsStorePaymentParam;
import com.fs.store.vo.FsStorePaymentVO;
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.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
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.domain.FsStorePayment;
import com.fs.store.service.IFsStorePaymentService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 支付明细Controller
 *
 * @author fs
 * @date 2022-06-20
 */
@RestController
@RequestMapping("/store/storePayment")
public class FsStorePaymentController extends BaseController
{
    @Autowired
    private IFsStorePaymentService fsStorePaymentService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询支付明细列表
     */
    @PreAuthorize("@ss.hasPermi('store:storePayment:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsStorePaymentParam fsStorePayment)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fsStorePayment.setBusinessType(1);
        fsStorePayment.setCompanyId(loginUser.getCompany().getCompanyId());
        startPage();
        List<FsStorePaymentVO> list = fsStorePaymentService.selectFsStorePaymentListQueryVO(fsStorePayment);
        for (FsStorePaymentVO vo : list){
            vo.setUserPhone(ParseUtils.parsePhone(vo.getUserPhone()));
        }
        return getDataTable(list);
    }

    /**
     * 导出支付明细列表
     */
    @PreAuthorize("@ss.hasPermi('store:storePayment:export')")
    @Log(title = "支付明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsStorePaymentParam fsStorePayment)
    {
        fsStorePayment.setBusinessType(1);
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fsStorePayment.setCompanyId(loginUser.getCompany().getCompanyId());
        List<FsStorePaymentVO> list = fsStorePaymentService.selectFsStorePaymentListQueryVO(fsStorePayment);
        for (FsStorePaymentVO vo : list){
            vo.setUserPhone(ParseUtils.parsePhone(vo.getUserPhone()));
        }
        ExcelUtil<FsStorePaymentVO> util = new ExcelUtil<FsStorePaymentVO>(FsStorePaymentVO.class);
        return util.exportExcel(list, "storePayment");
    }

    /**
     * 获取支付明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:storePayment:query')")
    @GetMapping(value = "/{paymentId}")
    public AjaxResult getInfo(@PathVariable("paymentId") Long paymentId)
    {
        return AjaxResult.success(fsStorePaymentService.selectFsStorePaymentById(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('store:storePayment:edit')")
    @Log(title = "支付明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStorePayment fsStorePayment)
    {
        return toAjax(fsStorePaymentService.updateFsStorePayment(fsStorePayment));
    }

    /**
     * 删除支付明细
     */
    @PreAuthorize("@ss.hasPermi('store:storePayment:remove')")
    @Log(title = "支付明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paymentIds}")
    public AjaxResult remove(@PathVariable Long[] paymentIds)
    {
        return toAjax(fsStorePaymentService.deleteFsStorePaymentByIds(paymentIds));
    }
    @GetMapping("/getStorePaymentList")
    public R getStorePaymentList(FsStorePaymentParam fsStorePayment)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fsStorePayment.setCompanyId(loginUser.getCompany().getCompanyId());
        List<FsStorePaymentVO> list = fsStorePaymentService.selectFsStorePaymentListQueryVO(fsStorePayment);
        return R.ok().put("data",list);
    }

    @GetMapping("/getMyPaymentList")
    public TableDataInfo getMyPaymentList(FsStorePaymentParam fsStorePayment)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fsStorePayment.setCompanyId(loginUser.getCompany().getCompanyId());
        fsStorePayment.setCompanyUserId(loginUser.getUser().getUserId());
        startPage();
        fsStorePayment.setStatus(1);
        List<FsStorePaymentVO> list = fsStorePaymentService.selectFsMyStorePaymentListQueryVO(fsStorePayment);
        return getDataTable(list);
    }
}
