package com.ruoyi.web.controller.business;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.SCompanyMember;
import com.ruoyi.business.service.ISCompanyMemberService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司成员，负责招标项目的联系人Controller
 * 
 * @author xiatao
 * @date 2022-01-18
 */
@Controller
@RequestMapping("/business/companyMember")
public class SCompanyMemberController extends BaseController
{
    private String prefix = "business/companyMember";

    @Autowired
    private ISCompanyMemberService sCompanyMemberService;

    @RequiresPermissions("business:companyMember:view")
    @GetMapping()
    public String companyMember()
    {
        return prefix + "/companyMember";
    }

    /**
     * 查询公司成员，负责招标项目的联系人列表
     */
    @RequiresPermissions("business:companyMember:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SCompanyMember sCompanyMember)
    {
        startPage();
        List<SCompanyMember> list = sCompanyMemberService.selectSCompanyMemberList(sCompanyMember);
        return getDataTable(list);
    }

    /**
     * 导出公司成员，负责招标项目的联系人列表
     */
    @RequiresPermissions("business:companyMember:export")
    @Log(title = "公司成员，负责招标项目的联系人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SCompanyMember sCompanyMember)
    {
        List<SCompanyMember> list = sCompanyMemberService.selectSCompanyMemberList(sCompanyMember);
        ExcelUtil<SCompanyMember> util = new ExcelUtil<SCompanyMember>(SCompanyMember.class);
        return util.exportExcel(list, "公司成员，负责招标项目的联系人数据");
    }

    /**
     * 新增公司成员，负责招标项目的联系人
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公司成员，负责招标项目的联系人
     */
    @RequiresPermissions("business:companyMember:add")
    @Log(title = "公司成员，负责招标项目的联系人", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SCompanyMember sCompanyMember)
    {
        return toAjax(sCompanyMemberService.insertSCompanyMember(sCompanyMember));
    }

    /**
     * 修改公司成员，负责招标项目的联系人
     */
    @RequiresPermissions("business:companyMember:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SCompanyMember sCompanyMember = sCompanyMemberService.selectSCompanyMemberById(id);
        mmap.put("sCompanyMember", sCompanyMember);
        return prefix + "/edit";
    }

    /**
     * 修改保存公司成员，负责招标项目的联系人
     */
    @RequiresPermissions("business:companyMember:edit")
    @Log(title = "公司成员，负责招标项目的联系人", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SCompanyMember sCompanyMember)
    {
        return toAjax(sCompanyMemberService.updateSCompanyMember(sCompanyMember));
    }

    /**
     * 删除公司成员，负责招标项目的联系人
     */
    @RequiresPermissions("business:companyMember:remove")
    @Log(title = "公司成员，负责招标项目的联系人", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sCompanyMemberService.deleteSCompanyMemberByIds(ids));
    }
}
