package com.dgtly.web.controller.company;

import java.util.List;

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.CompanyHonour;
import com.dgtly.companyext.service.ICompanyHonourService;
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 qxp
 * @date 2020-03-02
 */
@Controller
@RequestMapping("/company/honour")
public class CompanyHonourController extends BaseController
{
    private String prefix = "company/honour";

    @Autowired
    private ICompanyHonourService companyHonourService;

    @RequiresPermissions("company:honour:view")
    @GetMapping()
    public String company_honour()
    {
        return prefix + "/honour";
    }

    /**
     * 查询企业荣誉列表
     */
    @RequiresPermissions("company:honour:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CompanyHonour companyHonour)
    {
        startPage();
        List<CompanyHonour> list = companyHonourService.selectCompanyHonourList(companyHonour);
        return getDataTable(list);
    }



    /**
     * 新增企业荣誉
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存企业荣誉
     */
    @RequiresPermissions("company:honour:add")
    @Log(title = "企业荣誉", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CompanyHonour companyHonour)
    {
        companyHonour.setCompanyId(ShiroUtils.getCompanyId());
        return toAjax(companyHonourService.insertCompanyHonour(companyHonour));
    }

    /**
     * 修改企业荣誉
     */
    @GetMapping("/edit/{honourId}")
    public String edit(@PathVariable("honourId") Long honourId, ModelMap mmap)
    {
        CompanyHonour companyHonour = companyHonourService.selectCompanyHonourById(honourId);
        mmap.put("companyHonour", companyHonour);
        return prefix + "/edit";
    }

    /**
     * 修改保存企业荣誉
     */
    @RequiresPermissions("company:honour:edit")
    @Log(title = "企业荣誉", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CompanyHonour companyHonour)
    {
        return toAjax(companyHonourService.updateCompanyHonour(companyHonour));
    }

    /**
     * 删除企业荣誉
     */
    @RequiresPermissions("company:honour:remove")
    @Log(title = "企业荣誉", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(companyHonourService.deleteCompanyHonourByIds(ids));
    }
}
