package com.ruoyi.web.controller.proposal;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.system.domain.ProposalUser;
import com.ruoyi.system.service.IProposalUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 提案人员Controller
 *
 * @author boman
 * @date 2024-03-07
 */
@RestController
@RequestMapping("/proposal/user")
public class ProposalUserController extends BaseController
{
    @Autowired
    private IProposalUserService proposalUserService;

/**
 * 查询提案人员列表
 */
@PreAuthorize("@ss.hasPermi('proposal:user:list')")
@GetMapping("/list")
    public TableDataInfo list(ProposalUser proposalUser)
    {
        startPage();
        List<ProposalUser> list = proposalUserService.selectProposalUserList(proposalUser);
        return getDataTable(list);
    }

    /**
     * 导出提案人员列表
     */
    @PreAuthorize("@ss.hasPermi('proposal:user:export')")
    @Log(title = "提案人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProposalUser proposalUser)
    {
        List<ProposalUser> list = proposalUserService.selectProposalUserList(proposalUser);
        ExcelUtil<ProposalUser> util = new ExcelUtil<ProposalUser>(ProposalUser.class);
        util.exportExcel(response, list, "提案人员数据");
    }

    /**
     * 获取提案人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('proposal:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(proposalUserService.selectProposalUserById(id));
    }

    /**
     * 新增提案人员
     */
    @PreAuthorize("@ss.hasPermi('proposal:user:add')")
    @Log(title = "提案人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProposalUser proposalUser)
    {
        return toAjax(proposalUserService.insertProposalUser(proposalUser));
    }

    /**
     * 修改提案人员
     */
    @PreAuthorize("@ss.hasPermi('proposal:user:edit')")
    @Log(title = "提案人员", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ProposalUser proposalUser)
    {
        return toAjax(proposalUserService.updateProposalUser(proposalUser));
    }

    /**
     * 删除提案人员
     */
    @PreAuthorize("@ss.hasPermi('proposal:user:remove')")
    @Log(title = "提案人员", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proposalUserService.deleteProposalUserByIds(ids));
    }

    /**
     * 联名提案人员确认
     */
    @PreAuthorize("@ss.hasPermi('proposal:user:verify')")
    @Log(title = "提案人员", businessType = BusinessType.UPDATE)
    @PostMapping("/verify")
    public AjaxResult verify(@RequestBody ProposalUser proposalUser)
    {
        return toAjax(proposalUserService.verify(proposalUser));
    }
}
