package com.ruoyi.szxc.controller;

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.szxc.domain.SzxcPlaceManage;
import com.ruoyi.szxc.service.ISzxcPlaceManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 场所管理Controller
 * 
 * @author hs
 * @date 2024-03-28
 */
@RestController
@RequestMapping("/szxc/csmanage")
public class SzxcPlaceManageController extends BaseController
{
    @Autowired
    private ISzxcPlaceManageService szxcPlaceManageService;

    /**
     * 查询场所管理列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:csmanage:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcPlaceManage szxcPlaceManage)
    {
        startPage();
        List<SzxcPlaceManage> list = szxcPlaceManageService.selectSzxcPlaceManageList(szxcPlaceManage);
        return getDataTable(list);
    }

    /**
     * 导出场所管理列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:csmanage:export')")
    @Log(title = "场所管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcPlaceManage szxcPlaceManage)
    {
        List<SzxcPlaceManage> list = szxcPlaceManageService.selectSzxcPlaceManageList(szxcPlaceManage);
        ExcelUtil<SzxcPlaceManage> util = new ExcelUtil<SzxcPlaceManage>(SzxcPlaceManage.class);
        util.exportExcel(response, list, "场所管理数据");
    }

    /**
     * 获取场所管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:csmanage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcPlaceManageService.selectSzxcPlaceManageById(id));
    }

    /**
     * 新增场所管理
     */
    @PreAuthorize("@ss.hasPermi('szxc:csmanage:add')")
    @Log(title = "场所管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcPlaceManage szxcPlaceManage)
    {
        //根据前端传递过来的部门存储，如果没传则存储当前用户的部门
        if(szxcPlaceManage.getDeptId()==null){
            szxcPlaceManage.setDeptId(getDeptId());
        }
        szxcPlaceManage.setUserId(getUserId());
        return toAjax(szxcPlaceManageService.insertSzxcPlaceManage(szxcPlaceManage));
    }

    /**
     * 修改场所管理
     */
    @PreAuthorize("@ss.hasPermi('szxc:csmanage:edit')")
    @Log(title = "场所管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcPlaceManage szxcPlaceManage)
    {
        return toAjax(szxcPlaceManageService.updateSzxcPlaceManage(szxcPlaceManage));
    }

    /**
     * 删除场所管理
     */
    @PreAuthorize("@ss.hasPermi('szxc:csmanage:remove')")
    @Log(title = "场所管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcPlaceManageService.deleteSzxcPlaceManageByIds(ids));
    }
}
