package com.ruoyi.web.controller.post;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.post.domain.PostUser;
import com.ruoyi.post.service.IPostUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * @Author HuiANan
 * @Date 2023/1/25 20:32
 * @Exegesis:
 */
@RestController
@RequestMapping("/post/user")
public class PostUserController extends BaseController
{
    @Autowired
    private IPostUserService postUserService;

    /**
     * 查询邮贝用户信息;列表
     */
    @PreAuthorize("@ss.hasPermi('system:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(PostUser postUser)
    {
        startPage();
        List<PostUser> list = postUserService.selectPostUserList(postUser);
        return getDataTable(list);
    }

    /**
     * 导出邮贝用户信息;列表
     */
    @PreAuthorize("@ss.hasPermi('system:user:export')")
    @Log(title = "邮贝用户信息;", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PostUser postUser)
    {
        List<PostUser> list = postUserService.selectPostUserList(postUser);
        ExcelUtil<PostUser> util = new ExcelUtil<PostUser>(PostUser.class);
        util.exportExcel(response, list, "邮贝用户信息;数据");
    }

    /**
     * 获取邮贝用户信息;详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:user:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(postUserService.selectPostUserByUserId(userId));
    }

    /**
     * 新增邮贝用户信息;
     */
    @PreAuthorize("@ss.hasPermi('system:user:add')")
    @Log(title = "邮贝用户信息;", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PostUser postUser)
    {
        return toAjax(postUserService.insertPostUser(postUser));
    }

    /**
     * 修改邮贝用户信息;
     */
    @PreAuthorize("@ss.hasPermi('system:user:edit')")
    @Log(title = "邮贝用户信息;", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PostUser postUser)
    {
        return toAjax(postUserService.updatePostUser(postUser));
    }

    /**
     * 删除邮贝用户信息;
     */
    @PreAuthorize("@ss.hasPermi('system:user:remove')")
    @Log(title = "邮贝用户信息;", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(postUserService.deletePostUserByUserIds(userIds));
    }
}