package com.org.web.person.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.person.domain.BcPersonService;
import com.org.web.person.service.BcPersonServiceService;
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("/person/service")
public class BcPersonServiceController extends BaseController {

	@Autowired
	BcPersonServiceService serviceService;

	/**
	 * 新增
	 */
	@PostMapping("/addOrUpdate")
	@PreAuthorize("@ss.hasPermi('person:service:add')")
	@Log(title = "服务人员新增/编辑", businessType = BusinessType.INSERT)
	public AjaxResult add(@Validated @RequestBody BcPersonService params) {
		log.info("BcRoomController - add params:{}", params);

		return AjaxResult.success(serviceService.executeSaveOrUpdate(params));
	}

	/**
	 * 删除
	 */
	@PostMapping("/del")
	@PreAuthorize("@ss.hasPermi('person:service:del')")
	@Log(title = "服务人员删除", businessType = BusinessType.DELETE)
	public AjaxResult del(@Validated @RequestBody IdParams params) {
		log.info("BcRoomController - del params:{}", params);

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

	/**
	 * 详情
	 */
	@PostMapping("/detail")
	@PreAuthorize("@ss.hasAnyPermi('person:service:detail')")
	@Log(title = "服务人员详情", businessType = BusinessType.SELECT)
	public AjaxResult detail(@Validated @RequestBody IdParams params) {
		log.info("BcRoomController - detail params:{}", params);

		return AjaxResult.success(serviceService.get(params.getId()));
	}

	/**
	 * 列表查询
	 */
	@GetMapping("/list")
	@PreAuthorize("@ss.hasAnyPermi('person:service:detail')")
	@Log(title = "服务人员列表查询", businessType = BusinessType.SELECT)
	public TableDataInfo list(BcPersonService params) {
		log.info("BcRoomController - list params:{}", params);

		startPage();

		List<BcPersonService> list = serviceService.queryList(params);

		TableDataInfo dataTable = getDataTable(list);

		return dataTable;
	}


}
