package com.dgtly.order.controller;

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.order.domain.BpmWxNoticeOrg;
import com.dgtly.order.service.IBpmWxNoticeOrgService;
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 org.springframework.web.multipart.MultipartFile;

/**
 * 企微人员发送Controller
 * 
 * @author dgtly
 * @date 2021-08-26
 */
@Controller
@RequestMapping("/order/wxNoticeOrg")
public class BpmWxNoticeOrgController extends BaseController
{
    private String prefix = "order/wxNoticeOrg";

    @Autowired
    private IBpmWxNoticeOrgService bpmWxNoticeOrgService;

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

    /**
     * 查询企微人员发送列表
     */
    @RequiresPermissions("order:wxNoticeOrg:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BpmWxNoticeOrg bpmWxNoticeOrg)
    {
        startPage();
        List<BpmWxNoticeOrg> list = bpmWxNoticeOrgService.selectBpmWxNoticeOrgList(bpmWxNoticeOrg);
        return getDataTable(list);
    }

    /**
     * 导出企微人员发送列表
     */
    @RequiresPermissions("order:wxNoticeOrg:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BpmWxNoticeOrg bpmWxNoticeOrg)
    {
        List<BpmWxNoticeOrg> list = bpmWxNoticeOrgService.selectBpmWxNoticeOrgList(bpmWxNoticeOrg);
        ExcelUtil<BpmWxNoticeOrg> util = new ExcelUtil<BpmWxNoticeOrg>(BpmWxNoticeOrg.class);
        return util.exportExcel(list, "企微人员发送消息列表");
    }

    @RequiresPermissions("order:wxNoticeOrg:import")
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<BpmWxNoticeOrg> util = new ExcelUtil<BpmWxNoticeOrg>(BpmWxNoticeOrg.class);
        List<BpmWxNoticeOrg> wxNoticeOrgList = util.importExcel(file.getInputStream());
        String operName = ShiroUtils.getSysUser().getLoginName();
        String msg = bpmWxNoticeOrgService.importBpmWxNoticeOrg(wxNoticeOrgList, operName);
        return AjaxResult.success(msg);
    }

    /**
     * 新增企微人员发送
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存企微人员发送
     */
    @RequiresPermissions("order:wxNoticeOrg:add")
    @Log(title = "企微人员发送", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BpmWxNoticeOrg bpmWxNoticeOrg)
    {
        return toAjax(bpmWxNoticeOrgService.insertBpmWxNoticeOrg(bpmWxNoticeOrg));
    }

    /**
     * 修改企微人员发送
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BpmWxNoticeOrg bpmWxNoticeOrg = bpmWxNoticeOrgService.selectBpmWxNoticeOrgById(id);
        mmap.put("bpmWxNoticeOrg", bpmWxNoticeOrg);
        return prefix + "/edit";
    }

    /**
     * 修改保存企微人员发送
     */
    @RequiresPermissions("order:wxNoticeOrg:edit")
    @Log(title = "企微人员发送", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BpmWxNoticeOrg bpmWxNoticeOrg)
    {
        return toAjax(bpmWxNoticeOrgService.updateBpmWxNoticeOrg(bpmWxNoticeOrg));
    }

    /**
     * 删除企微人员发送
     */
    @RequiresPermissions("order:wxNoticeOrg:remove")
    @Log(title = "企微人员发送", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bpmWxNoticeOrgService.deleteBpmWxNoticeOrgByIds(ids));
    }
}
