package com.sooka.system.funeral.the_dead.controller;

import com.sooka.common.annotation.Log;
import com.sooka.common.core.controller.BaseController;
import com.sooka.common.core.domain.AjaxResult;
import com.sooka.common.core.page.TableDataInfo;
import com.sooka.common.enums.BusinessType;
import com.sooka.common.utils.poi.ExcelUtil;
import com.sooka.system.funeral.the_dead.domain.TGuijiTheDead;
import com.sooka.system.funeral.the_dead.service.ITGuijiTheDeadService;
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 lei
 * @date 2022-08-22
 */
@Controller
@RequestMapping("/system/funeral/funeral_the_dead")
public class TGuijiTheDeadController extends BaseController
{
    private String prefix = "system/funeral/the_dead";

    @Autowired
    private ITGuijiTheDeadService service;

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

    /**
     * 查询市殡葬-逝者基本信息列表
     */
    @RequiresPermissions("system:funeral_the_dead:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGuijiTheDead param)
    {
        startPage();
        List<TGuijiTheDead> list = service.selectList(param);
        return getDataTable(list);
    }

    /**
     * 导出市殡葬-逝者基本信息列表
     */
    @RequiresPermissions("system:funeral_the_dead:export")
    @Log(title = "市殡葬-逝者基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGuijiTheDead param)
    {
        List<TGuijiTheDead> list = service.selectList(param);
        ExcelUtil<TGuijiTheDead> util = new ExcelUtil<TGuijiTheDead>(TGuijiTheDead.class);
        return util.exportExcel(list, "市殡葬-逝者基本信息");
    }

    /**
     * 新增市殡葬-逝者基本信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存市殡葬-逝者基本信息
     */
    @RequiresPermissions("system:funeral_the_dead:add")
    @Log(title = "市殡葬-逝者基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGuijiTheDead param)
    {
        return toAjax(service.insert(param));
    }

    /**
     * 修改市殡葬-逝者基本信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiTheDead param = service.selectById(id);
        mmap.put("param", param);
        return prefix + "/edit";
    }

    /**
     * 修改保存市殡葬-逝者基本信息
     */
    @RequiresPermissions("system:funeral_the_dead:edit")
    @Log(title = "市殡葬-逝者基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGuijiTheDead param)
    {
        return toAjax(service.update(param));
    }

    /**
     * 删除市殡葬-逝者基本信息
     */
    @RequiresPermissions("system:funeral_the_dead:remove")
    @Log(title = "市殡葬-逝者基本信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(service.deleteByIds(ids));
    }

    /**
     * 市殡葬-逝者基本信息详情
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        TGuijiTheDead param = service.selectById(id);
        mmap.put("detail", param);
        return prefix + "/detail";
    }
}
