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.TbUserCompanyStore;
import com.ruoyi.business.service.ITbUserCompanyStoreService;
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/companyStore")
public class TbUserCompanyStoreController extends BaseController
{
    private String prefix = "business/companyStore";

    @Autowired
    private ITbUserCompanyStoreService tbUserCompanyStoreService;

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

    /**
     * 查询我收藏的企业列表
     */
    @RequiresPermissions("business:companyStore:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbUserCompanyStore tbUserCompanyStore)
    {
        startPage();
        List<TbUserCompanyStore> list = tbUserCompanyStoreService.selectTbUserCompanyStoreList(tbUserCompanyStore);
        return getDataTable(list);
    }

    /**
     * 导出我收藏的企业列表
     */
    @RequiresPermissions("business:companyStore:export")
    @Log(title = "我收藏的企业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbUserCompanyStore tbUserCompanyStore)
    {
        List<TbUserCompanyStore> list = tbUserCompanyStoreService.selectTbUserCompanyStoreList(tbUserCompanyStore);
        ExcelUtil<TbUserCompanyStore> util = new ExcelUtil<TbUserCompanyStore>(TbUserCompanyStore.class);
        return util.exportExcel(list, "我收藏的企业数据");
    }

    /**
     * 新增我收藏的企业
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存我收藏的企业
     */
    @RequiresPermissions("business:companyStore:add")
    @Log(title = "我收藏的企业", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbUserCompanyStore tbUserCompanyStore)
    {
        return toAjax(tbUserCompanyStoreService.insertTbUserCompanyStore(tbUserCompanyStore));
    }

    /**
     * 修改我收藏的企业
     */
    @RequiresPermissions("business:companyStore:edit")
    @GetMapping("/edit/{userCompanyId}")
    public String edit(@PathVariable("userCompanyId") Long userCompanyId, ModelMap mmap)
    {
        TbUserCompanyStore tbUserCompanyStore = tbUserCompanyStoreService.selectTbUserCompanyStoreByUserCompanyId(userCompanyId);
        mmap.put("tbUserCompanyStore", tbUserCompanyStore);
        return prefix + "/edit";
    }

    /**
     * 修改保存我收藏的企业
     */
    @RequiresPermissions("business:companyStore:edit")
    @Log(title = "我收藏的企业", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbUserCompanyStore tbUserCompanyStore)
    {
        return toAjax(tbUserCompanyStoreService.updateTbUserCompanyStore(tbUserCompanyStore));
    }

    /**
     * 删除我收藏的企业
     */
    @RequiresPermissions("business:companyStore:remove")
    @Log(title = "我收藏的企业", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbUserCompanyStoreService.deleteTbUserCompanyStoreByUserCompanyIds(ids));
    }
}
