package com.dgtly.web.controller.companyext;

import com.dgtly.framework.util.ShiroUtils;
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.CompanyExamine;
import com.dgtly.companyext.service.ICompanyExamineService;
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;

import java.util.List;

/**
 * 商户审核Controller
 * 
 * @author dgtly
 * @date 2020-02-13
 */
@Controller
@RequestMapping("/companyext/examine")
public class CompanyExamineController extends BaseController
{
    private String prefix = "companyext/examine";

    @Autowired
    private ICompanyExamineService companyExamineService;

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

    /*
     * @Description: 待审核列表页面
     * @Author: koucx
     * @Date: 2020-02-13
    **/
    @RequiresPermissions("companyext:noexamine:view")
    @GetMapping("/noexamine")
    public String noexamine()
    {
        return prefix + "/noexamine";
    }

    /*
     * @Description: 已经审核列表页面
     * @Author: koucx
     * @Date: 2020-02-13
     **/
    @RequiresPermissions("companyext:yesexamine:view")
    @GetMapping("/yesexamine")
    public String yesexamine()
    {
        return prefix + "/yesexamine";
    }

    /**
     * 查询商户审核列表
     */
    @RequiresPermissions("companyext:examine:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CompanyExamine companyExamine)
    {
        startPage();
        if(companyExamine.getStatus()==null){
            companyExamine.setStatus(3);
        }
        List<CompanyExamine> list = companyExamineService.selectCompanyExamineList(companyExamine);
        return getDataTable(list);
    }

    /**
     * 导出商户审核列表
     */
    @RequiresPermissions("companyext:examine:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CompanyExamine companyExamine)
    {
        List<CompanyExamine> list = companyExamineService.selectCompanyExamineList(companyExamine);
        ExcelUtil<CompanyExamine> util = new ExcelUtil<CompanyExamine>(CompanyExamine.class);
        return util.exportExcel(list, "examine");
    }

    /**
     * 新增商户审核
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商户审核
     */
    @RequiresPermissions("companyext:examine:add")
    @Log(title = "商户审核", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CompanyExamine companyExamine)
    {
        return toAjax(companyExamineService.insertCompanyExamine(companyExamine));
    }

    /**
     * 修改商户审核
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CompanyExamine companyExamine = companyExamineService.selectCompanyExamineById(id);
        mmap.put("companyExamine", companyExamine);
        return prefix + "/edit";
    }

    /**
     * 商户审核页面跳转
     */
    @GetMapping("/approvePage/{id}")
    public String approvePage(@PathVariable("id") Long id, ModelMap mmap)
    {
        CompanyExamine companyExamine = companyExamineService.selectCompanyExamineById(id);
        mmap.put("companyExamine", companyExamine);
        return prefix + "/approve";
    }

    /**
     * 修改保存商户审核
     */
    @RequiresPermissions("companyext:examine:edit")
    @Log(title = "商户审核", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CompanyExamine companyExamine)
    {
        companyExamine.setUpdateBy(ShiroUtils.getUserId().toString());
        return toAjax(companyExamineService.updateCompanyExamine(companyExamine));
    }

    /**
     * 删除商户审核
     */
    @RequiresPermissions("companyext:examine:remove")
    @Log(title = "商户审核", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(companyExamineService.deleteCompanyExamineByIds(ids));
    }
}
