package com.ruoyi.web.controller.buyerapi;

import java.util.List;
import cn.hutool.core.util.IdUtil;
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.buyerapi.domain.BuyerProjectMember;
import com.ruoyi.buyerapi.service.IBuyerProjectMemberService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 立项管理成员Controller
 * 
 * @author ruoyi
 * @date 2022-09-22
 */
@RestController
@RequestMapping("/buyer/member")
public class BuyerProjectMemberController extends BaseController
{
    @Autowired
    private IBuyerProjectMemberService buyerProjectMemberService;

    /**
     * 查询立项管理成员列表
     */
    @PreAuthorize("@ss.hasPermi('buyer:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuyerProjectMember buyerProjectMember)
    {
        startPage();
        List<BuyerProjectMember> list = buyerProjectMemberService.selectBuyerProjectMemberList(buyerProjectMember);
        return getDataTable(list);
    }

    /**
     * 导出立项管理成员列表
     */
    @PreAuthorize("@ss.hasPermi('buyer:member:export')")
    @Log(title = "立项管理成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyerProjectMember buyerProjectMember)
    {
        List<BuyerProjectMember> list = buyerProjectMemberService.selectBuyerProjectMemberList(buyerProjectMember);
        ExcelUtil<BuyerProjectMember> util = new ExcelUtil<BuyerProjectMember>(BuyerProjectMember.class);
        util.exportExcel(response, list, "立项管理成员数据");
    }

    /**
     * 获取立项管理成员详细信息
     */
    @PreAuthorize("@ss.hasPermi('buyer:member:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(buyerProjectMemberService.selectBuyerProjectMemberById(id));
    }

    /**
     * 新增立项管理成员
     */
    @PreAuthorize("@ss.hasPermi('buyer:member:add')")
    @Log(title = "立项管理成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyerProjectMember buyerProjectMember)
    {
        buyerProjectMember.setId(IdUtil.simpleUUID());
        buyerProjectMember.setCreateBy(getUsername());
        return toAjax(buyerProjectMemberService.insertBuyerProjectMember(buyerProjectMember));
    }

    /**
     * 修改立项管理成员
     */
    @PreAuthorize("@ss.hasPermi('buyer:member:edit')")
    @Log(title = "立项管理成员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyerProjectMember buyerProjectMember)
    {
        buyerProjectMember.setUpdateBy(getUsername());
        return toAjax(buyerProjectMemberService.updateBuyerProjectMember(buyerProjectMember));
    }

    /**
     * 删除立项管理成员
     */
    @PreAuthorize("@ss.hasPermi('buyer:member:remove')")
    @Log(title = "立项管理成员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(buyerProjectMemberService.deleteBuyerProjectMemberByIds(ids));
    }
}
