package org.security.trans.workHandOverUsers.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.security.ht.workHandOverUsers.entity.HandoverHistory;
import org.security.ht.workHandOverUsers.vo.HandoverHistoryVO;
import org.security.ht.workHandOverUsers.dto.HandoverHistoryDTO;
import org.security.trans.workHandOverUsers.service.HandoverHistoryService;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author zj 2022/9/7
 */
@AllArgsConstructor
@RestController
@RequestMapping("/handover/history")
public class HandoverHistoryController {
	private final HandoverHistoryService handoverHistoryService;

	@PostMapping("/save")
	public R add(@Valid @RequestBody HandoverHistoryVO handoverHistoryVO) {
		handoverHistoryVO.setHandoverTime(DateUtil.date());
		return handoverHistoryService.saveForm(handoverHistoryVO);
	}

	/**
	 * 自定义分页 工作交接历史
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入HandoverHistoryDTO")
	public R<IPage<HandoverHistoryVO>> page(HandoverHistoryDTO handoverHistoryDTO, Query query) {
		IPage<HandoverHistoryVO> pages = handoverHistoryService.selectProjectPage(Condition.getPage(query), handoverHistoryDTO);
		return R.data(pages);
	}

	/**
	 * 详情
	 */
	@GetMapping("/{id}")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入id")
	public R<HandoverHistoryVO> detail(@PathVariable String id) {
		HandoverHistory handoverHistory = handoverHistoryService.getDetail(id);
		return R.data(Func.copy(handoverHistory,HandoverHistoryVO.class));
	}
}
