package com.dgtly.web.controller.companyext;

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.dgtly.common.annotation.Log;
import com.dgtly.common.enums.BusinessType;
import com.dgtly.companyext.domain.CompanyExtInfo;
import com.dgtly.companyext.service.ICompanyExtInfoService;
import com.dgtly.common.core.controller.BaseController;
import com.dgtly.common.core.domain.AjaxResult;
import com.dgtly.common.utils.poi.ExcelUtil;
import com.dgtly.common.core.page.TableDataInfo;

/**
 * 商户扩展信息Controller
 * 
 * @author dgtly
 * @date 2020-02-13
 */
@Controller
@RequestMapping("/companyext/info")
public class CompanyExtInfoController extends BaseController
{
    private String prefix = "companyext/info";

    @Autowired
    private ICompanyExtInfoService companyExtInfoService;

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

    /**
     * 查询商户扩展信息列表
     */
    @RequiresPermissions("companyext:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CompanyExtInfo companyExtInfo)
    {
        startPage();
        List<CompanyExtInfo> list = companyExtInfoService.selectCompanyExtInfoList(companyExtInfo);
        return getDataTable(list);
    }

    /**
     * 导出商户扩展信息列表
     */
    @RequiresPermissions("companyext:info:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CompanyExtInfo companyExtInfo)
    {
        List<CompanyExtInfo> list = companyExtInfoService.selectCompanyExtInfoList(companyExtInfo);
        ExcelUtil<CompanyExtInfo> util = new ExcelUtil<CompanyExtInfo>(CompanyExtInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 新增商户扩展信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商户扩展信息
     */
    @RequiresPermissions("companyext:info:add")
    @Log(title = "商户扩展信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CompanyExtInfo companyExtInfo)
    {
        return toAjax(companyExtInfoService.insertCompanyExtInfo(companyExtInfo));
    }

    /**
     * 修改商户扩展信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CompanyExtInfo companyExtInfo = companyExtInfoService.selectCompanyExtInfoById(id);
        mmap.put("companyExtInfo", companyExtInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存商户扩展信息
     */
    @RequiresPermissions("companyext:info:edit")
    @Log(title = "商户扩展信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CompanyExtInfo companyExtInfo)
    {
        return toAjax(companyExtInfoService.updateCompanyExtInfo(companyExtInfo));
    }

    /**
     * 删除商户扩展信息
     */
    @RequiresPermissions("companyext:info:remove")
    @Log(title = "商户扩展信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(companyExtInfoService.deleteCompanyExtInfoByIds(ids));
    }
}
