package com.fs.course.controller;

import java.util.List;

import com.fs.course.param.FsUserCourseOrderParam;
import com.fs.course.vo.FsUserCourseOrderListPVO;
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.FsUserCourseOrder;
import com.fs.course.service.IFsUserCourseOrderService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

import static com.fs.his.utils.PhoneUtil.decryptAutoPhoneMk;

/**
 * 课程订单信息Controller
 *
 * @author fs
 * @date 2024-05-21
 */
@RestController
@RequestMapping("/course/userCourseOrder")
public class FsUserCourseOrderController extends BaseController
{
    @Autowired
    private IFsUserCourseOrderService fsUserCourseOrderService;

    /**
     * 查询课程订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserCourseOrderParam param)
    {
        startPage();
        List<FsUserCourseOrderListPVO> list = fsUserCourseOrderService.selectFsUserCourseOrderListPVO(param);
        for (FsUserCourseOrderListPVO vo : list) {
            vo.setUserName(decryptAutoPhoneMk(vo.getUserName()));
        }
        return getDataTable(list);
    }

    /**
     * 导出课程订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseOrder:export')")
    @Log(title = "课程订单信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserCourseOrder fsUserCourseOrder)
    {
        List<FsUserCourseOrder> list = fsUserCourseOrderService.selectFsUserCourseOrderList(fsUserCourseOrder);
        ExcelUtil<FsUserCourseOrder> util = new ExcelUtil<FsUserCourseOrder>(FsUserCourseOrder.class);
        return util.exportExcel(list, "课程订单信息数据");
    }

    /**
     * 获取课程订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseOrder:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return AjaxResult.success(fsUserCourseOrderService.selectFsUserCourseOrderVOByOrderId(orderId));
    }

    /**
     * 新增课程订单信息
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseOrder:add')")
    @Log(title = "课程订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserCourseOrder fsUserCourseOrder)
    {
        return toAjax(fsUserCourseOrderService.insertFsUserCourseOrder(fsUserCourseOrder));
    }

    /**
     * 修改课程订单信息
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseOrder:edit')")
    @Log(title = "课程订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserCourseOrder fsUserCourseOrder)
    {
        return toAjax(fsUserCourseOrderService.updateFsUserCourseOrder(fsUserCourseOrder));
    }

    /**
     * 删除课程订单信息
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseOrder:remove')")
    @Log(title = "课程订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(fsUserCourseOrderService.deleteFsUserCourseOrderByOrderIds(orderIds));
    }
}
