package com.org.web.hospital.controller;

import com.org.system.annotation.Log;
import com.org.system.controller.BaseController;
import com.org.system.enums.BusinessType;
import com.org.utils.AjaxResult;
import com.org.utils.core.IdParams;
import com.org.utils.page.TableDataInfo;
import com.org.web.hospital.domain.BcHospitalRecord;
import com.org.web.hospital.service.BcHospitalRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/hospital/record")
public class BcHospitalRecordController extends BaseController {

	@Autowired
	BcHospitalRecordService hospitalRecordService;

	/**
	 * 新增
	 */
	@PostMapping("/addOrUpdate")
	@PreAuthorize("@ss.hasPermi('hospital:record:add')")
	@Log(title = "入住退房管理新增/编辑", businessType = BusinessType.INSERT)
	public AjaxResult add(@Validated @RequestBody BcHospitalRecord bcHospitalRecord) {
		log.info("BcHospitalRecordController - add bcHospitalRecord:{}", bcHospitalRecord);

		return AjaxResult.success(hospitalRecordService.executeSaveOrUpdate(bcHospitalRecord));
	}

	/**
	 * 删除
	 */
	@PostMapping("/del")
	@PreAuthorize("@ss.hasPermi('hospital:record:del')")
	@Log(title = "入住退房管理删除", businessType = BusinessType.DELETE)
	public AjaxResult del(@Validated @RequestBody IdParams params) {
		log.info("BcHospitalRecordController - del params:{}", params);

		return AjaxResult.success(hospitalRecordService.del(params.getId()));
	}

	/**
	 * 详情
	 */
	@PostMapping("/detail")
	@PreAuthorize("@ss.hasAnyPermi('hospital:record:detail')")
	@Log(title = "入住退房管理详情", businessType = BusinessType.SELECT)
	public AjaxResult detail(@Validated @RequestBody IdParams params) {
		log.info("BcHospitalRecordController - detail params:{}", params);

		return AjaxResult.success(hospitalRecordService.getDetail(params.getId()));
	}

	/**
	 * 列表查询
	 */
	@PostMapping("/list")
	@PreAuthorize("@ss.hasAnyPermi('hospital:record:list')")
	@Log(title = "入住退房管理列表查询", businessType = BusinessType.SELECT)
	public TableDataInfo list(@RequestBody BcHospitalRecord params) {
		log.info("BcRoomController - list params:{}", params);

		startPage();

		List<BcHospitalRecord> list = hospitalRecordService.queryList(params);

		TableDataInfo dataTable = getDataTable(list);

		return dataTable;
	}

	/**
	 * 列表查询
	 */
	@GetMapping("/checkin/list")
	@PreAuthorize("@ss.hasAnyPermi('hospital:record:list')")
	@Log(title = "入住退房管理列表查询", businessType = BusinessType.SELECT)
	public TableDataInfo checkinList(BcHospitalRecord params) {
		log.info("BcRoomController - checkinList params:{}", params);

		startPage();

		List<BcHospitalRecord> list = hospitalRecordService.checkinList(params);

		TableDataInfo dataTable = getDataTable(list);

		return dataTable;
	}

	/**
	 * 列表查询
	 */
	@GetMapping("/checkout/list")
	@PreAuthorize("@ss.hasAnyPermi('hospital:record:list')")
	@Log(title = "入住退房管理列表查询", businessType = BusinessType.SELECT)
	public TableDataInfo checkoutList(BcHospitalRecord params) {
		log.info("BcRoomController - checkoutList params:{}", params);

		startPage();

		List<BcHospitalRecord> list = hospitalRecordService.checkoutList(params);

		TableDataInfo dataTable = getDataTable(list);

		return dataTable;
	}

}
