package com.fs.hospital.controller.hospital;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import com.fs.hospital.domain.HospitalOperLog;
import com.fs.hospital.service.IHospitalOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 操作日志记录Controller
 *
 * @author fs
 * @date 2021-10-04
 */
@RestController
@RequestMapping("/hospital/hospitalOperLog")
public class HospitalOperLogController extends BaseController
{
    @Autowired
    private IHospitalOperLogService hospitalOperLogService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询操作日志记录列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalOperLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalOperLog hospitalOperLog)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        startPage();
        hospitalOperLog.setHospitalId(loginUser.getHospital().getHospitalId());
        List<HospitalOperLog> list = hospitalOperLogService.selectHospitalOperLogList(hospitalOperLog);
        return getDataTable(list);
    }

    /**
     * 导出操作日志记录列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalOperLog:export')")
    @Log(title = "操作日志记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalOperLog hospitalOperLog)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalOperLog.setHospitalId(loginUser.getHospital().getHospitalId());
        List<HospitalOperLog> list = hospitalOperLogService.selectHospitalOperLogList(hospitalOperLog);
        ExcelUtil<HospitalOperLog> util = new ExcelUtil<HospitalOperLog>(HospitalOperLog.class);
        return util.exportExcel(list, "hospitalOperLog");
    }

    /**
     * 获取操作日志记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalOperLog:query')")
    @GetMapping(value = "/{operId}")
    public AjaxResult getInfo(@PathVariable("operId") Long operId)
    {
        return AjaxResult.success(hospitalOperLogService.selectHospitalOperLogByOperId(operId));
    }

    /**
     * 新增操作日志记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalOperLog:add')")
    @Log(title = "操作日志记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalOperLog hospitalOperLog)
    {
        return toAjax(hospitalOperLogService.insertHospitalOperLog(hospitalOperLog));
    }

    /**
     * 修改操作日志记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalOperLog:edit')")
    @Log(title = "操作日志记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalOperLog hospitalOperLog)
    {
        return toAjax(hospitalOperLogService.updateHospitalOperLog(hospitalOperLog));
    }

    /**
     * 删除操作日志记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalOperLog:remove')")
    @Log(title = "操作日志记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{operIds}")
    public AjaxResult remove(@PathVariable Long[] operIds)
    {
        return toAjax(hospitalOperLogService.deleteHospitalOperLogByOperIds(operIds));
    }
}
