package com.ruoyi.web.controller.system;

import java.util.Collection;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
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.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CompanyApp;
import com.ruoyi.system.service.ICompanyAppService;
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 ruoyi
 * @date 2023-05-15
 */
@Controller
@RequestMapping("/system/app")
public class CompanyAppController extends BaseController
{
    private String prefix = "system/app";

    @Autowired
    private ICompanyAppService companyAppService;

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

    /**
     * 查询客户端列表
     */
    @RequiresPermissions("system:app:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CompanyApp companyApp)
    {
        startPage();
        List<CompanyApp> list = companyAppService.selectCompanyAppList(companyApp);
        return getDataTable(list);
    }

    @PostMapping("/app/getById")
    @ResponseBody
    public AjaxResult getById(@RequestBody CompanyApp companyApp)
    {
        return AjaxResult.success(companyAppService.selectCompanyAppById(companyApp.getId()));
    }

    /**
     * 导出客户端列表
     */
    @RequiresPermissions("system:app:export")
    @Log(title = "客户端", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CompanyApp companyApp)
    {
        List<CompanyApp> list = companyAppService.selectCompanyAppList(companyApp);
        ExcelUtil<CompanyApp> util = new ExcelUtil<CompanyApp>(CompanyApp.class);
        return util.exportExcel(list, "客户端数据");
    }

    /**
     * 新增客户端
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存客户端
     */
    @RequiresPermissions("system:app:add")
    @Log(title = "客户端", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CompanyApp companyApp)
    {
        return toAjax(companyAppService.insertCompanyApp(companyApp));
    }

    /**
     * 修改客户端
     */
    @RequiresPermissions("system:app:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CompanyApp companyApp = companyAppService.selectCompanyAppById(id);
        mmap.put("companyApp", companyApp);
        return prefix + "/edit";
    }

    /**
     * 修改保存客户端
     */
    @RequiresPermissions("system:app:edit")
    @Log(title = "客户端", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CompanyApp companyApp)
    {
        return toAjax(companyAppService.updateCompanyApp(companyApp));
    }

    /**
     * 删除客户端
     */
    @RequiresPermissions("system:app:remove")
    @Log(title = "客户端", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(companyAppService.deleteCompanyAppByIds(ids));
    }
}
