package com.ghy.web.controller.system;

import com.ghy.common.annotation.Log;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.core.domain.entity.SysDept;
import com.ghy.common.core.page.TableDataInfo;
import com.ghy.common.enums.BusinessType;
import com.ghy.common.utils.poi.ExcelUtil;
import com.ghy.system.domain.SysDeptConfig;
import com.ghy.system.service.ISysDeptConfigService;
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;


/**
 * 部门配置信息
 *
 * @author clunt
 */
@Controller
@RequestMapping("/system/dept/config")
public class SysDeptConfigController extends BaseController {

    private String prefix = "system/dept/config";

    @Autowired
    private ISysDeptConfigService sysDeptConfigService;

    @PostMapping("/query")
    @ResponseBody
    public SysDeptConfig query(SysDept dept)
    {
        return sysDeptConfigService.selectByDeptId(dept.getDeptId());
    }

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

    /**
     * 查询分公司配置列表
     */
    @RequiresPermissions("dept:config:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysDeptConfig sysDeptConfig)
    {
        startPage();
        List<SysDeptConfig> list = sysDeptConfigService.selectSysDeptConfigList(sysDeptConfig);
        return getDataTable(list);
    }

    /**
     * App查询分公司配置列表
     */
    @PostMapping("/app/list")
    @ResponseBody
    public TableDataInfo appList(@RequestBody SysDeptConfig sysDeptConfig)
    {
        startPage();
        List<SysDeptConfig> list = sysDeptConfigService.selectSysDeptConfigList(sysDeptConfig);
        return getDataTable(list);
    }


    /**
     * 导出分公司配置列表
     */
    @RequiresPermissions("dept:config:export")
    @Log(title = "分公司配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysDeptConfig sysDeptConfig)
    {
        List<SysDeptConfig> list = sysDeptConfigService.selectSysDeptConfigList(sysDeptConfig);
        ExcelUtil<SysDeptConfig> util = new ExcelUtil<SysDeptConfig>(SysDeptConfig.class);
        return util.exportExcel(list, "分公司配置数据");
    }

    /**
     * 新增分公司配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存分公司配置
     */
    @RequiresPermissions("dept:config:add")
    @Log(title = "分公司配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysDeptConfig sysDeptConfig)
    {
        return toAjax(sysDeptConfigService.insertSysDeptConfig(sysDeptConfig));
    }

    /**
     * 修改分公司配置
     */
    @RequiresPermissions("dept:config:edit")
    @GetMapping("/edit/{sysDeptConfigId}")
    public String edit(@PathVariable("sysDeptConfigId") Long sysDeptConfigId, ModelMap mmap)
    {
        SysDeptConfig sysDeptConfig = sysDeptConfigService.selectSysDeptConfigBySysDeptConfigId(sysDeptConfigId);
        mmap.put("sysDeptConfig", sysDeptConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存分公司配置
     */
    @RequiresPermissions("dept:config:edit")
    @Log(title = "分公司配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysDeptConfig sysDeptConfig)
    {
        return toAjax(sysDeptConfigService.updateSysDeptConfig(sysDeptConfig));
    }

    /**
     * 删除分公司配置
     */
    @RequiresPermissions("dept:config:remove")
    @Log(title = "分公司配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysDeptConfigService.deleteSysDeptConfigBySysDeptConfigIds(ids));
    }

}
