package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.BusDevice;
import com.ruoyi.system.domain.BusPatient;
import com.ruoyi.system.domain.dto.Cure;
import com.ruoyi.system.domain.dto.SignDto;
import com.ruoyi.system.service.IBusDeviceHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.system.domain.BusDeviceHistory;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 透析管理Controller
 * 
 * @author zsl
 * @date 2022-06-07
 */
@Api("透析管理")
@RestController
@RequestMapping("/system/history")
public class BusDeviceHistoryController extends BaseController
{
    @Autowired
    private IBusDeviceHistoryService busDeviceHistoryService;

    /**
     * 查询透析管理列表
     */
    @ApiOperation("查询透析管理列表")
    @PreAuthorize("@ss.hasPermi('system:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusDeviceHistory busDeviceHistory)
    {
        startPage();
        List<BusDeviceHistory> list = busDeviceHistoryService.selectBusDeviceHistoryList(busDeviceHistory);
        return getDataTable(list);
    }

    /**
     * 导出透析管理列表
     */
    @ApiOperation("导出透析管理列表")
    @PreAuthorize("@ss.hasPermi('system:history:export')")
    @Log(title = "透析管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusDeviceHistory busDeviceHistory)
    {
        List<BusDeviceHistory> list = busDeviceHistoryService.selectBusDeviceHistoryList(busDeviceHistory);
        ExcelUtil<BusDeviceHistory> util = new ExcelUtil<BusDeviceHistory>(BusDeviceHistory.class);
        util.exportExcel(response, list, "透析管理数据");
    }


    /**
     * 获取透析管理详细信息
     */
    @ApiOperation("获取透析管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(busDeviceHistoryService.selectBusDeviceHistoryById(id));
    }

    /**
     * 新增透析管理
     */
    @ApiOperation("新增透析管理")
    @PreAuthorize("@ss.hasPermi('system:history:add')")
    @Log(title = "透析管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusDeviceHistory busDeviceHistory)
    {
        return toAjax(busDeviceHistoryService.insertBusDeviceHistory(busDeviceHistory));
    }

    /**
     * 签到管理
     */
    @ApiOperation("患者签到")
    @PreAuthorize("@ss.hasPermi('system:history:sign')")
    @Log(title = "患者签到", businessType = BusinessType.INSERT)
    @PostMapping("/sign")
    public AjaxResult sign(@RequestBody SignDto sign)
    {
        return toAjax(busDeviceHistoryService.sign(sign));
    }

    /**
     * 修改透析管理
     */
    @ApiOperation("修改透析管理")
    @PreAuthorize("@ss.hasPermi('system:history:edit')")
    @Log(title = "透析管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusDeviceHistory busDeviceHistory)
    {
        return toAjax(busDeviceHistoryService.updateBusDeviceHistory(busDeviceHistory));
    }

    /**
     * 删除透析管理
     */
    @ApiOperation("删除透析管理")
    @PreAuthorize("@ss.hasPermi('system:history:remove')")
    @Log(title = "透析管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busDeviceHistoryService.deleteBusDeviceHistoryByIds(ids));
    }
    /**
     * 删除透析管理
     */
    @ApiOperation("批量上机管理")
    @PreAuthorize("@ss.hasPermi('system:history:cure')")
    @Log(title = "透析管理", businessType = BusinessType.UPDATE)
    @PostMapping("/cure")
    public AjaxResult cure(@RequestBody Cure cure)
    {
        Long[] ids = new Long[1];
        ids[0] = cure.getIds();
        Long[] pids = new Long[1];
        pids[0] = cure.getPids();

        return toAjax(busDeviceHistoryService.cure(ids,pids));
    }


}
