package com.admin.web.controller.major;

import com.admin.common.annotation.Log;
import com.admin.common.core.controller.BaseController;
import com.admin.common.core.domain.AjaxResult;
import com.admin.common.core.page.TableDataInfo;
import com.admin.common.enums.BusinessType;
import com.admin.common.utils.poi.ExcelUtil;
import com.admin.major.domain.Proposal;
import com.admin.major.domain.dto.ProposalDTO;
import com.admin.major.service.EnhanceProposalService;
import com.admin.major.service.IProposalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 用户建议记录Controller
 * 
 * @author zewei
 * @date 2022-05-31
 */
@RestController
@RequestMapping("/major/proposal")
public class ProposalController extends BaseController
{
    @Autowired
    private IProposalService proposalService;

    @Autowired
    private EnhanceProposalService enhanceProposalService;

    /**
     * 查询用户建议记录列表
     */
    @PreAuthorize("@ss.hasPermi('major:proposal:list')")
    @GetMapping("/list")
    public TableDataInfo list(Proposal proposal)
    {
        startPage();
        List<ProposalDTO> list = enhanceProposalService.viewProposalList(proposal);
        return getDataTable(list);
    }

    /**
     * 导出用户建议记录列表
     */
    @PreAuthorize("@ss.hasPermi('major:proposal:export')")
    @Log(title = "用户建议记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Proposal proposal)
    {
        List<ProposalDTO> list = enhanceProposalService.viewProposalList(proposal);
        ExcelUtil<ProposalDTO> util = new ExcelUtil<ProposalDTO>(ProposalDTO.class);
        util.exportExcel(response, list, "用户建议记录数据");
    }

    /**
     * 获取用户建议记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('major:proposal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(proposalService.selectProposalById(id));
    }

    /**
     * 新增用户建议记录
     */
    @PreAuthorize("@ss.hasPermi('major:proposal:add')")
    @Log(title = "用户建议记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Proposal proposal)
    {
        return toAjax(proposalService.insertProposal(proposal));
    }

    /**
     * 修改用户建议记录
     */
    @PreAuthorize("@ss.hasPermi('major:proposal:edit')")
    @Log(title = "用户建议记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Proposal proposal)
    {
        return toAjax(proposalService.updateProposal(proposal));
    }

    /**
     * 删除用户建议记录
     */
    @PreAuthorize("@ss.hasPermi('major:proposal:remove')")
    @Log(title = "用户建议记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proposalService.deleteProposalByIds(ids));
    }
}
