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.TbUserCompanyRecord;
import com.ruoyi.business.service.ITbUserCompanyRecordService;
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/companyRecord")
public class TbUserCompanyRecordController extends BaseController
{
    private String prefix = "business/companyRecord";

    @Autowired
    private ITbUserCompanyRecordService tbUserCompanyRecordService;

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

    /**
     * 查询公司的搜索记录列表
     */
    @RequiresPermissions("business:companyRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbUserCompanyRecord tbUserCompanyRecord)
    {
        startPage();
        List<TbUserCompanyRecord> list = tbUserCompanyRecordService.selectTbUserCompanyRecordList(tbUserCompanyRecord);
        return getDataTable(list);
    }

    /**
     * 导出公司的搜索记录列表
     */
    @RequiresPermissions("business:companyRecord:export")
    @Log(title = "公司的搜索记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbUserCompanyRecord tbUserCompanyRecord)
    {
        List<TbUserCompanyRecord> list = tbUserCompanyRecordService.selectTbUserCompanyRecordList(tbUserCompanyRecord);
        ExcelUtil<TbUserCompanyRecord> util = new ExcelUtil<TbUserCompanyRecord>(TbUserCompanyRecord.class);
        return util.exportExcel(list, "公司的搜索记录数据");
    }

    /**
     * 新增公司的搜索记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公司的搜索记录
     */
    @RequiresPermissions("business:companyRecord:add")
    @Log(title = "公司的搜索记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbUserCompanyRecord tbUserCompanyRecord)
    {
        return toAjax(tbUserCompanyRecordService.insertTbUserCompanyRecord(tbUserCompanyRecord));
    }

    /**
     * 修改公司的搜索记录
     */
    @RequiresPermissions("business:companyRecord:edit")
    @GetMapping("/edit/{companyRecordId}")
    public String edit(@PathVariable("companyRecordId") Long companyRecordId, ModelMap mmap)
    {
        TbUserCompanyRecord tbUserCompanyRecord = tbUserCompanyRecordService.selectTbUserCompanyRecordByCompanyRecordId(companyRecordId);
        mmap.put("tbUserCompanyRecord", tbUserCompanyRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存公司的搜索记录
     */
    @RequiresPermissions("business:companyRecord:edit")
    @Log(title = "公司的搜索记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbUserCompanyRecord tbUserCompanyRecord)
    {
        return toAjax(tbUserCompanyRecordService.updateTbUserCompanyRecord(tbUserCompanyRecord));
    }

    /**
     * 删除公司的搜索记录
     */
    @RequiresPermissions("business:companyRecord:remove")
    @Log(title = "公司的搜索记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbUserCompanyRecordService.deleteTbUserCompanyRecordByCompanyRecordIds(ids));
    }
}
