package com.xinelu.manage.controller.schedule;

import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.R;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.manage.domain.schedule.Schedule;
import com.xinelu.manage.service.schedule.IScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 排班班次控制器
 * @author: haown
 * @create: 2023-09-21 17:25
 **/
@Api(tags = "排班班次控制器")
@RestController
@RequestMapping("/system/schedule")
public class ScheduleController extends BaseController {

	@Resource
	private IScheduleService scheduleService;

	/**
	 * 查询班次分页列表
	 */
	@ApiOperation("查询班次分页列表")
	@GetMapping("/list")
	public TableDataInfo list(Schedule schedule) {
		startPage();
		List<Schedule> list = scheduleService.getList(schedule);
		return getDataTable(list);
	}

	/**
	 * 查询班次列表
	 */
	@ApiOperation("查询班次列表")
	@GetMapping("/getList")
	public R<List<Schedule>> getList(Schedule schedule) {
		List<Schedule> list = scheduleService.getList(schedule);
		return R.ok(list);
	}

	@ApiOperation("新增班次")
	@PostMapping("add")
	public R<String> add(@RequestBody Schedule schedule) {
		return scheduleService.save(schedule) > 0 ? R.ok() : R.fail("保存失败");
	}

	@ApiOperation("修改班次")
	@PostMapping("update")
	public R<String> update(@RequestBody Schedule schedule) {
		return scheduleService.update(schedule) < 0 ? R.fail("修改失败") : R.ok();
	}

	@ApiOperation("逻辑删除班次")
	@ApiImplicitParam(name = "id", value = "班次主键", required = true, dataTypeClass = String.class)
	@DeleteMapping("/{id}")
	public R<String> delete(@PathVariable Long id) {
		scheduleService.delete(id);
		return R.ok();
	}

	/**
	 * 获取班次详细信息
	 */
	@ApiOperation("获取班次详细信息")
	@GetMapping(value = "getById/{id}")
	public R<Schedule> getById(@PathVariable("id") Long id) {
		return R.ok(scheduleService.getById(id));
	}

}
