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.SzxcZcss;
import com.ruoyi.szxc.service.ISzxcZcssService;
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-04-02
 */
@RestController
@RequestMapping("/szxc/zcss")
public class SzxcZcssController extends BaseController
{
    @Autowired
    private ISzxcZcssService szxcZcssService;

    /**
     * 查询资产设施列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:zcss:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcZcss szxcZcss)
    {
        startPage();
        List<SzxcZcss> list = szxcZcssService.selectSzxcZcssList(szxcZcss);
        return getDataTable(list);
    }

    /**
     * 导出资产设施列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:zcss:export')")
    @Log(title = "资产设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcZcss szxcZcss)
    {
        List<SzxcZcss> list = szxcZcssService.selectSzxcZcssList(szxcZcss);
        ExcelUtil<SzxcZcss> util = new ExcelUtil<SzxcZcss>(SzxcZcss.class);
        util.exportExcel(response, list, "资产设施数据");
    }

    /**
     * 获取资产设施详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:zcss:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcZcssService.selectSzxcZcssById(id));
    }

    /**
     * 新增资产设施
     */
    @PreAuthorize("@ss.hasPermi('szxc:zcss:add')")
    @Log(title = "资产设施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcZcss szxcZcss)
    {
        //根据前端传递过来的部门存储，如果没传则存储当前用户的部门
        if(szxcZcss.getDeptId()==null){
            szxcZcss.setDeptId(getDeptId());
        }
        return toAjax(szxcZcssService.insertSzxcZcss(szxcZcss));
    }

    /**
     * 修改资产设施
     */
    @PreAuthorize("@ss.hasPermi('szxc:zcss:edit')")
    @Log(title = "资产设施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcZcss szxcZcss)
    {
        return toAjax(szxcZcssService.updateSzxcZcss(szxcZcss));
    }

    /**
     * 删除资产设施
     */
    @PreAuthorize("@ss.hasPermi('szxc:zcss:remove')")
    @Log(title = "资产设施", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcZcssService.deleteSzxcZcssByIds(ids));
    }
}
