package com.yanzhu.manage.controller;

import com.yanzhu.common.core.utils.poi.ExcelUtil;
import com.yanzhu.common.core.web.controller.BaseController;
import com.yanzhu.common.core.web.domain.AjaxResult;
import com.yanzhu.common.core.web.page.TableDataInfo;
import com.yanzhu.common.log.annotation.Log;
import com.yanzhu.common.log.enums.BusinessType;
import com.yanzhu.common.security.annotation.RequiresPermissions;
import com.yanzhu.manage.domain.BusExamUser;
import com.yanzhu.manage.service.IBusExamUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户试卷Controller
 * 
 * @author JiangYuQi
 * @date 2024-08-25
 */
@RestController
@RequestMapping("/busExamUser")
public class BusExamUserController extends BaseController
{
    @Autowired
    private IBusExamUserService busExamUserService;

    /**
     * 查询用户试卷列表
     */
    @RequiresPermissions("manage:busExamUser:list")
    @GetMapping("/list")
    public TableDataInfo list(BusExamUser busExamUser)
    {
        startPage();
        List<BusExamUser> list = busExamUserService.selectBusExamUserList(busExamUser);
        return getDataTable(list);
    }

    /**
     * 导出用户试卷列表
     */
    @RequiresPermissions("manage:busExamUser:export")
    @Log(title = "用户试卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusExamUser busExamUser)
    {
        List<BusExamUser> list = busExamUserService.selectBusExamUserList(busExamUser);
        ExcelUtil<BusExamUser> util = new ExcelUtil<BusExamUser>(BusExamUser.class);
        util.exportExcel(response, list, "用户试卷数据");
    }

    /**
     * 获取用户试卷详细信息
     */
    @RequiresPermissions("manage:busExamUser:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busExamUserService.selectBusExamUserById(id));
    }

    /**
     * 修改用户试卷
     */
    @RequiresPermissions("manage:busExamUser:edit")
    @Log(title = "用户试卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusExamUser busExamUser)
    {
        return toAjax(busExamUserService.updateBusExamUser(busExamUser));
    }

    /**
     * 删除用户试卷
     */
    @RequiresPermissions("manage:busExamUser:remove")
    @Log(title = "用户试卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busExamUserService.deleteBusExamUserByIds(ids));
    }

    /**
     * 新增用户试卷
     * @RequiresPermissions("manage:busExamUser:add")
     */
    @Log(title = "新增试卷考题", businessType = BusinessType.INSERT)
    @PostMapping("/push")
    public AjaxResult pushBusExamUser()
    {
        return success(busExamUserService.insertBusExamUser());
    }
}
