package com.flossom.system.controller;

import javax.servlet.http.HttpServletResponse;

import com.flossom.common.core.domain.entity.WxUserMember;
import com.flossom.common.core.domain.req.WxUserMemberVm;
import com.flossom.common.core.utils.poi.ExcelUtil;
import com.flossom.common.core.web.controller.BaseController;
import com.flossom.common.core.web.domain.AjaxResult;
import com.flossom.common.core.web.page.TableDataInfo;
import com.flossom.common.log.annotation.Log;
import com.flossom.common.log.enums.BusinessType;
import com.flossom.common.security.annotation.RequiresPermissions;
import com.flossom.system.service.IWxUserMemberService;
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 java.util.List;

/**
 * 用户Controller
 *
 * @author flossom
 * @date 2023-12-08
 */
@RestController
@RequestMapping("/member")
public class WxUserMemberController extends BaseController {
    @Autowired
    private IWxUserMemberService wxUserMemberService;

    /**
     * 查询用户列表
     */
    @RequiresPermissions("system:member:list")
    @GetMapping("/list")
    public TableDataInfo list(WxUserMemberVm wxUserMemberVm) {
        startPage();
        List<WxUserMember> list = wxUserMemberService.selectWxUserMemberList(wxUserMemberVm);
        return getDataTable(list);
    }

    /**
     * 导出用户列表
     */
    @RequiresPermissions("system:member:export")
    @Log(title = "用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxUserMember wxUserMember) {
        List<WxUserMember> list = wxUserMemberService.selectWxUserMemberList(wxUserMember);
        ExcelUtil<WxUserMember> util = new ExcelUtil<WxUserMember>(WxUserMember.class);
        util.exportExcel(response, list, "用户数据");
    }

    /**
     * 获取用户详细信息
     */
    @RequiresPermissions("system:member:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wxUserMemberService.selectWxUserMemberById(id));
    }

    /**
     * 新增用户
     */
    @RequiresPermissions("system:member:add")
    @Log(title = "用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxUserMember wxUserMember) {
        return toAjax(wxUserMemberService.insertWxUserMember(wxUserMember));
    }

    /**
     * 修改用户
     */
    @RequiresPermissions("system:member:edit")
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxUserMember wxUserMember) {
        return toAjax(wxUserMemberService.updateWxUserMember(wxUserMember));
    }

    /**
     * 删除用户
     */
    @RequiresPermissions("system:member:remove")
    @Log(title = "用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wxUserMemberService.deleteWxUserMemberByIds(ids));
    }
}
