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.SzxcZcssxj;
import com.ruoyi.szxc.service.ISzxcZcssxjService;
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/zcssxj")
public class SzxcZcssxjController extends BaseController
{
    @Autowired
    private ISzxcZcssxjService szxcZcssxjService;

    /**
     * 查询资产设施巡检列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:zcssxj:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcZcssxj szxcZcssxj)
    {
        startPage();
        List<SzxcZcssxj> list = szxcZcssxjService.selectSzxcZcssxjList(szxcZcssxj);
        return getDataTable(list);
    }

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

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

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

    /**
     * 修改资产设施巡检
     */
    @PreAuthorize("@ss.hasPermi('szxc:zcssxj:edit')")
    @Log(title = "资产设施巡检", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcZcssxj szxcZcssxj)
    {
        return toAjax(szxcZcssxjService.updateSzxcZcssxj(szxcZcssxj));
    }

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