package com.ruoyi.project.religion.place.controller;

import java.util.List;
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.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.project.religion.place.domain.ReligionPlace;
import com.ruoyi.project.religion.place.service.IReligionPlaceService;

/**
 * 宗教活动场所Controller
 * 
 * @author ruoyi
 */
@Controller
@RequestMapping("/religion/place")
public class ReligionPlaceController extends BaseController
{
    private String prefix = "religion/place";

    @Autowired
    private IReligionPlaceService religionPlaceService;

    /**
     * 跳转到场所列表页面
     */
    @RequiresPermissions("religion:place:view")
    @GetMapping()
    public String place()
    {
        return prefix + "/place";
    }

    /**
     * 查询宗教活动场所列表
     */
    @RequiresPermissions("religion:place:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReligionPlace place)
    {
        startPage();
        List<ReligionPlace> list = religionPlaceService.selectPlaceList(place);
        return getDataTable(list);
    }

    /**
     * 导出宗教活动场所列表
     */
    @RequiresPermissions("religion:place:export")
    @Log(title = "宗教活动场所", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReligionPlace place)
    {
        List<ReligionPlace> list = religionPlaceService.selectPlaceList(place);
        ExcelUtil<ReligionPlace> util = new ExcelUtil<ReligionPlace>(ReligionPlace.class);
        return util.exportExcel(list, "场所数据");
    }

    /**
     * 新增宗教活动场所页面
     */
    @RequiresPermissions("religion:place:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存宗教活动场所
     */
    @RequiresPermissions("religion:place:add")
    @Log(title = "宗教活动场所", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReligionPlace place)
    {
        place.setCreateBy(getLoginName());
        return toAjax(religionPlaceService.insertPlace(place));
    }

    /**
     * 修改宗教活动场所页面
     */
    @RequiresPermissions("religion:place:edit")
    @GetMapping("/edit/{placeId}")
    public String edit(@PathVariable("placeId") Long placeId, ModelMap mmap)
    {
        ReligionPlace place = religionPlaceService.selectPlaceById(placeId);
        mmap.put("place", place);
        return prefix + "/edit";
    }

    /**
     * 修改保存宗教活动场所
     */
    @RequiresPermissions("religion:place:edit")
    @Log(title = "宗教活动场所", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReligionPlace place)
    {
        place.setUpdateBy(getLoginName());
        return toAjax(religionPlaceService.updatePlace(place));
    }

    /**
     * 删除宗教活动场所
     */
    @RequiresPermissions("religion:place:remove")
    @Log(title = "宗教活动场所", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        String[] idArray = ids.split(",");
        Long[] placeIds = new Long[idArray.length];
        for (int i = 0; i < idArray.length; i++)
        {
            placeIds[i] = Long.parseLong(idArray[i]);
        }
        return toAjax(religionPlaceService.deletePlaceByIds(placeIds));
    }

    /**
     * 根据场所ID查询场所详情（API接口）
     */
    @RequiresPermissions("religion:place:query")
    @GetMapping("/{placeId}")
    @ResponseBody
    public AjaxResult getInfo(@PathVariable("placeId") Long placeId)
    {
        return AjaxResult.success(religionPlaceService.selectPlaceById(placeId));
    }
}

