package com.ruoyi.web.controller.branch;

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

import com.ruoyi.system.service.ISysUserService;
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.branch.domain.TBranchMember;
import com.ruoyi.branch.service.ITBranchMemberService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支部成员管理Controller
 * 
 * @author ruoyi
 * @date 2023-06-15
 */
@RestController
@RequestMapping("/branch/member")
public class TBranchMemberController extends BaseController
{
    @Autowired
    private ITBranchMemberService tBranchMemberService;

    @Autowired
    private ISysUserService userService;

    /**
     * 查询支部成员政治生日列表
     */
    @PreAuthorize("@ss.hasPermi('branch:member:list')")
    @GetMapping("/listPoliticalBirthday")
    public AjaxResult listPoliticalBirthday(TBranchMember tBranchMember)
    {
        return AjaxResult.success(tBranchMemberService.selectPoliticalBirthdayList(tBranchMember));
    }

    /**
     * 查询支部成员管理列表
     */
    @PreAuthorize("@ss.hasPermi('branch:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBranchMember tBranchMember)
    {
        startPage();
        List<TBranchMember> list = tBranchMemberService.selectTBranchMemberList(tBranchMember);
        return getDataTable(list);
    }

    /**
     * 导出支部成员管理列表
     */
    @PreAuthorize("@ss.hasPermi('branch:member:export')")
    @Log(title = "支部成员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBranchMember tBranchMember)
    {
        List<TBranchMember> list = tBranchMemberService.selectTBranchMemberList(tBranchMember);
        ExcelUtil<TBranchMember> util = new ExcelUtil<TBranchMember>(TBranchMember.class);
        util.exportExcel(response, list, "支部成员管理数据");
    }

    /**
     * 获取支部成员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('branch:member:query')")
    @GetMapping(value = "/{memberId}")
    public AjaxResult getInfo(@PathVariable("memberId") Long memberId)
    {
        return success(tBranchMemberService.selectTBranchMemberByMemberId(memberId));
    }

    /**
     * 新增支部成员管理
     */
    @PreAuthorize("@ss.hasPermi('branch:member:add')")
    @Log(title = "支部成员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBranchMember tBranchMember)
    {
        Long userId = getUserId();
        Long deptId = userService.selectUserById(userId).getDeptId();
        tBranchMember.setDeptId(deptId);
        return toAjax(tBranchMemberService.insertTBranchMember(tBranchMember));
    }

    /**
     * 修改支部成员管理
     */
    @PreAuthorize("@ss.hasPermi('branch:member:edit')")
    @Log(title = "支部成员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBranchMember tBranchMember)
    {
        return toAjax(tBranchMemberService.updateTBranchMember(tBranchMember));
    }

    /**
     * 删除支部成员管理
     */
    @PreAuthorize("@ss.hasPermi('branch:member:remove')")
    @Log(title = "支部成员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberIds}")
    public AjaxResult remove(@PathVariable Long[] memberIds)
    {
        return toAjax(tBranchMemberService.deleteTBranchMemberByMemberIds(memberIds));
    }
}
