package org.sky.desk.controller;

import io.swagger.v3.oas.annotations.Hidden;
import lombok.AllArgsConstructor;
import org.sky.common.cache.CacheNames;
import org.sky.core.boot.ctrl.KdController;
import org.sky.core.tenant.annotation.NonDS;
import org.sky.core.tool.api.R;
import org.sky.desk.entity.ProcessLeave;
import org.sky.desk.service.ILeaveService;
import org.sky.system.cache.UserCache;
import org.springframework.web.bind.annotation.*;

/**
 * 控制器
 *
 */
@NonDS
@Hidden
@RestController
@RequestMapping("/process/leave")
@AllArgsConstructor
public class LeaveController extends KdController implements CacheNames {

	private final ILeaveService leaveService;

	/**
	 * 详情
	 *
	 * @param businessId 主键
	 */
	@GetMapping("detail")
	public R<ProcessLeave> detail(Long businessId) {
		ProcessLeave detail = leaveService.getById(businessId);
		detail.getFlow().setAssigneeName(UserCache.getUser(detail.getCreateUser()).getName());
		return R.data(detail);
	}

	/**
	 * 新增或修改
	 *
	 * @param leave 请假信息
	 */
	@PostMapping("start-process")
	public R startProcess(@RequestBody ProcessLeave leave) {
		return R.status(leaveService.startProcess(leave));
	}

}
