package com.ruoyi.app.user;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserMargin;
import com.ruoyi.system.service.IUserMarginService;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * usermarginController
 * 
 * @author ruoyi
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/system/marginlist")
public class UserMarginController extends BaseController
{
    @Autowired
    private IUserMarginService userMarginService;

    /**
     * 查询usermargin列表
     */
    @PreAuthorize("@ss.hasPermi('system:marginlist:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserMargin userMargin)
    {
        startPage();
        List<UserMargin> list = userMarginService.selectUserMarginList(userMargin);
        return getDataTable(list);
    }

    /**
     * 导出usermargin列表
     */
    @PreAuthorize("@ss.hasPermi('system:marginlist:export')")
    @Log(title = "usermargin", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserMargin userMargin)
    {
        List<UserMargin> list = userMarginService.selectUserMarginList(userMargin);
        ExcelUtil<UserMargin> util = new ExcelUtil<UserMargin>(UserMargin.class);
        util.exportExcel(response, list, MessageUtils.message("no.export.excel.usermargin"));
    }

    /**
     * 获取usermargin详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:marginlist:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userMarginService.selectUserMarginById(id));
    }

    /**
     * 新增usermargin
     */
    @PreAuthorize("@ss.hasPermi('system:marginlist:add')")
    @Log(title = "usermargin", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserMargin userMargin)
    {
        return toAjax(userMarginService.insertUserMargin(userMargin));
    }

    /**
     * 修改usermargin
     */
    @PreAuthorize("@ss.hasPermi('system:marginlist:edit')")
    @Log(title = "usermargin", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserMargin userMargin)
    {
        return toAjax(userMarginService.updateUserMargin(userMargin));
    }

    /**
     * 删除usermargin
     */
    @PreAuthorize("@ss.hasPermi('system:marginlist:remove')")
    @Log(title = "usermargin", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userMarginService.deleteUserMarginByIds(ids));
    }
}
