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.SzxcSbzl;
import com.ruoyi.szxc.service.ISzxcSbzlService;
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-20
 */
@RestController
@RequestMapping("/szxc/sbzl")
public class SzxcSbzlController extends BaseController
{
    @Autowired
    private ISzxcSbzlService szxcSbzlService;

    /**
     * 查询上报资料列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:sbzl:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcSbzl szxcSbzl)
    {
        startPage();
        List<SzxcSbzl> list = szxcSbzlService.selectSzxcSbzlList(szxcSbzl);
        return getDataTable(list);
    }

    /**
     * 导出上报资料列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:sbzl:export')")
    @Log(title = "上报资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcSbzl szxcSbzl)
    {
        List<SzxcSbzl> list = szxcSbzlService.selectSzxcSbzlList(szxcSbzl);
        ExcelUtil<SzxcSbzl> util = new ExcelUtil<SzxcSbzl>(SzxcSbzl.class);
        util.exportExcel(response, list, "上报资料数据");
    }

    /**
     * 获取上报资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:sbzl:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcSbzlService.selectSzxcSbzlById(id));
    }

    /**
     * 新增上报资料
     */
    @PreAuthorize("@ss.hasPermi('szxc:sbzl:add')")
    @Log(title = "上报资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcSbzl szxcSbzl)
    {
        return toAjax(szxcSbzlService.insertSzxcSbzl(szxcSbzl));
    }

    /**
     * 修改上报资料
     */
    @PreAuthorize("@ss.hasPermi('szxc:sbzl:edit')")
    @Log(title = "上报资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcSbzl szxcSbzl)
    {
        //根据前端传递过来的部门存储，如果没传则存储当前用户的部门
        if(szxcSbzl.getDeptId()==null){
            szxcSbzl.setDeptId(getDeptId());
        }
        szxcSbzl.setUserId(getUserId());
        return toAjax(szxcSbzlService.updateSzxcSbzl(szxcSbzl));
    }

    /**
     * 删除上报资料
     */
    @PreAuthorize("@ss.hasPermi('szxc:sbzl:remove')")
    @Log(title = "上报资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcSbzlService.deleteSzxcSbzlByIds(ids));
    }
}
