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.HospitalLogininfor;
import com.fs.hospital.service.IHospitalLogininforService;
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/logininfor")
public class HospitalLogininforController extends BaseController
{
    @Autowired
    private IHospitalLogininforService hospitalLogininforService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询系统访问记录列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalLogininfor:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalLogininfor hospitalLogininfor)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        startPage();
        hospitalLogininfor.setHospitalId(loginUser.getHospital().getHospitalId());
        List<HospitalLogininfor> list = hospitalLogininforService.selectHospitalLogininforList(hospitalLogininfor);
        return getDataTable(list);
    }

    /**
     * 导出系统访问记录列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalLogininfor:export')")
    @Log(title = "系统访问记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalLogininfor hospitalLogininfor)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalLogininfor.setHospitalId(loginUser.getHospital().getHospitalId());
        List<HospitalLogininfor> list = hospitalLogininforService.selectHospitalLogininforList(hospitalLogininfor);
        ExcelUtil<HospitalLogininfor> util = new ExcelUtil<HospitalLogininfor>(HospitalLogininfor.class);
        return util.exportExcel(list, "hospitalLogininfor");
    }

    /**
     * 获取系统访问记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalLogininfor:query')")
    @GetMapping(value = "/{infoId}")
    public AjaxResult getInfo(@PathVariable("infoId") Long infoId)
    {
        return AjaxResult.success(hospitalLogininforService.selectHospitalLogininforByInfoId(infoId));
    }

    /**
     * 新增系统访问记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalLogininfor:add')")
    @Log(title = "系统访问记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalLogininfor hospitalLogininfor)
    {
        return toAjax(hospitalLogininforService.insertHospitalLogininfor(hospitalLogininfor));
    }

    /**
     * 修改系统访问记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalLogininfor:edit')")
    @Log(title = "系统访问记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalLogininfor hospitalLogininfor)
    {
        return toAjax(hospitalLogininforService.updateHospitalLogininfor(hospitalLogininfor));
    }

    /**
     * 删除系统访问记录
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalLogininfor:remove')")
    @Log(title = "系统访问记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{infoIds}")
    public AjaxResult remove(@PathVariable Long[] infoIds)
    {
        return toAjax(hospitalLogininforService.deleteHospitalLogininforByInfoIds(infoIds));
    }
}
