package com.ruoyi.web.controller.invest;

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

import com.ruoyi.invest.domain.TProjectContacts;
import com.ruoyi.invest.service.ITProjectContactsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目联系人Controller
 * 
 * @author ruoyi
 * @date 2024-02-22
 */
@Api(tags = "项目联系人")
@RestController
@RequestMapping("/invest/contacts")
public class TProjectContactsController extends BaseController
{
    @Autowired
    private ITProjectContactsService tProjectContactsService;

    /**
     * 查询项目联系人列表
     */
    @ApiOperation("查询项目联系人列表")
    @PreAuthorize("@ss.hasPermi('invest:contacts:list')")
    @GetMapping("/list")
    public TableDataInfo list(TProjectContacts tProjectContacts)
    {
        startPage();
        List<TProjectContacts> list = tProjectContactsService.selectTProjectContactsList(tProjectContacts);
        return getDataTable(list);
    }

    /**
     * 导出项目联系人列表
     */
    @ApiOperation("导出项目联系人列表")
    @PreAuthorize("@ss.hasPermi('invest:contacts:export')")
    @Log(title = "项目联系人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TProjectContacts tProjectContacts)
    {
        List<TProjectContacts> list = tProjectContactsService.selectTProjectContactsList(tProjectContacts);
        ExcelUtil<TProjectContacts> util = new ExcelUtil<TProjectContacts>(TProjectContacts.class);
        util.exportExcel(response, list, "项目联系人数据");
    }

    /**
     * 获取项目联系人详细信息
     */
    @ApiOperation("获取项目联系人详细信息")
    @PreAuthorize("@ss.hasPermi('invest:contacts:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tProjectContactsService.selectTProjectContactsById(id));
    }

    /**
     * 新增项目联系人
     */
    @ApiOperation("新增项目联系人")
    @PreAuthorize("@ss.hasPermi('invest:contacts:add')")
    @Log(title = "项目联系人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TProjectContacts tProjectContacts)
    {
        tProjectContacts.setCreateBy(getNickName());
        return toAjax(tProjectContactsService.insertTProjectContacts(tProjectContacts));
    }

    /**
     * 修改项目联系人
     */
    @ApiOperation("修改项目联系人")
    @PreAuthorize("@ss.hasPermi('invest:contacts:edit')")
    @Log(title = "项目联系人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TProjectContacts tProjectContacts)
    {
        return toAjax(tProjectContactsService.updateTProjectContacts(tProjectContacts));
    }

    /**
     * 删除项目联系人
     */
    @ApiOperation("删除项目联系人")
    @PreAuthorize("@ss.hasPermi('invest:contacts:remove')")
    @Log(title = "项目联系人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tProjectContactsService.updateTProjectContactsByIds(ids));
    }
}
