package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ApplyChild;
import com.ruoyi.system.service.IApplyChildService;
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 java.util.List;

/**
 * 开通申请子系统Controller
 * 
 * @author ruoyi
 * @date 2022-10-27
 */
@Controller
@RequestMapping("/system/applyChild")
public class ApplyChildController extends BaseController
{
    private String prefix = "system/applyChild";

    @Autowired
    private IApplyChildService applyChildService;

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

    /**
     * 查询开通申请子系统列表
     */
    @RequiresPermissions("system:applyChild:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ApplyChild applyChild)
    {
        startPage();
        List<ApplyChild> list = applyChildService.selectApplyChildList(applyChild);
        return getDataTable(list);
    }

    /**
     * 导出开通申请子系统列表
     */
    @RequiresPermissions("system:applyChild:export")
    @Log(title = "开通申请子系统", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ApplyChild applyChild)
    {
        List<ApplyChild> list = applyChildService.selectApplyChildList(applyChild);
        ExcelUtil<ApplyChild> util = new ExcelUtil<ApplyChild>(ApplyChild.class);
        return util.exportExcel(list, "applyChild");
    }

    /**
     * 新增开通申请子系统
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存开通申请子系统
     */
    @RequiresPermissions("system:applyChild:add")
    @Log(title = "开通申请子系统", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ApplyChild applyChild)
    {
        return toAjax(applyChildService.insertApplyChild(applyChild));
    }

    /**
     * 修改开通申请子系统
     */
    @GetMapping("/edit/{childId}")
    public String edit(@PathVariable("childId") Long childId, ModelMap mmap)
    {
        ApplyChild applyChild = applyChildService.selectApplyChildById(childId);
        mmap.put("applyChild", applyChild);
        return prefix + "/edit";
    }

    /**
     * 修改保存开通申请子系统
     */
    @RequiresPermissions("system:applyChild:edit")
    @Log(title = "开通申请子系统", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ApplyChild applyChild)
    {
        return toAjax(applyChildService.updateApplyChild(applyChild));
    }

    /**
     * 删除开通申请子系统
     */
    @RequiresPermissions("system:applyChild:remove")
    @Log(title = "开通申请子系统", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(applyChildService.deleteApplyChildByIds(ids));
    }
}
