package com.huijy.web.controller.management;

import java.util.List;
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.huijy.common.annotation.Log;
import com.huijy.common.core.controller.BaseController;
import com.huijy.common.core.domain.AjaxResult;
import com.huijy.common.enums.BusinessType;
import com.huijy.management.domain.MemberHelp;
import com.huijy.management.service.IMemberHelpService;
import com.huijy.common.utils.poi.ExcelUtil;
import com.huijy.common.core.page.TableDataInfo;

/**
 * 求助记录Controller
 *
 * @author luobo
 * @date 2021-09-12
 */
@RestController
@RequestMapping("/management/help")
public class MemberHelpController extends BaseController
{
    @Autowired
    private IMemberHelpService memberHelpService;

    /**
     * 查询求助记录列表
     */
    @PreAuthorize("@ss.hasPermi('management:help:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberHelp memberHelp)
    {
        startPage();
        List<MemberHelp> list = memberHelpService.selectMemberHelpList(memberHelp);
        return getDataTable(list);
    }

    /**
     * 导出求助记录列表
     */
    @PreAuthorize("@ss.hasPermi('management:help:export')")
    @Log(title = "求助记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MemberHelp memberHelp)
    {
        List<MemberHelp> list = memberHelpService.selectMemberHelpList(memberHelp);
        ExcelUtil<MemberHelp> util = new ExcelUtil<MemberHelp>(MemberHelp.class);
        return util.exportExcel(list, "求助记录数据");
    }

    /**
     * 获取求助记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:help:query')")
    @GetMapping(value = "/{memberHelpId}")
    public AjaxResult getInfo(@PathVariable("memberHelpId") Long memberHelpId)
    {
        return AjaxResult.success(memberHelpService.selectMemberHelpByMemberHelpId(memberHelpId));
    }

    /**
     * 新增求助记录
     */
    @PreAuthorize("@ss.hasPermi('management:help:add')")
    @Log(title = "求助记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberHelp memberHelp)
    {
        return toAjax(memberHelpService.insertMemberHelp(memberHelp));
    }

    /**
     * 修改求助记录
     */
    @PreAuthorize("@ss.hasPermi('management:help:edit')")
    @Log(title = "求助记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberHelp memberHelp)
    {
        return toAjax(memberHelpService.updateMemberHelp(memberHelp));
    }

    /**
     * 删除求助记录
     */
    @PreAuthorize("@ss.hasPermi('management:help:remove')")
    @Log(title = "求助记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberHelpIds}")
    public AjaxResult remove(@PathVariable Long[] memberHelpIds)
    {
        return toAjax(memberHelpService.deleteMemberHelpByMemberHelpIds(memberHelpIds));
    }
}
