package com.ruoyi.szxc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.szxc.domain.SzxcWorkRecard;
import com.ruoyi.szxc.service.ISzxcWorkRecardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工作记录Controller
 * 
 * @author hs
 * @date 2024-03-20
 */
@RestController
@RequestMapping("/szxc/workrecard")
public class SzxcWorkRecardController extends BaseController
{
    @Autowired
    private ISzxcWorkRecardService szxcWorkRecardService;

    /**
     * 查询工作记录列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:workrecard:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcWorkRecard szxcWorkRecard)
    {
        startPage();
        List<SzxcWorkRecard> list = szxcWorkRecardService.selectSzxcWorkRecardList(szxcWorkRecard);
        return getDataTable(list);
    }

    /**
     * 导出工作记录列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:workrecard:export')")
    @Log(title = "工作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcWorkRecard szxcWorkRecard)
    {
        List<SzxcWorkRecard> list = szxcWorkRecardService.selectSzxcWorkRecardList(szxcWorkRecard);
        ExcelUtil<SzxcWorkRecard> util = new ExcelUtil<SzxcWorkRecard>(SzxcWorkRecard.class);
        util.exportExcel(response, list, "工作记录数据");
    }

    /**
     * 获取工作记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:workrecard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcWorkRecardService.selectSzxcWorkRecardById(id));
    }

    /**
     * 新增工作记录
     */
    @PreAuthorize("@ss.hasPermi('szxc:workrecard:add')")
    @Log(title = "工作记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcWorkRecard szxcWorkRecard)
    {
        return toAjax(szxcWorkRecardService.insertSzxcWorkRecard(szxcWorkRecard));
    }

    /**
     * 修改工作记录
     */
    @PreAuthorize("@ss.hasPermi('szxc:workrecard:edit')")
    @Log(title = "工作记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcWorkRecard szxcWorkRecard)
    {
        return toAjax(szxcWorkRecardService.updateSzxcWorkRecard(szxcWorkRecard));
    }

    /**
     * 删除工作记录
     */
    @PreAuthorize("@ss.hasPermi('szxc:workrecard:remove')")
    @Log(title = "工作记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcWorkRecardService.deleteSzxcWorkRecardByIds(ids));
    }
}
