package com.ruoyi.web.controller.member;


import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.member.MemberInfo;
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.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.service.IMemberInfoService;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 委员信息Controller
 *
 * @author boman
 * @date 2024-03-07
 */
@RestController
@RequestMapping("/member/info")
public class MemberInfoController extends BaseController {
    @Autowired
    private IMemberInfoService memberInfoService;

    /**
     * 查询委员信息列表
     */
    @PreAuthorize("@ss.hasPermi('member:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberInfo memberInfo) {
        startPage();
        List<MemberInfo> list = memberInfoService.selectMemberInfoList(memberInfo);
        return getDataTable(list);
    }

    /**
     * 获取委员菜单下拉树列表
     */
    @GetMapping("/treeSelect")
    public AjaxResult treeSelect(MemberInfo memberInfo) {
        List<MemberInfo> list = memberInfoService.selectMemberInfoList(memberInfo);
        return success(memberInfoService.buildMemberInfoTreeSelect(list));
    }

    /**
     * 查询委员信息列表不分页
     */
    @PreAuthorize("@ss.hasPermi('member:info:listNoPage')")
    @GetMapping("/listNoPage")
    public TableDataInfo listNoPage(MemberInfo memberInfo) {
        List<MemberInfo> list = memberInfoService.selectMemberInfoList(memberInfo);
        return getDataTable(list);
    }

    /**
     * 导出委员信息列表
     */
    @PreAuthorize("@ss.hasPermi('member:info:export')")
    @Log(title = "委员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberInfo memberInfo) {
        List<MemberInfo> list = memberInfoService.selectMemberInfoList(memberInfo);
        ExcelUtil<MemberInfo> util = new ExcelUtil<MemberInfo>(MemberInfo.class);
        util.exportExcel(response, list, "委员信息数据");
    }

    /**
     * 获取委员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:info:query')")
    @GetMapping(value = "/{memberId}")
    public AjaxResult getInfo(@PathVariable("memberId") Long memberId) {
        return success(memberInfoService.selectMemberInfoByMemberId(memberId));
    }

    /**
     * 获取委员履职信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:info:queryJop')")
    @PostMapping(value = "/getInfoJop")
    public AjaxResult getInfoJop(@RequestBody MemberInfo memberInfo) {
        return success(memberInfoService.getInfoJop(memberInfo));
    }

    /**
     * 获取委员履职年度报告
     */
    @PreAuthorize("@ss.hasPermi('member:info:MemberReport')")
    @PostMapping(value = "/getMemberReport")
    public AjaxResult getMemberReport(@RequestBody MemberInfo memberInfo) {
        return success(memberInfoService.getMemberReport(memberInfo));
    }

    /**
     * 新增委员信息
     */
    @PreAuthorize("@ss.hasPermi('member:info:add')")
    @Log(title = "委员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberInfo memberInfo) {
        return toAjax(memberInfoService.insertMemberInfo(memberInfo));
    }

    /**
     * 修改委员信息
     */
    @PreAuthorize("@ss.hasPermi('member:info:edit')")
    @Log(title = "委员信息", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody MemberInfo memberInfo) {
        return toAjax(memberInfoService.updateMemberInfo(memberInfo));
    }

    /**
     * 删除委员信息
     */
    @PreAuthorize("@ss.hasPermi('member:info:remove')")
    @Log(title = "委员信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{memberIds}")
    public AjaxResult remove(@PathVariable Long[] memberIds) {
        return toAjax(memberInfoService.deleteMemberInfoByMemberIds(memberIds));
    }
}
