package com.fs.course.controller;

import java.util.List;

import com.fs.course.param.FsUserVipOrderParam;
import com.fs.course.vo.FsUserCourseOrderListPVO;
import com.fs.course.vo.FsUserVipOrderListPVO;
import com.fs.his.utils.PhoneUtil;
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.course.domain.FsUserVipOrder;
import com.fs.course.service.IFsUserVipOrderService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 购买会员订单Controller
 *
 * @author fs
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/course/userVipOrder")
public class FsUserVipOrderController extends BaseController
{
    @Autowired
    private IFsUserVipOrderService fsUserVipOrderService;

    /**
     * 查询购买会员订单列表
     */
    @PreAuthorize("@ss.hasPermi('course:userVipOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserVipOrderParam param)
    {
        startPage();
        if (param.getPhone()!=null){
            param.setPhone(PhoneUtil.encryptPhone(param.getPhone()));
        }
        List<FsUserVipOrderListPVO> list = fsUserVipOrderService.selectFsUserVipOrderListPVO(param);
        for (FsUserVipOrderListPVO vo : list) {
            if (vo.getPhone() != null) {
                if (vo.getPhone().length()==11){
                    vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
                }else if(vo.getPhone().length()>11){
                    vo.setPhone(PhoneUtil.decryptPhone(vo.getPhone()).replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
                }
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出购买会员订单列表
     */
    @PreAuthorize("@ss.hasPermi('course:userVipOrder:export')")
    @Log(title = "购买会员订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserVipOrder fsUserVipOrder)
    {
        List<FsUserVipOrder> list = fsUserVipOrderService.selectFsUserVipOrderList(fsUserVipOrder);
        ExcelUtil<FsUserVipOrder> util = new ExcelUtil<FsUserVipOrder>(FsUserVipOrder.class);
        return util.exportExcel(list, "购买会员订单数据");
    }

    /**
     * 获取购买会员订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:userVipOrder:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return AjaxResult.success(fsUserVipOrderService.selectFsUserVipOrderByOrderId(orderId));
    }

    /**
     * 新增购买会员订单
     */
    @PreAuthorize("@ss.hasPermi('course:userVipOrder:add')")
    @Log(title = "购买会员订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserVipOrder fsUserVipOrder)
    {
        return toAjax(fsUserVipOrderService.insertFsUserVipOrder(fsUserVipOrder));
    }

    /**
     * 修改购买会员订单
     */
    @PreAuthorize("@ss.hasPermi('course:userVipOrder:edit')")
    @Log(title = "购买会员订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserVipOrder fsUserVipOrder)
    {
        return toAjax(fsUserVipOrderService.updateFsUserVipOrder(fsUserVipOrder));
    }

    /**
     * 删除购买会员订单
     */
    @PreAuthorize("@ss.hasPermi('course:userVipOrder:remove')")
    @Log(title = "购买会员订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(fsUserVipOrderService.deleteFsUserVipOrderByOrderIds(orderIds));
    }
}
